db-ebrowse.el 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664
  1. ;;; semantic/db-ebrowse.el --- Semanticdb backend using ebrowse.
  2. ;; Copyright (C) 2005-2012 Free Software Foundation, Inc.
  3. ;; Authors: Eric M. Ludlam <zappo@gnu.org>
  4. ;; Joakim Verona
  5. ;; Keywords: tags
  6. ;; This file is part of GNU Emacs.
  7. ;; GNU Emacs is free software: you can redistribute it and/or modify
  8. ;; it under the terms of the GNU General Public License as published by
  9. ;; the Free Software Foundation, either version 3 of the License, or
  10. ;; (at your option) any later version.
  11. ;; GNU Emacs is distributed in the hope that it will be useful,
  12. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. ;; GNU General Public License for more details.
  15. ;; You should have received a copy of the GNU General Public License
  16. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  17. ;;; Commentary:
  18. ;;
  19. ;; This program was started by Eric Ludlam, and Joakim Verona finished
  20. ;; the implementation by adding searches and fixing bugs.
  21. ;;
  22. ;; Read in custom-created ebrowse BROWSE files into a semanticdb back
  23. ;; end.
  24. ;;
  25. ;; Add these databases to the 'system' search.
  26. ;; Possibly use ebrowse for local parsing too.
  27. ;;
  28. ;; When real details are needed out of the tag system from ebrowse,
  29. ;; we will need to delve into the originating source and parse those
  30. ;; files the usual way.
  31. ;;
  32. ;; COMMANDS:
  33. ;; `semanticdb-create-ebrowse-database' - Call EBROWSE to create a
  34. ;; system database for some directory. In general, use this for
  35. ;; system libraries, such as /usr/include, or include directories
  36. ;; large software projects.
  37. ;; Customize `semanticdb-ebrowse-file-match' to make sure the correct
  38. ;; file extensions are matched.
  39. ;;
  40. ;; `semanticdb-load-ebrowse-caches' - Load all the EBROWSE caches from
  41. ;; your semanticdb system database directory. Once they are
  42. ;; loaded, they become searchable as omnipotent databases for
  43. ;; all C++ files. This is called automatically by semantic-load.
  44. ;; Call it a second time to refresh the Emacs DB with the file.
  45. ;;
  46. (require 'ebrowse)
  47. (require 'semantic)
  48. (require 'semantic/db-file)
  49. (eval-when-compile
  50. ;; For generic function searching.
  51. (require 'eieio)
  52. (require 'eieio-opt)
  53. (require 'semantic/find))
  54. (declare-function semantic-add-system-include "semantic/dep")
  55. ;;; Code:
  56. (defvar semanticdb-ebrowse-default-file-name "BROWSE"
  57. "The EBROWSE file name used for system caches.")
  58. (defcustom semanticdb-ebrowse-file-match "\\.\\(hh?\\|HH?\\|hpp\\)"
  59. "Regular expression matching file names for ebrowse to parse.
  60. This expression should exclude C++ headers that have no extension.
  61. By default, include only headers since the semantic use of EBrowse
  62. is only for searching via semanticdb, and thus only headers would
  63. be searched."
  64. :group 'semanticdb
  65. :type 'string)
  66. ;;; SEMANTIC Database related Code
  67. ;;; Classes:
  68. (defclass semanticdb-table-ebrowse (semanticdb-table)
  69. ((major-mode :initform c++-mode)
  70. (ebrowse-tree :initform nil
  71. :initarg :ebrowse-tree
  72. :documentation
  73. "The raw ebrowse tree for this file."
  74. )
  75. (global-extract :initform nil
  76. :initarg :global-extract
  77. :documentation
  78. "Table of ebrowse tags specific to this file.
  79. This table is composited from the ebrowse *Globals* section.")
  80. )
  81. "A table for returning search results from ebrowse.")
  82. (defclass semanticdb-project-database-ebrowse
  83. (semanticdb-project-database)
  84. ((new-table-class :initform semanticdb-table-ebrowse
  85. :type class
  86. :documentation
  87. "New tables created for this database are of this class.")
  88. (system-include-p :initform nil
  89. :initarg :system-include
  90. :documentation
  91. "Flag indicating this database represents a system include directory.")
  92. (ebrowse-struct :initform nil
  93. :initarg :ebrowse-struct
  94. )
  95. )
  96. "Semantic Database deriving tags using the EBROWSE tool.
  97. EBROWSE is a C/C++ parser for use with `ebrowse' Emacs program.")
  98. (defun semanticdb-ebrowse-C-file-p (file)
  99. "Is FILE a C or C++ file?"
  100. (or (string-match semanticdb-ebrowse-file-match file)
  101. (and (string-match "/\\w+$" file)
  102. (not (file-directory-p file))
  103. (let ((tmp (get-buffer-create "*semanticdb-ebrowse-tmp*")))
  104. (with-current-buffer tmp
  105. (condition-case nil
  106. (insert-file-contents file nil 0 100 t)
  107. (error (insert-file-contents file nil nil nil t)))
  108. (goto-char (point-min))
  109. (looking-at "\\s-*/\\(\\*\\|/\\)")
  110. ))
  111. )))
  112. (defun semanticdb-create-ebrowse-database (dir)
  113. "Create an EBROWSE database for directory DIR.
  114. The database file is stored in ~/.semanticdb, or whichever directory
  115. is specified by `semanticdb-default-save-directory'."
  116. (interactive "DDirectory: ")
  117. (setq dir (file-name-as-directory dir)) ;; for / on end
  118. (let* ((savein (semanticdb-ebrowse-file-for-directory dir))
  119. (filebuff (get-buffer-create "*SEMANTICDB EBROWSE TMP*"))
  120. (files (directory-files (expand-file-name dir) t))
  121. (mma auto-mode-alist)
  122. (regexp nil)
  123. )
  124. ;; Create the input to the ebrowse command
  125. (with-current-buffer filebuff
  126. (buffer-disable-undo filebuff)
  127. (setq default-directory (expand-file-name dir))
  128. ;;; @TODO - convert to use semanticdb-collect-matching-filenames
  129. ;; to get the file names.
  130. (mapc (lambda (f)
  131. (when (semanticdb-ebrowse-C-file-p f)
  132. (insert f)
  133. (insert "\n")))
  134. files)
  135. ;; Cleanup the ebrowse output buffer.
  136. (with-current-buffer (get-buffer-create "*EBROWSE OUTPUT*")
  137. (erase-buffer))
  138. ;; Call the EBROWSE command.
  139. (message "Creating ebrowse file: %s ..." savein)
  140. (call-process-region (point-min) (point-max)
  141. "ebrowse" nil "*EBROWSE OUTPUT*" nil
  142. (concat "--output-file=" savein)
  143. "--very-verbose")
  144. )
  145. ;; Create a short LOADER program for loading in this database.
  146. (let* ((lfn (concat savein "-load.el"))
  147. (lf (find-file-noselect lfn)))
  148. (with-current-buffer lf
  149. (erase-buffer)
  150. (insert "(semanticdb-ebrowse-load-helper \""
  151. (expand-file-name dir)
  152. "\")\n")
  153. (save-buffer)
  154. (kill-buffer (current-buffer)))
  155. (message "Creating ebrowse file: %s ... done" savein)
  156. ;; Reload that database
  157. (load lfn nil t)
  158. )))
  159. (defun semanticdb-load-ebrowse-caches ()
  160. "Load all semanticdb controlled EBROWSE caches."
  161. (interactive)
  162. (let ((f (directory-files semanticdb-default-save-directory
  163. t (concat semanticdb-ebrowse-default-file-name "-load.el$") t)))
  164. (while f
  165. (load (car f) nil t)
  166. (setq f (cdr f)))
  167. ))
  168. (defun semanticdb-ebrowse-load-helper (directory)
  169. "Create the semanticdb database via ebrowse for directory.
  170. If DIRECTORY is found to be defunct, it won't load the DB, and will
  171. warn instead."
  172. (if (file-directory-p directory)
  173. (semanticdb-create-database semanticdb-project-database-ebrowse
  174. directory)
  175. (let* ((BF (semanticdb-ebrowse-file-for-directory directory))
  176. (BFL (concat BF "-load.el"))
  177. (BFLB (concat BF "-load.el~")))
  178. (save-window-excursion
  179. (with-output-to-temp-buffer "*FILES TO DELETE*"
  180. (princ "The following BROWSE files are obsolete.\n\n")
  181. (princ BF)
  182. (princ "\n")
  183. (princ BFL)
  184. (princ "\n")
  185. (when (file-exists-p BFLB)
  186. (princ BFLB)
  187. (princ "\n"))
  188. )
  189. (when (y-or-n-p (format
  190. "Warning: Obsolete BROWSE file for: %s\nDelete? "
  191. directory))
  192. (delete-file BF)
  193. (delete-file BFL)
  194. (when (file-exists-p BFLB)
  195. (delete-file BFLB))
  196. )))))
  197. ;JAVE this just instantiates a default empty ebrowse struct?
  198. ; how would new instances wind up here?
  199. ; the ebrowse class isn't singleton, unlike the emacs lisp one
  200. (defvar-mode-local c++-mode semanticdb-project-system-databases
  201. ()
  202. "Search Ebrowse for symbols.")
  203. (defmethod semanticdb-needs-refresh-p ((table semanticdb-table-ebrowse))
  204. "EBROWSE database do not need to be refreshed.
  205. JAVE: stub for needs-refresh, because, how do we know if BROWSE files
  206. are out of date?
  207. EML: Our database should probably remember the timestamp/checksum of
  208. the most recently read EBROWSE file, and use that."
  209. nil
  210. )
  211. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  212. ;;; EBROWSE code
  213. ;;
  214. ;; These routines deal with part of the ebrowse interface.
  215. (defun semanticdb-ebrowse-file-for-directory (dir)
  216. "Return the file name for DIR where the ebrowse BROWSE file is.
  217. This file should reside in `semanticdb-default-save-directory'."
  218. (let* ((semanticdb-default-save-directory
  219. semanticdb-default-save-directory)
  220. (B (semanticdb-file-name-directory
  221. 'semanticdb-project-database-file
  222. (concat (expand-file-name dir)
  223. semanticdb-ebrowse-default-file-name)))
  224. )
  225. B))
  226. (defun semanticdb-ebrowse-get-ebrowse-structure (dir)
  227. "Return the ebrowse structure for directory DIR.
  228. This assumes semantic manages the BROWSE files, so they are assumed to live
  229. where semantic cache files live, depending on your settings.
  230. For instance: /home/<username>/.semanticdb/!usr!include!BROWSE"
  231. (let* ((B (semanticdb-ebrowse-file-for-directory dir))
  232. (buf (get-buffer-create "*semanticdb ebrowse*")))
  233. (message "semanticdb-ebrowse %s" B)
  234. (when (file-exists-p B)
  235. (set-buffer buf)
  236. (buffer-disable-undo buf)
  237. (erase-buffer)
  238. (insert-file-contents B)
  239. (let ((ans nil)
  240. (efcn (symbol-function 'ebrowse-show-progress)))
  241. (fset 'ebrowse-show-progress #'(lambda (&rest junk) nil))
  242. (unwind-protect ;; Protect against errors w/ ebrowse
  243. (setq ans (list B (ebrowse-read)))
  244. ;; These items must always happen
  245. (erase-buffer)
  246. (fset 'ebrowse-show-fcn efcn)
  247. )
  248. ans))))
  249. ;;; Methods for creating a database or tables
  250. ;;
  251. (defmethod semanticdb-create-database :STATIC ((dbeC semanticdb-project-database-ebrowse)
  252. directory)
  253. "Create a new semantic database for DIRECTORY based on ebrowse.
  254. If there is no database for DIRECTORY available, then
  255. {not implemented yet} create one. Return nil if that is not possible."
  256. ;; MAKE SURE THAT THE FILE LOADED DOESN'T ALREADY EXIST.
  257. (require 'semantic/dep)
  258. (let ((dbs semanticdb-database-list)
  259. (found nil))
  260. (while (and (not found) dbs)
  261. (when (semanticdb-project-database-ebrowse-p (car dbs))
  262. (when (string= (oref (car dbs) reference-directory) directory)
  263. (setq found (car dbs))))
  264. (setq dbs (cdr dbs)))
  265. ;;STATIC means DBE can't be used as object, only as a class
  266. (let* ((ebrowse-data (semanticdb-ebrowse-get-ebrowse-structure directory))
  267. (dat (car (cdr ebrowse-data)))
  268. (ebd (car dat))
  269. (db nil)
  270. (default-directory directory)
  271. )
  272. (if found
  273. (setq db found)
  274. (setq db (make-instance
  275. dbeC
  276. directory
  277. :ebrowse-struct ebd
  278. ))
  279. (oset db reference-directory directory))
  280. ;; Once we recycle or make a new DB, refresh the
  281. ;; contents from the BROWSE file.
  282. (oset db tables nil)
  283. ;; only possible after object creation, tables inited to nil.
  284. (semanticdb-ebrowse-strip-trees db dat)
  285. ;; Once our database is loaded, if we are a system DB, we
  286. ;; add ourselves to the include list for C++.
  287. (semantic-add-system-include directory 'c++-mode)
  288. (semantic-add-system-include directory 'c-mode)
  289. db)))
  290. (defmethod semanticdb-ebrowse-strip-trees ((dbe semanticdb-project-database-ebrowse)
  291. data)
  292. "For the ebrowse database DBE, strip all tables from DATA."
  293. ;JAVE what it actually seems to do is split the original tree in "tables" associated with files
  294. ; im not sure it actually works:
  295. ; the filename slot sometimes gets to be nil,
  296. ; apparently for classes which definition can't be found, yet needs to be included in the tree
  297. ; like library baseclasses
  298. ; a file can define several classes
  299. (let ((T (car (cdr data))));1st comes a header, then the tree
  300. (while T
  301. (let* ((tree (car T))
  302. (class (ebrowse-ts-class tree)); root class of tree
  303. ;; Something funny going on with this file thing...
  304. (filename (or (ebrowse-cs-source-file class)
  305. (ebrowse-cs-file class)))
  306. )
  307. (cond
  308. ((ebrowse-globals-tree-p tree)
  309. ;; We have the globals tree.. save this special.
  310. (semanticdb-ebrowse-add-globals-to-table dbe tree)
  311. )
  312. (t
  313. ;; ebrowse will collect all the info from multiple files
  314. ;; into one tree. Semantic wants all the bits to be tied
  315. ;; into different files. We need to do a full dissociation
  316. ;; into semantic parsable tables.
  317. (semanticdb-ebrowse-add-tree-to-table dbe tree)
  318. ))
  319. (setq T (cdr T))))
  320. ))
  321. ;;; Filename based methods
  322. ;;
  323. (defun semanticdb-ebrowse-add-globals-to-table (dbe tree)
  324. "For database DBE, add the ebrowse TREE into the table."
  325. (if (or (not (ebrowse-ts-p tree))
  326. (not (ebrowse-globals-tree-p tree)))
  327. (signal 'wrong-type-argument (list 'ebrowse-ts-p tree)))
  328. (let* ((class (ebrowse-ts-class tree))
  329. (fname (or (ebrowse-cs-source-file class)
  330. (ebrowse-cs-file class)
  331. ;; Not def'd here, assume our current
  332. ;; file
  333. (concat default-directory "/unknown-proxy.hh")))
  334. (vars (ebrowse-ts-member-functions tree))
  335. (fns (ebrowse-ts-member-variables tree))
  336. (toks nil)
  337. )
  338. (while vars
  339. (let ((nt (semantic-tag (ebrowse-ms-name (car vars))
  340. 'variable))
  341. (defpoint (ebrowse-bs-point class)))
  342. (when defpoint
  343. (semantic--tag-set-overlay nt
  344. (vector defpoint defpoint)))
  345. (setq toks (cons nt toks)))
  346. (setq vars (cdr vars)))
  347. (while fns
  348. (let ((nt (semantic-tag (ebrowse-ms-name (car fns))
  349. 'function))
  350. (defpoint (ebrowse-bs-point class)))
  351. (when defpoint
  352. (semantic--tag-set-overlay nt
  353. (vector defpoint defpoint)))
  354. (setq toks (cons nt toks)))
  355. (setq fns (cdr fns)))
  356. ))
  357. (defun semanticdb-ebrowse-add-tree-to-table (dbe tree &optional fname baseclasses)
  358. "For database DBE, add the ebrowse TREE into the table for FNAME.
  359. Optional argument BASECLASSES specifies a baseclass to the tree being provided."
  360. (if (not (ebrowse-ts-p tree))
  361. (signal 'wrong-type-argument (list 'ebrowse-ts-p tree)))
  362. ;; Strategy overview:
  363. ;; 1) Calculate the filename for this tree.
  364. ;; 2) Find a matching namespace in TAB, or create a new one.
  365. ;; 3) Fabricate a tag proxy for CLASS
  366. ;; 4) Add it to the namespace
  367. ;; 5) Add subclasses
  368. ;; 1 - Find the filename
  369. (if (not fname)
  370. (setq fname (or (ebrowse-cs-source-file (ebrowse-ts-class tree))
  371. (ebrowse-cs-file (ebrowse-ts-class tree))
  372. ;; Not def'd here, assume our current
  373. ;; file
  374. (concat default-directory "/unknown-proxy.hh"))))
  375. (let* ((tab (or (semanticdb-file-table dbe fname)
  376. (semanticdb-create-table dbe fname)))
  377. (class (ebrowse-ts-class tree))
  378. (scope (ebrowse-cs-scope class))
  379. (ns (when scope (split-string scope ":" t)))
  380. (nst nil)
  381. (cls nil)
  382. )
  383. ;; 2 - Get the namespace tag
  384. (when ns
  385. (let ((taglst (if (slot-boundp tab 'tags) (oref tab tags) nil)))
  386. (setq nst (semantic-find-first-tag-by-name (car ns) taglst))
  387. (when (not nst)
  388. (setq nst (semantic-tag (car ns) 'type :type "namespace"))
  389. (oset tab tags (cons nst taglst))
  390. )))
  391. ;; 3 - Create a proxy tg.
  392. (setq cls (semantic-tag (ebrowse-cs-name class)
  393. 'type
  394. :type "class"
  395. :superclasses baseclasses
  396. :faux t
  397. :filename fname
  398. ))
  399. (let ((defpoint (ebrowse-bs-point class)))
  400. (when defpoint
  401. (semantic--tag-set-overlay cls
  402. (vector defpoint defpoint))))
  403. ;; 4 - add to namespace
  404. (if nst
  405. (semantic-tag-put-attribute
  406. nst :members (cons cls (semantic-tag-get-attribute nst :members)))
  407. (oset tab tags (cons cls (when (slot-boundp tab 'tags)
  408. (oref tab tags)))))
  409. ;; 5 - Subclasses
  410. (let* ((subclass (ebrowse-ts-subclasses tree))
  411. (pname (ebrowse-cs-name class)))
  412. (when (ebrowse-cs-scope class)
  413. (setq pname (concat (mapconcat (lambda (a) a) (cdr ns) "::") "::" pname)))
  414. (while subclass
  415. (let* ((scc (ebrowse-ts-class (car subclass)))
  416. (fname (or (ebrowse-cs-source-file scc)
  417. (ebrowse-cs-file scc)
  418. ;; Not def'd here, assume our current
  419. ;; file
  420. fname
  421. )))
  422. (when fname
  423. (semanticdb-ebrowse-add-tree-to-table
  424. dbe (car subclass) fname pname)))
  425. (setq subclass (cdr subclass))))
  426. ))
  427. ;;;
  428. ;; Overload for converting the simple faux tag into something better.
  429. ;;
  430. (defmethod semanticdb-normalize-tags ((obj semanticdb-table-ebrowse) tags)
  431. "Convert in Ebrowse database OBJ a list of TAGS into a complete tag.
  432. The default tag provided by searches exclude many features of a
  433. semantic parsed tag. Look up the file for OBJ, and match TAGS
  434. against a semantic parsed tag that has all the info needed, and
  435. return that."
  436. (let ((tagret nil)
  437. )
  438. ;; SemanticDB will automatically create a regular database
  439. ;; on top of the file just loaded by ebrowse during the set
  440. ;; buffer. Fetch that table, and use it's tag list to look
  441. ;; up the tag we just got, and thus turn it into a full semantic
  442. ;; tag.
  443. (while tags
  444. (let ((tag (car tags)))
  445. (save-excursion
  446. (semanticdb-set-buffer obj)
  447. (let ((ans nil))
  448. ;; Gee, it would be nice to do this, but ebrowse LIES. Oi.
  449. (when (semantic-tag-with-position-p tag)
  450. (goto-char (semantic-tag-start tag))
  451. (let ((foundtag (semantic-current-tag)))
  452. ;; Make sure the discovered tag is the same as what we started with.
  453. (when (string= (semantic-tag-name tag)
  454. (semantic-tag-name foundtag))
  455. ;; We have a winner!
  456. (setq ans foundtag))))
  457. ;; Sometimes ebrowse lies. Do a generic search
  458. ;; to find it within this file.
  459. (when (not ans)
  460. ;; We might find multiple hits for this tag, and we have no way
  461. ;; of knowing which one the user wanted. Return the first one.
  462. (setq ans (semantic-deep-find-tags-by-name
  463. (semantic-tag-name tag)
  464. (semantic-fetch-tags))))
  465. (if (semantic-tag-p ans)
  466. (setq tagret (cons ans tagret))
  467. (setq tagret (append ans tagret)))
  468. ))
  469. (setq tags (cdr tags))))
  470. tagret))
  471. (defmethod semanticdb-normalize-one-tag ((obj semanticdb-table-ebrowse) tag)
  472. "Convert in Ebrowse database OBJ one TAG into a complete tag.
  473. The default tag provided by searches exclude many features of a
  474. semantic parsed tag. Look up the file for OBJ, and match TAG
  475. against a semantic parsed tag that has all the info needed, and
  476. return that."
  477. (let ((tagret nil)
  478. (objret nil))
  479. ;; SemanticDB will automatically create a regular database
  480. ;; on top of the file just loaded by ebrowse during the set
  481. ;; buffer. Fetch that table, and use it's tag list to look
  482. ;; up the tag we just got, and thus turn it into a full semantic
  483. ;; tag.
  484. (save-excursion
  485. (semanticdb-set-buffer obj)
  486. (setq objret semanticdb-current-table)
  487. (when (not objret)
  488. ;; What to do??
  489. (debug))
  490. (let ((ans nil))
  491. ;; Gee, it would be nice to do this, but ebrowse LIES. Oi.
  492. (when (semantic-tag-with-position-p tag)
  493. (goto-char (semantic-tag-start tag))
  494. (let ((foundtag (semantic-current-tag)))
  495. ;; Make sure the discovered tag is the same as what we started with.
  496. (when (string= (semantic-tag-name tag)
  497. (semantic-tag-name foundtag))
  498. ;; We have a winner!
  499. (setq ans foundtag))))
  500. ;; Sometimes ebrowse lies. Do a generic search
  501. ;; to find it within this file.
  502. (when (not ans)
  503. ;; We might find multiple hits for this tag, and we have no way
  504. ;; of knowing which one the user wanted. Return the first one.
  505. (setq ans (semantic-deep-find-tags-by-name
  506. (semantic-tag-name tag)
  507. (semantic-fetch-tags))))
  508. (if (semantic-tag-p ans)
  509. (setq tagret ans)
  510. (setq tagret (car ans)))
  511. ))
  512. (cons objret tagret)))
  513. ;;; Search Overrides
  514. ;;
  515. ;; NOTE WHEN IMPLEMENTING: Be sure to add doc-string updates explaining
  516. ;; how your new search routines are implemented.
  517. ;;
  518. (defmethod semanticdb-find-tags-by-name-method
  519. ((table semanticdb-table-ebrowse) name &optional tags)
  520. "Find all tags named NAME in TABLE.
  521. Return a list of tags."
  522. ;;(message "semanticdb-find-tags-by-name-method name -- %s" name)
  523. (if tags
  524. ;; If TAGS are passed in, then we don't need to do work here.
  525. (call-next-method)
  526. ;; If we ever need to do something special, add here.
  527. ;; Since ebrowse tags are converted into semantic tags, we can
  528. ;; get away with this sort of thing.
  529. (call-next-method)
  530. )
  531. )
  532. (defmethod semanticdb-find-tags-by-name-regexp-method
  533. ((table semanticdb-table-ebrowse) regex &optional tags)
  534. "Find all tags with name matching REGEX in TABLE.
  535. Optional argument TAGS is a list of tags to search.
  536. Return a list of tags."
  537. (if tags (call-next-method)
  538. ;; YOUR IMPLEMENTATION HERE
  539. (call-next-method)
  540. ))
  541. (defmethod semanticdb-find-tags-for-completion-method
  542. ((table semanticdb-table-ebrowse) prefix &optional tags)
  543. "In TABLE, find all occurrences of tags matching PREFIX.
  544. Optional argument TAGS is a list of tags to search.
  545. Returns a table of all matching tags."
  546. (if tags (call-next-method)
  547. ;; YOUR IMPLEMENTATION HERE
  548. (call-next-method)
  549. ))
  550. (defmethod semanticdb-find-tags-by-class-method
  551. ((table semanticdb-table-ebrowse) class &optional tags)
  552. "In TABLE, find all occurrences of tags of CLASS.
  553. Optional argument TAGS is a list of tags to search.
  554. Returns a table of all matching tags."
  555. (if tags (call-next-method)
  556. (call-next-method)))
  557. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  558. ;;; Deep Searches
  559. ;;
  560. ;; If your language does not have a `deep' concept, these can be left
  561. ;; alone, otherwise replace with implementations similar to those
  562. ;; above.
  563. ;;
  564. (defmethod semanticdb-deep-find-tags-by-name-method
  565. ((table semanticdb-table-ebrowse) name &optional tags)
  566. "Find all tags name NAME in TABLE.
  567. Optional argument TAGS is a list of tags to search.
  568. Like `semanticdb-find-tags-by-name-method' for ebrowse."
  569. ;;(semanticdb-find-tags-by-name-method table name tags)
  570. (call-next-method))
  571. (defmethod semanticdb-deep-find-tags-by-name-regexp-method
  572. ((table semanticdb-table-ebrowse) regex &optional tags)
  573. "Find all tags with name matching REGEX in TABLE.
  574. Optional argument TAGS is a list of tags to search.
  575. Like `semanticdb-find-tags-by-name-method' for ebrowse."
  576. ;;(semanticdb-find-tags-by-name-regexp-method table regex tags)
  577. (call-next-method))
  578. (defmethod semanticdb-deep-find-tags-for-completion-method
  579. ((table semanticdb-table-ebrowse) prefix &optional tags)
  580. "In TABLE, find all occurrences of tags matching PREFIX.
  581. Optional argument TAGS is a list of tags to search.
  582. Like `semanticdb-find-tags-for-completion-method' for ebrowse."
  583. ;;(semanticdb-find-tags-for-completion-method table prefix tags)
  584. (call-next-method))
  585. ;;; Advanced Searches
  586. ;;
  587. (defmethod semanticdb-find-tags-external-children-of-type-method
  588. ((table semanticdb-table-ebrowse) type &optional tags)
  589. "Find all nonterminals which are child elements of TYPE
  590. Optional argument TAGS is a list of tags to search.
  591. Return a list of tags."
  592. (if tags (call-next-method)
  593. ;; Ebrowse collects all this type of stuff together for us.
  594. ;; but we can't use it.... yet.
  595. nil
  596. ))
  597. (provide 'semantic/db-ebrowse)
  598. ;;; semantic/db-ebrowse.el ends here