Function: semantic-calculate-scope

semantic-calculate-scope is an interactive and byte-compiled function defined in scope.el.gz.

Signature

(semantic-calculate-scope &optional POINT)

Documentation

Calculate the scope at POINT.

If POINT is not provided, then use the current location of point. The class returned from the scope calculation is variable semantic-scope-cache(var)/semantic-scope-cache(fun).

Key Bindings

Source Code

;; Defined in /usr/src/emacs/lisp/cedet/semantic/scope.el.gz
;;; ANALYZER
;;
;; Create the scope structure for use in the Analyzer.
;;
;;;###autoload
(defun semantic-calculate-scope (&optional point)
  "Calculate the scope at POINT.
If POINT is not provided, then use the current location of point.
The class returned from the scope calculation is variable
`semantic-scope-cache'."
  (interactive)
  (if (not (and (featurep 'semantic/db) semanticdb-current-database))
      nil ;; Don't do anything...
    (require 'semantic/db-typecache)
    (if (not point) (setq point (point)))
    (when (called-interactively-p 'any)
      (semantic-fetch-tags)
      (semantic-scope-reset-cache))
    (save-excursion
      (goto-char point)
      (let* ((TAG  (semantic-current-tag))
	     (scopecache
	      (semanticdb-cache-get semanticdb-current-table
				    'semantic-scope-cache))
	     )
	(when (not (semantic-equivalent-tag-p TAG (oref scopecache tag)))
	  (semantic-reset scopecache))
	(if (oref scopecache tag)
	    ;; Even though we can recycle most of the scope, we
	    ;; need to redo the local variables since those change
	    ;; as you move about the tag.
	    (condition-case nil
		(oset scopecache localvar (semantic-get-all-local-variables))
	      (error nil))

	  (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))
		 )
	    (oset scopecache tag TAG)
	    (oset scopecache scopetypes scopetypes)
	    (oset scopecache parents parents)
	    (oset scopecache parentinheritance parentinherited)

	    (let* (;; Step 2:
		   (scope (when (or scopetypes parents)
			    (semantic-analyze-scoped-tags scopetypes scopecache))
			  )
		   ;; Step 3:
		   (localargs (semantic-get-local-arguments))
		   (localvar (condition-case nil
				 (semantic-get-all-local-variables)
			       (error nil)))
		   )

	      ;; Try looking for parents again.
	      (when (not parentinherited)
		(setq parentinherited (semantic-analyze-scope-lineage-tags
				       parents (append scopetypes scope)))
		(when parentinherited
		  (oset scopecache parentinheritance parentinherited)
		  ;; Try calculating the scope again with the new inherited parent list.
		  (setq scope (when (or scopetypes parents)
				(semantic-analyze-scoped-tags scopetypes scopecache))
			)))

	      ;; Fill out the scope.
	      (oset scopecache scope scope)
	      (oset scopecache fullscope (append scopetypes scope parents))
	      (oset scopecache localargs localargs)
	      (oset scopecache localvar localvar)
	      )))
	;; Make sure we become dependent on the typecache.
	(semanticdb-typecache-add-dependant scopecache)
	;; Handy debug output.
	(when (called-interactively-p 'any)
	  (require 'eieio-datadebug)
	  (data-debug-show scopecache))
	;; Return ourselves, but make a clone first so that the caller
	;; can reset the scope cache without affecting others.
	(clone scopecache)))))