Remove non-free old and crusty clearcase pkg
[packages] / xemacs-packages / semantic / 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 Eric M. Ludlam
4
5 ;; X-CVS: $Id: semantic-tag-ls.el,v 1.1 2007-11-26 15:10:43 michaels Exp $
6
7 ;; This file is not part of GNU Emacs.
8
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)
12 ;; any later version.
13
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.
18
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.
23
24 ;;; Commentary:
25 ;;
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
32 ;; the information.
33
34 (require 'semantic-tag)
35
36 ;;; Code:
37
38 ;;; UML features:
39 ;;
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.
43
44 ;;;###autoload
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.)")
50
51 (defun semantic-tag-calculate-parent-default (tag)
52   "Attempt to calculate the parent of TAG."
53   (save-excursion
54     (set-buffer (semantic-tag-buffer tag))
55     (save-excursion
56       (goto-char (semantic-tag-start tag))
57       (semantic-current-tag-parent))
58     ))
59
60 ;;;###autoload
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
68                 classes.
69 Some languages may choose to provide additional return symbols specific
70 to themselves.  Use of this function should allow for this.
71
72 The default behavior (if not overridden with `tag-protection'
73 is to return a symbol based on type modifiers."
74   (and (not parent)
75        (semantic-tag-overlay tag)
76        (semantic-tag-buffer tag)
77        (setq parent (semantic-tag-calculate-parent tag)))
78   (:override))
79
80 (make-obsolete-overload 'semantic-nonterminal-protection
81                         'semantic-tag-protection)
82
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))
87         (prot nil))
88     (while (and (not prot) mods)
89       (if (stringp (car mods))
90           (let ((s (car mods)))
91             (setq prot
92                   ;; A few silly defaults to get things started.
93                   (cond ((or (string= s "public")
94                              (string= s "extern")
95                              (string= s "export"))
96                          'public)
97                         ((string= s "private")
98                          'private)
99                         ((string= s "protected")
100                          'protected)))))
101       (setq mods (cdr mods)))
102     prot))
103
104 ;;;###autoload
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.
110
111 For these PROTECTIONs, true is returned if TAG is:
112 @table @asis
113 @item nil
114   Always true
115 @item  private
116   True if nil.
117 @item protected
118   True if private or nil.
119 @item public
120   True if private, protected, or nil.
121 @end table"
122   (let ((tagpro (semantic-tag-protection tag parent)))
123     (or (null protection)
124         (and (eq protection 'private)
125              (null tagpro))
126         (and (eq protection 'protected)
127              (or (null tagpro)
128                  (eq tagpro 'private)))
129         (and (eq protection 'public)
130              (not (eq tagpro 'public))))
131     ))
132
133 ;;;###autoload
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.
139
140 The default behavior (if not overridden with `tag-abstract-p'
141 is to return true if `abstract' is in the type modifiers.")
142
143 (make-obsolete-overload 'semantic-nonterminal-abstract
144                         'semantic-tag-abstract-p)
145
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))
150         (abs nil))
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)))
156     abs))
157
158 ;;;###autoload
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.
163
164 The default behavior (if not overridden with `tag-leaf-p'
165 is to return true if `leaf' is in the type modifiers.")
166
167 (make-obsolete-overload 'semantic-nonterminal-leaf
168                         'semantic-tag-leaf-p)
169
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))
174         (leaf nil))
175     (while (and (not leaf) mods)
176       (if (stringp (car mods))
177           ;; Use java FINAL as example default.  There is none
178           ;; for C/C++
179           (setq leaf (string= (car mods) "final")))
180       (setq mods (cdr mods)))
181     leaf))
182
183 ;;;###autoload
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.")
190
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))
195         (static nil))
196     (while (and (not static) mods)
197       (if (stringp (car mods))
198           (setq static (string= (car mods) "static")))
199       (setq mods (cdr mods)))
200     static))
201
202 ;;; FULL NAMES
203 ;;
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.
207
208 ;;;###autoload
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))))
224
225 (make-obsolete-overload 'semantic-nonterminal-full-name
226                         'semantic-tag-full-name)
227
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))
232
233 ;;; Compatibility aliases.
234 ;;
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)
253
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)
258
259
260 (provide 'semantic-tag-ls)
261
262 ;;; semantic-tag-ls.el ends here