]> code.delx.au - gnu-emacs/blobdiff - lisp/cedet/semantic/scope.el
Update copyright year to 2016
[gnu-emacs] / lisp / cedet / semantic / scope.el
index 13e858ca000232447ede78eaf4f0fddcdc811faf..ddef5105892c4612d9ac97bfe0a555d515b85fd1 100644 (file)
@@ -1,6 +1,6 @@
 ;;; semantic/scope.el --- Analyzer Scope Calculations
 
-;; Copyright (C) 2007-2013 Free Software Foundation, Inc.
+;; Copyright (C) 2007-2016 Free Software Foundation, Inc.
 
 ;; Author: Eric M. Ludlam <eric@siege-engine.com>
 
@@ -101,7 +101,7 @@ Saves scoping information between runs of the analyzer.")
 ;;
 ;; Methods for basic management of the structure in semanticdb.
 ;;
-(defmethod semantic-reset ((obj semantic-scope-cache))
+(cl-defmethod semantic-reset ((obj semantic-scope-cache))
   "Reset OBJ back to it's empty settings."
   (oset obj tag nil)
   (oset obj scopetypes nil)
@@ -114,13 +114,13 @@ Saves scoping information between runs of the analyzer.")
   (oset obj typescope nil)
   )
 
-(defmethod semanticdb-synchronize ((cache semantic-scope-cache)
+(cl-defmethod semanticdb-synchronize ((cache semantic-scope-cache)
                                   new-tags)
   "Synchronize a CACHE with some NEW-TAGS."
   (semantic-reset cache))
 
 
-(defmethod semanticdb-partial-synchronize ((cache semantic-scope-cache)
+(cl-defmethod semanticdb-partial-synchronize ((cache semantic-scope-cache)
                                           new-tags)
   "Synchronize a CACHE with some changed NEW-TAGS."
   ;; If there are any includes or datatypes changed, then clear.
@@ -134,10 +134,10 @@ Saves scoping information between runs of the analyzer.")
   "Get the current cached scope, and reset it."
   (when semanticdb-current-table
     (let ((co (semanticdb-cache-get semanticdb-current-table
-                                   semantic-scope-cache)))
+                                   'semantic-scope-cache)))
       (semantic-reset co))))
 
-(defmethod semantic-scope-set-typecache ((cache semantic-scope-cache)
+(cl-defmethod semantic-scope-set-typecache ((cache semantic-scope-cache)
                                         types-in-scope)
   "Set the :typescope property on CACHE to some types.
 TYPES-IN-SCOPE is a list of type tags whos members are
@@ -195,12 +195,18 @@ Use `semantic-ctxt-scoped-types' to find types."
          ;; Get this thing as a tag
          (let ((tmp (cond
                      ((stringp (car sp))
-                      (semanticdb-typecache-find (car sp)))
-                      ;(semantic-analyze-find-tag (car sp) 'type))
+                      (or (semanticdb-typecache-find (car sp))
+                          ;; If we did not find it in the typecache,
+                          ;; look in the tags we found so far
+                          (car (semantic-deep-find-tags-by-name
+                                (car sp)
+                                code-scoped-types))))
                      ((semantic-tag-p (car sp))
                       (if (semantic-tag-prototype-p (car sp))
-                          (semanticdb-typecache-find (semantic-tag-name (car sp)))
-                          ;;(semantic-analyze-find-tag (semantic-tag-name (car sp)) 'type)
+                          (or (semanticdb-typecache-find (semantic-tag-name (car sp)))
+                              (car (semantic-deep-find-tags-by-name
+                                    (semantic-tag-name (car sp))
+                                    code-scoped-types)))
                         (car sp)))
                      (t nil))))
            (when tmp
@@ -506,10 +512,33 @@ tag is not something you can complete from within TYPE."
        (leftover nil)
        )
     (dolist (S allslots)
-      (when (or (not (semantic-tag-of-class-p S 'function))
-               (not (semantic-tag-function-parent S)))
-       (setq leftover (cons S leftover)))
-      )
+      ;; We have to specially deal with 'using' tags here, since those
+      ;; pull in namespaces or classes into the current scope.
+      ;; (Should this go into c.el? If so, into which override?)
+      (if (semantic-tag-of-class-p S 'using)
+         (let* ((fullname (semantic-analyze-unsplit-name
+                           (list (semantic-tag-name type)
+                                 (semantic-tag-name S))))
+                ;; Search the typecache, first for the unqualified name
+                (usingtype (or
+                             (semanticdb-typecache-find (semantic-tag-name S))
+                             ;; If that didn't return anything, use
+                             ;; fully qualified name
+                             (semanticdb-typecache-find fullname)))
+                (filename (when usingtype (semantic-tag-file-name usingtype))))
+           (when usingtype
+             ;; Use recursion to examine that namespace or class
+             (let ((tags (semantic-completable-tags-from-type usingtype)))
+               (if filename
+                   ;; If we have a filename, copy the tags with it
+                   (dolist (cur tags)
+                     (setq leftover (cons (semantic-tag-copy cur nil filename)
+                                          leftover)))
+                 ;; Otherwise just run with it
+                 (setq leftover (append tags leftover))))))
+       (when (or (not (semantic-tag-of-class-p S 'function))
+                 (not (semantic-tag-function-parent S)))
+         (setq leftover (cons S leftover)))))
     (nreverse leftover)))
 
 (defun semantic-analyze-scoped-type-parts (type &optional scope noinherit protection)
@@ -677,7 +706,7 @@ The class returned from the scope calculation is variable
       (let* ((TAG  (semantic-current-tag))
             (scopecache
              (semanticdb-cache-get semanticdb-current-table
-                                   semantic-scope-cache))
+                                   'semantic-scope-cache))
             )
        (when (not (semantic-equivalent-tag-p TAG (oref scopecache tag)))
          (semantic-reset scopecache))
@@ -734,8 +763,9 @@ The class returned from the scope calculation is variable
        (when (called-interactively-p 'any)
          (require 'eieio-datadebug)
          (data-debug-show scopecache))
-       ;; Return ourselves
-       scopecache))))
+       ;; Return ourselves, but make a clone first so that the caller
+       ;; can reset the scope cache without affecting others.
+       (clone scopecache)))))
 
 (defun semantic-scope-find (name &optional class scope-in)
   "Find the tag with NAME, and optional CLASS in the current SCOPE-IN.
@@ -799,7 +829,7 @@ hits in order, with the first tag being in the closest scope."
 
 ;;; DUMP
 ;;
-(defmethod semantic-analyze-show ((context semantic-scope-cache))
+(cl-defmethod semantic-analyze-show ((context semantic-scope-cache))
   "Insert CONTEXT into the current buffer in a nice way."
   (require 'semantic/analyze)
   (semantic-analyze-princ-sequence (oref context scopetypes) "-> ScopeTypes: " )