Function: semantic-analyze-scope-nested-tags-default

semantic-analyze-scope-nested-tags-default is a byte-compiled function defined in scope.el.gz.

Signature

(semantic-analyze-scope-nested-tags-default POSITION SCOPETYPES)

Documentation

Return a list of types in order of nesting for the context of POSITION.

If POSITION is in a method with a named parent, find that parent, and identify it's scope via overlay instead. Optional SCOPETYPES are additional scoped entities in which our parent might be found. This only finds ONE immediate parent by name. All other parents returned are from nesting data types.

Source Code

;; Defined in /usr/src/emacs/lisp/cedet/semantic/scope.el.gz
(defun semantic-analyze-scope-nested-tags-default (position scopetypes)
  "Return a list of types in order of nesting for the context of POSITION.
If POSITION is in a method with a named parent, find that parent, and
identify it's scope via overlay instead.
Optional SCOPETYPES are additional scoped entities in which our parent might
be found.
This only finds ONE immediate parent by name.  All other parents returned
are from nesting data types."
  (require 'semantic/analyze)
  (save-excursion
    (if position (goto-char position))
    (let* ((stack (reverse (semantic-find-tag-by-overlay (point))))
	   (tag (car stack))
	   (pparent (car (cdr stack)))
	   (returnlist nil)
	   )
      ;; 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))))

      ;; 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.
      ;;

      ;; If we have a pparent tag, let's go there
      ;; an analyze that stack of tags.
      (when (and pparent (semantic-tag-with-position-p pparent))
	(semantic-go-to-tag pparent)
	(setq stack (semantic-find-tag-by-overlay (point)))
	;; Step one, find the merged version of stack in the typecache.
	(let* ((stacknames (reverse (mapcar #'semantic-tag-name stack)))
	       (tc nil)
	       )
	  ;; @todo - can we use the typecache ability to
	  ;;         put a scope into a tag to do this?
	  (while (and stacknames
		      (setq tc (semanticdb-typecache-find
				(reverse stacknames))))
	    (setq returnlist (cons tc returnlist)
		  stacknames (cdr stacknames)))
	  (when (not returnlist)
	    ;; When there was nothing from the typecache, then just
	    ;; use what's right here.
	    (setq stack (reverse stack))
	    ;; Add things to STACK until we cease finding tags of class type.
	    (while (and stack (eq (semantic-tag-class (car stack)) 'type))
	      ;; Otherwise, just add this to the returnlist, but make
	      ;; sure we didn't already have that tag in scopetypes
             (unless (member (car stack) scopetypes)
               (setq returnlist (cons (car stack) returnlist)))
	     (setq stack (cdr stack)))

	    (setq returnlist (nreverse returnlist))
	    ))
	)

      ;; Only do this level of analysis for functions.
      (when (eq (semantic-tag-class tag) 'function)
	;; Step 2:
	;;   If the function tag itself has a "parent" by name, then that
	;;   parent will exist in the scope we just calculated, so look it
	;;   up now.
	;;
	(let ((p (semantic-tag-function-parent tag)))
	  (when p
	    ;; We have a parent, search for it.
	    (let* ((searchnameraw (cond ((stringp p) p)
					((semantic-tag-p p)
					 (semantic-tag-name p))
					((and (listp p) (stringp (car p)))
					 (car p))))
		   (searchname (semantic-analyze-split-name searchnameraw))
		   (snlist (if (consp searchname)
			       searchname
			     (list searchname)))
		   (fullsearchname nil)

		   (miniscope (semantic-scope-cache))
		   ptag)

	      ;; Find the next entry in the referenced type for
	      ;; our function, and append to return list till our
	      ;; returnlist is empty.
	      (while snlist
		(setq fullsearchname
		      (append (mapcar #'semantic-tag-name returnlist)
			      (list (car snlist)))) ;; Next one
		(setq ptag
		      (semanticdb-typecache-find fullsearchname))

		(when (or (not ptag)
			  (not (semantic-tag-of-class-p ptag 'type)))
		  (let ((rawscope
			 (apply #'append
				(mapcar #'semantic-tag-type-members
					(cons (car returnlist) scopetypes)
					)))
			)
		    (oset miniscope parents returnlist) ;; Not really accurate, but close
		    (oset miniscope scope rawscope)
		    (oset miniscope fullscope rawscope)
		    (setq ptag
			  (semantic-analyze-find-tag searchnameraw
						     'type
						     miniscope
						     ))
		    ))

		(when ptag
		  (when (and (not (semantic-tag-p ptag))
			     (semantic-tag-p (car ptag)))
		    (setq ptag (car ptag)))
		  (setq returnlist (append returnlist (list ptag)))
		  )

		(setq snlist (cdr snlist)))
	      (setq returnlist returnlist)
	      )))
	)
      returnlist
      )))