1 ;;; semantic-tag-ls.el --- Language Specific override functions for tags
3 ;;; Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2006 Eric M. Ludlam
5 ;; X-CVS: $Id: semantic-tag-ls.el,v 1.1 2007-11-26 15:10:43 michaels Exp $
7 ;; This file is not part of GNU Emacs.
9 ;; Semantic 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 2, or (at your option)
14 ;; This software 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.
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with GNU Emacs; see the file COPYING. If not, write to the
21 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
22 ;; Boston, MA 02110-1301, USA.
26 ;; There are some features of tags that are too langauge dependent to
27 ;; put in the core `semantic-tag' functionality. For instance, the
28 ;; protection of a tag (as specified by UML) could be almost anything.
29 ;; In Java, it is a type specifier. In C, there is a label. This
30 ;; informatin can be derived, and thus should not be stored in the tag
31 ;; itself. These are the functions that languages can use to derive
34 (require 'semantic-tag)
40 ;; UML can represent several types of features of a tag
41 ;; such as the `protection' of a symbol, or if it is abstract,
42 ;; leaf, etc. Learn about UML to catch onto the lingo.
45 (define-overload semantic-tag-calculate-parent (tag)
46 "Attempt to calculate the parent of TAG.
47 The default behavior (if not overriden with `tag-calculate-parent')
48 is to search a buffer found with TAG, and if externally defined,
49 search locally, then semanticdb for that tag (when enabled.)")
51 (defun semantic-tag-calculate-parent-default (tag)
52 "Attempt to calculate the parent of TAG."
54 (set-buffer (semantic-tag-buffer tag))
56 (goto-char (semantic-tag-start tag))
57 (semantic-current-tag-parent))
61 (define-overload semantic-tag-protection (tag &optional parent)
62 "Return protection information about TAG with optional PARENT.
63 This function returns on of the following symbols:
64 nil - No special protection. Language dependent.
65 'public - Anyone can access this TAG.
66 'private - Only methods in the local scope can access TAG.
67 'protected - Like private for outside scopes, like public for child
69 Some languages may choose to provide additional return symbols specific
70 to themselves. Use of this function should allow for this.
72 The default behavior (if not overridden with `tag-protection'
73 is to return a symbol based on type modifiers."
75 (semantic-tag-overlay tag)
76 (semantic-tag-buffer tag)
77 (setq parent (semantic-tag-calculate-parent tag)))
80 (make-obsolete-overload 'semantic-nonterminal-protection
81 'semantic-tag-protection)
83 (defun semantic-tag-protection-default (tag &optional parent)
84 "Return the protection of TAG as a child of PARENT default action.
85 See `semantic-tag-protection'."
86 (let ((mods (semantic-tag-modifiers tag))
88 (while (and (not prot) mods)
89 (if (stringp (car mods))
92 ;; A few silly defaults to get things started.
93 (cond ((or (string= s "public")
97 ((string= s "private")
99 ((string= s "protected")
101 (setq mods (cdr mods)))
105 (defun semantic-tag-protected-p (tag protection &optional parent)
106 "Non-nil if TAG is is protected.
107 PROTECTION is a symbol which can be returned by the method
108 `semantic-tag-protection'.
109 PARENT is the parent data type which contains TAG.
111 For these PROTECTIONs, true is returned if TAG is:
118 True if private or nil.
120 True if private, protected, or nil.
122 (let ((tagpro (semantic-tag-protection tag parent)))
123 (or (null protection)
124 (and (eq protection 'private)
126 (and (eq protection 'protected)
128 (eq tagpro 'private)))
129 (and (eq protection 'public)
130 (not (eq tagpro 'public))))
134 (define-overload semantic-tag-abstract-p (tag &optional parent)
135 "Return non nil if TAG is abstract.
136 Optional PARENT is the parent tag of TAG.
137 In UML, abstract methods and classes have special meaning and behavior
138 in how methods are overridden. In UML, abstract methods are italicized.
140 The default behavior (if not overridden with `tag-abstract-p'
141 is to return true if `abstract' is in the type modifiers.")
143 (make-obsolete-overload 'semantic-nonterminal-abstract
144 'semantic-tag-abstract-p)
146 (defun semantic-tag-abstract-p-default (tag &optional parent)
147 "Return non-nil if TAG is abstract as a child of PARENT default action.
148 See `semantic-tag-abstract-p'."
149 (let ((mods (semantic-tag-modifiers tag))
151 (while (and (not abs) mods)
152 (if (stringp (car mods))
153 (setq abs (or (string= (car mods) "abstract")
154 (string= (car mods) "virtual"))))
155 (setq mods (cdr mods)))
159 (define-overload semantic-tag-leaf-p (tag &optional parent)
160 "Return non nil if TAG is leaf.
161 Optional PARENT is the parent tag of TAG.
162 In UML, leaf methods and classes have special meaning and behavior.
164 The default behavior (if not overridden with `tag-leaf-p'
165 is to return true if `leaf' is in the type modifiers.")
167 (make-obsolete-overload 'semantic-nonterminal-leaf
168 'semantic-tag-leaf-p)
170 (defun semantic-tag-leaf-p-default (tag &optional parent)
171 "Return non-nil if TAG is leaf as a child of PARENT default action.
172 See `semantic-tag-leaf-p'."
173 (let ((mods (semantic-tag-modifiers tag))
175 (while (and (not leaf) mods)
176 (if (stringp (car mods))
177 ;; Use java FINAL as example default. There is none
179 (setq leaf (string= (car mods) "final")))
180 (setq mods (cdr mods)))
184 (define-overload semantic-tag-static-p (tag &optional parent)
185 "Return non nil if TAG is static.
186 Optional PARENT is the parent tag of TAG.
187 In UML, static methods and attributes mean that they are allocated
188 in the parent class, and are not instance specific.
189 UML notation specifies that STATIC entries are underlined.")
191 (defun semantic-tag-static-p-default (tag &optional parent)
192 "Return non-nil if TAG is static as a child of PARENT default action.
193 See `semantic-tag-static-p'."
194 (let ((mods (semantic-tag-modifiers tag))
196 (while (and (not static) mods)
197 (if (stringp (car mods))
198 (setq static (string= (car mods) "static")))
199 (setq mods (cdr mods)))
204 ;; For programmer convenience, a full name is not specified in source
205 ;; code. Instead some abbreviation is made, and the local environment
206 ;; will contain the info needed to determine the full name.
209 (define-overload semantic-tag-full-name (tag &optional stream-or-buffer)
210 "Return the fully qualified name of TAG in the package hierarchy.
211 STREAM-OR-BUFFER can be anything convertable by `semantic-something-to-stream',
212 but must be a toplevel semantic tag stream that contains TAG.
213 A Package Hierarchy is defined in UML by the way classes and methods
214 are organized on disk. Some language use this concept such that a
215 class can be accessed via it's fully qualified name, (such as Java.)
216 Other languages qualify names within a Namespace (such as C++) which
217 result in a different package like structure. Languages which do not
218 override this function with `tag-full-name' will use
219 `semantic-tag-name'. Override functions only need to handle
220 STREAM-OR-BUFFER with a tag stream value, or nil."
221 (let ((stream (semantic-something-to-tag-table
222 (or stream-or-buffer tag))))
223 (:override-with-args (tag stream))))
225 (make-obsolete-overload 'semantic-nonterminal-full-name
226 'semantic-tag-full-name)
228 (defun semantic-tag-full-name-default (tag stream)
229 "Default method for `semantic-tag-full-name'.
230 Return the name of TAG found in the toplevel STREAM."
231 (semantic-tag-name tag))
233 ;;; Compatibility aliases.
235 (semantic-alias-obsolete 'semantic-nonterminal-protection
236 'semantic-tag-protection)
237 (semantic-alias-obsolete 'semantic-nonterminal-protection-default
238 'semantic-tag-protection-default)
239 (semantic-alias-obsolete 'semantic-nonterminal-abstract
240 'semantic-tag-abstract-p)
241 (semantic-alias-obsolete 'semantic-nonterminal-abstract-default
242 'semantic-tag-abstract-p-default)
243 (semantic-alias-obsolete 'semantic-nonterminal-leaf
244 'semantic-tag-leaf-p)
245 (semantic-alias-obsolete 'semantic-nonterminal-leaf-default
246 'semantic-tag-leaf-p-default)
247 (semantic-alias-obsolete 'semantic-nonterminal-static-default
248 'semantic-tag-static-p-default)
249 (semantic-alias-obsolete 'semantic-nonterminal-full-name
250 'semantic-tag-full-name)
251 (semantic-alias-obsolete 'semantic-nonterminal-full-name-default
252 'semantic-tag-full-name-default)
254 ;; TEMPORARY within betas of CEDET 1.0
255 (semantic-alias-obsolete 'semantic-tag-static 'semantic-tag-static-p)
256 (semantic-alias-obsolete 'semantic-tag-leaf 'semantic-tag-leaf-p)
257 (semantic-alias-obsolete 'semantic-tag-abstract 'semantic-tag-abstract-p)
260 (provide 'semantic-tag-ls)
262 ;;; semantic-tag-ls.el ends here