1 ;;; semantic/scope.el --- Analyzer Scope Calculations
3 ;; Copyright (C) 2007-2012 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 ;; Calculate information about the current scope.
26 ;; Manages the current scope as a structure that can be cached on a
27 ;; per-file basis and recycled between different occurrences of
28 ;; analysis on different parts of a file.
30 ;; Pattern for Scope Calculation
32 ;; Step 1: Calculate DataTypes in Scope:
34 ;; a) What is in scope via using statements or local namespaces
35 ;; b) Lineage of current context. Some names drawn from step 1.
37 ;; Step 2: Convert type names into lists of concrete tags
39 ;; a) Convert each datatype into the real datatype tag
40 ;; b) Convert namespaces into the list of contents of the namespace.
41 ;; c) Merge all existing scopes together into one search list.
43 ;; Step 3: Local variables
45 ;; a) Local variables are in the master search list.
48 (require 'semantic/db)
49 (require 'semantic/analyze/fcn)
50 (require 'semantic/ctxt)
52 (eval-when-compile (require 'semantic/find))
54 (declare-function data-debug-show "eieio-datadebug")
55 (declare-function semantic-analyze-find-tag "semantic/analyze")
56 (declare-function semantic-analyze-princ-sequence "semantic/analyze")
57 (declare-function semanticdb-typecache-merge-streams "semantic/db-typecache")
58 (declare-function semanticdb-typecache-add-dependant "semantic/db-typecache")
59 (declare-function semantic-tag-similar-p "semantic/tag-ls")
63 (defclass semantic-scope-cache (semanticdb-abstract-cache)
66 "The tag this scope was calculated for.")
67 (scopetypes :initform nil
69 "The list of types currently in scope.
70 For C++, this would contain anonymous namespaces known, and
71 anything labeled by a `using' statement.")
72 (parents :initform nil
74 "List of parents in scope w/in the body of this function.
75 Presumably, the members of these parent classes are available for access
76 based on private:, or public: style statements.")
77 (parentinheritance :initform nil
78 :documentation "Alist of parents by inheritance.
79 Each entry is ( PARENT . PROTECTION ), where PARENT is a type, and
80 PROTECTION is a symbol representing the level of inheritance, such as 'private, or 'protected.")
83 "Items in scope due to the scopetypes or parents.")
84 (fullscope :initform nil
86 "All the other stuff on one master list you can search.")
87 (localargs :initform nil
89 "The arguments to the function tag.")
90 (localvar :initform nil
92 "The local variables.")
93 (typescope :initform nil
95 "Slot to save intermediate scope while metatypes are dereferenced.")
97 "Cache used for storage of the current scope by the Semantic Analyzer.
98 Saves scoping information between runs of the analyzer.")
102 ;; Methods for basic management of the structure in semanticdb.
104 (defmethod semantic-reset ((obj semantic-scope-cache))
105 "Reset OBJ back to it's empty settings."
107 (oset obj scopetypes nil)
108 (oset obj parents nil)
109 (oset obj parentinheritance nil)
111 (oset obj fullscope nil)
112 (oset obj localargs nil)
113 (oset obj localvar nil)
114 (oset obj typescope nil)
117 (defmethod semanticdb-synchronize ((cache semantic-scope-cache)
119 "Synchronize a CACHE with some NEW-TAGS."
120 (semantic-reset cache))
123 (defmethod semanticdb-partial-synchronize ((cache semantic-scope-cache)
125 "Synchronize a CACHE with some changed NEW-TAGS."
126 ;; If there are any includes or datatypes changed, then clear.
127 (if (or (semantic-find-tags-by-class 'include new-tags)
128 (semantic-find-tags-by-class 'type new-tags)
129 (semantic-find-tags-by-class 'using new-tags))
130 (semantic-reset cache))
133 (defun semantic-scope-reset-cache ()
134 "Get the current cached scope, and reset it."
135 (when semanticdb-current-table
136 (let ((co (semanticdb-cache-get semanticdb-current-table
137 semantic-scope-cache)))
138 (semantic-reset co))))
140 (defmethod semantic-scope-set-typecache ((cache semantic-scope-cache)
142 "Set the :typescope property on CACHE to some types.
143 TYPES-IN-SCOPE is a list of type tags whos members are
144 currently in scope. For each type in TYPES-IN-SCOPE,
145 add those members to the types list.
146 If nil, then the typescope is reset."
147 (let ((newts nil)) ;; New Type Scope
148 (dolist (onetype types-in-scope)
149 (setq newts (append (semantic-tag-type-members onetype)
152 (oset cache typescope newts)))
156 ;; These fcns should be used by search routines that return a single
157 ;; tag which, in turn, may have come from a deep scope. The scope
158 ;; will be attached to the tag. Thus, in future scope based calls, a
159 ;; tag can be passed in and a scope derived from it.
161 (defun semantic-scope-tag-clone-with-scope (tag scopetags)
162 "Clone TAG, and return it. Add SCOPETAGS as a tag-local scope.
163 Stores the SCOPETAGS as a set of tag properties on the cloned tag."
164 (let ((clone (semantic-tag-clone tag))
166 (semantic--tag-put-property clone 'scope scopetags)
169 (defun semantic-scope-tag-get-scope (tag)
170 "Get from TAG the list of tags comprising the scope from TAG."
171 (semantic--tag-get-property tag 'scope))
175 ;; Functions that do the main scope calculations
178 (define-overloadable-function semantic-analyze-scoped-types (position)
179 "Return a list of types currently in scope at POSITION.
180 This is based on what tags exist at POSITION, and any associated
183 (defun semantic-analyze-scoped-types-default (position)
184 "Return a list of types currently in scope at POSITION.
185 Use `semantic-ctxt-scoped-types' to find types."
186 (require 'semantic/db-typecache)
189 (let ((code-scoped-types nil))
190 ;; Let's ask if any types are currently scoped. Scoped
191 ;; classes and types provide their public methods and types
192 ;; in source code, but are unrelated hierarchically.
193 (let ((sp (semantic-ctxt-scoped-types)))
195 ;; Get this thing as a tag
198 (semanticdb-typecache-find (car sp)))
199 ;(semantic-analyze-find-tag (car sp) 'type))
200 ((semantic-tag-p (car sp))
201 (if (semantic-tag-prototype-p (car sp))
202 (semanticdb-typecache-find (semantic-tag-name (car sp)))
203 ;;(semantic-analyze-find-tag (semantic-tag-name (car sp)) 'type)
207 (setq code-scoped-types
208 (cons tmp code-scoped-types))))
210 (setq code-scoped-types (nreverse code-scoped-types))
212 (when code-scoped-types
213 (semanticdb-typecache-merge-streams code-scoped-types nil))
217 ;;------------------------------------------------------------
218 (define-overloadable-function semantic-analyze-scope-nested-tags (position scopedtypes)
219 "Return a list of types in order of nesting for the context of POSITION.
220 If POSITION is in a method with a named parent, find that parent, and
221 identify it's scope via overlay instead.
222 Optional SCOPETYPES are additional scoped entities in which our parent might
225 (defun semantic-analyze-scope-nested-tags-default (position scopetypes)
226 "Return a list of types in order of nesting for the context of POSITION.
227 If POSITION is in a method with a named parent, find that parent, and
228 identify it's scope via overlay instead.
229 Optional SCOPETYPES are additional scoped entities in which our parent might
231 This only finds ONE immediate parent by name. All other parents returned
232 are from nesting data types."
233 (require 'semantic/analyze)
235 (if position (goto-char position))
236 (let* ((stack (reverse (semantic-find-tag-by-overlay (point))))
238 (pparent (car (cdr stack)))
241 ;; In case of arg lists or some-such, throw out non-types.
242 (while (and stack (not (semantic-tag-of-class-p pparent 'type)))
243 (setq stack (cdr stack) pparent (car (cdr stack))))
246 (while (member pparent scopetypes)
247 (setq stack (cdr stack) pparent (car (cdr stack))))
250 ;; Analyze the stack of tags we are nested in as parents.
253 ;; If we have a pparent tag, let's go there
254 ;; an analyze that stack of tags.
255 (when (and pparent (semantic-tag-with-position-p pparent))
256 (semantic-go-to-tag pparent)
257 (setq stack (semantic-find-tag-by-overlay (point)))
258 ;; Step one, find the merged version of stack in the typecache.
259 (let* ((stacknames (reverse (mapcar 'semantic-tag-name stack)))
262 ;; @todo - can we use the typecache ability to
263 ;; put a scope into a tag to do this?
264 (while (and stacknames
265 (setq tc (semanticdb-typecache-find
266 (reverse stacknames))))
267 (setq returnlist (cons tc returnlist)
268 stacknames (cdr stacknames)))
269 (when (not returnlist)
270 ;; When there was nothing from the typecache, then just
271 ;; use what's right here.
272 (setq stack (reverse stack))
273 ;; Add things to STACK until we cease finding tags of class type.
274 (while (and stack (eq (semantic-tag-class (car stack)) 'type))
275 ;; Otherwise, just add this to the returnlist, but make
276 ;; sure we didn't already have that tag in scopetypes
277 (unless (member (car stack) scopetypes)
278 (setq returnlist (cons (car stack) returnlist)))
279 (setq stack (cdr stack)))
281 (setq returnlist (nreverse returnlist))
285 ;; Only do this level of analysis for functions.
286 (when (eq (semantic-tag-class tag) 'function)
288 ;; If the function tag itself has a "parent" by name, then that
289 ;; parent will exist in the scope we just calculated, so look it
292 (let ((p (semantic-tag-function-parent tag)))
294 ;; We have a parent, search for it.
295 (let* ((searchnameraw (cond ((stringp p) p)
297 (semantic-tag-name p))
298 ((and (listp p) (stringp (car p)))
300 (searchname (semantic-analyze-split-name searchnameraw))
301 (snlist (if (consp searchname)
306 (miniscope (semantic-scope-cache "mini"))
309 ;; Find the next entry in the referenced type for
310 ;; our function, and append to return list till our
311 ;; returnlist is empty.
314 (append (mapcar 'semantic-tag-name returnlist)
315 (list (car snlist)))) ;; Next one
317 (semanticdb-typecache-find fullsearchname))
320 (not (semantic-tag-of-class-p ptag 'type)))
323 (mapcar 'semantic-tag-type-members
324 (cons (car returnlist) scopetypes)
327 (oset miniscope parents returnlist) ;; Not really accurate, but close
328 (oset miniscope scope rawscope)
329 (oset miniscope fullscope rawscope)
331 (semantic-analyze-find-tag searchnameraw
338 (when (and (not (semantic-tag-p ptag))
339 (semantic-tag-p (car ptag)))
340 (setq ptag (car ptag)))
341 (setq returnlist (append returnlist (list ptag)))
344 (setq snlist (cdr snlist)))
345 (setq returnlist returnlist)
351 (define-overloadable-function semantic-analyze-scope-lineage-tags (parents scopedtypes)
352 "Return the full lineage of tags from PARENTS.
353 The return list is of the form ( TAG . PROTECTION ), where TAG is a tag,
354 and PROTECTION is the level of protection offered by the relationship.
355 Optional SCOPETYPES are additional scoped entities in which our parent might
358 (defun semantic-analyze-scope-lineage-tags-default (parents scopetypes)
359 "Return the full lineage of tags from PARENTS.
360 The return list is of the form ( TAG . PROTECTION ), where TAG is a tag,
361 and PROTECTION is the level of protection offered by the relationship.
362 Optional SCOPETYPES are additional scoped entities in which our parent might
365 (miniscope (semantic-scope-cache "mini"))
367 (oset miniscope parents parents)
368 (oset miniscope scope scopetypes)
369 (oset miniscope fullscope scopetypes)
371 (dolist (slp parents)
372 (semantic-analyze-scoped-inherited-tag-map
373 slp (lambda (newparent)
374 (let* ((pname (semantic-tag-name newparent))
375 (prot (semantic-tag-type-superclass-protection slp pname))
376 (effectiveprot (cond ((eq prot 'public)
377 ;; doesn't provide access to private slots?
380 (push (cons newparent effectiveprot) lineage)
387 ;;------------------------------------------------------------
389 (define-overloadable-function semantic-analyze-scoped-tags (typelist parentlist)
390 "Return accessible tags when TYPELIST and PARENTLIST is in scope.
391 Tags returned are not in the global name space, but are instead
392 scoped inside a class or namespace. Such items can be referenced
393 without use of \"object.function()\" style syntax due to an
394 implicit \"object\".")
396 (defun semantic-analyze-scoped-tags-default (typelist halfscope)
397 "Return accessible tags when TYPELIST and HALFSCOPE is in scope.
398 HALFSCOPE is the current scope partially initialized.
399 Tags returned are not in the global name space, but are instead
400 scoped inside a class or namespace. Such items can be referenced
401 without use of \"object.function()\" style syntax due to an
402 implicit \"object\"."
403 (let ((typelist2 nil)
405 (parentlist (oref halfscope parents))
406 (miniscope halfscope)
408 ;; Loop over typelist, and find and merge all namespaces matching
409 ;; the names in typelist.
411 (let ((tt (semantic-tag-type (car typelist))))
412 (when (and (stringp tt) (string= tt "namespace"))
413 ;; By using the typecache, our namespaces are pre-merged.
414 (setq typelist2 (cons (car typelist) typelist2))
416 (setq typelist (cdr typelist)))
418 ;; Loop over the types (which should be sorted by position)
419 ;; adding to the scopelist as we go, and using the scopelist
420 ;; for additional searching!
422 (oset miniscope scope currentscope)
423 (oset miniscope fullscope currentscope)
424 (setq currentscope (append
425 (semantic-analyze-scoped-type-parts (car typelist2)
428 (setq typelist2 (cdr typelist2)))
430 ;; Collect all the types (class, etc) that are in our heritage.
431 ;; These are types that we can extract members from, not those
432 ;; declared in using statements, or the like.
433 ;; Get the PARENTS including nesting scope for this location.
435 (oset miniscope scope currentscope)
436 (oset miniscope fullscope currentscope)
437 (setq currentscope (append
438 (semantic-analyze-scoped-type-parts (car parentlist)
441 (setq parentlist (cdr parentlist)))
443 ;; Loop over all the items, and collect any type constants.
444 (let ((constants nil))
445 (dolist (T currentscope)
446 (setq constants (append constants
447 (semantic-analyze-type-constants T)))
450 (setq currentscope (append currentscope constants)))
454 ;;------------------------------------------------------------
455 (define-overloadable-function semantic-analyze-scope-calculate-access (type scope)
456 "Calculate the access class for TYPE as defined by the current SCOPE.
457 Access is related to the :parents in SCOPE. If type is a member of SCOPE
458 then access would be 'private. If TYPE is inherited by a member of SCOPE,
459 the access would be 'protected. Otherwise, access is 'public")
461 (defun semantic-analyze-scope-calculate-access-default (type scope)
462 "Calculate the access class for TYPE as defined by the current SCOPE."
463 (cond ((semantic-scope-cache-p scope)
464 (let ((parents (oref scope parents))
465 (parentsi (oref scope parentinheritance))
468 ;; Investigate the parent, and see how it relates to type.
469 ;; If these tags are basically the same, then we have full access.
471 (when (semantic-tag-similar-p type p)
472 (throw 'moose 'private))
474 ;; Look to see if type is in our list of inherited parents.
475 (dolist (pi parentsi)
476 ;; pi is a cons cell ( PARENT . protection)
479 (when (semantic-tag-similar-p type pip)
481 ;; protection via inheritance means to pull out different
482 ;; bits based on protection labels in an opposite way.
485 (protected . protected)
486 (private . public))))
489 ;; Not in our parentage. Is type a FRIEND?
490 (let ((friends (semantic-find-tags-by-class 'friend (semantic-tag-type-members type))))
493 (if (string= (semantic-tag-name F) (semantic-tag-name pi))
494 (throw 'moose 'private))
496 ;; Found nothing, return public
501 (defun semantic-completable-tags-from-type (type)
502 "Return a list of slots that are valid completions from the list of SLOTS.
503 If a tag in SLOTS has a named parent, then that implies that the
504 tag is not something you can complete from within TYPE."
505 (let ((allslots (semantic-tag-components type))
509 (when (or (not (semantic-tag-of-class-p S 'function))
510 (not (semantic-tag-function-parent S)))
511 (setq leftover (cons S leftover)))
513 (nreverse leftover)))
515 (defun semantic-analyze-scoped-type-parts (type &optional scope noinherit protection)
516 "Return all parts of TYPE, a tag representing a TYPE declaration.
517 SCOPE is the scope object.
518 NOINHERIT turns off searching of inherited tags.
519 PROTECTION specifies the type of access requested, such as 'public or 'private."
522 (let* ((access (semantic-analyze-scope-calculate-access type scope))
523 ;; SLOTS are the slots directly a part of TYPE.
524 (allslots (semantic-completable-tags-from-type type))
525 (slots (semantic-find-tags-by-scope-protection
528 (fname (semantic-tag-file-name type))
529 ;; EXTMETH are externally defined methods that are still
530 ;; a part of this class.
532 ;; @TODO - is this line needed?? Try w/out for a while
533 ;; @note - I think C++ says no. elisp might, but methods
534 ;; look like defuns, so it makes no difference.
535 (extmeth nil) ; (semantic-tag-external-member-children type t))
537 ;; INHERITED are tags found in classes that our TYPE tag
538 ;; inherits from. Do not do this if it was not requested.
539 (inherited (when (not noinherit)
540 (semantic-analyze-scoped-inherited-tags type scope
543 (when (not (semantic-tag-in-buffer-p type))
544 (let ((copyslots nil))
546 ;;(semantic--tag-put-property TAG :filename fname)
547 (if (semantic-tag-file-name TAG)
548 ;; If it has a filename, just go with it...
549 (setq copyslots (cons TAG copyslots))
550 ;; Otherwise, copy the tag w/ the guessed filename.
551 (setq copyslots (cons (semantic-tag-copy TAG nil fname)
554 (setq slots (nreverse copyslots))
556 ;; Flatten the database output.
557 (append slots extmeth inherited)
560 (defun semantic-analyze-scoped-inherited-tags (type scope access)
561 "Return all tags that TYPE inherits from.
562 Argument SCOPE specify additional tags that are in scope
563 whose tags can be searched when needed, OR it may be a scope object.
564 ACCESS is the level of access we filter on child supplied tags.
565 For languages with protection on specific methods or slots,
566 it should strip out those not accessible by methods of TYPE.
567 An ACCESS of 'public means not in a method of a subclass of type.
568 A value of 'private means we can access private parts of the originating
571 (semantic-analyze-scoped-inherited-tag-map
573 (let* ((pname (semantic-tag-name p))
574 (protection (semantic-tag-type-superclass-protection
577 (if (and (eq access 'public) (not (eq protection 'public)))
580 ;; We can get some parts of this type.
582 ;; Do not pull in inherited parts here. Those
583 ;; will come via the inherited-tag-map fcn
584 (semantic-analyze-scoped-type-parts
585 p scope t protection))
590 (defun semantic-analyze-scoped-inherited-tag-map (type fcn scope)
591 "Map all parents of TYPE to FCN. Return tags of all the types.
592 Argument SCOPE specify additional tags that are in scope
593 whose tags can be searched when needed, OR it may be a scope object."
594 (require 'semantic/analyze)
595 (let* (;; PARENTS specifies only the superclasses and not
596 ;; interfaces. Inheriting from an interfaces implies
597 ;; you have a copy of all methods locally. I think.
598 (parents (semantic-tag-type-superclasses type))
604 ;; Create a SCOPE just for looking up the parent based on where
605 ;; the parent came from.
607 ;; @TODO - Should we cache these mini-scopes around in Emacs
608 ;; for recycling later? Should this become a helpful
610 (when (and parents (semantic-tag-with-position-p type))
612 ;; If TYPE has a position, go there and get the scope.
613 (semantic-go-to-tag type)
615 ;; We need to make a mini scope, and only include the misc bits
616 ;; that will help in finding the parent. We don't really need
617 ;; to do any of the stuff related to variables and what-not.
618 (setq tmpscope (semantic-scope-cache "mini"))
620 (scopetypes (cons type (semantic-analyze-scoped-types (point))))
621 (parents (semantic-analyze-scope-nested-tags (point) scopetypes))
622 ;;(parentinherited (semantic-analyze-scope-lineage-tags parents scopetypes))
625 (oset tmpscope scopetypes scopetypes)
626 (oset tmpscope parents parents)
627 ;;(oset tmpscope parentinheritance parentinherited)
629 (when (or scopetypes parents)
630 (setq lscope (semantic-analyze-scoped-tags scopetypes tmpscope))
631 (oset tmpscope scope lscope))
632 (oset tmpscope fullscope (append scopetypes lscope parents))
634 ;; END creating tmpscope
636 ;; Look up each parent one at a time.
638 (setq ps (cond ((stringp p) p)
639 ((and (semantic-tag-p p) (semantic-tag-prototype-p p))
640 (semantic-tag-name p))
641 ((and (listp p) (stringp (car p)))
643 pt (condition-case nil
644 (or (semantic-analyze-find-tag ps 'type tmpscope)
646 (semantic-analyze-find-tag ps 'type scope))
651 ;; Note that we pass the original SCOPE in while recursing.
652 ;; so that the correct inheritance model is passed along.
653 (semantic-analyze-scoped-inherited-tag-map pt fcn scope)
659 ;; Create the scope structure for use in the Analyzer.
662 (defun semantic-calculate-scope (&optional point)
663 "Calculate the scope at POINT.
664 If POINT is not provided, then use the current location of point.
665 The class returned from the scope calculation is variable
666 `semantic-scope-cache'."
668 (if (not (and (featurep 'semantic/db) semanticdb-current-database))
669 nil ;; Don't do anything...
670 (require 'semantic/db-typecache)
671 (if (not point) (setq point (point)))
672 (when (called-interactively-p 'any)
673 (semantic-fetch-tags)
674 (semantic-scope-reset-cache))
677 (let* ((TAG (semantic-current-tag))
679 (semanticdb-cache-get semanticdb-current-table
680 semantic-scope-cache))
682 (when (not (semantic-equivalent-tag-p TAG (oref scopecache tag)))
683 (semantic-reset scopecache))
684 (if (oref scopecache tag)
685 ;; Even though we can recycle most of the scope, we
686 ;; need to redo the local variables since those change
687 ;; as you move about the tag.
689 (oset scopecache localvar (semantic-get-all-local-variables))
693 (scopetypes (semantic-analyze-scoped-types point))
694 (parents (semantic-analyze-scope-nested-tags point scopetypes))
695 (parentinherited (semantic-analyze-scope-lineage-tags
698 (oset scopecache tag TAG)
699 (oset scopecache scopetypes scopetypes)
700 (oset scopecache parents parents)
701 (oset scopecache parentinheritance parentinherited)
704 (scope (when (or scopetypes parents)
705 (semantic-analyze-scoped-tags scopetypes scopecache))
708 (localargs (semantic-get-local-arguments))
709 (localvar (condition-case nil
710 (semantic-get-all-local-variables)
714 ;; Try looking for parents again.
715 (when (not parentinherited)
716 (setq parentinherited (semantic-analyze-scope-lineage-tags
717 parents (append scopetypes scope)))
718 (when parentinherited
719 (oset scopecache parentinheritance parentinherited)
720 ;; Try calculating the scope again with the new inherited parent list.
721 (setq scope (when (or scopetypes parents)
722 (semantic-analyze-scoped-tags scopetypes scopecache))
725 ;; Fill out the scope.
726 (oset scopecache scope scope)
727 (oset scopecache fullscope (append scopetypes scope parents))
728 (oset scopecache localargs localargs)
729 (oset scopecache localvar localvar)
731 ;; Make sure we become dependent on the typecache.
732 (semanticdb-typecache-add-dependant scopecache)
733 ;; Handy debug output.
734 (when (called-interactively-p 'any)
735 (require 'eieio-datadebug)
736 (data-debug-show scopecache))
740 (defun semantic-scope-find (name &optional class scope-in)
741 "Find the tag with NAME, and optional CLASS in the current SCOPE-IN.
742 Searches various elements of the scope for NAME. Return ALL the
743 hits in order, with the first tag being in the closest scope."
744 (let ((scope (or scope-in (semantic-calculate-scope)))
746 ;; Is the passed in scope really a scope? if so, look through
747 ;; the options in that scope.
748 (if (semantic-scope-cache-p scope)
750 ;; This should be first, but bugs in the
751 ;; C parser will turn function calls into
752 ;; assumed int return function prototypes. Yuck!
753 (semantic-find-tags-by-name name (oref scope localargs)))
755 (semantic-find-tags-by-name name (oref scope localvar)))
756 (fullscoperaw (oref scope fullscope))
757 (sc (semantic-find-tags-by-name name fullscoperaw))
758 (typescoperaw (oref scope typescope))
759 (tsc (semantic-find-tags-by-name name typescoperaw))
763 ;; Scan out things not of the right class.
764 (semantic-find-tags-by-class class (append la lv sc tsc))
765 (append la lv sc tsc))
768 (when (and (not ans) (or typescoperaw fullscoperaw))
769 (let ((namesplit (semantic-analyze-split-name name)))
770 (when (consp namesplit)
771 ;; It may be we need to hack our way through type typescope.
774 (semantic-find-tags-by-name (car namesplit)
776 (semantic-find-tags-by-name (car namesplit)
780 (setq typescoperaw nil)
781 (when (cdr namesplit)
782 (setq typescoperaw (semantic-tag-type-members
785 (setq namesplit (cdr namesplit)))
786 ;; Once done, store the current typecache lookup
787 (oset scope typescope
788 (append typescoperaw (oref scope typescope)))
792 ;; Not a real scope. Our scope calculation analyze parts of
793 ;; what it finds, and needs to pass lists through to do it's work.
794 ;; Tread that list as a singly entry.
796 (semantic-find-tags-by-class class scope)
802 (defmethod semantic-analyze-show ((context semantic-scope-cache))
803 "Insert CONTEXT into the current buffer in a nice way."
804 (require 'semantic/analyze)
805 (semantic-analyze-princ-sequence (oref context scopetypes) "-> ScopeTypes: " )
806 (semantic-analyze-princ-sequence (oref context parents) "-> Parents: " )
807 (semantic-analyze-princ-sequence (oref context scope) "-> Scope: " )
808 ;;(semantic-analyze-princ-sequence (oref context fullscope) "Fullscope: " )
809 (semantic-analyze-princ-sequence (oref context localargs) "-> Local Args: " )
810 (semantic-analyze-princ-sequence (oref context localvar) "-> Local Vars: " )
813 (provide 'semantic/scope)
816 ;; generated-autoload-file: "loaddefs.el"
817 ;; generated-autoload-load-name: "semantic/scope"
820 ;;; semantic/scope.el ends here