comparison lisp/cedet/semantic/db-ref.el @ 104417:6810f0d84270

cedet/semantic/ctxt.el, cedet/semantic/db-find.el, cedet/semantic/db-ref.el, cedet/semantic/find.el, cedet/semantic/format.el, cedet/semantic/sort.el: New files.
author Chong Yidong <cyd@stupidchicken.com>
date Fri, 28 Aug 2009 19:18:35 +0000
parents
children 902d22a2d922
comparison
equal deleted inserted replaced
104416:c13af98da4d6 104417:6810f0d84270
1 ;;; db-ref.el --- Handle cross-db file references
2
3 ;;; Copyright (C) 2007, 2008, 2009 Free Software Foundation, Inc.
4
5 ;; Author: Eric M. Ludlam <eric@siege-engine.com>
6
7 ;; This file is part of GNU Emacs.
8
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.
13
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.
18
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/>.
21
22 ;;; Commentary:
23 ;;
24 ;; Handle cross-database file references.
25 ;;
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
29 ;; it.
30 ;;
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.
36
37
38 ;;; Code:
39 (defmethod semanticdb-add-reference ((dbt semanticdb-abstract-table)
40 include-tag)
41 "Add a reference for the database table DBT based on INCLUDE-TAG.
42 DBT is the database table that owns the INCLUDE-TAG. The reference
43 will be added to the database that INCLUDE-TAG refers to."
44 ;; NOTE: I should add a check to make sure include-tag is in DB.
45 ;; but I'm too lazy.
46 (let* ((semanticdb-find-default-throttle
47 (if (featurep 'semanticdb-find)
48 (remq 'unloaded semanticdb-find-default-throttle)
49 nil))
50 (refdbt (semanticdb-find-table-for-include include-tag dbt))
51 ;;(fullfile (semanticdb-full-filename dbt))
52 )
53 (when refdbt
54 ;; Add our filename (full path)
55 ;; (object-add-to-list refdbt 'file-refs fullfile)
56
57 ;; Add our database.
58 (object-add-to-list refdbt 'db-refs dbt)
59 t)))
60
61 (defmethod semanticdb-check-references ((dbt semanticdb-abstract-table))
62 "Check and cleanup references in the database DBT.
63 Abstract tables would be difficult to reference."
64 ;; Not sure how an abstract table can have references.
65 nil)
66
67 (defmethod semanticdb-includes-in-table ((dbt semanticdb-abstract-table))
68 "Return a list of direct includes in table DBT."
69 (semantic-find-tags-by-class 'include (semanticdb-get-tags dbt)))
70
71
72 (defmethod semanticdb-check-references ((dbt semanticdb-table))
73 "Check and cleanup references in the database DBT.
74 Any reference to a file that cannot be found, or whos file no longer
75 refers to DBT will be removed."
76 (let ((refs (oref dbt db-refs))
77 (myexpr (concat "\\<" (oref dbt file)))
78 )
79 (while refs
80 (let* ((ok t)
81 (db (car refs))
82 (f (when (semanticdb-table-child-p db)
83 (semanticdb-full-filename db)))
84 )
85
86 ;; The file was deleted
87 (when (and f (not (file-exists-p f)))
88 (setq ok nil))
89
90 ;; The reference no longer includes the textual reference?
91 (let* ((refs (semanticdb-includes-in-table db))
92 (inc (semantic-find-tags-by-name-regexp
93 myexpr refs)))
94 (when (not inc)
95 (setq ok nil)))
96
97 ;; Remove not-ok databases from the list.
98 (when (not ok)
99 (object-remove-from-list dbt 'db-refs db)
100 ))
101 (setq refs (cdr refs)))))
102
103 (defmethod semanticdb-refresh-references ((dbt semanticdb-abstract-table))
104 "Refresh references to DBT in other files."
105 ;; alternate tables can't be edited, so can't be changed.
106 nil
107 )
108
109 (defmethod semanticdb-refresh-references ((dbt semanticdb-table))
110 "Refresh references to DBT in other files."
111 (let ((refs (semanticdb-includes-in-table dbt))
112 )
113 (while refs
114 (if (semanticdb-add-reference dbt (car refs))
115 nil
116 ;; If we succeeded, then do... nothing?
117 nil
118 )
119 (setq refs (cdr refs)))
120 ))
121
122 (defmethod semanticdb-notify-references ((dbt semanticdb-table)
123 method)
124 "Notify all references of the table DBT using method.
125 METHOD takes two arguments.
126 (METHOD TABLE-TO-NOTIFY DBT)
127 TABLE-TO-NOTIFY is a semanticdb-table which is being notified.
128 DBT, the second argument is DBT."
129 (mapc (lambda (R) (funcall method R dbt))
130 (oref dbt db-refs)))
131
132 ;;; DEBUG
133 ;;
134 (defclass semanticdb-ref-adebug ()
135 ((i-depend-on :initarg :i-depend-on)
136 (local-table :initarg :local-table)
137 (i-include :initarg :i-include))
138 "Simple class to allow ADEBUG to show a nice list.")
139
140 (defun semanticdb-ref-test (refresh)
141 "Dump out the list of references for the current buffer.
142 If REFRESH is non-nil, cause the current table to have it's references
143 refreshed before dumping the result."
144 (interactive "p")
145 ;; If we need to refresh... then do so.
146 (when refresh
147 (semanticdb-refresh-references semanticdb-current-table))
148 ;; Do the debug system
149 (let* ((tab semanticdb-current-table)
150 (myrefs (oref tab db-refs))
151 (myinc (semanticdb-includes-in-table tab))
152 (adbc (semanticdb-ref-adebug "DEBUG"
153 :i-depend-on myrefs
154 :local-table tab
155 :i-include myinc)))
156 (data-debug-new-buffer "*References ADEBUG*")
157 (data-debug-insert-object-slots adbc "!"))
158 )
159
160 (provide 'semantic/db-ref)
161 ;;; semanticdb-ref.el ends here