]> code.delx.au - gnu-emacs/blob - lisp/cedet/semantic/format.el
lisp/cedet/semantic/analyze.el: Add local vars for autoloading.
[gnu-emacs] / lisp / cedet / semantic / format.el
1 ;;; semantic/format.el --- Routines for formatting tags
2
3 ;;; Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2007,
4 ;;; 2008, 2009 Free Software Foundation, Inc.
5
6 ;; Author: Eric M. Ludlam <zappo@gnu.org>
7 ;; Keywords: syntax
8
9 ;; This file is part of GNU Emacs.
10
11 ;; GNU Emacs is free software: you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation, either version 3 of the License, or
14 ;; (at your option) any later version.
15
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
20
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
23
24 ;;; Commentary:
25 ;;
26 ;; Once a language file has been parsed into a TAG, it is often useful
27 ;; then display that tag information in browsers, completion engines, or
28 ;; help routines. The functions and setup in this file provide ways
29 ;; to reformat a tag into different standard output types.
30 ;;
31 ;; In addition, macros for setting up customizable variables that let
32 ;; the user choose their default format type are also provided.
33 ;;
34
35 ;;; Code:
36 (require 'semantic)
37 (require 'semantic/tag)
38 (require 'semantic/tag-ls)
39 (require 'ezimage)
40
41 (eval-when-compile
42 (require 'font-lock)
43 (require 'semantic/find))
44
45 ;;; Tag to text overload functions
46 ;;
47 ;; abbreviations, prototypes, and coloring support.
48 ;;;###autoload
49 (defvar semantic-format-tag-functions
50 '(semantic-format-tag-name
51 semantic-format-tag-canonical-name
52 semantic-format-tag-abbreviate
53 semantic-format-tag-summarize
54 semantic-format-tag-summarize-with-file
55 semantic-format-tag-short-doc
56 semantic-format-tag-prototype
57 semantic-format-tag-concise-prototype
58 semantic-format-tag-uml-abbreviate
59 semantic-format-tag-uml-prototype
60 semantic-format-tag-uml-concise-prototype
61 semantic-format-tag-prin1
62 )
63 "List of functions which convert a tag to text.
64 Each function must take the parameters TAG &optional PARENT COLOR.
65 TAG is the tag to convert.
66 PARENT is a parent tag or name which refers to the structure
67 or class which contains TAG. PARENT is NOT a class which a TAG
68 would claim as a parent.
69 COLOR indicates that the generated text should be colored using
70 `font-lock'.")
71
72 (semantic-varalias-obsolete 'semantic-token->text-functions
73 'semantic-format-tag-functions)
74 ;;;###autoload
75 (defvar semantic-format-tag-custom-list
76 (append '(radio)
77 (mapcar (lambda (f) (list 'const f))
78 semantic-format-tag-functions)
79 '(function))
80 "A List used by customizeable variables to choose a tag to text function.
81 Use this variable in the :type field of a customizable variable.")
82
83 (semantic-varalias-obsolete 'semantic-token->text-custom-list
84 'semantic-format-tag-custom-list)
85
86 (defcustom semantic-format-use-images-flag ezimage-use-images
87 "Non-nil means semantic format functions use images.
88 Images can be used as icons instead of some types of text strings."
89 :group 'semantic
90 :type 'boolean)
91
92 (defvar semantic-function-argument-separator ","
93 "Text used to separate arguments when creating text from tags.")
94 (make-variable-buffer-local 'semantic-function-argument-separator)
95
96 (defvar semantic-format-parent-separator "::"
97 "Text used to separate names when between namespaces/classes and functions.")
98 (make-variable-buffer-local 'semantic-format-parent-separator)
99
100 ;;;###autoload
101 (define-overloadable-function semantic-format-tag-name (tag &optional parent color)
102 "Return the name string describing TAG.
103 The name is the shortest possible representation.
104 Optional argument PARENT is the parent type if TAG is a detail.
105 Optional argument COLOR means highlight the prototype with font-lock colors.")
106
107 ;;;###autoload
108 (define-overloadable-function semantic-format-tag-prototype (tag &optional parent color)
109 "Return a prototype for TAG.
110 This function should be overloaded, though it need not be used.
111 This is because it can be used to create code by language independent
112 tools.
113 Optional argument PARENT is the parent type if TAG is a detail.
114 Optional argument COLOR means highlight the prototype with font-lock colors.")
115
116
117 (defun semantic-test-all-format-tag-functions (&optional arg)
118 "Test all outputs from `semantic-format-tag-functions'.
119 Output is generated from the function under `point'.
120 Optional argument ARG specifies not to use color."
121 (interactive "P")
122 (require 'semantic/find)
123 (semantic-fetch-tags)
124 (let* ((tag (semantic-current-tag))
125 (par (semantic-current-tag-parent))
126 (fns semantic-format-tag-functions))
127 (with-output-to-temp-buffer "*format-tag*"
128 (princ "Tag->format function tests:")
129 (while fns
130 (princ "\n")
131 (princ (car fns))
132 (princ ":\n ")
133 (let ((s (funcall (car fns) tag par (not arg))))
134 (save-excursion
135 (set-buffer "*format-tag*")
136 (goto-char (point-max))
137 (insert s)))
138 (setq fns (cdr fns))))
139 ))
140
141 (defvar semantic-format-face-alist
142 `( (function . font-lock-function-name-face)
143 (variable . font-lock-variable-name-face)
144 (type . font-lock-type-face)
145 ;; These are different between Emacsen.
146 (include . ,(if (featurep 'xemacs)
147 'font-lock-preprocessor-face
148 'font-lock-constant-face))
149 (package . ,(if (featurep 'xemacs)
150 'font-lock-preprocessor-face
151 'font-lock-constant-face))
152 ;; Not a tag, but instead a feature of output
153 (label . font-lock-string-face)
154 (comment . font-lock-comment-face)
155 (keyword . font-lock-keyword-face)
156 (abstract . italic)
157 (static . underline)
158 (documentation . font-lock-doc-face)
159 )
160 "Face used to colorize tags of different types.
161 Override the value locally if a language supports other tag types.
162 When adding new elements, try to use symbols also returned by the parser.
163 The form of an entry in this list is of the form:
164 ( SYMBOL . FACE )
165 where SYMBOL is a tag type symbol used with semantic. FACE
166 is a symbol representing a face.
167 Faces used are generated in `font-lock' for consistency, and will not
168 be used unless font lock is a feature.")
169
170 (semantic-varalias-obsolete 'semantic-face-alist
171 'semantic-format-face-alist)
172
173
174 \f
175 ;;; Coloring Functions
176 ;;
177 (defun semantic--format-colorize-text (text face-class)
178 "Apply onto TEXT a color associated with FACE-CLASS.
179 FACE-CLASS is a tag type found in `semantic-face-alist'. See this variable
180 for details on adding new types."
181 (if (featurep 'font-lock)
182 (let ((face (cdr-safe (assoc face-class semantic-format-face-alist)))
183 (newtext (concat text)))
184 (put-text-property 0 (length text) 'face face newtext)
185 newtext)
186 text))
187
188 (make-obsolete 'semantic-colorize-text
189 'semantic--format-colorize-text)
190
191 (defun semantic--format-colorize-merge-text (precoloredtext face-class)
192 "Apply onto PRECOLOREDTEXT a color associated with FACE-CLASS.
193 FACE-CLASS is a tag type found in 'semantic-face-alist'. See this
194 variable for details on adding new types."
195 (let ((face (cdr-safe (assoc face-class semantic-format-face-alist)))
196 (newtext (concat precoloredtext))
197 )
198 (if (featurep 'xemacs)
199 (add-text-properties 0 (length newtext) (list 'face face) newtext)
200 (alter-text-property 0 (length newtext) 'face
201 (lambda (current-face)
202 (let ((cf
203 (cond ((facep current-face)
204 (list current-face))
205 ((listp current-face)
206 current-face)
207 (t nil)))
208 (nf
209 (cond ((facep face)
210 (list face))
211 ((listp face)
212 face)
213 (t nil))))
214 (append cf nf)))
215 newtext))
216 newtext))
217
218 ;;; Function Arguments
219 ;;
220 (defun semantic--format-tag-arguments (args formatter color)
221 "Format the argument list ARGS with FORMATTER.
222 FORMATTER is a function used to format a tag.
223 COLOR specifies if color should be used."
224 (let ((out nil))
225 (while args
226 (push (if (and formatter
227 (semantic-tag-p (car args))
228 (not (string= (semantic-tag-name (car args)) ""))
229 )
230 (funcall formatter (car args) nil color)
231 (semantic-format-tag-name-from-anything
232 (car args) nil color 'variable))
233 out)
234 (setq args (cdr args)))
235 (mapconcat 'identity (nreverse out) semantic-function-argument-separator)
236 ))
237
238 ;;; Data Type
239 (define-overloadable-function semantic-format-tag-type (tag color)
240 "Convert the data type of TAG to a string usable in tag formatting.
241 It is presumed that TYPE is a string or semantic tag.")
242
243 (defun semantic-format-tag-type-default (tag color)
244 "Convert the data type of TAG to a string usable in tag formatting.
245 Argument COLOR specifies to colorize the text."
246 (let* ((type (semantic-tag-type tag))
247 (out (cond ((semantic-tag-p type)
248 (let* ((typetype (semantic-tag-type type))
249 (name (semantic-tag-name type))
250 (str (if typetype
251 (concat typetype " " name)
252 name)))
253 (if color
254 (semantic--format-colorize-text
255 str
256 'type)
257 str)))
258 ((and (listp type)
259 (stringp (car type)))
260 (car type))
261 ((stringp type)
262 type)
263 (t nil))))
264 (if (and color out)
265 (setq out (semantic--format-colorize-text out 'type))
266 out)
267 ))
268
269 \f
270 ;;; Abstract formatting functions
271
272 (defun semantic-format-tag-prin1 (tag &optional parent color)
273 "Convert TAG to a string that is the print name for TAG.
274 PARENT and COLOR are ignored."
275 (format "%S" tag))
276
277 (defun semantic-format-tag-name-from-anything (anything &optional
278 parent color
279 colorhint)
280 "Convert just about anything into a name like string.
281 Argument ANYTHING is the thing to be converted.
282 Optional argument PARENT is the parent type if TAG is a detail.
283 Optional argument COLOR means highlight the prototype with font-lock colors.
284 Optional COLORHINT is the type of color to use if ANYTHING is not a tag
285 with a tag class. See `semantic--format-colorize-text' for a definition
286 of FACE-CLASS for which this is used."
287 (cond ((stringp anything)
288 (semantic--format-colorize-text anything colorhint))
289 ((semantic-tag-p anything)
290 (let ((ans (semantic-format-tag-name anything parent color)))
291 ;; If ANS is empty string or nil, then the name wasn't
292 ;; supplied. The implication is as in C where there is a data
293 ;; type but no name for a prototype from an include file, or
294 ;; an argument just wasn't used in the body of the fcn.
295 (if (or (null ans) (string= ans ""))
296 (setq ans (semantic-format-tag-type anything color)))
297 ans))
298 ((and (listp anything)
299 (stringp (car anything)))
300 (semantic--format-colorize-text (car anything) colorhint))))
301
302 (defun semantic-format-tag-name-default (tag &optional parent color)
303 "Return an abbreviated string describing TAG.
304 Optional argument PARENT is the parent type if TAG is a detail.
305 Optional argument COLOR means highlight the prototype with font-lock colors."
306 (let ((name (semantic-tag-name tag))
307 (destructor
308 (if (eq (semantic-tag-class tag) 'function)
309 (semantic-tag-function-destructor-p tag))))
310 (when destructor
311 (setq name (concat "~" name)))
312 (if color
313 (setq name (semantic--format-colorize-text name (semantic-tag-class tag))))
314 name))
315
316 (declare-function semantic-go-to-tag "semantic/tag-file")
317
318 (defun semantic--format-tag-parent-tree (tag parent)
319 "Under Consideration.
320
321 Return a list of parents for TAG.
322 PARENT is the first parent, or nil. If nil, then an attempt to
323 determine PARENT is made.
324 Once PARENT is identified, additional parents are looked for.
325 The return list first element is the nearest parent, and the last
326 item is the first parent which may be a string. The root parent may
327 not be the actual first parent as there may just be a failure to find
328 local definitions."
329 ;; First, validate the PARENT argument.
330 (unless parent
331 ;; All mechanisms here must be fast as often parent
332 ;; is nil because there isn't one.
333 (setq parent (or (semantic-tag-function-parent tag)
334 (save-excursion
335 (require 'semantic/tag-file)
336 (semantic-go-to-tag tag)
337 (semantic-current-tag-parent)))))
338 (when (stringp parent)
339 (setq parent (semantic-find-first-tag-by-name
340 parent (current-buffer))))
341 ;; Try and find a trail of parents from PARENT
342 (let ((rlist (list parent))
343 )
344 ;; IMPLELEMENT ME!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
345 (reverse rlist)))
346
347 (define-overloadable-function semantic-format-tag-canonical-name (tag &optional parent color)
348 "Return a canonical name for TAG.
349 A canonical name includes the names of any parents or namespaces preceeding
350 the tag.
351 Optional argument PARENT is the parent type if TAG is a detail.
352 Optional argument COLOR means highlight the prototype with font-lock colors.")
353
354 (defun semantic-format-tag-canonical-name-default (tag &optional parent color)
355 "Return a canonical name for TAG.
356 A canonical name includes the names of any parents or namespaces preceeding
357 the tag with colons separating them.
358 Optional argument PARENT is the parent type if TAG is a detail.
359 Optional argument COLOR means highlight the prototype with font-lock colors."
360 (let ((parent-input-str
361 (if (and parent
362 (semantic-tag-p parent)
363 (semantic-tag-of-class-p parent 'type))
364 (concat
365 ;; Choose a class of 'type as the default parent for something.
366 ;; Just a guess though.
367 (semantic-format-tag-name-from-anything parent nil color 'type)
368 ;; Default separator between class/namespace and others.
369 semantic-format-parent-separator)
370 ""))
371 (tag-parent-str
372 (or (when (and (semantic-tag-of-class-p tag 'function)
373 (semantic-tag-function-parent tag))
374 (concat (semantic-tag-function-parent tag)
375 semantic-format-parent-separator))
376 ""))
377 )
378 (concat parent-input-str
379 tag-parent-str
380 (semantic-format-tag-name tag parent color))
381 ))
382
383 (define-overloadable-function semantic-format-tag-abbreviate (tag &optional parent color)
384 "Return an abbreviated string describing TAG.
385 The abbreviation is to be short, with possible symbols indicating
386 the type of tag, or other information.
387 Optional argument PARENT is the parent type if TAG is a detail.
388 Optional argument COLOR means highlight the prototype with font-lock colors.")
389
390 (defun semantic-format-tag-abbreviate-default (tag &optional parent color)
391 "Return an abbreviated string describing TAG.
392 Optional argument PARENT is a parent tag in the tag hierarchy.
393 In this case PARENT refers to containment, not inheritance.
394 Optional argument COLOR means highlight the prototype with font-lock colors.
395 This is a simple C like default."
396 ;; Do lots of complex stuff here.
397 (let ((class (semantic-tag-class tag))
398 (name (semantic-format-tag-canonical-name tag parent color))
399 (suffix "")
400 (prefix "")
401 str)
402 (cond ((eq class 'function)
403 (setq suffix "()"))
404 ((eq class 'include)
405 (setq suffix "<>"))
406 ((eq class 'variable)
407 (setq suffix (if (semantic-tag-variable-default tag)
408 "=" "")))
409 ((eq class 'label)
410 (setq suffix ":"))
411 ((eq class 'code)
412 (setq prefix "{"
413 suffix "}"))
414 ((eq class 'type)
415 (setq suffix "{}"))
416 )
417 (setq str (concat prefix name suffix))
418 str))
419
420 ;; Semantic 1.2.x had this misspelling. Keep it for backwards compatibiity.
421 (semantic-alias-obsolete
422 'semantic-summerize-nonterminal 'semantic-format-tag-summarize)
423
424 ;;;###autoload
425 (define-overloadable-function semantic-format-tag-summarize (tag &optional parent color)
426 "Summarize TAG in a reasonable way.
427 Optional argument PARENT is the parent type if TAG is a detail.
428 Optional argument COLOR means highlight the prototype with font-lock colors.")
429
430 (defun semantic-format-tag-summarize-default (tag &optional parent color)
431 "Summarize TAG in a reasonable way.
432 Optional argument PARENT is the parent type if TAG is a detail.
433 Optional argument COLOR means highlight the prototype with font-lock colors."
434 (let* ((proto (semantic-format-tag-prototype tag nil color))
435 (names (if parent
436 semantic-symbol->name-assoc-list-for-type-parts
437 semantic-symbol->name-assoc-list))
438 (tsymb (semantic-tag-class tag))
439 (label (capitalize (or (cdr-safe (assoc tsymb names))
440 (symbol-name tsymb)))))
441 (if color
442 (setq label (semantic--format-colorize-text label 'label)))
443 (concat label ": " proto)))
444
445 (define-overloadable-function semantic-format-tag-summarize-with-file (tag &optional parent color)
446 "Like `semantic-format-tag-summarize', but with the file name.
447 Optional argument PARENT is the parent type if TAG is a detail.
448 Optional argument COLOR means highlight the prototype with font-lock colors.")
449
450 (defun semantic-format-tag-summarize-with-file-default (tag &optional parent color)
451 "Summarize TAG in a reasonable way.
452 Optional argument PARENT is the parent type if TAG is a detail.
453 Optional argument COLOR means highlight the prototype with font-lock colors."
454 (let* ((proto (semantic-format-tag-prototype tag nil color))
455 (file (semantic-tag-file-name tag))
456 )
457 ;; Nothing for tag? Try parent.
458 (when (and (not file) (and parent))
459 (setq file (semantic-tag-file-name parent)))
460 ;; Don't include the file name if we can't find one, or it is the
461 ;; same as the current buffer.
462 (if (or (not file)
463 (string= file (buffer-file-name (current-buffer))))
464 proto
465 (setq file (file-name-nondirectory file))
466 (when color
467 (setq file (semantic--format-colorize-text file 'label)))
468 (concat file ": " proto))))
469
470 (define-overloadable-function semantic-format-tag-short-doc (tag &optional parent color)
471 "Display a short form of TAG's documentation. (Comments, or docstring.)
472 Optional argument PARENT is the parent type if TAG is a detail.
473 Optional argument COLOR means highlight the prototype with font-lock colors.")
474
475 (declare-function semantic-documentation-for-tag "semantic/doc")
476
477 (defun semantic-format-tag-short-doc-default (tag &optional parent color)
478 "Display a short form of TAG's documentation. (Comments, or docstring.)
479 Optional argument PARENT is the parent type if TAG is a detail.
480 Optional argument COLOR means highlight the prototype with font-lock colors."
481
482 (let* ((fname (or (semantic-tag-file-name tag)
483 (when parent (semantic-tag-file-name parent))))
484 (buf (or (semantic-tag-buffer tag)
485 (when parent (semantic-tag-buffer parent))))
486 (doc (semantic-tag-docstring tag buf)))
487 (when (and (not doc) (not buf) fname)
488 ;; If there is no doc, and no buffer, but we have a filename,
489 ;; lets try again.
490 (setq buf (find-file-noselect fname))
491 (setq doc (semantic-tag-docstring tag buf)))
492 (when (not doc)
493 (require 'semantic/doc)
494 (setq doc (semantic-documentation-for-tag tag))
495 )
496 (setq doc
497 (if (not doc)
498 ;; No doc, use summarize.
499 (semantic-format-tag-summarize tag parent color)
500 ;; We have doc. Can we devise a single line?
501 (if (string-match "$" doc)
502 (substring doc 0 (match-beginning 0))
503 doc)
504 ))
505 (when color
506 (setq doc (semantic--format-colorize-text doc 'documentation)))
507 doc
508 ))
509
510 ;;; Prototype generation
511 ;;
512 (defun semantic-format-tag-prototype-default (tag &optional parent color)
513 "Default method for returning a prototype for TAG.
514 This will work for C like languages.
515 Optional argument PARENT is the parent type if TAG is a detail.
516 Optional argument COLOR means highlight the prototype with font-lock colors."
517 (let* ((class (semantic-tag-class tag))
518 (name (semantic-format-tag-name tag parent color))
519 (type (if (member class '(function variable type))
520 (semantic-format-tag-type tag color)))
521 (args (if (member class '(function type))
522 (semantic--format-tag-arguments
523 (if (eq class 'function)
524 (semantic-tag-function-arguments tag)
525 (list "")
526 ;;(semantic-tag-type-members tag)
527 )
528 #'semantic-format-tag-prototype
529 color)))
530 (const (semantic-tag-get-attribute tag :constant-flag))
531 (tm (semantic-tag-get-attribute tag :typemodifiers))
532 (mods (append
533 (if const '("const") nil)
534 (cond ((stringp tm) (list tm))
535 ((consp tm) tm)
536 (t nil))
537 ))
538 (array (if (eq class 'variable)
539 (let ((deref
540 (semantic-tag-get-attribute
541 tag :dereference))
542 (r ""))
543 (while (and deref (/= deref 0))
544 (setq r (concat r "[]")
545 deref (1- deref)))
546 r)))
547 )
548 (if args
549 (setq args
550 (concat " "
551 (if (eq class 'type) "{" "(")
552 args
553 (if (eq class 'type) "}" ")"))))
554 (when mods
555 (setq mods (concat (mapconcat 'identity mods " ") " ")))
556 (concat (or mods "")
557 (if type (concat type " "))
558 name
559 (or args "")
560 (or array ""))))
561
562 (define-overloadable-function semantic-format-tag-concise-prototype (tag &optional parent color)
563 "Return a concise prototype for TAG.
564 Optional argument PARENT is the parent type if TAG is a detail.
565 Optional argument COLOR means highlight the prototype with font-lock colors.")
566
567 (defun semantic-format-tag-concise-prototype-default (tag &optional parent color)
568 "Return a concise prototype for TAG.
569 This default function will make a cheap concise prototype using C like syntax.
570 Optional argument PARENT is the parent type if TAG is a detail.
571 Optional argument COLOR means highlight the prototype with font-lock colors."
572 (let ((class (semantic-tag-class tag)))
573 (cond
574 ((eq class 'type)
575 (concat (semantic-format-tag-name tag parent color) "{}"))
576 ((eq class 'function)
577 (concat (semantic-format-tag-name tag parent color)
578 " ("
579 (semantic--format-tag-arguments
580 (semantic-tag-function-arguments tag)
581 'semantic-format-tag-concise-prototype
582 color)
583 ")"))
584 ((eq class 'variable)
585 (let* ((deref (semantic-tag-get-attribute
586 tag :dereference))
587 (array "")
588 )
589 (while (and deref (/= deref 0))
590 (setq array (concat array "[]")
591 deref (1- deref)))
592 (concat (semantic-format-tag-name tag parent color)
593 array)))
594 (t
595 (semantic-format-tag-abbreviate tag parent color)))))
596
597 ;;; UML display styles
598 ;;
599 (defcustom semantic-uml-colon-string " : "
600 "*String used as a color separator between parts of a UML string.
601 In UML, a variable may appear as `varname : type'.
602 Change this variable to change the output separator."
603 :group 'semantic
604 :type 'string)
605
606 (defcustom semantic-uml-no-protection-string ""
607 "*String used to describe when no protection is specified.
608 Used by `semantic-format-tag-uml-protection-to-string'."
609 :group 'semantic
610 :type 'string)
611
612 (defun semantic--format-uml-post-colorize (text tag parent)
613 "Add color to TEXT created from TAG and PARENT.
614 Adds augmentation for `abstract' and `static' entries."
615 (if (semantic-tag-abstract-p tag parent)
616 (setq text (semantic--format-colorize-merge-text text 'abstract)))
617 (if (semantic-tag-static-p tag parent)
618 (setq text (semantic--format-colorize-merge-text text 'static)))
619 text
620 )
621
622 (defun semantic-uml-attribute-string (tag &optional parent)
623 "Return a string for TAG, a child of PARENT representing a UML attribute.
624 UML attribute strings are things like {abstract} or {leaf}."
625 (cond ((semantic-tag-abstract-p tag parent)
626 "{abstract}")
627 ((semantic-tag-leaf-p tag parent)
628 "{leaf}")
629 ))
630
631 (defvar semantic-format-tag-protection-image-alist
632 '(("+" . ezimage-unlock)
633 ("#" . ezimage-key)
634 ("-" . ezimage-lock)
635 )
636 "Association of protection strings, and images to use.")
637
638 (defvar semantic-format-tag-protection-symbol-to-string-assoc-list
639 '((public . "+")
640 (protected . "#")
641 (private . "-")
642 )
643 "Association list of the form (SYMBOL . \"STRING\") for protection symbols.
644 This associates a symbol, such as 'public with the st ring \"+\".")
645
646 (define-overloadable-function semantic-format-tag-uml-protection-to-string (protection-symbol color)
647 "Convert PROTECTION-SYMBOL to a string for UML.
648 By default, uses `semantic-format-tag-protection-symbol-to-string-assoc-list'
649 to convert.
650 By defaul character returns are:
651 public -- +
652 private -- -
653 protected -- #.
654 If PROTECTION-SYMBOL is unknown, then the return value is
655 `semantic-uml-no-protection-string'.
656 COLOR indicates if we should use an image on the text.")
657
658 (defun semantic-format-tag-uml-protection-to-string-default (protection-symbol color)
659 "Convert PROTECTION-SYMBOL to a string for UML.
660 Uses `semantic-format-tag-protection-symbol-to-string-assoc-list' to convert.
661 If PROTECTION-SYMBOL is unknown, then the return value is
662 `semantic-uml-no-protection-string'.
663 COLOR indicates if we should use an image on the text."
664 (let* ((ezimage-use-images (and semantic-format-use-images-flag color))
665 (key (assoc protection-symbol
666 semantic-format-tag-protection-symbol-to-string-assoc-list))
667 (str (or (cdr-safe key) semantic-uml-no-protection-string)))
668 (ezimage-image-over-string
669 (copy-sequence str) ; make a copy to keep the original pristine.
670 semantic-format-tag-protection-image-alist)))
671
672 (defsubst semantic-format-tag-uml-protection (tag parent color)
673 "Retrieve the protection string for TAG with PARENT.
674 Argument COLOR specifies that color should be added to the string as
675 needed."
676 (semantic-format-tag-uml-protection-to-string
677 (semantic-tag-protection tag parent)
678 color))
679
680 (defun semantic--format-tag-uml-type (tag color)
681 "Format the data type of TAG to a string usable for formatting.
682 COLOR indicates if it should be colorized."
683 (let ((str (semantic-format-tag-type tag color)))
684 (if str
685 (concat semantic-uml-colon-string str))))
686
687 (define-overloadable-function semantic-format-tag-uml-abbreviate (tag &optional parent color)
688 "Return a UML style abbreviation for TAG.
689 Optional argument PARENT is the parent type if TAG is a detail.
690 Optional argument COLOR means highlight the prototype with font-lock colors.")
691
692 (defun semantic-format-tag-uml-abbreviate-default (tag &optional parent color)
693 "Return a UML style abbreviation for TAG.
694 Optional argument PARENT is the parent type if TAG is a detail.
695 Optional argument COLOR means highlight the prototype with font-lock colors."
696 (let* ((name (semantic-format-tag-name tag parent color))
697 (type (semantic--format-tag-uml-type tag color))
698 (protstr (semantic-format-tag-uml-protection tag parent color))
699 (text nil))
700 (setq text
701 (concat
702 protstr
703 (if type (concat name type)
704 name)))
705 (if color
706 (setq text (semantic--format-uml-post-colorize text tag parent)))
707 text))
708
709 (define-overloadable-function semantic-format-tag-uml-prototype (tag &optional parent color)
710 "Return a UML style prototype for TAG.
711 Optional argument PARENT is the parent type if TAG is a detail.
712 Optional argument COLOR means highlight the prototype with font-lock colors.")
713
714 (defun semantic-format-tag-uml-prototype-default (tag &optional parent color)
715 "Return a UML style prototype for TAG.
716 Optional argument PARENT is the parent type if TAG is a detail.
717 Optional argument COLOR means highlight the prototype with font-lock colors."
718 (let* ((class (semantic-tag-class tag))
719 (cp (semantic-format-tag-name tag parent color))
720 (type (semantic--format-tag-uml-type tag color))
721 (prot (semantic-format-tag-uml-protection tag parent color))
722 (argtext
723 (cond ((eq class 'function)
724 (concat
725 " ("
726 (semantic--format-tag-arguments
727 (semantic-tag-function-arguments tag)
728 #'semantic-format-tag-uml-prototype
729 color)
730 ")"))
731 ((eq class 'type)
732 "{}")))
733 (text nil))
734 (setq text (concat prot cp argtext type))
735 (if color
736 (setq text (semantic--format-uml-post-colorize text tag parent)))
737 text
738 ))
739
740 (define-overloadable-function semantic-format-tag-uml-concise-prototype (tag &optional parent color)
741 "Return a UML style concise prototype for TAG.
742 Optional argument PARENT is the parent type if TAG is a detail.
743 Optional argument COLOR means highlight the prototype with font-lock colors.")
744
745 (defun semantic-format-tag-uml-concise-prototype-default (tag &optional parent color)
746 "Return a UML style concise prototype for TAG.
747 Optional argument PARENT is the parent type if TAG is a detail.
748 Optional argument COLOR means highlight the prototype with font-lock colors."
749 (let* ((cp (semantic-format-tag-concise-prototype tag parent color))
750 (type (semantic--format-tag-uml-type tag color))
751 (prot (semantic-format-tag-uml-protection tag parent color))
752 (text nil)
753 )
754 (setq text (concat prot cp type))
755 (if color
756 (setq text (semantic--format-uml-post-colorize text tag parent)))
757 text
758 ))
759
760 \f
761 ;;; Compatibility and aliases
762 ;;
763 (semantic-alias-obsolete 'semantic-prin1-nonterminal
764 'semantic-format-tag-prin1)
765
766 (semantic-alias-obsolete 'semantic-name-nonterminal
767 'semantic-format-tag-name)
768
769 (semantic-alias-obsolete 'semantic-abbreviate-nonterminal
770 'semantic-format-tag-abbreviate)
771
772 (semantic-alias-obsolete 'semantic-summarize-nonterminal
773 'semantic-format-tag-summarize)
774
775 (semantic-alias-obsolete 'semantic-prototype-nonterminal
776 'semantic-format-tag-prototype)
777
778 (semantic-alias-obsolete 'semantic-concise-prototype-nonterminal
779 'semantic-format-tag-concise-prototype)
780
781 (semantic-alias-obsolete 'semantic-uml-abbreviate-nonterminal
782 'semantic-format-tag-uml-abbreviate)
783
784 (semantic-alias-obsolete 'semantic-uml-prototype-nonterminal
785 'semantic-format-tag-uml-prototype)
786
787 (semantic-alias-obsolete 'semantic-uml-concise-prototype-nonterminal
788 'semantic-format-tag-uml-concise-prototype)
789
790
791 (provide 'semantic/format)
792
793 ;; Local variables:
794 ;; generated-autoload-file: "loaddefs.el"
795 ;; generated-autoload-feature: semantic/loaddefs
796 ;; End:
797
798 ;;; semantic/format.el ends here