db-find.el 52 KB

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