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