2021-03-15 00:08:34 -04:00
|
|
|
;;; semantic/db-ref.el --- Handle cross-db file references -*- lexical-binding: t; -*-
|
2009-08-28 19:18:35 +00:00
|
|
|
|
2022-01-01 02:45:51 -05:00
|
|
|
;; Copyright (C) 2007-2022 Free Software Foundation, Inc.
|
2009-08-28 19:18:35 +00:00
|
|
|
|
2019-05-26 00:58:28 -07:00
|
|
|
;; Author: Eric M. Ludlam <zappo@gnu.org>
|
2009-08-28 19:18:35 +00:00
|
|
|
|
|
|
|
;; This file is part of GNU Emacs.
|
|
|
|
|
|
|
|
;; GNU Emacs is free software: you can redistribute it and/or modify
|
|
|
|
;; it under the terms of the GNU General Public License as published by
|
|
|
|
;; the Free Software Foundation, either version 3 of the License, or
|
|
|
|
;; (at your option) any later version.
|
|
|
|
|
|
|
|
;; GNU Emacs is distributed in the hope that it will be useful,
|
|
|
|
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
;; GNU General Public License for more details.
|
|
|
|
|
|
|
|
;; You should have received a copy of the GNU General Public License
|
2017-09-13 15:52:52 -07:00
|
|
|
;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
|
2009-08-28 19:18:35 +00:00
|
|
|
|
|
|
|
;;; Commentary:
|
|
|
|
;;
|
|
|
|
;; Handle cross-database file references.
|
|
|
|
;;
|
|
|
|
;; Any given database may be referred to by some other database. For
|
|
|
|
;; example, if a .cpp file has a #include in a header, then that
|
|
|
|
;; header file should have a reference to the .cpp file that included
|
|
|
|
;; it.
|
|
|
|
;;
|
|
|
|
;; This is critical for purposes where a file (such as a .cpp file)
|
|
|
|
;; needs to have its caches flushed because of changes in the
|
|
|
|
;; header. Changing a header may cause a referring file to be
|
|
|
|
;; reparsed due to account for changes in defined macros, or perhaps
|
|
|
|
;; a change to files the header includes.
|
|
|
|
|
|
|
|
|
|
|
|
;;; Code:
|
cedet/semantic/db-debug.el: Don't require semantic/db-mode, since
semanticdb-current-database and semanticdb-current-table are now in
semantic/db.el.
cedet/semantic/db-ebrowse.el: Don't require semantic/db-mode, since
semanticdb-current-database and semanticdb-current-table are now in
semantic/db.el.
cedet/semantic/db-el.el: Require semantic/lex-spp.
Require semantic/db instead of semantic/db-search.
cedet/semantic/db-file.el: Declare inversion-test and
data-debug-insert-thing.
(semanticdb-load-database): Load inversion only if necessary.
cedet/semantic/db-find.el: Autoload semanticdb-find-default-throttle.
Defvar data-debug-thing-alist, and ede-current-project.
Declare data-debug-insert-stuff-list, data-debug-insert-tag-list,
semantic-scope-reset-cache, and semanticdb-typecache-notify-reset.
Require semantic/tag-file, and semantic/sort.
(semantic-reset): Require semantic/scope.
(semanticdb-partial-synchronize): Require semantic/db-typecache.
(semanticdb-find-table-for-include) Move up to avoid compiler warning.
cedet/semantic/db-global.el: Declare data-debug-new-buffer and
data-debug-insert-thing.
(semanticdb-project-database-global) Move up to avoid compiler warning.
cedet/semantic/db-javascript.el: Fix provide statement.
Require semantic/db-find instead of semantic/db-search.
cedet/semantic/db-mode.el: Declare semantic-lex-spp-set-dynamic-table.
(semanticdb-current-database, semanticdb-current-table): Move into
semantic/db.el
cedet/semantic/db-ref.el: Require eieio, semantic/db, and semantic/util.
Declare data-debug-new-buffer and data-debug-insert-object-slots.
Defvar semantic-case-fold. Require semantic/find when compiling.
cedet/semantic/db-typecache.el: Require semantic/tag-ls,
semantic/analyze/fcn, and semantic/scope. Declare
data-debug-insert-thing and data-debug-new-buffer.
cedet/semantic/db.el (semanticdb-search-results-table): Move class
definition here from semantic/db-search.el.
(semanticdb-current-database, semanticdb-current-table) Move variable
definitions here from semantic/db-mode.el.
2009-08-31 00:45:41 +00:00
|
|
|
(require 'eieio)
|
2015-02-04 13:49:49 -05:00
|
|
|
(require 'cl-generic)
|
2009-09-02 04:37:10 +00:00
|
|
|
(require 'semantic)
|
2009-09-05 23:04:46 +00:00
|
|
|
(require 'semantic/db)
|
2009-09-02 04:37:10 +00:00
|
|
|
(require 'semantic/tag)
|
cedet/semantic/db-debug.el: Don't require semantic/db-mode, since
semanticdb-current-database and semanticdb-current-table are now in
semantic/db.el.
cedet/semantic/db-ebrowse.el: Don't require semantic/db-mode, since
semanticdb-current-database and semanticdb-current-table are now in
semantic/db.el.
cedet/semantic/db-el.el: Require semantic/lex-spp.
Require semantic/db instead of semantic/db-search.
cedet/semantic/db-file.el: Declare inversion-test and
data-debug-insert-thing.
(semanticdb-load-database): Load inversion only if necessary.
cedet/semantic/db-find.el: Autoload semanticdb-find-default-throttle.
Defvar data-debug-thing-alist, and ede-current-project.
Declare data-debug-insert-stuff-list, data-debug-insert-tag-list,
semantic-scope-reset-cache, and semanticdb-typecache-notify-reset.
Require semantic/tag-file, and semantic/sort.
(semantic-reset): Require semantic/scope.
(semanticdb-partial-synchronize): Require semantic/db-typecache.
(semanticdb-find-table-for-include) Move up to avoid compiler warning.
cedet/semantic/db-global.el: Declare data-debug-new-buffer and
data-debug-insert-thing.
(semanticdb-project-database-global) Move up to avoid compiler warning.
cedet/semantic/db-javascript.el: Fix provide statement.
Require semantic/db-find instead of semantic/db-search.
cedet/semantic/db-mode.el: Declare semantic-lex-spp-set-dynamic-table.
(semanticdb-current-database, semanticdb-current-table): Move into
semantic/db.el
cedet/semantic/db-ref.el: Require eieio, semantic/db, and semantic/util.
Declare data-debug-new-buffer and data-debug-insert-object-slots.
Defvar semantic-case-fold. Require semantic/find when compiling.
cedet/semantic/db-typecache.el: Require semantic/tag-ls,
semantic/analyze/fcn, and semantic/scope. Declare
data-debug-insert-thing and data-debug-new-buffer.
cedet/semantic/db.el (semanticdb-search-results-table): Move class
definition here from semantic/db-search.el.
(semanticdb-current-database, semanticdb-current-table) Move variable
definitions here from semantic/db-mode.el.
2009-08-31 00:45:41 +00:00
|
|
|
|
|
|
|
;; For the semantic-find-tags-by-name-regexp macro.
|
|
|
|
(eval-when-compile (require 'semantic/find))
|
2009-09-02 04:37:10 +00:00
|
|
|
|
2015-02-04 13:49:49 -05:00
|
|
|
(cl-defmethod semanticdb-add-reference ((dbt semanticdb-abstract-table)
|
2009-08-28 19:18:35 +00:00
|
|
|
include-tag)
|
|
|
|
"Add a reference for the database table DBT based on INCLUDE-TAG.
|
|
|
|
DBT is the database table that owns the INCLUDE-TAG. The reference
|
|
|
|
will be added to the database that INCLUDE-TAG refers to."
|
|
|
|
;; NOTE: I should add a check to make sure include-tag is in DB.
|
|
|
|
;; but I'm too lazy.
|
|
|
|
(let* ((semanticdb-find-default-throttle
|
2009-09-05 23:04:46 +00:00
|
|
|
(if (featurep 'semantic/db-find)
|
2009-08-28 19:18:35 +00:00
|
|
|
(remq 'unloaded semanticdb-find-default-throttle)
|
|
|
|
nil))
|
|
|
|
(refdbt (semanticdb-find-table-for-include include-tag dbt))
|
|
|
|
;;(fullfile (semanticdb-full-filename dbt))
|
|
|
|
)
|
|
|
|
(when refdbt
|
|
|
|
;; Add our filename (full path)
|
|
|
|
;; (object-add-to-list refdbt 'file-refs fullfile)
|
|
|
|
|
|
|
|
;; Add our database.
|
|
|
|
(object-add-to-list refdbt 'db-refs dbt)
|
|
|
|
t)))
|
|
|
|
|
2021-03-15 00:08:34 -04:00
|
|
|
(cl-defmethod semanticdb-check-references ((_dbt semanticdb-abstract-table))
|
2009-08-28 19:18:35 +00:00
|
|
|
"Check and cleanup references in the database DBT.
|
|
|
|
Abstract tables would be difficult to reference."
|
|
|
|
;; Not sure how an abstract table can have references.
|
|
|
|
nil)
|
|
|
|
|
2015-02-04 13:49:49 -05:00
|
|
|
(cl-defmethod semanticdb-includes-in-table ((dbt semanticdb-abstract-table))
|
2009-08-28 19:18:35 +00:00
|
|
|
"Return a list of direct includes in table DBT."
|
|
|
|
(semantic-find-tags-by-class 'include (semanticdb-get-tags dbt)))
|
|
|
|
|
|
|
|
|
2015-02-04 13:49:49 -05:00
|
|
|
(cl-defmethod semanticdb-check-references ((dbt semanticdb-table))
|
2009-08-28 19:18:35 +00:00
|
|
|
"Check and cleanup references in the database DBT.
|
2018-09-28 14:02:52 -04:00
|
|
|
Any reference to a file that cannot be found, or whose file no longer
|
2009-08-28 19:18:35 +00:00
|
|
|
refers to DBT will be removed."
|
|
|
|
(let ((refs (oref dbt db-refs))
|
|
|
|
(myexpr (concat "\\<" (oref dbt file)))
|
|
|
|
)
|
|
|
|
(while refs
|
|
|
|
(let* ((ok t)
|
|
|
|
(db (car refs))
|
2019-06-14 15:47:54 +02:00
|
|
|
(f (when (cl-typep db 'semanticdb-table)
|
2009-08-28 19:18:35 +00:00
|
|
|
(semanticdb-full-filename db)))
|
|
|
|
)
|
|
|
|
|
|
|
|
;; The file was deleted
|
|
|
|
(when (and f (not (file-exists-p f)))
|
|
|
|
(setq ok nil))
|
|
|
|
|
|
|
|
;; The reference no longer includes the textual reference?
|
|
|
|
(let* ((refs (semanticdb-includes-in-table db))
|
|
|
|
(inc (semantic-find-tags-by-name-regexp
|
|
|
|
myexpr refs)))
|
|
|
|
(when (not inc)
|
|
|
|
(setq ok nil)))
|
|
|
|
|
|
|
|
;; Remove not-ok databases from the list.
|
|
|
|
(when (not ok)
|
|
|
|
(object-remove-from-list dbt 'db-refs db)
|
|
|
|
))
|
|
|
|
(setq refs (cdr refs)))))
|
|
|
|
|
2021-03-15 00:08:34 -04:00
|
|
|
(cl-defmethod semanticdb-refresh-references ((_dbt semanticdb-abstract-table))
|
2009-08-28 19:18:35 +00:00
|
|
|
"Refresh references to DBT in other files."
|
|
|
|
;; alternate tables can't be edited, so can't be changed.
|
|
|
|
nil
|
|
|
|
)
|
|
|
|
|
2015-02-04 13:49:49 -05:00
|
|
|
(cl-defmethod semanticdb-refresh-references ((dbt semanticdb-table))
|
2009-08-28 19:18:35 +00:00
|
|
|
"Refresh references to DBT in other files."
|
|
|
|
(let ((refs (semanticdb-includes-in-table dbt))
|
|
|
|
)
|
|
|
|
(while refs
|
|
|
|
(if (semanticdb-add-reference dbt (car refs))
|
|
|
|
nil
|
|
|
|
;; If we succeeded, then do... nothing?
|
|
|
|
nil
|
|
|
|
)
|
|
|
|
(setq refs (cdr refs)))
|
|
|
|
))
|
|
|
|
|
2015-02-04 13:49:49 -05:00
|
|
|
(cl-defmethod semanticdb-notify-references ((dbt semanticdb-table)
|
2009-08-28 19:18:35 +00:00
|
|
|
method)
|
|
|
|
"Notify all references of the table DBT using method.
|
|
|
|
METHOD takes two arguments.
|
|
|
|
(METHOD TABLE-TO-NOTIFY DBT)
|
|
|
|
TABLE-TO-NOTIFY is a semanticdb-table which is being notified.
|
|
|
|
DBT, the second argument is DBT."
|
|
|
|
(mapc (lambda (R) (funcall method R dbt))
|
|
|
|
(oref dbt db-refs)))
|
|
|
|
|
|
|
|
;;; DEBUG
|
|
|
|
;;
|
|
|
|
(defclass semanticdb-ref-adebug ()
|
|
|
|
((i-depend-on :initarg :i-depend-on)
|
|
|
|
(local-table :initarg :local-table)
|
|
|
|
(i-include :initarg :i-include))
|
|
|
|
"Simple class to allow ADEBUG to show a nice list.")
|
|
|
|
|
cedet/semantic/db-debug.el: Don't require semantic/db-mode, since
semanticdb-current-database and semanticdb-current-table are now in
semantic/db.el.
cedet/semantic/db-ebrowse.el: Don't require semantic/db-mode, since
semanticdb-current-database and semanticdb-current-table are now in
semantic/db.el.
cedet/semantic/db-el.el: Require semantic/lex-spp.
Require semantic/db instead of semantic/db-search.
cedet/semantic/db-file.el: Declare inversion-test and
data-debug-insert-thing.
(semanticdb-load-database): Load inversion only if necessary.
cedet/semantic/db-find.el: Autoload semanticdb-find-default-throttle.
Defvar data-debug-thing-alist, and ede-current-project.
Declare data-debug-insert-stuff-list, data-debug-insert-tag-list,
semantic-scope-reset-cache, and semanticdb-typecache-notify-reset.
Require semantic/tag-file, and semantic/sort.
(semantic-reset): Require semantic/scope.
(semanticdb-partial-synchronize): Require semantic/db-typecache.
(semanticdb-find-table-for-include) Move up to avoid compiler warning.
cedet/semantic/db-global.el: Declare data-debug-new-buffer and
data-debug-insert-thing.
(semanticdb-project-database-global) Move up to avoid compiler warning.
cedet/semantic/db-javascript.el: Fix provide statement.
Require semantic/db-find instead of semantic/db-search.
cedet/semantic/db-mode.el: Declare semantic-lex-spp-set-dynamic-table.
(semanticdb-current-database, semanticdb-current-table): Move into
semantic/db.el
cedet/semantic/db-ref.el: Require eieio, semantic/db, and semantic/util.
Declare data-debug-new-buffer and data-debug-insert-object-slots.
Defvar semantic-case-fold. Require semantic/find when compiling.
cedet/semantic/db-typecache.el: Require semantic/tag-ls,
semantic/analyze/fcn, and semantic/scope. Declare
data-debug-insert-thing and data-debug-new-buffer.
cedet/semantic/db.el (semanticdb-search-results-table): Move class
definition here from semantic/db-search.el.
(semanticdb-current-database, semanticdb-current-table) Move variable
definitions here from semantic/db-mode.el.
2009-08-31 00:45:41 +00:00
|
|
|
(declare-function data-debug-new-buffer "data-debug")
|
2009-09-05 23:04:46 +00:00
|
|
|
(declare-function data-debug-insert-object-slots "eieio-datadebug")
|
cedet/semantic/db-debug.el: Don't require semantic/db-mode, since
semanticdb-current-database and semanticdb-current-table are now in
semantic/db.el.
cedet/semantic/db-ebrowse.el: Don't require semantic/db-mode, since
semanticdb-current-database and semanticdb-current-table are now in
semantic/db.el.
cedet/semantic/db-el.el: Require semantic/lex-spp.
Require semantic/db instead of semantic/db-search.
cedet/semantic/db-file.el: Declare inversion-test and
data-debug-insert-thing.
(semanticdb-load-database): Load inversion only if necessary.
cedet/semantic/db-find.el: Autoload semanticdb-find-default-throttle.
Defvar data-debug-thing-alist, and ede-current-project.
Declare data-debug-insert-stuff-list, data-debug-insert-tag-list,
semantic-scope-reset-cache, and semanticdb-typecache-notify-reset.
Require semantic/tag-file, and semantic/sort.
(semantic-reset): Require semantic/scope.
(semanticdb-partial-synchronize): Require semantic/db-typecache.
(semanticdb-find-table-for-include) Move up to avoid compiler warning.
cedet/semantic/db-global.el: Declare data-debug-new-buffer and
data-debug-insert-thing.
(semanticdb-project-database-global) Move up to avoid compiler warning.
cedet/semantic/db-javascript.el: Fix provide statement.
Require semantic/db-find instead of semantic/db-search.
cedet/semantic/db-mode.el: Declare semantic-lex-spp-set-dynamic-table.
(semanticdb-current-database, semanticdb-current-table): Move into
semantic/db.el
cedet/semantic/db-ref.el: Require eieio, semantic/db, and semantic/util.
Declare data-debug-new-buffer and data-debug-insert-object-slots.
Defvar semantic-case-fold. Require semantic/find when compiling.
cedet/semantic/db-typecache.el: Require semantic/tag-ls,
semantic/analyze/fcn, and semantic/scope. Declare
data-debug-insert-thing and data-debug-new-buffer.
cedet/semantic/db.el (semanticdb-search-results-table): Move class
definition here from semantic/db-search.el.
(semanticdb-current-database, semanticdb-current-table) Move variable
definitions here from semantic/db-mode.el.
2009-08-31 00:45:41 +00:00
|
|
|
|
2009-08-28 19:18:35 +00:00
|
|
|
(defun semanticdb-ref-test (refresh)
|
|
|
|
"Dump out the list of references for the current buffer.
|
2009-09-20 03:44:02 +00:00
|
|
|
If REFRESH is non-nil, cause the current table to have its references
|
2009-08-28 19:18:35 +00:00
|
|
|
refreshed before dumping the result."
|
|
|
|
(interactive "p")
|
2009-09-05 23:04:46 +00:00
|
|
|
(require 'eieio-datadebug)
|
2009-08-28 19:18:35 +00:00
|
|
|
;; If we need to refresh... then do so.
|
|
|
|
(when refresh
|
|
|
|
(semanticdb-refresh-references semanticdb-current-table))
|
|
|
|
;; Do the debug system
|
|
|
|
(let* ((tab semanticdb-current-table)
|
|
|
|
(myrefs (oref tab db-refs))
|
|
|
|
(myinc (semanticdb-includes-in-table tab))
|
cedet: remove obsolete name args to constructors
* lisp/cedet/ede/proj-archive.el, lisp/cedet/ede/proj-aux.el:
* lisp/cedet/ede/proj-elisp.el, lisp/cedet/ede/proj-info.el:
* lisp/cedet/ede/proj-misc.el, lisp/cedet/ede/proj-obj.el:
* lisp/cedet/ede/proj-shared.el, lisp/cedet/ede/simple.el:
* lisp/cedet/ede/source.el, lisp/cedet/semantic/:
* lisp/cedet/semantic/analyze.el, lisp/cedet/semantic/complete.el:
* lisp/cedet/semantic/db-javascript.el:
* lisp/cedet/semantic/db-ref.el, lisp/cedet/semantic/debug.el:
* lisp/cedet/semantic/ede-grammar.el:
* lisp/cedet/semantic/mru-bookmark.el, lisp/cedet/semantic/scope.el:
* lisp/cedet/semantic/texi.el, lisp/cedet/semantic/bovine/:
* lisp/cedet/semantic/bovine/c.el:
* lisp/cedet/semantic/bovine/debug.el, lisp/cedet/srecode/:
* lisp/cedet/srecode/extract.el, lisp/cedet/srecode/map.el:
* lisp/cedet/srecode/srt-mode.el:
Remove obsolete name args to constructors.
2018-03-16 20:34:27 -04:00
|
|
|
(adbc (semanticdb-ref-adebug :i-depend-on myrefs
|
2009-08-28 19:18:35 +00:00
|
|
|
:local-table tab
|
|
|
|
:i-include myinc)))
|
|
|
|
(data-debug-new-buffer "*References ADEBUG*")
|
|
|
|
(data-debug-insert-object-slots adbc "!"))
|
|
|
|
)
|
|
|
|
|
|
|
|
(provide 'semantic/db-ref)
|
2009-10-02 10:53:34 +00:00
|
|
|
|
cedet/semantic/db-debug.el: Don't require semantic/db-mode, since
semanticdb-current-database and semanticdb-current-table are now in
semantic/db.el.
cedet/semantic/db-ebrowse.el: Don't require semantic/db-mode, since
semanticdb-current-database and semanticdb-current-table are now in
semantic/db.el.
cedet/semantic/db-el.el: Require semantic/lex-spp.
Require semantic/db instead of semantic/db-search.
cedet/semantic/db-file.el: Declare inversion-test and
data-debug-insert-thing.
(semanticdb-load-database): Load inversion only if necessary.
cedet/semantic/db-find.el: Autoload semanticdb-find-default-throttle.
Defvar data-debug-thing-alist, and ede-current-project.
Declare data-debug-insert-stuff-list, data-debug-insert-tag-list,
semantic-scope-reset-cache, and semanticdb-typecache-notify-reset.
Require semantic/tag-file, and semantic/sort.
(semantic-reset): Require semantic/scope.
(semanticdb-partial-synchronize): Require semantic/db-typecache.
(semanticdb-find-table-for-include) Move up to avoid compiler warning.
cedet/semantic/db-global.el: Declare data-debug-new-buffer and
data-debug-insert-thing.
(semanticdb-project-database-global) Move up to avoid compiler warning.
cedet/semantic/db-javascript.el: Fix provide statement.
Require semantic/db-find instead of semantic/db-search.
cedet/semantic/db-mode.el: Declare semantic-lex-spp-set-dynamic-table.
(semanticdb-current-database, semanticdb-current-table): Move into
semantic/db.el
cedet/semantic/db-ref.el: Require eieio, semantic/db, and semantic/util.
Declare data-debug-new-buffer and data-debug-insert-object-slots.
Defvar semantic-case-fold. Require semantic/find when compiling.
cedet/semantic/db-typecache.el: Require semantic/tag-ls,
semantic/analyze/fcn, and semantic/scope. Declare
data-debug-insert-thing and data-debug-new-buffer.
cedet/semantic/db.el (semanticdb-search-results-table): Move class
definition here from semantic/db-search.el.
(semanticdb-current-database, semanticdb-current-table) Move variable
definitions here from semantic/db-mode.el.
2009-08-31 00:45:41 +00:00
|
|
|
;;; semantic/db-ref.el ends here
|