1 ;;; semantic/db-ref.el --- Handle cross-db file references
3 ;;; Copyright (C) 2007-2015 Free Software Foundation, Inc.
5 ;; Author: Eric M. Ludlam <eric@siege-engine.com>
7 ;; This file is part of GNU Emacs.
9 ;; GNU Emacs is free software: you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation, either version 3 of the License, or
12 ;; (at your option) any later version.
14 ;; GNU Emacs is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ;; GNU General Public License for more details.
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
24 ;; Handle cross-database file references.
26 ;; Any given database may be referred to by some other database. For
27 ;; example, if a .cpp file has a #include in a header, then that
28 ;; header file should have a reference to the .cpp file that included
31 ;; This is critical for purposes where a file (such as a .cpp file)
32 ;; needs to have its caches flushed because of changes in the
33 ;; header. Changing a header may cause a referring file to be
34 ;; reparsed due to account for changes in defined macros, or perhaps
35 ;; a change to files the header includes.
42 (require 'semantic
/db
)
43 (require 'semantic
/tag
)
45 ;; For the semantic-find-tags-by-name-regexp macro.
46 (eval-when-compile (require 'semantic
/find
))
48 (cl-defmethod semanticdb-add-reference ((dbt semanticdb-abstract-table
)
50 "Add a reference for the database table DBT based on INCLUDE-TAG.
51 DBT is the database table that owns the INCLUDE-TAG. The reference
52 will be added to the database that INCLUDE-TAG refers to."
53 ;; NOTE: I should add a check to make sure include-tag is in DB.
55 (let* ((semanticdb-find-default-throttle
56 (if (featurep 'semantic
/db-find
)
57 (remq 'unloaded semanticdb-find-default-throttle
)
59 (refdbt (semanticdb-find-table-for-include include-tag dbt
))
60 ;;(fullfile (semanticdb-full-filename dbt))
63 ;; Add our filename (full path)
64 ;; (object-add-to-list refdbt 'file-refs fullfile)
67 (object-add-to-list refdbt
'db-refs dbt
)
70 (cl-defmethod semanticdb-check-references ((dbt semanticdb-abstract-table
))
71 "Check and cleanup references in the database DBT.
72 Abstract tables would be difficult to reference."
73 ;; Not sure how an abstract table can have references.
76 (cl-defmethod semanticdb-includes-in-table ((dbt semanticdb-abstract-table
))
77 "Return a list of direct includes in table DBT."
78 (semantic-find-tags-by-class 'include
(semanticdb-get-tags dbt
)))
81 (cl-defmethod semanticdb-check-references ((dbt semanticdb-table
))
82 "Check and cleanup references in the database DBT.
83 Any reference to a file that cannot be found, or whos file no longer
84 refers to DBT will be removed."
85 (let ((refs (oref dbt db-refs
))
86 (myexpr (concat "\\<" (oref dbt file
)))
91 (f (when (semanticdb-table-child-p db
)
92 (semanticdb-full-filename db
)))
95 ;; The file was deleted
96 (when (and f
(not (file-exists-p f
)))
99 ;; The reference no longer includes the textual reference?
100 (let* ((refs (semanticdb-includes-in-table db
))
101 (inc (semantic-find-tags-by-name-regexp
106 ;; Remove not-ok databases from the list.
108 (object-remove-from-list dbt
'db-refs db
)
110 (setq refs
(cdr refs
)))))
112 (cl-defmethod semanticdb-refresh-references ((dbt semanticdb-abstract-table
))
113 "Refresh references to DBT in other files."
114 ;; alternate tables can't be edited, so can't be changed.
118 (cl-defmethod semanticdb-refresh-references ((dbt semanticdb-table
))
119 "Refresh references to DBT in other files."
120 (let ((refs (semanticdb-includes-in-table dbt
))
123 (if (semanticdb-add-reference dbt
(car refs
))
125 ;; If we succeeded, then do... nothing?
128 (setq refs
(cdr refs
)))
131 (cl-defmethod semanticdb-notify-references ((dbt semanticdb-table
)
133 "Notify all references of the table DBT using method.
134 METHOD takes two arguments.
135 (METHOD TABLE-TO-NOTIFY DBT)
136 TABLE-TO-NOTIFY is a semanticdb-table which is being notified.
137 DBT, the second argument is DBT."
138 (mapc (lambda (R) (funcall method R dbt
))
143 (defclass semanticdb-ref-adebug
()
144 ((i-depend-on :initarg
:i-depend-on
)
145 (local-table :initarg
:local-table
)
146 (i-include :initarg
:i-include
))
147 "Simple class to allow ADEBUG to show a nice list.")
149 (declare-function data-debug-new-buffer
"data-debug")
150 (declare-function data-debug-insert-object-slots
"eieio-datadebug")
152 (defun semanticdb-ref-test (refresh)
153 "Dump out the list of references for the current buffer.
154 If REFRESH is non-nil, cause the current table to have its references
155 refreshed before dumping the result."
157 (require 'eieio-datadebug
)
158 ;; If we need to refresh... then do so.
160 (semanticdb-refresh-references semanticdb-current-table
))
161 ;; Do the debug system
162 (let* ((tab semanticdb-current-table
)
163 (myrefs (oref tab db-refs
))
164 (myinc (semanticdb-includes-in-table tab
))
165 (adbc (semanticdb-ref-adebug "DEBUG"
169 (data-debug-new-buffer "*References ADEBUG*")
170 (data-debug-insert-object-slots adbc
"!"))
173 (provide 'semantic
/db-ref
)
175 ;;; semantic/db-ref.el ends here