* emacs-lisp/autoload.el (generated-autoload-load-name): New var.
[bpt/emacs.git] / lisp / cedet / semantic / tag-ls.el
CommitLineData
55b522b2 1;;; semantic/tag-ls.el --- Language Specific override functions for tags
f273dfc6
CY
2
3;;; Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2006, 2007, 2008
4;;; Free Software Foundation, Inc.
5
6;; Author: Eric M. Ludlam <zappo@gnu.org>
7
8;; This file is part of GNU Emacs.
9
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.
14
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.
19
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/>.
22
23;;; Commentary:
24;;
25;; There are some features of tags that are too langauge 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;; informatin can be derived, and thus should not be stored in the tag
30;; itself. These are the functions that languages can use to derive
31;; the information.
32
55b522b2 33(require 'semantic)
f273dfc6
CY
34
35;;; Code:
36
37;;; UML features:
38;;
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.
42
43(define-overloadable-function semantic-tag-calculate-parent (tag)
44 "Attempt to calculate the parent of TAG.
45The default behavior (if not overriden with `tag-calculate-parent')
46is to search a buffer found with TAG, and if externally defined,
47search locally, then semanticdb for that tag (when enabled.)")
48
49(defun semantic-tag-calculate-parent-default (tag)
50 "Attempt to calculate the parent of TAG."
51 (when (semantic-tag-in-buffer-p tag)
52 (save-excursion
53 (set-buffer (semantic-tag-buffer tag))
54 (save-excursion
55 (goto-char (semantic-tag-start tag))
56 (semantic-current-tag-parent))
57 )))
58
59(define-overloadable-function semantic-tag-protection (tag &optional parent)
60 "Return protection information about TAG with optional PARENT.
61This 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
66 classes.
67Some languages may choose to provide additional return symbols specific
68to themselves. Use of this function should allow for this.
69
70The default behavior (if not overridden with `tag-protection'
71is to return a symbol based on type modifiers."
72 (and (not parent)
73 (semantic-tag-overlay tag)
74 (semantic-tag-in-buffer-p tag)
75 (setq parent (semantic-tag-calculate-parent tag)))
76 (:override))
77
78(make-obsolete-overload 'semantic-nonterminal-protection
79 'semantic-tag-protection)
80
81(defun semantic-tag-protection-default (tag &optional parent)
82 "Return the protection of TAG as a child of PARENT default action.
83See `semantic-tag-protection'."
84 (let ((mods (semantic-tag-modifiers tag))
85 (prot nil))
86 (while (and (not prot) mods)
87 (if (stringp (car mods))
88 (let ((s (car mods)))
89 (setq prot
90 ;; A few silly defaults to get things started.
91 (cond ((or (string= s "public")
92 (string= s "extern")
93 (string= s "export"))
94 'public)
95 ((string= s "private")
96 'private)
97 ((string= s "protected")
98 'protected)))))
99 (setq mods (cdr mods)))
100 prot))
101
102(defun semantic-tag-protected-p (tag protection &optional parent)
103 "Non-nil if TAG is is protected.
104PROTECTION is a symbol which can be returned by the method
105`semantic-tag-protection'.
106PARENT is the parent data type which contains TAG.
107
108For these PROTECTIONs, true is returned if TAG is:
109@table @asis
110@item nil
111 Always true
112@item private
113 True if nil.
114@item protected
115 True if private or nil.
116@item public
117 True if private, protected, or nil.
118@end table"
119 (if (null protection)
120 t
121 (let ((tagpro (semantic-tag-protection tag parent)))
122 (or (and (eq protection 'private)
123 (null tagpro))
124 (and (eq protection 'protected)
125 (or (null tagpro)
126 (eq tagpro 'private)))
127 (and (eq protection 'public)
128 (not (eq tagpro 'public)))))
129 ))
130
131(define-overloadable-function semantic-tag-abstract-p (tag &optional parent)
132 "Return non nil if TAG is abstract.
133Optional PARENT is the parent tag of TAG.
134In UML, abstract methods and classes have special meaning and behavior
135in how methods are overridden. In UML, abstract methods are italicized.
136
137The default behavior (if not overridden with `tag-abstract-p'
138is to return true if `abstract' is in the type modifiers.")
139
140(make-obsolete-overload 'semantic-nonterminal-abstract
141 'semantic-tag-abstract-p)
142
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.
145See `semantic-tag-abstract-p'."
146 (let ((mods (semantic-tag-modifiers tag))
147 (abs nil))
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)))
153 abs))
154
155(define-overloadable-function semantic-tag-leaf-p (tag &optional parent)
156 "Return non nil if TAG is leaf.
157Optional PARENT is the parent tag of TAG.
158In UML, leaf methods and classes have special meaning and behavior.
159
160The default behavior (if not overridden with `tag-leaf-p'
161is to return true if `leaf' is in the type modifiers.")
162
163(make-obsolete-overload 'semantic-nonterminal-leaf
164 'semantic-tag-leaf-p)
165
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.
168See `semantic-tag-leaf-p'."
169 (let ((mods (semantic-tag-modifiers tag))
170 (leaf nil))
171 (while (and (not leaf) mods)
172 (if (stringp (car mods))
173 ;; Use java FINAL as example default. There is none
174 ;; for C/C++
175 (setq leaf (string= (car mods) "final")))
176 (setq mods (cdr mods)))
177 leaf))
178
179(define-overloadable-function semantic-tag-static-p (tag &optional parent)
180 "Return non nil if TAG is static.
181Optional PARENT is the parent tag of TAG.
182In UML, static methods and attributes mean that they are allocated
183in the parent class, and are not instance specific.
184UML notation specifies that STATIC entries are underlined.")
185
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.
188See `semantic-tag-static-p'."
189 (let ((mods (semantic-tag-modifiers tag))
190 (static nil))
191 (while (and (not static) mods)
192 (if (stringp (car mods))
193 (setq static (string= (car mods) "static")))
194 (setq mods (cdr mods)))
195 static))
196
3d9d8486 197;;;###autoload
f273dfc6
CY
198(define-overloadable-function semantic-tag-prototype-p (tag)
199 "Return non nil if TAG is a prototype.
200For some laguages, such as C, a prototype is a declaration of
201something without an implementation."
202 )
203
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)))
207 (cond
208 ;; Trust the parser author.
209 (p p)
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.
215 (t nil))
216 ))
217
218;;; FULL NAMES
219;;
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.
223
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.
226STREAM-OR-BUFFER can be anything convertable by `semantic-something-to-stream',
227but must be a toplevel semantic tag stream that contains TAG.
228A Package Hierarchy is defined in UML by the way classes and methods
229are organized on disk. Some language use this concept such that a
230class can be accessed via it's fully qualified name, (such as Java.)
231Other languages qualify names within a Namespace (such as C++) which
232result in a different package like structure. Languages which do not
233override this function with `tag-full-name' will use
234`semantic-tag-name'. Override functions only need to handle
235STREAM-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))))
239
240(make-obsolete-overload 'semantic-nonterminal-full-name
241 'semantic-tag-full-name)
242
243(defun semantic-tag-full-name-default (tag stream)
244 "Default method for `semantic-tag-full-name'.
245Return the name of TAG found in the toplevel STREAM."
246 (semantic-tag-name tag))
247
248;;; Compatibility aliases.
249;;
250(semantic-alias-obsolete 'semantic-nonterminal-protection
251 'semantic-tag-protection)
252(semantic-alias-obsolete 'semantic-nonterminal-protection-default
253 'semantic-tag-protection-default)
254(semantic-alias-obsolete 'semantic-nonterminal-abstract
255 'semantic-tag-abstract-p)
256(semantic-alias-obsolete 'semantic-nonterminal-abstract-default
257 'semantic-tag-abstract-p-default)
258(semantic-alias-obsolete 'semantic-nonterminal-leaf
259 'semantic-tag-leaf-p)
260(semantic-alias-obsolete 'semantic-nonterminal-leaf-default
261 'semantic-tag-leaf-p-default)
262(semantic-alias-obsolete 'semantic-nonterminal-static-default
263 'semantic-tag-static-p-default)
264(semantic-alias-obsolete 'semantic-nonterminal-full-name
265 'semantic-tag-full-name)
266(semantic-alias-obsolete 'semantic-nonterminal-full-name-default
267 'semantic-tag-full-name-default)
268
269;; TEMPORARY within betas of CEDET 1.0
270(semantic-alias-obsolete 'semantic-tag-static 'semantic-tag-static-p)
271(semantic-alias-obsolete 'semantic-tag-leaf 'semantic-tag-leaf-p)
272(semantic-alias-obsolete 'semantic-tag-abstract 'semantic-tag-abstract-p)
273
f273dfc6
CY
274(provide 'semantic/tag-ls)
275
3d9d8486
CY
276;; Local variables:
277;; generated-autoload-file: "loaddefs.el"
278;; generated-autoload-feature: semantic/loaddefs
996bc9bf 279;; generated-autoload-load-name: "semantic/tag-ls"
3d9d8486
CY
280;; End:
281
55b522b2 282;;; semantic/tag-ls.el ends here