~ubuntu-branches/ubuntu/karmic/cedet/karmic

« back to all changes in this revision

Viewing changes to semantic/semanticdb-find.el

  • Committer: Bazaar Package Importer
  • Author(s): Masayuki Hatta (mhatta)
  • Date: 2006-10-17 05:51:33 UTC
  • mfrom: (2.1.1 dapper)
  • Revision ID: james.westby@ubuntu.com-20061017055133-dlxjfrmuevx5p7uw
Tags: 1:1.0pre3-6
Made Depends to Pre-Depends in cedet-common.  Let's see what happens.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
;;; semanticdb-find.el --- Searching through semantic databases.
2
2
 
3
 
;;; Copyright (C) 2000, 2001, 2002, 2003, 2004 Eric M. Ludlam
 
3
;;; Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005 Eric M. Ludlam
4
4
 
5
5
;; Author: Eric M. Ludlam <zappo@gnu.org>
6
6
;; Keywords: tags
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 $
8
8
 
9
9
;; This file is not part of GNU Emacs.
10
10
 
32
32
;;    These searches scan a database table  collection for tags based
33
33
;;    on name.
34
34
;;
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.
38
38
;;
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.
48
 
;;
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.
51
49
;;
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.
 
60
;;
 
61
;;   Deep Search:
 
62
;;    A deep search will search more than just the global namespace.
 
63
;;    It will recurse into tags that contain more tags, and search
 
64
;;    those too.
60
65
;;
61
66
;;   Brute 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.
87
92
;;
 
93
;; Search Results:
 
94
;;
 
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.
 
99
;;
88
100
;; Application:
89
101
;;
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)
109
121
 
110
122
;;; Code:
111
 
 
 
123
(defvar semanticdb-find-throttle-custom-list
 
124
  '(repeat (radio (const 'local)
 
125
                  (const 'project)
 
126
                  (const 'unloaded)
 
127
                  (const 'system)
 
128
                  (const 'recursive)
 
129
                  (const 'omniscience)))
 
130
  "Customization values for semanticdb find throttle.
 
131
See `semanticdb-find-throttle' for details.")
 
132
 
 
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
 
137
the following keys:
 
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
 
148
                 the table.
 
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
 
152
                 by included files.
 
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."
 
157
  :group 'semanticdb
 
158
  :type semanticdb-find-throttle-custom-list)
 
159
 
 
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))
 
166
      ))
 
167
        
112
168
;;; Path Translations
113
169
;;
114
170
;;; OVERLOAD Functions
173
229
      (lambda (db) (semanticdb-get-database-tables db))
174
230
      ;; FIXME:
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)))))
178
234
  )
179
235
 
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)))
208
265
 
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)))
224
282
 
230
288
        (ans nil))
231
289
    (cond
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)))
235
294
 
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)))
245
 
     ;;  )
246
 
     (t
 
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))))
 
301
        (if db
 
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.
 
306
          )
 
307
        (if ans
 
308
            ;; We are A-ok!
 
309
            nil
 
310
          ;; The file is not i memory!
 
311
          ;; Should we force it to be loaded in?
 
312
          (if (semanticdb-find-throttle-active-p 'unloaded)
 
313
              (progn
 
314
                (setq ans (semanticdb-file-table-object tmp))
 
315
                )
 
316
            ;; We are not allowed to return the discovered
 
317
            ;; answer if the throttle is set low.
 
318
            (setq ans nil)))))
 
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
265
 
                       (car roots)
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
 
339
                           (car roots)
 
340
                           ;; Use name direct from tag.  System DB will expect it
 
341
                           ;; in the original form.
 
342
                           (semantic-tag-name includetag))))))
269
343
 
270
344
        (setq roots (cdr roots))))
271
345
     )
272
346
    ans))
273
347
 
274
348
 
 
349
;;; Perform interactive tests on the path/search mechanisms.
 
350
;;
 
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."
 
356
  (interactive "P")
 
357
  (let ((p (semanticdb-find-translate-path nil arg)))
 
358
    ;; Output the result
 
359
    (message "%d paths found." (length p))
 
360
    (with-output-to-temp-buffer "*Translated Path*"
 
361
      (while p
 
362
        (condition-case nil
 
363
            (progn
 
364
              (princ (semanticdb-full-filename (car p)))
 
365
              (princ ": ")
 
366
              (prin1 (length (oref (car p) tags)))
 
367
              (princ " tags")
 
368
              (let ((parent (oref (car p) parent-db)))
 
369
                (when parent
 
370
                  (princ " : ")
 
371
                  (princ (object-name parent))))
 
372
              )
 
373
          (no-method-definition
 
374
           (princ (semanticdb-printable-name (car p)))))
 
375
        (princ "\n")
 
376
        (setq p (cdr p)))
 
377
      )
 
378
    ))
 
379
 
275
380
;;; FIND results and edebug
276
381
;;
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
 
400
return a value."
 
401
  (when find-file-match
 
402
    ;; Load all files associated with RESULTS.
 
403
    (let ((tmp results))
 
404
      (while tmp
 
405
        (semanticdb-get-buffer (car (car tmp)))
 
406
        (setq tmp (cdr tmp)))))
294
407
  (apply #'append (mapcar #'cdr results)))
295
408
 
296
409
(defun semanticdb-find-results-p (resultp)
371
484
    (while (< i len)
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)))))
376
489
 
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))))))
501
 
    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.
 
619
 
 
620
    ;; It must be reversed.
 
621
    (nreverse found)))
502
622
 
503
623
;;;###autoload
504
624
(defun semanticdb-find-tags-by-name (name &optional path find-file-match)