Merge from CEDET upstream (8564).
[bpt/emacs.git] / lisp / cedet / semantic / ctxt.el
1 ;;; semantic/ctxt.el --- Context calculations for Semantic tools.
2
3 ;; Copyright (C) 1999-2013 Free Software Foundation, Inc.
4
5 ;; Author: Eric M. Ludlam <zappo@gnu.org>
6 ;; Keywords: syntax
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 ;; Semantic, as a tool, provides a nice list of searchable tags.
26 ;; That information can provide some very accurate answers if the current
27 ;; context of a position is known.
28 ;;
29 ;; This library provides the hooks needed for a language to specify how
30 ;; the current context is calculated.
31 ;;
32 (require 'semantic)
33
34 ;;; Code:
35 (defvar semantic-command-separation-character
36 ";"
37 "String which indicates the end of a command.
38 Used for identifying the end of a single command.")
39 (make-variable-buffer-local 'semantic-command-separation-character)
40
41 (defvar semantic-function-argument-separation-character
42 ","
43 "String which indicates the end of an argument.
44 Used for identifying arguments to functions.")
45 (make-variable-buffer-local 'semantic-function-argument-separation-character)
46
47 ;;; Local Contexts
48 ;;
49 ;; These context are nested blocks of code, such as code in an
50 ;; if clause
51 (declare-function semantic-current-tag-of-class "semantic/find")
52
53 (define-overloadable-function semantic-up-context (&optional point bounds-type)
54 "Move point up one context from POINT.
55 Return non-nil if there are no more context levels.
56 Overloaded functions using `up-context' take no parameters.
57 BOUNDS-TYPE is a symbol representing a tag class to restrict
58 movement to. If this is nil, 'function is used.
59 This will find the smallest tag of that class (function, variable,
60 type, etc) and make sure non-nil is returned if you cannot
61 go up past the bounds of that tag."
62 (require 'semantic/find)
63 (if point (goto-char point))
64 (let ((nar (semantic-current-tag-of-class (or bounds-type 'function))))
65 (if nar
66 (semantic-with-buffer-narrowed-to-tag nar (:override-with-args ()))
67 (when bounds-type
68 (error "No context of type %s to advance in" bounds-type))
69 (:override-with-args ()))))
70
71 (defun semantic-up-context-default ()
72 "Move the point up and out one context level.
73 Works with languages that use parenthetical grouping."
74 ;; By default, assume that the language uses some form of parenthetical
75 ;; do dads for their context.
76 (condition-case nil
77 (progn
78 (up-list -1)
79 nil)
80 (error t)))
81
82 (define-overloadable-function semantic-beginning-of-context (&optional point)
83 "Move POINT to the beginning of the current context.
84 Return non-nil if there is no upper context.
85 The default behavior uses `semantic-up-context'.")
86
87 (defun semantic-beginning-of-context-default (&optional point)
88 "Move POINT to the beginning of the current context via parenthesis.
89 Return non-nil if there is no upper context."
90 (if point (goto-char point))
91 (if (semantic-up-context)
92 t
93 (forward-char 1)
94 nil))
95
96 (define-overloadable-function semantic-end-of-context (&optional point)
97 "Move POINT to the end of the current context.
98 Return non-nil if there is no upper context.
99 Be default, this uses `semantic-up-context', and assumes parenthetical
100 block delimiters.")
101
102 (defun semantic-end-of-context-default (&optional point)
103 "Move POINT to the end of the current context via parenthesis.
104 Return non-nil if there is no upper context."
105 (if point (goto-char point))
106 (let ((start (point)))
107 (if (semantic-up-context)
108 t
109 ;; Go over the list, and back over the end parenthesis.
110 (condition-case nil
111 (progn
112 (forward-sexp 1)
113 (forward-char -1))
114 (error
115 ;; If an error occurs, get the current tag from the cache,
116 ;; and just go to the end of that. Make sure we end up at least
117 ;; where start was so parse-region type calls work.
118 (if (semantic-current-tag)
119 (progn
120 (goto-char (semantic-tag-end (semantic-current-tag)))
121 (when (< (point) start)
122 (goto-char start)))
123 (goto-char start))
124 t)))
125 nil))
126
127 (defun semantic-narrow-to-context ()
128 "Narrow the buffer to the extent of the current context."
129 (let (b e)
130 (save-excursion
131 (if (semantic-beginning-of-context)
132 nil
133 (setq b (point))))
134 (save-excursion
135 (if (semantic-end-of-context)
136 nil
137 (setq e (point))))
138 (if (and b e) (narrow-to-region b e))))
139
140 (defmacro semantic-with-buffer-narrowed-to-context (&rest body)
141 "Execute BODY with the buffer narrowed to the current context."
142 `(save-restriction
143 (semantic-narrow-to-context)
144 ,@body))
145 (put 'semantic-with-buffer-narrowed-to-context 'lisp-indent-function 0)
146 (add-hook 'edebug-setup-hook
147 (lambda ()
148 (def-edebug-spec semantic-with-buffer-narrowed-to-context
149 (def-body))))
150
151 ;;; Local Variables
152 ;;
153 ;;
154 (define-overloadable-function semantic-get-local-variables (&optional point)
155 "Get the local variables based on POINT's context.
156 Local variables are returned in Semantic tag format.
157 This can be overridden with `get-local-variables'."
158 ;; Disable parsing messages
159 (let ((semantic--progress-reporter nil))
160 (save-excursion
161 (if point (goto-char point))
162 (let* ((case-fold-search semantic-case-fold))
163 (:override-with-args ())))))
164
165 (defun semantic-get-local-variables-default ()
166 "Get local values from a specific context.
167 Uses the bovinator with the special top-symbol `bovine-inner-scope'
168 to collect tags, such as local variables or prototypes."
169 ;; This assumes a bovine parser. Make sure we don't do
170 ;; anything in that case.
171 (when (and semantic--parse-table (not (eq semantic--parse-table t))
172 (not (semantic-parse-tree-unparseable-p)))
173 (let ((vars (semantic-get-cache-data 'get-local-variables)))
174 (if vars
175 (progn
176 ;;(message "Found cached vars.")
177 vars)
178 (let ((vars2 nil)
179 ;; We want nothing to do with funny syntaxing while doing this.
180 (semantic-unmatched-syntax-hook nil)
181 (start (point))
182 (firstusefulstart nil)
183 )
184 (while (not (semantic-up-context (point) 'function))
185 (when (not vars)
186 (setq firstusefulstart (point)))
187 (save-excursion
188 (forward-char 1)
189 (setq vars
190 ;; Note to self: semantic-parse-region returns cooked
191 ;; but unlinked tags. File information is lost here
192 ;; and is added next.
193 (append (semantic-parse-region
194 (point)
195 (save-excursion (semantic-end-of-context) (point))
196 'bovine-inner-scope
197 nil
198 t)
199 vars))))
200 ;; Modify the tags in place.
201 (setq vars2 vars)
202 (while vars2
203 (semantic--tag-put-property (car vars2) :filename (buffer-file-name))
204 (setq vars2 (cdr vars2)))
205 ;; Hash our value into the first context that produced useful results.
206 (when (and vars firstusefulstart)
207 (let ((end (save-excursion
208 (goto-char firstusefulstart)
209 (save-excursion
210 (unless (semantic-end-of-context)
211 (point))))))
212 ;;(message "Caching values %d->%d." firstusefulstart end)
213 (semantic-cache-data-to-buffer
214 (current-buffer) firstusefulstart
215 (or end
216 ;; If the end-of-context fails,
217 ;; just use our cursor starting
218 ;; position.
219 start)
220 vars 'get-local-variables 'exit-cache-zone))
221 )
222 ;; Return our list.
223 vars)))))
224
225 (define-overloadable-function semantic-get-local-arguments (&optional point)
226 "Get arguments (variables) from the current context at POINT.
227 Parameters are available if the point is in a function or method.
228 Return a list of tags unlinked from the originating buffer.
229 Arguments are obtained by overriding `get-local-arguments', or by the
230 default function `semantic-get-local-arguments-default'. This, must
231 return a list of tags, or a list of strings that will be converted to
232 tags."
233 (save-excursion
234 (if point (goto-char point))
235 (let* ((case-fold-search semantic-case-fold)
236 (args (:override-with-args ()))
237 arg tags)
238 ;; Convert unsafe arguments to the right thing.
239 (while args
240 (setq arg (car args)
241 args (cdr args)
242 tags (cons (cond
243 ((semantic-tag-p arg)
244 ;; Return a copy of tag without overlay.
245 ;; The overlay is preserved.
246 (semantic-tag-copy arg nil t))
247 ((stringp arg)
248 (semantic--tag-put-property
249 (semantic-tag-new-variable arg nil nil)
250 :filename (buffer-file-name)))
251 (t
252 (error "Unknown parameter element %S" arg)))
253 tags)))
254 (nreverse tags))))
255
256 (defun semantic-get-local-arguments-default ()
257 "Get arguments (variables) from the current context.
258 Parameters are available if the point is in a function or method."
259 (let ((tag (semantic-current-tag)))
260 (if (and tag (semantic-tag-of-class-p tag 'function))
261 (semantic-tag-function-arguments tag))))
262
263 (define-overloadable-function semantic-get-all-local-variables (&optional point)
264 "Get all local variables for this context, and parent contexts.
265 Local variables are returned in Semantic tag format.
266 Be default, this gets local variables, and local arguments.
267 Optional argument POINT is the location to start getting the variables from.")
268
269 (defun semantic-get-all-local-variables-default (&optional point)
270 "Get all local variables for this context.
271 Optional argument POINT is the location to start getting the variables from.
272 That is a cons (LOCAL-ARGUMENTS . LOCAL-VARIABLES) where:
273
274 - LOCAL-ARGUMENTS is collected by `semantic-get-local-arguments'.
275 - LOCAL-VARIABLES is collected by `semantic-get-local-variables'."
276 (save-excursion
277 (if point (goto-char point))
278 (let ((case-fold-search semantic-case-fold))
279 (append (semantic-get-local-arguments)
280 (semantic-get-local-variables)))))
281
282 ;;; Local context parsing
283 ;;
284 ;; Context parsing assumes a series of language independent commonalities.
285 ;; These terms are used to describe those contexts:
286 ;;
287 ;; command - One command in the language.
288 ;; symbol - The symbol the cursor is on.
289 ;; This would include a series of type/field when applicable.
290 ;; assignment - The variable currently being assigned to
291 ;; function - The function call the cursor is on/in
292 ;; argument - The index to the argument the cursor is on.
293 ;;
294 ;;
295 (define-overloadable-function semantic-end-of-command ()
296 "Move to the end of the current command.
297 Be default, uses `semantic-command-separation-character'.")
298
299 (defun semantic-end-of-command-default ()
300 "Move to the end of the current command.
301 Depends on `semantic-command-separation-character' to find the
302 beginning and end of a command."
303 (semantic-with-buffer-narrowed-to-context
304 (let ((case-fold-search semantic-case-fold))
305 (with-syntax-table semantic-lex-syntax-table
306
307 (if (re-search-forward (regexp-quote semantic-command-separation-character)
308 nil t)
309 (forward-char -1)
310 ;; If there wasn't a command after this, we are the last
311 ;; command, and we are incomplete.
312 (goto-char (point-max)))))))
313
314 (define-overloadable-function semantic-beginning-of-command ()
315 "Move to the beginning of the current command.
316 Be default, uses `semantic-command-separation-character'.")
317
318 (defun semantic-beginning-of-command-default ()
319 "Move to the beginning of the current command.
320 Depends on `semantic-command-separation-character' to find the
321 beginning and end of a command."
322 (semantic-with-buffer-narrowed-to-context
323 (with-syntax-table semantic-lex-syntax-table
324 (let ((case-fold-search semantic-case-fold))
325 (skip-chars-backward semantic-command-separation-character)
326 (if (re-search-backward (regexp-quote semantic-command-separation-character)
327 nil t)
328 (goto-char (match-end 0))
329 ;; If there wasn't a command after this, we are the last
330 ;; command, and we are incomplete.
331 (goto-char (point-min)))
332 (skip-chars-forward " \t\n")
333 ))))
334
335
336 (defsubst semantic-point-at-beginning-of-command ()
337 "Return the point at the beginning of the current command."
338 (save-excursion (semantic-beginning-of-command) (point)))
339
340 (defsubst semantic-point-at-end-of-command ()
341 "Return the point at the beginning of the current command."
342 (save-excursion (semantic-end-of-command) (point)))
343
344 (defsubst semantic-narrow-to-command ()
345 "Narrow the current buffer to the current command."
346 (narrow-to-region (semantic-point-at-beginning-of-command)
347 (semantic-point-at-end-of-command)))
348
349 (defmacro semantic-with-buffer-narrowed-to-command (&rest body)
350 "Execute BODY with the buffer narrowed to the current command."
351 `(save-restriction
352 (semantic-narrow-to-command)
353 ,@body))
354 (put 'semantic-with-buffer-narrowed-to-command 'lisp-indent-function 0)
355 (add-hook 'edebug-setup-hook
356 (lambda ()
357 (def-edebug-spec semantic-with-buffer-narrowed-to-command
358 (def-body))))
359
360 (define-overloadable-function semantic-ctxt-end-of-symbol (&optional point)
361 "Move point to the end of the current symbol under POINT.
362 This skips forward over symbols in a complex reference.
363 For example, in the C statement:
364 this.that().entry;
365
366 If the cursor is on 'this', will move point to the ; after entry.")
367
368 (defun semantic-ctxt-end-of-symbol-default (&optional point)
369 "Move poin to the end of the current symbol under POINT.
370 This will move past type/field names when applicable.
371 Depends on `semantic-type-relation-separator-character', and will
372 work on C like languages."
373 (if point (goto-char point))
374 (let* ((fieldsep1 (mapconcat (lambda (a) (regexp-quote a))
375 semantic-type-relation-separator-character
376 "\\|"))
377 ;; NOTE: The [ \n] expression below should used \\s-, but that
378 ;; doesn't work in C since \n means end-of-comment, and isn't
379 ;; really whitespace.
380 (fieldsep (concat "[ \t\n\r]*\\(" fieldsep1 "\\)[ \t\n\r]*\\(\\w\\|\\s_\\)"))
381 (case-fold-search semantic-case-fold)
382 (continuesearch t)
383 (end nil)
384 )
385 (with-syntax-table semantic-lex-syntax-table
386 (cond ((looking-at "\\w\\|\\s_")
387 ;; In the middle of a symbol, move to the end.
388 (forward-sexp 1))
389 ((looking-at fieldsep1)
390 ;; We are in a fine spot.. do nothing.
391 nil
392 )
393 ((save-excursion
394 (and (condition-case nil
395 (progn (forward-sexp -1)
396 (forward-sexp 1)
397 t)
398 (error nil))
399 (looking-at fieldsep1)))
400 (setq symlist (list ""))
401 (forward-sexp -1)
402 ;; Skip array expressions.
403 (while (looking-at "\\s(") (forward-sexp -1))
404 (forward-sexp 1))
405 )
406 ;; Set the current end marker.
407 (setq end (point))
408
409 ;; Cursor is at the safe end of some symbol. Look until we
410 ;; find the logical end of this current complex symbol.
411 (condition-case nil
412 (while continuesearch
413 ;; If there are functional arguments, arrays, etc, skip them.
414 (when (looking-at "\\s(")
415 (forward-sexp 1))
416
417 ;; If there is a field separator, then skip that, plus
418 ;; the next expected symbol.
419 (if (not (looking-at fieldsep1))
420 ;; We hit the end.
421 (error nil)
422
423 ;; Skip the separator and the symbol.
424 (goto-char (match-end 0))
425
426 (if (looking-at "\\w\\|\\s_")
427 ;; Skip symbols
428 (forward-sexp 1)
429 ;; No symbol, exit the search...
430 (setq continuesearch nil))
431
432 (setq end (point)))
433
434 ;; Cont...
435 )
436
437 ;; Restore position if we go to far....
438 (error (goto-char end)) )
439
440 )))
441
442 (define-overloadable-function semantic-ctxt-current-symbol (&optional point)
443 "Return the current symbol the cursor is on at POINT in a list.
444 The symbol includes all logical parts of a complex reference.
445 For example, in C the statement:
446 this.that().entry
447
448 Would be object `this' calling method `that' which returns some structure
449 whose field `entry' is being reference. In this case, this function
450 would return the list:
451 ( \"this\" \"that\" \"entry\" )")
452
453 (defun semantic-ctxt-current-symbol-default (&optional point)
454 "Return the current symbol the cursor is on at POINT in a list.
455 This will include a list of type/field names when applicable.
456 Depends on `semantic-type-relation-separator-character'."
457 (save-excursion
458 (if point (goto-char point))
459 (let* ((fieldsep1 (mapconcat (lambda (a) (regexp-quote a))
460 semantic-type-relation-separator-character
461 "\\|"))
462 ;; NOTE: The [ \n] expression below should used \\s-, but that
463 ;; doesn't work in C since \n means end-of-comment, and isn't
464 ;; really whitespace.
465 (fieldsep (concat "[ \t\n\r]*\\(" fieldsep1 "\\)[ \t\n\r]*\\(\\w\\|\\s_\\)"))
466 (case-fold-search semantic-case-fold)
467 (symlist nil)
468 end)
469 (with-syntax-table semantic-lex-syntax-table
470 (save-excursion
471 (cond ((looking-at "\\w\\|\\s_")
472 ;; In the middle of a symbol, move to the end.
473 (forward-sexp 1))
474 ((looking-at fieldsep1)
475 ;; We are in a fine spot.. do nothing.
476 nil
477 )
478 ((save-excursion
479 (and (condition-case nil
480 (progn (forward-sexp -1)
481 (forward-sexp 1)
482 t)
483 (error nil))
484 (looking-at fieldsep1)))
485 (setq symlist (list ""))
486 (forward-sexp -1)
487 ;; Skip array expressions.
488 (while (looking-at "\\s(") (forward-sexp -1))
489 (forward-sexp 1))
490 )
491 ;; Set our end point.
492 (setq end (point))
493
494 ;; Now that we have gotten started, let's do the rest.
495 (condition-case nil
496 (while (save-excursion
497 (forward-char -1)
498 (looking-at "\\w\\|\\s_"))
499 ;; We have a symbol.. Do symbol things
500 (forward-sexp -1)
501 (setq symlist (cons (buffer-substring-no-properties (point) end)
502 symlist))
503 ;; Skip the next syntactic expression backwards, then go forwards.
504 (let ((cp (point)))
505 (forward-sexp -1)
506 (forward-sexp 1)
507 ;; If we end up at the same place we started, we are at the
508 ;; beginning of a buffer, or narrowed to a command and
509 ;; have to stop.
510 (if (<= cp (point)) (error nil)))
511 (if (looking-at fieldsep)
512 (progn
513 (forward-sexp -1)
514 ;; Skip array expressions.
515 (while (and (looking-at "\\s(") (not (bobp)))
516 (forward-sexp -1))
517 (forward-sexp 1)
518 (setq end (point)))
519 (error nil))
520 )
521 (error nil)))
522 symlist))))
523
524
525 (define-overloadable-function semantic-ctxt-current-symbol-and-bounds (&optional point)
526 "Return the current symbol and bounds the cursor is on at POINT.
527 The symbol should be the same as returned by `semantic-ctxt-current-symbol'.
528 Return (PREFIX ENDSYM BOUNDS).")
529
530 (defun semantic-ctxt-current-symbol-and-bounds-default (&optional point)
531 "Return the current symbol and bounds the cursor is on at POINT.
532 Uses `semantic-ctxt-current-symbol' to calculate the symbol.
533 Return (PREFIX ENDSYM BOUNDS)."
534 (save-excursion
535 (when point (goto-char (point)))
536 (let* ((prefix (semantic-ctxt-current-symbol))
537 (endsym (car (reverse prefix)))
538 ;; @todo - Can we get this data direct from ctxt-current-symbol?
539 (bounds (save-excursion
540 (cond ((string= endsym "")
541 (cons (point) (point))
542 )
543 ((and prefix (looking-at endsym))
544 (cons (point) (progn
545 (condition-case nil
546 (forward-sexp 1)
547 (error nil))
548 (point))))
549 (prefix
550 (condition-case nil
551 (cons (progn (forward-sexp -1) (point))
552 (progn (forward-sexp 1) (point)))
553 (error nil)))
554 (t nil))))
555 )
556 (list prefix endsym bounds))))
557
558 (define-overloadable-function semantic-ctxt-current-assignment (&optional point)
559 "Return the current assignment near the cursor at POINT.
560 Return a list as per `semantic-ctxt-current-symbol'.
561 Return nil if there is nothing relevant.")
562
563 (defun semantic-ctxt-current-assignment-default (&optional point)
564 "Return the current assignment near the cursor at POINT.
565 By default, assume that \"=\" indicates an assignment."
566 (if point (goto-char point))
567 (let ((case-fold-search semantic-case-fold))
568 (with-syntax-table semantic-lex-syntax-table
569 (condition-case nil
570 (semantic-with-buffer-narrowed-to-command
571 (save-excursion
572 (skip-chars-forward " \t=")
573 (condition-case nil (forward-char 1) (error nil))
574 (re-search-backward "[^=]=\\([^=]\\|$\\)")
575 ;; We are at an equals sign. Go backwards a sexp, and
576 ;; we'll have the variable. Otherwise we threw an error
577 (forward-sexp -1)
578 (semantic-ctxt-current-symbol)))
579 (error nil)))))
580
581 (define-overloadable-function semantic-ctxt-current-function (&optional point)
582 "Return the current function call the cursor is in at POINT.
583 The function returned is the one accepting the arguments that
584 the cursor is currently in. It will not return function symbol if the
585 cursor is on the text representing that function.")
586
587 (defun semantic-ctxt-current-function-default (&optional point)
588 "Return the current function call the cursor is in at POINT.
589 The call will be identified for C like languages with the form
590 NAME ( args ... )"
591 (if point (goto-char point))
592 (let ((case-fold-search semantic-case-fold))
593 (with-syntax-table semantic-lex-syntax-table
594 (save-excursion
595 (semantic-up-context)
596 (when (looking-at "(")
597 (semantic-ctxt-current-symbol))))
598 ))
599
600 (define-overloadable-function semantic-ctxt-current-argument (&optional point)
601 "Return the index of the argument position the cursor is on at POINT.")
602
603 (defun semantic-ctxt-current-argument-default (&optional point)
604 "Return the index of the argument the cursor is on at POINT.
605 Depends on `semantic-function-argument-separation-character'."
606 (if point (goto-char point))
607 (let ((case-fold-search semantic-case-fold))
608 (with-syntax-table semantic-lex-syntax-table
609 (when (semantic-ctxt-current-function)
610 (save-excursion
611 ;; Only get the current arg index if we are in function args.
612 (let ((p (point))
613 (idx 1))
614 (semantic-up-context)
615 (while (re-search-forward
616 (regexp-quote semantic-function-argument-separation-character)
617 p t)
618 (setq idx (1+ idx)))
619 idx))))))
620
621 (defun semantic-ctxt-current-thing ()
622 "Calculate a thing identified by the current cursor position.
623 Calls previously defined `semantic-ctxt-current-...' calls until something
624 gets a match. See `semantic-ctxt-current-symbol',
625 `semantic-ctxt-current-function', and `semantic-ctxt-current-assignment'
626 for details on the return value."
627 (or (semantic-ctxt-current-symbol)
628 (semantic-ctxt-current-function)
629 (semantic-ctxt-current-assignment)))
630
631 (define-overloadable-function semantic-ctxt-current-class-list (&optional point)
632 "Return a list of tag classes that are allowed at POINT.
633 If POINT is nil, the current buffer location is used.
634 For example, in Emacs Lisp, the symbol after a ( is most likely
635 a function. In a makefile, symbols after a : are rules, and symbols
636 after a $( are variables.")
637
638 (defun semantic-ctxt-current-class-list-default (&optional point)
639 "Return a list of tag classes that are allowed at POINT.
640 Assume a functional typed language. Uses very simple rules."
641 (save-excursion
642 (if point (goto-char point))
643
644 (let ((tag (semantic-current-tag)))
645 (if tag
646 (cond ((semantic-tag-of-class-p tag 'function)
647 '(function variable type))
648 ((or (semantic-tag-of-class-p tag 'type)
649 (semantic-tag-of-class-p tag 'variable))
650 '(type))
651 (t nil))
652 '(type)
653 ))))
654
655 ;;;###autoload
656 (define-overloadable-function semantic-ctxt-current-mode (&optional point)
657 "Return the major mode active at POINT.
658 POINT defaults to the value of point in current buffer.
659 You should override this function in multiple mode buffers to
660 determine which major mode apply at point.")
661
662 (defun semantic-ctxt-current-mode-default (&optional point)
663 "Return the major mode active at POINT.
664 POINT defaults to the value of point in current buffer.
665 This default implementation returns the current major mode."
666 major-mode)
667 \f
668 ;;; Scoped Types
669 ;;
670 ;; Scoped types are types that the current code would have access to.
671 ;; The come from the global namespace or from special commands such as "using"
672 (define-overloadable-function semantic-ctxt-scoped-types (&optional point)
673 "Return a list of type names currently in scope at POINT.
674 The return value can be a mixed list of either strings (names of
675 types that are in scope) or actual tags (type declared locally
676 that may or may not have a name.)")
677
678 (defun semantic-ctxt-scoped-types-default (&optional point)
679 "Return a list of scoped types by name for the current context at POINT.
680 This is very different for various languages, and does nothing unless
681 overridden."
682 nil)
683
684 (define-overloadable-function semantic-ctxt-imported-packages (&optional point)
685 "Return a list of package tags or names which are being imported at POINT.
686 The return value is a list of strings which are package names
687 that are implied in code. Thus a C++ symbol:
688 foo::bar();
689 where there is a statement such as:
690 using baz;
691 means that the first symbol might be:
692 baz::foo::bar();"
693 nil)
694
695 (provide 'semantic/ctxt)
696
697 ;; Local variables:
698 ;; generated-autoload-file: "loaddefs.el"
699 ;; generated-autoload-load-name: "semantic/ctxt"
700 ;; End:
701
702 ;;; semantic/ctxt.el ends here