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