1
1
;;; semanticdb-find.el --- Searching through semantic databases.
3
;;; Copyright (C) 2000, 2001, 2002, 2003, 2004 Eric M. Ludlam
3
;;; Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005 Eric M. Ludlam
5
5
;; Author: Eric M. Ludlam <zappo@gnu.org>
7
;; X-RCS: $Id: semanticdb-find.el,v 1.20 2004/07/30 17:57:58 zappo Exp $
7
;; X-RCS: $Id: semanticdb-find.el,v 1.27 2005/06/30 01:26:25 zappo Exp $
9
9
;; This file is not part of GNU Emacs.
32
32
;; These searches scan a database table collection for tags based
35
;; Basic Brute Search:
35
;; Basic Attribute Search:
36
36
;; These searches allow searching on specific attributes of tags,
37
37
;; such as name, type, or other attribute.
44
44
;; The reason for advanced searches are so that external
45
45
;; repositories such as the Emacs obarray, or java .class files can
46
46
;; quickly answer these needed questions without dumping the entire
47
;; symbol list into Emacs for a regular semanticdb search.
49
;; Generic Brute Search:
50
;; The generic search, `semanticdb-find-nonterminal-by-function'
47
;; symbol list into Emacs for additional refinement searches via
48
;; regular semanticdb search.
52
50
;; How databases are decided upon is another important aspect of a
53
51
;; database search. When it comes to searching for a name, there are
57
55
;; Basic search means that tags looking for a given name start
58
56
;; with a specific search path. Names are sought on that path
59
57
;; until it is empty or items on the path can no longer be found.
58
;; Use `semanticdb-dump-all-table-summary' to test this list.
59
;; Use `semanticdb-find-throttle-custom-list' to refine this list.
62
;; A deep search will search more than just the global namespace.
63
;; It will recurse into tags that contain more tags, and search
62
67
;; Brute search means that all tables in all databases in a given
85
90
;; tag - Get that tag's buffer of file file. See above.
86
91
;; table - Search that table, and it's include list.
95
;; Semanticdb returns the results in a specific format. There are a
96
;; series of routines for using those results, and results can be
97
;; passed in as a search-path for refinement searches with
98
;; semanticdb. Apropos for semanticdb.*find-result for more.
90
102
;; Here are applications where different searches are needed which
93
105
;; eldoc - popup help
94
106
;; => Requires basic search using default path. (Header files ok)
95
107
;; tag jump - jump to a named tag
96
;; => Requires a brute search useing whole project. (Source files only)
108
;; => Requires a brute search useing whole project. (Source files only)
97
109
;; completion - Completing symbol names in a smart way
98
110
;; => Basic search (headers ok)
99
111
;; type analysis - finding type definitions for variables & fcns
108
120
(require 'semanticdb)
123
(defvar semanticdb-find-throttle-custom-list
124
'(repeat (radio (const 'local)
129
(const 'omniscience)))
130
"Customization values for semanticdb find throttle.
131
See `semanticdb-find-throttle' for details.")
133
(defcustom semanticdb-find-default-throttle '(project system recursive)
134
"The default throttle for `semanticdb-find' routines.
135
The throttle controls how detailed the list of database
136
tables is for a symbol lookup. The value is a list with
138
`file' - The file the search is being performed from.
139
This option is here for completeness only, and
140
is assumed to always be on.
141
`local' - Tables from the same local directory are included.
142
This includes files directly referenced by a file name
143
which might be in a different directory.
144
`project' - Tables from the same local project are included
145
If `project' is specified, then `local' is assumed.
146
`unloaded' - If a table is not in memory, load it. If it is not cached
147
on disk either, get the source, parse it, and create
149
`system' - Tables from system databases. These are specifically
150
tables from system header files, or language equivalent.
151
`recursive' - For include based searches, includes tables referenced
153
`omniscience' - Included system databases which are omniscience, or
154
somehow know everything. Omniscience databases are found
155
in `semanticdb-project-system-databases'.
156
The Emacs Lisp system DB is an omniscience database."
158
:type semanticdb-find-throttle-custom-list)
160
(defun semanticdb-find-throttle-active-p (access-type)
161
"Non-nil if ACCESS-TYPE is an active throttle type."
162
(or (memq access-type semanticdb-find-default-throttle)
163
(eq access-type 'file)
164
(and (eq access-type 'local)
165
(memq 'project semanticdb-find-default-throttle))
112
168
;;; Path Translations
114
170
;;; OVERLOAD Functions
173
229
(lambda (db) (semanticdb-get-database-tables db))
175
231
;; This should scan the current project directory list for all
176
;; semanticdb files, perhaps hadding proxies for them.
232
;; semanticdb files, perhaps handling proxies for them.
177
233
(semanticdb-current-database-list (oref basedb reference-directory)))))
200
256
;; Add to list of tables
201
257
(push nexttable matchedtables)
202
258
;; Queue new includes to list
203
(setq includetags (append includetags
204
(semantic-find-tags-included
205
(semanticdb-get-tags nexttable)))))
259
(if (semanticdb-find-throttle-active-p 'recursive)
260
(setq includetags (append includetags
261
(semantic-find-tags-included
262
(semanticdb-get-tags nexttable))))))
206
263
(setq includetags (cdr includetags)))
207
264
(nreverse matchedtables)))
218
275
(defun semanticdb-find-table-for-include-default (includetag &optional table)
219
276
"Default implementation of `semanticdb-find-table-for-include'.
220
277
Uses `semanticdb-current-database-list' as the search path.
221
INCLUDETAG and TABLE are documented in `semanticdb-find-table-for-include'."
278
INCLUDETAG and TABLE are documented in `semanticdb-find-table-for-include'.
279
Included databases are filtered based on `semanticdb-find-default-throttle'."
222
280
(if (not (eq (semantic-tag-class includetag) 'include))
223
281
(signal 'wrong-type-argument (list includetag 'include)))
232
290
;; Relative path name
233
((file-exists-p (expand-file-name name))
291
((and (file-exists-p (expand-file-name name))
292
(semanticdb-find-throttle-active-p 'local))
234
293
(setq ans (semanticdb-file-table-object name)))
236
295
;; On the path somewhere
237
;;;; THIS NEEDS WORK!
238
296
;;;; NOTES: Separate system includes from local includes.
239
297
;;;; Use only system databases for system includes.
240
;((setq tmp (semantic-dependency-tag-file includetag))
241
; (setq ans (semanticdb-file-table-object tmp))
242
;; If we don't load this, then finding include tags within
243
;; the table could fail!
244
;; (when ans (save-excursion (semanticdb-set-buffer ans)))
298
((and (setq tmp (semantic-dependency-tag-file includetag))
299
(semanticdb-find-throttle-active-p 'system))
300
(let ((db (semanticdb-directory-loaded-p (file-name-directory tmp))))
302
;; We have a database, but perhaps not a table?
303
(setq ans (semanticdb-file-table db tmp))
304
;; ELSE: we could load a cache if it isn't already loaded
305
;; based on another throttle value.
310
;; The file is not i memory!
311
;; Should we force it to be loaded in?
312
(if (semanticdb-find-throttle-active-p 'unloaded)
314
(setq ans (semanticdb-file-table-object tmp))
316
;; We are not allowed to return the discovered
317
;; answer if the throttle is set low.
319
((semanticdb-find-throttle-active-p 'project)
247
320
;; Somewhere in our project hierarchy
248
321
;; Remember: Roots includes system databases which can create
249
322
;; specialized tables we can search.
261
334
(setq ans (semanticdb-file-table-object fname)))
262
335
;; No reference directory Probably a system database
263
336
;; NOTE: Systemdb will need to override `semanticdb-file-table'.
264
(setq ans (semanticdb-file-table
266
;; Use name direct from tag. System DB will expect it
267
;; in the original form.
268
(semantic-tag-name includetag)))))
337
(if (semanticdb-find-throttle-active-p 'omniscience)
338
(setq ans (semanticdb-file-table
340
;; Use name direct from tag. System DB will expect it
341
;; in the original form.
342
(semantic-tag-name includetag))))))
270
344
(setq roots (cdr roots))))
349
;;; Perform interactive tests on the path/search mechanisms.
351
(defun semanticdb-find-test-translate-path (&optional arg)
352
"Call and output results of `semanticdb-find-translate-path'.
353
With ARG non-nil, specify a BRUTISH translation.
354
See `semanticdb-find-default-throttle' and `semanticdb-project-roots'
355
for details on how this list is derived."
357
(let ((p (semanticdb-find-translate-path nil arg)))
359
(message "%d paths found." (length p))
360
(with-output-to-temp-buffer "*Translated Path*"
364
(princ (semanticdb-full-filename (car p)))
366
(prin1 (length (oref (car p) tags)))
368
(let ((parent (oref (car p) parent-db)))
371
(princ (object-name parent))))
373
(no-method-definition
374
(princ (semanticdb-printable-name (car p)))))
275
380
;;; FIND results and edebug
277
382
(eval-after-load "cedet-edebug"
290
395
(defun semanticdb-strip-find-results (results &optional find-file-match)
291
396
"Strip a semanticdb search RESULTS to exclude objects.
292
397
This makes it appear more like the results of a `semantic-find-' call.
293
Optional FIND-FILE-MATCH is not yet implemented."
398
Optional FIND-FILE-MATCH loads all files associated with RESULTS
399
into buffers. This has the side effect of enabling `semantic-tag-buffer' to
401
(when find-file-match
402
;; Load all files associated with RESULTS.
405
(semanticdb-get-buffer (car (car tmp)))
406
(setq tmp (cdr tmp)))))
294
407
(apply #'append (mapcar #'cdr results)))
296
409
(defun semanticdb-find-results-p (resultp)
372
485
(let ((tag (semanticdb-find-result-nth result i)))
373
486
(if (not (semantic-tag-p (car tag)))
374
(error "%d entry is not a tag." i)))
487
(error "%d entry is not a tag" i)))
375
488
(setq i (1+ i)))))
377
490
(defun semanticdb-find-result-nth-in-buffer (result n)
498
611
(when find-file-match
499
612
(save-excursion (semanticdb-set-buffer table)))
500
613
(push (cons table match) found))))))
614
;; At this point, FOUND has had items pushed onto it.
615
;; This means items are being returned in REVERSE order
616
;; of the tables searched, so if you just get th CAR, then
617
;; too-bad, you may have some system-tag that has no
618
;; buffer associated with it.
620
;; It must be reversed.
504
624
(defun semanticdb-find-tags-by-name (name &optional path find-file-match)