/.emacs.d/cedet-1.0/semantic/semanticdb-find.el

https://bitbucket.org/shuangxinyu/emacspack · Lisp · 1399 lines · 937 code · 128 blank · 334 comment · 55 complexity · c8dda10f68946ffafc920d38a1d03a84 MD5 · raw file

  1. ;;; semanticdb-find.el --- Searching through semantic databases.
  2. ;;; Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 Eric M. Ludlam
  3. ;; Author: Eric M. Ludlam <zappo@gnu.org>
  4. ;; Keywords: tags
  5. ;; X-RCS: $Id: semanticdb-find.el,v 1.90 2010/08/05 03:02:31 zappo Exp $
  6. ;; This file is not part of GNU Emacs.
  7. ;; Semanticdb is free software; you can redistribute it and/or modify
  8. ;; it under the terms of the GNU General Public License as published by
  9. ;; the Free Software Foundation; either version 2, or (at your option)
  10. ;; any later version.
  11. ;; This software is distributed in the hope that it will be useful,
  12. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. ;; GNU General Public License for more details.
  15. ;; You should have received a copy of the GNU General Public License
  16. ;; along with GNU Emacs; see the file COPYING. If not, write to the
  17. ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  18. ;; Boston, MA 02110-1301, USA.
  19. ;;
  20. ;;; Commentary:
  21. ;;
  22. ;; Databases of various forms can all be searched.
  23. ;; There are a few types of searches that can be done:
  24. ;;
  25. ;; Basic Name Search:
  26. ;; These searches scan a database table collection for tags based
  27. ;; on name.
  28. ;;
  29. ;; Basic Attribute Search:
  30. ;; These searches allow searching on specific attributes of tags,
  31. ;; such as name, type, or other attribute.
  32. ;;
  33. ;; Advanced Search:
  34. ;; These are searches that were needed to accomplish some
  35. ;; specialized tasks as discovered in utilities. Advanced searches
  36. ;; include matching methods defined outside some parent class.
  37. ;;
  38. ;; The reason for advanced searches are so that external
  39. ;; repositories such as the Emacs obarray, or java .class files can
  40. ;; quickly answer these needed questions without dumping the entire
  41. ;; symbol list into Emacs for additional refinement searches via
  42. ;; regular semanticdb search.
  43. ;;
  44. ;; How databases are decided upon is another important aspect of a
  45. ;; database search. When it comes to searching for a name, there are
  46. ;; these types of searches:
  47. ;;
  48. ;; Basic Search:
  49. ;; Basic search means that tags looking for a given name start
  50. ;; with a specific search path. Names are sought on that path
  51. ;; until it is empty or items on the path can no longer be found.
  52. ;; Use `semanticdb-dump-all-table-summary' to test this list.
  53. ;; Use `semanticdb-find-throttle-custom-list' to refine this list.
  54. ;;
  55. ;; Deep Search:
  56. ;; A deep search will search more than just the global namespace.
  57. ;; It will recurse into tags that contain more tags, and search
  58. ;; those too.
  59. ;;
  60. ;; Brute Search:
  61. ;; Brute search means that all tables in all databases in a given
  62. ;; project are searched. Brute searches are the search style as
  63. ;; written for semantic version 1.x.
  64. ;;
  65. ;; How does the search path work?
  66. ;;
  67. ;; A basic search starts with three parameters:
  68. ;;
  69. ;; (FINDME &optional PATH FIND-FILE-MATCH)
  70. ;;
  71. ;; FINDME is key to be searched for dependent on the type of search.
  72. ;; PATH is an indicator of which tables are to be searched.
  73. ;; FIND-FILE-MATCH indicates that any time a match is found, the
  74. ;; file associated with the tag should be read into a file.
  75. ;;
  76. ;; The PATH argument is then the most interesting argument. It can
  77. ;; have these values:
  78. ;;
  79. ;; nil - Take the current buffer, and use its include list
  80. ;; buffer - Use that buffer's include list.
  81. ;; filename - Use that file's include list. If the file is not
  82. ;; in a buffer, see of there is a semanticdb table for it. If
  83. ;; not, read that file into a buffer.
  84. ;; tag - Get that tag's buffer of file file. See above.
  85. ;; table - Search that table, and its include list.
  86. ;;
  87. ;; Search Results:
  88. ;;
  89. ;; Semanticdb returns the results in a specific format. There are a
  90. ;; series of routines for using those results, and results can be
  91. ;; passed in as a search-path for refinement searches with
  92. ;; semanticdb. Apropos for semanticdb.*find-result for more.
  93. ;;
  94. ;; Application:
  95. ;;
  96. ;; Here are applications where different searches are needed which
  97. ;; exist as of semantic 1.4.x
  98. ;;
  99. ;; eldoc - popup help
  100. ;; => Requires basic search using default path. (Header files ok)
  101. ;; tag jump - jump to a named tag
  102. ;; => Requires a brute search using whole project. (Source files only)
  103. ;; completion - Completing symbol names in a smart way
  104. ;; => Basic search (headers ok)
  105. ;; type analysis - finding type definitions for variables & fcns
  106. ;; => Basic search (headers ok)
  107. ;; Class browser - organize types into some structure
  108. ;; => Brute search, or custom navigation.
  109. ;; TODO:
  110. ;; During a search, load any unloaded DB files based on paths in the
  111. ;; current project.
  112. (require 'semanticdb)
  113. (require 'semanticdb-ref)
  114. (eval-when-compile
  115. (require 'semantic-find)
  116. (require 'eieio)
  117. )
  118. ;;; Code:
  119. ;;;###autoload
  120. (defvar semanticdb-find-throttle-custom-list
  121. '(repeat (radio (const 'local)
  122. (const 'project)
  123. (const 'unloaded)
  124. (const 'system)
  125. (const 'recursive)
  126. (const 'omniscience)))
  127. "Customization values for semanticdb find throttle.
  128. See `semanticdb-find-throttle' for details.")
  129. ;;;###autoload
  130. (defcustom semanticdb-find-default-throttle
  131. '(local project unloaded system recursive)
  132. "The default throttle for `semanticdb-find' routines.
  133. The throttle controls how detailed the list of database
  134. tables is for a symbol lookup. The value is a list with
  135. the following keys:
  136. `file' - The file the search is being performed from.
  137. This option is here for completeness only, and
  138. is assumed to always be on.
  139. `local' - Tables from the same local directory are included.
  140. This includes files directly referenced by a file name
  141. which might be in a different directory.
  142. `project' - Tables from the same local project are included
  143. If `project' is specified, then `local' is assumed.
  144. `unloaded' - If a table is not in memory, load it. If it is not cached
  145. on disk either, get the source, parse it, and create
  146. the table.
  147. `system' - Tables from system databases. These are specifically
  148. tables from system header files, or language equivalent.
  149. `recursive' - For include based searches, includes tables referenced
  150. by included files.
  151. `omniscience' - Included system databases which are omniscience, or
  152. somehow know everything. Omniscience databases are found
  153. in `semanticdb-project-system-databases'.
  154. The Emacs Lisp system DB is an omniscience database."
  155. :group 'semanticdb
  156. :type semanticdb-find-throttle-custom-list)
  157. (defun semanticdb-find-throttle-active-p (access-type)
  158. "Non-nil if ACCESS-TYPE is an active throttle type."
  159. (or (memq access-type semanticdb-find-default-throttle)
  160. (eq access-type 'file)
  161. (and (eq access-type 'local)
  162. (memq 'project semanticdb-find-default-throttle))
  163. ))
  164. ;;; Index Class
  165. ;;
  166. ;; The find routines spend a lot of time looking stuff up.
  167. ;; Use this handy search index to cache data between searches.
  168. ;; This should allow searches to start running faster.
  169. (defclass semanticdb-find-search-index (semanticdb-abstract-search-index)
  170. ((include-path :initform nil
  171. :documentation
  172. "List of semanticdb tables from the include path.")
  173. (type-cache :initform nil
  174. :documentation
  175. "Cache of all the data types accessible from this file.
  176. Includes all types from all included files, merged namespaces, and
  177. expunge duplicates.")
  178. )
  179. "Concrete search index for `semanticdb-find'.
  180. This class will cache data derived during various searches.")
  181. (defmethod semantic-reset ((idx semanticdb-find-search-index))
  182. "Reset the object IDX."
  183. ;; Clear the include path.
  184. (oset idx include-path nil)
  185. (when (oref idx type-cache)
  186. (semantic-reset (oref idx type-cache)))
  187. ;; Clear the scope. Scope doesn't have the data it needs to track
  188. ;; its own reset.
  189. (semantic-scope-reset-cache)
  190. )
  191. (defmethod semanticdb-synchronize ((idx semanticdb-find-search-index)
  192. new-tags)
  193. "Synchronize the search index IDX with some NEW-TAGS."
  194. ;; Reset our parts.
  195. (semantic-reset idx)
  196. ;; Notify dependants by clearning their indicies.
  197. (semanticdb-notify-references
  198. (oref idx table)
  199. (lambda (tab me)
  200. (semantic-reset (semanticdb-get-table-index tab))))
  201. )
  202. (defmethod semanticdb-partial-synchronize ((idx semanticdb-find-search-index)
  203. new-tags)
  204. "Synchronize the search index IDX with some changed NEW-TAGS."
  205. ;; Only reset if include statements changed.
  206. (if (semantic-find-tags-by-class 'include new-tags)
  207. (progn
  208. (semantic-reset idx)
  209. ;; Notify dependants by clearning their indicies.
  210. (semanticdb-notify-references
  211. (oref idx table)
  212. (lambda (tab me)
  213. (semantic-reset (semanticdb-get-table-index tab))))
  214. )
  215. ;; Else, not an include, by just a type.
  216. (when (oref idx type-cache)
  217. (when (semanticdb-partial-synchronize (oref idx type-cache) new-tags)
  218. ;; If the synchronize returns true, we need to notify.
  219. ;; Notify dependants by clearning their indicies.
  220. (semanticdb-notify-references
  221. (oref idx table)
  222. (lambda (tab me)
  223. (let ((tab-idx (semanticdb-get-table-index tab)))
  224. ;; Not a full reset?
  225. (when (oref tab-idx type-cache)
  226. (semanticdb-typecache-notify-reset
  227. (oref tab-idx type-cache)))
  228. )))
  229. ))
  230. ))
  231. ;;; Path Translations
  232. ;;
  233. ;;; OVERLOAD Functions
  234. ;;
  235. ;; These routines needed to be overloaded by specific language modes.
  236. ;; They are needed for translating an INCLUDE tag into a semanticdb
  237. ;; TABLE object.
  238. (define-overloadable-function semanticdb-find-translate-path (path brutish)
  239. "Translate PATH into a list of semantic tables.
  240. Path translation involves identifying the PATH input argument
  241. in one of the following ways:
  242. nil - Take the current buffer, and use its include list
  243. buffer - Use that buffer's include list.
  244. filename - Use that file's include list. If the file is not
  245. in a buffer, see of there is a semanticdb table for it. If
  246. not, read that file into a buffer.
  247. tag - Get that tag's buffer of file file. See above.
  248. table - Search that table, and its include list.
  249. find result - Search the results of a previous find.
  250. In addition, once the base path is found, there is the possibility of
  251. each added table adding yet more tables to the path, so this routine
  252. can return a lengthy list.
  253. If argument BRUTISH is non-nil, then instead of using the include
  254. list, use all tables found in the parent project of the table
  255. identified by translating PATH. Such searches use brute force to
  256. scan every available table.
  257. The return value is a list of objects of type `semanticdb-table' or
  258. their children. In the case of passing in a find result, the result
  259. is returned unchanged.
  260. This routine uses `semanticdb-find-table-for-include' to translate
  261. specific include tags into a semanticdb table.
  262. Note: When searching using a non-brutish method, the list of
  263. included files will be cached between runs. Database-references
  264. are used to track which files need to have their include lists
  265. refreshed when things change. See `semanticdb-ref-test'.
  266. Note for overloading: If you opt to overload this function for your
  267. major mode, and your routine takes a long time, be sure to call
  268. (semantic-throw-on-input 'your-symbol-here)
  269. so that it can be called from the idle work handler."
  270. )
  271. ;;;###autoload
  272. (defun semanticdb-find-translate-path-default (path brutish)
  273. "Translate PATH into a list of semantic tables.
  274. If BRUTISH is non nil, return all tables associated with PATH.
  275. Default action as described in `semanticdb-find-translate-path'."
  276. (if (semanticdb-find-results-p path)
  277. ;; nil means perform the search over these results.
  278. nil
  279. (if brutish
  280. (semanticdb-find-translate-path-brutish-default path)
  281. (semanticdb-find-translate-path-includes-default path))))
  282. ;;;###autoload
  283. (define-overloadable-function semanticdb-find-table-for-include (includetag &optional table)
  284. "For a single INCLUDETAG found in TABLE, find a `semanticdb-table' object
  285. INCLUDETAG is a semantic TAG of class 'include.
  286. TABLE is a semanticdb table that identifies where INCLUDETAG came from.
  287. TABLE is optional if INCLUDETAG has an overlay of :filename attribute."
  288. )
  289. (defun semanticdb-find-translate-path-brutish-default (path)
  290. "Translate PATH into a list of semantic tables.
  291. Default action as described in `semanticdb-find-translate-path'."
  292. (let ((basedb
  293. (cond ((null path) semanticdb-current-database)
  294. ((semanticdb-table-p path) (oref path parent-db))
  295. (t (let ((tt (semantic-something-to-tag-table path)))
  296. ;; @todo - What does this DO ??!?!
  297. (with-current-buffer (semantic-tag-buffer (car tt))
  298. semanticdb-current-database))))))
  299. (apply
  300. #'nconc
  301. (mapcar
  302. (lambda (db)
  303. (let ((tabs (semanticdb-get-database-tables db))
  304. (ret nil))
  305. ;; Only return tables of the same language (major-mode)
  306. ;; as the current search environment.
  307. (while tabs
  308. (semantic-throw-on-input 'translate-path-brutish)
  309. (if (semanticdb-equivalent-mode-for-search (car tabs)
  310. (current-buffer))
  311. (setq ret (cons (car tabs) ret)))
  312. (setq tabs (cdr tabs)))
  313. ret))
  314. ;; FIXME:
  315. ;; This should scan the current project directory list for all
  316. ;; semanticdb files, perhaps handling proxies for them.
  317. (semanticdb-current-database-list
  318. (if basedb (oref basedb reference-directory)
  319. default-directory))))
  320. ))
  321. (defun semanticdb-find-incomplete-cache-entries-p (cache)
  322. "Are there any incomplete entries in CACHE?"
  323. (let ((ans nil))
  324. (dolist (tab cache)
  325. (when (and (semanticdb-table-child-p tab)
  326. (not (number-or-marker-p (oref tab pointmax))))
  327. (setq ans t))
  328. )
  329. ans))
  330. (defun semanticdb-find-need-cache-update-p (table)
  331. "Non-nil if the semanticdb TABLE cache needs to be updated."
  332. ;; If we were passed in something related to a TABLE,
  333. ;; do a caching lookup.
  334. (let* ((index (semanticdb-get-table-index table))
  335. (cache (when index (oref index include-path)))
  336. (incom (semanticdb-find-incomplete-cache-entries-p cache))
  337. (unl (semanticdb-find-throttle-active-p 'unloaded))
  338. )
  339. (if (and
  340. cache ;; Must have a cache
  341. (or
  342. ;; If all entries are "full", or if 'unloaded
  343. ;; OR
  344. ;; is not in the throttle, it is ok to use the cache.
  345. (not incom) (not unl)
  346. ))
  347. nil
  348. ;;cache
  349. ;; ELSE
  350. ;;
  351. ;; We need an update.
  352. t))
  353. )
  354. (defun semanticdb-find-translate-path-includes-default (path)
  355. "Translate PATH into a list of semantic tables.
  356. Default action as described in `semanticdb-find-translate-path'."
  357. (let ((table (cond ((null path)
  358. semanticdb-current-table)
  359. ((bufferp path)
  360. (semantic-buffer-local-value 'semanticdb-current-table path))
  361. ((and (stringp path) (file-exists-p path))
  362. (semanticdb-file-table-object path t))
  363. ((semanticdb-abstract-table-child-p path)
  364. path)
  365. (t nil))))
  366. (if table
  367. ;; If we were passed in something related to a TABLE,
  368. ;; do a caching lookup.
  369. (let ((index (semanticdb-get-table-index table)))
  370. (if (semanticdb-find-need-cache-update-p table)
  371. ;; Lets go look up our indicies
  372. (let ((ans (semanticdb-find-translate-path-includes--internal path)))
  373. (oset index include-path ans)
  374. ;; Once we have our new indicies set up, notify those
  375. ;; who depend on us if we found something for them to
  376. ;; depend on.
  377. (when ans (semanticdb-refresh-references table))
  378. ans)
  379. ;; ELSE
  380. ;;
  381. ;; Just return the cache.
  382. (oref index include-path)))
  383. ;; If we were passed in something like a tag list, or other boring
  384. ;; searchable item, then instead do the regular thing without caching.
  385. (semanticdb-find-translate-path-includes--internal path))))
  386. (defvar semanticdb-find-lost-includes nil
  387. "Include files that we cannot find associated with this buffer.")
  388. (make-variable-buffer-local 'semanticdb-find-lost-includes)
  389. (defvar semanticdb-find-scanned-include-tags nil
  390. "All include tags scanned, plus action taken on the tag.
  391. Each entry is an alist:
  392. (ACTION . TAG)
  393. where ACTION is one of 'scanned, 'duplicate, 'lost
  394. and TAG is a clone of the include tag that was found.")
  395. (make-variable-buffer-local 'semanticdb-find-scanned-include-tags)
  396. (defvar semanticdb-implied-include-tags nil
  397. "Include tags implied for all files of a given mode.
  398. Set this variable with `defvar-mode-local' for a particular mode so
  399. that any symbols that exist for all files for that mode are included.
  400. Note: This could be used as a way to write a file in a language
  401. to declare all the built-ins for that language.")
  402. (defun semanticdb-find-translate-path-includes--internal (path)
  403. "Internal implementation of `semanticdb-find-translate-path-includes-default'.
  404. This routine does not depend on the cache, but will always derive
  405. a new path from the provided PATH."
  406. (let ((includetags nil)
  407. (curtable nil)
  408. (matchedtables (list semanticdb-current-table))
  409. (matchedincludes nil)
  410. (lostincludes nil)
  411. (scannedincludes nil)
  412. (incfname nil)
  413. nexttable)
  414. (cond ((null path)
  415. (semantic-refresh-tags-safe)
  416. (setq includetags (append
  417. (semantic-find-tags-included (current-buffer))
  418. semanticdb-implied-include-tags)
  419. curtable semanticdb-current-table
  420. incfname (buffer-file-name))
  421. )
  422. ((semanticdb-table-p path)
  423. (setq includetags (semantic-find-tags-included path)
  424. curtable path
  425. incfname (semanticdb-full-filename path))
  426. )
  427. ((bufferp path)
  428. (with-current-buffer path
  429. (semantic-refresh-tags-safe))
  430. (setq includetags (semantic-find-tags-included path)
  431. curtable (with-current-buffer path
  432. semanticdb-current-table)
  433. incfname (buffer-file-name path)))
  434. (t
  435. (setq includetags (semantic-find-tags-included path))
  436. (when includetags
  437. ;; If we have some tags, derive a table from them.
  438. ;; else we will do nothing, so the table is useless.
  439. ;; @todo - derive some tables
  440. (message "Need to derive tables for %S in translate-path-includes--default."
  441. path)
  442. )))
  443. ;; Make sure each found include tag has an originating file name associated
  444. ;; with it.
  445. (when incfname
  446. (dolist (it includetags)
  447. (semantic--tag-put-property it :filename incfname)))
  448. ;; Loop over all include tags adding to matchedtables
  449. (while includetags
  450. (semantic-throw-on-input 'semantic-find-translate-path-includes-default)
  451. ;; If we've seen this include string before, lets skip it.
  452. (if (member (semantic-tag-name (car includetags)) matchedincludes)
  453. (progn
  454. (setq nexttable nil)
  455. (push (cons 'duplicate (semantic-tag-clone (car includetags)))
  456. scannedincludes)
  457. )
  458. (setq nexttable (semanticdb-find-table-for-include (car includetags) curtable))
  459. (when (not nexttable)
  460. ;; Save the lost include.
  461. (push (car includetags) lostincludes)
  462. (push (cons 'lost (semantic-tag-clone (car includetags)))
  463. scannedincludes)
  464. )
  465. )
  466. ;; Push the include file, so if we can't find it, we only
  467. ;; can't find it once.
  468. (push (semantic-tag-name (car includetags)) matchedincludes)
  469. ;; (message "Scanning %s" (semantic-tag-name (car includetags)))
  470. (when (and nexttable
  471. (not (memq nexttable matchedtables))
  472. (semanticdb-equivalent-mode-for-search nexttable
  473. (current-buffer))
  474. )
  475. ;; Add to list of tables
  476. (push nexttable matchedtables)
  477. ;; Queue new includes to list
  478. (if (semanticdb-find-throttle-active-p 'recursive)
  479. ;; @todo - recursive includes need to have the originating
  480. ;; buffer's location added to the path.
  481. (let ((newtags
  482. (cond
  483. ((semanticdb-table-p nexttable)
  484. (semanticdb-refresh-table nexttable)
  485. ;; Use the method directly, or we will recurse
  486. ;; into ourselves here.
  487. (semanticdb-find-tags-by-class-method
  488. nexttable 'include))
  489. (t ;; @todo - is this ever possible???
  490. (message "semanticdb-ftp - how did you do that?")
  491. (semantic-find-tags-included
  492. (semanticdb-get-tags nexttable)))
  493. ))
  494. (newincfname (semanticdb-full-filename nexttable))
  495. )
  496. (push (cons 'scanned (semantic-tag-clone (car includetags)))
  497. scannedincludes)
  498. ;; Setup new tags so we know where they are.
  499. (dolist (it newtags)
  500. (semantic--tag-put-property it :filename
  501. newincfname))
  502. (setq includetags (nconc includetags newtags)))
  503. ;; ELSE - not recursive throttle
  504. (push (cons 'scanned-no-recurse
  505. (semantic-tag-clone (car includetags)))
  506. scannedincludes)
  507. )
  508. )
  509. (setq includetags (cdr includetags)))
  510. (setq semanticdb-find-lost-includes lostincludes)
  511. (setq semanticdb-find-scanned-include-tags (reverse scannedincludes))
  512. ;; Find all the omniscient databases for this major mode, and
  513. ;; add them if needed
  514. (when (and (semanticdb-find-throttle-active-p 'omniscience)
  515. semanticdb-search-system-databases)
  516. ;; We can append any mode-specific omniscience databases into
  517. ;; our search list here.
  518. (let ((systemdb semanticdb-project-system-databases)
  519. (ans nil))
  520. (while systemdb
  521. (setq ans (semanticdb-file-table
  522. (car systemdb)
  523. ;; I would expect most omniscient to return the same
  524. ;; thing reguardless of filename, but we may have
  525. ;; one that can return a table of all things the
  526. ;; current file needs.
  527. (buffer-file-name (current-buffer))))
  528. (when (not (memq ans matchedtables))
  529. (setq matchedtables (cons ans matchedtables)))
  530. (setq systemdb (cdr systemdb))))
  531. )
  532. (nreverse matchedtables)))
  533. (define-overloadable-function semanticdb-find-load-unloaded (filename)
  534. "Create a database table for FILENAME if it hasn't been parsed yet.
  535. Assumes that FILENAME exists as a source file.
  536. Assumes that a preexisting table does not exist, even if it
  537. isn't in memory yet."
  538. (if (semanticdb-find-throttle-active-p 'unloaded)
  539. (:override)
  540. (semanticdb-file-table-object filename t)))
  541. (defun semanticdb-find-load-unloaded-default (filename)
  542. "Load an unloaded file in FILENAME using the default semanticdb loader."
  543. (semanticdb-file-table-object filename))
  544. ;; The creation of the overload occurs above.
  545. (defun semanticdb-find-table-for-include-default (includetag &optional table)
  546. "Default implementation of `semanticdb-find-table-for-include'.
  547. Uses `semanticdb-current-database-list' as the search path.
  548. INCLUDETAG and TABLE are documented in `semanticdb-find-table-for-include'.
  549. Included databases are filtered based on `semanticdb-find-default-throttle'."
  550. (if (not (eq (semantic-tag-class includetag) 'include))
  551. (signal 'wrong-type-argument (list includetag 'include)))
  552. (let ((name
  553. ;; Note, some languages (like Emacs or Java) use include tag names
  554. ;; that don't represent files! We want to have file names.
  555. (semantic-tag-include-filename includetag))
  556. (originfiledir nil)
  557. (roots nil)
  558. (tmp nil)
  559. (ans nil))
  560. ;; INCLUDETAG should have some way to reference where it came
  561. ;; from! If not, TABLE should provide the way. Each time we
  562. ;; look up a tag, we may need to find it in some relative way
  563. ;; and must set our current buffer eto the origin of includetag
  564. ;; or nothing may work.
  565. (setq originfiledir
  566. (cond ((semantic-tag-file-name includetag)
  567. ;; A tag may have a buffer, or a :filename property.
  568. (file-name-directory (semantic-tag-file-name includetag)))
  569. (table
  570. (file-name-directory (semanticdb-full-filename table)))
  571. (t
  572. ;; @todo - what to do here? Throw an error maybe
  573. ;; and fix usage bugs?
  574. default-directory)))
  575. (cond
  576. ;; Step 1: Relative path name
  577. ;;
  578. ;; If the name is relative, then it should be findable as relative
  579. ;; to the source file that this tag originated in, and be fast.
  580. ;;
  581. ((and (semanticdb-find-throttle-active-p 'local)
  582. (file-exists-p (expand-file-name name originfiledir)))
  583. (setq ans (semanticdb-find-load-unloaded
  584. (expand-file-name name originfiledir)))
  585. )
  586. ;; Step 2: System or Project level includes
  587. ;;
  588. ((or
  589. ;; First, if it a system include, we can investigate that tags
  590. ;; dependency file
  591. (and (semanticdb-find-throttle-active-p 'system)
  592. ;; Sadly, not all languages make this distinction.
  593. ;;(semantic-tag-include-system-p includetag)
  594. ;; Here, we get local and system files.
  595. (setq tmp (semantic-dependency-tag-file includetag))
  596. )
  597. ;; Second, project files are active, we and we have EDE,
  598. ;; we can find it using the same tool.
  599. (and (semanticdb-find-throttle-active-p 'project)
  600. ;; Make sure EDE is available, and we have a project
  601. (featurep 'ede) (ede-current-project originfiledir)
  602. ;; The EDE query is hidden in this call.
  603. (setq tmp (semantic-dependency-tag-file includetag))
  604. )
  605. )
  606. (setq ans (semanticdb-find-load-unloaded tmp))
  607. )
  608. ;; Somewhere in our project hierarchy
  609. ;;
  610. ;; Remember: Roots includes system databases which can create
  611. ;; specialized tables we can search.
  612. ;;
  613. ;; NOTE: Not used if EDE is active!
  614. ((and (semanticdb-find-throttle-active-p 'project)
  615. ;; And dont do this if it is a system include. Not supported by all languages,
  616. ;; but when it is, this is a nice fast way to skip this step.
  617. (not (semantic-tag-include-system-p includetag))
  618. ;; Don't do this if we have an EDE project.
  619. (not (and (featurep 'ede)
  620. ;; Note: We don't use originfiledir here because
  621. ;; we want to know about the source file we are
  622. ;; starting from.
  623. (ede-current-project)))
  624. )
  625. (setq roots (semanticdb-current-database-list))
  626. (while (and (not ans) roots)
  627. (let* ((ref (if (slot-boundp (car roots) 'reference-directory)
  628. (oref (car roots) reference-directory)))
  629. (fname (cond ((null ref) nil)
  630. ((file-exists-p (expand-file-name name ref))
  631. (expand-file-name name ref))
  632. ((file-exists-p (expand-file-name (file-name-nondirectory name) ref))
  633. (expand-file-name (file-name-nondirectory name) ref)))))
  634. (when (and ref fname)
  635. ;; There is an actual file. Grab it.
  636. (setq ans (semanticdb-find-load-unloaded fname)))
  637. ;; ELSE
  638. ;;
  639. ;; NOTE: We used to look up omniscient databases here, but that
  640. ;; is now handled one layer up.
  641. ;;
  642. ;; Missing: a database that knows where missing files are. Hmm.
  643. ;; perhaps I need an override function for that?
  644. )
  645. (setq roots (cdr roots))))
  646. )
  647. ans))
  648. ;;; Perform interactive tests on the path/search mechanisms.
  649. ;;
  650. ;;;###autoload
  651. (defun semanticdb-find-test-translate-path (&optional arg)
  652. "Call and output results of `semanticdb-find-translate-path'.
  653. With ARG non-nil, specify a BRUTISH translation.
  654. See `semanticdb-find-default-throttle' and `semanticdb-project-roots'
  655. for details on how this list is derived."
  656. (interactive "P")
  657. (semantic-fetch-tags)
  658. (require 'data-debug)
  659. (let ((start (current-time))
  660. (p (semanticdb-find-translate-path nil arg))
  661. (end (current-time))
  662. )
  663. (data-debug-new-buffer "*SEMANTICDB FTP ADEBUG*")
  664. (message "Search of tags took %.2f seconds."
  665. (semantic-elapsed-time start end))
  666. (data-debug-insert-stuff-list p "*")))
  667. (defun semanticdb-find-test-translate-path-no-loading (&optional arg)
  668. "Call and output results of `semanticdb-find-translate-path'.
  669. With ARG non-nil, specify a BRUTISH translation.
  670. See `semanticdb-find-default-throttle' and `semanticdb-project-roots'
  671. for details on how this list is derived."
  672. (interactive "P")
  673. (semantic-fetch-tags)
  674. (require 'data-debug)
  675. (let* ((semanticdb-find-default-throttle
  676. (if (featurep 'semanticdb-find)
  677. (remq 'unloaded semanticdb-find-default-throttle)
  678. nil))
  679. (start (current-time))
  680. (p (semanticdb-find-translate-path nil arg))
  681. (end (current-time))
  682. )
  683. (data-debug-new-buffer "*SEMANTICDB FTP ADEBUG*")
  684. (message "Search of tags took %.2f seconds."
  685. (semantic-elapsed-time start end))
  686. (data-debug-insert-stuff-list p "*")))
  687. ;;;###autoload
  688. (defun semanticdb-test-current-database-list ()
  689. "Call and output results of `semanticdb-current-database-list'.
  690. Uses the `default-directory' to derive results."
  691. (interactive)
  692. (require 'data-debug)
  693. (let ((start (current-time))
  694. (p (semanticdb-current-database-list))
  695. )
  696. (data-debug-new-buffer "*SEMANTICDB Current Database List*")
  697. (data-debug-insert-stuff-list p "*")))
  698. (defun semanticdb-find-adebug-lost-includes ()
  699. "Translate the current path, then display the lost includes.
  700. Examines the variable `semanticdb-find-lost-includes'."
  701. (interactive)
  702. (require 'data-debug)
  703. (semanticdb-find-translate-path nil nil)
  704. (let ((lost semanticdb-find-lost-includes)
  705. )
  706. (if (not lost)
  707. (message "There are no unknown includes for %s"
  708. (buffer-name))
  709. (data-debug-new-buffer "*SEMANTICDB lost-includes ADEBUG*")
  710. (data-debug-insert-tag-list lost "*")
  711. )))
  712. (defun semanticdb-find-adebug-insert-scanned-tag-cons (consdata prefix prebuttontext)
  713. "Insert a button representing scanned include CONSDATA.
  714. PREFIX is the text that precedes the button.
  715. PREBUTTONTEXT is some text between prefix and the overlay button."
  716. (let* ((start (point))
  717. (end nil)
  718. (mode (car consdata))
  719. (tag (cdr consdata))
  720. (name (semantic-tag-name tag))
  721. (file (semantic-tag-file-name tag))
  722. (str1 (format "%S %s" mode name))
  723. (str2 (format " : %s" file))
  724. (tip nil))
  725. (insert prefix prebuttontext str1)
  726. (setq end (point))
  727. (insert str2)
  728. (put-text-property start end 'face
  729. (cond ((eq mode 'scanned)
  730. 'font-lock-function-name-face)
  731. ((eq mode 'duplicate)
  732. 'font-lock-comment-face)
  733. ((eq mode 'lost)
  734. 'font-lock-variable-name-face)
  735. ((eq mode 'scanned-no-recurse)
  736. 'font-lock-type-face)))
  737. (put-text-property start end 'ddebug (cdr consdata))
  738. (put-text-property start end 'ddebug-indent(length prefix))
  739. (put-text-property start end 'ddebug-prefix prefix)
  740. (put-text-property start end 'help-echo tip)
  741. (put-text-property start end 'ddebug-function
  742. 'data-debug-insert-tag-parts-from-point)
  743. (insert "\n")
  744. )
  745. )
  746. ;;;###autoload
  747. (defun semanticdb-find-adebug-scanned-includes ()
  748. "Translate the current path, then display the lost includes.
  749. Examines the variable `semanticdb-find-lost-includes'."
  750. (interactive)
  751. (require 'data-debug)
  752. (semanticdb-find-translate-path nil nil)
  753. (let ((scanned semanticdb-find-scanned-include-tags)
  754. (data-debug-thing-alist
  755. (cons
  756. '((lambda (thing) (and (consp thing)
  757. (symbolp (car thing))
  758. (memq (car thing)
  759. '(scanned scanned-no-recurse
  760. lost duplicate))))
  761. . semanticdb-find-adebug-insert-scanned-tag-cons)
  762. data-debug-thing-alist))
  763. )
  764. (if (not scanned)
  765. (message "There are no includes scanned %s"
  766. (buffer-name))
  767. (data-debug-new-buffer "*SEMANTICDB scanned-includes ADEBUG*")
  768. (data-debug-insert-stuff-list scanned "*")
  769. )))
  770. ;;; FIND results and edebug
  771. ;;
  772. (eval-after-load "cedet-edebug"
  773. '(progn
  774. (cedet-edebug-add-print-override
  775. '(semanticdb-find-results-p object)
  776. '(semanticdb-find-result-prin1-to-string object) )
  777. ))
  778. ;;; API Functions
  779. ;;
  780. ;; Once you have a search result, use these routines to operate
  781. ;; on the search results at a higher level
  782. ;;;###autoload
  783. (defun semanticdb-strip-find-results (results &optional find-file-match)
  784. "Strip a semanticdb search RESULTS to exclude objects.
  785. This makes it appear more like the results of a `semantic-find-' call.
  786. Optional FIND-FILE-MATCH loads all files associated with RESULTS
  787. into buffers. This has the side effect of enabling `semantic-tag-buffer' to
  788. return a value.
  789. If FIND-FILE-MATCH is 'name, then only the filename is stored
  790. in each tag instead of loading each file into a buffer.
  791. If the input RESULTS are not going to be used again, and if
  792. FIND-FILE-MATCH is nil, you can use `semanticdb-fast-strip-find-results'
  793. instead."
  794. (if find-file-match
  795. ;; Load all files associated with RESULTS.
  796. (let ((tmp results)
  797. (output nil))
  798. (while tmp
  799. (let ((tab (car (car tmp)))
  800. (tags (cdr (car tmp))))
  801. (dolist (T tags)
  802. ;; Normilzation gives specialty database tables a chance
  803. ;; to convert into a more stable tag format.
  804. (let* ((norm (semanticdb-normalize-one-tag tab T))
  805. (ntab (car norm))
  806. (ntag (cdr norm))
  807. (nametable ntab))
  808. ;; If it didn't normalize, use what we had.
  809. (if (not norm)
  810. (setq nametable tab)
  811. (setq output (append output (list ntag))))
  812. ;; Find-file-match allows a tool to make sure the tag is
  813. ;; 'live', somewhere in a buffer.
  814. (cond ((eq find-file-match 'name)
  815. (let ((f (semanticdb-full-filename nametable)))
  816. (semantic--tag-put-property ntag :filename f)))
  817. ((and find-file-match ntab)
  818. (semanticdb-get-buffer ntab))
  819. )
  820. ))
  821. )
  822. (setq tmp (cdr tmp)))
  823. output)
  824. ;; @todo - I could use nconc, but I don't know what the caller may do with
  825. ;; RESULTS after this is called. Right now semantic-complete will
  826. ;; recycling the input after calling this routine.
  827. (apply #'append (mapcar #'cdr results))))
  828. ;;;###autoload
  829. (defun semanticdb-fast-strip-find-results (results)
  830. "Destructively strip a semanticdb search RESULTS to exclude objects.
  831. This makes it appear more like the results of a `semantic-find-' call.
  832. This is like `semanticdb-strip-find-results', except the input list RESULTS
  833. will be changed."
  834. (apply #'nconc (mapcar #'cdr results)))
  835. ;;;###autoload
  836. (defun semanticdb-find-results-p (resultp)
  837. "Non-nil if RESULTP is in the form of a semanticdb search result.
  838. This query only really tests the first entry in the list that is RESULTP,
  839. but should be good enough for debugging assertions."
  840. (and (listp resultp)
  841. (listp (car resultp))
  842. (semanticdb-abstract-table-child-p (car (car resultp)))
  843. (or (semantic-tag-p (car (cdr (car resultp))))
  844. (null (car (cdr (car resultp)))))))
  845. (defun semanticdb-find-result-prin1-to-string (result)
  846. "Presuming RESULT satisfies `semanticdb-find-results-p', provide a short PRIN1 output."
  847. (if (< (length result) 2)
  848. (concat "#<FIND RESULT "
  849. (mapconcat (lambda (a)
  850. (concat "(" (object-name (car a) ) " . "
  851. "#<TAG LIST " (number-to-string (length (cdr a))) ">)"))
  852. result
  853. " ")
  854. ">")
  855. ;; Longer results should have an abreviated form.
  856. (format "#<FIND RESULT %d TAGS in %d FILES>"
  857. (semanticdb-find-result-length result)
  858. (length result))))
  859. ;;;###autoload
  860. (defun semanticdb-find-result-with-nil-p (resultp)
  861. "Non-nil of RESULTP is in the form of a semanticdb search result.
  862. The value nil is valid where a TABLE usually is, but only if the TAG
  863. results include overlays.
  864. This query only really tests the first entry in the list that is RESULTP,
  865. but should be good enough for debugging assertions."
  866. (and (listp resultp)
  867. (listp (car resultp))
  868. (let ((tag-to-test (car-safe (cdr (car resultp)))))
  869. (or (and (semanticdb-abstract-table-child-p (car (car resultp)))
  870. (or (semantic-tag-p tag-to-test)
  871. (null tag-to-test)))
  872. (and (null (car (car resultp)))
  873. (or (semantic-tag-with-position-p tag-to-test)
  874. (null tag-to-test))))
  875. )))
  876. (defun semanticdb-find-result-length (result)
  877. "Number of tags found in RESULT."
  878. (let ((count 0))
  879. (mapc (lambda (onetable)
  880. (setq count (+ count (1- (length onetable)))))
  881. result)
  882. count))
  883. ;;;###autoload
  884. (defun semanticdb-find-result-nth (result n)
  885. "In RESULT, return the Nth search result.
  886. This is a 0 based search result, with the first match being element 0.
  887. The returned value is a cons cell: (TAG . TABLE) where TAG
  888. is the tag at the Nth position. TABLE is the semanticdb table where
  889. the TAG was found. Sometimes TABLE can be nil."
  890. (let ((ans nil)
  891. (anstable nil))
  892. ;; Loop over each single table hit.
  893. (while (and (not ans) result)
  894. ;; For each table result, get local length, and modify
  895. ;; N to be that much less.
  896. (let ((ll (length (cdr (car result))))) ;; local length
  897. (if (> ll n)
  898. ;; We have a local match.
  899. (setq ans (nth n (cdr (car result)))
  900. anstable (car (car result)))
  901. ;; More to go. Decrement N.
  902. (setq n (- n ll))))
  903. ;; Keep moving.
  904. (setq result (cdr result)))
  905. (cons ans anstable)))
  906. (defun semanticdb-find-result-test (result)
  907. "Test RESULT by accessing all the tags in the list."
  908. (if (not (semanticdb-find-results-p result))
  909. (error "Does not pass `semanticdb-find-results-p.\n"))
  910. (let ((len (semanticdb-find-result-length result))
  911. (i 0))
  912. (while (< i len)
  913. (let ((tag (semanticdb-find-result-nth result i)))
  914. (if (not (semantic-tag-p (car tag)))
  915. (error "%d entry is not a tag" i)))
  916. (setq i (1+ i)))))
  917. ;;;###autoload
  918. (defun semanticdb-find-result-nth-in-buffer (result n)
  919. "In RESULT, return the Nth search result.
  920. Like `semanticdb-find-result-nth', except that only the TAG
  921. is returned, and the buffer it is found it will be made current.
  922. If the result tag has no position information, the originating buffer
  923. is still made current."
  924. (let* ((ret (semanticdb-find-result-nth result n))
  925. (ans (car ret))
  926. (anstable (cdr ret)))
  927. ;; If we have a hit, double-check the find-file
  928. ;; entry. If the file must be loaded, then gat that table's
  929. ;; source file into a buffer.
  930. (if anstable
  931. (let ((norm (semanticdb-normalize-one-tag anstable ans)))
  932. (when norm
  933. ;; The normalized tags can now be found based on that
  934. ;; tags table.
  935. (condition-case foo
  936. (progn
  937. (semanticdb-set-buffer (car norm))
  938. ;; Now reset ans
  939. (setq ans (cdr norm)))
  940. ;; Don't error for this case, but don't store
  941. ;; the thing either.
  942. (no-method-definition nil))
  943. ))
  944. )
  945. ;; Return the tag.
  946. ans))
  947. ;;;###autoload
  948. (defun semanticdb-find-result-mapc (fcn result)
  949. "Apply FCN to each element of find RESULT for side-effects only.
  950. FCN takes two arguments. The first is a TAG, and the
  951. second is a DB from whence TAG originated.
  952. Returns result."
  953. (mapc (lambda (sublst-icky)
  954. (mapc (lambda (tag-icky)
  955. (funcall fcn tag-icky (car sublst-icky)))
  956. (cdr sublst-icky)))
  957. result)
  958. result)
  959. ;;; Search Logging
  960. ;;
  961. ;; Basic logging to see what the search routines are doing.
  962. (defvar semanticdb-find-log-flag nil
  963. "Non-nil means log the process of searches.")
  964. (defvar semanticdb-find-log-buffer-name "*SemanticDB Find Log*"
  965. "The name of the logging buffer.")
  966. (defun semanticdb-find-toggle-logging ()
  967. "Toggle semanticdb logging."
  968. (interactive)
  969. (setq semanticdb-find-log-flag (null semanticdb-find-log-flag))
  970. (message "Semanticdb find logging is %sabled"
  971. (if semanticdb-find-log-flag "en" "dis")))
  972. (defun semanticdb-reset-log ()
  973. "Reset the log buffer."
  974. (interactive)
  975. (when semanticdb-find-log-flag
  976. (with-current-buffer (get-buffer-create semanticdb-find-log-buffer-name)
  977. (erase-buffer)
  978. )))
  979. (defun semanticdb-find-log-move-to-end ()
  980. "Move to the end of the semantic log."
  981. (let ((cb (current-buffer))
  982. (cw (selected-window)))
  983. (unwind-protect
  984. (progn
  985. (set-buffer semanticdb-find-log-buffer-name)
  986. (if (get-buffer-window (current-buffer) 'visible)
  987. (select-window (get-buffer-window (current-buffer) 'visible)))
  988. (goto-char (point-max)))
  989. (if cw (select-window cw))
  990. (set-buffer cb))))
  991. (defun semanticdb-find-log-new-search (forwhat)
  992. "Start a new search FORWHAT."
  993. (when semanticdb-find-log-flag
  994. (with-current-buffer (get-buffer-create semanticdb-find-log-buffer-name)
  995. (insert (format "New Search: %S\n" forwhat))
  996. )
  997. (semanticdb-find-log-move-to-end)))
  998. (defun semanticdb-find-log-activity (table result)
  999. "Log that TABLE has been searched and RESULT was found."
  1000. (when semanticdb-find-log-flag
  1001. (with-current-buffer semanticdb-find-log-buffer-name
  1002. (insert "Table: " (object-print table)
  1003. " Result: " (int-to-string (length result)) " tags"
  1004. "\n")
  1005. )
  1006. (semanticdb-find-log-move-to-end)))
  1007. ;;; Semanticdb find API functions
  1008. ;;
  1009. ;; These are the routines actually used to perform searches.
  1010. ;;
  1011. ;;;###autoload
  1012. (defun semanticdb-find-tags-collector (function &optional path find-file-match
  1013. brutish)
  1014. "Collect all tags returned by FUNCTION over PATH.
  1015. The FUNCTION must take two arguments. The first is TABLE,
  1016. which is a semanticdb table containing tags. The second argument
  1017. to FUNCTION is TAGS. TAGS may be a list of tags. If TAGS is non-nil,
  1018. then FUNCTION should search the TAG list, not through TABLE.
  1019. See `semanticdb-find-translate-path' for details on PATH.
  1020. FIND-FILE-MATCH indicates that any time a match is found, the file
  1021. associated with that tag should be loaded into a buffer.
  1022. Note: You should leave FIND-FILE-MATCH as nil. It is far more
  1023. efficient to take the results from any search and use
  1024. `semanticdb-strip-find-results' instead. This argument is here
  1025. for backward compatibility.
  1026. If optional argument BRUTISH is non-nil, then ignore include statements,
  1027. and search all tables in this project tree."
  1028. (let (found match)
  1029. (save-excursion
  1030. ;; If path is a buffer, set ourselves up in that buffer
  1031. ;; so that the override methods work correctly.
  1032. (when (bufferp path) (set-buffer path))
  1033. (if (semanticdb-find-results-p path)
  1034. ;; When we get find results, loop over that.
  1035. (dolist (tableandtags path)
  1036. (semantic-throw-on-input 'semantic-find-translate-path)
  1037. ;; If FIND-FILE-MATCH is non-nil, skip tables of class
  1038. ;; `semanticdb-search-results-table', since those are system
  1039. ;; databases and not associated with a file.
  1040. (unless (and find-file-match
  1041. (obj-of-class-p
  1042. (car tableandtags) semanticdb-search-results-table))
  1043. (when (setq match (funcall function
  1044. (car tableandtags) (cdr tableandtags)))
  1045. (when find-file-match
  1046. (save-excursion (semanticdb-set-buffer (car tableandtags))))
  1047. (push (cons (car tableandtags) match) found)))
  1048. )
  1049. ;; Only log searches across data bases.
  1050. (semanticdb-find-log-new-search nil)
  1051. ;; If we get something else, scan the list of tables resulting
  1052. ;; from translating it into a list of objects.
  1053. (dolist (table (semanticdb-find-translate-path path brutish))
  1054. (semantic-throw-on-input 'semantic-find-translate-path)
  1055. ;; If FIND-FILE-MATCH is non-nil, skip tables of class
  1056. ;; `semanticdb-search-results-table', since those are system
  1057. ;; databases and not associated with a file.
  1058. (unless (and find-file-match
  1059. (obj-of-class-p table semanticdb-search-results-table))
  1060. (when (and table (setq match (funcall function table nil)))
  1061. (semanticdb-find-log-activity table match)
  1062. (when find-file-match
  1063. (save-excursion (semanticdb-set-buffer table)))
  1064. (push (cons table match) found))))))
  1065. ;; At this point, FOUND has had items pushed onto it.
  1066. ;; This means items are being returned in REVERSE order
  1067. ;; of the tables searched, so if you just get th CAR, then
  1068. ;; too-bad, you may have some system-tag that has no
  1069. ;; buffer associated with it.
  1070. ;; It must be reversed.
  1071. (nreverse found)))
  1072. ;;;###autoload
  1073. (defun semanticdb-find-tags-by-name (name &optional path find-file-match)
  1074. "Search for all tags matching NAME on PATH.
  1075. See `semanticdb-find-translate-path' for details on PATH.
  1076. FIND-FILE-MATCH indicates that any time a match is found, the file
  1077. associated with that tag should be loaded into a buffer."
  1078. (semanticdb-find-tags-collector
  1079. (lambda (table tags)
  1080. (semanticdb-find-tags-by-name-method table name tags))
  1081. path find-file-match))
  1082. ;;;###autoload
  1083. (defun semanticdb-find-tags-by-name-regexp (regexp &optional path find-file-match)
  1084. "Search for all tags matching REGEXP on PATH.
  1085. See `semanticdb-find-translate-path' for details on PATH.
  1086. FIND-FILE-MATCH indicates that any time a match is found, the file
  1087. associated with that tag should be loaded into a buffer."
  1088. (semanticdb-find-tags-collector
  1089. (lambda (table tags)
  1090. (semanticdb-find-tags-by-name-regexp-method table regexp tags))
  1091. path find-file-match))
  1092. ;;;###autoload
  1093. (defun semanticdb-find-tags-for-completion (prefix &optional path find-file-match)
  1094. "Search for all tags matching PREFIX on PATH.
  1095. See `semanticdb-find-translate-path' for details on PATH.
  1096. FIND-FILE-MATCH indicates that any time a match is found, the file
  1097. associated with that tag should be loaded into a buffer."
  1098. (semanticdb-find-tags-collector
  1099. (lambda (table tags)
  1100. (semanticdb-find-tags-for-completion-method table prefix tags))
  1101. path find-file-match))
  1102. ;;;###autoload
  1103. (defun semanticdb-find-tags-by-class (class &optional path find-file-match)
  1104. "Search for all tags of CLASS on PATH.
  1105. See `semanticdb-find-translate-path' for details on PATH.
  1106. FIND-FILE-MATCH indicates that any time a match is found, the file
  1107. associated with that tag should be loaded into a buffer."
  1108. (semanticdb-find-tags-collector
  1109. (lambda (table tags)
  1110. (semanticdb-find-tags-by-class-method table class tags))
  1111. path find-file-match))
  1112. ;;; Deep Searches
  1113. ;;
  1114. ;;;###autoload
  1115. (defun semanticdb-deep-find-tags-by-name (name &optional path find-file-match)
  1116. "Search for all tags matching NAME on PATH.
  1117. Search also in all components of top level tags founds.
  1118. See `semanticdb-find-translate-path' for details on PATH.
  1119. FIND-FILE-MATCH indicates that any time a match is found, the file
  1120. associated with that tag should be loaded into a buffer."
  1121. (semanticdb-find-tags-collector
  1122. (lambda (table tags)
  1123. (semanticdb-deep-find-tags-by-name-method table name tags))
  1124. path find-file-match))
  1125. ;;;###autoload
  1126. (defun semanticdb-deep-find-tags-by-name-regexp (regexp &optional path find-file-match)
  1127. "Search for all tags matching REGEXP on PATH.
  1128. Search also in all components of top level tags founds.
  1129. See `semanticdb-find-translate-path' for details on PATH.
  1130. FIND-FILE-MATCH indicates that any time a match is found, the file
  1131. associated with that tag should be loaded into a buffer."
  1132. (semanticdb-find-tags-collector
  1133. (lambda (table tags)
  1134. (semanticdb-deep-find-tags-by-name-regexp-method table regexp tags))
  1135. path find-file-match))
  1136. ;;;###autoload
  1137. (defun semanticdb-deep-find-tags-for-completion (prefix &optional path find-file-match)
  1138. "Search for all tags matching PREFIX on PATH.
  1139. Search also in all components of top level tags founds.
  1140. See `semanticdb-find-translate-path' for details on PATH.
  1141. FIND-FILE-MATCH indicates that any time a match is found, the file
  1142. associated with that tag should be loaded into a buffer."
  1143. (semanticdb-find-tags-collector
  1144. (lambda (table tags)
  1145. (semanticdb-deep-find-tags-for-completion-method table prefix tags))
  1146. path find-file-match))
  1147. ;;; Brutish Search Routines
  1148. ;;
  1149. ;;;###autoload
  1150. (defun semanticdb-brute-deep-find-tags-by-name (name &optional path find-file-match)
  1151. "Search for all tags matching NAME on PATH.
  1152. See `semanticdb-find-translate-path' for details on PATH.
  1153. The argument BRUTISH will be set so that searching includes all tables
  1154. in the current project.
  1155. FIND-FILE-MATCH indicates that any time a match is found, the file
  1156. associated wit that tag should be loaded into a buffer."
  1157. (semanticdb-find-tags-collector
  1158. (lambda (table tags)
  1159. (semanticdb-deep-find-tags-by-name-method table name tags))
  1160. path find-file-match t))
  1161. ;;;###autoload
  1162. (defun semanticdb-brute-deep-find-tags-for-completion (prefix &optional path find-file-match)
  1163. "Search for all tags matching PREFIX on PATH.
  1164. See `semanticdb-find-translate-path' for details on PATH.
  1165. The argument BRUTISH will be set so that searching includes all tables
  1166. in the current project.
  1167. FIND-FILE-MATCH indicates that any time a match is found, the file
  1168. associated wit that tag should be loaded into a buffer."
  1169. (semanticdb-find-tags-collector
  1170. (lambda (table tags)
  1171. (semanticdb-deep-find-tags-for-completion-method table prefix tags))
  1172. path find-file-match t))
  1173. ;;;###autoload
  1174. (defun semanticdb-brute-find-tags-by-class (class &optional path find-file-match)
  1175. "Search for all tags of CLASS on PATH.
  1176. See `semanticdb-find-translate-path' for details on PATH.
  1177. The argument BRUTISH will be set so that searching includes all tables
  1178. in the current project.
  1179. FIND-FILE-MATCH indicates that any time a match is found, the file
  1180. associated with that tag should be loaded into a buffer."
  1181. (semanticdb-find-tags-collector
  1182. (lambda (table tags)
  1183. (semanticdb-find-tags-by-class-method table class tags))
  1184. path find-file-match t))
  1185. ;;; Specialty Search Routines
  1186. ;;
  1187. ;;;###autoload
  1188. (defun semanticdb-find-tags-external-children-of-type
  1189. (type &optional path find-file-match)
  1190. "Search for all tags defined outside of TYPE w/ TYPE as a parent.
  1191. See `semanticdb-find-translate-path' for details on PATH.
  1192. FIND-FILE-MATCH indicates that any time a match is found, the file
  1193. associated with that tag should be loaded into a buffer."
  1194. (semanticdb-find-tags-collector
  1195. (lambda (table tags)
  1196. (semanticdb-find-tags-external-children-of-type-method table type tags))
  1197. path find-file-match))
  1198. ;;;###autoload
  1199. (defun semanticdb-find-tags-subclasses-of-type
  1200. (type &optional path find-file-match)
  1201. "Search for all tags of class type defined that subclass TYPE.
  1202. See `semanticdb-find-translate-path' for details on PATH.
  1203. FIND-FILE-MATCH indicates that any time a match is found, the file
  1204. associated with that tag should be loaded into a buffer."
  1205. (semanticdb-find-tags-collector
  1206. (lambda (table tags)
  1207. (semanticdb-find-tags-subclasses-of-type-method table type tags))
  1208. path find-file-match t))
  1209. ;;; METHODS
  1210. ;;
  1211. ;; Default methods for semanticdb database and table objects.
  1212. ;; Override these with system databases to as new types of back ends.
  1213. ;;; Top level Searches
  1214. (defmethod semanticdb-find-tags-by-name-method ((table semanticdb-abstract-table) name &optional tags)
  1215. "In TABLE, find all occurrences of tags with NAME.
  1216. Optional argument TAGS is a list of tags to search.
  1217. Returns a table of all matching tags."
  1218. (semantic-find-tags-by-name name (or tags (semanticdb-get-tags table))))
  1219. (defmethod semanticdb-find-tags-by-name-regexp-method ((table semanticdb-abstract-table) regexp &optional tags)
  1220. "In TABLE, find all occurrences of tags matching REGEXP.
  1221. Optional argument TAGS is a list of tags to search.
  1222. Returns a table of all matching tags."
  1223. (semantic-find-tags-by-name-regexp regexp (or tags (semanticdb-get-tags table))))
  1224. (defmethod semanticdb-find-tags-for-completion-method ((table semanticdb-abstract-table) prefix &optional tags)
  1225. "In TABLE, find all occurrences of tags matching PREFIX.
  1226. Optional argument TAGS is a list of tags to search.
  1227. Returns a table of all matching tags."
  1228. (semantic-find-tags-for-completion prefix (or tags (semanticdb-get-tags table))))
  1229. (defmethod semanticdb-find-tags-by-class-method ((table semanticdb-abstract-table) class &optional tags)
  1230. "In TABLE, find all occurrences of tags of CLASS.
  1231. Optional argument TAGS is a list of tags to search.
  1232. Returns a table of all matching tags."
  1233. (semantic-find-tags-by-class class (or tags (semanticdb-get-tags table))))
  1234. (defmethod semanticdb-find-tags-external-children-of-type-method ((table semanticdb-abstract-table) parent &optional tags)
  1235. "In TABLE, find all occurrences of tags whose parent is the PARENT type.
  1236. Optional argument TAGS is a list of tags to search.
  1237. Returns a table of all matching tags."
  1238. (semantic-find-tags-external-children-of-type parent (or tags (semanticdb-get-tags table))))
  1239. (defmethod semanticdb-find-tags-subclasses-of-type-method ((table semanticdb-abstract-table) parent &optional tags)
  1240. "In TABLE, find all occurrences of tags whose parent is the PARENT type.
  1241. Optional argument TAGS is a list of tags to search.
  1242. Returns a table of all matching tags."
  1243. (semantic-find-tags-subclasses-of-type parent (or tags (semanticdb-get-tags table))))
  1244. ;;; Deep Searches
  1245. (defmethod semanticdb-deep-find-tags-by-name-method ((table semanticdb-abstract-table) name &optional tags)
  1246. "In TABLE, find all occurrences of tags with NAME.
  1247. Search in all tags in TABLE, and all components of top level tags in
  1248. TABLE.
  1249. Optional argument TAGS is a list of tags to search.
  1250. Return a table of all matching tags."
  1251. (semantic-find-tags-by-name name (semantic-flatten-tags-table (or tags (semanticdb-get-tags table)))))
  1252. (defmethod semanticdb-deep-find-tags-by-name-regexp-method ((table semanticdb-abstract-table) regexp &optional tags)
  1253. "In TABLE, find all occurrences of tags matching REGEXP.
  1254. Search in all tags in TABLE, and all components of top level tags in
  1255. TABLE.
  1256. Optional argument TAGS is a list of tags to search.
  1257. Return a table of all matching tags."
  1258. (semantic-find-tags-by-name-regexp regexp (semantic-flatten-tags-table (or tags (semanticdb-get-tags table)))))
  1259. (defmethod semanticdb-deep-find-tags-for-completion-method ((table semanticdb-abstract-table) prefix &optional tags)
  1260. "In TABLE, find all occurrences of tags matching PREFIX.
  1261. Search in all tags in TABLE, and all components of top level tags in
  1262. TABLE.
  1263. Optional argument TAGS is a list of tags to search.
  1264. Return a table of all matching tags."
  1265. (semantic-find-tags-for-completion prefix (semantic-flatten-tags-table (or tags (semanticdb-get-tags table)))))
  1266. (provide 'semanticdb-find)
  1267. ;;; semanticdb-find.el ends here