1 ;;; semantic/analyze.el --- Analyze semantic tags against local context
3 ;; Copyright (C) 2000-2005, 2007-2018 Free Software Foundation, Inc.
5 ;; Author: Eric M. Ludlam <zappo@gnu.org>
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 <https://www.gnu.org/licenses/>.
24 ;; Semantic, as a tool, provides a nice list of searchable tags.
25 ;; That information can provide some very accurate answers if the current
26 ;; context of a position is known.
28 ;; Semantic-ctxt provides ways of analyzing, and manipulating the
29 ;; semantic context of a language in code.
31 ;; This library provides routines for finding intelligent answers to
32 ;; tough problems, such as if an argument to a function has the correct
33 ;; return type, or all possible tags that fit in a given local context.
38 ;; Here are some words used to describe different things in the analyzer:
40 ;; tag - A single entity
41 ;; prefix - The beginning of a symbol, usually used to look up something
43 ;; type - The name of a datatype in the language.
44 ;; metatype - If a type is named in a declaration like:
45 ;; struct moose somevariable;
46 ;; that name "moose" can be turned into a concrete type.
47 ;; tag sequence - In C code, a list of dereferences, such as:
48 ;; this.that.theother();
49 ;; parent - For a datatype in an OO language, another datatype
50 ;; inherited from. This excludes interfaces.
51 ;; scope - A list of tags that can be dereferenced that cannot
52 ;; be found from the global namespace.
53 ;; scopetypes - A list of tags which are datatype that contain
54 ;; the scope. The scopetypes need to have the scope extracted
55 ;; in a way that honors the type of inheritance.
56 ;; nest/nested - When one tag is contained entirely in another.
58 ;; context - A semantic datatype representing a point in a buffer.
60 ;; constraint - If a context specifies a specific datatype is needed,
61 ;; that is a constraint.
62 ;; constants - Some datatypes define elements of themselves as a
63 ;; constant. These need to be returned as there would be no
64 ;; other possible completions.
66 (eval-when-compile (require 'cl
))
68 (require 'semantic
/format
)
69 (require 'semantic
/ctxt
)
70 (require 'semantic
/scope
)
71 (require 'semantic
/sort
)
72 (require 'semantic
/analyze
/fcn
)
74 (eval-when-compile (require 'semantic
/find
))
76 (declare-function data-debug-new-buffer
"data-debug")
77 (declare-function data-debug-insert-object-slots
"eieio-datadebug")
80 (defvar semantic-analyze-error-stack nil
81 "Collection of any errors thrown during analysis.")
83 (defun semantic-analyze-push-error (err)
84 "Push the error in ERR-DATA onto the error stack.
86 (push err semantic-analyze-error-stack
))
90 ;; These classes represent what a context is. Different types
91 ;; of contexts provide differing amounts of information to help
92 ;; provide completions.
94 (defclass semantic-analyze-context
()
95 ((bounds :initarg
:bounds
97 :documentation
"The bounds of this context.
98 Usually bound to the dimension of a single symbol or command.")
99 (prefix :initarg
:prefix
101 :documentation
"List of tags defining local text.
102 This can be nil, or a list where the last element can be a string
103 representing text that may be incomplete. Preceding elements
104 must be semantic tags representing variables or functions
105 called in a dereference sequence.")
106 (prefixclass :initarg
:prefixclass
108 :documentation
"Tag classes expected at this context.
109 These are classes for tags, such as 'function, or 'variable.")
110 (prefixtypes :initarg
:prefixtypes
112 :documentation
"List of tags defining types for :prefix.
113 This list is one shorter than :prefix. Each element is a semantic
114 tag representing a type matching the semantic tag in the same
115 position in PREFIX.")
116 (scope :initarg
:scope
117 :type
(or null semantic-scope-cache
)
118 :documentation
"List of tags available in scopetype.
119 See `semantic-analyze-scoped-tags' for details.")
120 (buffer :initarg
:buffer
122 :documentation
"The buffer this context is derived from.")
123 (errors :initarg
:errors
124 :documentation
"Any errors thrown and caught during analysis.")
126 "Base analysis data for any context.")
128 (defclass semantic-analyze-context-assignment
(semantic-analyze-context)
129 ((assignee :initarg
:assignee
131 :documentation
"A sequence of tags for an assignee.
132 This is a variable into which some value is being placed. The last
133 item in the list is the variable accepting the value. Earlier
134 tags represent the variables being dereferenced to get to the
136 "Analysis class for a value in an assignment.")
138 (defclass semantic-analyze-context-functionarg
(semantic-analyze-context)
139 ((function :initarg
:function
141 :documentation
"A sequence of tags for a function.
142 This is a function being called. The cursor will be in the position
144 The last tag in :function is the function being called. Earlier
145 tags represent the variables being dereferenced to get to the
147 (index :initarg
:index
149 :documentation
"The index of the argument for this context.
150 If a function takes 4 arguments, this value should be bound to
151 the values 1 through 4.")
152 (argument :initarg
:argument
154 :documentation
"A sequence of tags for the :index argument.
155 The argument can accept a value of some type, and this contains the
156 tag for that definition. It should be a tag, but might
157 be just a string in some circumstances.")
159 "Analysis class for a value as a function argument.")
161 (defclass semantic-analyze-context-return
(semantic-analyze-context)
163 "Analysis class for return data.
164 Return data methods identify the required type by the return value
165 of the parent function.")
169 ;; Simple methods against the context classes.
171 (cl-defmethod semantic-analyze-type-constraint
172 ((context semantic-analyze-context
) &optional desired-type
)
173 "Return a type constraint for completing :prefix in CONTEXT.
174 Optional argument DESIRED-TYPE may be a non-type tag to analyze."
175 (when (semantic-tag-p desired-type
)
176 ;; Convert the desired type if needed.
177 (if (not (eq (semantic-tag-class desired-type
) 'type
))
178 (setq desired-type
(semantic-tag-type desired-type
)))
179 ;; Protect against plain strings
180 (cond ((stringp desired-type
)
181 (setq desired-type
(list desired-type
'type
)))
182 ((and (stringp (car desired-type
))
183 (not (semantic-tag-p desired-type
)))
184 (setq desired-type
(list (car desired-type
) 'type
)))
185 ((semantic-tag-p desired-type
)
186 ;; We have a tag of some sort. Yay!
188 (t (setq desired-type nil
))
192 (cl-defmethod semantic-analyze-type-constraint
193 ((context semantic-analyze-context-functionarg
))
194 "Return a type constraint for completing :prefix in CONTEXT."
195 (cl-call-next-method context
(car (oref context argument
))))
197 (cl-defmethod semantic-analyze-type-constraint
198 ((context semantic-analyze-context-assignment
))
199 "Return a type constraint for completing :prefix in CONTEXT."
200 (cl-call-next-method context
(car (reverse (oref context assignee
)))))
202 (cl-defmethod semantic-analyze-interesting-tag
203 ((context semantic-analyze-context
))
204 "Return a tag from CONTEXT that would be most interesting to a user."
205 (let ((prefix (reverse (oref context
:prefix
))))
206 ;; Go back through the prefix until we find a tag we can return.
207 (while (and prefix
(not (semantic-tag-p (car prefix
))))
208 (setq prefix
(cdr prefix
)))
209 ;; Return the found tag, or nil.
212 (cl-defmethod semantic-analyze-interesting-tag
213 ((context semantic-analyze-context-functionarg
))
214 "Try the base, and if that fails, return what we are assigning into."
215 (or (cl-call-next-method) (car-safe (oref context
:function
))))
217 (cl-defmethod semantic-analyze-interesting-tag
218 ((context semantic-analyze-context-assignment
))
219 "Try the base, and if that fails, return what we are assigning into."
220 (or (cl-call-next-method) (car-safe (oref context
:assignee
))))
224 ;; Start out with routines that will calculate useful parts of
225 ;; the general analyzer function. These could be used directly
226 ;; by an application that doesn't need to calculate the full
229 (define-overloadable-function semantic-analyze-find-tag-sequence
230 (sequence &optional scope typereturn throwsym
&rest flags
)
231 "Attempt to find all tags in SEQUENCE.
232 Optional argument LOCALVAR is the list of local variables to use when
233 finding the details on the first element of SEQUENCE in case
234 it is not found in the global set of tables.
235 Optional argument SCOPE are additional terminals to search which are currently
236 scoped. These are not local variables, but symbols available in a structure
237 which doesn't need to be dereferenced.
238 Optional argument TYPERETURN is a symbol in which the types of all found
239 will be stored. If nil, that data is thrown away.
240 Optional argument THROWSYM specifies a symbol the throw on non-recoverable error.
241 Remaining arguments FLAGS are additional flags to apply when searching.")
243 (defun semantic-analyze-find-tag-sequence-default
244 ;; Note: overloadable fcn uses &rest, but it is a list already, so we don't need
245 ;; to do that in the -default.
246 (sequence &optional scope typereturn throwsym flags
)
247 "Attempt to find all tags in SEQUENCE.
248 SCOPE are extra tags which are in scope.
249 TYPERETURN is a symbol in which to place a list of tag classes that
250 are found in SEQUENCE.
251 Optional argument THROWSYM specifies a symbol the throw on non-recoverable error.
252 Remaining arguments FLAGS are additional flags to apply when searching.
253 This function knows of flags:
254 `mustbeclassvariable'"
255 (let ((s sequence
) ; copy of the sequence
256 (tmp nil
) ; tmp find variable
257 (tag nil
) ; tag return list
258 (tagtype nil
) ; tag types return list
260 (miniscope (when scope
(clone scope
)))
261 (tagclass (if (memq 'mustbeclassvariable flags
)
264 ;; First order check. Is this wholly contained in the typecache?
265 (setq tmp
(semanticdb-typecache-find sequence
))
268 (if (or (not tagclass
) (semantic-tag-of-class-p tmp tagclass
))
269 ;; We are effectively done...
272 ;; tagclass doesn't match, so fail this.
276 ;; For tag class filtering, only apply the filter if the first entry
277 ;; is also the only entry.
278 (let ((lftagclass (if (= (length s
) 1) tagclass
)))
280 ;; For the first entry, it better be a variable, but it might
281 ;; be in the local context too.
282 ;; NOTE: Don't forget c++ namespace foo::bar.
284 ;; Is this tag within our scope. Scopes can sometimes
285 ;; shadow other things, so it goes first.
286 (and scope
(semantic-scope-find (car s
) lftagclass scope
))
287 ;; Find the tag out there... somewhere, but not in scope
288 (semantic-analyze-find-tag (car s
) lftagclass
)
291 (if (and (listp tmp
) (semantic-tag-p (car tmp
)))
292 (setq tmp
(semantic-analyze-select-best-tag tmp lftagclass
)))
293 (if (not (semantic-tag-p tmp
))
295 (throw throwsym
"Cannot find definition")
296 (error "Cannot find definition for \"%s\"" (car s
))))
298 (setq tag
(cons tmp tag
)) ; tag is nil here...
299 (setq fname
(semantic-tag-file-name tmp
))
302 ;; For the middle entries
304 ;; Using the tag found in TMP, let's find the tag
305 ;; representing the full typeographic information of its
306 ;; type, and use that to determine the search context for
309 ;; In some cases the found TMP is a type,
310 ;; and we can use it directly.
311 (cond ((semantic-tag-of-class-p tmp
'type
)
312 (or (semantic-analyze-type tmp miniscope
)
315 (semantic-analyze-tag-type tmp miniscope
))))
318 (semantic-tag-file-name tmptype
)))
322 (setq slots
(semantic-analyze-scoped-type-parts tmptype scope
))
324 ;; find (car s) in the list o slots
325 (setq tmp
(semantic-find-tags-by-name (car s
) slots
))
328 (if (and (listp tmp
) (semantic-tag-p (car tmp
)))
329 (setq tmp
(semantic-analyze-select-best-tag tmp
)))
331 ;; Make sure we have a tag.
332 (if (not (semantic-tag-p tmp
))
334 ;; In the middle, we need to keep seeking our types out.
335 (error "Cannot find definition for \"%s\"" (car s
))
336 ;; Else, it's ok to end with a non-tag
339 (setq fname
(or typefile fname
))
340 (when (and fname
(semantic-tag-p tmp
)
341 (not (semantic-tag-in-buffer-p tmp
)))
342 (semantic--tag-put-property tmp
:filename fname
))
343 (setq tag
(cons tmp tag
))
344 (setq tagtype
(cons tmptype tagtype
))
348 (mapcar 'semantic-tag-type-members tagtype
))))
349 (oset miniscope fullscope rawscope
)))
353 (if typereturn
(set typereturn
(nreverse tagtype
)))
357 (defun semantic-analyze-find-tag (name &optional tagclass scope
)
358 "Return the first tag found with NAME or nil if not found.
359 Optional argument TAGCLASS specifies the class of tag to return,
360 such as 'function or 'variable.
361 Optional argument SCOPE specifies a scope object which has
362 additional tags which are in SCOPE and do not need prefixing to
365 This is a wrapper on top of semanticdb, semanticdb typecache,
366 semantic-scope, and semantic search functions. Almost all
367 searches use the same arguments."
368 (let ((namelst (if (consp name
) name
;; test if pre-split.
369 (semantic-analyze-split-name name
))))
371 ;; If the splitter gives us a list, use the sequence finder
372 ;; to get the list. Since this routine is expected to return
373 ;; only one tag, return the LAST tag found from the sequence
374 ;; which is supposedly the nested reference.
376 ;; Of note, the SEQUENCE function below calls this function
377 ;; (recursively now) so the names that we get from the above
378 ;; fcn better not, in turn, be splittable.
380 ;; If we had a split, then this is likely a c++ style namespace::name sequence,
381 ;; so take a short-cut through the typecache.
382 (or (semanticdb-typecache-find namelst
)
383 ;; Ok, not there, try the usual...
384 (let ((seq (semantic-analyze-find-tag-sequence
386 (semantic-analyze-select-best-tag seq tagclass
)
388 ;; If NAME is solo, then do our searches for it here.
390 (let ((retlist (and scope
(semantic-scope-find name tagclass scope
))))
392 (semantic-analyze-select-best-tag
394 (if (eq tagclass
'type
)
395 (semanticdb-typecache-find name
)
396 ;; Search in the typecache. First entries in a sequence are
398 (setq retlist
(semanticdb-typecache-find name
))
399 (if (and retlist
(or (not tagclass
)
400 (semantic-tag-of-class-p retlist
'tagclass
)))
402 (semantic-analyze-select-best-tag
403 (semanticdb-strip-find-results
404 (semanticdb-find-tags-by-name name
)
412 ;; Create a mini-analysis of just the symbol under point.
414 (define-overloadable-function semantic-analyze-current-symbol
415 (analyzehookfcn &optional position
)
416 "Call ANALYZEHOOKFCN after analyzing the symbol under POSITION.
417 The ANALYZEHOOKFCN is called with the current symbol bounds, and the
418 analyzed prefix. It should take the arguments (START END PREFIX).
419 The ANALYZEHOOKFCN is only called if some sort of prefix with bounds was
420 found under POSITION.
422 The results of ANALYZEHOOKFCN is returned, or nil if there was nothing to
425 For regular analysis, you should call `semantic-analyze-current-context'
426 to calculate the context information. The purpose for this function is
427 to provide a large number of non-cached analysis for filtering symbols."
428 ;; Only do this in a Semantic enabled buffer.
429 (when (not (semantic-active-p))
430 (error "Cannot analyze buffers not supported by Semantic"))
431 ;; Always refresh out tags in a safe way before doing the
433 (semantic-refresh-tags-safe)
434 ;; Do the rest of the analysis.
440 (defun semantic-analyze-current-symbol-default (analyzehookfcn position
)
441 "Call ANALYZEHOOKFCN on the analyzed symbol at POSITION."
442 (let* ((semantic-analyze-error-stack nil
)
443 ;; (LLstart (current-time))
444 (prefixandbounds (semantic-ctxt-current-symbol-and-bounds (or position
(point))))
445 (prefix (car prefixandbounds
))
446 (bounds (nth 2 prefixandbounds
))
447 (scope (semantic-calculate-scope position
))
449 ;; Only do work if we have bounds (meaning a prefix to complete)
454 ;; If debug on error is on, allow debugging in this fcn.
455 (setq prefix
(semantic-analyze-find-tag-sequence
456 prefix scope
'prefixtypes
'unfindable
)))
457 ;; Debug on error is off. Capture errors and move on
459 ;; NOTE: This line is duplicated in
460 ;; semantic-analyzer-debug-global-symbol
461 ;; You will need to update both places.
462 (setq prefix
(semantic-analyze-find-tag-sequence
463 prefix scope
'prefixtypes
))
464 (error (semantic-analyze-push-error err
))))
466 ;;(message "Analysis took %.2f sec" (semantic-elapsed-time LLstart nil))
471 (funcall analyzehookfcn
(car bounds
) (cdr bounds
) prefix
)
472 ;;(message "hookfcn took %.5f sec" (semantic-elapsed-time LLstart nil))
479 ;; Create a full-up context analysis.
482 (define-overloadable-function semantic-analyze-current-context
(&optional position
)
483 "Analyze the current context at optional POSITION.
484 If called interactively, display interesting information about POSITION
485 in a separate buffer.
486 Returns an object based on symbol `semantic-analyze-context'.
488 This function can be overridden with the symbol `analyze-context'.
489 When overriding this function, your override will be called while
490 cursor is at POSITION. In addition, your function will not be called
491 if a cached copy of the return object is found."
493 ;; Only do this in a Semantic enabled buffer.
494 (when (not (semantic-active-p))
495 (error "Cannot analyze buffers not supported by Semantic"))
496 ;; Always refresh out tags in a safe way before doing the
498 (semantic-refresh-tags-safe)
499 ;; Do the rest of the analysis.
500 (if (not position
) (setq position
(point)))
503 (let* ((answer (semantic-get-cache-data 'current-context
)))
504 (with-syntax-table semantic-lex-syntax-table
506 (setq answer
(:override
))
507 (when (and answer
(oref answer bounds
))
508 (with-slots (bounds) answer
509 (semantic-cache-data-to-buffer (current-buffer)
515 ;; Check for interactivity
516 (when (called-interactively-p 'any
)
518 (semantic-analyze-pop-to-context answer
)
519 (message "No Context."))
524 (defun semantic-analyze-current-context-default (position)
525 "Analyze the current context at POSITION.
526 Returns an object based on symbol `semantic-analyze-context'."
527 (let* ((semantic-analyze-error-stack nil
)
529 (prefixandbounds (semantic-ctxt-current-symbol-and-bounds (or position
(point))))
530 (prefix (car prefixandbounds
))
531 (bounds (nth 2 prefixandbounds
))
532 ;; @todo - vv too early to really know this answer! vv
533 (prefixclass (semantic-ctxt-current-class-list))
535 (scope (semantic-calculate-scope position
))
542 ;; Pattern for Analysis:
544 ;; Step 1: Calculate DataTypes in Scope:
546 ;; a) Calculate the scope (above)
548 ;; Step 2: Parse context
550 ;; a) Identify function being called, or variable assignment,
551 ;; and find source tags for those references
552 ;; b) Identify the prefix (text cursor is on) and find the source
553 ;; tags for those references.
555 ;; Step 3: Assemble an object
560 (setq function
(semantic-ctxt-current-function))
563 ;; Calculate the argument for the function if there is one.
564 (setq arg
(semantic-ctxt-current-argument))
566 ;; Find a tag related to the function name.
569 (semantic-analyze-find-tag-sequence function scope
))
570 (error (semantic-analyze-push-error err
)))
572 ;; fntag can have the last entry as just a string, meaning we
573 ;; could not find the core datatype. In this case, the searches
574 ;; below will not work.
575 (when (stringp (car (last fntag
)))
576 ;; Take a wild guess!
577 (setcar (last fntag
) (semantic-tag (car (last fntag
)) 'function
))
581 (let ((fcn (semantic-find-tags-by-class 'function fntag
)))
583 (let ((ty (semantic-find-tags-by-class 'type fntag
)))
585 ;; We might have a constructor with the same name as
586 ;; the found datatype.
587 (setq fcn
(semantic-find-tags-by-name
588 (semantic-tag-name (car ty
))
589 (semantic-tag-type-members (car ty
))))
593 (when (semantic-tag-get-attribute (car lp
)
595 (setq fcn
(cons (car lp
) fcn
)))
597 ;; Give up, go old school
600 (setq fntagend
(car (reverse fcn
))
602 (when (semantic-tag-p fntagend
)
603 (nth (1- arg
) (semantic-tag-function-arguments fntagend
)))
608 ;; Only do work if we have bounds (meaning a prefix to complete)
613 (setq prefix
(semantic-analyze-find-tag-sequence
614 prefix scope
'prefixtypes
'unfindable
))
615 ;; If there's an alias, dereference it and analyze
618 (semantic-analyze-dereference-alias prefix
))
619 (setq prefix
(semantic-analyze-find-tag-sequence
620 newseq scope
'prefixtypes
'unfindable
))))
621 ;; Debug on error is off. Capture errors and move on
623 ;; NOTE: This line is duplicated in
624 ;; semantic-analyzer-debug-global-symbol
625 ;; You will need to update both places.
627 (setq prefix
(semantic-analyze-find-tag-sequence
628 prefix scope
'prefixtypes
))
630 (semantic-analyze-dereference-alias prefix
))
631 (setq prefix
(semantic-analyze-find-tag-sequence
632 newseq scope
'prefixtypes
))))
633 (error (semantic-analyze-push-error err
))))
640 ;; If we found a tag for our function, we can go into
641 ;; functional context analysis mode, meaning we have a type
644 (semantic-analyze-context-functionarg
645 :buffer
(current-buffer)
648 :argument
(list argtag
)
651 :prefixclass prefixclass
653 :prefixtypes prefixtypes
654 :errors semantic-analyze-error-stack
)))
656 ;; No function, try assignment
657 ((and (setq assign
(semantic-ctxt-current-assignment))
658 ;; We have some sort of an assignment
660 (setq asstag
(semantic-analyze-find-tag-sequence
661 assign scope nil nil
'mustbeclassvariable
))
662 (error (semantic-analyze-push-error err
)
666 (semantic-analyze-context-assignment
667 :buffer
(current-buffer)
672 :prefixclass prefixclass
673 :prefixtypes prefixtypes
674 :errors semantic-analyze-error-stack
)))
676 ;; TODO: Identify return value condition.
677 ;;((setq return .... what to do?)
681 ;; Nothing in particular
683 (semantic-analyze-context
684 :buffer
(current-buffer)
688 :prefixclass prefixclass
689 :prefixtypes prefixtypes
690 :errors semantic-analyze-error-stack
)))
692 (t (setq context-return nil
))
695 ;; Return our context.
698 (defun semantic-analyze-dereference-alias (taglist)
699 "Dereference first tag in TAGLIST if it is an alias.
700 Returns a sequence of names which can then be fed again into
701 `semantic-analyze-find-tag-sequence'.
702 Returns nil if no alias was found."
703 (when (eq (semantic-tag-get-attribute (car taglist
) :kind
) 'alias
)
705 (semantic-analyze-split-name
707 (car (semantic-tag-get-attribute (car taglist
) :members
))))))
708 (append (if (listp tagname
)
713 (defun semantic-adebug-analyze (&optional ctxt
)
714 "Perform `semantic-analyze-current-context'.
715 Display the results as a debug list.
716 Optional argument CTXT is the context to show."
718 (require 'data-debug
)
719 (let ((start (current-time))
720 (ctxt (or ctxt
(semantic-analyze-current-context))))
722 (message "No Analyzer Results")
723 (message "Analysis took %.2f seconds."
724 (semantic-elapsed-time start nil
))
725 (semantic-analyze-pulse ctxt
)
728 (data-debug-new-buffer "*Analyzer ADEBUG*")
729 (data-debug-insert-object-slots ctxt
"]"))
730 (message "No Context to analyze here.")))))
735 ;; Friendly output of a context analysis.
737 (declare-function pulse-momentary-highlight-region
"pulse")
739 (cl-defmethod semantic-analyze-pulse ((context semantic-analyze-context
))
740 "Pulse the region that CONTEXT affects."
742 (with-current-buffer (oref context
:buffer
)
743 (let ((bounds (oref context
:bounds
)))
745 (pulse-momentary-highlight-region (car bounds
) (cdr bounds
))))))
747 (defcustom semantic-analyze-summary-function
'semantic-format-tag-prototype
748 "Function to use when creating items in Imenu.
749 Some useful functions are found in `semantic-format-tag-functions'."
751 :type semantic-format-tag-custom-list
)
753 (defun semantic-analyze-princ-sequence (sequence &optional prefix buff
)
754 "Send the tag SEQUENCE to standard out.
755 Use PREFIX as a label.
756 Use BUFF as a source of override methods."
757 ;; If there is no sequence, at least show the field as being empty.
758 (unless sequence
(princ prefix
) (princ "<none>\n"))
760 ;; Display the sequence column aligned.
764 ((semantic-tag-p (car sequence
))
765 (princ (funcall semantic-analyze-summary-function
767 ((stringp (car sequence
))
769 (princ (semantic--format-colorize-text (car sequence
) 'variable
))
772 (princ (format "'%S" (car sequence
)))))
774 (setq sequence
(cdr sequence
))
775 (setq prefix
(make-string (length prefix
) ?
))
778 (cl-defmethod semantic-analyze-show ((context semantic-analyze-context
))
779 "Insert CONTEXT into the current buffer in a nice way."
780 (semantic-analyze-princ-sequence (oref context prefix
) "Prefix: " )
781 (semantic-analyze-princ-sequence (oref context prefixclass
) "Prefix Classes: ")
782 (semantic-analyze-princ-sequence (oref context prefixtypes
) "Prefix Types: ")
783 (semantic-analyze-princ-sequence (oref context errors
) "Encountered Errors: ")
785 ;(semantic-analyze-princ-sequence (oref context scopetypes) "Scope Types: ")
786 ;(semantic-analyze-princ-sequence (oref context scope) "Scope: ")
787 ;(semantic-analyze-princ-sequence (oref context localvariables) "LocalVars: ")
788 (when (oref context scope
)
789 (semantic-analyze-show (oref context scope
)))
792 (cl-defmethod semantic-analyze-show ((context semantic-analyze-context-assignment
))
793 "Insert CONTEXT into the current buffer in a nice way."
794 (semantic-analyze-princ-sequence (oref context assignee
) "Assignee: ")
795 (cl-call-next-method))
797 (cl-defmethod semantic-analyze-show ((context semantic-analyze-context-functionarg
))
798 "Insert CONTEXT into the current buffer in a nice way."
799 (semantic-analyze-princ-sequence (oref context function
) "Function: ")
800 (princ "Argument Index: ")
801 (princ (oref context index
))
803 (semantic-analyze-princ-sequence (oref context argument
) "Argument: ")
804 (cl-call-next-method))
806 (defun semantic-analyze-pop-to-context (context)
807 "Display CONTEXT in a temporary buffer.
808 CONTEXT's content is described in `semantic-analyze-current-context'."
809 (semantic-analyze-pulse context
)
810 (with-output-to-temp-buffer "*Semantic Context Analysis*"
811 (princ "Context Type: ")
812 (princ (eieio-object-name context
))
815 (princ (oref context bounds
))
817 (semantic-analyze-show context
)
819 (shrink-window-if-larger-than-buffer
820 (get-buffer-window "*Semantic Context Analysis*"))
823 (provide 'semantic
/analyze
)
826 ;; generated-autoload-file: "loaddefs.el"
827 ;; generated-autoload-load-name: "semantic/analyze"
830 ;;; semantic/analyze.el ends here