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