]> code.delx.au - gnu-emacs/blobdiff - lisp/cedet/semantic/scope.el
Merge from mainline.
[gnu-emacs] / lisp / cedet / semantic / scope.el
index a8654e90c07c485e70ed2b00fef2e367f3558553..f2472ef94104a3468431238be43726fecbba2d24 100644 (file)
@@ -1,6 +1,6 @@
 ;;; semantic/scope.el --- Analyzer Scope Calculations
 
-;; Copyright (C) 2007, 2008, 2009 Free Software Foundation, Inc.
+;; Copyright (C) 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
 
 ;; Author: Eric M. Ludlam <eric@siege-engine.com>
 
@@ -24,7 +24,7 @@
 ;; Calculate information about the current scope.
 ;;
 ;; Manages the current scope as a structure that can be cached on a
-;; per-file basis and recycled between different occurances of
+;; per-file basis and recycled between different occurrences of
 ;; analysis on different parts of a file.
 ;;
 ;; Pattern for Scope Calculation
@@ -67,7 +67,7 @@
               :documentation
               "The list of types currently in scope.
 For C++, this would contain anonymous namespaces known, and
-anything labled by a `using' statement.")
+anything labeled by a `using' statement.")
    (parents :initform nil
            :documentation
            "List of parents in scope w/in the body of this function.
@@ -239,8 +239,11 @@ are from nesting data types."
           )
       ;; In case of arg lists or some-such, throw out non-types.
       (while (and stack (not (semantic-tag-of-class-p pparent 'type)))
-       (setq stack (cdr stack)
-                   pparent (car (cdr stack))))
+       (setq stack (cdr stack) pparent (car (cdr stack))))
+
+      ;; Remove duplicates
+      (while (member pparent scopetypes)
+       (setq stack (cdr stack) pparent (car (cdr stack))))
 
       ;; Step 1:
       ;;    Analyze the stack of tags we are nested in as parents.
@@ -388,7 +391,7 @@ without use of \"object.function()\" style syntax due to an
 implicit \"object\".")
 
 (defun semantic-analyze-scoped-tags-default (typelist halfscope)
-  "Return accessable tags when TYPELIST and HALFSCOPE is in scope.
+  "Return accessible tags when TYPELIST and HALFSCOPE is in scope.
 HALFSCOPE is the current scope partially initialized.
 Tags returned are not in the global name space, but are instead
 scoped inside a class or namespace.  Such items can be referenced
@@ -556,8 +559,8 @@ PROTECTION specifies the type of access requested, such as 'public or 'private."
 Argument SCOPE specify additional tags that are in scope
 whose tags can be searched when needed, OR it may be a scope object.
 ACCESS is the level of access we filter on child supplied tags.
-For langauges with protection on specific methods or slots,
-it should strip out those not accessable by methods of TYPE.
+For languages with protection on specific methods or slots,
+it should strip out those not accessible by methods of TYPE.
 An ACCESS of 'public means not in a method of a subclass of type.
 A value of 'private means we can access private parts of the originating
 type."
@@ -602,28 +605,29 @@ whose tags can be searched when needed, OR it may be a scope object."
       ;;         for recycling later?  Should this become a helpful
       ;;         extra routine?
       (when (and parents (semantic-tag-with-position-p type))
-       ;; If TYPE has a position, go there and get the scope.
-       (semantic-go-to-tag type)
-
-       ;; We need to make a mini scope, and only include the misc bits
-       ;; that will help in finding the parent.  We don't really need
-       ;; to do any of the stuff related to variables and what-not.
-       (setq tmpscope (semantic-scope-cache "mini"))
-       (let* (;; Step 1:
-              (scopetypes (semantic-analyze-scoped-types (point)))
-              (parents (semantic-analyze-scope-nested-tags (point) scopetypes))
-              ;;(parentinherited (semantic-analyze-scope-lineage-tags parents scopetypes))
-              (lscope nil)
-              )
-         (oset tmpscope scopetypes scopetypes)
-         (oset tmpscope parents parents)
-         ;;(oset tmpscope parentinheritance parentinherited)
-
-         (when (or scopetypes parents)
-           (setq lscope (semantic-analyze-scoped-tags scopetypes tmpscope))
-           (oset tmpscope scope lscope))
-         (oset tmpscope fullscope (append scopetypes lscope parents))
-         ))
+       (save-excursion
+         ;; If TYPE has a position, go there and get the scope.
+         (semantic-go-to-tag type)
+
+         ;; We need to make a mini scope, and only include the misc bits
+         ;; that will help in finding the parent.  We don't really need
+         ;; to do any of the stuff related to variables and what-not.
+         (setq tmpscope (semantic-scope-cache "mini"))
+         (let* ( ;; Step 1:
+                (scopetypes (cons type (semantic-analyze-scoped-types (point))))
+                (parents (semantic-analyze-scope-nested-tags (point) scopetypes))
+                ;;(parentinherited (semantic-analyze-scope-lineage-tags parents scopetypes))
+                (lscope nil)
+                )
+           (oset tmpscope scopetypes scopetypes)
+           (oset tmpscope parents parents)
+           ;;(oset tmpscope parentinheritance parentinherited)
+
+           (when (or scopetypes parents)
+             (setq lscope (semantic-analyze-scoped-tags scopetypes tmpscope))
+             (oset tmpscope scope lscope))
+           (oset tmpscope fullscope (append scopetypes lscope parents))
+           )))
       ;; END creating tmpscope
 
       ;; Look up each parent one at a time.
@@ -662,10 +666,9 @@ The class returned from the scope calculation is variable
       nil ;; Don't do anything...
     (require 'semantic/db-typecache)
     (if (not point) (setq point (point)))
-    (when (interactive-p)
+    (when (called-interactively-p 'any)
       (semantic-fetch-tags)
-      (semantic-scope-reset-cache)
-      )
+      (semantic-scope-reset-cache))
     (save-excursion
       (goto-char point)
       (let* ((TAG  (semantic-current-tag))
@@ -725,15 +728,14 @@ The class returned from the scope calculation is variable
        ;; Make sure we become dependant on the typecache.
        (semanticdb-typecache-add-dependant scopecache)
        ;; Handy debug output.
-       (when (interactive-p)
+       (when (called-interactively-p 'any)
          (require 'eieio-datadebug)
-         (data-debug-show scopecache)
-         )
+         (data-debug-show scopecache))
        ;; Return ourselves
        scopecache))))
 
 (defun semantic-scope-find (name &optional class scope-in)
-  "Find the tag with NAME, and optinal CLASS in the current SCOPE-IN.
+  "Find the tag with NAME, and optional CLASS in the current SCOPE-IN.
 Searches various elements of the scope for NAME.  Return ALL the
 hits in order, with the first tag being in the closest scope."
   (let ((scope (or scope-in (semantic-calculate-scope)))
@@ -796,7 +798,7 @@ hits in order, with the first tag being in the closest scope."
 ;;
 (defmethod semantic-analyze-show ((context semantic-scope-cache))
   "Insert CONTEXT into the current buffer in a nice way."
-  (require 'semantic-analyze)
+  (require 'semantic/analyze)
   (semantic-analyze-princ-sequence (oref context scopetypes) "-> ScopeTypes: " )
   (semantic-analyze-princ-sequence (oref context parents) "-> Parents: " )
   (semantic-analyze-princ-sequence (oref context scope) "-> Scope: " )
@@ -809,8 +811,8 @@ hits in order, with the first tag being in the closest scope."
 
 ;; Local variables:
 ;; generated-autoload-file: "loaddefs.el"
-;; generated-autoload-feature: semantic/loaddefs
 ;; generated-autoload-load-name: "semantic/scope"
 ;; End:
 
+;; arch-tag: 056ab514-3e28-4d6e-84ed-9283dce5a01e
 ;;; semantic/scope.el ends here