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