Function: semanticdb-find-table-for-include-default

semanticdb-find-table-for-include-default is a byte-compiled function defined in db-find.el.gz.

Signature

(semanticdb-find-table-for-include-default INCLUDETAG &optional TABLE)

Documentation

Default implementation of semanticdb-find-table-for-include.

Uses semanticdb-current-database-list as the search path. INCLUDETAG and TABLE are documented in semanticdb-find-table-for-include. Included databases are filtered based on semanticdb-find-default-throttle.

Source Code

;; Defined in /usr/src/emacs/lisp/cedet/semantic/db-find.el.gz
;; The creation of the overload occurs above.
(defun semanticdb-find-table-for-include-default (includetag &optional table)
  "Default implementation of `semanticdb-find-table-for-include'.
Uses `semanticdb-current-database-list' as the search path.
INCLUDETAG and TABLE are documented in `semanticdb-find-table-for-include'.
Included databases are filtered based on `semanticdb-find-default-throttle'."
  (if (not (eq (semantic-tag-class includetag) 'include))
      (signal 'wrong-type-argument (list includetag 'include)))

  (let ((name
	 ;; Note, some languages (like Emacs or Java) use include tag names
	 ;; that don't represent files!  We want to have file names.
	 (semantic-tag-include-filename includetag))
	(originfiledir nil)
	(roots nil)
	(tmp nil)
	(ans nil))

    ;; INCLUDETAG should have some way to reference where it came
    ;; from!  If not, TABLE should provide the way.  Each time we
    ;; look up a tag, we may need to find it in some relative way
    ;; and must set our current buffer to the origin of includetag
    ;; or nothing may work.
    (setq originfiledir
	  (cond ((semantic-tag-file-name includetag)
		 ;; A tag may have a buffer, or a :filename property.
		 (file-name-directory (semantic-tag-file-name includetag)))
		(table
		 (file-name-directory (semanticdb-full-filename table)))
		(t
		 ;; @todo - what to do here?  Throw an error maybe
		 ;; and fix usage bugs?
		 default-directory)))

    (cond
     ;; Step 1: Relative path name
     ;;
     ;; If the name is relative, then it should be findable as relative
     ;; to the source file that this tag originated in, and be fast.
     ;;
     ((and (semanticdb-find-throttle-active-p 'local)
	   (file-exists-p (expand-file-name name originfiledir)))

      (setq ans (semanticdb-find-load-unloaded
		 (expand-file-name name originfiledir)))
      )
     ;; Step 2: System or Project level includes
     ;;
     ((or
       ;; First, if it a system include, we can investigate that tags
       ;; dependency file
       (and (semanticdb-find-throttle-active-p 'system)

	    ;; Sadly, not all languages make this distinction.
	    ;;(semantic-tag-include-system-p includetag)

	    ;; Here, we get local and system files.
	    (setq tmp (semantic-dependency-tag-file includetag))
	    )
       ;; Second, project files are active, we and we have EDE,
       ;; we can find it using the same tool.
       (and (semanticdb-find-throttle-active-p 'project)
	    ;; Make sure EDE is available, and we have a project
	    (featurep 'ede) (ede-current-project originfiledir)
	    ;; The EDE query is hidden in this call.
	    (setq tmp (semantic-dependency-tag-file includetag))
	    )
       )
      (setq ans (semanticdb-find-load-unloaded tmp))
      )
     ;; Somewhere in our project hierarchy
     ;;
     ;; Remember: Roots includes system databases which can create
     ;; specialized tables we can search.
     ;;
     ;; NOTE: Not used if EDE is active!
     ((and (semanticdb-find-throttle-active-p 'project)
	   ;; And don't do this if it is a system include.  Not supported by all languages,
	   ;; but when it is, this is a nice fast way to skip this step.
	   (not (semantic-tag-include-system-p includetag))
	   ;; Don't do this if we have an EDE project.
	   (not (and (featurep 'ede)
		     ;; Note: We don't use originfiledir here because
		     ;; we want to know about the source file we are
		     ;; starting from.
		     (ede-current-project)))
	   )

      (setq roots (semanticdb-current-database-list))

      (while (and (not ans) roots)
	(let* ((ref (if (slot-boundp (car roots) 'reference-directory)
			(oref (car roots) reference-directory)))
	       (fname (cond ((null ref) nil)
			    ((file-exists-p (expand-file-name name ref))
			     (expand-file-name name ref))
			    ((file-exists-p (expand-file-name (file-name-nondirectory name) ref))
			     (expand-file-name (file-name-nondirectory name) ref)))))
	  (when (and ref fname)
	    ;; There is an actual file.  Grab it.
	    (setq ans (semanticdb-find-load-unloaded fname)))

	  ;; ELSE
	  ;;
	  ;; NOTE: We used to look up omniscient databases here, but that
	  ;; is now handled one layer up.
	  ;;
	  ;; Missing: a database that knows where missing files are.  Hmm.
	  ;; perhaps I need an override function for that?

	  )

	(setq roots (cdr roots))))
     )
    ans))