comparison lisp/cedet/semantic/analyze/refs.el @ 110534:826d60163924

Merge changes from emacs-23 branch.
author Chong Yidong <cyd@stupidchicken.com>
date Thu, 23 Sep 2010 22:10:54 -0400
parents a5ad4f188e19
children 376148b31b5e
comparison
equal deleted inserted replaced
110517:64945cefe6a6 110534:826d60163924
102 ;; into the context. 102 ;; into the context.
103 (defmethod semantic-analyze-refs-impl ((refs semantic-analyze-references) &optional in-buffer) 103 (defmethod semantic-analyze-refs-impl ((refs semantic-analyze-references) &optional in-buffer)
104 "Return the implementations derived in the reference analyzer REFS. 104 "Return the implementations derived in the reference analyzer REFS.
105 Optional argument IN-BUFFER indicates that the returned tag should be in an active buffer." 105 Optional argument IN-BUFFER indicates that the returned tag should be in an active buffer."
106 (let ((allhits (oref refs rawsearchdata)) 106 (let ((allhits (oref refs rawsearchdata))
107 (tag (oref refs :tag))
107 (impl nil) 108 (impl nil)
108 ) 109 )
109 (semanticdb-find-result-mapc 110 (semanticdb-find-result-mapc
110 (lambda (T DB) 111 (lambda (T DB)
111 "Examine T in the database DB, and sont it." 112 "Examine T in the database DB, and sont it."
112 (let* ((ans (semanticdb-normalize-one-tag DB T)) 113 (let* ((ans (semanticdb-normalize-one-tag DB T))
113 (aT (cdr ans)) 114 (aT (cdr ans))
114 (aDB (car ans)) 115 (aDB (car ans))
115 ) 116 )
116 (when (not (semantic-tag-prototype-p aT)) 117 (when (and (not (semantic-tag-prototype-p aT))
118 (semantic-tag-similar-p tag aT :prototype-flag :parent))
117 (when in-buffer (save-excursion (semantic-go-to-tag aT aDB))) 119 (when in-buffer (save-excursion (semantic-go-to-tag aT aDB)))
118 (push aT impl)))) 120 (push aT impl))))
119 allhits) 121 allhits)
120 impl)) 122 impl))
121 123
122 (defmethod semantic-analyze-refs-proto ((refs semantic-analyze-references) &optional in-buffer) 124 (defmethod semantic-analyze-refs-proto ((refs semantic-analyze-references) &optional in-buffer)
123 "Return the prototypes derived in the reference analyzer REFS. 125 "Return the prototypes derived in the reference analyzer REFS.
124 Optional argument IN-BUFFER indicates that the returned tag should be in an active buffer." 126 Optional argument IN-BUFFER indicates that the returned tag should be in an active buffer."
125 (let ((allhits (oref refs rawsearchdata)) 127 (let ((allhits (oref refs rawsearchdata))
128 (tag (oref refs :tag))
126 (proto nil)) 129 (proto nil))
127 (semanticdb-find-result-mapc 130 (semanticdb-find-result-mapc
128 (lambda (T DB) 131 (lambda (T DB)
129 "Examine T in the database DB, and sort it." 132 "Examine T in the database DB, and sort it."
130 (let* ((ans (semanticdb-normalize-one-tag DB T)) 133 (let* ((ans (semanticdb-normalize-one-tag DB T))
131 (aT (cdr ans)) 134 (aT (cdr ans))
132 (aDB (car ans)) 135 (aDB (car ans))
133 ) 136 )
134 (when (semantic-tag-prototype-p aT) 137 (when (and (semantic-tag-prototype-p aT)
138 (semantic-tag-similar-p tag aT :prototype-flag :parent))
135 (when in-buffer (save-excursion (semantic-go-to-tag aT aDB))) 139 (when in-buffer (save-excursion (semantic-go-to-tag aT aDB)))
136 (push aT proto)))) 140 (push aT proto))))
137 allhits) 141 allhits)
138 proto)) 142 proto))
139 143
140 ;;; LOOKUP 144 ;;; LOOKUP
141 ;; 145 ;;
142 (defun semantic--analyze-refs-full-lookup (tag scope) 146 (defun semantic--analyze-refs-full-lookup (tag scope)
143 "Perform a full lookup for all occurrences of TAG in the current project. 147 "Perform a full lookup for all occurrences of TAG in the current project.
144 TAG should be the tag currently under point. 148 TAG should be the tag currently under point.
145 PARENT is the list of tags that are parents to TAG by 149 SCOPE is the scope the cursor is in. From this a list of parents is
146 containment, as opposed to reference." 150 derived. If SCOPE does not have parents, then only a simple lookup is done."
147 (if (not (oref scope parents)) 151 (if (not (oref scope parents))
148 ;; If this tag has some named parent, but is not 152 ;; If this tag has some named parent, but is not
149 (semantic--analyze-refs-full-lookup-simple tag) 153 (semantic--analyze-refs-full-lookup-simple tag)
150 154
151 ;; We have some sort of lineage we need to consider when we do 155 ;; We have some sort of lineage we need to consider when we do
175 (push (cons (car FDB) subans) ans)) 179 (push (cons (car FDB) subans) ans))
176 ) 180 )
177 ans)) 181 ans))
178 182
179 (defun semantic--analyze-refs-find-tags-with-parent (find-results parents) 183 (defun semantic--analyze-refs-find-tags-with-parent (find-results parents)
180 "Find in FIND-RESULTS all tags with PARNTS. 184 "Find in FIND-RESULTS all tags with PARENTS.
181 NAME is the name of the tag needing finding. 185 NAME is the name of the tag needing finding.
182 PARENTS is a list of names." 186 PARENTS is a list of names."
183 (let ((ans nil)) 187 (let ((ans nil) (usingnames nil))
188 ;; Loop over the find-results passed in.
184 (semanticdb-find-result-mapc 189 (semanticdb-find-result-mapc
185 (lambda (tag db) 190 (lambda (tag db)
186 (let* ((p (semantic-tag-named-parent tag)) 191 (let* ((p (semantic-tag-named-parent tag))
187 (ps (when (stringp p) 192 (ps (when (stringp p) (semantic-analyze-split-name p))))
188 (semantic-analyze-split-name p))))
189 (when (stringp ps) (setq ps (list ps))) 193 (when (stringp ps) (setq ps (list ps)))
190 (when (and ps (equal ps parents)) 194 (when ps
191 ;; We could optimize this, but it seems unlikely. 195 ;; If there is a perfect match, then use it.
192 (push (list db tag) ans)) 196 (if (equal ps parents)
193 )) 197 (push (list db tag) ans))
198 ;; No match, find something from our list of using names.
199 ;; Do we need to split UN?
200 (save-excursion
201 (semantic-go-to-tag tag db)
202 (setq usingnames nil)
203 (let ((imports (semantic-ctxt-imported-packages)))
204 ;; Derive the names from all the using statements.
205 (mapc (lambda (T)
206 (setq usingnames
207 (cons (semantic-format-tag-name-from-anything T) usingnames)))
208 imports))
209 (dolist (UN usingnames)
210 (when (equal (cons UN ps) parents)
211 (push (list db tag) ans)
212 (setq usingnames (cdr usingnames))))
213 ))))
194 find-results) 214 find-results)
195 ans)) 215 ans))
196 216
197 (defun semantic--analyze-refs-full-lookup-with-parents (tag scope) 217 (defun semantic--analyze-refs-full-lookup-with-parents (tag scope)
198 "Perform a lookup for all occurrences of TAG based on TAG's SCOPE. 218 "Perform a lookup for all occurrences of TAG based on TAG's SCOPE.
204 ;; Stuff from the simple list. 224 ;; Stuff from the simple list.
205 (simple (semantic--analyze-refs-full-lookup-simple tag t)) 225 (simple (semantic--analyze-refs-full-lookup-simple tag t))
206 ;; Find all hits for the first parent name. 226 ;; Find all hits for the first parent name.
207 (brute (semanticdb-find-tags-collector 227 (brute (semanticdb-find-tags-collector
208 (lambda (table tags) 228 (lambda (table tags)
209 (semanticdb-find-tags-by-name-method table name tags) 229 (semanticdb-deep-find-tags-by-name-method table name tags)
210 ) 230 )
211 nil nil t)) 231 nil nil t))
212 ;; Prime the answer. 232 ;; Prime the answer.
213 (answer (semantic--analyze-refs-find-tags-with-parent simple plist)) 233 (answer (semantic--analyze-refs-find-tags-with-parent simple plist))
214 ) 234 )
215 ;; First parent is already search to initialize "brute". 235 ;; First parent is already search to initialize "brute".
216 (setq plist (cdr plist)) 236 (setq plist (cdr plist))
237
217 ;; Go through the list of parents, and try to find matches. 238 ;; Go through the list of parents, and try to find matches.
218 ;; As we cycle through plist, for each level look for NAME, 239 ;; As we cycle through plist, for each level look for NAME,
219 ;; and compare the named-parent, and also dive into the next item of 240 ;; and compare the named-parent, and also dive into the next item of
220 ;; plist. 241 ;; plist.
221 (while (and plist brute) 242 (while (and plist brute)
251 (let* ((name (semantic-tag-name tag)) 272 (let* ((name (semantic-tag-name tag))
252 (brute (semanticdb-find-tags-collector 273 (brute (semanticdb-find-tags-collector
253 (lambda (table tags) 274 (lambda (table tags)
254 (semanticdb-find-tags-by-name-method table name tags) 275 (semanticdb-find-tags-by-name-method table name tags)
255 ) 276 )
256 nil nil t)) 277 nil ;; This may need to be the entire project??
278 nil t))
257 ) 279 )
258 280
259 (when (and (not brute) (not noerror)) 281 (when (and (not brute) (not noerror))
260 ;; An error, because tag under point ought to be found. 282 ;; An error, because tag under point ought to be found.
261 (error "Cannot find any references to %s in wide search" name)) 283 (error "Cannot find any references to %s in wide search" name))