tag-ls.el 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. ;;; semantic/tag-ls.el --- Language Specific override functions for tags
  2. ;; Copyright (C) 1999-2004, 2006-2012 Free Software Foundation, Inc.
  3. ;; Author: Eric M. Ludlam <zappo@gnu.org>
  4. ;; This file is part of GNU Emacs.
  5. ;; GNU Emacs is free software: you can redistribute it and/or modify
  6. ;; it under the terms of the GNU General Public License as published by
  7. ;; the Free Software Foundation, either version 3 of the License, or
  8. ;; (at your option) any later version.
  9. ;; GNU Emacs is distributed in the hope that it will be useful,
  10. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. ;; GNU General Public License for more details.
  13. ;; You should have received a copy of the GNU General Public License
  14. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  15. ;;; Commentary:
  16. ;;
  17. ;; There are some features of tags that are too language dependent to
  18. ;; put in the core `semantic-tag' functionality. For instance, the
  19. ;; protection of a tag (as specified by UML) could be almost anything.
  20. ;; In Java, it is a type specifier. In C, there is a label. This
  21. ;; information can be derived, and thus should not be stored in the tag
  22. ;; itself. These are the functions that languages can use to derive
  23. ;; the information.
  24. (require 'semantic)
  25. ;;; Code:
  26. ;;; UML features:
  27. ;;
  28. ;; UML can represent several types of features of a tag
  29. ;; such as the `protection' of a symbol, or if it is abstract,
  30. ;; leaf, etc. Learn about UML to catch onto the lingo.
  31. (define-overloadable-function semantic-tag-calculate-parent (tag)
  32. "Attempt to calculate the parent of TAG.
  33. The default behavior (if not overridden with `tag-calculate-parent')
  34. is to search a buffer found with TAG, and if externally defined,
  35. search locally, then semanticdb for that tag (when enabled.)")
  36. (defun semantic-tag-calculate-parent-default (tag)
  37. "Attempt to calculate the parent of TAG."
  38. (when (semantic-tag-in-buffer-p tag)
  39. (with-current-buffer (semantic-tag-buffer tag)
  40. (save-excursion
  41. (goto-char (semantic-tag-start tag))
  42. (semantic-current-tag-parent))
  43. )))
  44. (define-overloadable-function semantic-tag-protection (tag &optional parent)
  45. "Return protection information about TAG with optional PARENT.
  46. This function returns on of the following symbols:
  47. nil - No special protection. Language dependent.
  48. 'public - Anyone can access this TAG.
  49. 'private - Only methods in the local scope can access TAG.
  50. 'protected - Like private for outside scopes, like public for child
  51. classes.
  52. Some languages may choose to provide additional return symbols specific
  53. to themselves. Use of this function should allow for this.
  54. The default behavior (if not overridden with `tag-protection'
  55. is to return a symbol based on type modifiers."
  56. (and (not parent)
  57. (semantic-tag-overlay tag)
  58. (semantic-tag-in-buffer-p tag)
  59. (setq parent (semantic-tag-calculate-parent tag)))
  60. (:override))
  61. (make-obsolete-overload 'semantic-nonterminal-protection
  62. 'semantic-tag-protection "23.2")
  63. (defun semantic-tag-protection-default (tag &optional parent)
  64. "Return the protection of TAG as a child of PARENT default action.
  65. See `semantic-tag-protection'."
  66. (let ((mods (semantic-tag-modifiers tag))
  67. (prot nil))
  68. (while (and (not prot) mods)
  69. (if (stringp (car mods))
  70. (let ((s (car mods)))
  71. (setq prot
  72. ;; A few silly defaults to get things started.
  73. (cond ((or (string= s "public")
  74. (string= s "extern")
  75. (string= s "export"))
  76. 'public)
  77. ((string= s "private")
  78. 'private)
  79. ((string= s "protected")
  80. 'protected)))))
  81. (setq mods (cdr mods)))
  82. prot))
  83. (defun semantic-tag-protected-p (tag protection &optional parent)
  84. "Non-nil if TAG is protected.
  85. PROTECTION is a symbol which can be returned by the method
  86. `semantic-tag-protection'.
  87. PARENT is the parent data type which contains TAG.
  88. For these PROTECTIONs, true is returned if TAG is:
  89. @table @asis
  90. @item nil
  91. Always true.
  92. @item private
  93. True if nil.
  94. @item protected
  95. True if private or nil.
  96. @item public
  97. True if private, protected, or nil.
  98. @end table"
  99. (if (null protection)
  100. t
  101. (let ((tagpro (semantic-tag-protection tag parent)))
  102. (or (and (eq protection 'private)
  103. (null tagpro))
  104. (and (eq protection 'protected)
  105. (or (null tagpro)
  106. (eq tagpro 'private)))
  107. (and (eq protection 'public)
  108. (not (eq tagpro 'public)))))
  109. ))
  110. (define-overloadable-function semantic-tag-abstract-p (tag &optional parent)
  111. "Return non nil if TAG is abstract.
  112. Optional PARENT is the parent tag of TAG.
  113. In UML, abstract methods and classes have special meaning and behavior
  114. in how methods are overridden. In UML, abstract methods are italicized.
  115. The default behavior (if not overridden with `tag-abstract-p'
  116. is to return true if `abstract' is in the type modifiers.")
  117. (make-obsolete-overload 'semantic-nonterminal-abstract
  118. 'semantic-tag-abstract-p "23.2")
  119. (defun semantic-tag-abstract-p-default (tag &optional parent)
  120. "Return non-nil if TAG is abstract as a child of PARENT default action.
  121. See `semantic-tag-abstract-p'."
  122. (let ((mods (semantic-tag-modifiers tag))
  123. (abs nil))
  124. (while (and (not abs) mods)
  125. (if (stringp (car mods))
  126. (setq abs (or (string= (car mods) "abstract")
  127. (string= (car mods) "virtual"))))
  128. (setq mods (cdr mods)))
  129. abs))
  130. (define-overloadable-function semantic-tag-leaf-p (tag &optional parent)
  131. "Return non nil if TAG is leaf.
  132. Optional PARENT is the parent tag of TAG.
  133. In UML, leaf methods and classes have special meaning and behavior.
  134. The default behavior (if not overridden with `tag-leaf-p'
  135. is to return true if `leaf' is in the type modifiers.")
  136. (make-obsolete-overload 'semantic-nonterminal-leaf
  137. 'semantic-tag-leaf-p "23.2")
  138. (defun semantic-tag-leaf-p-default (tag &optional parent)
  139. "Return non-nil if TAG is leaf as a child of PARENT default action.
  140. See `semantic-tag-leaf-p'."
  141. (let ((mods (semantic-tag-modifiers tag))
  142. (leaf nil))
  143. (while (and (not leaf) mods)
  144. (if (stringp (car mods))
  145. ;; Use java FINAL as example default. There is none
  146. ;; for C/C++
  147. (setq leaf (string= (car mods) "final")))
  148. (setq mods (cdr mods)))
  149. leaf))
  150. (define-overloadable-function semantic-tag-static-p (tag &optional parent)
  151. "Return non nil if TAG is static.
  152. Optional PARENT is the parent tag of TAG.
  153. In UML, static methods and attributes mean that they are allocated
  154. in the parent class, and are not instance specific.
  155. UML notation specifies that STATIC entries are underlined.")
  156. (defun semantic-tag-static-p-default (tag &optional parent)
  157. "Return non-nil if TAG is static as a child of PARENT default action.
  158. See `semantic-tag-static-p'."
  159. (let ((mods (semantic-tag-modifiers tag))
  160. (static nil))
  161. (while (and (not static) mods)
  162. (if (stringp (car mods))
  163. (setq static (string= (car mods) "static")))
  164. (setq mods (cdr mods)))
  165. static))
  166. ;;;###autoload
  167. (define-overloadable-function semantic-tag-prototype-p (tag)
  168. "Return non nil if TAG is a prototype.
  169. For some languages, such as C, a prototype is a declaration of
  170. something without an implementation."
  171. )
  172. (defun semantic-tag-prototype-p-default (tag)
  173. "Non-nil if TAG is a prototype."
  174. (let ((p (semantic-tag-get-attribute tag :prototype-flag)))
  175. (cond
  176. ;; Trust the parser author.
  177. (p p)
  178. ;; Empty types might be a prototype.
  179. ;; @todo - make this better.
  180. ((eq (semantic-tag-class tag) 'type)
  181. (not (semantic-tag-type-members tag)))
  182. ;; No other heuristics.
  183. (t nil))
  184. ))
  185. ;;; FULL NAMES
  186. ;;
  187. ;; For programmer convenience, a full name is not specified in source
  188. ;; code. Instead some abbreviation is made, and the local environment
  189. ;; will contain the info needed to determine the full name.
  190. (define-overloadable-function semantic-tag-full-name (tag &optional stream-or-buffer)
  191. "Return the fully qualified name of TAG in the package hierarchy.
  192. STREAM-OR-BUFFER can be anything convertible by `semantic-something-to-stream',
  193. but must be a toplevel semantic tag stream that contains TAG.
  194. A Package Hierarchy is defined in UML by the way classes and methods
  195. are organized on disk. Some language use this concept such that a
  196. class can be accessed via it's fully qualified name, (such as Java.)
  197. Other languages qualify names within a Namespace (such as C++) which
  198. result in a different package like structure. Languages which do not
  199. override this function with `tag-full-name' will use
  200. `semantic-tag-name'. Override functions only need to handle
  201. STREAM-OR-BUFFER with a tag stream value, or nil."
  202. (let ((stream (semantic-something-to-tag-table
  203. (or stream-or-buffer tag))))
  204. (:override-with-args (tag stream))))
  205. (make-obsolete-overload 'semantic-nonterminal-full-name
  206. 'semantic-tag-full-name "23.2")
  207. (defun semantic-tag-full-name-default (tag stream)
  208. "Default method for `semantic-tag-full-name'.
  209. Return the name of TAG found in the toplevel STREAM."
  210. (semantic-tag-name tag))
  211. (provide 'semantic/tag-ls)
  212. ;; Local variables:
  213. ;; generated-autoload-file: "loaddefs.el"
  214. ;; generated-autoload-load-name: "semantic/tag-ls"
  215. ;; End:
  216. ;;; semantic/tag-ls.el ends here