1 ;;; cc-langs.el --- language specific settings for CC Mode
3 ;; Copyright (C) 1985, 1987, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
4 ;; 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007
5 ;; Free Software Foundation, Inc.
7 ;; Authors: 2002- Alan Mackenzie
8 ;; 1998- Martin Stjernholm
9 ;; 1992-1999 Barry A. Warsaw
10 ;; 1987 Dave Detlefs and Stewart Clamen
11 ;; 1985 Richard M. Stallman
12 ;; Maintainer: bug-cc-mode@gnu.org
13 ;; Created: 22-Apr-1997 (split from cc-mode.el)
14 ;; Version: See cc-mode.el
15 ;; Keywords: c languages oop
17 ;; This file is part of GNU Emacs.
19 ;; GNU Emacs is free software; you can redistribute it and/or modify
20 ;; it under the terms of the GNU General Public License as published by
21 ;; the Free Software Foundation; either version 3, or (at your option)
24 ;; GNU Emacs is distributed in the hope that it will be useful,
25 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
26 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27 ;; GNU General Public License for more details.
29 ;; You should have received a copy of the GNU General Public License
30 ;; along with this program; see the file COPYING. If not, write to
31 ;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
32 ;; Boston, MA 02110-1301, USA.
36 ;; HACKERS NOTE: There's heavy macro magic here. If you need to make
37 ;; changes in this or other files containing `c-lang-defconst' but
38 ;; don't want to read through the longer discussion below then read
41 ;; o A change in a `c-lang-defconst' or `c-lang-defvar' will not take
42 ;; effect if the file containing the mode init function (typically
43 ;; cc-mode.el) is byte compiled.
44 ;; o To make changes show in font locking you need to reevaluate the
45 ;; `*-font-lock-keywords-*' constants, which normally is easiest to
46 ;; do with M-x eval-buffer in cc-fonts.el.
47 ;; o In either case it's necessary to reinitialize the mode to make
48 ;; the changes show in an existing buffer.
50 ;;; Introduction to the language dependent variable system:
52 ;; This file contains all the language dependent variables, except
53 ;; those specific for font locking which reside in cc-fonts.el. As
54 ;; far as possible, all the differences between the languages that CC
55 ;; Mode supports are described with these variables only, so that the
56 ;; code can be shared.
58 ;; The language constant system (see cc-defs.el) is used to specify
59 ;; various language dependent info at a high level, such as lists of
60 ;; keywords, and then from them generate - at compile time - the
61 ;; various regexps and other low-level structures actually employed in
62 ;; the code at runtime.
64 ;; This system is also designed to make it easy for developers of
65 ;; derived modes to customize the source constants for new language
66 ;; variants, without having to keep up with the exact regexps etc that
67 ;; are used in each CC Mode version. It's possible from an external
68 ;; package to add a new language by inheriting an existing one, and
69 ;; then change specific constants as necessary for the new language.
70 ;; The old values for those constants (and the values of all the other
71 ;; high-level constants) may be used to build the new ones, and those
72 ;; new values will in turn be used by the low-level definitions here
73 ;; to build the runtime constants appropriately for the new language
74 ;; in the current version of CC Mode.
76 ;; Like elsewhere in CC Mode, the existence of a doc string signifies
77 ;; that a language constant is part of the external API, and that it
78 ;; therefore can be used with a high confidence that it will continue
79 ;; to work with future versions of CC Mode. Even so, it's not
80 ;; unlikely that such constants will change meaning slightly as this
81 ;; system is refined further; a certain degree of dependence on the CC
82 ;; Mode version is unavoidable when hooking in at this level. Also
83 ;; note that there's still work to be done to actually use these
84 ;; constants everywhere inside CC Mode; there are still hardcoded
85 ;; values in many places in the code.
87 ;; Separate packages will also benefit from the compile time
88 ;; evaluation; the byte compiled file(s) for them will contain the
89 ;; compiled runtime constants ready for use by (the byte compiled) CC
90 ;; Mode, and the source definitions in this file don't have to be
91 ;; loaded then. However, if a byte compiled package is loaded that
92 ;; has been compiled with a different version of CC Mode than the one
93 ;; currently loaded, then the compiled-in values will be discarded and
94 ;; new ones will be built when the mode is initialized. That will
95 ;; automatically trig a load of the file(s) containing the source
96 ;; definitions (i.e. this file and/or cc-fonts.el) if necessary.
98 ;; A small example of a derived mode is available at
99 ;; <http://cc-mode.sourceforge.net/derived-mode-ex.el>. It also
100 ;; contains some useful hints for derived mode developers.
102 ;;; Using language variables:
104 ;; The `c-lang-defvar' forms in this file comprise the language
105 ;; variables that CC Mode uses. It does not work to use
106 ;; `c-lang-defvar' anywhere else (which isn't much of a limitation
107 ;; since these variables sole purpose is to interface with the CC Mode
108 ;; core functions). The values in these `c-lang-defvar's are not
109 ;; evaluated right away but instead collected to a single large `setq'
110 ;; that can be inserted for a particular language with the
111 ;; `c-init-language-vars' macro.
113 ;; This file is only required at compile time, or when not running
114 ;; from byte compiled files, or when the source definitions for the
115 ;; language constants are requested.
121 (if (and (boundp 'byte-compile-dest-file
)
122 (stringp byte-compile-dest-file
))
123 (cons (file-name-directory byte-compile-dest-file
) load-path
)
125 (load "cc-bytecomp" nil t
)))
127 (cc-require 'cc-defs
)
128 (cc-require 'cc-vars
)
131 ;; This file is not always loaded. See note above.
132 (cc-external-require 'cl
)
135 ;;; Setup for the `c-lang-defvar' system.
138 ;; These are used to collect the init forms from the subsequent
139 ;; `c-lang-defvar' and `c-lang-setvar'. They are used to build the
140 ;; lambda in `c-make-init-lang-vars-fun' below, and to build `defvar's
141 ;; and `make-variable-buffer-local's in cc-engine and
142 ;; `make-local-variable's in `c-init-language-vars-for'.
143 (defvar c-lang-variable-inits nil
)
144 (defvar c-lang-variable-inits-tail nil
)
145 (setq c-lang-variable-inits
(list nil
)
146 c-lang-variable-inits-tail c-lang-variable-inits
)
147 (defvar c-emacs-variable-inits nil
)
148 (defvar c-emacs-variable-inits-tail nil
)
149 (setq c-emacs-variable-inits
(list nil
)
150 c-emacs-variable-inits-tail c-emacs-variable-inits
))
152 (defmacro c-lang-defvar
(var val
&optional doc
)
153 "Declares the buffer local variable VAR to get the value VAL. VAL is
154 evaluated and assigned at mode initialization. More precisely, VAL is
155 evaluated and bound to VAR when the result from the macro
156 `c-init-language-vars' is evaluated.
158 `c-lang-const' is typically used in VAL to get the right value for the
159 language being initialized, and such calls will be macro expanded to
160 the evaluated constant value at compile time."
163 (eq (car-safe val
) 'c-lang-const
)
166 ;; Special case: If there's no docstring and the value is a
167 ;; simple (c-lang-const foo) where foo is the same name as VAR
168 ;; then take the docstring from the language constant foo.
169 (setq doc
(get (intern (symbol-name (nth 1 val
)) c-lang-constants
)
170 'variable-documentation
)))
174 (let ((elem (assq var
(cdr c-lang-variable-inits
))))
176 (setcdr elem
(list val doc
))
177 (setcdr c-lang-variable-inits-tail
(list (list var val doc
)))
178 (setq c-lang-variable-inits-tail
(cdr c-lang-variable-inits-tail
))))
180 ;; Return the symbol, like the other def* forms.
183 (defmacro c-lang-setvar
(var val
)
184 "Causes the variable VAR to be made buffer local and to get set to the
185 value VAL. VAL is evaluated and assigned at mode initialization. More
186 precisely, VAL is evaluated and bound to VAR when the result from the
187 macro `c-init-language-vars' is evaluated. VAR is typically a standard
188 Emacs variable like `comment-start'.
190 `c-lang-const' is typically used in VAL to get the right value for the
191 language being initialized, and such calls will be macro expanded to
192 the evaluated constant value at compile time."
193 (let ((elem (assq var
(cdr c-emacs-variable-inits
))))
195 (setcdr elem
(list val
)) ; Maybe remove "list", sometime. 2006-07-19
196 (setcdr c-emacs-variable-inits-tail
(list (list var val
)))
197 (setq c-emacs-variable-inits-tail
(cdr c-emacs-variable-inits-tail
))))
199 ;; Return the symbol, like the other def* forms.
202 (put 'c-lang-defvar
'lisp-indent-function
'defun
)
203 ; (eval-after-load "edebug" ; 2006-07-09: def-edebug-spec is now in subr.el.
205 (def-edebug-spec c-lang-defvar
206 (&define name def-form
&optional stringp
)) ;)
209 ;; Some helper functions used when building the language constants.
211 (defun c-filter-ops (ops opgroup-filter op-filter
&optional xlate
)
212 ;; Extract a subset of the operators in the list OPS in a DWIM:ey
213 ;; way. The return value is a plain list of operators:
215 ;; OPS either has the structure of `c-operators', is a single
216 ;; group in `c-operators', or is a plain list of operators.
218 ;; OPGROUP-FILTER specifies how to select the operator groups. It
219 ;; can be t to choose all groups, a list of group type symbols
220 ;; (such as 'prefix) to accept, or a function which will be called
221 ;; with the group symbol for each group and should return non-nil
222 ;; if that group is to be included.
224 ;; If XLATE is given, it's a function which is called for each
225 ;; matching operator and its return value is collected instead.
226 ;; If it returns a list, the elements are spliced directly into
227 ;; the final result, which is returned as a list with duplicates
228 ;; removed using `equal'.
230 ;; `c-mode-syntax-table' for the current mode is in effect during
231 ;; the whole procedure.
232 (unless (listp (car-safe ops
))
233 (setq ops
(list ops
)))
234 (cond ((eq opgroup-filter t
)
235 (setq opgroup-filter
(lambda (opgroup) t
)))
236 ((not (functionp opgroup-filter
))
237 (setq opgroup-filter
`(lambda (opgroup)
238 (memq opgroup
',opgroup-filter
)))))
239 (cond ((eq op-filter t
)
240 (setq op-filter
(lambda (op) t
)))
242 (setq op-filter
`(lambda (op)
243 (string-match ,op-filter op
)))))
245 (setq xlate
'identity
))
246 (c-with-syntax-table (c-lang-const c-mode-syntax-table
)
248 (mapcan (lambda (opgroup)
249 (when (if (symbolp (car opgroup
))
250 (when (funcall opgroup-filter
(car opgroup
))
251 (setq opgroup
(cdr opgroup
))
255 (when (funcall op-filter op
)
256 (let ((res (funcall xlate op
)))
257 (if (listp res
) res
(list res
)))))
263 ;;; Various mode specific values that aren't language related.
265 (c-lang-defconst c-mode-menu
266 ;; The definition for the mode menu. The menu title is prepended to
267 ;; this before it's fed to `easy-menu-define'.
268 t
`(["Comment Out Region" comment-region
269 (c-fn-region-is-active-p)]
270 ["Uncomment Region" (comment-region (region-beginning)
272 (c-fn-region-is-active-p)]
273 ["Indent Expression" c-indent-exp
274 (memq (char-after) '(?\
( ?\
[ ?\
{))]
275 ["Indent Line or Region" c-indent-line-or-region t
]
276 ["Fill Comment Paragraph" c-fill-paragraph t
]
278 ["Backward Statement" c-beginning-of-statement t
]
279 ["Forward Statement" c-end-of-statement t
]
280 ,@(when (c-lang-const c-opt-cpp-prefix
)
281 ;; Only applicable if there's a cpp preprocessor.
282 `(["Up Conditional" c-up-conditional t
]
283 ["Backward Conditional" c-backward-conditional t
]
284 ["Forward Conditional" c-forward-conditional t
]
286 ["Macro Expand Region" c-macro-expand
287 (c-fn-region-is-active-p)]
288 ["Backslashify" c-backslash-region
289 (c-fn-region-is-active-p)]))
292 ["Syntactic indentation" c-toggle-syntactic-indentation
293 :style toggle
:selected c-syntactic-indentation
]
294 ["Electric mode" c-toggle-electric-state
295 :style toggle
:selected c-electric-flag
]
296 ["Auto newline" c-toggle-auto-newline
297 :style toggle
:selected c-auto-newline
]
298 ["Hungry delete" c-toggle-hungry-state
299 :style toggle
:selected c-hungry-delete-key
]
300 ["Subword mode" c-subword-mode
301 :style toggle
:selected
(and (boundp 'c-subword-mode
)
307 (defun c-populate-syntax-table (table)
308 "Populate the given syntax table as necessary for a C-like language.
309 This includes setting ' and \" as string delimiters, and setting up
310 the comment syntax to handle both line style \"//\" and block style
311 \"/*\" \"*/\" comments."
313 (modify-syntax-entry ?_
"_" table
)
314 (modify-syntax-entry ?
\\ "\\" table
)
315 (modify-syntax-entry ?
+ "." table
)
316 (modify-syntax-entry ?-
"." table
)
317 (modify-syntax-entry ?
= "." table
)
318 (modify-syntax-entry ?%
"." table
)
319 (modify-syntax-entry ?
< "." table
)
320 (modify-syntax-entry ?
> "." table
)
321 (modify-syntax-entry ?
& "." table
)
322 (modify-syntax-entry ?|
"." table
)
323 (modify-syntax-entry ?
\' "\"" table
)
324 (modify-syntax-entry ?
\240 "." table
)
326 ;; Set up block and line oriented comments. The new C
327 ;; standard mandates both comment styles even in C, so since
328 ;; all languages now require dual comments, we make this the
332 ((memq '8-bit c-emacs-features
)
333 (modify-syntax-entry ?
/ ". 1456" table
)
334 (modify-syntax-entry ?
* ". 23" table
))
336 ((memq '1-bit c-emacs-features
)
337 (modify-syntax-entry ?
/ ". 124b" table
)
338 (modify-syntax-entry ?
* ". 23" table
))
340 (t (error "CC Mode is incompatible with this version of Emacs")))
342 (modify-syntax-entry ?
\n "> b" table
)
343 ;; Give CR the same syntax as newline, for selective-display
344 (modify-syntax-entry ?\^m
"> b" table
))
346 (c-lang-defconst c-make-mode-syntax-table
347 "Functions that generates the mode specific syntax tables.
348 The syntax tables aren't stored directly since they're quite large."
350 (let ((table (make-syntax-table)))
351 (c-populate-syntax-table table
)
352 ;; Mode specific syntaxes.
353 ,(cond ((c-major-mode-is 'objc-mode
)
354 ;; Let '@' be part of symbols in ObjC to cope with
355 ;; its compiler directives as single keyword tokens.
356 ;; This is then necessary since it's assumed that
357 ;; every keyword is a single symbol.
358 `(modify-syntax-entry ?
@ "_" table
))
359 ((c-major-mode-is 'pike-mode
)
360 `(modify-syntax-entry ?
@ "." table
)))
363 (c-lang-defconst c-mode-syntax-table
364 ;; The syntax tables in evaluated form. Only used temporarily when
365 ;; the constants in this file are evaluated.
366 t
(funcall (c-lang-const c-make-mode-syntax-table
)))
368 (c-lang-defconst c
++-make-template-syntax-table
369 ;; A variant of `c++-mode-syntax-table' that defines `<' and `>' as
370 ;; parenthesis characters. Used temporarily when template argument
371 ;; lists are parsed. Note that this encourages incorrect parsing of
372 ;; templates since they might contain normal operators that uses the
373 ;; '<' and '>' characters. Therefore this syntax table might go
374 ;; away when CC Mode handles templates correctly everywhere.
377 (let ((table (funcall ,(c-lang-const c-make-mode-syntax-table
))))
378 (modify-syntax-entry ?
< "(>" table
)
379 (modify-syntax-entry ?
> ")<" table
)
381 (c-lang-defvar c
++-template-syntax-table
382 (and (c-lang-const c
++-make-template-syntax-table
)
383 (funcall (c-lang-const c
++-make-template-syntax-table
))))
385 (c-lang-defconst c-identifier-syntax-modifications
386 "A list that describes the modifications that should be done to the
387 mode syntax table to get a syntax table that matches all identifiers
388 and keywords as words.
390 The list is just like the one used in `font-lock-defaults': Each
391 element is a cons where the car is the character to modify and the cdr
392 the new syntax, as accepted by `modify-syntax-entry'."
393 ;; The $ character is not allowed in most languages (one exception
394 ;; is Java which allows it for legacy reasons) but we still classify
395 ;; it as an indentifier character since it's often used in various
396 ;; machine generated identifiers.
397 t
'((?_ .
"w") (?$ .
"w"))
398 objc
(append '((?
@ .
"w"))
399 (c-lang-const c-identifier-syntax-modifications
))
401 (c-lang-defvar c-identifier-syntax-modifications
402 (c-lang-const c-identifier-syntax-modifications
))
404 (c-lang-defvar c-identifier-syntax-table
405 (let ((table (copy-syntax-table (c-mode-var "mode-syntax-table")))
406 (mods c-identifier-syntax-modifications
)
411 (modify-syntax-entry (car mod
) (cdr mod
) table
))
413 "Syntax table built on the mode syntax table but additionally
414 classifies symbol constituents like '_' and '$' as word constituents,
415 so that all identifiers are recognized as words.")
418 ;;; Lexer-level syntax (identifiers, tokens etc).
420 (c-lang-defconst c-symbol-start
421 "Regexp that matches the start of a symbol, i.e. any identifier or
422 keyword. It's unspecified how far it matches. Does not contain a \\|
423 operator at the top level."
424 t
(concat "[" c-alpha
"_]")
425 objc
(concat "[" c-alpha
"@]")
426 pike
(concat "[" c-alpha
"_`]"))
427 (c-lang-defvar c-symbol-start
(c-lang-const c-symbol-start
))
429 (c-lang-defconst c-symbol-chars
430 "Set of characters that can be part of a symbol.
431 This is on the form that fits inside [ ] in a regexp."
432 ;; Pike note: With the backquote identifiers this would include most
433 ;; operator chars too, but they are handled with other means instead.
434 t
(concat c-alnum
"_$")
435 objc
(concat c-alnum
"_$@"))
437 (c-lang-defconst c-symbol-key
438 "Regexp matching identifiers and keywords (with submatch 0). Assumed
439 to match if `c-symbol-start' matches on the same position."
440 t
(concat (c-lang-const c-symbol-start
)
441 "[" (c-lang-const c-symbol-chars
) "]*")
443 ;; Use the value from C here since the operator backquote is
444 ;; covered by the other alternative.
445 (c-lang-const c-symbol-key c
)
447 (c-make-keywords-re nil
448 (c-lang-const c-overloadable-operators
))))
449 (c-lang-defvar c-symbol-key
(c-lang-const c-symbol-key
))
451 (c-lang-defconst c-symbol-key-depth
452 ;; Number of regexp grouping parens in `c-symbol-key'.
453 t
(regexp-opt-depth (c-lang-const c-symbol-key
)))
455 (c-lang-defconst c-nonsymbol-chars
456 "This is the set of chars that can't be part of a symbol, i.e. the
457 negation of `c-symbol-chars'."
458 t
(concat "^" (c-lang-const c-symbol-chars
)))
459 (c-lang-defvar c-nonsymbol-chars
(c-lang-const c-nonsymbol-chars
))
461 (c-lang-defconst c-nonsymbol-key
462 "Regexp that matches any character that can't be part of a symbol.
463 It's usually appended to other regexps to avoid matching a prefix.
464 It's assumed to not contain any submatchers."
465 ;; The same thing regarding Unicode identifiers applies here as to
467 t
(concat "[" (c-lang-const c-nonsymbol-chars
) "]"))
469 (c-lang-defconst c-identifier-ops
470 "The operators that make up fully qualified identifiers. nil in
471 languages that don't have such things. See `c-operators' for a
472 description of the format. Binary operators can concatenate symbols,
473 e.g. \"::\" in \"A::B::C\". Prefix operators can precede identifiers,
474 e.g. \"~\" in \"~A::B\". Other types of operators aren't supported.
476 This value is by default merged into `c-operators'."
478 c
++ '((prefix "~" "??-" "compl")
481 ;; Java has "." to concatenate identifiers but it's also used for
482 ;; normal indexing. There's special code in the Java font lock
483 ;; rules to fontify qualified identifiers based on the standard
484 ;; naming conventions. We still define "." here to make
485 ;; `c-forward-name' move over as long names as possible which is
486 ;; necessary to e.g. handle throws clauses correctly.
487 java
'((left-assoc "."))
488 idl
'((left-assoc "::")
490 pike
'((left-assoc "::")
494 (c-lang-defconst c-opt-identifier-concat-key
495 ;; Appendable adorned regexp matching the operators that join
496 ;; symbols to fully qualified identifiers, or nil in languages that
497 ;; don't have such things.
499 ;; This was a docstring constant in 5.30. It still works but is now
500 ;; considered internal - change `c-identifier-ops' instead.
501 t
(let ((ops (c-filter-ops (c-lang-const c-identifier-ops
)
502 '(left-assoc right-assoc
)
505 (c-make-keywords-re 'appendable ops
))))
506 (c-lang-defvar c-opt-identifier-concat-key
507 (c-lang-const c-opt-identifier-concat-key
)
510 (c-lang-defconst c-opt-identifier-concat-key-depth
511 ;; Number of regexp grouping parens in `c-opt-identifier-concat-key'.
512 t
(regexp-opt-depth (c-lang-const c-opt-identifier-concat-key
)))
514 (c-lang-defconst c-opt-identifier-prefix-key
515 ;; Appendable adorned regexp matching operators that might precede
516 ;; an identifier and that are part of the identifier in that case.
517 ;; nil in languages without such things.
518 t
(let ((ops (c-filter-ops (c-lang-const c-identifier-ops
)
522 (c-make-keywords-re 'appendable ops
))))
524 (c-lang-defconst c-after-id-concat-ops
525 "Operators that can occur after a binary operator on `c-identifier-ops'
526 in identifiers. nil in languages that don't have such things.
528 Operators here should also have appropriate entries in `c-operators' -
529 it's not taken care of by default."
531 ;; '~' for destructors in C++, '*' for member pointers.
533 ;; In Java we recognize '*' to deal with "foo.bar.*" that can occur
534 ;; in import declarations. (This will also match bogus things like
535 ;; "foo.*bar" but we don't bother.)
538 (c-lang-defconst c-opt-after-id-concat-key
539 ;; Regexp that must match the token after
540 ;; `c-opt-identifier-concat-key' for it to be considered an
541 ;; identifier concatenation operator (which e.g. causes the
542 ;; preceding identifier to be fontified as a reference). Assumed to
543 ;; be a string if `c-opt-identifier-concat-key' is.
545 ;; This was a docstring constant in 5.30. It still works but is now
546 ;; considered internal - change `c-after-id-concat-ops' instead.
547 t
(concat (c-lang-const c-symbol-start
)
548 (if (c-lang-const c-after-id-concat-ops
)
549 (concat "\\|" (c-make-keywords-re 'appendable
550 (c-lang-const c-after-id-concat-ops
)))
553 (c-lang-defconst c-identifier-start
554 "Regexp that matches the start of an (optionally qualified) identifier.
555 It should also match all keywords. It's unspecified how far it
557 t
(concat (c-lang-const c-symbol-start
)
558 (if (c-lang-const c-opt-identifier-prefix-key
)
560 (c-lang-const c-opt-identifier-prefix-key
))
562 (c-lang-defvar c-identifier-start
(c-lang-const c-identifier-start
))
564 (c-lang-defconst c-identifier-key
565 "Regexp matching a fully qualified identifier, like \"A::B::c\" in
566 C++. It does not recognize the full range of syntactic whitespace
567 between the tokens; `c-forward-name' has to be used for that. It
568 should also not match identifiers containing parenthesis groupings,
569 e.g. identifiers with template arguments such as \"A<X,Y>\" in C++."
570 ;; This regexp is more complex than strictly necessary to ensure
571 ;; that it can be matched with a minimum of backtracking.
572 t
(concat (if (c-lang-const c-opt-identifier-prefix-key
)
575 (c-lang-const c-opt-identifier-prefix-key
)
576 (c-lang-const c-simple-ws
) "*"
579 "\\(" (c-lang-const c-symbol-key
) "\\)"
580 (if (c-lang-const c-opt-identifier-concat-key
)
583 (c-lang-const c-simple-ws
) "*"
584 (c-lang-const c-opt-identifier-concat-key
)
585 (c-lang-const c-simple-ws
) "*"
586 (if (c-lang-const c-after-id-concat-ops
)
589 (c-make-keywords-re 'appendable
590 (c-lang-const c-after-id-concat-ops
))
592 ;; For flexibility, consider the symbol match
593 ;; optional if we've hit a
594 ;; `c-after-id-concat-ops' operator. This is
595 ;; also necessary to handle the "*" that can
596 ;; end import declaration identifiers in Java.
598 (c-lang-const c-simple-ws
) "*"
599 "\\(" (c-lang-const c-symbol-key
) "\\)"
602 "\\(" (c-lang-const c-symbol-key
) "\\)"
604 (concat "\\(" (c-lang-const c-symbol-key
) "\\)"))
607 (c-lang-defvar c-identifier-key
(c-lang-const c-identifier-key
))
609 (c-lang-defconst c-identifier-last-sym-match
610 ;; This was a docstring constant in 5.30 but it's no longer used.
611 ;; It's only kept to avoid breaking third party code.
613 ;; Used to identify the submatch in `c-identifier-key' that
614 ;; surrounds the last symbol in the qualified identifier. It's a
615 ;; list of submatch numbers, of which the first that has a match is
616 ;; taken. It's assumed that at least one does when the regexp has
620 (c-lang-defconst c-string-escaped-newlines
621 "Set if the language support backslash escaped newlines inside string
625 (c-lang-defvar c-string-escaped-newlines
626 (c-lang-const c-string-escaped-newlines
))
628 (c-lang-defconst c-multiline-string-start-char
629 "Set if the language supports multiline string literals without escaped
630 newlines. If t, all string literals are multiline. If a character,
631 only literals where the open quote is immediately preceded by that
632 literal are multiline."
635 (c-lang-defvar c-multiline-string-start-char
636 (c-lang-const c-multiline-string-start-char
))
638 (c-lang-defconst c-opt-cpp-prefix
639 "Regexp matching the prefix of a cpp directive in the languages that
640 normally use that macro preprocessor. Tested at bol or at boi.
641 Assumed to not contain any submatches or \\| operators."
642 ;; TODO (ACM, 2005-04-01). Amend the following to recognise escaped NLs;
643 ;; amend all uses of c-opt-cpp-prefix which count regexp-depth.
646 (c-lang-defvar c-opt-cpp-prefix
(c-lang-const c-opt-cpp-prefix
))
648 (c-lang-defconst c-opt-cpp-start
649 "Regexp matching the prefix of a cpp directive including the directive
650 name, or nil in languages without preprocessor support. The first
651 submatch surrounds the directive name."
652 t
(if (c-lang-const c-opt-cpp-prefix
)
653 (concat (c-lang-const c-opt-cpp-prefix
)
654 "\\([" c-alnum
"]+\\)"))
655 ;; Pike, being a scripting language, recognizes hash-bangs too.
656 pike
(concat (c-lang-const c-opt-cpp-prefix
)
657 "\\([" c-alnum
"]+\\|!\\)"))
658 (c-lang-defvar c-opt-cpp-start
(c-lang-const c-opt-cpp-start
))
660 (c-lang-defconst c-cpp-message-directives
661 "List of cpp directives (without the prefix) that are followed by a
663 t
(if (c-lang-const c-opt-cpp-prefix
)
665 pike
'("error" "warning"))
667 (c-lang-defconst c-cpp-include-directives
668 "List of cpp directives (without the prefix) that are followed by a
669 file name in angle brackets or quotes."
670 t
(if (c-lang-const c-opt-cpp-prefix
)
672 objc
'("include" "import"))
674 (c-lang-defconst c-opt-cpp-macro-define
675 "Cpp directive (without the prefix) that is followed by a macro
676 definition, or nil if the language doesn't have any."
677 t
(if (c-lang-const c-opt-cpp-prefix
)
680 (c-lang-defconst c-opt-cpp-macro-define-start
681 ;; Regexp matching everything up to the macro body of a cpp define,
682 ;; or the end of the logical line if there is none. Set if
683 ;; c-opt-cpp-macro-define is.
684 t
(if (c-lang-const c-opt-cpp-macro-define
)
685 (concat (c-lang-const c-opt-cpp-prefix
)
686 (c-lang-const c-opt-cpp-macro-define
)
687 "[ \t]+\\(\\sw\\|_\\)+\\(\([^\)]*\)\\)?"
688 "\\([ \t]\\|\\\\\n\\)*")))
689 (c-lang-defvar c-opt-cpp-macro-define-start
690 (c-lang-const c-opt-cpp-macro-define-start
))
692 (c-lang-defconst c-opt-cpp-macro-define-id
693 ;; Regexp matching everything up to the end of the identifier defined
695 t
(if (c-lang-const c-opt-cpp-macro-define
)
696 (concat (c-lang-const c-opt-cpp-prefix
) ; #
697 (c-lang-const c-opt-cpp-macro-define
) ; define
698 "[ \t]+\\(\\sw\\|_\\)+")))
699 (c-lang-defvar c-opt-cpp-macro-define-id
700 (c-lang-const c-opt-cpp-macro-define-id
))
702 (c-lang-defconst c-cpp-expr-directives
703 "List if cpp directives (without the prefix) that are followed by an
705 t
(if (c-lang-const c-opt-cpp-prefix
)
708 (c-lang-defconst c-cpp-expr-functions
709 "List of functions in cpp expressions."
710 t
(if (c-lang-const c-opt-cpp-prefix
)
712 pike
'("defined" "efun" "constant"))
714 (c-lang-defconst c-assignment-operators
715 "List of all assignment operators."
716 t
'("=" "*=" "/=" "%=" "+=" "-=" ">>=" "<<=" "&=" "^=" "|=")
717 java
(append (c-lang-const c-assignment-operators
)
719 c
++ (append (c-lang-const c-assignment-operators
)
720 '("and_eq" "or_eq" "xor_eq" "??!=" "??'="))
723 (c-lang-defconst c-operators
724 "List describing all operators, along with their precedence and
725 associativity. The order in the list corresponds to the precedence of
726 the operators: The operators in each element are a group with the same
727 precedence, and the group has higher precedence than the groups in all
728 following elements. The car of each element describes the type of the
729 operator group, and the cdr is a list of the operator tokens in it.
730 The operator group types are:
732 'prefix Unary prefix operators.
733 'postfix Unary postfix operators.
735 Unary postfix operators if and only if the chars have
737 'left-assoc Binary left associative operators (i.e. a+b+c means (a+b)+c).
738 'right-assoc Binary right associative operators (i.e. a=b=c means a=(b=c)).
739 'right-assoc-sequence
740 Right associative operator that constitutes of a
741 sequence of tokens that separate expressions. All the
742 tokens in the group are in this case taken as
743 describing the sequence in one such operator, and the
744 order between them is therefore significant.
746 Operators containing a character with paren syntax are taken to match
747 with a corresponding open/close paren somewhere else. A postfix
748 operator with close paren syntax is taken to end a postfix expression
749 started somewhere earlier, rather than start a new one at point. Vice
750 versa for prefix operators with open paren syntax.
752 Note that operators like \".\" and \"->\" which in language references
753 often are described as postfix operators are considered binary here,
754 since CC Mode treats every identifier as an expression."
756 ;; There's currently no code in CC Mode that exploit all the info
757 ;; in this variable; precedence, associativity etc are present as a
758 ;; preparation for future work.
761 ,@(when (c-lang-const c-opt-cpp-prefix
)
763 ,@(when (c-major-mode-is '(c-mode c
++-mode
))
766 ,@(when (c-major-mode-is '(c-mode c
++-mode
))
767 '("%:%:" "??=??=")))))
770 ,@(c-lang-const c-identifier-ops
)
771 ,@(cond ((c-major-mode-is 'c
++-mode
)
772 `((postfix-if-paren "<" ">"))) ; Templates.
773 ((c-major-mode-is 'pike-mode
)
774 `((prefix "global" "predef")))
775 ((c-major-mode-is 'java-mode
)
776 `((prefix "super"))))
779 ,@(when (c-major-mode-is 'c
++-mode
)
780 ;; The following need special treatment.
781 `((prefix "dynamic_cast" "static_cast"
782 "reinterpret_cast" "const_cast" "typeid")))
784 ,@(unless (c-major-mode-is 'java-mode
)
786 (postfix "++" "--" "[" "]" "(" ")"
787 ,@(when (c-major-mode-is '(c-mode c
++-mode
))
788 '("<:" ":>" "??(" "??)")))
791 (prefix "++" "--" "+" "-" "!" "~"
792 ,@(when (c-major-mode-is 'c
++-mode
) '("not" "compl"))
793 ,@(when (c-major-mode-is '(c-mode c
++-mode
))
794 '("*" "&" "sizeof" "??-"))
795 ,@(when (c-major-mode-is 'objc-mode
)
796 '("@selector" "@protocol" "@encode"))
797 ;; The following need special treatment.
798 ,@(cond ((c-major-mode-is 'c
++-mode
)
800 ((c-major-mode-is 'java-mode
)
802 ((c-major-mode-is 'pike-mode
)
803 '("class" "lambda" "catch" "throw" "gauge")))
805 ,@(when (c-major-mode-is 'pike-mode
)
806 '("[" "]"))) ; Type cast.
809 ,@(when (c-major-mode-is 'c
++-mode
)
810 `((left-assoc ".*" "->*")))
813 (left-assoc "*" "/" "%")
819 (left-assoc "<<" ">>"
820 ,@(when (c-major-mode-is 'java-mode
)
824 (left-assoc "<" ">" "<=" ">="
825 ,@(when (c-major-mode-is 'java-mode
)
829 (left-assoc "==" "!="
830 ,@(when (c-major-mode-is 'c
++-mode
) '("not_eq")))
834 ,@(when (c-major-mode-is 'c
++-mode
) '("bitand")))
836 ;; Bitwise exclusive or.
838 ,@(when (c-major-mode-is '(c-mode c
++-mode
))
840 ,@(when (c-major-mode-is 'c
++-mode
) '("xor")))
844 ,@(when (c-major-mode-is '(c-mode c
++-mode
))
846 ,@(when (c-major-mode-is 'c
++-mode
) '("bitor")))
850 ,@(when (c-major-mode-is 'c
++-mode
) '("and")))
854 ,@(when (c-major-mode-is '(c-mode c
++-mode
))
856 ,@(when (c-major-mode-is 'c
++-mode
) '("or")))
859 (right-assoc-sequence "?" ":")
862 (right-assoc ,@(c-lang-const c-assignment-operators
))
865 ,@(when (c-major-mode-is 'c
++-mode
)
871 ;; IDL got its own definition since it has a much smaller operator
872 ;; set than the other languages.
873 idl
`(;; Preprocessor.
877 ,@(c-lang-const c-identifier-ops
)
881 (left-assoc "*" "/" "%")
885 (left-assoc "<<" ">>")
893 (c-lang-defconst c-operator-list
894 ;; The operators as a flat list (without duplicates).
895 t
(c-filter-ops (c-lang-const c-operators
) t t
))
897 (c-lang-defconst c-overloadable-operators
898 "List of the operators that are overloadable, in their \"identifier
899 form\". See also `c-op-identifier-prefix'."
901 c
++ '("new" "delete" ;; Can be followed by "[]" but we ignore that.
903 "^" "??'" "xor" "&" "bitand" "|" "??!" "bitor" "~" "??-" "compl"
904 "!" "=" "<" ">" "+=" "-=" "*=" "/=" "%=" "^="
905 "??'=" "xor_eq" "&=" "and_eq" "|=" "??!=" "or_eq"
906 "<<" ">>" ">>=" "<<=" "==" "!=" "not_eq" "<=" ">="
907 "&&" "and" "||" "??!??!" "or" "++" "--" "," "->*" "->"
908 "()" "[]" "<::>" "??(??)")
909 ;; These work like identifiers in Pike.
910 pike
'("`+" "`-" "`&" "`|" "`^" "`<<" "`>>" "`*" "`/" "`%" "`~"
911 "`==" "`<" "`>" "`!" "`[]" "`[]=" "`->" "`->=" "`()" "``+"
912 "``-" "``&" "``|" "``^" "``<<" "``>>" "``*" "``/" "``%"
915 (c-lang-defconst c-overloadable-operators-regexp
916 ;; Regexp tested after an "operator" token in C++.
918 c
++ (c-make-keywords-re nil
(c-lang-const c-overloadable-operators
)))
919 (c-lang-defvar c-overloadable-operators-regexp
920 (c-lang-const c-overloadable-operators-regexp
))
922 (c-lang-defconst c-opt-op-identifier-prefix
923 "Regexp matching the token before the ones in
924 `c-overloadable-operators' when operators are specified in their
925 \"identifier form\". This typically matches \"operator\" in C++ where
926 operator functions are specified as e.g. \"operator +\". It's nil in
927 languages without operator functions or where the complete operator
928 identifier is listed in `c-overloadable-operators'.
930 This regexp is assumed to not match any non-operator identifier."
932 c
++ (c-make-keywords-re t
'("operator")))
933 (c-lang-defvar c-opt-op-identifier-prefix
934 (c-lang-const c-opt-op-identifier-prefix
))
936 ;; Note: the following alias is an old name which was a mis-spelling. It has
937 ;; been corrected above and throughout cc-engine.el. It will be removed at
938 ;; some release very shortly in the future. ACM, 2006-04-14.
939 (defalias 'c-opt-op-identitier-prefix
'c-opt-op-identifier-prefix
)
940 (make-obsolete-variable 'c-opt-op-identitier-prefix
'c-opt-op-identifier-prefix
941 "CC Mode 5.31.4, 2006-04-14")
943 (c-lang-defconst c-other-op-syntax-tokens
944 "List of the tokens made up of characters in the punctuation or
945 parenthesis syntax classes that have uses other than as expression
947 t
'("{" "}" "(" ")" "[" "]" ";" ":" "," "=" "/*" "*/" "//")
948 (c c
++ pike
) (append '("#" "##" ; Used by cpp.
950 (c-lang-const c-other-op-syntax-tokens
))
951 (c c
++) (append '("*") (c-lang-const c-other-op-syntax-tokens
))
952 c
++ (append '("&" "<%" "%>" "<:" ":>" "%:" "%:%:")
953 (c-lang-const c-other-op-syntax-tokens
))
954 objc
(append '("#" "##" ; Used by cpp.
955 "+" "-") (c-lang-const c-other-op-syntax-tokens
))
956 idl
(append '("#" "##") ; Used by cpp.
957 (c-lang-const c-other-op-syntax-tokens
))
959 (c-lang-const c-other-op-syntax-tokens
)
960 (c-lang-const c-overloadable-operators
))
961 awk
'("{" "}" "(" ")" "[" "]" ";" "," "=" "/"))
963 (c-lang-defconst c-all-op-syntax-tokens
964 ;; List of all tokens in the punctuation and parenthesis syntax
966 t
(delete-duplicates (append (c-lang-const c-other-op-syntax-tokens
)
967 (c-lang-const c-operator-list
))
968 :test
'string-equal
))
970 (c-lang-defconst c-nonsymbol-token-char-list
971 ;; List containing all chars not in the word, symbol or
972 ;; syntactically irrelevant syntax classes, i.e. all punctuation,
973 ;; parenthesis and string delimiter chars.
974 t
(c-with-syntax-table (c-lang-const c-mode-syntax-table
)
975 ;; Only go through the chars in the printable ASCII range. No
976 ;; language so far has 8-bit or widestring operators.
977 (let (list (char 32))
979 (or (memq (char-syntax char
) '(?w ?_ ?
< ?
> ?\
))
980 (setq list
(cons (c-int-to-char char
) list
)))
981 (setq char
(1+ char
)))
984 (c-lang-defconst c-nonsymbol-token-regexp
985 ;; Regexp matching all tokens in the punctuation and parenthesis
986 ;; syntax classes. Note that this also matches ".", which can start
988 t
(c-make-keywords-re nil
989 (c-filter-ops (c-lang-const c-all-op-syntax-tokens
)
991 "\\`\\(\\s.\\|\\s\(\\|\\s\)\\)+\\'")))
992 (c-lang-defvar c-nonsymbol-token-regexp
993 (c-lang-const c-nonsymbol-token-regexp
))
995 (c-lang-defconst c-assignment-op-regexp
996 ;; Regexp matching all assignment operators and only them. The
997 ;; beginning of the first submatch is used to detect the end of the
998 ;; token, along with the end of the whole match.
999 t
(if (c-lang-const c-assignment-operators
)
1001 ;; Need special case for "=" since it's a prefix of "==".
1004 (c-make-keywords-re nil
1005 (set-difference (c-lang-const c-assignment-operators
)
1007 :test
'string-equal
)))
1009 (c-lang-defvar c-assignment-op-regexp
1010 (c-lang-const c-assignment-op-regexp
))
1012 (c-lang-defconst c-
<>-multichar-token-regexp
1013 ;; Regexp matching all tokens containing "<" or ">" which are longer
1015 t
(c-make-keywords-re nil
1016 (c-filter-ops (c-lang-const c-all-op-syntax-tokens
)
1019 (c-lang-defvar c-
<>-multichar-token-regexp
1020 (c-lang-const c-
<>-multichar-token-regexp
))
1022 (c-lang-defconst c-
<-op-cont-regexp
1023 ;; Regexp matching the second and subsequent characters of all
1024 ;; multicharacter tokens that begin with "<".
1025 t
(c-make-keywords-re nil
1026 (c-filter-ops (c-lang-const c-all-op-syntax-tokens
)
1029 (lambda (op) (substring op
1)))))
1030 (c-lang-defvar c-
<-op-cont-regexp
(c-lang-const c-
<-op-cont-regexp
))
1032 (c-lang-defconst c-
>-op-cont-regexp
1033 ;; Regexp matching the second and subsequent characters of all
1034 ;; multicharacter tokens that begin with ">".
1035 t
(c-make-keywords-re nil
1036 (c-filter-ops (c-lang-const c-all-op-syntax-tokens
)
1039 (lambda (op) (substring op
1)))))
1040 (c-lang-defvar c-
>-op-cont-regexp
(c-lang-const c-
>-op-cont-regexp
))
1042 (c-lang-defconst c-stmt-delim-chars
1043 ;; The characters that should be considered to bound statements. To
1044 ;; optimize `c-crosses-statement-barrier-p' somewhat, it's assumed to
1045 ;; begin with "^" to negate the set. If ? : operators should be
1046 ;; detected then the string must end with "?:".
1048 awk
"^;{}#\n\r?:") ; The newline chars gets special treatment.
1049 (c-lang-defvar c-stmt-delim-chars
(c-lang-const c-stmt-delim-chars
))
1051 (c-lang-defconst c-stmt-delim-chars-with-comma
1052 ;; Variant of `c-stmt-delim-chars' that additionally contains ','.
1054 awk
"^;,{}\n\r?:") ; The newline chars gets special treatment.
1055 (c-lang-defvar c-stmt-delim-chars-with-comma
1056 (c-lang-const c-stmt-delim-chars-with-comma
))
1059 ;;; Syntactic whitespace.
1061 (c-lang-defconst c-simple-ws
1062 "Regexp matching an ordinary whitespace character.
1063 Does not contain a \\| operator at the top level."
1064 ;; "\\s " is not enough since it doesn't match line breaks.
1065 t
"\\(\\s \\|[\n\r]\\)")
1067 (c-lang-defconst c-simple-ws-depth
1068 ;; Number of regexp grouping parens in `c-simple-ws'.
1069 t
(regexp-opt-depth (c-lang-const c-simple-ws
)))
1071 (c-lang-defconst c-line-comment-starter
1072 "String that starts line comments, or nil if such don't exist.
1073 Line comments are always terminated by newlines. At least one of
1074 `c-block-comment-starter' and this one is assumed to be set.
1076 Note that it's currently not enough to set this to support a new
1077 comment style. Other stuff like the syntax table must also be set up
1081 (c-lang-defvar c-line-comment-starter
(c-lang-const c-line-comment-starter
))
1083 (c-lang-defconst c-block-comment-starter
1084 "String that starts block comments, or nil if such don't exist.
1085 Block comments are ended by `c-block-comment-ender', which is assumed
1086 to be set if this is. At least one of `c-line-comment-starter' and
1087 this one is assumed to be set.
1089 Note that it's currently not enough to set this to support a new
1090 comment style. Other stuff like the syntax table must also be set up
1095 (c-lang-defconst c-block-comment-ender
1096 "String that ends block comments, or nil if such don't exist.
1098 Note that it's currently not enough to set this to support a new
1099 comment style. Other stuff like the syntax table must also be set up
1104 (c-lang-defconst c-comment-start-regexp
1105 ;; Regexp to match the start of any type of comment.
1106 t
(let ((re (c-make-keywords-re nil
1107 (list (c-lang-const c-line-comment-starter
)
1108 (c-lang-const c-block-comment-starter
)))))
1109 (if (memq 'gen-comment-delim c-emacs-features
)
1110 (concat re
"\\|\\s!")
1112 (c-lang-defvar c-comment-start-regexp
(c-lang-const c-comment-start-regexp
))
1114 ;;;; Added by ACM, 2003/9/18.
1115 (c-lang-defconst c-block-comment-start-regexp
1116 ;; Regexp which matches the start of a block comment (if such exists in the
1118 t
(if (c-lang-const c-block-comment-starter
)
1119 (regexp-quote (c-lang-const c-block-comment-starter
))
1121 (c-lang-defvar c-block-comment-start-regexp
1122 (c-lang-const c-block-comment-start-regexp
))
1124 (c-lang-defconst c-literal-start-regexp
1125 ;; Regexp to match the start of comments and string literals.
1126 t
(concat (c-lang-const c-comment-start-regexp
)
1128 (if (memq 'gen-string-delim c-emacs-features
)
1131 (c-lang-defvar c-literal-start-regexp
(c-lang-const c-literal-start-regexp
))
1133 (c-lang-defconst c-doc-comment-start-regexp
1134 "Regexp to match the start of documentation comments."
1136 ;; From font-lock.el: `doxygen' uses /*! while others use /**.
1137 (c c
++ objc
) "/\\*[*!]"
1140 (c-lang-defvar c-doc-comment-start-regexp
1141 (c-lang-const c-doc-comment-start-regexp
))
1143 (c-lang-defconst comment-start
1144 "String that starts comments inserted with M-; etc.
1145 `comment-start' is initialized from this."
1146 ;; Default: Prefer line comments to block comments, and pad with a space.
1147 t
(concat (or (c-lang-const c-line-comment-starter
)
1148 (c-lang-const c-block-comment-starter
))
1150 ;; In C we still default to the block comment style since line
1151 ;; comments aren't entirely portable.
1153 (c-lang-setvar comment-start
(c-lang-const comment-start
))
1155 (c-lang-defconst comment-end
1156 "String that ends comments inserted with M-; etc.
1157 `comment-end' is initialized from this."
1158 ;; Default: Use block comment style if comment-start uses block
1159 ;; comments, and pad with a space in that case.
1160 t
(if (string-match (concat "\\`\\("
1161 (c-lang-const c-block-comment-start-regexp
)
1163 (c-lang-const comment-start
))
1164 (concat " " (c-lang-const c-block-comment-ender
))
1166 (c-lang-setvar comment-end
(c-lang-const comment-end
))
1168 (c-lang-defconst comment-start-skip
1169 "Regexp to match the start of a comment plus everything up to its body.
1170 `comment-start-skip' is initialized from this."
1171 ;; Default: Allow the last char of the comment starter(s) to be
1172 ;; repeated, then allow any amount of horizontal whitespace.
1175 (mapcar (lambda (cs)
1177 (concat (regexp-quote cs
) "+")))
1178 (list (c-lang-const c-line-comment-starter
)
1179 (c-lang-const c-block-comment-starter
)))
1182 (c-lang-setvar comment-start-skip
(c-lang-const comment-start-skip
))
1184 (c-lang-defconst c-syntactic-ws-start
1185 ;; Regexp matching any sequence that can start syntactic whitespace.
1186 ;; The only uncertain case is '#' when there are cpp directives.
1188 (c-make-keywords-re nil
1189 (append (list (c-lang-const c-line-comment-starter
)
1190 (c-lang-const c-block-comment-starter
)
1191 (when (c-lang-const c-opt-cpp-prefix
)
1195 (when (memq 'gen-comment-delim c-emacs-features
)
1197 (c-lang-defvar c-syntactic-ws-start
(c-lang-const c-syntactic-ws-start
))
1199 (c-lang-defconst c-syntactic-ws-end
1200 ;; Regexp matching any single character that might end syntactic whitespace.
1202 (c-make-keywords-re nil
1203 (append (when (c-lang-const c-block-comment-ender
)
1206 (elt (c-lang-const c-block-comment-ender
)
1208 (c-lang-const c-block-comment-ender
)))))))
1210 (when (memq 'gen-comment-delim c-emacs-features
)
1212 (c-lang-defvar c-syntactic-ws-end
(c-lang-const c-syntactic-ws-end
))
1214 (c-lang-defconst c-unterminated-block-comment-regexp
1215 ;; Regexp matching an unterminated block comment that doesn't
1216 ;; contain line breaks, or nil in languages without block comments.
1217 ;; Does not contain a \| operator at the top level.
1218 t
(when (c-lang-const c-block-comment-starter
)
1220 (regexp-quote (c-lang-const c-block-comment-starter
))
1221 ;; It's messy to cook together a regexp that matches anything
1222 ;; but c-block-comment-ender.
1223 (let ((end (c-lang-const c-block-comment-ender
)))
1224 (cond ((= (length end
) 1)
1225 (concat "[^" end
"\n\r]*"))
1227 (concat "[^" (substring end
0 1) "\n\r]*"
1229 (regexp-quote (substring end
0 1)) "+"
1231 ;; The quoting rules inside char classes are silly. :P
1232 (cond ((= (elt end
0) (elt end
1))
1233 (concat (substring end
0 1) "\n\r"))
1234 ((= (elt end
1) ?\
])
1235 (concat (substring end
1 2) "\n\r"
1236 (substring end
0 1)))
1238 (concat (substring end
0 1) "\n\r"
1239 (substring end
1 2))))
1241 "[^" (substring end
0 1) "\n\r]*"
1244 (error "Can't handle a block comment ender of length %s"
1247 (c-lang-defconst c-block-comment-regexp
1248 ;; Regexp matching a block comment that doesn't contain line breaks,
1249 ;; or nil in languages without block comments. The reason we don't
1250 ;; allow line breaks is to avoid going very far and risk running out
1251 ;; of regexp stack; this regexp is intended to handle only short
1252 ;; comments that might be put in the middle of limited constructs
1253 ;; like declarations. Does not contain a \| operator at the top
1255 t
(when (c-lang-const c-unterminated-block-comment-regexp
)
1257 (c-lang-const c-unterminated-block-comment-regexp
)
1258 (let ((end (c-lang-const c-block-comment-ender
)))
1259 (cond ((= (length end
) 1)
1262 (concat (regexp-quote (substring end
0 1)) "+"
1263 (regexp-quote (substring end
1 2))))
1265 (error "Can't handle a block comment ender of length %s"
1268 (c-lang-defconst c-nonwhite-syntactic-ws
1269 ;; Regexp matching a piece of syntactic whitespace that isn't a
1270 ;; sequence of simple whitespace characters. As opposed to
1271 ;; `c-(forward|backward)-syntactic-ws', this doesn't regard cpp
1272 ;; directives as syntactic whitespace.
1273 t
(c-concat-separated
1274 (list (when (c-lang-const c-line-comment-starter
)
1275 (concat (regexp-quote (c-lang-const c-line-comment-starter
))
1277 (c-lang-const c-block-comment-regexp
)
1279 (when (memq 'gen-comment-delim c-emacs-features
)
1283 (c-lang-defconst c-syntactic-ws
1284 ;; Regexp matching syntactic whitespace, including possibly the
1285 ;; empty string. As opposed to `c-(forward|backward)-syntactic-ws',
1286 ;; this doesn't regard cpp directives as syntactic whitespace. Does
1287 ;; not contain a \| operator at the top level.
1288 t
(concat (c-lang-const c-simple-ws
) "*"
1290 (concat "\\(" (c-lang-const c-nonwhite-syntactic-ws
) "\\)"
1291 (c-lang-const c-simple-ws
) "*")
1294 (c-lang-defconst c-syntactic-ws-depth
1295 ;; Number of regexp grouping parens in `c-syntactic-ws'.
1296 t
(regexp-opt-depth (c-lang-const c-syntactic-ws
)))
1298 (c-lang-defconst c-nonempty-syntactic-ws
1299 ;; Regexp matching syntactic whitespace, which is at least one
1300 ;; character long. As opposed to `c-(forward|backward)-syntactic-ws',
1301 ;; this doesn't regard cpp directives as syntactic whitespace. Does
1302 ;; not contain a \| operator at the top level.
1304 (c-lang-const c-simple-ws
)
1306 (c-lang-const c-nonwhite-syntactic-ws
)
1309 (c-lang-defconst c-nonempty-syntactic-ws-depth
1310 ;; Number of regexp grouping parens in `c-nonempty-syntactic-ws'.
1311 t
(regexp-opt-depth (c-lang-const c-nonempty-syntactic-ws
)))
1313 (c-lang-defconst c-single-line-syntactic-ws
1314 ;; Regexp matching syntactic whitespace without any line breaks. As
1315 ;; opposed to `c-(forward|backward)-syntactic-ws', this doesn't
1316 ;; regard cpp directives as syntactic whitespace. Does not contain
1317 ;; a \| operator at the top level.
1318 t
(if (c-lang-const c-block-comment-regexp
)
1320 (c-lang-const c-block-comment-regexp
)
1324 (c-lang-defconst c-single-line-syntactic-ws-depth
1325 ;; Number of regexp grouping parens in `c-single-line-syntactic-ws'.
1326 t
(regexp-opt-depth (c-lang-const c-single-line-syntactic-ws
)))
1328 (c-lang-defconst c-syntactic-eol
1329 ;; Regexp that matches when there is no syntactically significant
1330 ;; text before eol. Macros are regarded as syntactically
1331 ;; significant text here.
1332 t
(concat (c-lang-const c-single-line-syntactic-ws
)
1333 ;; Match eol (possibly inside a block comment or preceded
1334 ;; by a line continuation backslash), or the beginning of a
1335 ;; line comment. Note: This has to be modified for awk
1336 ;; where line comments start with '#'.
1339 (list (when (c-lang-const c-line-comment-starter
)
1340 (regexp-quote (c-lang-const c-line-comment-starter
)))
1341 (when (c-lang-const c-unterminated-block-comment-regexp
)
1342 (concat (c-lang-const c-unterminated-block-comment-regexp
)
1348 (c-lang-defvar c-syntactic-eol
(c-lang-const c-syntactic-eol
))
1351 ;;; Syntactic analysis ("virtual semicolons") for line-oriented languages (AWK).
1352 (c-lang-defconst c-at-vsemi-p-fn
1353 "Contains a function \"Is there a virtual semicolon at POS or point?\".
1354 Such a function takes one optional parameter, a buffer position (defaults to
1355 point), and returns nil or t. This variable contains nil for languages which
1356 don't have EOL terminated statements. "
1358 awk
'c-awk-at-vsemi-p
)
1359 (c-lang-defvar c-at-vsemi-p-fn
(c-lang-const c-at-vsemi-p-fn
))
1361 (c-lang-defconst c-vsemi-status-unknown-p-fn
1362 "Contains a function \"are we unsure whether there is a virtual semicolon on this line?\".
1363 The (admittedly kludgey) purpose of such a function is to prevent an infinite
1364 recursion in c-beginning-of-statement-1 when point starts at a `while' token.
1365 The function MUST NOT UNDER ANY CIRCUMSTANCES call c-beginning-of-statement-1,
1366 even indirectly. This variable contains nil for languages which don't have
1367 EOL terminated statements."
1369 awk
'c-awk-vsemi-status-unknown-p
)
1370 (c-lang-defvar c-vsemi-status-unknown-p-fn
1371 (c-lang-const c-vsemi-status-unknown-p-fn
))
1376 ;; The Emacs variables beginning-of-defun-function and
1377 ;; end-of-defun-function will be set so that commands like
1378 ;; `mark-defun' and `narrow-to-defun' work right. The key sequences
1379 ;; C-M-a and C-M-e are, however, bound directly to the CC Mode
1380 ;; functions, allowing optimisation for large n.
1381 (c-lang-defconst beginning-of-defun-function
1382 "Function to which beginning-of-defun-function will be set."
1383 t
'c-beginning-of-defun
1384 awk
'c-awk-beginning-of-defun
)
1385 (c-lang-setvar beginning-of-defun-function
1386 (c-lang-const beginning-of-defun-function
))
1388 (c-lang-defconst end-of-defun-function
1389 "Function to which end-of-defun-function will be set."
1391 awk
'c-awk-end-of-defun
)
1392 (c-lang-setvar end-of-defun-function
(c-lang-const end-of-defun-function
))
1394 ;;; In-comment text handling.
1396 (c-lang-defconst c-paragraph-start
1397 "Regexp to append to `paragraph-start'."
1399 java
"\\(@[a-zA-Z]+\\>\\|$\\)" ; For Javadoc.
1400 pike
"\\(@[a-zA-Z_-]+\\>\\([^{]\\|$\\)\\|$\\)") ; For Pike refdoc.
1401 (c-lang-defvar c-paragraph-start
(c-lang-const c-paragraph-start
))
1403 (c-lang-defconst c-paragraph-separate
1404 "Regexp to append to `paragraph-separate'."
1406 pike
(c-lang-const c-paragraph-start
))
1407 (c-lang-defvar c-paragraph-separate
(c-lang-const c-paragraph-separate
))
1412 ;; Note: All and only all language constants containing keyword lists
1413 ;; should end with "-kwds"; they're automatically collected into the
1414 ;; `c-kwds-lang-consts' list below and used to build `c-keywords' etc.
1416 (c-lang-defconst c-primitive-type-kwds
1417 "Primitive type keywords. As opposed to the other keyword lists, the
1418 keywords listed here are fontified with the type face instead of the
1421 If any of these also are on `c-type-list-kwds', `c-ref-list-kwds',
1422 `c-colon-type-list-kwds', `c-paren-nontype-kwds', `c-paren-type-kwds',
1423 `c-<>-type-kwds', or `c-<>-arglist-kwds' then the associated clauses
1426 Do not try to modify this list for end user customizations; the
1427 `*-font-lock-extra-types' variable, where `*' is the mode prefix, is
1428 the appropriate place for that."
1429 t
'("char" "double" "float" "int" "long" "short" "signed"
1432 '("_Bool" "_Complex" "_Imaginary") ; Conditionally defined in C99.
1433 (c-lang-const c-primitive-type-kwds
))
1436 (c-lang-const c-primitive-type-kwds
))
1437 ;; Objective-C extends C, but probably not the new stuff in C99.
1439 '("id" "Class" "SEL" "IMP" "BOOL")
1440 (c-lang-const c-primitive-type-kwds
))
1441 java
'("boolean" "byte" "char" "double" "float" "int" "long" "short" "void")
1442 idl
'("Object" "ValueBase" "any" "boolean" "char" "double" "fixed" "float"
1443 "long" "octet" "sequence" "short" "string" "void" "wchar" "wstring"
1446 ;; The following can't really end a type, but we have to specify them
1447 ;; here due to the assumption in `c-primitive-type-prefix-kwds'. It
1448 ;; doesn't matter that much.
1449 "unsigned" "strong")
1450 pike
'(;; this_program isn't really a keyword, but it's practically
1451 ;; used as a builtin type.
1452 "array" "float" "function" "int" "mapping" "mixed" "multiset"
1453 "object" "program" "string" "this_program" "void"))
1455 (c-lang-defconst c-primitive-type-key
1456 ;; An adorned regexp that matches `c-primitive-type-kwds'.
1457 t
(c-make-keywords-re t
(c-lang-const c-primitive-type-kwds
)))
1458 (c-lang-defvar c-primitive-type-key
(c-lang-const c-primitive-type-key
))
1460 (c-lang-defconst c-primitive-type-prefix-kwds
1461 "Keywords that might act as prefixes for primitive types. Assumed to
1462 be a subset of `c-primitive-type-kwds'."
1464 (c c
++) '("long" "short" "signed" "unsigned")
1465 idl
'("long" "unsigned"
1469 (c-lang-defconst c-type-prefix-kwds
1470 "Keywords where the following name - if any - is a type name, and
1471 where the keyword together with the symbol works as a type in
1474 Note that an alternative if the second part doesn't hold is
1475 `c-type-list-kwds'. Keywords on this list are typically also present
1476 on one of the `*-decl-kwds' lists."
1478 c
'("struct" "union" "enum")
1479 c
++ (append '("class" "typename")
1480 (c-lang-const c-type-prefix-kwds c
)))
1482 (c-lang-defconst c-type-prefix-key
1483 ;; Adorned regexp matching `c-type-prefix-kwds'.
1484 t
(c-make-keywords-re t
(c-lang-const c-type-prefix-kwds
)))
1485 (c-lang-defvar c-type-prefix-key
(c-lang-const c-type-prefix-key
))
1487 (c-lang-defconst c-type-modifier-kwds
1488 "Type modifier keywords. These can occur almost anywhere in types
1489 but they don't build a type of themselves. Unlike the keywords on
1490 `c-primitive-type-kwds', they are fontified with the keyword face and
1493 c
'("const" "restrict" "volatile")
1494 c
++ '("const" "volatile" "throw")
1495 objc
'("const" "volatile"))
1497 (c-lang-defconst c-opt-type-modifier-key
1498 ;; Adorned regexp matching `c-type-modifier-kwds', or nil in
1499 ;; languages without such keywords.
1500 t
(and (c-lang-const c-type-modifier-kwds
)
1501 (c-make-keywords-re t
(c-lang-const c-type-modifier-kwds
))))
1502 (c-lang-defvar c-opt-type-modifier-key
(c-lang-const c-opt-type-modifier-key
))
1504 (c-lang-defconst c-opt-type-component-key
1505 ;; An adorned regexp that matches `c-primitive-type-prefix-kwds' and
1506 ;; `c-type-modifier-kwds', or nil in languages without any of them.
1507 t
(and (or (c-lang-const c-primitive-type-prefix-kwds
)
1508 (c-lang-const c-type-modifier-kwds
))
1509 (c-make-keywords-re t
1510 (append (c-lang-const c-primitive-type-prefix-kwds
)
1511 (c-lang-const c-type-modifier-kwds
)))))
1512 (c-lang-defvar c-opt-type-component-key
1513 (c-lang-const c-opt-type-component-key
))
1515 (c-lang-defconst c-type-start-kwds
1516 ;; All keywords that can start a type (i.e. are either a type prefix
1517 ;; or a complete type).
1518 t
(delete-duplicates (append (c-lang-const c-primitive-type-kwds
)
1519 (c-lang-const c-type-prefix-kwds
)
1520 (c-lang-const c-type-modifier-kwds
))
1521 :test
'string-equal
))
1523 (c-lang-defconst c-class-decl-kwds
1524 "Keywords introducing declarations where the following block (if any)
1525 contains another declaration level that should be considered a class.
1527 If any of these also are on `c-type-list-kwds', `c-ref-list-kwds',
1528 `c-colon-type-list-kwds', `c-paren-nontype-kwds', `c-paren-type-kwds',
1529 `c-<>-type-kwds', or `c-<>-arglist-kwds' then the associated clauses
1532 Note that presence on this list does not automatically treat the
1533 following identifier as a type; the keyword must also be present on
1534 `c-type-prefix-kwds' or `c-type-list-kwds' to accomplish that."
1536 c
'("struct" "union")
1537 c
++ '("class" "struct" "union")
1538 objc
'("struct" "union"
1539 "@interface" "@implementation" "@protocol")
1540 java
'("class" "interface")
1541 idl
'("component" "eventtype" "exception" "home" "interface" "struct"
1544 "storagehome" "storagetype"
1546 "catalog" "executor" "manages" "segment")
1549 (c-lang-defconst c-class-key
1550 ;; Regexp matching the start of a class.
1551 t
(c-make-keywords-re t
(c-lang-const c-class-decl-kwds
)))
1552 (c-lang-defvar c-class-key
(c-lang-const c-class-key
))
1554 (c-lang-defconst c-brace-list-decl-kwds
1555 "Keywords introducing declarations where the following block (if
1556 any) is a brace list.
1558 If any of these also are on `c-type-list-kwds', `c-ref-list-kwds',
1559 `c-colon-type-list-kwds', `c-paren-nontype-kwds', `c-paren-type-kwds',
1560 `c-<>-type-kwds', or `c-<>-arglist-kwds' then the associated clauses
1565 (c-lang-defconst c-brace-list-key
1566 ;; Regexp matching the start of declarations where the following
1567 ;; block is a brace list.
1568 t
(c-make-keywords-re t
(c-lang-const c-brace-list-decl-kwds
)))
1569 (c-lang-defvar c-brace-list-key
(c-lang-const c-brace-list-key
))
1571 (c-lang-defconst c-other-block-decl-kwds
1572 "Keywords where the following block (if any) contains another
1573 declaration level that should not be considered a class. For every
1574 keyword here, CC Mode will add a set of special syntactic symbols for
1575 those blocks. E.g. if the keyword is \"foo\" then there will be
1576 `foo-open', `foo-close', and `infoo' symbols.
1578 The intention is that this category should be used for block
1579 constructs that aren't related to object orientation concepts like
1580 classes (which thus also include e.g. interfaces, templates,
1581 contracts, structs, etc). The more pragmatic distinction is that
1582 while most want some indentation inside classes, it's fairly common
1583 that they don't want it in some of these constructs, so it should be
1584 simple to configure that differently from classes. See also
1585 `c-class-decl-kwds'.
1587 If any of these also are on `c-type-list-kwds', `c-ref-list-kwds',
1588 `c-colon-type-list-kwds', `c-paren-nontype-kwds', `c-paren-type-kwds',
1589 `c-<>-type-kwds', or `c-<>-arglist-kwds' then the associated clauses
1592 (c objc
) '("extern")
1593 c
++ '("namespace" "extern")
1598 (c-lang-defconst c-other-decl-block-key
1599 ;; Regexp matching the start of blocks besides classes that contain
1600 ;; another declaration level.
1601 t
(c-make-keywords-re t
(c-lang-const c-other-block-decl-kwds
)))
1602 (c-lang-defvar c-other-decl-block-key
(c-lang-const c-other-decl-block-key
))
1604 (c-lang-defvar c-other-decl-block-key-in-symbols-alist
1608 (if (string= elt
"extern")
1610 (intern (concat "in" elt
)))))
1611 (c-lang-const c-other-block-decl-kwds
))
1612 "Alist associating keywords in c-other-decl-block-decl-kwds with
1613 their matching \"in\" syntactic symbols.")
1615 (c-lang-defconst c-typedef-decl-kwds
1616 "Keywords introducing declarations where the identifier(s) being
1619 If any of these also are on `c-type-list-kwds', `c-ref-list-kwds',
1620 `c-colon-type-list-kwds', `c-paren-nontype-kwds', `c-paren-type-kwds',
1621 `c-<>-type-kwds', or `c-<>-arglist-kwds' then the associated clauses
1623 ;; Default to `c-class-decl-kwds' and `c-brace-list-decl-kwds'
1624 ;; (since e.g. "Foo" is a type that's being defined in "class Foo
1626 t
(append (c-lang-const c-class-decl-kwds
)
1627 (c-lang-const c-brace-list-decl-kwds
))
1628 ;; Languages that have a "typedef" construct.
1629 (c c
++ objc idl pike
) (append (c-lang-const c-typedef-decl-kwds
)
1631 ;; Unlike most other languages, exception names are not handled as
1632 ;; types in IDL since they only can occur in "raises" specs.
1633 idl
(delete "exception" (append (c-lang-const c-typedef-decl-kwds
) nil
)))
1635 (c-lang-defconst c-typeless-decl-kwds
1636 "Keywords introducing declarations where the \(first) identifier
1637 \(declarator) follows directly after the keyword, without any type.
1639 If any of these also are on `c-type-list-kwds', `c-ref-list-kwds',
1640 `c-colon-type-list-kwds', `c-paren-nontype-kwds', `c-paren-type-kwds',
1641 `c-<>-type-kwds', or `c-<>-arglist-kwds' then the associated clauses
1643 ;; Default to `c-class-decl-kwds' and `c-brace-list-decl-kwds'
1644 ;; (since e.g. "Foo" is the identifier being defined in "class Foo
1646 t
(append (c-lang-const c-class-decl-kwds
)
1647 (c-lang-const c-brace-list-decl-kwds
))
1648 ;; Note: "manages" for CORBA CIDL clashes with its presence on
1649 ;; `c-type-list-kwds' for IDL.
1650 idl
(append (c-lang-const c-typeless-decl-kwds
)
1651 '("factory" "finder" "native"
1656 pike
(append (c-lang-const c-class-decl-kwds
)
1659 (c-lang-defconst c-modifier-kwds
1660 "Keywords that can prefix normal declarations of identifiers
1661 \(and typically act as flags). Things like argument declarations
1662 inside function headers are also considered declarations in this
1665 If any of these also are on `c-type-list-kwds', `c-ref-list-kwds',
1666 `c-colon-type-list-kwds', `c-paren-nontype-kwds', `c-paren-type-kwds',
1667 `c-<>-type-kwds', or `c-<>-arglist-kwds' then the associated clauses
1670 (c c
++) '("auto" "extern" "inline" "register" "static")
1671 c
++ (append '("explicit" "friend" "mutable" "template" "using" "virtual")
1672 (c-lang-const c-modifier-kwds
))
1673 objc
'("auto" "bycopy" "byref" "extern" "in" "inout" "oneway" "out" "static")
1674 ;; FIXME: Some of those below ought to be on `c-other-decl-kwds' instead.
1675 idl
'("abstract" "attribute" "const" "consumes" "custom" "emits" "import"
1676 "in" "inout" "local" "multiple" "oneway" "out" "private" "provides"
1677 "public" "publishes" "readonly" "typeid" "typeprefix" "uses"
1681 "bindsTo" "delegatesTo" "implements" "proxy" "storedOn")
1682 ;; Note: "const" is not used in Java, but it's still a reserved keyword.
1683 java
'("abstract" "const" "final" "native" "private" "protected" "public"
1684 "static" "strictfp" "synchronized" "transient" "volatile")
1685 pike
'("final" "inline" "local" "nomask" "optional" "private" "protected"
1686 "public" "static" "variant"))
1688 (c-lang-defconst c-other-decl-kwds
1689 "Keywords that can start or prefix any declaration level construct,
1690 besides those on `c-class-decl-kwds', `c-brace-list-decl-kwds',
1691 `c-other-block-decl-kwds', `c-typedef-decl-kwds',
1692 `c-typeless-decl-kwds' and `c-modifier-kwds'.
1694 If any of these also are on `c-type-list-kwds', `c-ref-list-kwds',
1695 `c-colon-type-list-kwds', `c-paren-nontype-kwds', `c-paren-type-kwds',
1696 `c-<>-type-kwds', or `c-<>-arglist-kwds' then the associated clauses
1699 objc
'("@class" "@end" "@defs")
1700 java
'("import" "package")
1701 pike
'("import" "inherit"))
1703 (c-lang-defconst c-decl-start-kwds
1704 "Keywords that always start declarations, wherever they occur.
1705 This can be used for declarations that aren't recognized by the normal
1706 combination of `c-decl-prefix-re' and `c-decl-start-re'."
1708 ;; Classes can be declared anywhere in a Pike expression.
1711 (c-lang-defconst c-decl-hangon-kwds
1712 "Keywords that can occur anywhere in a declaration level construct.
1713 This is used for self-contained things that can be tacked on anywhere
1714 on a declaration and that should be ignored to be able to recognize it
1715 correctly. Typical cases are compiler extensions like
1716 \"__attribute__\" or \"__declspec\":
1718 __declspec(noreturn) void foo();
1719 class __declspec(dllexport) classname {...};
1720 void foo() __attribute__((noreturn));
1722 Note that unrecognized plain symbols are skipped anyway if they occur
1723 before the type, so such things are not necessary to mention here.
1724 Mentioning them here is necessary only if they can occur in other
1725 places, or if they are followed by a construct that must be skipped
1726 over \(like the parens in the \"__attribute__\" and \"__declspec\"
1727 examples above). In the last case, they alse need to be present on
1728 one of `c-type-list-kwds', `c-ref-list-kwds',
1729 `c-colon-type-list-kwds', `c-paren-nontype-kwds', `c-paren-type-kwds',
1730 `c-<>-type-kwds', or `c-<>-arglist-kwds'."
1731 ;; NB: These are currently not recognized in all parts of a
1732 ;; declaration. Specifically, they aren't recognized in the middle
1733 ;; of multi-token types, inside declarators, and between the
1734 ;; identifier and the arglist paren of a function declaration.
1736 ;; FIXME: This ought to be user customizable since compiler stuff
1737 ;; like this usually is wrapped in project specific macros. (It'd
1738 ;; of course be even better if we could cope without knowing this.)
1740 (c c
++) '(;; GCC extension.
1745 (c-lang-defconst c-decl-hangon-key
1746 ;; Adorned regexp matching `c-decl-hangon-kwds'.
1747 t
(c-make-keywords-re t
(c-lang-const c-decl-hangon-kwds
)))
1748 (c-lang-defvar c-decl-hangon-key
(c-lang-const c-decl-hangon-key
))
1750 (c-lang-defconst c-prefix-spec-kwds
1751 ;; All keywords that can occur in the preamble of a declaration.
1752 ;; They typically occur before the type, but they are also matched
1753 ;; after presumptive types since we often can't be sure that
1754 ;; something is a type or just some sort of macro in front of the
1755 ;; declaration. They might be ambiguous with types or type
1757 t
(delete-duplicates (append (c-lang-const c-class-decl-kwds
)
1758 (c-lang-const c-brace-list-decl-kwds
)
1759 (c-lang-const c-other-block-decl-kwds
)
1760 (c-lang-const c-typedef-decl-kwds
)
1761 (c-lang-const c-typeless-decl-kwds
)
1762 (c-lang-const c-modifier-kwds
)
1763 (c-lang-const c-other-decl-kwds
)
1764 (c-lang-const c-decl-start-kwds
)
1765 (c-lang-const c-decl-hangon-kwds
))
1766 :test
'string-equal
))
1768 (c-lang-defconst c-prefix-spec-kwds-re
1769 ;; Adorned regexp of `c-prefix-spec-kwds'.
1770 t
(c-make-keywords-re t
(c-lang-const c-prefix-spec-kwds
)))
1771 (c-lang-defvar c-prefix-spec-kwds-re
(c-lang-const c-prefix-spec-kwds-re
))
1773 (c-lang-defconst c-specifier-key
1774 ;; Adorned regexp of the keywords in `c-prefix-spec-kwds' that
1775 ;; aren't ambiguous with types or type prefixes.
1776 t
(c-make-keywords-re t
1777 (set-difference (c-lang-const c-prefix-spec-kwds
)
1778 (c-lang-const c-type-start-kwds
)
1779 :test
'string-equal
)))
1780 (c-lang-defvar c-specifier-key
(c-lang-const c-specifier-key
))
1782 (c-lang-defconst c-postfix-spec-kwds
1783 ;; Keywords that can occur after argument list of a function header
1784 ;; declaration, i.e. in the "K&R region".
1785 t
(append (c-lang-const c-postfix-decl-spec-kwds
)
1786 (c-lang-const c-decl-hangon-kwds
)))
1788 (c-lang-defconst c-not-decl-init-keywords
1789 ;; Adorned regexp matching all keywords that can't appear at the
1790 ;; start of a declaration.
1791 t
(c-make-keywords-re t
1792 (set-difference (c-lang-const c-keywords
)
1793 (append (c-lang-const c-type-start-kwds
)
1794 (c-lang-const c-prefix-spec-kwds
))
1795 :test
'string-equal
)))
1796 (c-lang-defvar c-not-decl-init-keywords
1797 (c-lang-const c-not-decl-init-keywords
))
1799 (c-lang-defconst c-protection-kwds
1800 "Access protection label keywords in classes."
1802 c
++ '("private" "protected" "public")
1803 objc
'("@private" "@protected" "@public"))
1805 (c-lang-defconst c-block-decls-with-vars
1806 "Keywords introducing declarations that can contain a block which
1807 might be followed by variable declarations, e.g. like \"foo\" in
1808 \"class Foo { ... } foo;\". So if there is a block in a declaration
1809 like that, it ends with the following ';' and not right away.
1811 The keywords on list are assumed to also be present on one of the
1812 `*-decl-kwds' lists."
1814 (c objc
) '("struct" "union" "enum" "typedef")
1815 c
++ '("class" "struct" "union" "enum" "typedef"))
1817 (c-lang-defconst c-opt-block-decls-with-vars-key
1818 ;; Regexp matching the `c-block-decls-with-vars' keywords, or nil in
1819 ;; languages without such constructs.
1820 t
(and (c-lang-const c-block-decls-with-vars
)
1821 (c-make-keywords-re t
(c-lang-const c-block-decls-with-vars
))))
1822 (c-lang-defvar c-opt-block-decls-with-vars-key
1823 (c-lang-const c-opt-block-decls-with-vars-key
))
1825 (c-lang-defconst c-postfix-decl-spec-kwds
1826 "Keywords introducing extra declaration specifiers in the region
1827 between the header and the body \(i.e. the \"K&R-region\") in
1830 java
'("extends" "implements" "throws")
1831 idl
'("context" "getraises" "manages" "primarykey" "raises" "setraises"
1834 "as" "const" "implements" "of" "ref"))
1836 (c-lang-defconst c-nonsymbol-sexp-kwds
1837 "Keywords that may be followed by a nonsymbol sexp before whatever
1838 construct it's part of continues."
1840 (c c
++ objc
) '("extern"))
1842 (c-lang-defconst c-type-list-kwds
1843 "Keywords that may be followed by a comma separated list of type
1844 identifiers, where each optionally can be prefixed by keywords. (Can
1845 also be used for the special case when the list can contain only one
1848 Assumed to be mutually exclusive with `c-ref-list-kwds'. There's no
1849 reason to put keywords on this list if they are on `c-type-prefix-kwds'.
1850 There's also no reason to add keywords that prefixes a normal
1851 declaration consisting of a type followed by a declarator (list), so
1852 the keywords on `c-modifier-kwds' should normally not be listed here
1855 Note: Use `c-typeless-decl-kwds' for keywords followed by a function
1856 or variable identifier (that's being defined)."
1860 java
'("import" "new" "extends" "implements" "throws")
1861 idl
'("manages" "native" "primarykey" "supports"
1863 "as" "implements" "of" "scope")
1866 (c-lang-defconst c-ref-list-kwds
1867 "Keywords that may be followed by a comma separated list of
1868 reference (i.e. namespace/scope/module) identifiers, where each
1869 optionally can be prefixed by keywords. (Can also be used for the
1870 special case when the list can contain only one element.) Assumed to
1871 be mutually exclusive with `c-type-list-kwds'.
1873 Note: Use `c-typeless-decl-kwds' for keywords followed by a function
1874 or variable identifier (that's being defined)."
1878 idl
'("import" "module"
1883 (c-lang-defconst c-colon-type-list-kwds
1884 "Keywords that may be followed (not necessarily directly) by a colon
1885 and then a comma separated list of type identifiers, where each
1886 optionally can be prefixed by keywords. (Can also be used for the
1887 special case when the list can contain only one element.)"
1889 c
++ '("class" "struct")
1890 idl
'("component" "eventtype" "home" "interface" "valuetype"
1892 "storagehome" "storagetype"))
1894 (c-lang-defconst c-colon-type-list-re
1895 "Regexp matched after the keywords in `c-colon-type-list-kwds' to skip
1896 forward to the colon. The end of the match is assumed to be directly
1897 after the colon, so the regexp should end with \":\". Must be a
1898 regexp if `c-colon-type-list-kwds' isn't nil."
1899 t
(if (c-lang-const c-colon-type-list-kwds
)
1900 ;; Disallow various common punctuation chars that can't come
1901 ;; before the ":" that starts the inherit list after "class"
1902 ;; or "struct" in C++. (Also used as default for other
1904 "[^\]\[{}();,/#=:]*:"))
1905 (c-lang-defvar c-colon-type-list-re
(c-lang-const c-colon-type-list-re
))
1907 (c-lang-defconst c-paren-nontype-kwds
1908 "Keywords that may be followed by a parenthesis expression that doesn't
1909 contain type identifiers."
1911 (c c
++) '(;; GCC extension.
1916 (c-lang-defconst c-paren-type-kwds
1917 "Keywords that may be followed by a parenthesis expression containing
1918 type identifiers separated by arbitrary tokens."
1923 pike
'("array" "function" "int" "mapping" "multiset" "object" "program"))
1925 (c-lang-defconst c-paren-any-kwds
1926 t
(delete-duplicates (append (c-lang-const c-paren-nontype-kwds
)
1927 (c-lang-const c-paren-type-kwds
))
1928 :test
'string-equal
))
1930 (c-lang-defconst c-
<>-type-kwds
1931 "Keywords that may be followed by an angle bracket expression
1932 containing type identifiers separated by \",\". The difference from
1933 `c-<>-arglist-kwds' is that unknown names are taken to be types and
1934 not other identifiers. `c-recognize-<>-arglists' is assumed to be set
1942 (c-lang-defconst c-
<>-arglist-kwds
1943 "Keywords that can be followed by a C++ style template arglist; see
1944 `c-recognize-<>-arglists' for details. That language constant is
1945 assumed to be set if this isn't nil."
1948 idl
'("fixed" "string" "wstring"))
1950 (c-lang-defconst c-
<>-sexp-kwds
1951 ;; All keywords that can be followed by an angle bracket sexp.
1952 t
(delete-duplicates (append (c-lang-const c-
<>-type-kwds
)
1953 (c-lang-const c-
<>-arglist-kwds
))
1954 :test
'string-equal
))
1956 (c-lang-defconst c-opt-
<>-sexp-key
1957 ;; Adorned regexp matching keywords that can be followed by an angle
1958 ;; bracket sexp. Always set when `c-recognize-<>-arglists' is.
1959 t
(if (c-lang-const c-recognize-
<>-arglists
)
1960 (c-make-keywords-re t
(c-lang-const c-
<>-sexp-kwds
))))
1961 (c-lang-defvar c-opt-
<>-sexp-key
(c-lang-const c-opt-
<>-sexp-key
))
1963 (c-lang-defconst c-brace-id-list-kwds
1964 "Keywords that may be followed by a brace block containing a comma
1965 separated list of identifier definitions, i.e. like the list of
1966 identifiers that follows the type in a normal declaration."
1967 t
(c-lang-const c-brace-list-decl-kwds
))
1969 (c-lang-defconst c-block-stmt-1-kwds
1970 "Statement keywords followed directly by a substatement."
1972 c
++ '("do" "else" "try")
1973 objc
'("do" "else" "@finally" "@try")
1974 java
'("do" "else" "finally" "try")
1977 (c-lang-defconst c-block-stmt-1-key
1978 ;; Regexp matching the start of any statement followed directly by a
1979 ;; substatement (doesn't match a bare block, however).
1980 t
(c-make-keywords-re t
(c-lang-const c-block-stmt-1-kwds
)))
1981 (c-lang-defvar c-block-stmt-1-key
(c-lang-const c-block-stmt-1-key
))
1983 (c-lang-defconst c-block-stmt-2-kwds
1984 "Statement keywords followed by a paren sexp and then by a substatement."
1985 t
'("for" "if" "switch" "while")
1986 c
++ '("for" "if" "switch" "while" "catch")
1987 objc
'("for" "if" "switch" "while" "@catch" "@synchronized")
1988 java
'("for" "if" "switch" "while" "catch" "synchronized")
1990 pike
'("for" "if" "switch" "while" "foreach")
1991 awk
'("for" "if" "while"))
1993 (c-lang-defconst c-block-stmt-2-key
1994 ;; Regexp matching the start of any statement followed by a paren sexp
1995 ;; and then by a substatement.
1996 t
(c-make-keywords-re t
(c-lang-const c-block-stmt-2-kwds
)))
1997 (c-lang-defvar c-block-stmt-2-key
(c-lang-const c-block-stmt-2-key
))
1999 (c-lang-defconst c-block-stmt-kwds
2000 ;; Union of `c-block-stmt-1-kwds' and `c-block-stmt-2-kwds'.
2001 t
(delete-duplicates (append (c-lang-const c-block-stmt-1-kwds
)
2002 (c-lang-const c-block-stmt-2-kwds
))
2003 :test
'string-equal
))
2005 (c-lang-defconst c-opt-block-stmt-key
2006 ;; Regexp matching the start of any statement that has a
2007 ;; substatement (except a bare block). Nil in languages that
2008 ;; don't have such constructs.
2009 t
(if (or (c-lang-const c-block-stmt-1-kwds
)
2010 (c-lang-const c-block-stmt-2-kwds
))
2011 (c-make-keywords-re t
2012 (append (c-lang-const c-block-stmt-1-kwds
)
2013 (c-lang-const c-block-stmt-2-kwds
)))))
2014 (c-lang-defvar c-opt-block-stmt-key
(c-lang-const c-opt-block-stmt-key
))
2016 (c-lang-defconst c-simple-stmt-kwds
2017 "Statement keywords followed by an expression or nothing."
2018 t
'("break" "continue" "goto" "return")
2019 objc
'("break" "continue" "goto" "return" "@throw")
2020 ;; Note: `goto' is not valid in Java, but the keyword is still reserved.
2021 java
'("break" "continue" "goto" "return" "throw")
2023 pike
'("break" "continue" "return")
2024 awk
'(;; Not sure about "delete", "exit", "getline", etc. ; ACM 2002/5/30
2025 "break" "continue" "return" "delete" "exit" "getline" "next"
2026 "nextfile" "print" "printf"))
2028 (c-lang-defconst c-simple-stmt-key
2029 ;; Adorned regexp matching `c-simple-stmt-kwds'.
2030 t
(c-make-keywords-re t
(c-lang-const c-simple-stmt-kwds
)))
2031 (c-lang-defvar c-simple-stmt-key
(c-lang-const c-simple-stmt-key
))
2033 (c-lang-defconst c-paren-stmt-kwds
2034 "Statement keywords followed by a parenthesis expression that
2035 nevertheless contains a list separated with ';' and not ','."
2039 (c-lang-defconst c-paren-stmt-key
2040 ;; Adorned regexp matching `c-paren-stmt-kwds'.
2041 t
(c-make-keywords-re t
(c-lang-const c-paren-stmt-kwds
)))
2042 (c-lang-defvar c-paren-stmt-key
(c-lang-const c-paren-stmt-key
))
2044 (c-lang-defconst c-asm-stmt-kwds
2045 "Statement keywords followed by an assembler expression."
2047 (c c
++) '("asm" "__asm__")) ;; Not standard, but common.
2049 (c-lang-defconst c-opt-asm-stmt-key
2050 ;; Regexp matching the start of an assembler statement. Nil in
2051 ;; languages that don't support that.
2052 t
(if (c-lang-const c-asm-stmt-kwds
)
2053 (c-make-keywords-re t
(c-lang-const c-asm-stmt-kwds
))))
2054 (c-lang-defvar c-opt-asm-stmt-key
(c-lang-const c-opt-asm-stmt-key
))
2056 (c-lang-defconst c-label-kwds
2057 "Keywords introducing colon terminated labels in blocks."
2058 t
'("case" "default")
2061 (c-lang-defconst c-label-kwds-regexp
2062 ;; Adorned regexp matching any keyword that introduces a label.
2063 t
(c-make-keywords-re t
(c-lang-const c-label-kwds
)))
2064 (c-lang-defvar c-label-kwds-regexp
(c-lang-const c-label-kwds-regexp
))
2066 (c-lang-defconst c-before-label-kwds
2067 "Keywords that might be followed by a label identifier."
2069 (java pike
) (append '("break" "continue")
2070 (c-lang-const c-before-label-kwds
))
2074 (c-lang-defconst c-constant-kwds
2075 "Keywords for constants."
2077 (c c
++) '("NULL" ;; Not a keyword, but practically works as one.
2078 "false" "true") ; Defined in C99.
2080 idl
'("TRUE" "FALSE")
2081 java
'("true" "false" "null") ; technically "literals", not keywords
2082 pike
'("UNDEFINED")) ;; Not a keyword, but practically works as one.
2084 (c-lang-defconst c-primary-expr-kwds
2085 "Keywords besides constants and operators that start primary expressions."
2087 c
++ '("operator" "this")
2088 objc
'("super" "self")
2090 pike
'("this")) ;; Not really a keyword, but practically works as one.
2092 (c-lang-defconst c-expr-kwds
2093 ;; Keywords that can occur anywhere in expressions. Built from
2094 ;; `c-primary-expr-kwds' and all keyword operators in `c-operators'.
2095 t
(delete-duplicates
2096 (append (c-lang-const c-primary-expr-kwds
)
2097 (c-filter-ops (c-lang-const c-operator-list
)
2099 "\\`\\(\\w\\|\\s_\\)+\\'"))
2100 :test
'string-equal
))
2102 (c-lang-defconst c-lambda-kwds
2103 "Keywords that start lambda constructs, i.e. function definitions in
2108 (c-lang-defconst c-inexpr-block-kwds
2109 "Keywords that start constructs followed by statement blocks which can
2110 be used in expressions \(the gcc extension for this in C and C++ is
2111 handled separately by `c-recognize-paren-inexpr-blocks')."
2113 pike
'("catch" "gauge"))
2115 (c-lang-defconst c-inexpr-class-kwds
2116 "Keywords that can start classes inside expressions."
2121 (c-lang-defconst c-inexpr-brace-list-kwds
2122 "Keywords that can start brace list blocks inside expressions.
2123 Note that Java specific rules are currently applied to tell this from
2124 `c-inexpr-class-kwds'."
2128 (c-lang-defconst c-opt-inexpr-brace-list-key
2129 ;; Regexp matching the start of a brace list in an expression, or
2130 ;; nil in languages that don't have such things. This should not
2131 ;; match brace lists recognized through `c-special-brace-lists'.
2132 t
(and (c-lang-const c-inexpr-brace-list-kwds
)
2133 (c-make-keywords-re t
(c-lang-const c-inexpr-brace-list-kwds
))))
2134 (c-lang-defvar c-opt-inexpr-brace-list-key
2135 (c-lang-const c-opt-inexpr-brace-list-key
))
2137 (c-lang-defconst c-decl-block-key
2138 ;; Regexp matching keywords in any construct that contain another
2139 ;; declaration level, i.e. that isn't followed by a function block
2140 ;; or brace list. When the first submatch matches, it's an
2141 ;; unambiguous construct, otherwise it's an ambiguous match that
2142 ;; might also be the return type of a function declaration.
2143 t
(let* ((decl-kwds (append (c-lang-const c-class-decl-kwds
)
2144 (c-lang-const c-other-block-decl-kwds
)
2145 (c-lang-const c-inexpr-class-kwds
)))
2146 (unambiguous (set-difference decl-kwds
2147 (c-lang-const c-type-start-kwds
)
2148 :test
'string-equal
))
2149 (ambiguous (intersection decl-kwds
2150 (c-lang-const c-type-start-kwds
)
2151 :test
'string-equal
)))
2153 (concat (c-make-keywords-re t unambiguous
)
2155 (c-make-keywords-re t ambiguous
))
2156 (c-make-keywords-re t unambiguous
))))
2157 (c-lang-defvar c-decl-block-key
(c-lang-const c-decl-block-key
))
2159 (c-lang-defconst c-bitfield-kwds
2160 "Keywords that can introduce bitfields."
2162 (c c
++ objc
) '("char" "int" "long" "signed" "unsigned"))
2164 (c-lang-defconst c-opt-bitfield-key
2165 ;; Regexp matching the start of a bitfield (not uniquely), or nil in
2166 ;; languages without bitfield support.
2168 (c c
++) (c-make-keywords-re t
(c-lang-const c-bitfield-kwds
)))
2169 (c-lang-defvar c-opt-bitfield-key
(c-lang-const c-opt-bitfield-key
))
2171 (c-lang-defconst c-other-kwds
2172 "Keywords not accounted for by any other `*-kwds' language constant."
2175 ;; In CORBA CIDL: (These are declaration keywords that never
2176 ;; can start a declaration.)
2177 "entity" "process" "service" "session" "storage"))
2180 ;;; Constants built from keywords.
2182 ;; Note: No `*-kwds' language constants may be defined below this point.
2185 (defconst c-kwds-lang-consts
2186 ;; List of all the language constants that contain keyword lists.
2188 (mapatoms (lambda (sym)
2189 (when (and (boundp sym
)
2190 (string-match "-kwds\\'" (symbol-name sym
)))
2191 ;; Make the list of globally interned symbols
2192 ;; instead of ones interned in `c-lang-constants'.
2193 (setq list
(cons (intern (symbol-name sym
)) list
))))
2197 (c-lang-defconst c-keywords
2198 ;; All keywords as a list.
2199 t
(delete-duplicates
2200 (c-lang-defconst-eval-immediately
2201 `(append ,@(mapcar (lambda (kwds-lang-const)
2202 `(c-lang-const ,kwds-lang-const
))
2205 :test
'string-equal
))
2207 (c-lang-defconst c-keywords-regexp
2208 ;; All keywords as an adorned regexp.
2209 t
(c-make-keywords-re t
(c-lang-const c-keywords
)))
2210 (c-lang-defvar c-keywords-regexp
(c-lang-const c-keywords-regexp
))
2212 (c-lang-defconst c-keyword-member-alist
2213 ;; An alist with all the keywords in the cars. The cdr for each
2214 ;; keyword is a list of the symbols for the `*-kwds' lists that
2216 t
(let ((kwd-list-alist
2217 (c-lang-defconst-eval-immediately
2218 `(list ,@(mapcar (lambda (kwds-lang-const)
2219 `(cons ',kwds-lang-const
2220 (c-lang-const ,kwds-lang-const
)))
2221 c-kwds-lang-consts
))))
2222 lang-const kwd-list kwd
2224 (while kwd-list-alist
2225 (setq lang-const
(caar kwd-list-alist
)
2226 kwd-list
(cdar kwd-list-alist
)
2227 kwd-list-alist
(cdr kwd-list-alist
))
2229 (setq kwd
(car kwd-list
)
2230 kwd-list
(cdr kwd-list
))
2231 (unless (setq elem
(assoc kwd result-alist
))
2232 (setq result-alist
(cons (setq elem
(list kwd
)) result-alist
)))
2233 (unless (memq lang-const
(cdr elem
))
2234 (setcdr elem
(cons lang-const
(cdr elem
))))))
2237 (c-lang-defvar c-keywords-obarray
2238 ;; An obarray containing all keywords as symbols. The property list
2239 ;; of each symbol has a non-nil entry for the specific `*-kwds'
2240 ;; lists it's a member of.
2242 ;; E.g. to see whether the string str contains a keyword on
2243 ;; `c-class-decl-kwds', one can do like this:
2244 ;; (get (intern-soft str c-keyword-obarray) 'c-class-decl-kwds)
2245 ;; Which preferably is written using the associated functions in
2247 ;; (c-keyword-member (c-keyword-sym str) 'c-class-decl-kwds)
2249 ;; The obarray is not stored directly as a language constant since
2250 ;; the printed representation for obarrays used in .elc files isn't
2253 (let* ((alist (c-lang-const c-keyword-member-alist
))
2255 (obarray (make-vector (* (length alist
) 2) 0)))
2257 (setq kwd
(caar alist
)
2258 lang-const-list
(cdar alist
)
2260 (setplist (intern kwd obarray
)
2261 ;; Emacs has an odd bug that causes `mapcan' to fail
2262 ;; with unintelligible errors. (XEmacs works.)
2263 ;;(mapcan (lambda (lang-const)
2264 ;; (list lang-const t))
2266 (apply 'nconc
(mapcar (lambda (lang-const)
2267 (list lang-const t
))
2271 (c-lang-defconst c-regular-keywords-regexp
2272 ;; Adorned regexp matching all keywords that should be fontified
2273 ;; with the keywords face. I.e. that aren't types or constants.
2274 t
(c-make-keywords-re t
2275 (set-difference (c-lang-const c-keywords
)
2276 (append (c-lang-const c-primitive-type-kwds
)
2277 (c-lang-const c-constant-kwds
))
2278 :test
'string-equal
)))
2279 (c-lang-defvar c-regular-keywords-regexp
2280 (c-lang-const c-regular-keywords-regexp
))
2282 (c-lang-defconst c-primary-expr-regexp
2283 ;; Regexp matching the start of any primary expression, i.e. any
2284 ;; literal, symbol, prefix operator, and '('. It doesn't need to
2285 ;; exclude keywords; they are excluded afterwards unless the second
2286 ;; submatch matches. If the first but not the second submatch
2287 ;; matches then it is an ambiguous primary expression; it could also
2288 ;; be a match of e.g. an infix operator. (The case with ambiguous
2289 ;; keyword operators isn't handled.)
2291 t
(let* ((prefix-ops
2292 (c-filter-ops (c-lang-const c-operators
)
2295 ;; Filter out the special case prefix
2296 ;; operators that are close parens.
2297 (not (string-match "\\s)" op
)))))
2299 (nonkeyword-prefix-ops
2300 (c-filter-ops prefix-ops
2302 "\\`\\(\\s.\\|\\s(\\|\\s)\\)+\\'"))
2305 (c-filter-ops (c-lang-const c-operators
)
2310 right-assoc-sequence
)
2313 (unambiguous-prefix-ops (set-difference nonkeyword-prefix-ops
2315 :test
'string-equal
))
2316 (ambiguous-prefix-ops (intersection nonkeyword-prefix-ops
2318 :test
'string-equal
)))
2322 ;; Take out all symbol class operators from `prefix-ops' and make the
2323 ;; first submatch from them together with `c-primary-expr-kwds'.
2324 (c-make-keywords-re t
2325 (append (c-lang-const c-primary-expr-kwds
)
2326 (set-difference prefix-ops nonkeyword-prefix-ops
2327 :test
'string-equal
)))
2330 ;; Match all ambiguous operators.
2331 (c-make-keywords-re nil
2332 (intersection nonkeyword-prefix-ops in-or-postfix-ops
2333 :test
'string-equal
))
2337 ;; Now match all other symbols.
2338 (c-lang-const c-symbol-start
)
2341 ;; The chars that can start integer and floating point
2346 ;; The nonambiguous operators from `prefix-ops'.
2347 (c-make-keywords-re nil
2348 (set-difference nonkeyword-prefix-ops in-or-postfix-ops
2349 :test
'string-equal
))
2352 ;; Match string and character literals.
2354 (if (memq 'gen-string-delim c-emacs-features
)
2357 (c-lang-defvar c-primary-expr-regexp
(c-lang-const c-primary-expr-regexp
))
2360 ;;; Additional constants for parser-level constructs.
2362 (c-lang-defconst c-decl-prefix-re
2363 "Regexp matching something that might precede a declaration, cast or
2364 label, such as the last token of a preceding statement or declaration.
2365 This is used in the common situation where a declaration or cast
2366 doesn't start with any specific token that can be searched for.
2368 The regexp should not match bob; that is done implicitly. It can't
2369 require a match longer than one token. The end of the token is taken
2370 to be at the end of the first submatch, which is assumed to always
2371 match. It's undefined whether identifier syntax (see
2372 `c-identifier-syntax-table') is in effect or not. This regexp is
2373 assumed to be a superset of `c-label-prefix-re' if
2374 `c-recognize-colon-labels' is set.
2376 Besides this, `c-decl-start-kwds' is used to find declarations.
2378 Note: This variable together with `c-decl-start-re' and
2379 `c-decl-start-kwds' is only used to detect \"likely\"
2380 declaration/cast/label starts. I.e. they might produce more matches
2381 but should not miss anything (or else it's necessary to use text
2382 properties - see the next note). Wherever they match, the following
2383 construct is analyzed to see if it indeed is a declaration, cast or
2384 label. That analysis is not cheap, so it's important that not too
2385 many false matches are triggered.
2387 Note: If a declaration/cast/label start can't be detected with this
2388 variable, it's necessary to use the `c-type' text property with the
2389 value `c-decl-end' on the last char of the last token preceding the
2390 declaration. See the comment blurb at the start of cc-engine.el for
2393 ;; We match a sequence of characters to skip over things like \"};\"
2394 ;; more quickly. We match ")" in C for K&R region declarations, and
2395 ;; in all languages except Java for when a cpp macro definition
2396 ;; begins with a declaration.
2397 t
"\\([\{\}\(\);,]+\\)"
2398 java
"\\([\{\}\(;,]+\\)"
2399 ;; Match "<" in C++ to get the first argument in a template arglist.
2400 ;; In that case there's an additional check in `c-find-decl-spots'
2401 ;; that it got open paren syntax.
2402 c
++ "\\([\{\}\(\);,<]+\\)"
2403 ;; Additionally match the protection directives in Objective-C.
2404 ;; Note that this doesn't cope with the longer directives, which we
2405 ;; would have to match from start to end since they don't end with
2406 ;; any easily recognized characters.
2407 objc
(concat "\\([\{\}\(\);,]+\\|"
2408 (c-make-keywords-re nil
(c-lang-const c-protection-kwds
))
2410 ;; Pike is like C but we also match "[" for multiple value
2411 ;; assignments and type casts.
2412 pike
"\\([\{\}\(\)\[;,]+\\)")
2413 (c-lang-defvar c-decl-prefix-re
(c-lang-const c-decl-prefix-re
)
2416 (c-lang-defconst c-decl-start-re
2417 "Regexp matching the start of any declaration, cast or label.
2418 It's used on the token after the one `c-decl-prefix-re' matched. This
2419 regexp should not try to match those constructs accurately as it's
2420 only used as a sieve to avoid spending more time checking other
2422 t
(c-lang-const c-identifier-start
))
2423 (c-lang-defvar c-decl-start-re
(c-lang-const c-decl-start-re
))
2425 (c-lang-defconst c-decl-prefix-or-start-re
2426 ;; Regexp matching something that might precede or start a
2427 ;; declaration, cast or label.
2429 ;; If the first submatch matches, it's taken to match the end of a
2430 ;; token that might precede such a construct, e.g. ';', '}' or '{'.
2431 ;; It's built from `c-decl-prefix-re'.
2433 ;; If the first submatch did not match, the match of the whole
2434 ;; regexp is taken to be at the first token in the declaration.
2435 ;; `c-decl-start-re' is not checked in this case.
2437 ;; Design note: The reason the same regexp is used to match both
2438 ;; tokens that precede declarations and start them is to avoid an
2439 ;; extra regexp search from the previous declaration spot in
2440 ;; `c-find-decl-spots'. Users of `c-find-decl-spots' also count on
2441 ;; that it finds all declaration/cast/label starts in approximately
2442 ;; linear order, so we can't do the searches in two separate passes.
2443 t
(if (c-lang-const c-decl-start-kwds
)
2444 (concat (c-lang-const c-decl-prefix-re
)
2446 (c-make-keywords-re t
(c-lang-const c-decl-start-kwds
)))
2447 (c-lang-const c-decl-prefix-re
)))
2448 (c-lang-defvar c-decl-prefix-or-start-re
2449 (c-lang-const c-decl-prefix-or-start-re
)
2452 (c-lang-defconst c-cast-parens
2453 ;; List containing the paren characters that can open a cast, or nil in
2454 ;; languages without casts.
2455 t
(c-filter-ops (c-lang-const c-operators
)
2458 (lambda (op) (elt op
0))))
2459 (c-lang-defvar c-cast-parens
(c-lang-const c-cast-parens
))
2461 (c-lang-defconst c-block-prefix-disallowed-chars
2462 "List of syntactically relevant characters that never can occur before
2463 the open brace in any construct that contains a brace block, e.g. in
2464 the \"class Foo: public Bar\" part of:
2466 class Foo: public Bar {int x();} a, *b;
2468 If parens can occur, the chars inside those aren't filtered with this
2471 '<' and '>' should be disallowed even if angle bracket arglists can
2472 occur. That since the search function needs to stop at them anyway to
2473 ensure they are given paren syntax.
2475 This is used to skip backward from the open brace to find the region
2476 in which to look for a construct like \"class\", \"enum\",
2477 \"namespace\" or whatever. That skipping should be as tight as
2478 possible for good performance."
2480 ;; Default to all chars that only occurs in nonsymbol tokens outside
2483 (c-lang-const c-nonsymbol-token-char-list
)
2484 (c-filter-ops (append (c-lang-const c-identifier-ops
)
2486 (c-lang-const c-after-id-concat-ops
))))
2491 (while (string-match "\\(\\s.\\|\\s(\\|\\s)\\)"
2493 (setq res
(cons (aref op
(match-beginning 1)) res
)
2497 ;; Allow cpp operatios (where applicable).
2498 t
(if (c-lang-const c-opt-cpp-prefix
)
2499 (set-difference (c-lang-const c-block-prefix-disallowed-chars
)
2501 (c-lang-const c-block-prefix-disallowed-chars
))
2503 ;; Allow ':' for inherit list starters.
2504 (c++ objc idl
) (set-difference (c-lang-const c-block-prefix-disallowed-chars
)
2507 ;; Allow ',' for multiple inherits.
2508 (c++ java
) (set-difference (c-lang-const c-block-prefix-disallowed-chars
)
2511 ;; Allow parentheses for anonymous inner classes in Java and class
2512 ;; initializer lists in Pike.
2513 (java pike
) (set-difference (c-lang-const c-block-prefix-disallowed-chars
)
2516 ;; Allow '"' for extern clauses (e.g. extern "C" {...}).
2517 (c c
++ objc
) (set-difference (c-lang-const c-block-prefix-disallowed-chars
)
2520 (c-lang-defconst c-block-prefix-charset
2521 ;; `c-block-prefix-disallowed-chars' as an inverted charset suitable
2522 ;; for `c-syntactic-skip-backward'.
2523 t
(c-make-bare-char-alt (c-lang-const c-block-prefix-disallowed-chars
) t
))
2524 (c-lang-defvar c-block-prefix-charset
(c-lang-const c-block-prefix-charset
))
2526 (c-lang-defconst c-type-decl-prefix-key
2527 "Regexp matching the declarator operators that might precede the
2528 identifier in a declaration, e.g. the \"*\" in \"char *argv\". This
2529 regexp should match \"(\" if parentheses are valid in declarators.
2530 The end of the first submatch is taken as the end of the operator.
2531 Identifier syntax is in effect when this is matched \(see
2532 `c-identifier-syntax-table')."
2533 t
(if (c-lang-const c-type-modifier-kwds
)
2534 (concat (regexp-opt (c-lang-const c-type-modifier-kwds
) t
) "\\>")
2535 ;; Default to a regexp that never matches.
2537 ;; Check that there's no "=" afterwards to avoid matching tokens
2539 (c objc
) (concat "\\("
2542 (c-lang-const c-type-decl-prefix-key
)
2549 ;; If this matches there's special treatment in
2550 ;; `c-font-lock-declarators' and
2551 ;; `c-font-lock-declarations' that check for a
2552 ;; complete name followed by ":: *".
2553 (c-lang-const c-identifier-start
)
2556 (c-lang-const c-type-decl-prefix-key
)
2559 pike
"\\(\\*\\)\\([^=]\\|$\\)")
2560 (c-lang-defvar c-type-decl-prefix-key
(c-lang-const c-type-decl-prefix-key
)
2563 (c-lang-defconst c-type-decl-suffix-key
2564 "Regexp matching the declarator operators that might follow after the
2565 identifier in a declaration, e.g. the \"[\" in \"char argv[]\". This
2566 regexp should match \")\" if parentheses are valid in declarators. If
2567 it matches an open paren of some kind, the type declaration check
2568 continues at the corresponding close paren, otherwise the end of the
2569 first submatch is taken as the end of the operator. Identifier syntax
2570 is in effect when this is matched (see `c-identifier-syntax-table')."
2571 ;; Default to a regexp that matches `c-type-modifier-kwds' and a
2572 ;; function argument list parenthesis.
2573 t
(if (c-lang-const c-type-modifier-kwds
)
2575 (regexp-opt (c-lang-const c-type-modifier-kwds
) t
) "\\>"
2578 (c c
++ objc
) (concat
2581 (if (c-lang-const c-type-modifier-kwds
)
2584 ;; "throw" in `c-type-modifier-kwds' is followed
2585 ;; by a parenthesis list, but no extra measures
2586 ;; are necessary to handle that.
2587 (regexp-opt (c-lang-const c-type-modifier-kwds
) t
)
2591 (java idl
) "\\([\[\(]\\)")
2592 (c-lang-defvar c-type-decl-suffix-key
(c-lang-const c-type-decl-suffix-key
)
2595 (c-lang-defconst c-after-suffixed-type-decl-key
2596 "This regexp is matched after a declarator expression where
2597 `c-type-decl-suffix-key' has matched. If it matches then the
2598 construct is taken as a declaration. It's typically used to match the
2599 beginning of a function body or whatever might occur after the
2600 function header in a function declaration or definition. It's
2601 undefined whether identifier syntax (see `c-identifier-syntax-table')
2602 is in effect or not.
2604 Note that it's used in cases like after \"foo (bar)\" so it should
2605 only match when it's certain that it's a declaration, e.g \"{\" but
2606 not \",\" or \";\"."
2608 ;; If K&R style declarations should be recognized then one could
2609 ;; consider to match the start of any symbol since we want to match
2610 ;; the start of the first declaration in the "K&R region". That
2611 ;; could however produce false matches on code like "FOO(bar) x"
2612 ;; where FOO is a cpp macro, so it's better to leave it out and rely
2613 ;; on the other heuristics in that case.
2614 t
(if (c-lang-const c-postfix-spec-kwds
)
2615 ;; Add on the keywords in `c-postfix-spec-kwds'.
2616 (concat (c-lang-const c-after-suffixed-type-decl-key
)
2618 (c-make-keywords-re t
(c-lang-const c-postfix-spec-kwds
)))
2619 (c-lang-const c-after-suffixed-type-decl-key
))
2620 ;; Also match the colon that starts a base class initializer list in
2621 ;; C++. That can be confused with a function call before the colon
2622 ;; in a ? : operator, but we count on that `c-decl-prefix-re' won't
2623 ;; match before such a thing (as a declaration-level construct;
2624 ;; matches inside arglist contexts are already excluded).
2626 (c-lang-defvar c-after-suffixed-type-decl-key
2627 (c-lang-const c-after-suffixed-type-decl-key
)
2630 (c-lang-defconst c-after-suffixed-type-maybe-decl-key
2631 ;; Regexp that in addition to `c-after-suffixed-type-decl-key'
2632 ;; matches ";" and ",".
2633 t
(concat "\\(" (c-lang-const c-after-suffixed-type-decl-key
) "\\)"
2635 (c-lang-defvar c-after-suffixed-type-maybe-decl-key
2636 (c-lang-const c-after-suffixed-type-maybe-decl-key
))
2638 (c-lang-defconst c-opt-type-concat-key
2639 "Regexp matching operators that concatenate types, e.g. the \"|\" in
2640 \"int|string\" in Pike. The end of the first submatch is taken as the
2641 end of the operator. nil in languages without such operators. It's
2642 undefined whether identifier syntax (see `c-identifier-syntax-table')
2643 is in effect or not."
2645 pike
"\\([|.&]\\)\\($\\|[^|.&]\\)")
2646 (c-lang-defvar c-opt-type-concat-key
(c-lang-const c-opt-type-concat-key
)
2649 (c-lang-defconst c-opt-type-suffix-key
2650 "Regexp matching operators that might follow after a type, or nil in
2651 languages that don't have such operators. The end of the first
2652 submatch is taken as the end of the operator. This should not match
2653 things like C++ template arglists if `c-recognize-<>-arglists' is set.
2654 It's undefined whether identifier syntax (see `c-identifier-syntax-table')
2655 is in effect or not."
2657 (c c
++ objc pike
) "\\(\\.\\.\\.\\)"
2658 java
(concat "\\(\\[" (c-lang-const c-simple-ws
) "*\\]\\)"))
2659 (c-lang-defvar c-opt-type-suffix-key
(c-lang-const c-opt-type-suffix-key
))
2661 (c-lang-defvar c-known-type-key
2662 ;; Regexp matching the known type identifiers. This is initialized
2663 ;; from the type keywords and `*-font-lock-extra-types'. The first
2664 ;; submatch is the one that matches the type. Note that this regexp
2665 ;; assumes that symbol constituents like '_' and '$' have word
2668 (when (boundp (c-mode-symbol "font-lock-extra-types"))
2669 (c-mode-var "font-lock-extra-types")))
2672 (mapcar (lambda (re)
2673 (when (string-match "[][.*+?^$\\]" re
)
2678 (mapcar (lambda (re)
2679 (unless (string-match "[][.*+?^$\\]" re
)
2684 (append (list (c-make-keywords-re nil
2685 (append (c-lang-const c-primitive-type-kwds
)
2691 (c-lang-defconst c-special-brace-lists
2692 "List of open- and close-chars that makes up a pike-style brace list,
2693 i.e. for a ([Â ]) list there should be a cons (?\\[ . ?\\]) in this
2696 pike
'((?
{ . ?
}) (?\
[ . ?\
]) (?
< . ?
>)))
2697 (c-lang-defvar c-special-brace-lists
(c-lang-const c-special-brace-lists
))
2699 (c-lang-defconst c-recognize-knr-p
2700 "Non-nil means K&R style argument declarations are valid."
2703 (c-lang-defvar c-recognize-knr-p
(c-lang-const c-recognize-knr-p
))
2705 (c-lang-defconst c-recognize-typeless-decls
2706 "Non-nil means function declarations without return type should be
2707 recognized. That can introduce an ambiguity with parenthesized macro
2708 calls before a brace block. This setting does not affect declarations
2709 that are preceded by a declaration starting keyword, so
2710 e.g. `c-typeless-decl-kwds' may still be used when it's set to nil."
2713 (c-lang-defvar c-recognize-typeless-decls
2714 (c-lang-const c-recognize-typeless-decls
))
2716 (c-lang-defconst c-recognize-
<>-arglists
2717 "Non-nil means C++ style template arglists should be handled. More
2718 specifically, this means a comma separated list of types or
2719 expressions surrounded by \"<\" and \">\". It's always preceded by an
2720 identifier or one of the keywords on `c-<>-type-kwds' or
2721 `c-<>-arglist-kwds'. If there's an identifier before then the whole
2722 expression is considered to be a type."
2723 t
(or (consp (c-lang-const c-
<>-type-kwds
))
2724 (consp (c-lang-const c-
<>-arglist-kwds
))))
2725 (c-lang-defvar c-recognize-
<>-arglists
(c-lang-const c-recognize-
<>-arglists
))
2727 (c-lang-defconst c-recognize-paren-inits
2728 "Non-nil means that parenthesis style initializers exist,
2729 i.e. constructs like
2733 in addition to the more classic
2738 (c-lang-defvar c-recognize-paren-inits
(c-lang-const c-recognize-paren-inits
))
2740 (c-lang-defconst c-recognize-paren-inexpr-blocks
2741 "Non-nil to recognize gcc style in-expression blocks,
2742 i.e. compound statements surrounded by parentheses inside expressions."
2745 (c-lang-defvar c-recognize-paren-inexpr-blocks
2746 (c-lang-const c-recognize-paren-inexpr-blocks
))
2748 (c-lang-defconst c-opt-
<>-arglist-start
2749 ;; Regexp matching the start of angle bracket arglists in languages
2750 ;; where `c-recognize-<>-arglists' is set. Does not exclude
2751 ;; keywords outside `c-<>-arglist-kwds'. The first submatch is
2752 ;; assumed to surround the preceding symbol. The whole match is
2753 ;; assumed to end directly after the opening "<".
2754 t
(if (c-lang-const c-recognize-
<>-arglists
)
2756 (c-lang-const c-symbol-key
)
2758 (c-lang-const c-syntactic-ws
)
2760 (c-lang-defvar c-opt-
<>-arglist-start
(c-lang-const c-opt-
<>-arglist-start
))
2762 (c-lang-defconst c-opt-
<>-arglist-start-in-paren
2763 ;; Regexp that in addition to `c-opt-<>-arglist-start' matches close
2764 ;; parens. The first submatch is assumed to surround
2765 ;; `c-opt-<>-arglist-start'.
2766 t
(if (c-lang-const c-opt-
<>-arglist-start
)
2768 (c-lang-const c-opt-
<>-arglist-start
)
2770 (c-lang-defvar c-opt-
<>-arglist-start-in-paren
2771 (c-lang-const c-opt-
<>-arglist-start-in-paren
))
2773 (c-lang-defconst c-opt-postfix-decl-spec-key
2774 ;; Regexp matching the beginning of a declaration specifier in the
2775 ;; region between the header and the body of a declaration.
2777 ;; TODO: This is currently not used uniformly; c++-mode and
2778 ;; java-mode each have their own ways of using it.
2781 (c-lang-const c-simple-ws
) "*"
2782 "\\(virtual" (c-lang-const c-simple-ws
) "+\\)?\\("
2783 (c-make-keywords-re nil
(c-lang-const c-protection-kwds
))
2784 "\\)" (c-lang-const c-simple-ws
) "+"
2785 "\\(" (c-lang-const c-symbol-key
) "\\)")
2786 java
(c-make-keywords-re t
(c-lang-const c-postfix-spec-kwds
)))
2787 (c-lang-defvar c-opt-postfix-decl-spec-key
2788 (c-lang-const c-opt-postfix-decl-spec-key
))
2790 (c-lang-defconst c-recognize-colon-labels
2791 "Non-nil if generic labels ending with \":\" should be recognized.
2792 That includes labels in code and access keys in classes. This does
2793 not apply to labels recognized by `c-label-kwds' and
2794 `c-opt-extra-label-key'."
2796 (c c
++ objc java pike
) t
)
2797 (c-lang-defvar c-recognize-colon-labels
2798 (c-lang-const c-recognize-colon-labels
))
2800 (c-lang-defconst c-label-prefix-re
2801 "Regexp like `c-decl-prefix-re' that matches any token that can precede
2802 a generic colon label. Not used if `c-recognize-colon-labels' is
2805 (c-lang-defvar c-label-prefix-re
2806 (c-lang-const c-label-prefix-re
))
2808 (c-lang-defconst c-nonlabel-token-key
2809 "Regexp matching things that can't occur in generic colon labels,
2810 neither in a statement nor in a declaration context. The regexp is
2811 tested at the beginning of every sexp in a suspected label,
2812 i.e. before \":\". Only used if `c-recognize-colon-labels' is set."
2814 ;; Don't allow string literals.
2816 ;; All keywords except `c-label-kwds' and `c-protection-kwds'.
2817 (c-make-keywords-re t
2818 (set-difference (c-lang-const c-keywords
)
2819 (append (c-lang-const c-label-kwds
)
2820 (c-lang-const c-protection-kwds
))
2821 :test
'string-equal
)))
2822 ;; Also check for open parens in C++, to catch member init lists in
2823 ;; constructors. We normally allow it so that macros with arguments
2825 c
++ (concat "\\s\(\\|" (c-lang-const c-nonlabel-token-key
)))
2826 (c-lang-defvar c-nonlabel-token-key
(c-lang-const c-nonlabel-token-key
))
2828 (c-lang-defconst c-opt-extra-label-key
2829 "Optional regexp matching labels.
2830 Normally, labels are detected according to `c-nonlabel-token-key',
2831 `c-decl-prefix-re' and `c-nonlabel-decl-prefix-re'. This regexp can
2832 be used if there are additional labels that aren't recognized that
2835 objc
(c-make-keywords-re t
(c-lang-const c-protection-kwds
)))
2836 (c-lang-defvar c-opt-extra-label-key
(c-lang-const c-opt-extra-label-key
))
2838 (c-lang-defconst c-opt-friend-key
2839 ;; Regexp describing friend declarations classes, or nil in
2840 ;; languages that don't have such things.
2842 ;; TODO: Ought to use `c-prefix-spec-kwds-re' or similar, and the
2843 ;; template skipping isn't done properly. This will disappear soon.
2845 c
++ (concat "friend" (c-lang-const c-simple-ws
) "+"
2848 (c-lang-const c-simple-ws
) "*"
2850 (c-lang-const c-simple-ws
) "*"
2852 (c-lang-const c-simple-ws
) "+")))
2853 (c-lang-defvar c-opt-friend-key
(c-lang-const c-opt-friend-key
))
2855 (c-lang-defconst c-opt-method-key
2856 ;; Special regexp to match the start of Objective-C methods. The
2857 ;; first submatch is assumed to end after the + or - key.
2860 ;; TODO: Ought to use a better method than anchoring on bol.
2863 (c-lang-const c-simple-ws
) "*"
2864 (concat "\\(" ; Return type.
2866 (c-lang-const c-simple-ws
) "*"
2868 "\\(" (c-lang-const c-symbol-key
) "\\)"))
2869 (c-lang-defvar c-opt-method-key
(c-lang-const c-opt-method-key
))
2871 (c-lang-defconst c-type-decl-end-used
2872 ;; Must be set in buffers where the `c-type' text property might be
2873 ;; used with the value `c-decl-end'.
2875 ;; `c-decl-end' is used to mark the ends of labels and access keys
2876 ;; to make interactive refontification work better.
2877 t
(or (c-lang-const c-recognize-colon-labels
)
2878 (and (c-lang-const c-label-kwds
) t
))
2879 ;; `c-decl-end' is used to mark the end of the @-style directives in
2882 (c-lang-defvar c-type-decl-end-used
(c-lang-const c-type-decl-end-used
))
2885 ;;; Wrap up the `c-lang-defvar' system.
2887 ;; Compile in the list of language variables that has been collected
2888 ;; with the `c-lang-defvar' and `c-lang-setvar' macros. Note that the
2889 ;; first element of each is nil.
2890 (defconst c-lang-variable-inits
(cc-eval-when-compile c-lang-variable-inits
))
2891 (defconst c-emacs-variable-inits
(cc-eval-when-compile c-emacs-variable-inits
))
2893 ;; Make the `c-lang-setvar' variables buffer local in the current buffer.
2894 ;; These are typically standard emacs variables such as `comment-start'.
2895 (defmacro c-make-emacs-variables-local
()
2897 ,@(mapcar (lambda (init)
2898 `(make-local-variable ',(car init
)))
2899 (cdr c-emacs-variable-inits
))))
2901 (defun c-make-init-lang-vars-fun (mode)
2902 "Create a function that initializes all the language dependent variables
2905 This function should be evaluated at compile time, so that the
2906 function it returns is byte compiled with all the evaluated results
2907 from the language constants. Use the `c-init-language-vars' macro to
2908 accomplish that conveniently."
2910 (if (and (not load-in-progress
)
2911 (boundp 'byte-compile-dest-file
)
2912 (stringp byte-compile-dest-file
))
2914 ;; No need to byte compile this lambda since the byte compiler is
2915 ;; smart enough to detect the `funcall' construct in the
2916 ;; `c-init-language-vars' macro below and compile it all straight
2917 ;; into the function that contains `c-init-language-vars'.
2920 ;; This let sets up the context for `c-mode-var' and similar
2921 ;; that could be in the result from `cl-macroexpand-all'.
2922 (let ((c-buffer-is-cc-mode ',mode
)
2923 current-var source-eval
)
2924 (c-make-emacs-variables-local)
2927 (if (eq c-version-sym
',c-version-sym
)
2928 (setq ,@(let ((c-buffer-is-cc-mode mode
)
2929 (c-lang-const-expansion 'immediate
))
2930 ;; `c-lang-const' will expand to the evaluated
2931 ;; constant immediately in `cl-macroexpand-all'
2935 `(current-var ',(car init
)
2936 ,(car init
) ,(cl-macroexpand-all
2938 ;; Note: The following `append' copies the
2939 ;; first argument. That list is small, so
2940 ;; this doesn't matter too much.
2941 (append (cdr c-emacs-variable-inits
)
2942 (cdr c-lang-variable-inits
)))))
2944 ;; This diagnostic message isn't useful for end
2945 ;; users, so it's disabled.
2946 ;;(unless (get ',mode 'c-has-warned-lang-consts)
2947 ;; (message ,(concat "%s compiled with CC Mode %s "
2948 ;; "but loaded with %s - evaluating "
2949 ;; "language constants from source")
2950 ;; ',mode ,c-version c-version)
2951 ;; (put ',mode 'c-has-warned-lang-consts t))
2954 (setq source-eval t
)
2955 (let ((init (append (cdr c-emacs-variable-inits
)
2956 (cdr c-lang-variable-inits
))))
2958 (setq current-var
(caar init
))
2959 (set (caar init
) (eval (cadar init
)))
2960 (setq init
(cdr init
)))))
2964 (message "Eval error in the `c-lang-defvar' or `c-lang-setvar' for `%s'%s: %S"
2968 (fallback source eval - %s compiled with CC Mode %s but loaded with %s)"
2969 ',mode
,c-version c-version
)
2972 (signal (car err
) (cdr err
)))))))
2974 ;; Being evaluated from source. Always use the dynamic method to
2975 ;; work well when `c-lang-defvar's in this file are reevaluated
2979 (let ((c-buffer-is-cc-mode ',mode
)
2980 (init (append (cdr c-emacs-variable-inits
)
2981 (cdr c-lang-variable-inits
)))
2983 (c-make-emacs-variables-local)
2987 (setq current-var
(caar init
))
2988 (set (caar init
) (eval (cadar init
)))
2989 (setq init
(cdr init
)))
2994 "Eval error in the `c-lang-defvar' or `c-lang-setver' for `%s' (source eval): %S"
2996 (signal (car err
) (cdr err
)))))))
2999 (defmacro c-init-language-vars
(mode)
3000 "Initialize all the language dependent variables for the given mode.
3001 This macro is expanded at compile time to a form tailored for the mode
3002 in question, so MODE must be a constant. Therefore MODE is not
3003 evaluated and should not be quoted."
3004 `(funcall ,(c-make-init-lang-vars-fun mode
)))
3007 (cc-provide 'cc-langs
)
3009 ;;; arch-tag: 1ab57482-cfc2-4c5b-b628-3539c3098822
3010 ;;; cc-langs.el ends here