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