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