Add 2011 to FSF/AIST copyright years.
[bpt/emacs.git] / lisp / cedet / semantic / tag-ls.el
CommitLineData
55b522b2 1;;; semantic/tag-ls.el --- Language Specific override functions for tags
f273dfc6 2
cb758101 3;; Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2006, 2007, 2008,
5df4f04c 4;; 2009, 2010, 2011 Free Software Foundation, Inc.
f273dfc6
CY
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;;
e2309735 25;; There are some features of tags that are too language dependent to
f273dfc6
CY
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
e2309735 29;; information can be derived, and thus should not be stored in the tag
f273dfc6
CY
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)
0816d744 52 (with-current-buffer (semantic-tag-buffer tag)
f273dfc6
CY
53 (save-excursion
54 (goto-char (semantic-tag-start tag))
55 (semantic-current-tag-parent))
56 )))
57
58(define-overloadable-function semantic-tag-protection (tag &optional parent)
59 "Return protection information about TAG with optional PARENT.
60This function returns on of the following symbols:
61 nil - No special protection. Language dependent.
62 'public - Anyone can access this TAG.
63 'private - Only methods in the local scope can access TAG.
64 'protected - Like private for outside scopes, like public for child
65 classes.
66Some languages may choose to provide additional return symbols specific
67to themselves. Use of this function should allow for this.
68
69The default behavior (if not overridden with `tag-protection'
70is to return a symbol based on type modifiers."
71 (and (not parent)
72 (semantic-tag-overlay tag)
73 (semantic-tag-in-buffer-p tag)
74 (setq parent (semantic-tag-calculate-parent tag)))
75 (:override))
76
77(make-obsolete-overload 'semantic-nonterminal-protection
5a916e35 78 'semantic-tag-protection "23.2")
f273dfc6
CY
79
80(defun semantic-tag-protection-default (tag &optional parent)
81 "Return the protection of TAG as a child of PARENT default action.
82See `semantic-tag-protection'."
83 (let ((mods (semantic-tag-modifiers tag))
84 (prot nil))
85 (while (and (not prot) mods)
86 (if (stringp (car mods))
87 (let ((s (car mods)))
88 (setq prot
89 ;; A few silly defaults to get things started.
90 (cond ((or (string= s "public")
91 (string= s "extern")
92 (string= s "export"))
93 'public)
94 ((string= s "private")
95 'private)
96 ((string= s "protected")
97 'protected)))))
98 (setq mods (cdr mods)))
99 prot))
100
101(defun semantic-tag-protected-p (tag protection &optional parent)
102 "Non-nil if TAG is is protected.
103PROTECTION is a symbol which can be returned by the method
104`semantic-tag-protection'.
105PARENT is the parent data type which contains TAG.
106
107For these PROTECTIONs, true is returned if TAG is:
108@table @asis
109@item nil
110 Always true
111@item private
112 True if nil.
113@item protected
114 True if private or nil.
115@item public
116 True if private, protected, or nil.
117@end table"
118 (if (null protection)
119 t
120 (let ((tagpro (semantic-tag-protection tag parent)))
121 (or (and (eq protection 'private)
122 (null tagpro))
123 (and (eq protection 'protected)
124 (or (null tagpro)
125 (eq tagpro 'private)))
126 (and (eq protection 'public)
127 (not (eq tagpro 'public)))))
128 ))
129
130(define-overloadable-function semantic-tag-abstract-p (tag &optional parent)
131 "Return non nil if TAG is abstract.
132Optional PARENT is the parent tag of TAG.
133In UML, abstract methods and classes have special meaning and behavior
134in how methods are overridden. In UML, abstract methods are italicized.
135
136The default behavior (if not overridden with `tag-abstract-p'
137is to return true if `abstract' is in the type modifiers.")
138
139(make-obsolete-overload 'semantic-nonterminal-abstract
5a916e35 140 'semantic-tag-abstract-p "23.2")
f273dfc6
CY
141
142(defun semantic-tag-abstract-p-default (tag &optional parent)
143 "Return non-nil if TAG is abstract as a child of PARENT default action.
144See `semantic-tag-abstract-p'."
145 (let ((mods (semantic-tag-modifiers tag))
146 (abs nil))
147 (while (and (not abs) mods)
148 (if (stringp (car mods))
149 (setq abs (or (string= (car mods) "abstract")
150 (string= (car mods) "virtual"))))
151 (setq mods (cdr mods)))
152 abs))
153
154(define-overloadable-function semantic-tag-leaf-p (tag &optional parent)
155 "Return non nil if TAG is leaf.
156Optional PARENT is the parent tag of TAG.
157In UML, leaf methods and classes have special meaning and behavior.
158
159The default behavior (if not overridden with `tag-leaf-p'
160is to return true if `leaf' is in the type modifiers.")
161
162(make-obsolete-overload 'semantic-nonterminal-leaf
5a916e35 163 'semantic-tag-leaf-p "23.2")
f273dfc6
CY
164
165(defun semantic-tag-leaf-p-default (tag &optional parent)
166 "Return non-nil if TAG is leaf as a child of PARENT default action.
167See `semantic-tag-leaf-p'."
168 (let ((mods (semantic-tag-modifiers tag))
169 (leaf nil))
170 (while (and (not leaf) mods)
171 (if (stringp (car mods))
172 ;; Use java FINAL as example default. There is none
173 ;; for C/C++
174 (setq leaf (string= (car mods) "final")))
175 (setq mods (cdr mods)))
176 leaf))
177
178(define-overloadable-function semantic-tag-static-p (tag &optional parent)
179 "Return non nil if TAG is static.
180Optional PARENT is the parent tag of TAG.
181In UML, static methods and attributes mean that they are allocated
182in the parent class, and are not instance specific.
183UML notation specifies that STATIC entries are underlined.")
184
185(defun semantic-tag-static-p-default (tag &optional parent)
186 "Return non-nil if TAG is static as a child of PARENT default action.
187See `semantic-tag-static-p'."
188 (let ((mods (semantic-tag-modifiers tag))
189 (static nil))
190 (while (and (not static) mods)
191 (if (stringp (car mods))
192 (setq static (string= (car mods) "static")))
193 (setq mods (cdr mods)))
194 static))
195
3d9d8486 196;;;###autoload
f273dfc6
CY
197(define-overloadable-function semantic-tag-prototype-p (tag)
198 "Return non nil if TAG is a prototype.
199For some laguages, such as C, a prototype is a declaration of
200something without an implementation."
201 )
202
203(defun semantic-tag-prototype-p-default (tag)
204 "Non-nil if TAG is a prototype."
205 (let ((p (semantic-tag-get-attribute tag :prototype-flag)))
206 (cond
207 ;; Trust the parser author.
208 (p p)
209 ;; Empty types might be a prototype.
210 ;; @todo - make this better.
211 ((eq (semantic-tag-class tag) 'type)
212 (not (semantic-tag-type-members tag)))
213 ;; No other heuristics.
214 (t nil))
215 ))
216
217;;; FULL NAMES
218;;
219;; For programmer convenience, a full name is not specified in source
220;; code. Instead some abbreviation is made, and the local environment
221;; will contain the info needed to determine the full name.
222
223(define-overloadable-function semantic-tag-full-name (tag &optional stream-or-buffer)
224 "Return the fully qualified name of TAG in the package hierarchy.
225STREAM-OR-BUFFER can be anything convertable by `semantic-something-to-stream',
226but must be a toplevel semantic tag stream that contains TAG.
227A Package Hierarchy is defined in UML by the way classes and methods
228are organized on disk. Some language use this concept such that a
229class can be accessed via it's fully qualified name, (such as Java.)
230Other languages qualify names within a Namespace (such as C++) which
231result in a different package like structure. Languages which do not
232override this function with `tag-full-name' will use
233`semantic-tag-name'. Override functions only need to handle
234STREAM-OR-BUFFER with a tag stream value, or nil."
235 (let ((stream (semantic-something-to-tag-table
236 (or stream-or-buffer tag))))
237 (:override-with-args (tag stream))))
238
239(make-obsolete-overload 'semantic-nonterminal-full-name
5a916e35 240 'semantic-tag-full-name "23.2")
f273dfc6
CY
241
242(defun semantic-tag-full-name-default (tag stream)
243 "Default method for `semantic-tag-full-name'.
244Return the name of TAG found in the toplevel STREAM."
245 (semantic-tag-name tag))
246
f273dfc6
CY
247(provide 'semantic/tag-ls)
248
3d9d8486
CY
249;; Local variables:
250;; generated-autoload-file: "loaddefs.el"
996bc9bf 251;; generated-autoload-load-name: "semantic/tag-ls"
3d9d8486
CY
252;; End:
253
3999968a 254;; arch-tag: 06041439-e4bf-46f9-ab30-7805888d4464
55b522b2 255;;; semantic/tag-ls.el ends here