1 ;;; semantic/tag-ls.el --- Language Specific override functions for tags
3 ;; Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2006, 2007, 2008,
4 ;; 2009 Free Software Foundation, Inc.
6 ;; Author: Eric M. Ludlam <zappo@gnu.org>
8 ;; This file is part of GNU Emacs.
10 ;; GNU Emacs is free software: you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation, either version 3 of the License, or
13 ;; (at your option) any later version.
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
25 ;; There are some features of tags that are too language dependent to
26 ;; put in the core `semantic-tag' functionality. For instance, the
27 ;; protection of a tag (as specified by UML) could be almost anything.
28 ;; In Java, it is a type specifier. In C, there is a label. This
29 ;; information can be derived, and thus should not be stored in the tag
30 ;; itself. These are the functions that languages can use to derive
39 ;; UML can represent several types of features of a tag
40 ;; such as the `protection' of a symbol, or if it is abstract,
41 ;; leaf, etc. Learn about UML to catch onto the lingo.
43 (define-overloadable-function semantic-tag-calculate-parent
(tag)
44 "Attempt to calculate the parent of TAG.
45 The default behavior (if not overriden with `tag-calculate-parent')
46 is to search a buffer found with TAG, and if externally defined,
47 search locally, then semanticdb for that tag (when enabled.)")
49 (defun semantic-tag-calculate-parent-default (tag)
50 "Attempt to calculate the parent of TAG."
51 (when (semantic-tag-in-buffer-p tag
)
53 (set-buffer (semantic-tag-buffer tag
))
55 (goto-char (semantic-tag-start tag
))
56 (semantic-current-tag-parent))
59 (define-overloadable-function semantic-tag-protection
(tag &optional parent
)
60 "Return protection information about TAG with optional PARENT.
61 This function returns on of the following symbols:
62 nil - No special protection. Language dependent.
63 'public - Anyone can access this TAG.
64 'private - Only methods in the local scope can access TAG.
65 'protected - Like private for outside scopes, like public for child
67 Some languages may choose to provide additional return symbols specific
68 to themselves. Use of this function should allow for this.
70 The default behavior (if not overridden with `tag-protection'
71 is to return a symbol based on type modifiers."
73 (semantic-tag-overlay tag
)
74 (semantic-tag-in-buffer-p tag
)
75 (setq parent
(semantic-tag-calculate-parent tag
)))
78 (make-obsolete-overload 'semantic-nonterminal-protection
79 'semantic-tag-protection
)
81 (defun semantic-tag-protection-default (tag &optional parent
)
82 "Return the protection of TAG as a child of PARENT default action.
83 See `semantic-tag-protection'."
84 (let ((mods (semantic-tag-modifiers tag
))
86 (while (and (not prot
) mods
)
87 (if (stringp (car mods
))
90 ;; A few silly defaults to get things started.
91 (cond ((or (string= s
"public")
95 ((string= s
"private")
97 ((string= s
"protected")
99 (setq mods
(cdr mods
)))
102 (defun semantic-tag-protected-p (tag protection
&optional parent
)
103 "Non-nil if TAG is is protected.
104 PROTECTION is a symbol which can be returned by the method
105 `semantic-tag-protection'.
106 PARENT is the parent data type which contains TAG.
108 For these PROTECTIONs, true is returned if TAG is:
115 True if private or nil.
117 True if private, protected, or nil.
119 (if (null protection
)
121 (let ((tagpro (semantic-tag-protection tag parent
)))
122 (or (and (eq protection
'private
)
124 (and (eq protection
'protected
)
126 (eq tagpro
'private
)))
127 (and (eq protection
'public
)
128 (not (eq tagpro
'public
)))))
131 (define-overloadable-function semantic-tag-abstract-p
(tag &optional parent
)
132 "Return non nil if TAG is abstract.
133 Optional PARENT is the parent tag of TAG.
134 In UML, abstract methods and classes have special meaning and behavior
135 in how methods are overridden. In UML, abstract methods are italicized.
137 The default behavior (if not overridden with `tag-abstract-p'
138 is to return true if `abstract' is in the type modifiers.")
140 (make-obsolete-overload 'semantic-nonterminal-abstract
141 'semantic-tag-abstract-p
)
143 (defun semantic-tag-abstract-p-default (tag &optional parent
)
144 "Return non-nil if TAG is abstract as a child of PARENT default action.
145 See `semantic-tag-abstract-p'."
146 (let ((mods (semantic-tag-modifiers tag
))
148 (while (and (not abs
) mods
)
149 (if (stringp (car mods
))
150 (setq abs
(or (string= (car mods
) "abstract")
151 (string= (car mods
) "virtual"))))
152 (setq mods
(cdr mods
)))
155 (define-overloadable-function semantic-tag-leaf-p
(tag &optional parent
)
156 "Return non nil if TAG is leaf.
157 Optional PARENT is the parent tag of TAG.
158 In UML, leaf methods and classes have special meaning and behavior.
160 The default behavior (if not overridden with `tag-leaf-p'
161 is to return true if `leaf' is in the type modifiers.")
163 (make-obsolete-overload 'semantic-nonterminal-leaf
164 'semantic-tag-leaf-p
)
166 (defun semantic-tag-leaf-p-default (tag &optional parent
)
167 "Return non-nil if TAG is leaf as a child of PARENT default action.
168 See `semantic-tag-leaf-p'."
169 (let ((mods (semantic-tag-modifiers tag
))
171 (while (and (not leaf
) mods
)
172 (if (stringp (car mods
))
173 ;; Use java FINAL as example default. There is none
175 (setq leaf
(string= (car mods
) "final")))
176 (setq mods
(cdr mods
)))
179 (define-overloadable-function semantic-tag-static-p
(tag &optional parent
)
180 "Return non nil if TAG is static.
181 Optional PARENT is the parent tag of TAG.
182 In UML, static methods and attributes mean that they are allocated
183 in the parent class, and are not instance specific.
184 UML notation specifies that STATIC entries are underlined.")
186 (defun semantic-tag-static-p-default (tag &optional parent
)
187 "Return non-nil if TAG is static as a child of PARENT default action.
188 See `semantic-tag-static-p'."
189 (let ((mods (semantic-tag-modifiers tag
))
191 (while (and (not static
) mods
)
192 (if (stringp (car mods
))
193 (setq static
(string= (car mods
) "static")))
194 (setq mods
(cdr mods
)))
198 (define-overloadable-function semantic-tag-prototype-p
(tag)
199 "Return non nil if TAG is a prototype.
200 For some laguages, such as C, a prototype is a declaration of
201 something without an implementation."
204 (defun semantic-tag-prototype-p-default (tag)
205 "Non-nil if TAG is a prototype."
206 (let ((p (semantic-tag-get-attribute tag
:prototype-flag
)))
208 ;; Trust the parser author.
210 ;; Empty types might be a prototype.
211 ;; @todo - make this better.
212 ((eq (semantic-tag-class tag
) 'type
)
213 (not (semantic-tag-type-members tag
)))
214 ;; No other heuristics.
220 ;; For programmer convenience, a full name is not specified in source
221 ;; code. Instead some abbreviation is made, and the local environment
222 ;; will contain the info needed to determine the full name.
224 (define-overloadable-function semantic-tag-full-name
(tag &optional stream-or-buffer
)
225 "Return the fully qualified name of TAG in the package hierarchy.
226 STREAM-OR-BUFFER can be anything convertable by `semantic-something-to-stream',
227 but must be a toplevel semantic tag stream that contains TAG.
228 A Package Hierarchy is defined in UML by the way classes and methods
229 are organized on disk. Some language use this concept such that a
230 class can be accessed via it's fully qualified name, (such as Java.)
231 Other languages qualify names within a Namespace (such as C++) which
232 result in a different package like structure. Languages which do not
233 override this function with `tag-full-name' will use
234 `semantic-tag-name'. Override functions only need to handle
235 STREAM-OR-BUFFER with a tag stream value, or nil."
236 (let ((stream (semantic-something-to-tag-table
237 (or stream-or-buffer tag
))))
238 (:override-with-args
(tag stream
))))
240 (make-obsolete-overload 'semantic-nonterminal-full-name
241 'semantic-tag-full-name
)
243 (defun semantic-tag-full-name-default (tag stream
)
244 "Default method for `semantic-tag-full-name'.
245 Return the name of TAG found in the toplevel STREAM."
246 (semantic-tag-name tag
))
248 (provide 'semantic
/tag-ls
)
251 ;; generated-autoload-file: "loaddefs.el"
252 ;; generated-autoload-feature: semantic/loaddefs
253 ;; generated-autoload-load-name: "semantic/tag-ls"
256 ;;; semantic/tag-ls.el ends here