Function: semanticdb-find-table-for-include-c-mode

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

Signature

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

Documentation

For a single INCLUDETAG found in TABLE, find a semanticdb-table(var)/semanticdb-table(fun) object.

INCLUDETAG is a semantic TAG of class include. TABLE is a semanticdb table that identifies where INCLUDETAG came from. TABLE is optional if INCLUDETAG has an overlay of :filename attribute.

For C++, we also have to check if the include is inside a namespace, since this means all tags inside this include will have to be wrapped in that namespace. Override semanticdb-find-table-for-include in c-mode buffers.

Source Code

;; Defined in /usr/src/emacs/lisp/cedet/semantic/bovine/c.el.gz
(define-mode-local-override semanticdb-find-table-for-include c-mode
  (includetag &optional table)
  "For a single INCLUDETAG found in TABLE, find a `semanticdb-table' object.
INCLUDETAG is a semantic TAG of class `include'.
TABLE is a semanticdb table that identifies where INCLUDETAG came from.
TABLE is optional if INCLUDETAG has an overlay of :filename attribute.

For C++, we also have to check if the include is inside a
namespace, since this means all tags inside this include will
have to be wrapped in that namespace."
  (let ((inctable (semanticdb-find-table-for-include-default includetag table))
	(inside-ns (semantic-tag-get-attribute includetag :inside-ns))
	tags newtags namespaces parenttable newtable) ;; prefix
    (if (or (null inside-ns)
	    (not inctable)
	    (not (slot-boundp inctable 'tags)))
	inctable
      (when (and (eq inside-ns t)
		 ;; Get the table which has this include.
		 (setq parenttable
		       (semanticdb-find-table-for-include-default
			(semantic-tag-new-include
			 (semantic--tag-get-property includetag :filename) nil)))
		 table)
	;; Find the namespace where this include is located.
	(setq namespaces
	      (semantic-find-tags-by-type "namespace" parenttable))
	(when (and namespaces
		   (slot-boundp inctable 'tags))
	  (dolist (cur namespaces)
	    (when (semantic-find-tags-by-name
		   (semantic-tag-name includetag)
		   (semantic-tag-get-attribute cur :members))
	      (setq inside-ns (semantic-tag-name cur))
	      ;; Cache the namespace value.
	      (semantic-tag-put-attribute includetag :inside-ns inside-ns)))))
      (unless (semantic-find-tags-by-name
	       inside-ns
	       (semantic-find-tags-by-type "namespace" inctable))
	(setq tags (oref inctable tags))
	;; Wrap tags inside namespace tag
	(setq newtags
	      (list (semantic-tag-new-type inside-ns "namespace" tags nil)))
	;; Create new semantic-table for the wrapped tags, since we don't want
	;; the namespace to actually be a part of the header file.
	(setq newtable (semanticdb-table))
	(oset newtable tags newtags)
	(oset newtable parent-db (oref inctable parent-db))
	(oset newtable file (oref inctable file)))
      newtable)))