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