]> code.delx.au - gnu-emacs/blob - lisp/cedet/semantic/tag-ls.el
Add 2012 to FSF copyright years for Emacs files (do not merge to trunk)
[gnu-emacs] / lisp / cedet / semantic / tag-ls.el
1 ;;; semantic/tag-ls.el --- Language Specific override functions for tags
2
3 ;; Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2006, 2007, 2008,
4 ;; 2009, 2010, 2011, 2012 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 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
31 ;; the information.
32
33 (require 'semantic)
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.
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.)")
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 (with-current-buffer (semantic-tag-buffer tag)
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.
60 This 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.
66 Some languages may choose to provide additional return symbols specific
67 to themselves. Use of this function should allow for this.
68
69 The default behavior (if not overridden with `tag-protection'
70 is 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
78 'semantic-tag-protection "23.2")
79
80 (defun semantic-tag-protection-default (tag &optional parent)
81 "Return the protection of TAG as a child of PARENT default action.
82 See `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.
103 PROTECTION is a symbol which can be returned by the method
104 `semantic-tag-protection'.
105 PARENT is the parent data type which contains TAG.
106
107 For 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.
132 Optional PARENT is the parent tag of TAG.
133 In UML, abstract methods and classes have special meaning and behavior
134 in how methods are overridden. In UML, abstract methods are italicized.
135
136 The default behavior (if not overridden with `tag-abstract-p'
137 is to return true if `abstract' is in the type modifiers.")
138
139 (make-obsolete-overload 'semantic-nonterminal-abstract
140 'semantic-tag-abstract-p "23.2")
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.
144 See `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.
156 Optional PARENT is the parent tag of TAG.
157 In UML, leaf methods and classes have special meaning and behavior.
158
159 The default behavior (if not overridden with `tag-leaf-p'
160 is to return true if `leaf' is in the type modifiers.")
161
162 (make-obsolete-overload 'semantic-nonterminal-leaf
163 'semantic-tag-leaf-p "23.2")
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.
167 See `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.
180 Optional PARENT is the parent tag of TAG.
181 In UML, static methods and attributes mean that they are allocated
182 in the parent class, and are not instance specific.
183 UML 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.
187 See `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
196 ;;;###autoload
197 (define-overloadable-function semantic-tag-prototype-p (tag)
198 "Return non nil if TAG is a prototype.
199 For some laguages, such as C, a prototype is a declaration of
200 something 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.
225 STREAM-OR-BUFFER can be anything convertable by `semantic-something-to-stream',
226 but must be a toplevel semantic tag stream that contains TAG.
227 A Package Hierarchy is defined in UML by the way classes and methods
228 are organized on disk. Some language use this concept such that a
229 class can be accessed via it's fully qualified name, (such as Java.)
230 Other languages qualify names within a Namespace (such as C++) which
231 result in a different package like structure. Languages which do not
232 override this function with `tag-full-name' will use
233 `semantic-tag-name'. Override functions only need to handle
234 STREAM-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
240 'semantic-tag-full-name "23.2")
241
242 (defun semantic-tag-full-name-default (tag stream)
243 "Default method for `semantic-tag-full-name'.
244 Return the name of TAG found in the toplevel STREAM."
245 (semantic-tag-name tag))
246
247 (provide 'semantic/tag-ls)
248
249 ;; Local variables:
250 ;; generated-autoload-file: "loaddefs.el"
251 ;; generated-autoload-load-name: "semantic/tag-ls"
252 ;; End:
253
254 ;; arch-tag: 06041439-e4bf-46f9-ab30-7805888d4464
255 ;;; semantic/tag-ls.el ends here