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