Add 2010 to copyright years.
[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, 2010 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 "adebug")
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 (with-current-buffer path
473 (semantic-refresh-tags-safe))
474 (setq includetags (semantic-find-tags-included path)
475 curtable (with-current-buffer path
476 semanticdb-current-table)
477 incfname (buffer-file-name path)))
478 (t
479 (setq includetags (semantic-find-tags-included path))
480 (when includetags
481 ;; If we have some tags, derive a table from them.
482 ;; else we will do nothing, so the table is useless.
483
484 ;; @todo - derive some tables
485 (message "Need to derive tables for %S in translate-path-includes--default."
486 path)
487 )))
488
489 ;; Make sure each found include tag has an originating file name associated
490 ;; with it.
491 (when incfname
492 (dolist (it includetags)
493 (semantic--tag-put-property it :filename incfname)))
494
495 ;; Loop over all include tags adding to matchedtables
496 (while includetags
497 (semantic-throw-on-input 'semantic-find-translate-path-includes-default)
498
499 ;; If we've seen this include string before, lets skip it.
500 (if (member (semantic-tag-name (car includetags)) matchedincludes)
501 (progn
502 (setq nexttable nil)
503 (push (cons 'duplicate (semantic-tag-clone (car includetags)))
504 scannedincludes)
505 )
506 (setq nexttable (semanticdb-find-table-for-include (car includetags) curtable))
507 (when (not nexttable)
508 ;; Save the lost include.
509 (push (car includetags) lostincludes)
510 (push (cons 'lost (semantic-tag-clone (car includetags)))
511 scannedincludes)
512 )
513 )
514
515 ;; Push the include file, so if we can't find it, we only
516 ;; can't find it once.
517 (push (semantic-tag-name (car includetags)) matchedincludes)
518
519 ;; (message "Scanning %s" (semantic-tag-name (car includetags)))
520 (when (and nexttable
521 (not (memq nexttable matchedtables))
522 (semanticdb-equivalent-mode-for-search nexttable
523 (current-buffer))
524 )
525 ;; Add to list of tables
526 (push nexttable matchedtables)
527
528 ;; Queue new includes to list
529 (if (semanticdb-find-throttle-active-p 'recursive)
530 ;; @todo - recursive includes need to have the originating
531 ;; buffer's location added to the path.
532 (let ((newtags
533 (cond
534 ((semanticdb-table-p nexttable)
535 (semanticdb-refresh-table nexttable)
536 ;; Use the method directly, or we will recurse
537 ;; into ourselves here.
538 (semanticdb-find-tags-by-class-method
539 nexttable 'include))
540 (t ;; @todo - is this ever possible???
541 (message "semanticdb-ftp - how did you do that?")
542 (semantic-find-tags-included
543 (semanticdb-get-tags nexttable)))
544 ))
545 (newincfname (semanticdb-full-filename nexttable))
546 )
547
548 (push (cons 'scanned (semantic-tag-clone (car includetags)))
549 scannedincludes)
550
551 ;; Setup new tags so we know where they are.
552 (dolist (it newtags)
553 (semantic--tag-put-property it :filename
554 newincfname))
555
556 (setq includetags (nconc includetags newtags)))
557 ;; ELSE - not recursive throttle
558 (push (cons 'scanned-no-recurse
559 (semantic-tag-clone (car includetags)))
560 scannedincludes)
561 )
562 )
563 (setq includetags (cdr includetags)))
564
565 (setq semanticdb-find-lost-includes lostincludes)
566 (setq semanticdb-find-scanned-include-tags (reverse scannedincludes))
567
568 ;; Find all the omniscient databases for this major mode, and
569 ;; add them if needed
570 (when (and (semanticdb-find-throttle-active-p 'omniscience)
571 semanticdb-search-system-databases)
572 ;; We can append any mode-specific omniscience databases into
573 ;; our search list here.
574 (let ((systemdb semanticdb-project-system-databases)
575 (ans nil))
576 (while systemdb
577 (setq ans (semanticdb-file-table
578 (car systemdb)
579 ;; I would expect most omniscient to return the same
580 ;; thing reguardless of filename, but we may have
581 ;; one that can return a table of all things the
582 ;; current file needs.
583 (buffer-file-name (current-buffer))))
584 (when (not (memq ans matchedtables))
585 (setq matchedtables (cons ans matchedtables)))
586 (setq systemdb (cdr systemdb))))
587 )
588 (nreverse matchedtables)))
589
590 (define-overloadable-function semanticdb-find-load-unloaded (filename)
591 "Create a database table for FILENAME if it hasn't been parsed yet.
592 Assumes that FILENAME exists as a source file.
593 Assumes that a preexisting table does not exist, even if it
594 isn't in memory yet."
595 (if (semanticdb-find-throttle-active-p 'unloaded)
596 (:override)
597 (semanticdb-file-table-object filename t)))
598
599 (defun semanticdb-find-load-unloaded-default (filename)
600 "Load an unloaded file in FILENAME using the default semanticdb loader."
601 (semanticdb-file-table-object filename))
602
603 ;; The creation of the overload occurs above.
604 (defun semanticdb-find-table-for-include-default (includetag &optional table)
605 "Default implementation of `semanticdb-find-table-for-include'.
606 Uses `semanticdb-current-database-list' as the search path.
607 INCLUDETAG and TABLE are documented in `semanticdb-find-table-for-include'.
608 Included databases are filtered based on `semanticdb-find-default-throttle'."
609 (if (not (eq (semantic-tag-class includetag) 'include))
610 (signal 'wrong-type-argument (list includetag 'include)))
611
612 (let ((name
613 ;; Note, some languages (like Emacs or Java) use include tag names
614 ;; that don't represent files! We want to have file names.
615 (semantic-tag-include-filename includetag))
616 (originfiledir nil)
617 (roots nil)
618 (tmp nil)
619 (ans nil))
620
621 ;; INCLUDETAG should have some way to reference where it came
622 ;; from! If not, TABLE should provide the way. Each time we
623 ;; look up a tag, we may need to find it in some relative way
624 ;; and must set our current buffer eto the origin of includetag
625 ;; or nothing may work.
626 (setq originfiledir
627 (cond ((semantic-tag-file-name includetag)
628 ;; A tag may have a buffer, or a :filename property.
629 (file-name-directory (semantic-tag-file-name includetag)))
630 (table
631 (file-name-directory (semanticdb-full-filename table)))
632 (t
633 ;; @todo - what to do here? Throw an error maybe
634 ;; and fix usage bugs?
635 default-directory)))
636
637 (cond
638 ;; Step 1: Relative path name
639 ;;
640 ;; If the name is relative, then it should be findable as relative
641 ;; to the source file that this tag originated in, and be fast.
642 ;;
643 ((and (semanticdb-find-throttle-active-p 'local)
644 (file-exists-p (expand-file-name name originfiledir)))
645
646 (setq ans (semanticdb-find-load-unloaded
647 (expand-file-name name originfiledir)))
648 )
649 ;; Step 2: System or Project level includes
650 ;;
651 ((or
652 ;; First, if it a system include, we can investigate that tags
653 ;; dependency file
654 (and (semanticdb-find-throttle-active-p 'system)
655
656 ;; Sadly, not all languages make this distinction.
657 ;;(semantic-tag-include-system-p includetag)
658
659 ;; Here, we get local and system files.
660 (setq tmp (semantic-dependency-tag-file includetag))
661 )
662 ;; Second, project files are active, we and we have EDE,
663 ;; we can find it using the same tool.
664 (and (semanticdb-find-throttle-active-p 'project)
665 ;; Make sure EDE is available, and we have a project
666 (featurep 'ede) (ede-current-project originfiledir)
667 ;; The EDE query is hidden in this call.
668 (setq tmp (semantic-dependency-tag-file includetag))
669 )
670 )
671 (setq ans (semanticdb-find-load-unloaded tmp))
672 )
673 ;; Somewhere in our project hierarchy
674 ;;
675 ;; Remember: Roots includes system databases which can create
676 ;; specialized tables we can search.
677 ;;
678 ;; NOTE: Not used if EDE is active!
679 ((and (semanticdb-find-throttle-active-p 'project)
680 ;; And dont do this if it is a system include. Not supported by all languages,
681 ;; but when it is, this is a nice fast way to skip this step.
682 (not (semantic-tag-include-system-p includetag))
683 ;; Don't do this if we have an EDE project.
684 (not (and (featurep 'ede)
685 ;; Note: We don't use originfiledir here because
686 ;; we want to know about the source file we are
687 ;; starting from.
688 (ede-current-project)))
689 )
690
691 (setq roots (semanticdb-current-database-list))
692
693 (while (and (not ans) roots)
694 (let* ((ref (if (slot-boundp (car roots) 'reference-directory)
695 (oref (car roots) reference-directory)))
696 (fname (cond ((null ref) nil)
697 ((file-exists-p (expand-file-name name ref))
698 (expand-file-name name ref))
699 ((file-exists-p (expand-file-name (file-name-nondirectory name) ref))
700 (expand-file-name (file-name-nondirectory name) ref)))))
701 (when (and ref fname)
702 ;; There is an actual file. Grab it.
703 (setq ans (semanticdb-find-load-unloaded fname)))
704
705 ;; ELSE
706 ;;
707 ;; NOTE: We used to look up omniscient databases here, but that
708 ;; is now handled one layer up.
709 ;;
710 ;; Missing: a database that knows where missing files are. Hmm.
711 ;; perhaps I need an override function for that?
712
713 )
714
715 (setq roots (cdr roots))))
716 )
717 ans))
718
719 \f
720 ;;; Perform interactive tests on the path/search mechanisms.
721 ;;
722 ;;;###autoload
723 (defun semanticdb-find-test-translate-path (&optional arg)
724 "Call and output results of `semanticdb-find-translate-path'.
725 With ARG non-nil, specify a BRUTISH translation.
726 See `semanticdb-find-default-throttle' and `semanticdb-project-roots'
727 for details on how this list is derived."
728 (interactive "P")
729 (semantic-fetch-tags)
730 (require 'data-debug)
731 (let ((start (current-time))
732 (p (semanticdb-find-translate-path nil arg))
733 (end (current-time))
734 )
735 (data-debug-new-buffer "*SEMANTICDB FTP ADEBUG*")
736 (message "Search of tags took %.2f seconds."
737 (semantic-elapsed-time start end))
738
739 (data-debug-insert-stuff-list p "*")))
740
741 (defun semanticdb-find-test-translate-path-no-loading (&optional arg)
742 "Call and output results of `semanticdb-find-translate-path'.
743 With ARG non-nil, specify a BRUTISH translation.
744 See `semanticdb-find-default-throttle' and `semanticdb-project-roots'
745 for details on how this list is derived."
746 (interactive "P")
747 (semantic-fetch-tags)
748 (require 'data-debug)
749 (let* ((semanticdb-find-default-throttle
750 (if (featurep 'semantic/db-find)
751 (remq 'unloaded semanticdb-find-default-throttle)
752 nil))
753 (start (current-time))
754 (p (semanticdb-find-translate-path nil arg))
755 (end (current-time))
756 )
757 (data-debug-new-buffer "*SEMANTICDB FTP ADEBUG*")
758 (message "Search of tags took %.2f seconds."
759 (semantic-elapsed-time start end))
760
761 (data-debug-insert-stuff-list p "*")))
762
763 ;;;###autoload
764 (defun semanticdb-find-adebug-lost-includes ()
765 "Translate the current path, then display the lost includes.
766 Examines the variable `semanticdb-find-lost-includes'."
767 (interactive)
768 (require 'data-debug)
769 (semanticdb-find-translate-path nil nil)
770 (let ((lost semanticdb-find-lost-includes)
771 )
772
773 (if (not lost)
774 (message "There are no unknown includes for %s"
775 (buffer-name))
776
777 (data-debug-new-buffer "*SEMANTICDB lost-includes ADEBUG*")
778 (data-debug-insert-tag-list lost "*")
779 )))
780
781 (defun semanticdb-find-adebug-insert-scanned-tag-cons (consdata prefix prebuttontext)
782 "Insert a button representing scanned include CONSDATA.
783 PREFIX is the text that precedes the button.
784 PREBUTTONTEXT is some text between prefix and the overlay button."
785 (let* ((start (point))
786 (end nil)
787 (mode (car consdata))
788 (tag (cdr consdata))
789 (name (semantic-tag-name tag))
790 (file (semantic-tag-file-name tag))
791 (str1 (format "%S %s" mode name))
792 (str2 (format " : %s" file))
793 (tip nil))
794 (insert prefix prebuttontext str1)
795 (setq end (point))
796 (insert str2)
797 (put-text-property start end 'face
798 (cond ((eq mode 'scanned)
799 'font-lock-function-name-face)
800 ((eq mode 'duplicate)
801 'font-lock-comment-face)
802 ((eq mode 'lost)
803 'font-lock-variable-name-face)
804 ((eq mode 'scanned-no-recurse)
805 'font-lock-type-face)))
806 (put-text-property start end 'ddebug (cdr consdata))
807 (put-text-property start end 'ddebug-indent(length prefix))
808 (put-text-property start end 'ddebug-prefix prefix)
809 (put-text-property start end 'help-echo tip)
810 (put-text-property start end 'ddebug-function
811 'data-debug-insert-tag-parts-from-point)
812 (insert "\n")
813 )
814 )
815
816 (defun semanticdb-find-adebug-scanned-includes ()
817 "Translate the current path, then display the lost includes.
818 Examines the variable `semanticdb-find-lost-includes'."
819 (interactive)
820 (require 'data-debug)
821 (semanticdb-find-translate-path nil nil)
822 (let ((scanned semanticdb-find-scanned-include-tags)
823 (data-debug-thing-alist
824 (cons
825 '((lambda (thing) (and (consp thing)
826 (symbolp (car thing))
827 (memq (car thing)
828 '(scanned scanned-no-recurse
829 lost duplicate))))
830 . semanticdb-find-adebug-insert-scanned-tag-cons)
831 data-debug-thing-alist))
832 )
833
834 (if (not scanned)
835 (message "There are no includes scanned %s"
836 (buffer-name))
837
838 (data-debug-new-buffer "*SEMANTICDB scanned-includes ADEBUG*")
839 (data-debug-insert-stuff-list scanned "*")
840 )))
841 \f
842 ;;; API Functions
843 ;;
844 ;; Once you have a search result, use these routines to operate
845 ;; on the search results at a higher level
846
847 ;;;###autoload
848 (defun semanticdb-strip-find-results (results &optional find-file-match)
849 "Strip a semanticdb search RESULTS to exclude objects.
850 This makes it appear more like the results of a `semantic-find-' call.
851 Optional FIND-FILE-MATCH loads all files associated with RESULTS
852 into buffers. This has the side effect of enabling `semantic-tag-buffer' to
853 return a value.
854 If FIND-FILE-MATCH is 'name, then only the filename is stored
855 in each tag instead of loading each file into a buffer.
856 If the input RESULTS are not going to be used again, and if
857 FIND-FILE-MATCH is nil, you can use `semanticdb-fast-strip-find-results'
858 instead."
859 (if find-file-match
860 ;; Load all files associated with RESULTS.
861 (let ((tmp results)
862 (output nil))
863 (while tmp
864 (let ((tab (car (car tmp)))
865 (tags (cdr (car tmp))))
866 (dolist (T tags)
867 ;; Normilzation gives specialty database tables a chance
868 ;; to convert into a more stable tag format.
869 (let* ((norm (semanticdb-normalize-one-tag tab T))
870 (ntab (car norm))
871 (ntag (cdr norm))
872 (nametable ntab))
873
874 ;; If it didn't normalize, use what we had.
875 (if (not norm)
876 (setq nametable tab)
877 (setq output (append output (list ntag))))
878
879 ;; Find-file-match allows a tool to make sure the tag is
880 ;; 'live', somewhere in a buffer.
881 (cond ((eq find-file-match 'name)
882 (let ((f (semanticdb-full-filename nametable)))
883 (semantic--tag-put-property ntag :filename f)))
884 ((and find-file-match ntab)
885 (semanticdb-get-buffer ntab))
886 )
887 ))
888 )
889 (setq tmp (cdr tmp)))
890 output)
891 ;; @todo - I could use nconc, but I don't know what the caller may do with
892 ;; RESULTS after this is called. Right now semantic-complete will
893 ;; recycling the input after calling this routine.
894 (apply #'append (mapcar #'cdr results))))
895
896 (defun semanticdb-fast-strip-find-results (results)
897 "Destructively strip a semanticdb search RESULTS to exclude objects.
898 This makes it appear more like the results of a `semantic-find-' call.
899 This is like `semanticdb-strip-find-results', except the input list RESULTS
900 will be changed."
901 (apply #'nconc (mapcar #'cdr results)))
902
903 (defun semanticdb-find-results-p (resultp)
904 "Non-nil if RESULTP is in the form of a semanticdb search result.
905 This query only really tests the first entry in the list that is RESULTP,
906 but should be good enough for debugging assertions."
907 (and (listp resultp)
908 (listp (car resultp))
909 (semanticdb-abstract-table-child-p (car (car resultp)))
910 (or (semantic-tag-p (car (cdr (car resultp))))
911 (null (car (cdr (car resultp)))))))
912
913 (defun semanticdb-find-result-prin1-to-string (result)
914 "Presuming RESULT satisfies `semanticdb-find-results-p', provide a short PRIN1 output."
915 (if (< (length result) 2)
916 (concat "#<FIND RESULT "
917 (mapconcat (lambda (a)
918 (concat "(" (object-name (car a) ) " . "
919 "#<TAG LIST " (number-to-string (length (cdr a))) ">)"))
920 result
921 " ")
922 ">")
923 ;; Longer results should have an abreviated form.
924 (format "#<FIND RESULT %d TAGS in %d FILES>"
925 (semanticdb-find-result-length result)
926 (length result))))
927
928 (defun semanticdb-find-result-with-nil-p (resultp)
929 "Non-nil of RESULTP is in the form of a semanticdb search result.
930 nil is a valid value where a TABLE usually is, but only if the TAG
931 results include overlays.
932 This query only really tests the first entry in the list that is RESULTP,
933 but should be good enough for debugging assertions."
934 (and (listp resultp)
935 (listp (car resultp))
936 (let ((tag-to-test (car-safe (cdr (car resultp)))))
937 (or (and (semanticdb-abstract-table-child-p (car (car resultp)))
938 (or (semantic-tag-p tag-to-test)
939 (null tag-to-test)))
940 (and (null (car (car resultp)))
941 (or (semantic-tag-with-position-p tag-to-test)
942 (null tag-to-test))))
943 )))
944
945 ;;;###autoload
946 (defun semanticdb-find-result-length (result)
947 "Number of tags found in RESULT."
948 (let ((count 0))
949 (mapc (lambda (onetable)
950 (setq count (+ count (1- (length onetable)))))
951 result)
952 count))
953
954 ;;;###autoload
955 (defun semanticdb-find-result-nth (result n)
956 "In RESULT, return the Nth search result.
957 This is a 0 based search result, with the first match being element 0.
958
959 The returned value is a cons cell: (TAG . TABLE) where TAG
960 is the tag at the Nth position. TABLE is the semanticdb table where
961 the TAG was found. Sometimes TABLE can be nil."
962 (let ((ans nil)
963 (anstable nil))
964 ;; Loop over each single table hit.
965 (while (and (not ans) result)
966 ;; For each table result, get local length, and modify
967 ;; N to be that much less.
968 (let ((ll (length (cdr (car result))))) ;; local length
969 (if (> ll n)
970 ;; We have a local match.
971 (setq ans (nth n (cdr (car result)))
972 anstable (car (car result)))
973 ;; More to go. Decrement N.
974 (setq n (- n ll))))
975 ;; Keep moving.
976 (setq result (cdr result)))
977 (cons ans anstable)))
978
979 (defun semanticdb-find-result-test (result)
980 "Test RESULT by accessing all the tags in the list."
981 (if (not (semanticdb-find-results-p result))
982 (error "Does not pass `semanticdb-find-results-p.\n"))
983 (let ((len (semanticdb-find-result-length result))
984 (i 0))
985 (while (< i len)
986 (let ((tag (semanticdb-find-result-nth result i)))
987 (if (not (semantic-tag-p (car tag)))
988 (error "%d entry is not a tag" i)))
989 (setq i (1+ i)))))
990
991 ;;;###autoload
992 (defun semanticdb-find-result-nth-in-buffer (result n)
993 "In RESULT, return the Nth search result.
994 Like `semanticdb-find-result-nth', except that only the TAG
995 is returned, and the buffer it is found it will be made current.
996 If the result tag has no position information, the originating buffer
997 is still made current."
998 (let* ((ret (semanticdb-find-result-nth result n))
999 (ans (car ret))
1000 (anstable (cdr ret)))
1001 ;; If we have a hit, double-check the find-file
1002 ;; entry. If the file must be loaded, then gat that table's
1003 ;; source file into a buffer.
1004
1005 (if anstable
1006 (let ((norm (semanticdb-normalize-one-tag anstable ans)))
1007 (when norm
1008 ;; The normalized tags can now be found based on that
1009 ;; tags table.
1010 (semanticdb-set-buffer (car norm))
1011 ;; Now reset ans
1012 (setq ans (cdr norm))
1013 ))
1014 )
1015 ;; Return the tag.
1016 ans))
1017
1018 (defun semanticdb-find-result-mapc (fcn result)
1019 "Apply FCN to each element of find RESULT for side-effects only.
1020 FCN takes two arguments. The first is a TAG, and the
1021 second is a DB from whence TAG originated.
1022 Returns result."
1023 (mapc (lambda (sublst)
1024 (mapc (lambda (tag)
1025 (funcall fcn tag (car sublst)))
1026 (cdr sublst)))
1027 result)
1028 result)
1029
1030 ;;; Search Logging
1031 ;;
1032 ;; Basic logging to see what the search routines are doing.
1033 (defvar semanticdb-find-log-flag nil
1034 "Non-nil means log the process of searches.")
1035
1036 (defvar semanticdb-find-log-buffer-name "*SemanticDB Find Log*"
1037 "The name of the logging buffer.")
1038
1039 (defun semanticdb-find-toggle-logging ()
1040 "Toggle semanticdb logging."
1041 (interactive)
1042 (setq semanticdb-find-log-flag (null semanticdb-find-log-flag))
1043 (message "Semanticdb find logging is %sabled"
1044 (if semanticdb-find-log-flag "en" "dis")))
1045
1046 (defun semanticdb-reset-log ()
1047 "Reset the log buffer."
1048 (interactive)
1049 (when semanticdb-find-log-flag
1050 (with-current-buffer (get-buffer-create semanticdb-find-log-buffer-name)
1051 (erase-buffer)
1052 )))
1053
1054 (defun semanticdb-find-log-move-to-end ()
1055 "Move to the end of the semantic log."
1056 (let ((cb (current-buffer))
1057 (cw (selected-window)))
1058 (unwind-protect
1059 (progn
1060 (set-buffer semanticdb-find-log-buffer-name)
1061 (if (get-buffer-window (current-buffer) 'visible)
1062 (select-window (get-buffer-window (current-buffer) 'visible)))
1063 (goto-char (point-max)))
1064 (if cw (select-window cw))
1065 (set-buffer cb))))
1066
1067 (defun semanticdb-find-log-new-search (forwhat)
1068 "Start a new search FORWHAT."
1069 (when semanticdb-find-log-flag
1070 (with-current-buffer (get-buffer-create semanticdb-find-log-buffer-name)
1071 (insert (format "New Search: %S\n" forwhat))
1072 )
1073 (semanticdb-find-log-move-to-end)))
1074
1075 (defun semanticdb-find-log-activity (table result)
1076 "Log that TABLE has been searched and RESULT was found."
1077 (when semanticdb-find-log-flag
1078 (with-current-buffer semanticdb-find-log-buffer-name
1079 (insert "Table: " (object-print table)
1080 " Result: " (int-to-string (length result)) " tags"
1081 "\n")
1082 )
1083 (semanticdb-find-log-move-to-end)))
1084
1085 ;;; Semanticdb find API functions
1086 ;; These are the routines actually used to perform searches.
1087 ;;
1088 (defun semanticdb-find-tags-collector (function &optional path find-file-match
1089 brutish)
1090 "Collect all tags returned by FUNCTION over PATH.
1091 The FUNCTION must take two arguments. The first is TABLE,
1092 which is a semanticdb table containing tags. The second argument
1093 to FUNCTION is TAGS. TAGS may be a list of tags. If TAGS is non-nil, then
1094 FUNCTION should search the TAG list, not through TABLE.
1095
1096 See `semanticdb-find-translate-path' for details on PATH.
1097 FIND-FILE-MATCH indicates that any time a match is found, the file
1098 associated with that tag should be loaded into a buffer.
1099
1100 Note: You should leave FIND-FILE-MATCH as nil. It is far more
1101 efficient to take the results from any search and use
1102 `semanticdb-strip-find-results' instead. This argument is here
1103 for backward compatibility.
1104
1105 If optional argument BRUTISH is non-nil, then ignore include statements,
1106 and search all tables in this project tree."
1107 (let (found match)
1108 (save-excursion
1109 ;; If path is a buffer, set ourselves up in that buffer
1110 ;; so that the override methods work correctly.
1111 (when (bufferp path) (set-buffer path))
1112 (if (semanticdb-find-results-p path)
1113 ;; When we get find results, loop over that.
1114 (dolist (tableandtags path)
1115 (semantic-throw-on-input 'semantic-find-translate-path)
1116 ;; If FIND-FILE-MATCH is non-nil, skip tables of class
1117 ;; `semanticdb-search-results-table', since those are system
1118 ;; databases and not associated with a file.
1119 (unless (and find-file-match
1120 (obj-of-class-p
1121 (car tableandtags) semanticdb-search-results-table))
1122 (when (setq match (funcall function
1123 (car tableandtags) (cdr tableandtags)))
1124 (when find-file-match
1125 (save-excursion (semanticdb-set-buffer (car tableandtags))))
1126 (push (cons (car tableandtags) match) found)))
1127 )
1128 ;; Only log searches across data bases.
1129 (semanticdb-find-log-new-search nil)
1130 ;; If we get something else, scan the list of tables resulting
1131 ;; from translating it into a list of objects.
1132 (dolist (table (semanticdb-find-translate-path path brutish))
1133 (semantic-throw-on-input 'semantic-find-translate-path)
1134 ;; If FIND-FILE-MATCH is non-nil, skip tables of class
1135 ;; `semanticdb-search-results-table', since those are system
1136 ;; databases and not associated with a file.
1137 (unless (and find-file-match
1138 (obj-of-class-p table semanticdb-search-results-table))
1139 (when (and table (setq match (funcall function table nil)))
1140 (semanticdb-find-log-activity table match)
1141 (when find-file-match
1142 (save-excursion (semanticdb-set-buffer table)))
1143 (push (cons table match) found))))))
1144 ;; At this point, FOUND has had items pushed onto it.
1145 ;; This means items are being returned in REVERSE order
1146 ;; of the tables searched, so if you just get th CAR, then
1147 ;; too-bad, you may have some system-tag that has no
1148 ;; buffer associated with it.
1149
1150 ;; It must be reversed.
1151 (nreverse found)))
1152
1153 ;;;###autoload
1154 (defun semanticdb-find-tags-by-name (name &optional path find-file-match)
1155 "Search for all tags matching NAME on PATH.
1156 See `semanticdb-find-translate-path' for details on PATH.
1157 FIND-FILE-MATCH indicates that any time a match is found, the file
1158 associated with that tag should be loaded into a buffer."
1159 (semanticdb-find-tags-collector
1160 (lambda (table tags)
1161 (semanticdb-find-tags-by-name-method table name tags))
1162 path find-file-match))
1163
1164 ;;;###autoload
1165 (defun semanticdb-find-tags-by-name-regexp (regexp &optional path find-file-match)
1166 "Search for all tags matching REGEXP on PATH.
1167 See `semanticdb-find-translate-path' for details on PATH.
1168 FIND-FILE-MATCH indicates that any time a match is found, the file
1169 associated with that tag should be loaded into a buffer."
1170 (semanticdb-find-tags-collector
1171 (lambda (table tags)
1172 (semanticdb-find-tags-by-name-regexp-method table regexp tags))
1173 path find-file-match))
1174
1175 ;;;###autoload
1176 (defun semanticdb-find-tags-for-completion (prefix &optional path find-file-match)
1177 "Search for all tags matching PREFIX on PATH.
1178 See `semanticdb-find-translate-path' for details on PATH.
1179 FIND-FILE-MATCH indicates that any time a match is found, the file
1180 associated with that tag should be loaded into a buffer."
1181 (semanticdb-find-tags-collector
1182 (lambda (table tags)
1183 (semanticdb-find-tags-for-completion-method table prefix tags))
1184 path find-file-match))
1185
1186 ;;;###autoload
1187 (defun semanticdb-find-tags-by-class (class &optional path find-file-match)
1188 "Search for all tags of CLASS on PATH.
1189 See `semanticdb-find-translate-path' for details on PATH.
1190 FIND-FILE-MATCH indicates that any time a match is found, the file
1191 associated with that tag should be loaded into a buffer."
1192 (semanticdb-find-tags-collector
1193 (lambda (table tags)
1194 (semanticdb-find-tags-by-class-method table class tags))
1195 path find-file-match))
1196
1197 ;;; Deep Searches
1198 (defun semanticdb-deep-find-tags-by-name (name &optional path find-file-match)
1199 "Search for all tags matching NAME on PATH.
1200 Search also in all components of top level tags founds.
1201 See `semanticdb-find-translate-path' for details on PATH.
1202 FIND-FILE-MATCH indicates that any time a match is found, the file
1203 associated with that tag should be loaded into a buffer."
1204 (semanticdb-find-tags-collector
1205 (lambda (table tags)
1206 (semanticdb-deep-find-tags-by-name-method table name tags))
1207 path find-file-match))
1208
1209 (defun semanticdb-deep-find-tags-by-name-regexp (regexp &optional path find-file-match)
1210 "Search for all tags matching REGEXP on PATH.
1211 Search also in all components of top level tags founds.
1212 See `semanticdb-find-translate-path' for details on PATH.
1213 FIND-FILE-MATCH indicates that any time a match is found, the file
1214 associated with that tag should be loaded into a buffer."
1215 (semanticdb-find-tags-collector
1216 (lambda (table tags)
1217 (semanticdb-deep-find-tags-by-name-regexp-method table regexp tags))
1218 path find-file-match))
1219
1220 (defun semanticdb-deep-find-tags-for-completion (prefix &optional path find-file-match)
1221 "Search for all tags matching PREFIX on PATH.
1222 Search also in all components of top level tags founds.
1223 See `semanticdb-find-translate-path' for details on PATH.
1224 FIND-FILE-MATCH indicates that any time a match is found, the file
1225 associated with that tag should be loaded into a buffer."
1226 (semanticdb-find-tags-collector
1227 (lambda (table tags)
1228 (semanticdb-deep-find-tags-for-completion-method table prefix tags))
1229 path find-file-match))
1230
1231 ;;; Brutish Search Routines
1232 ;;
1233 (defun semanticdb-brute-deep-find-tags-by-name (name &optional path find-file-match)
1234 "Search for all tags matching NAME on PATH.
1235 See `semanticdb-find-translate-path' for details on PATH.
1236 The argument BRUTISH will be set so that searching includes all tables
1237 in the current project.
1238 FIND-FILE-MATCH indicates that any time a match is found, the file
1239 associated wit that tag should be loaded into a buffer."
1240 (semanticdb-find-tags-collector
1241 (lambda (table tags)
1242 (semanticdb-deep-find-tags-by-name-method table name tags))
1243 path find-file-match t))
1244
1245 (defun semanticdb-brute-deep-find-tags-for-completion (prefix &optional path find-file-match)
1246 "Search for all tags matching PREFIX on PATH.
1247 See `semanticdb-find-translate-path' for details on PATH.
1248 The argument BRUTISH will be set so that searching includes all tables
1249 in the current project.
1250 FIND-FILE-MATCH indicates that any time a match is found, the file
1251 associated wit that tag should be loaded into a buffer."
1252 (semanticdb-find-tags-collector
1253 (lambda (table tags)
1254 (semanticdb-deep-find-tags-for-completion-method table prefix tags))
1255 path find-file-match t))
1256
1257 (defun semanticdb-brute-find-tags-by-class (class &optional path find-file-match)
1258 "Search for all tags of CLASS on PATH.
1259 See `semanticdb-find-translate-path' for details on PATH.
1260 The argument BRUTISH will be set so that searching includes all tables
1261 in the current project.
1262 FIND-FILE-MATCH indicates that any time a match is found, the file
1263 associated with that tag should be loaded into a buffer."
1264 (semanticdb-find-tags-collector
1265 (lambda (table tags)
1266 (semanticdb-find-tags-by-class-method table class tags))
1267 path find-file-match t))
1268
1269 ;;; Specialty Search Routines
1270 (defun semanticdb-find-tags-external-children-of-type
1271 (type &optional path find-file-match)
1272 "Search for all tags defined outside of TYPE w/ TYPE as a parent.
1273 See `semanticdb-find-translate-path' for details on PATH.
1274 FIND-FILE-MATCH indicates that any time a match is found, the file
1275 associated with that tag should be loaded into a buffer."
1276 (semanticdb-find-tags-collector
1277 (lambda (table tags)
1278 (semanticdb-find-tags-external-children-of-type-method table type tags))
1279 path find-file-match))
1280
1281 (defun semanticdb-find-tags-subclasses-of-type
1282 (type &optional path find-file-match)
1283 "Search for all tags of class type defined that subclass TYPE.
1284 See `semanticdb-find-translate-path' for details on PATH.
1285 FIND-FILE-MATCH indicates that any time a match is found, the file
1286 associated with that tag should be loaded into a buffer."
1287 (semanticdb-find-tags-collector
1288 (lambda (table tags)
1289 (semanticdb-find-tags-subclasses-of-type-method table type tags))
1290 path find-file-match t))
1291 \f
1292 ;;; METHODS
1293 ;;
1294 ;; Default methods for semanticdb database and table objects.
1295 ;; Override these with system databases to as new types of back ends.
1296
1297 ;;; Top level Searches
1298 (defmethod semanticdb-find-tags-by-name-method ((table semanticdb-abstract-table) name &optional tags)
1299 "In TABLE, find all occurances of tags with NAME.
1300 Optional argument TAGS is a list of tags to search.
1301 Returns a table of all matching tags."
1302 (semantic-find-tags-by-name name (or tags (semanticdb-get-tags table))))
1303
1304 (defmethod semanticdb-find-tags-by-name-regexp-method ((table semanticdb-abstract-table) regexp &optional tags)
1305 "In TABLE, find all occurances of tags matching REGEXP.
1306 Optional argument TAGS is a list of tags to search.
1307 Returns a table of all matching tags."
1308 (semantic-find-tags-by-name-regexp regexp (or tags (semanticdb-get-tags table))))
1309
1310 (defmethod semanticdb-find-tags-for-completion-method ((table semanticdb-abstract-table) prefix &optional tags)
1311 "In TABLE, find all occurances of tags matching PREFIX.
1312 Optional argument TAGS is a list of tags to search.
1313 Returns a table of all matching tags."
1314 (semantic-find-tags-for-completion prefix (or tags (semanticdb-get-tags table))))
1315
1316 (defmethod semanticdb-find-tags-by-class-method ((table semanticdb-abstract-table) class &optional tags)
1317 "In TABLE, find all occurances of tags of CLASS.
1318 Optional argument TAGS is a list of tags to search.
1319 Returns a table of all matching tags."
1320 (semantic-find-tags-by-class class (or tags (semanticdb-get-tags table))))
1321
1322 (defmethod semanticdb-find-tags-external-children-of-type-method ((table semanticdb-abstract-table) parent &optional tags)
1323 "In TABLE, find all occurances of tags whose parent is the PARENT type.
1324 Optional argument TAGS is a list of tags to search.
1325 Returns a table of all matching tags."
1326 (require 'semantic/find)
1327 (semantic-find-tags-external-children-of-type parent (or tags (semanticdb-get-tags table))))
1328
1329 (defmethod semanticdb-find-tags-subclasses-of-type-method ((table semanticdb-abstract-table) parent &optional tags)
1330 "In TABLE, find all occurances of tags whose parent is the PARENT type.
1331 Optional argument TAGS is a list of tags to search.
1332 Returns a table of all matching tags."
1333 (require 'semantic/find)
1334 (semantic-find-tags-subclasses-of-type parent (or tags (semanticdb-get-tags table))))
1335
1336 ;;; Deep Searches
1337 (defmethod semanticdb-deep-find-tags-by-name-method ((table semanticdb-abstract-table) name &optional tags)
1338 "In TABLE, find all occurances of tags with NAME.
1339 Search in all tags in TABLE, and all components of top level tags in
1340 TABLE.
1341 Optional argument TAGS is a list of tags to search.
1342 Return a table of all matching tags."
1343 (semantic-find-tags-by-name name (semantic-flatten-tags-table (or tags (semanticdb-get-tags table)))))
1344
1345 (defmethod semanticdb-deep-find-tags-by-name-regexp-method ((table semanticdb-abstract-table) regexp &optional tags)
1346 "In TABLE, find all occurances of tags matching REGEXP.
1347 Search in all tags in TABLE, and all components of top level tags in
1348 TABLE.
1349 Optional argument TAGS is a list of tags to search.
1350 Return a table of all matching tags."
1351 (semantic-find-tags-by-name-regexp regexp (semantic-flatten-tags-table (or tags (semanticdb-get-tags table)))))
1352
1353 (defmethod semanticdb-deep-find-tags-for-completion-method ((table semanticdb-abstract-table) prefix &optional tags)
1354 "In TABLE, find all occurances of tags matching PREFIX.
1355 Search in all tags in TABLE, and all components of top level tags in
1356 TABLE.
1357 Optional argument TAGS is a list of tags to search.
1358 Return a table of all matching tags."
1359 (semantic-find-tags-for-completion prefix (semantic-flatten-tags-table (or tags (semanticdb-get-tags table)))))
1360
1361 (provide 'semantic/db-find)
1362
1363 ;; Local variables:
1364 ;; generated-autoload-file: "loaddefs.el"
1365 ;; generated-autoload-load-name: "semantic/db-find"
1366 ;; End:
1367
1368 ;; arch-tag: 5d4162f5-5092-46d7-beed-55c78aab4116
1369 ;;; semantic/db-find.el ends here