Function: semanticdb-typecache-find-method

semanticdb-typecache-find-method is a byte-compiled function defined in db-typecache.el.gz.

Signature

(semanticdb-typecache-find-method ARG &rest ARGS)

Implementations

((table semanticdb-abstract-table) type find-file-match) in `semantic/db-typecache.el'.

Search the typecache in TABLE for the datatype TYPE. If type is a string, split the string, and search for the parts. If type is a list, treat the type as a pre-split string. If FIND-FILE-MATCH is non-nil, then force the file belonging to the found tag to be loaded.

Source Code

;; Defined in /usr/src/emacs/lisp/cedet/semantic/db-typecache.el.gz
(cl-defmethod semanticdb-typecache-find-method ((table semanticdb-abstract-table)
					     type find-file-match)
  "Search the typecache in TABLE for the datatype TYPE.
If type is a string, split the string, and search for the parts.
If type is a list, treat the type as a pre-split string.
If FIND-FILE-MATCH is non-nil, then force the file belonging to the
found tag to be loaded."
  ;; convert string to a list.
  (when (stringp type) (setq type (semantic-analyze-split-name type)))
  (when (stringp type) (setq type (list type)))

  ;; Search for the list in our typecache.
  (let* ((file (semanticdb-typecache-file-tags table))
	 (inc (semanticdb-typecache-include-tags table))
	 (stream nil)
	 (f-ans nil)
	 (i-ans nil)
	 (ans nil)
	 (notdone t)
	 (lastfile nil)
	 (thisfile nil)
	 (lastans nil)
	 (calculated-scope nil)
	 )
    ;; 1) Find first symbol in the two master lists and then merge
    ;;    the found streams.

    ;; We stripped duplicates, so these will be super-fast!
    (setq f-ans (semantic-find-first-tag-by-name (car type) file))
    (setq i-ans (semantic-find-first-tag-by-name (car type) inc))
    (if (and f-ans i-ans)
	(progn
	  ;; This trick merges the two identified tags, making sure our lists are
	  ;; complete.  The second find then gets the new 'master' from the list of 2.
	  (setq ans (semanticdb-typecache-merge-streams (list f-ans) (list i-ans)))
	  (setq ans (semantic-find-first-tag-by-name (car type) ans))
	  )

      ;; The answers are already sorted and merged, so if one misses,
      ;; no need to do any special work.
      (setq ans (or f-ans i-ans)))

    ;; 2) Loop over the remaining parts.
    (while (and type notdone)

      ;; For pass > 1, stream will be non-nil, so do a search, otherwise
      ;; ans is from outside the loop.
      (when stream
	(setq ans (semanticdb-typecache-find-by-name-helper (car type) stream))

	;; NOTE: The below test to make sure we get a type is only relevant
	;;       for the SECOND pass or later.  The first pass can only ever
	;;       find a type/namespace because everything else is excluded.

	;; If this is not the last entry from the list, then it
	;; must be a type or a namespace.  Let's double check.
	(when (cdr type)

	  ;; From above, there is only one tag in ans, and we prefer
	  ;; types.
	  (when (not (semantic-tag-of-class-p ans 'type))

	    (setq ans nil)))
	)

      ;; The typecache holds all the known types and elements.  Some databases
      ;; may provide tags that are simplified by name, and are proxies.  These
      ;; proxies must be resolved in order to extract type members.
      (setq ans (semantic-tag-resolve-proxy ans))

      (push ans calculated-scope)

      ;; Track most recent file.
      (setq thisfile (semantic-tag-file-name ans))
      (when (and thisfile (stringp thisfile))
	(setq lastfile thisfile))

      ;; If we have a miss, exit, otherwise, update the stream to
      ;; the next set of members.
      (if (not ans)
	  (setq notdone nil)
	(setq stream (semantic-tag-type-members ans)))

      (setq lastans ans
	    ans nil
	    type (cdr type)))

    (if (or type (not notdone))
	;; If there is stuff left over, then we failed.  Just return
	;; nothing.
	nil

      ;; We finished, so return everything.

      (if (and find-file-match lastfile)
	  ;; This won't liven up the tag since we have a copy, but
	  ;; we ought to be able to get there and go to the right line.
	  (find-file-noselect lastfile)
	;; We don't want to find-file match, so instead let's
	;; push the filename onto the return tag.
	(when lastans
	  (setq lastans (semantic-tag-copy lastans nil lastfile))
	  ;; We used to do the below, but we would erroneously be putting
	  ;; attributes on tags being shred with other lists.
	  ;;(semantic--tag-put-property lastans :filename lastfile)
	  )
	)

      (if (and lastans calculated-scope)

	  ;; Put our discovered scope into the tag if we have a tag
	  (progn
	    (require 'semantic/scope)
	    (semantic-scope-tag-clone-with-scope
	     lastans (reverse (cdr calculated-scope))))

	;; Else, just return
	lastans
	))))