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, 2008, 2009
5 ;; Free Software Foundation, Inc.
7 ;; Authors: 2002- Alan Mackenzie
8 ;; 1998- Martin Stjernholm
9 ;; 1992-1999 Barry A. Warsaw
11 ;; 1987 Stewart Clamen
12 ;; 1985 Richard M. Stallman
13 ;; Maintainer: bug-cc-mode@gnu.org
14 ;; Created: 22-Apr-1997 (split from cc-mode.el)
15 ;; Version: See cc-mode.el
16 ;; Keywords: c languages oop
18 ;; This file is part of GNU Emacs.
20 ;; GNU Emacs is free software: you can redistribute it and/or modify
21 ;; it under the terms of the GNU General Public License as published by
22 ;; the Free Software Foundation, either version 3 of the License, or
23 ;; (at your option) any later version.
25 ;; GNU Emacs is distributed in the hope that it will be useful,
26 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
27 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28 ;; GNU General Public License for more details.
30 ;; You should have received a copy of the GNU General Public License
31 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
35 ;; HACKERS NOTE: There's heavy macro magic here. If you need to make
36 ;; changes in this or other files containing `c-lang-defconst' but
37 ;; don't want to read through the longer discussion below then read
40 ;; o A change in a `c-lang-defconst' or `c-lang-defvar' will not take
41 ;; effect if the file containing the mode init function (typically
42 ;; cc-mode.el) is byte compiled.
43 ;; o To make changes show in font locking you need to reevaluate the
44 ;; `*-font-lock-keywords-*' constants, which normally is easiest to
45 ;; do with M-x eval-buffer in cc-fonts.el.
46 ;; o In either case it's necessary to reinitialize the mode to make
47 ;; the changes show in an existing buffer.
49 ;;; Introduction to the language dependent variable system:
51 ;; This file contains all the language dependent variables, except
52 ;; those specific for font locking which reside in cc-fonts.el. As
53 ;; far as possible, all the differences between the languages that CC
54 ;; Mode supports are described with these variables only, so that the
55 ;; code can be shared.
57 ;; The language constant system (see cc-defs.el) is used to specify
58 ;; various language dependent info at a high level, such as lists of
59 ;; keywords, and then from them generate - at compile time - the
60 ;; various regexps and other low-level structures actually employed in
61 ;; the code at runtime.
63 ;; This system is also designed to make it easy for developers of
64 ;; derived modes to customize the source constants for new language
65 ;; variants, without having to keep up with the exact regexps etc that
66 ;; are used in each CC Mode version. It's possible from an external
67 ;; package to add a new language by inheriting an existing one, and
68 ;; then change specific constants as necessary for the new language.
69 ;; The old values for those constants (and the values of all the other
70 ;; high-level constants) may be used to build the new ones, and those
71 ;; new values will in turn be used by the low-level definitions here
72 ;; to build the runtime constants appropriately for the new language
73 ;; in the current version of CC Mode.
75 ;; Like elsewhere in CC Mode, the existence of a doc string signifies
76 ;; that a language constant is part of the external API, and that it
77 ;; therefore can be used with a high confidence that it will continue
78 ;; to work with future versions of CC Mode. Even so, it's not
79 ;; unlikely that such constants will change meaning slightly as this
80 ;; system is refined further; a certain degree of dependence on the CC
81 ;; Mode version is unavoidable when hooking in at this level. Also
82 ;; note that there's still work to be done to actually use these
83 ;; constants everywhere inside CC Mode; there are still hardcoded
84 ;; values in many places in the code.
86 ;; Separate packages will also benefit from the compile time
87 ;; evaluation; the byte compiled file(s) for them will contain the
88 ;; compiled runtime constants ready for use by (the byte compiled) CC
89 ;; Mode, and the source definitions in this file don't have to be
90 ;; loaded then. However, if a byte compiled package is loaded that
91 ;; has been compiled with a different version of CC Mode than the one
92 ;; currently loaded, then the compiled-in values will be discarded and
93 ;; new ones will be built when the mode is initialized. That will
94 ;; automatically trig a load of the file(s) containing the source
95 ;; definitions (i.e. this file and/or cc-fonts.el) if necessary.
97 ;; A small example of a derived mode is available at
98 ;; <http://cc-mode.sourceforge.net/derived-mode-ex.el>. It also
99 ;; contains some useful hints for derived mode developers.
101 ;;; Using language variables:
103 ;; The `c-lang-defvar' forms in this file comprise the language
104 ;; variables that CC Mode uses. It does not work to use
105 ;; `c-lang-defvar' anywhere else (which isn't much of a limitation
106 ;; since these variables sole purpose is to interface with the CC Mode
107 ;; core functions). The values in these `c-lang-defvar's are not
108 ;; evaluated right away but instead collected to a single large `setq'
109 ;; that can be inserted for a particular language with the
110 ;; `c-init-language-vars' macro.
112 ;; This file is only required at compile time, or when not running
113 ;; from byte compiled files, or when the source definitions for the
114 ;; language constants are requested.
120 (unless (fboundp 'declare-function) (defmacro declare-function (&rest r))))
124 (if (and (boundp 'byte-compile-dest-file)
125 (stringp byte-compile-dest-file))
126 (cons (file-name-directory byte-compile-dest-file) load-path)
128 (load "cc-bytecomp" nil t)))
130 (cc-require 'cc-defs)
131 (cc-require 'cc-vars)
134 ;; This file is not always loaded. See note above.
135 (cc-external-require 'cl)
138 ;;; Setup for the `c-lang-defvar' system.
141 ;; These are used to collect the init forms from the subsequent
142 ;; `c-lang-defvar' and `c-lang-setvar'. They are used to build the
143 ;; lambda in `c-make-init-lang-vars-fun' below, and to build `defvar's
144 ;; and `make-variable-buffer-local's in cc-engine and
145 ;; `make-local-variable's in `c-init-language-vars-for'.
146 (defvar c-lang-variable-inits nil)
147 (defvar c-lang-variable-inits-tail nil)
148 (setq c-lang-variable-inits (list nil)
149 c-lang-variable-inits-tail c-lang-variable-inits)
150 (defvar c-emacs-variable-inits nil)
151 (defvar c-emacs-variable-inits-tail nil)
152 (setq c-emacs-variable-inits (list nil)
153 c-emacs-variable-inits-tail c-emacs-variable-inits))
155 (defmacro c-lang-defvar (var val &optional doc)
156 "Declares the buffer local variable VAR to get the value VAL. VAL is
157 evaluated and assigned at mode initialization. More precisely, VAL is
158 evaluated and bound to VAR when the result from the macro
159 `c-init-language-vars' is evaluated.
161 `c-lang-const' is typically used in VAL to get the right value for the
162 language being initialized, and such calls will be macro expanded to
163 the evaluated constant value at compile time."
166 (eq (car-safe val) 'c-lang-const)
169 ;; Special case: If there's no docstring and the value is a
170 ;; simple (c-lang-const foo) where foo is the same name as VAR
171 ;; then take the docstring from the language constant foo.
172 (setq doc (get (intern (symbol-name (nth 1 val)) c-lang-constants)
173 'variable-documentation)))
177 (let ((elem (assq var (cdr c-lang-variable-inits))))
179 (setcdr elem (list val doc))
180 (setcdr c-lang-variable-inits-tail (list (list var val doc)))
181 (setq c-lang-variable-inits-tail (cdr c-lang-variable-inits-tail))))
183 ;; Return the symbol, like the other def* forms.
186 (defmacro c-lang-setvar (var val)
187 "Causes the variable VAR to be made buffer local and to get set to the
188 value VAL. VAL is evaluated and assigned at mode initialization. More
189 precisely, VAL is evaluated and bound to VAR when the result from the
190 macro `c-init-language-vars' is evaluated. VAR is typically a standard
191 Emacs variable like `comment-start'.
193 `c-lang-const' is typically used in VAL to get the right value for the
194 language being initialized, and such calls will be macro expanded to
195 the evaluated constant value at compile time."
196 (let ((elem (assq var (cdr c-emacs-variable-inits))))
198 (setcdr elem (list val)) ; Maybe remove "list", sometime. 2006-07-19
199 (setcdr c-emacs-variable-inits-tail (list (list var val)))
200 (setq c-emacs-variable-inits-tail (cdr c-emacs-variable-inits-tail))))
202 ;; Return the symbol, like the other def* forms.
205 (put 'c-lang-defvar 'lisp-indent-function 'defun)
206 ; (eval-after-load "edebug" ; 2006-07-09: def-edebug-spec is now in subr.el.
208 (def-edebug-spec c-lang-defvar
209 (&define name def-form &optional stringp)) ;)
211 ;; Suppress "might not be defined at runtime" warning.
212 ;; This file is only used when compiling other cc files.
213 (declare-function delete-duplicates "cl-seq" (cl-seq &rest cl-keys))
214 (declare-function mapcan "cl-extra" (cl-func cl-seq &rest cl-rest))
215 (declare-function cl-macroexpand-all "cl-extra" (form &optional env))
218 ;; Some helper functions used when building the language constants.
220 (defun c-filter-ops (ops opgroup-filter op-filter &optional xlate)
221 ;; Extract a subset of the operators in the list OPS in a DWIM:ey
222 ;; way. The return value is a plain list of operators:
224 ;; OPS either has the structure of `c-operators', is a single
225 ;; group in `c-operators', or is a plain list of operators.
227 ;; OPGROUP-FILTER specifies how to select the operator groups. It
228 ;; can be t to choose all groups, a list of group type symbols
229 ;; (such as 'prefix) to accept, or a function which will be called
230 ;; with the group symbol for each group and should return non-nil
231 ;; if that group is to be included.
233 ;; If XLATE is given, it's a function which is called for each
234 ;; matching operator and its return value is collected instead.
235 ;; If it returns a list, the elements are spliced directly into
236 ;; the final result, which is returned as a list with duplicates
237 ;; removed using `equal'.
239 ;; `c-mode-syntax-table' for the current mode is in effect during
240 ;; the whole procedure.
241 (unless (listp (car-safe ops))
242 (setq ops (list ops)))
243 (cond ((eq opgroup-filter t)
244 (setq opgroup-filter (lambda (opgroup) t)))
245 ((not (functionp opgroup-filter))
246 (setq opgroup-filter `(lambda (opgroup)
247 (memq opgroup ',opgroup-filter)))))
248 (cond ((eq op-filter t)
249 (setq op-filter (lambda (op) t)))
251 (setq op-filter `(lambda (op)
252 (string-match ,op-filter op)))))
254 (setq xlate 'identity))
255 (c-with-syntax-table (c-lang-const c-mode-syntax-table)
257 (mapcan (lambda (opgroup)
258 (when (if (symbolp (car opgroup))
259 (when (funcall opgroup-filter (car opgroup))
260 (setq opgroup (cdr opgroup))
264 (when (funcall op-filter op)
265 (let ((res (funcall xlate op)))
266 (if (listp res) res (list res)))))
272 ;;; Various mode specific values that aren't language related.
274 (c-lang-defconst c-mode-menu
275 ;; The definition for the mode menu. The menu title is prepended to
276 ;; this before it's fed to `easy-menu-define'.
277 t `(["Comment Out Region" comment-region
278 (c-fn-region-is-active-p)]
279 ["Uncomment Region" (comment-region (region-beginning)
281 (c-fn-region-is-active-p)]
282 ["Indent Expression" c-indent-exp
283 (memq (char-after) '(?\( ?\[ ?\{))]
284 ["Indent Line or Region" c-indent-line-or-region t]
285 ["Fill Comment Paragraph" c-fill-paragraph t]
287 ["Backward Statement" c-beginning-of-statement t]
288 ["Forward Statement" c-end-of-statement t]
289 ,@(when (c-lang-const c-opt-cpp-prefix)
290 ;; Only applicable if there's a cpp preprocessor.
291 `(["Up Conditional" c-up-conditional t]
292 ["Backward Conditional" c-backward-conditional t]
293 ["Forward Conditional" c-forward-conditional t]
295 ["Macro Expand Region" c-macro-expand
296 (c-fn-region-is-active-p)]
297 ["Backslashify" c-backslash-region
298 (c-fn-region-is-active-p)]))
301 ["Syntactic indentation" c-toggle-syntactic-indentation
302 :style toggle :selected c-syntactic-indentation]
303 ["Electric mode" c-toggle-electric-state
304 :style toggle :selected c-electric-flag]
305 ["Auto newline" c-toggle-auto-newline
306 :style toggle :selected c-auto-newline]
307 ["Hungry delete" c-toggle-hungry-state
308 :style toggle :selected c-hungry-delete-key]
309 ["Subword mode" c-subword-mode
310 :style toggle :selected (and (boundp 'c-subword-mode)
316 (defun c-populate-syntax-table (table)
317 "Populate the given syntax table as necessary for a C-like language.
318 This includes setting ' and \" as string delimiters, and setting up
319 the comment syntax to handle both line style \"//\" and block style
320 \"/*\" \"*/\" comments."
322 (modify-syntax-entry ?_ "_" table)
323 (modify-syntax-entry ?\\ "\\" table)
324 (modify-syntax-entry ?+ "." table)
325 (modify-syntax-entry ?- "." table)
326 (modify-syntax-entry ?= "." table)
327 (modify-syntax-entry ?% "." table)
328 (modify-syntax-entry ?< "." table)
329 (modify-syntax-entry ?> "." table)
330 (modify-syntax-entry ?& "." table)
331 (modify-syntax-entry ?| "." table)
332 (modify-syntax-entry ?\' "\"" table)
333 (modify-syntax-entry ?\240 "." table)
335 ;; Set up block and line oriented comments. The new C
336 ;; standard mandates both comment styles even in C, so since
337 ;; all languages now require dual comments, we make this the
341 ((memq '8-bit c-emacs-features)
342 (modify-syntax-entry ?/ ". 1456" table)
343 (modify-syntax-entry ?* ". 23" table))
345 ((memq '1-bit c-emacs-features)
346 (modify-syntax-entry ?/ ". 124b" table)
347 (modify-syntax-entry ?* ". 23" table))
349 (t (error "CC Mode is incompatible with this version of Emacs")))
351 (modify-syntax-entry ?\n "> b" table)
352 ;; Give CR the same syntax as newline, for selective-display
353 (modify-syntax-entry ?\^m "> b" table))
355 (c-lang-defconst c-make-mode-syntax-table
356 "Functions that generates the mode specific syntax tables.
357 The syntax tables aren't stored directly since they're quite large."
359 (let ((table (make-syntax-table)))
360 (c-populate-syntax-table table)
361 ;; Mode specific syntaxes.
362 ,(cond ((c-major-mode-is 'objc-mode)
363 ;; Let '@' be part of symbols in ObjC to cope with
364 ;; its compiler directives as single keyword tokens.
365 ;; This is then necessary since it's assumed that
366 ;; every keyword is a single symbol.
367 `(modify-syntax-entry ?@ "_" table))
368 ((c-major-mode-is 'pike-mode)
369 `(modify-syntax-entry ?@ "." table)))
372 (c-lang-defconst c-mode-syntax-table
373 ;; The syntax tables in evaluated form. Only used temporarily when
374 ;; the constants in this file are evaluated.
375 t (funcall (c-lang-const c-make-mode-syntax-table)))
377 (c-lang-defconst c++-make-template-syntax-table
378 ;; A variant of `c++-mode-syntax-table' that defines `<' and `>' as
379 ;; parenthesis characters. Used temporarily when template argument
380 ;; lists are parsed. Note that this encourages incorrect parsing of
381 ;; templates since they might contain normal operators that uses the
382 ;; '<' and '>' characters. Therefore this syntax table might go
383 ;; away when CC Mode handles templates correctly everywhere.
386 (let ((table (funcall ,(c-lang-const c-make-mode-syntax-table))))
387 (modify-syntax-entry ?< "(>" table)
388 (modify-syntax-entry ?> ")<" table)
390 (c-lang-defvar c++-template-syntax-table
391 (and (c-lang-const c++-make-template-syntax-table)
392 (funcall (c-lang-const c++-make-template-syntax-table))))
394 (c-lang-defconst c-identifier-syntax-modifications
395 "A list that describes the modifications that should be done to the
396 mode syntax table to get a syntax table that matches all identifiers
397 and keywords as words.
399 The list is just like the one used in `font-lock-defaults': Each
400 element is a cons where the car is the character to modify and the cdr
401 the new syntax, as accepted by `modify-syntax-entry'."
402 ;; The $ character is not allowed in most languages (one exception
403 ;; is Java which allows it for legacy reasons) but we still classify
404 ;; it as an indentifier character since it's often used in various
405 ;; machine generated identifiers.
406 t '((?_ . "w") (?$ . "w"))
407 objc (append '((?@ . "w"))
408 (c-lang-const c-identifier-syntax-modifications))
410 (c-lang-defvar c-identifier-syntax-modifications
411 (c-lang-const c-identifier-syntax-modifications))
413 (c-lang-defvar c-identifier-syntax-table
414 (let ((table (copy-syntax-table (c-mode-var "mode-syntax-table")))
415 (mods c-identifier-syntax-modifications)
420 (modify-syntax-entry (car mod) (cdr mod) table))
422 "Syntax table built on the mode syntax table but additionally
423 classifies symbol constituents like '_' and '$' as word constituents,
424 so that all identifiers are recognized as words.")
426 (c-lang-defconst c-get-state-before-change-function
427 "If non-nil, a function called from c-before-change-hook.
428 Typically it will record enough state to allow
429 `c-before-font-lock-function' to extend the region to fontify,
430 and may do such things as removing text-properties which must be
433 It takes 2 parameters, the BEG and END supplied to every
434 before-change function; on entry, the buffer will have been
435 widened and match-data will have been saved; point is undefined
436 on both entry and exit; the return value is ignored.
438 When the mode is initialized, this function is called with
439 parameters \(point-min) and \(point-max)."
441 (c c++ objc) 'c-extend-region-for-CPP
442 awk 'c-awk-record-region-clear-NL)
443 (c-lang-defvar c-get-state-before-change-function
444 (c-lang-const c-get-state-before-change-function))
446 (c-lang-defconst c-before-font-lock-function
447 "If non-nil, a function called just before font locking.
448 Typically it will extend the region about to be fontified \(see
449 below) and will set `syntax-table' text properties on the region.
451 It takes 3 parameters, the BEG, END, and OLD-LEN supplied to
452 every after-change function; point is undefined on both entry and
453 exit; on entry, the buffer will have been widened and match-data
454 will have been saved; the return value is ignored.
456 The function may extend the region to be fontified by setting the
457 buffer local variables c-new-BEG and c-new-END.
459 The function is called even when font locking is disabled.
461 When the mode is initialized, this function is called with
462 parameters \(point-min), \(point-max) and <buffer size>."
464 (c c++ objc) 'c-neutralize-syntax-in-CPP
465 awk 'c-awk-extend-and-syntax-tablify-region)
466 (c-lang-defvar c-before-font-lock-function
467 (c-lang-const c-before-font-lock-function))
470 ;;; Lexer-level syntax (identifiers, tokens etc).
472 (c-lang-defconst c-symbol-start
473 "Regexp that matches the start of a symbol, i.e. any identifier or
474 keyword. It's unspecified how far it matches. Does not contain a \\|
475 operator at the top level."
476 t (concat "[" c-alpha "_]")
477 objc (concat "[" c-alpha "@]")
478 pike (concat "[" c-alpha "_`]"))
479 (c-lang-defvar c-symbol-start (c-lang-const c-symbol-start))
481 (c-lang-defconst c-symbol-chars
482 "Set of characters that can be part of a symbol.
483 This is on the form that fits inside [ ] in a regexp."
484 ;; Pike note: With the backquote identifiers this would include most
485 ;; operator chars too, but they are handled with other means instead.
486 t (concat c-alnum "_$")
487 objc (concat c-alnum "_$@"))
489 (c-lang-defconst c-symbol-key
490 "Regexp matching identifiers and keywords (with submatch 0). Assumed
491 to match if `c-symbol-start' matches on the same position."
492 t (concat (c-lang-const c-symbol-start)
493 "[" (c-lang-const c-symbol-chars) "]*")
495 ;; Use the value from C here since the operator backquote is
496 ;; covered by the other alternative.
497 (c-lang-const c-symbol-key c)
499 (c-make-keywords-re nil
500 (c-lang-const c-overloadable-operators))))
501 (c-lang-defvar c-symbol-key (c-lang-const c-symbol-key))
503 (c-lang-defconst c-symbol-key-depth
504 ;; Number of regexp grouping parens in `c-symbol-key'.
505 t (regexp-opt-depth (c-lang-const c-symbol-key)))
507 (c-lang-defconst c-nonsymbol-chars
508 "This is the set of chars that can't be part of a symbol, i.e. the
509 negation of `c-symbol-chars'."
510 t (concat "^" (c-lang-const c-symbol-chars)))
511 (c-lang-defvar c-nonsymbol-chars (c-lang-const c-nonsymbol-chars))
513 (c-lang-defconst c-nonsymbol-key
514 "Regexp that matches any character that can't be part of a symbol.
515 It's usually appended to other regexps to avoid matching a prefix.
516 It's assumed to not contain any submatchers."
517 ;; The same thing regarding Unicode identifiers applies here as to
519 t (concat "[" (c-lang-const c-nonsymbol-chars) "]"))
521 (c-lang-defconst c-identifier-ops
522 "The operators that make up fully qualified identifiers. nil in
523 languages that don't have such things. See `c-operators' for a
524 description of the format. Binary operators can concatenate symbols,
525 e.g. \"::\" in \"A::B::C\". Prefix operators can precede identifiers,
526 e.g. \"~\" in \"~A::B\". Other types of operators aren't supported.
528 This value is by default merged into `c-operators'."
530 c++ '((prefix "~" "??-" "compl")
533 ;; Java has "." to concatenate identifiers but it's also used for
534 ;; normal indexing. There's special code in the Java font lock
535 ;; rules to fontify qualified identifiers based on the standard
536 ;; naming conventions. We still define "." here to make
537 ;; `c-forward-name' move over as long names as possible which is
538 ;; necessary to e.g. handle throws clauses correctly.
539 java '((left-assoc "."))
540 idl '((left-assoc "::")
542 pike '((left-assoc "::")
546 (c-lang-defconst c-opt-identifier-concat-key
547 ;; Appendable adorned regexp matching the operators that join
548 ;; symbols to fully qualified identifiers, or nil in languages that
549 ;; don't have such things.
551 ;; This was a docstring constant in 5.30. It still works but is now
552 ;; considered internal - change `c-identifier-ops' instead.
553 t (let ((ops (c-filter-ops (c-lang-const c-identifier-ops)
554 '(left-assoc right-assoc)
557 (c-make-keywords-re 'appendable ops))))
558 (c-lang-defvar c-opt-identifier-concat-key
559 (c-lang-const c-opt-identifier-concat-key)
562 (c-lang-defconst c-opt-identifier-concat-key-depth
563 ;; Number of regexp grouping parens in `c-opt-identifier-concat-key'.
564 t (regexp-opt-depth (c-lang-const c-opt-identifier-concat-key)))
566 (c-lang-defconst c-opt-identifier-prefix-key
567 ;; Appendable adorned regexp matching operators that might precede
568 ;; an identifier and that are part of the identifier in that case.
569 ;; nil in languages without such things.
570 t (let ((ops (c-filter-ops (c-lang-const c-identifier-ops)
574 (c-make-keywords-re 'appendable ops))))
576 (c-lang-defconst c-after-id-concat-ops
577 "Operators that can occur after a binary operator on `c-identifier-ops'
578 in identifiers. nil in languages that don't have such things.
580 Operators here should also have appropriate entries in `c-operators' -
581 it's not taken care of by default."
583 ;; '~' for destructors in C++, '*' for member pointers.
585 ;; In Java we recognize '*' to deal with "foo.bar.*" that can occur
586 ;; in import declarations. (This will also match bogus things like
587 ;; "foo.*bar" but we don't bother.)
590 (c-lang-defconst c-opt-after-id-concat-key
591 ;; Regexp that must match the token after
592 ;; `c-opt-identifier-concat-key' for it to be considered an
593 ;; identifier concatenation operator (which e.g. causes the
594 ;; preceding identifier to be fontified as a reference). Assumed to
595 ;; be a string if `c-opt-identifier-concat-key' is.
597 ;; This was a docstring constant in 5.30. It still works but is now
598 ;; considered internal - change `c-after-id-concat-ops' instead.
599 t (concat (c-lang-const c-symbol-start)
600 (if (c-lang-const c-after-id-concat-ops)
601 (concat "\\|" (c-make-keywords-re 'appendable
602 (c-lang-const c-after-id-concat-ops)))
605 (c-lang-defconst c-identifier-start
606 "Regexp that matches the start of an (optionally qualified) identifier.
607 It should also match all keywords. It's unspecified how far it
609 t (concat (c-lang-const c-symbol-start)
610 (if (c-lang-const c-opt-identifier-prefix-key)
612 (c-lang-const c-opt-identifier-prefix-key))
614 (c-lang-defvar c-identifier-start (c-lang-const c-identifier-start))
616 (c-lang-defconst c-identifier-key
617 "Regexp matching a fully qualified identifier, like \"A::B::c\" in
618 C++. It does not recognize the full range of syntactic whitespace
619 between the tokens; `c-forward-name' has to be used for that. It
620 should also not match identifiers containing parenthesis groupings,
621 e.g. identifiers with template arguments such as \"A<X,Y>\" in C++."
622 ;; This regexp is more complex than strictly necessary to ensure
623 ;; that it can be matched with a minimum of backtracking.
624 t (concat (if (c-lang-const c-opt-identifier-prefix-key)
627 (c-lang-const c-opt-identifier-prefix-key)
628 (c-lang-const c-simple-ws) "*"
631 "\\(" (c-lang-const c-symbol-key) "\\)"
632 (if (c-lang-const c-opt-identifier-concat-key)
635 (c-lang-const c-simple-ws) "*"
636 (c-lang-const c-opt-identifier-concat-key)
637 (c-lang-const c-simple-ws) "*"
638 (if (c-lang-const c-after-id-concat-ops)
641 (c-make-keywords-re 'appendable
642 (c-lang-const c-after-id-concat-ops))
644 ;; For flexibility, consider the symbol match
645 ;; optional if we've hit a
646 ;; `c-after-id-concat-ops' operator. This is
647 ;; also necessary to handle the "*" that can
648 ;; end import declaration identifiers in Java.
650 (c-lang-const c-simple-ws) "*"
651 "\\(" (c-lang-const c-symbol-key) "\\)"
654 "\\(" (c-lang-const c-symbol-key) "\\)"
656 (concat "\\(" (c-lang-const c-symbol-key) "\\)"))
659 (c-lang-defvar c-identifier-key (c-lang-const c-identifier-key))
661 (c-lang-defconst c-identifier-last-sym-match
662 ;; This was a docstring constant in 5.30 but it's no longer used.
663 ;; It's only kept to avoid breaking third party code.
665 ;; Used to identify the submatch in `c-identifier-key' that
666 ;; surrounds the last symbol in the qualified identifier. It's a
667 ;; list of submatch numbers, of which the first that has a match is
668 ;; taken. It's assumed that at least one does when the regexp has
672 (c-lang-defconst c-string-escaped-newlines
673 "Set if the language support backslash escaped newlines inside string
677 (c-lang-defvar c-string-escaped-newlines
678 (c-lang-const c-string-escaped-newlines))
680 (c-lang-defconst c-multiline-string-start-char
681 "Set if the language supports multiline string literals without escaped
682 newlines. If t, all string literals are multiline. If a character,
683 only literals where the open quote is immediately preceded by that
684 literal are multiline."
687 (c-lang-defvar c-multiline-string-start-char
688 (c-lang-const c-multiline-string-start-char))
690 (c-lang-defconst c-opt-cpp-prefix
691 "Regexp matching the prefix of a cpp directive in the languages that
692 normally use that macro preprocessor. Tested at bol or at boi.
693 Assumed to not contain any submatches or \\| operators."
694 ;; TODO (ACM, 2005-04-01). Amend the following to recognise escaped NLs;
695 ;; amend all uses of c-opt-cpp-prefix which count regexp-depth.
698 (c-lang-defvar c-opt-cpp-prefix (c-lang-const c-opt-cpp-prefix))
700 (c-lang-defconst c-anchored-cpp-prefix
701 "Regexp matching the prefix of a cpp directive anchored to BOL,
702 in the languages that have a macro preprocessor."
703 t (if (c-lang-const c-opt-cpp-prefix)
704 (concat "^" (c-lang-const c-opt-cpp-prefix))))
705 (c-lang-defvar c-anchored-cpp-prefix (c-lang-const c-anchored-cpp-prefix))
707 (c-lang-defconst c-opt-cpp-start
708 "Regexp matching the prefix of a cpp directive including the directive
709 name, or nil in languages without preprocessor support. The first
710 submatch surrounds the directive name."
711 t (if (c-lang-const c-opt-cpp-prefix)
712 (concat (c-lang-const c-opt-cpp-prefix)
713 "\\([" c-alnum "]+\\)"))
714 ;; Pike, being a scripting language, recognizes hash-bangs too.
715 pike (concat (c-lang-const c-opt-cpp-prefix)
716 "\\([" c-alnum "]+\\|!\\)"))
717 (c-lang-defvar c-opt-cpp-start (c-lang-const c-opt-cpp-start))
719 (c-lang-defconst c-cpp-message-directives
720 "List of cpp directives (without the prefix) that are followed by a
722 t (if (c-lang-const c-opt-cpp-prefix)
724 (c c++ objc pike) '("error" "warning"))
726 (c-lang-defconst c-cpp-include-directives
727 "List of cpp directives (without the prefix) that are followed by a
728 file name in angle brackets or quotes."
729 t (if (c-lang-const c-opt-cpp-prefix)
731 objc '("include" "import"))
733 (c-lang-defconst c-opt-cpp-macro-define
734 "Cpp directive (without the prefix) that is followed by a macro
735 definition, or nil if the language doesn't have any."
736 t (if (c-lang-const c-opt-cpp-prefix)
739 (c-lang-defconst c-opt-cpp-macro-define-start
740 ;; Regexp matching everything up to the macro body of a cpp define, or the
741 ;; end of the logical line if there is none. Submatch 1 is the name of the
742 ;; macro. Set if c-opt-cpp-macro-define is.
743 t (if (c-lang-const c-opt-cpp-macro-define)
744 (concat (c-lang-const c-opt-cpp-prefix)
745 (c-lang-const c-opt-cpp-macro-define)
746 "[ \t]+\\(\\(\\sw\\|_\\)+\\)\\(\([^\)]*\)\\)?"
748 "\\([ \t]\\|\\\\\n\\)*")))
749 (c-lang-defvar c-opt-cpp-macro-define-start
750 (c-lang-const c-opt-cpp-macro-define-start))
752 (c-lang-defconst c-opt-cpp-macro-define-id
753 ;; Regexp matching everything up to the end of the identifier defined
755 t (if (c-lang-const c-opt-cpp-macro-define)
756 (concat (c-lang-const c-opt-cpp-prefix) ; #
757 (c-lang-const c-opt-cpp-macro-define) ; define
758 "[ \t]+\\(\\sw\\|_\\)+")))
759 (c-lang-defvar c-opt-cpp-macro-define-id
760 (c-lang-const c-opt-cpp-macro-define-id))
762 (c-lang-defconst c-cpp-expr-directives
763 "List of cpp directives (without the prefix) that are followed by an
765 t (if (c-lang-const c-opt-cpp-prefix)
768 (c-lang-defconst c-cpp-expr-functions
769 "List of functions in cpp expressions."
770 t (if (c-lang-const c-opt-cpp-prefix)
772 pike '("defined" "efun" "constant"))
774 (c-lang-defconst c-assignment-operators
775 "List of all assignment operators."
776 t '("=" "*=" "/=" "%=" "+=" "-=" ">>=" "<<=" "&=" "^=" "|=")
777 java (append (c-lang-const c-assignment-operators)
779 c++ (append (c-lang-const c-assignment-operators)
780 '("and_eq" "or_eq" "xor_eq" "??!=" "??'="))
783 (c-lang-defconst c-operators
784 "List describing all operators, along with their precedence and
785 associativity. The order in the list corresponds to the precedence of
786 the operators: The operators in each element are a group with the same
787 precedence, and the group has higher precedence than the groups in all
788 following elements. The car of each element describes the type of the
789 operator group, and the cdr is a list of the operator tokens in it.
790 The operator group types are:
792 'prefix Unary prefix operators.
793 'postfix Unary postfix operators.
795 Unary postfix operators if and only if the chars have
797 'left-assoc Binary left associative operators (i.e. a+b+c means (a+b)+c).
798 'right-assoc Binary right associative operators (i.e. a=b=c means a=(b=c)).
799 'right-assoc-sequence
800 Right associative operator that constitutes of a
801 sequence of tokens that separate expressions. All the
802 tokens in the group are in this case taken as
803 describing the sequence in one such operator, and the
804 order between them is therefore significant.
806 Operators containing a character with paren syntax are taken to match
807 with a corresponding open/close paren somewhere else. A postfix
808 operator with close paren syntax is taken to end a postfix expression
809 started somewhere earlier, rather than start a new one at point. Vice
810 versa for prefix operators with open paren syntax.
812 Note that operators like \".\" and \"->\" which in language references
813 often are described as postfix operators are considered binary here,
814 since CC Mode treats every identifier as an expression."
816 ;; There's currently no code in CC Mode that exploit all the info
817 ;; in this variable; precedence, associativity etc are present as a
818 ;; preparation for future work.
821 ,@(when (c-lang-const c-opt-cpp-prefix)
823 ,@(when (c-major-mode-is '(c-mode c++-mode))
826 ,@(when (c-major-mode-is '(c-mode c++-mode))
827 '("%:%:" "??=??=")))))
830 ,@(c-lang-const c-identifier-ops)
831 ,@(cond ((c-major-mode-is 'c++-mode)
832 `((postfix-if-paren "<" ">"))) ; Templates.
833 ((c-major-mode-is 'pike-mode)
834 `((prefix "global" "predef")))
835 ((c-major-mode-is 'java-mode)
836 `((prefix "super"))))
839 ,@(when (c-major-mode-is 'c++-mode)
840 ;; The following need special treatment.
841 `((prefix "dynamic_cast" "static_cast"
842 "reinterpret_cast" "const_cast" "typeid")))
844 ,@(unless (c-major-mode-is 'java-mode)
846 (postfix "++" "--" "[" "]" "(" ")"
847 ,@(when (c-major-mode-is '(c-mode c++-mode))
848 '("<:" ":>" "??(" "??)")))
851 (prefix "++" "--" "+" "-" "!" "~"
852 ,@(when (c-major-mode-is 'c++-mode) '("not" "compl"))
853 ,@(when (c-major-mode-is '(c-mode c++-mode))
854 '("*" "&" "sizeof" "??-"))
855 ,@(when (c-major-mode-is 'objc-mode)
856 '("@selector" "@protocol" "@encode"))
857 ;; The following need special treatment.
858 ,@(cond ((c-major-mode-is 'c++-mode)
860 ((c-major-mode-is 'java-mode)
862 ((c-major-mode-is 'pike-mode)
863 '("class" "lambda" "catch" "throw" "gauge")))
865 ,@(when (c-major-mode-is 'pike-mode)
866 '("[" "]"))) ; Type cast.
869 ,@(when (c-major-mode-is 'c++-mode)
870 `((left-assoc ".*" "->*")))
873 (left-assoc "*" "/" "%")
879 (left-assoc "<<" ">>"
880 ,@(when (c-major-mode-is 'java-mode)
884 (left-assoc "<" ">" "<=" ">="
885 ,@(when (c-major-mode-is 'java-mode)
889 (left-assoc "==" "!="
890 ,@(when (c-major-mode-is 'c++-mode) '("not_eq")))
894 ,@(when (c-major-mode-is 'c++-mode) '("bitand")))
896 ;; Bitwise exclusive or.
898 ,@(when (c-major-mode-is '(c-mode c++-mode))
900 ,@(when (c-major-mode-is 'c++-mode) '("xor")))
904 ,@(when (c-major-mode-is '(c-mode c++-mode))
906 ,@(when (c-major-mode-is 'c++-mode) '("bitor")))
910 ,@(when (c-major-mode-is 'c++-mode) '("and")))
914 ,@(when (c-major-mode-is '(c-mode c++-mode))
916 ,@(when (c-major-mode-is 'c++-mode) '("or")))
919 (right-assoc-sequence "?" ":")
922 (right-assoc ,@(c-lang-const c-assignment-operators))
925 ,@(when (c-major-mode-is 'c++-mode)
931 ;; IDL got its own definition since it has a much smaller operator
932 ;; set than the other languages.
933 idl `(;; Preprocessor.
937 ,@(c-lang-const c-identifier-ops)
941 (left-assoc "*" "/" "%")
945 (left-assoc "<<" ">>")
953 (c-lang-defconst c-operator-list
954 ;; The operators as a flat list (without duplicates).
955 t (c-filter-ops (c-lang-const c-operators) t t))
957 (c-lang-defconst c-overloadable-operators
958 "List of the operators that are overloadable, in their \"identifier
959 form\". See also `c-op-identifier-prefix'."
961 c++ '("new" "delete" ;; Can be followed by "[]" but we ignore that.
963 "^" "??'" "xor" "&" "bitand" "|" "??!" "bitor" "~" "??-" "compl"
964 "!" "=" "<" ">" "+=" "-=" "*=" "/=" "%=" "^="
965 "??'=" "xor_eq" "&=" "and_eq" "|=" "??!=" "or_eq"
966 "<<" ">>" ">>=" "<<=" "==" "!=" "not_eq" "<=" ">="
967 "&&" "and" "||" "??!??!" "or" "++" "--" "," "->*" "->"
968 "()" "[]" "<::>" "??(??)")
969 ;; These work like identifiers in Pike.
970 pike '("`+" "`-" "`&" "`|" "`^" "`<<" "`>>" "`*" "`/" "`%" "`~"
971 "`==" "`<" "`>" "`!" "`[]" "`[]=" "`->" "`->=" "`()" "``+"
972 "``-" "``&" "``|" "``^" "``<<" "``>>" "``*" "``/" "``%"
975 (c-lang-defconst c-overloadable-operators-regexp
976 ;; Regexp tested after an "operator" token in C++.
978 c++ (c-make-keywords-re nil (c-lang-const c-overloadable-operators)))
979 (c-lang-defvar c-overloadable-operators-regexp
980 (c-lang-const c-overloadable-operators-regexp))
982 (c-lang-defconst c-opt-op-identifier-prefix
983 "Regexp matching the token before the ones in
984 `c-overloadable-operators' when operators are specified in their
985 \"identifier form\". This typically matches \"operator\" in C++ where
986 operator functions are specified as e.g. \"operator +\". It's nil in
987 languages without operator functions or where the complete operator
988 identifier is listed in `c-overloadable-operators'.
990 This regexp is assumed to not match any non-operator identifier."
992 c++ (c-make-keywords-re t '("operator")))
993 (c-lang-defvar c-opt-op-identifier-prefix
994 (c-lang-const c-opt-op-identifier-prefix))
996 ;; Note: the following alias is an old name which was a mis-spelling. It has
997 ;; been corrected above and throughout cc-engine.el. It will be removed at
998 ;; some release very shortly in the future. ACM, 2006-04-14.
999 (defvaralias 'c-opt-op-identitier-prefix 'c-opt-op-identifier-prefix)
1000 (make-obsolete-variable 'c-opt-op-identitier-prefix 'c-opt-op-identifier-prefix
1001 "CC Mode 5.31.4, 2006-04-14")
1003 (c-lang-defconst c-other-op-syntax-tokens
1004 "List of the tokens made up of characters in the punctuation or
1005 parenthesis syntax classes that have uses other than as expression
1007 t '("{" "}" "(" ")" "[" "]" ";" ":" "," "=" "/*" "*/" "//")
1008 (c c++ pike) (append '("#" "##" ; Used by cpp.
1010 (c-lang-const c-other-op-syntax-tokens))
1011 (c c++) (append '("*") (c-lang-const c-other-op-syntax-tokens))
1012 c++ (append '("&" "<%" "%>" "<:" ":>" "%:" "%:%:")
1013 (c-lang-const c-other-op-syntax-tokens))
1014 objc (append '("#" "##" ; Used by cpp.
1015 "+" "-") (c-lang-const c-other-op-syntax-tokens))
1016 idl (append '("#" "##") ; Used by cpp.
1017 (c-lang-const c-other-op-syntax-tokens))
1018 pike (append '("..")
1019 (c-lang-const c-other-op-syntax-tokens)
1020 (c-lang-const c-overloadable-operators))
1021 awk '("{" "}" "(" ")" "[" "]" ";" "," "=" "/"))
1023 (c-lang-defconst c-all-op-syntax-tokens
1024 ;; List of all tokens in the punctuation and parenthesis syntax
1026 t (delete-duplicates (append (c-lang-const c-other-op-syntax-tokens)
1027 (c-lang-const c-operator-list))
1028 :test 'string-equal))
1030 (c-lang-defconst c-nonsymbol-token-char-list
1031 ;; List containing all chars not in the word, symbol or
1032 ;; syntactically irrelevant syntax classes, i.e. all punctuation,
1033 ;; parenthesis and string delimiter chars.
1034 t (c-with-syntax-table (c-lang-const c-mode-syntax-table)
1035 ;; Only go through the chars in the printable ASCII range. No
1036 ;; language so far has 8-bit or widestring operators.
1037 (let (list (char 32))
1039 (or (memq (char-syntax char) '(?w ?_ ?< ?> ?\ ))
1040 (setq list (cons (c-int-to-char char) list)))
1041 (setq char (1+ char)))
1044 (c-lang-defconst c-nonsymbol-token-regexp
1045 ;; Regexp matching all tokens in the punctuation and parenthesis
1046 ;; syntax classes. Note that this also matches ".", which can start
1048 t (c-make-keywords-re nil
1049 (c-filter-ops (c-lang-const c-all-op-syntax-tokens)
1051 "\\`\\(\\s.\\|\\s\(\\|\\s\)\\)+\\'")))
1052 (c-lang-defvar c-nonsymbol-token-regexp
1053 (c-lang-const c-nonsymbol-token-regexp))
1055 (c-lang-defconst c-assignment-op-regexp
1056 ;; Regexp matching all assignment operators and only them. The
1057 ;; beginning of the first submatch is used to detect the end of the
1058 ;; token, along with the end of the whole match.
1059 t (if (c-lang-const c-assignment-operators)
1061 ;; Need special case for "=" since it's a prefix of "==".
1064 (c-make-keywords-re nil
1065 (set-difference (c-lang-const c-assignment-operators)
1067 :test 'string-equal)))
1069 (c-lang-defvar c-assignment-op-regexp
1070 (c-lang-const c-assignment-op-regexp))
1072 (c-lang-defconst c-<>-multichar-token-regexp
1073 ;; Regexp matching all tokens containing "<" or ">" which are longer
1075 t (c-make-keywords-re nil
1076 (c-filter-ops (c-lang-const c-all-op-syntax-tokens)
1079 (c-lang-defvar c-<>-multichar-token-regexp
1080 (c-lang-const c-<>-multichar-token-regexp))
1082 (c-lang-defconst c-<-op-cont-regexp
1083 ;; Regexp matching the second and subsequent characters of all
1084 ;; multicharacter tokens that begin with "<".
1085 t (c-make-keywords-re nil
1086 (c-filter-ops (c-lang-const c-all-op-syntax-tokens)
1089 (lambda (op) (substring op 1)))))
1090 (c-lang-defvar c-<-op-cont-regexp (c-lang-const c-<-op-cont-regexp))
1092 (c-lang-defconst c->-op-cont-regexp
1093 ;; Regexp matching the second and subsequent characters of all
1094 ;; multicharacter tokens that begin with ">".
1095 t (c-make-keywords-re nil
1096 (c-filter-ops (c-lang-const c-all-op-syntax-tokens)
1099 (lambda (op) (substring op 1)))))
1100 (c-lang-defvar c->-op-cont-regexp (c-lang-const c->-op-cont-regexp))
1102 (c-lang-defconst c-stmt-delim-chars
1103 ;; The characters that should be considered to bound statements. To
1104 ;; optimize `c-crosses-statement-barrier-p' somewhat, it's assumed to
1105 ;; begin with "^" to negate the set. If ? : operators should be
1106 ;; detected then the string must end with "?:".
1108 awk "^;{}#\n\r?:") ; The newline chars gets special treatment.
1109 (c-lang-defvar c-stmt-delim-chars (c-lang-const c-stmt-delim-chars))
1111 (c-lang-defconst c-stmt-delim-chars-with-comma
1112 ;; Variant of `c-stmt-delim-chars' that additionally contains ','.
1114 awk "^;,{}\n\r?:") ; The newline chars gets special treatment.
1115 (c-lang-defvar c-stmt-delim-chars-with-comma
1116 (c-lang-const c-stmt-delim-chars-with-comma))
1119 ;;; Syntactic whitespace.
1121 (c-lang-defconst c-simple-ws
1122 "Regexp matching an ordinary whitespace character.
1123 Does not contain a \\| operator at the top level."
1124 ;; "\\s " is not enough since it doesn't match line breaks.
1125 t "\\(\\s \\|[\n\r]\\)")
1127 (c-lang-defconst c-simple-ws-depth
1128 ;; Number of regexp grouping parens in `c-simple-ws'.
1129 t (regexp-opt-depth (c-lang-const c-simple-ws)))
1131 (c-lang-defconst c-line-comment-starter
1132 "String that starts line comments, or nil if such don't exist.
1133 Line comments are always terminated by newlines. At least one of
1134 `c-block-comment-starter' and this one is assumed to be set.
1136 Note that it's currently not enough to set this to support a new
1137 comment style. Other stuff like the syntax table must also be set up
1141 (c-lang-defvar c-line-comment-starter (c-lang-const c-line-comment-starter))
1143 (c-lang-defconst c-block-comment-starter
1144 "String that starts block comments, or nil if such don't exist.
1145 Block comments are ended by `c-block-comment-ender', which is assumed
1146 to be set if this is. At least one of `c-line-comment-starter' and
1147 this one is assumed to be set.
1149 Note that it's currently not enough to set this to support a new
1150 comment style. Other stuff like the syntax table must also be set up
1155 (c-lang-defconst c-block-comment-ender
1156 "String that ends block comments, or nil if such don't exist.
1158 Note that it's currently not enough to set this to support a new
1159 comment style. Other stuff like the syntax table must also be set up
1164 (c-lang-defconst c-comment-start-regexp
1165 ;; Regexp to match the start of any type of comment.
1166 t (let ((re (c-make-keywords-re nil
1167 (list (c-lang-const c-line-comment-starter)
1168 (c-lang-const c-block-comment-starter)))))
1169 (if (memq 'gen-comment-delim c-emacs-features)
1170 (concat re "\\|\\s!")
1172 (c-lang-defvar c-comment-start-regexp (c-lang-const c-comment-start-regexp))
1174 ;;;; Added by ACM, 2003/9/18.
1175 (c-lang-defconst c-block-comment-start-regexp
1176 ;; Regexp which matches the start of a block comment (if such exists in the
1178 t (if (c-lang-const c-block-comment-starter)
1179 (regexp-quote (c-lang-const c-block-comment-starter))
1181 (c-lang-defvar c-block-comment-start-regexp
1182 (c-lang-const c-block-comment-start-regexp))
1184 (c-lang-defconst c-literal-start-regexp
1185 ;; Regexp to match the start of comments and string literals.
1186 t (concat (c-lang-const c-comment-start-regexp)
1188 (if (memq 'gen-string-delim c-emacs-features)
1191 (c-lang-defvar c-literal-start-regexp (c-lang-const c-literal-start-regexp))
1193 (c-lang-defconst c-doc-comment-start-regexp
1194 "Regexp to match the start of documentation comments."
1196 ;; From font-lock.el: `doxygen' uses /*! while others use /**.
1197 (c c++ objc) "/\\*[*!]"
1200 (c-lang-defvar c-doc-comment-start-regexp
1201 (c-lang-const c-doc-comment-start-regexp))
1203 (c-lang-defconst comment-start
1204 "String that starts comments inserted with M-; etc.
1205 `comment-start' is initialized from this."
1206 ;; Default: Prefer line comments to block comments, and pad with a space.
1207 t (concat (or (c-lang-const c-line-comment-starter)
1208 (c-lang-const c-block-comment-starter))
1210 ;; In C we still default to the block comment style since line
1211 ;; comments aren't entirely portable.
1213 (c-lang-setvar comment-start (c-lang-const comment-start))
1215 (c-lang-defconst comment-end
1216 "String that ends comments inserted with M-; etc.
1217 `comment-end' is initialized from this."
1218 ;; Default: Use block comment style if comment-start uses block
1219 ;; comments, and pad with a space in that case.
1220 t (if (string-match (concat "\\`\\("
1221 (c-lang-const c-block-comment-start-regexp)
1223 (c-lang-const comment-start))
1224 (concat " " (c-lang-const c-block-comment-ender))
1226 (c-lang-setvar comment-end (c-lang-const comment-end))
1228 (c-lang-defconst comment-start-skip
1229 "Regexp to match the start of a comment plus everything up to its body.
1230 `comment-start-skip' is initialized from this."
1231 ;; Default: Allow the last char of the comment starter(s) to be
1232 ;; repeated, then allow any amount of horizontal whitespace.
1235 (mapcar (lambda (cs)
1237 (concat (regexp-quote cs) "+")))
1238 (list (c-lang-const c-line-comment-starter)
1239 (c-lang-const c-block-comment-starter)))
1242 (c-lang-setvar comment-start-skip (c-lang-const comment-start-skip))
1244 (c-lang-defconst c-syntactic-ws-start
1245 ;; Regexp matching any sequence that can start syntactic whitespace.
1246 ;; The only uncertain case is '#' when there are cpp directives.
1248 (c-make-keywords-re nil
1249 (append (list (c-lang-const c-line-comment-starter)
1250 (c-lang-const c-block-comment-starter)
1251 (when (c-lang-const c-opt-cpp-prefix)
1255 (when (memq 'gen-comment-delim c-emacs-features)
1257 (c-lang-defvar c-syntactic-ws-start (c-lang-const c-syntactic-ws-start))
1259 (c-lang-defconst c-syntactic-ws-end
1260 ;; Regexp matching any single character that might end syntactic whitespace.
1262 (c-make-keywords-re nil
1263 (append (when (c-lang-const c-block-comment-ender)
1266 (elt (c-lang-const c-block-comment-ender)
1268 (c-lang-const c-block-comment-ender)))))))
1270 (when (memq 'gen-comment-delim c-emacs-features)
1272 (c-lang-defvar c-syntactic-ws-end (c-lang-const c-syntactic-ws-end))
1274 (c-lang-defconst c-unterminated-block-comment-regexp
1275 ;; Regexp matching an unterminated block comment that doesn't
1276 ;; contain line breaks, or nil in languages without block comments.
1277 ;; Does not contain a \| operator at the top level.
1278 t (when (c-lang-const c-block-comment-starter)
1280 (regexp-quote (c-lang-const c-block-comment-starter))
1281 ;; It's messy to cook together a regexp that matches anything
1282 ;; but c-block-comment-ender.
1283 (let ((end (c-lang-const c-block-comment-ender)))
1284 (cond ((= (length end) 1)
1285 (concat "[^" end "\n\r]*"))
1287 (concat "[^" (substring end 0 1) "\n\r]*"
1289 (regexp-quote (substring end 0 1)) "+"
1291 ;; The quoting rules inside char classes are silly. :P
1292 (cond ((= (elt end 0) (elt end 1))
1293 (concat (substring end 0 1) "\n\r"))
1294 ((= (elt end 1) ?\])
1295 (concat (substring end 1 2) "\n\r"
1296 (substring end 0 1)))
1298 (concat (substring end 0 1) "\n\r"
1299 (substring end 1 2))))
1301 "[^" (substring end 0 1) "\n\r]*"
1304 (error "Can't handle a block comment ender of length %s"
1307 (c-lang-defconst c-block-comment-regexp
1308 ;; Regexp matching a block comment that doesn't contain line breaks,
1309 ;; or nil in languages without block comments. The reason we don't
1310 ;; allow line breaks is to avoid going very far and risk running out
1311 ;; of regexp stack; this regexp is intended to handle only short
1312 ;; comments that might be put in the middle of limited constructs
1313 ;; like declarations. Does not contain a \| operator at the top
1315 t (when (c-lang-const c-unterminated-block-comment-regexp)
1317 (c-lang-const c-unterminated-block-comment-regexp)
1318 (let ((end (c-lang-const c-block-comment-ender)))
1319 (cond ((= (length end) 1)
1322 (concat (regexp-quote (substring end 0 1)) "+"
1323 (regexp-quote (substring end 1 2))))
1325 (error "Can't handle a block comment ender of length %s"
1328 (c-lang-defconst c-nonwhite-syntactic-ws
1329 ;; Regexp matching a piece of syntactic whitespace that isn't a
1330 ;; sequence of simple whitespace characters. As opposed to
1331 ;; `c-(forward|backward)-syntactic-ws', this doesn't regard cpp
1332 ;; directives as syntactic whitespace.
1333 t (c-concat-separated
1334 (list (when (c-lang-const c-line-comment-starter)
1335 (concat (regexp-quote (c-lang-const c-line-comment-starter))
1337 (c-lang-const c-block-comment-regexp)
1339 (when (memq 'gen-comment-delim c-emacs-features)
1343 (c-lang-defconst c-syntactic-ws
1344 ;; Regexp matching syntactic whitespace, including possibly the
1345 ;; empty string. As opposed to `c-(forward|backward)-syntactic-ws',
1346 ;; this doesn't regard cpp directives as syntactic whitespace. Does
1347 ;; not contain a \| operator at the top level.
1348 t (concat (c-lang-const c-simple-ws) "*"
1350 (concat "\\(" (c-lang-const c-nonwhite-syntactic-ws) "\\)"
1351 (c-lang-const c-simple-ws) "*")
1354 (c-lang-defconst c-syntactic-ws-depth
1355 ;; Number of regexp grouping parens in `c-syntactic-ws'.
1356 t (regexp-opt-depth (c-lang-const c-syntactic-ws)))
1358 (c-lang-defconst c-nonempty-syntactic-ws
1359 ;; Regexp matching syntactic whitespace, which is at least one
1360 ;; character long. As opposed to `c-(forward|backward)-syntactic-ws',
1361 ;; this doesn't regard cpp directives as syntactic whitespace. Does
1362 ;; not contain a \| operator at the top level.
1364 (c-lang-const c-simple-ws)
1366 (c-lang-const c-nonwhite-syntactic-ws)
1369 (c-lang-defconst c-nonempty-syntactic-ws-depth
1370 ;; Number of regexp grouping parens in `c-nonempty-syntactic-ws'.
1371 t (regexp-opt-depth (c-lang-const c-nonempty-syntactic-ws)))
1373 (c-lang-defconst c-single-line-syntactic-ws
1374 ;; Regexp matching syntactic whitespace without any line breaks. As
1375 ;; opposed to `c-(forward|backward)-syntactic-ws', this doesn't
1376 ;; regard cpp directives as syntactic whitespace. Does not contain
1377 ;; a \| operator at the top level.
1378 t (if (c-lang-const c-block-comment-regexp)
1380 (c-lang-const c-block-comment-regexp)
1384 (c-lang-defconst c-single-line-syntactic-ws-depth
1385 ;; Number of regexp grouping parens in `c-single-line-syntactic-ws'.
1386 t (regexp-opt-depth (c-lang-const c-single-line-syntactic-ws)))
1388 (c-lang-defconst c-syntactic-eol
1389 ;; Regexp that matches when there is no syntactically significant
1390 ;; text before eol. Macros are regarded as syntactically
1391 ;; significant text here.
1392 t (concat (c-lang-const c-single-line-syntactic-ws)
1393 ;; Match eol (possibly inside a block comment or preceded
1394 ;; by a line continuation backslash), or the beginning of a
1395 ;; line comment. Note: This has to be modified for awk
1396 ;; where line comments start with '#'.
1399 (list (when (c-lang-const c-line-comment-starter)
1400 (regexp-quote (c-lang-const c-line-comment-starter)))
1401 (when (c-lang-const c-unterminated-block-comment-regexp)
1402 (concat (c-lang-const c-unterminated-block-comment-regexp)
1408 (c-lang-defvar c-syntactic-eol (c-lang-const c-syntactic-eol))
1411 ;;; Syntactic analysis ("virtual semicolons") for line-oriented languages (AWK).
1412 (c-lang-defconst c-at-vsemi-p-fn
1413 "Contains a function \"Is there a virtual semicolon at POS or point?\".
1414 Such a function takes one optional parameter, a buffer position (defaults to
1415 point), and returns nil or t. This variable contains nil for languages which
1416 don't have EOL terminated statements. "
1418 awk 'c-awk-at-vsemi-p)
1419 (c-lang-defvar c-at-vsemi-p-fn (c-lang-const c-at-vsemi-p-fn))
1421 (c-lang-defconst c-vsemi-status-unknown-p-fn
1422 "Contains a function \"are we unsure whether there is a virtual semicolon on this line?\".
1423 The (admittedly kludgey) purpose of such a function is to prevent an infinite
1424 recursion in c-beginning-of-statement-1 when point starts at a `while' token.
1425 The function MUST NOT UNDER ANY CIRCUMSTANCES call c-beginning-of-statement-1,
1426 even indirectly. This variable contains nil for languages which don't have
1427 EOL terminated statements."
1429 awk 'c-awk-vsemi-status-unknown-p)
1430 (c-lang-defvar c-vsemi-status-unknown-p-fn
1431 (c-lang-const c-vsemi-status-unknown-p-fn))
1436 ;; The Emacs variables beginning-of-defun-function and
1437 ;; end-of-defun-function will be set so that commands like
1438 ;; `mark-defun' and `narrow-to-defun' work right. The key sequences
1439 ;; C-M-a and C-M-e are, however, bound directly to the CC Mode
1440 ;; functions, allowing optimisation for large n.
1441 (c-lang-defconst beginning-of-defun-function
1442 "Function to which beginning-of-defun-function will be set."
1443 t 'c-beginning-of-defun
1444 awk 'c-awk-beginning-of-defun)
1445 (c-lang-setvar beginning-of-defun-function
1446 (c-lang-const beginning-of-defun-function))
1448 (c-lang-defconst end-of-defun-function
1449 "Function to which end-of-defun-function will be set."
1451 awk 'c-awk-end-of-defun)
1452 (c-lang-setvar end-of-defun-function (c-lang-const end-of-defun-function))
1454 ;;; In-comment text handling.
1456 (c-lang-defconst c-paragraph-start
1457 "Regexp to append to `paragraph-start'."
1459 java "\\(@[a-zA-Z]+\\>\\|$\\)" ; For Javadoc.
1460 pike "\\(@[a-zA-Z_-]+\\>\\([^{]\\|$\\)\\|$\\)") ; For Pike refdoc.
1461 (c-lang-defvar c-paragraph-start (c-lang-const c-paragraph-start))
1463 (c-lang-defconst c-paragraph-separate
1464 "Regexp to append to `paragraph-separate'."
1466 pike (c-lang-const c-paragraph-start))
1467 (c-lang-defvar c-paragraph-separate (c-lang-const c-paragraph-separate))
1472 ;; Note: All and only all language constants containing keyword lists
1473 ;; should end with "-kwds"; they're automatically collected into the
1474 ;; `c-kwds-lang-consts' list below and used to build `c-keywords' etc.
1476 (c-lang-defconst c-primitive-type-kwds
1477 "Primitive type keywords. As opposed to the other keyword lists, the
1478 keywords listed here are fontified with the type face instead of the
1481 If any of these also are on `c-type-list-kwds', `c-ref-list-kwds',
1482 `c-colon-type-list-kwds', `c-paren-nontype-kwds', `c-paren-type-kwds',
1483 `c-<>-type-kwds', or `c-<>-arglist-kwds' then the associated clauses
1486 Do not try to modify this list for end user customizations; the
1487 `*-font-lock-extra-types' variable, where `*' is the mode prefix, is
1488 the appropriate place for that."
1489 t '("char" "double" "float" "int" "long" "short" "signed"
1492 '("_Bool" "_Complex" "_Imaginary") ; Conditionally defined in C99.
1493 (c-lang-const c-primitive-type-kwds))
1496 (c-lang-const c-primitive-type-kwds))
1497 ;; Objective-C extends C, but probably not the new stuff in C99.
1499 '("id" "Class" "SEL" "IMP" "BOOL")
1500 (c-lang-const c-primitive-type-kwds))
1501 java '("boolean" "byte" "char" "double" "float" "int" "long" "short" "void")
1502 idl '("Object" "ValueBase" "any" "boolean" "char" "double" "fixed" "float"
1503 "long" "octet" "sequence" "short" "string" "void" "wchar" "wstring"
1506 ;; The following can't really end a type, but we have to specify them
1507 ;; here due to the assumption in `c-primitive-type-prefix-kwds'. It
1508 ;; doesn't matter that much.
1509 "unsigned" "strong")
1510 pike '(;; this_program isn't really a keyword, but it's practically
1511 ;; used as a builtin type.
1512 "array" "float" "function" "int" "mapping" "mixed" "multiset"
1513 "object" "program" "string" "this_program" "void"))
1515 (c-lang-defconst c-primitive-type-key
1516 ;; An adorned regexp that matches `c-primitive-type-kwds'.
1517 t (c-make-keywords-re t (c-lang-const c-primitive-type-kwds)))
1518 (c-lang-defvar c-primitive-type-key (c-lang-const c-primitive-type-key))
1520 (c-lang-defconst c-primitive-type-prefix-kwds
1521 "Keywords that might act as prefixes for primitive types. Assumed to
1522 be a subset of `c-primitive-type-kwds'."
1524 (c c++) '("long" "short" "signed" "unsigned")
1525 idl '("long" "unsigned"
1529 (c-lang-defconst c-type-prefix-kwds
1530 "Keywords where the following name - if any - is a type name, and
1531 where the keyword together with the symbol works as a type in
1534 Note that an alternative if the second part doesn't hold is
1535 `c-type-list-kwds'. Keywords on this list are typically also present
1536 on one of the `*-decl-kwds' lists."
1538 c '("struct" "union" "enum")
1539 c++ (append '("class" "typename")
1540 (c-lang-const c-type-prefix-kwds c)))
1542 (c-lang-defconst c-type-prefix-key
1543 ;; Adorned regexp matching `c-type-prefix-kwds'.
1544 t (c-make-keywords-re t (c-lang-const c-type-prefix-kwds)))
1545 (c-lang-defvar c-type-prefix-key (c-lang-const c-type-prefix-key))
1547 (c-lang-defconst c-type-modifier-kwds
1548 "Type modifier keywords. These can occur almost anywhere in types
1549 but they don't build a type of themselves. Unlike the keywords on
1550 `c-primitive-type-kwds', they are fontified with the keyword face and
1553 c '("const" "restrict" "volatile")
1554 c++ '("const" "volatile" "throw")
1555 objc '("const" "volatile"))
1557 (c-lang-defconst c-opt-type-modifier-key
1558 ;; Adorned regexp matching `c-type-modifier-kwds', or nil in
1559 ;; languages without such keywords.
1560 t (and (c-lang-const c-type-modifier-kwds)
1561 (c-make-keywords-re t (c-lang-const c-type-modifier-kwds))))
1562 (c-lang-defvar c-opt-type-modifier-key (c-lang-const c-opt-type-modifier-key))
1564 (c-lang-defconst c-opt-type-component-key
1565 ;; An adorned regexp that matches `c-primitive-type-prefix-kwds' and
1566 ;; `c-type-modifier-kwds', or nil in languages without any of them.
1567 t (and (or (c-lang-const c-primitive-type-prefix-kwds)
1568 (c-lang-const c-type-modifier-kwds))
1569 (c-make-keywords-re t
1570 (append (c-lang-const c-primitive-type-prefix-kwds)
1571 (c-lang-const c-type-modifier-kwds)))))
1572 (c-lang-defvar c-opt-type-component-key
1573 (c-lang-const c-opt-type-component-key))
1575 (c-lang-defconst c-type-start-kwds
1576 ;; All keywords that can start a type (i.e. are either a type prefix
1577 ;; or a complete type).
1578 t (delete-duplicates (append (c-lang-const c-primitive-type-kwds)
1579 (c-lang-const c-type-prefix-kwds)
1580 (c-lang-const c-type-modifier-kwds))
1581 :test 'string-equal))
1583 (c-lang-defconst c-class-decl-kwds
1584 "Keywords introducing declarations where the following block (if any)
1585 contains another declaration level that should be considered a class.
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 Note that presence on this list does not automatically treat the
1593 following identifier as a type; the keyword must also be present on
1594 `c-type-prefix-kwds' or `c-type-list-kwds' to accomplish that."
1596 c '("struct" "union")
1597 c++ '("class" "struct" "union")
1598 objc '("struct" "union"
1599 "@interface" "@implementation" "@protocol")
1600 java '("class" "interface")
1601 idl '("component" "eventtype" "exception" "home" "interface" "struct"
1604 "storagehome" "storagetype"
1606 "catalog" "executor" "manages" "segment")
1609 (c-lang-defconst c-class-key
1610 ;; Regexp matching the start of a class.
1611 t (c-make-keywords-re t (c-lang-const c-class-decl-kwds)))
1612 (c-lang-defvar c-class-key (c-lang-const c-class-key))
1614 (c-lang-defconst c-brace-list-decl-kwds
1615 "Keywords introducing declarations where the following block (if
1616 any) is a brace list.
1618 If any of these also are on `c-type-list-kwds', `c-ref-list-kwds',
1619 `c-colon-type-list-kwds', `c-paren-nontype-kwds', `c-paren-type-kwds',
1620 `c-<>-type-kwds', or `c-<>-arglist-kwds' then the associated clauses
1625 (c-lang-defconst c-brace-list-key
1626 ;; Regexp matching the start of declarations where the following
1627 ;; block is a brace list.
1628 t (c-make-keywords-re t (c-lang-const c-brace-list-decl-kwds)))
1629 (c-lang-defvar c-brace-list-key (c-lang-const c-brace-list-key))
1631 (c-lang-defconst c-other-block-decl-kwds
1632 "Keywords where the following block (if any) contains another
1633 declaration level that should not be considered a class. For every
1634 keyword here, CC Mode will add a set of special syntactic symbols for
1635 those blocks. E.g. if the keyword is \"foo\" then there will be
1636 `foo-open', `foo-close', and `infoo' symbols.
1638 The intention is that this category should be used for block
1639 constructs that aren't related to object orientation concepts like
1640 classes (which thus also include e.g. interfaces, templates,
1641 contracts, structs, etc). The more pragmatic distinction is that
1642 while most want some indentation inside classes, it's fairly common
1643 that they don't want it in some of these constructs, so it should be
1644 simple to configure that differently from classes. See also
1645 `c-class-decl-kwds'.
1647 If any of these also are on `c-type-list-kwds', `c-ref-list-kwds',
1648 `c-colon-type-list-kwds', `c-paren-nontype-kwds', `c-paren-type-kwds',
1649 `c-<>-type-kwds', or `c-<>-arglist-kwds' then the associated clauses
1652 (c objc) '("extern")
1653 c++ '("namespace" "extern")
1658 (c-lang-defconst c-other-decl-block-key
1659 ;; Regexp matching the start of blocks besides classes that contain
1660 ;; another declaration level.
1661 t (c-make-keywords-re t (c-lang-const c-other-block-decl-kwds)))
1662 (c-lang-defvar c-other-decl-block-key (c-lang-const c-other-decl-block-key))
1664 (c-lang-defvar c-other-decl-block-key-in-symbols-alist
1668 (if (string= elt "extern")
1670 (intern (concat "in" elt)))))
1671 (c-lang-const c-other-block-decl-kwds))
1672 "Alist associating keywords in c-other-decl-block-decl-kwds with
1673 their matching \"in\" syntactic symbols.")
1675 (c-lang-defconst c-typedef-decl-kwds
1676 "Keywords introducing declarations where the identifier(s) being
1679 If any of these also are on `c-type-list-kwds', `c-ref-list-kwds',
1680 `c-colon-type-list-kwds', `c-paren-nontype-kwds', `c-paren-type-kwds',
1681 `c-<>-type-kwds', or `c-<>-arglist-kwds' then the associated clauses
1683 ;; Default to `c-class-decl-kwds' and `c-brace-list-decl-kwds'
1684 ;; (since e.g. "Foo" is a type that's being defined in "class Foo
1686 t (append (c-lang-const c-class-decl-kwds)
1687 (c-lang-const c-brace-list-decl-kwds))
1688 ;; Languages that have a "typedef" construct.
1689 (c c++ objc idl pike) (append (c-lang-const c-typedef-decl-kwds)
1691 ;; Unlike most other languages, exception names are not handled as
1692 ;; types in IDL since they only can occur in "raises" specs.
1693 idl (delete "exception" (append (c-lang-const c-typedef-decl-kwds) nil)))
1695 (c-lang-defconst c-typeless-decl-kwds
1696 "Keywords introducing declarations where the \(first) identifier
1697 \(declarator) follows directly after the keyword, without any type.
1699 If any of these also are on `c-type-list-kwds', `c-ref-list-kwds',
1700 `c-colon-type-list-kwds', `c-paren-nontype-kwds', `c-paren-type-kwds',
1701 `c-<>-type-kwds', or `c-<>-arglist-kwds' then the associated clauses
1703 ;; Default to `c-class-decl-kwds' and `c-brace-list-decl-kwds'
1704 ;; (since e.g. "Foo" is the identifier being defined in "class Foo
1706 t (append (c-lang-const c-class-decl-kwds)
1707 (c-lang-const c-brace-list-decl-kwds))
1708 ;; Note: "manages" for CORBA CIDL clashes with its presence on
1709 ;; `c-type-list-kwds' for IDL.
1710 idl (append (c-lang-const c-typeless-decl-kwds)
1711 '("factory" "finder" "native"
1716 pike (append (c-lang-const c-class-decl-kwds)
1719 (c-lang-defconst c-modifier-kwds
1720 "Keywords that can prefix normal declarations of identifiers
1721 \(and typically act as flags). Things like argument declarations
1722 inside function headers are also considered declarations in this
1725 If any of these also are on `c-type-list-kwds', `c-ref-list-kwds',
1726 `c-colon-type-list-kwds', `c-paren-nontype-kwds', `c-paren-type-kwds',
1727 `c-<>-type-kwds', or `c-<>-arglist-kwds' then the associated clauses
1730 (c c++) '("auto" "extern" "inline" "register" "static")
1731 c++ (append '("explicit" "friend" "mutable" "template" "using" "virtual")
1732 (c-lang-const c-modifier-kwds))
1733 objc '("auto" "bycopy" "byref" "extern" "in" "inout" "oneway" "out" "static")
1734 ;; FIXME: Some of those below ought to be on `c-other-decl-kwds' instead.
1735 idl '("abstract" "attribute" "const" "consumes" "custom" "emits" "import"
1736 "in" "inout" "local" "multiple" "oneway" "out" "private" "provides"
1737 "public" "publishes" "readonly" "typeid" "typeprefix" "uses"
1741 "bindsTo" "delegatesTo" "implements" "proxy" "storedOn")
1742 ;; Note: "const" is not used in Java, but it's still a reserved keyword.
1743 java '("abstract" "const" "final" "native" "private" "protected" "public"
1744 "static" "strictfp" "synchronized" "transient" "volatile")
1745 pike '("final" "inline" "local" "nomask" "optional" "private" "protected"
1746 "public" "static" "variant"))
1748 (c-lang-defconst c-other-decl-kwds
1749 "Keywords that can start or prefix any declaration level construct,
1750 besides those on `c-class-decl-kwds', `c-brace-list-decl-kwds',
1751 `c-other-block-decl-kwds', `c-typedef-decl-kwds',
1752 `c-typeless-decl-kwds' and `c-modifier-kwds'.
1754 If any of these also are on `c-type-list-kwds', `c-ref-list-kwds',
1755 `c-colon-type-list-kwds', `c-paren-nontype-kwds', `c-paren-type-kwds',
1756 `c-<>-type-kwds', or `c-<>-arglist-kwds' then the associated clauses
1759 objc '("@class" "@end" "@defs")
1760 java '("import" "package")
1761 pike '("import" "inherit"))
1763 (c-lang-defconst c-decl-start-kwds
1764 "Keywords that always start declarations, wherever they occur.
1765 This can be used for declarations that aren't recognized by the normal
1766 combination of `c-decl-prefix-re' and `c-decl-start-re'."
1768 ;; Classes can be declared anywhere in a Pike expression.
1771 (c-lang-defconst c-decl-hangon-kwds
1772 "Keywords that can occur anywhere in a declaration level construct.
1773 This is used for self-contained things that can be tacked on anywhere
1774 on a declaration and that should be ignored to be able to recognize it
1775 correctly. Typical cases are compiler extensions like
1776 \"__attribute__\" or \"__declspec\":
1778 __declspec(noreturn) void foo();
1779 class __declspec(dllexport) classname {...};
1780 void foo() __attribute__((noreturn));
1782 Note that unrecognized plain symbols are skipped anyway if they occur
1783 before the type, so such things are not necessary to mention here.
1784 Mentioning them here is necessary only if they can occur in other
1785 places, or if they are followed by a construct that must be skipped
1786 over \(like the parens in the \"__attribute__\" and \"__declspec\"
1787 examples above). In the last case, they alse need to be present on
1788 one of `c-type-list-kwds', `c-ref-list-kwds',
1789 `c-colon-type-list-kwds', `c-paren-nontype-kwds', `c-paren-type-kwds',
1790 `c-<>-type-kwds', or `c-<>-arglist-kwds'."
1791 ;; NB: These are currently not recognized in all parts of a
1792 ;; declaration. Specifically, they aren't recognized in the middle
1793 ;; of multi-token types, inside declarators, and between the
1794 ;; identifier and the arglist paren of a function declaration.
1796 ;; FIXME: This ought to be user customizable since compiler stuff
1797 ;; like this usually is wrapped in project specific macros. (It'd
1798 ;; of course be even better if we could cope without knowing this.)
1800 (c c++) '(;; GCC extension.
1805 (c-lang-defconst c-decl-hangon-key
1806 ;; Adorned regexp matching `c-decl-hangon-kwds'.
1807 t (c-make-keywords-re t (c-lang-const c-decl-hangon-kwds)))
1808 (c-lang-defvar c-decl-hangon-key (c-lang-const c-decl-hangon-key))
1810 (c-lang-defconst c-prefix-spec-kwds
1811 ;; All keywords that can occur in the preamble of a declaration.
1812 ;; They typically occur before the type, but they are also matched
1813 ;; after presumptive types since we often can't be sure that
1814 ;; something is a type or just some sort of macro in front of the
1815 ;; declaration. They might be ambiguous with types or type
1817 t (delete-duplicates (append (c-lang-const c-class-decl-kwds)
1818 (c-lang-const c-brace-list-decl-kwds)
1819 (c-lang-const c-other-block-decl-kwds)
1820 (c-lang-const c-typedef-decl-kwds)
1821 (c-lang-const c-typeless-decl-kwds)
1822 (c-lang-const c-modifier-kwds)
1823 (c-lang-const c-other-decl-kwds)
1824 (c-lang-const c-decl-start-kwds)
1825 (c-lang-const c-decl-hangon-kwds))
1826 :test 'string-equal))
1828 (c-lang-defconst c-prefix-spec-kwds-re
1829 ;; Adorned regexp of `c-prefix-spec-kwds'.
1830 t (c-make-keywords-re t (c-lang-const c-prefix-spec-kwds)))
1831 (c-lang-defvar c-prefix-spec-kwds-re (c-lang-const c-prefix-spec-kwds-re))
1833 (c-lang-defconst c-specifier-key
1834 ;; Adorned regexp of the keywords in `c-prefix-spec-kwds' that aren't
1835 ;; ambiguous with types or type prefixes. These are the keywords (like
1836 ;; extern, namespace, but NOT template) that can modify a declaration.
1837 t (c-make-keywords-re t
1838 (set-difference (c-lang-const c-prefix-spec-kwds)
1839 (append (c-lang-const c-type-start-kwds)
1840 (c-lang-const c-<>-arglist-kwds))
1841 :test 'string-equal)))
1842 (c-lang-defvar c-specifier-key (c-lang-const c-specifier-key))
1844 (c-lang-defconst c-postfix-spec-kwds
1845 ;; Keywords that can occur after argument list of a function header
1846 ;; declaration, i.e. in the "K&R region".
1847 t (append (c-lang-const c-postfix-decl-spec-kwds)
1848 (c-lang-const c-decl-hangon-kwds)))
1850 (c-lang-defconst c-not-decl-init-keywords
1851 ;; Adorned regexp matching all keywords that can't appear at the
1852 ;; start of a declaration.
1853 t (c-make-keywords-re t
1854 (set-difference (c-lang-const c-keywords)
1855 (append (c-lang-const c-type-start-kwds)
1856 (c-lang-const c-prefix-spec-kwds))
1857 :test 'string-equal)))
1858 (c-lang-defvar c-not-decl-init-keywords
1859 (c-lang-const c-not-decl-init-keywords))
1861 (c-lang-defconst c-protection-kwds
1862 "Access protection label keywords in classes."
1864 c++ '("private" "protected" "public")
1865 objc '("@private" "@protected" "@public"))
1867 (c-lang-defconst c-block-decls-with-vars
1868 "Keywords introducing declarations that can contain a block which
1869 might be followed by variable declarations, e.g. like \"foo\" in
1870 \"class Foo { ... } foo;\". So if there is a block in a declaration
1871 like that, it ends with the following ';' and not right away.
1873 The keywords on list are assumed to also be present on one of the
1874 `*-decl-kwds' lists."
1876 (c objc) '("struct" "union" "enum" "typedef")
1877 c++ '("class" "struct" "union" "enum" "typedef"))
1879 (c-lang-defconst c-opt-block-decls-with-vars-key
1880 ;; Regexp matching the `c-block-decls-with-vars' keywords, or nil in
1881 ;; languages without such constructs.
1882 t (and (c-lang-const c-block-decls-with-vars)
1883 (c-make-keywords-re t (c-lang-const c-block-decls-with-vars))))
1884 (c-lang-defvar c-opt-block-decls-with-vars-key
1885 (c-lang-const c-opt-block-decls-with-vars-key))
1887 (c-lang-defconst c-postfix-decl-spec-kwds
1888 "Keywords introducing extra declaration specifiers in the region
1889 between the header and the body \(i.e. the \"K&R-region\") in
1892 java '("extends" "implements" "throws")
1893 idl '("context" "getraises" "manages" "primarykey" "raises" "setraises"
1896 "as" "const" "implements" "of" "ref"))
1898 (c-lang-defconst c-nonsymbol-sexp-kwds
1899 "Keywords that may be followed by a nonsymbol sexp before whatever
1900 construct it's part of continues."
1902 (c c++ objc) '("extern"))
1904 (c-lang-defconst c-type-list-kwds
1905 "Keywords that may be followed by a comma separated list of type
1906 identifiers, where each optionally can be prefixed by keywords. (Can
1907 also be used for the special case when the list can contain only one
1910 Assumed to be mutually exclusive with `c-ref-list-kwds'. There's no
1911 reason to put keywords on this list if they are on `c-type-prefix-kwds'.
1912 There's also no reason to add keywords that prefixes a normal
1913 declaration consisting of a type followed by a declarator (list), so
1914 the keywords on `c-modifier-kwds' should normally not be listed here
1917 Note: Use `c-typeless-decl-kwds' for keywords followed by a function
1918 or variable identifier (that's being defined)."
1922 java '("import" "new" "extends" "implements" "throws")
1923 idl '("manages" "native" "primarykey" "supports"
1925 "as" "implements" "of" "scope")
1928 (c-lang-defconst c-ref-list-kwds
1929 "Keywords that may be followed by a comma separated list of
1930 reference (i.e. namespace/scope/module) identifiers, where each
1931 optionally can be prefixed by keywords. (Can also be used for the
1932 special case when the list can contain only one element.) Assumed to
1933 be mutually exclusive with `c-type-list-kwds'.
1935 Note: Use `c-typeless-decl-kwds' for keywords followed by a function
1936 or variable identifier (that's being defined)."
1940 idl '("import" "module"
1945 (c-lang-defconst c-colon-type-list-kwds
1946 "Keywords that may be followed (not necessarily directly) by a colon
1947 and then a comma separated list of type identifiers, where each
1948 optionally can be prefixed by keywords. (Can also be used for the
1949 special case when the list can contain only one element.)"
1951 c++ '("class" "struct")
1952 idl '("component" "eventtype" "home" "interface" "valuetype"
1954 "storagehome" "storagetype"))
1956 (c-lang-defconst c-colon-type-list-re
1957 "Regexp matched after the keywords in `c-colon-type-list-kwds' to skip
1958 forward to the colon. The end of the match is assumed to be directly
1959 after the colon, so the regexp should end with \":\". Must be a
1960 regexp if `c-colon-type-list-kwds' isn't nil."
1961 t (if (c-lang-const c-colon-type-list-kwds)
1962 ;; Disallow various common punctuation chars that can't come
1963 ;; before the ":" that starts the inherit list after "class"
1964 ;; or "struct" in C++. (Also used as default for other
1966 "[^\]\[{}();,/#=:]*:"))
1967 (c-lang-defvar c-colon-type-list-re (c-lang-const c-colon-type-list-re))
1969 (c-lang-defconst c-paren-nontype-kwds
1970 "Keywords that may be followed by a parenthesis expression that doesn't
1971 contain type identifiers."
1973 (c c++) '(;; GCC extension.
1978 (c-lang-defconst c-paren-type-kwds
1979 "Keywords that may be followed by a parenthesis expression containing
1980 type identifiers separated by arbitrary tokens."
1985 pike '("array" "function" "int" "mapping" "multiset" "object" "program"))
1987 (c-lang-defconst c-paren-any-kwds
1988 t (delete-duplicates (append (c-lang-const c-paren-nontype-kwds)
1989 (c-lang-const c-paren-type-kwds))
1990 :test 'string-equal))
1992 (c-lang-defconst c-<>-type-kwds
1993 "Keywords that may be followed by an angle bracket expression
1994 containing type identifiers separated by \",\". The difference from
1995 `c-<>-arglist-kwds' is that unknown names are taken to be types and
1996 not other identifiers. `c-recognize-<>-arglists' is assumed to be set
2004 (c-lang-defconst c-<>-arglist-kwds
2005 "Keywords that can be followed by a C++ style template arglist; see
2006 `c-recognize-<>-arglists' for details. That language constant is
2007 assumed to be set if this isn't nil."
2010 idl '("fixed" "string" "wstring"))
2012 (c-lang-defconst c-<>-sexp-kwds
2013 ;; All keywords that can be followed by an angle bracket sexp.
2014 t (delete-duplicates (append (c-lang-const c-<>-type-kwds)
2015 (c-lang-const c-<>-arglist-kwds))
2016 :test 'string-equal))
2018 (c-lang-defconst c-opt-<>-sexp-key
2019 ;; Adorned regexp matching keywords that can be followed by an angle
2020 ;; bracket sexp. Always set when `c-recognize-<>-arglists' is.
2021 t (if (c-lang-const c-recognize-<>-arglists)
2022 (c-make-keywords-re t (c-lang-const c-<>-sexp-kwds))))
2023 (c-lang-defvar c-opt-<>-sexp-key (c-lang-const c-opt-<>-sexp-key))
2025 (c-lang-defconst c-brace-id-list-kwds
2026 "Keywords that may be followed by a brace block containing a comma
2027 separated list of identifier definitions, i.e. like the list of
2028 identifiers that follows the type in a normal declaration."
2029 t (c-lang-const c-brace-list-decl-kwds))
2031 (c-lang-defconst c-block-stmt-1-kwds
2032 "Statement keywords followed directly by a substatement."
2034 c++ '("do" "else" "try")
2035 objc '("do" "else" "@finally" "@try")
2036 java '("do" "else" "finally" "try")
2039 (c-lang-defconst c-block-stmt-1-key
2040 ;; Regexp matching the start of any statement followed directly by a
2041 ;; substatement (doesn't match a bare block, however).
2042 t (c-make-keywords-re t (c-lang-const c-block-stmt-1-kwds)))
2043 (c-lang-defvar c-block-stmt-1-key (c-lang-const c-block-stmt-1-key))
2045 (c-lang-defconst c-block-stmt-2-kwds
2046 "Statement keywords followed by a paren sexp and then by a substatement."
2047 t '("for" "if" "switch" "while")
2048 c++ '("for" "if" "switch" "while" "catch")
2049 objc '("for" "if" "switch" "while" "@catch" "@synchronized")
2050 java '("for" "if" "switch" "while" "catch" "synchronized")
2052 pike '("for" "if" "switch" "while" "foreach")
2053 awk '("for" "if" "while"))
2055 (c-lang-defconst c-block-stmt-2-key
2056 ;; Regexp matching the start of any statement followed by a paren sexp
2057 ;; and then by a substatement.
2058 t (c-make-keywords-re t (c-lang-const c-block-stmt-2-kwds)))
2059 (c-lang-defvar c-block-stmt-2-key (c-lang-const c-block-stmt-2-key))
2061 (c-lang-defconst c-block-stmt-kwds
2062 ;; Union of `c-block-stmt-1-kwds' and `c-block-stmt-2-kwds'.
2063 t (delete-duplicates (append (c-lang-const c-block-stmt-1-kwds)
2064 (c-lang-const c-block-stmt-2-kwds))
2065 :test 'string-equal))
2067 (c-lang-defconst c-opt-block-stmt-key
2068 ;; Regexp matching the start of any statement that has a
2069 ;; substatement (except a bare block). Nil in languages that
2070 ;; don't have such constructs.
2071 t (if (or (c-lang-const c-block-stmt-1-kwds)
2072 (c-lang-const c-block-stmt-2-kwds))
2073 (c-make-keywords-re t
2074 (append (c-lang-const c-block-stmt-1-kwds)
2075 (c-lang-const c-block-stmt-2-kwds)))))
2076 (c-lang-defvar c-opt-block-stmt-key (c-lang-const c-opt-block-stmt-key))
2078 (c-lang-defconst c-simple-stmt-kwds
2079 "Statement keywords followed by an expression or nothing."
2080 t '("break" "continue" "goto" "return")
2081 objc '("break" "continue" "goto" "return" "@throw")
2082 ;; Note: `goto' is not valid in Java, but the keyword is still reserved.
2083 java '("break" "continue" "goto" "return" "throw")
2085 pike '("break" "continue" "return")
2086 awk '(;; Not sure about "delete", "exit", "getline", etc. ; ACM 2002/5/30
2087 "break" "continue" "return" "delete" "exit" "getline" "next"
2088 "nextfile" "print" "printf"))
2090 (c-lang-defconst c-simple-stmt-key
2091 ;; Adorned regexp matching `c-simple-stmt-kwds'.
2092 t (c-make-keywords-re t (c-lang-const c-simple-stmt-kwds)))
2093 (c-lang-defvar c-simple-stmt-key (c-lang-const c-simple-stmt-key))
2095 (c-lang-defconst c-paren-stmt-kwds
2096 "Statement keywords followed by a parenthesis expression that
2097 nevertheless contains a list separated with ';' and not ','."
2101 (c-lang-defconst c-paren-stmt-key
2102 ;; Adorned regexp matching `c-paren-stmt-kwds'.
2103 t (c-make-keywords-re t (c-lang-const c-paren-stmt-kwds)))
2104 (c-lang-defvar c-paren-stmt-key (c-lang-const c-paren-stmt-key))
2106 (c-lang-defconst c-asm-stmt-kwds
2107 "Statement keywords followed by an assembler expression."
2109 (c c++) '("asm" "__asm__")) ;; Not standard, but common.
2111 (c-lang-defconst c-opt-asm-stmt-key
2112 ;; Regexp matching the start of an assembler statement. Nil in
2113 ;; languages that don't support that.
2114 t (if (c-lang-const c-asm-stmt-kwds)
2115 (c-make-keywords-re t (c-lang-const c-asm-stmt-kwds))))
2116 (c-lang-defvar c-opt-asm-stmt-key (c-lang-const c-opt-asm-stmt-key))
2118 (c-lang-defconst c-label-kwds
2119 "Keywords introducing colon terminated labels in blocks."
2120 t '("case" "default")
2123 (c-lang-defconst c-label-kwds-regexp
2124 ;; Adorned regexp matching any keyword that introduces a label.
2125 t (c-make-keywords-re t (c-lang-const c-label-kwds)))
2126 (c-lang-defvar c-label-kwds-regexp (c-lang-const c-label-kwds-regexp))
2128 (c-lang-defconst c-before-label-kwds
2129 "Keywords that might be followed by a label identifier."
2131 (java pike) (append '("break" "continue")
2132 (c-lang-const c-before-label-kwds))
2136 (c-lang-defconst c-constant-kwds
2137 "Keywords for constants."
2139 (c c++) '("NULL" ;; Not a keyword, but practically works as one.
2140 "false" "true") ; Defined in C99.
2142 idl '("TRUE" "FALSE")
2143 java '("true" "false" "null") ; technically "literals", not keywords
2144 pike '("UNDEFINED")) ;; Not a keyword, but practically works as one.
2146 (c-lang-defconst c-primary-expr-kwds
2147 "Keywords besides constants and operators that start primary expressions."
2149 c++ '("operator" "this")
2150 objc '("super" "self")
2152 pike '("this")) ;; Not really a keyword, but practically works as one.
2154 (c-lang-defconst c-expr-kwds
2155 ;; Keywords that can occur anywhere in expressions. Built from
2156 ;; `c-primary-expr-kwds' and all keyword operators in `c-operators'.
2157 t (delete-duplicates
2158 (append (c-lang-const c-primary-expr-kwds)
2159 (c-filter-ops (c-lang-const c-operator-list)
2161 "\\`\\(\\w\\|\\s_\\)+\\'"))
2162 :test 'string-equal))
2164 (c-lang-defconst c-lambda-kwds
2165 "Keywords that start lambda constructs, i.e. function definitions in
2170 (c-lang-defconst c-inexpr-block-kwds
2171 "Keywords that start constructs followed by statement blocks which can
2172 be used in expressions \(the gcc extension for this in C and C++ is
2173 handled separately by `c-recognize-paren-inexpr-blocks')."
2175 pike '("catch" "gauge"))
2177 (c-lang-defconst c-inexpr-class-kwds
2178 "Keywords that can start classes inside expressions."
2183 (c-lang-defconst c-inexpr-brace-list-kwds
2184 "Keywords that can start brace list blocks inside expressions.
2185 Note that Java specific rules are currently applied to tell this from
2186 `c-inexpr-class-kwds'."
2190 (c-lang-defconst c-opt-inexpr-brace-list-key
2191 ;; Regexp matching the start of a brace list in an expression, or
2192 ;; nil in languages that don't have such things. This should not
2193 ;; match brace lists recognized through `c-special-brace-lists'.
2194 t (and (c-lang-const c-inexpr-brace-list-kwds)
2195 (c-make-keywords-re t (c-lang-const c-inexpr-brace-list-kwds))))
2196 (c-lang-defvar c-opt-inexpr-brace-list-key
2197 (c-lang-const c-opt-inexpr-brace-list-key))
2199 (c-lang-defconst c-decl-block-key
2200 ;; Regexp matching keywords in any construct that contain another
2201 ;; declaration level, i.e. that isn't followed by a function block
2202 ;; or brace list. When the first submatch matches, it's an
2203 ;; unambiguous construct, otherwise it's an ambiguous match that
2204 ;; might also be the return type of a function declaration.
2205 t (let* ((decl-kwds (append (c-lang-const c-class-decl-kwds)
2206 (c-lang-const c-other-block-decl-kwds)
2207 (c-lang-const c-inexpr-class-kwds)))
2208 (unambiguous (set-difference decl-kwds
2209 (c-lang-const c-type-start-kwds)
2210 :test 'string-equal))
2211 (ambiguous (intersection decl-kwds
2212 (c-lang-const c-type-start-kwds)
2213 :test 'string-equal)))
2215 (concat (c-make-keywords-re t unambiguous)
2217 (c-make-keywords-re t ambiguous))
2218 (c-make-keywords-re t unambiguous))))
2219 (c-lang-defvar c-decl-block-key (c-lang-const c-decl-block-key))
2221 (c-lang-defconst c-bitfield-kwds
2222 "Keywords that can introduce bitfields."
2224 (c c++ objc) '("char" "int" "long" "signed" "unsigned"))
2226 (c-lang-defconst c-opt-bitfield-key
2227 ;; Regexp matching the start of a bitfield (not uniquely), or nil in
2228 ;; languages without bitfield support.
2230 (c c++) (c-make-keywords-re t (c-lang-const c-bitfield-kwds)))
2231 (c-lang-defvar c-opt-bitfield-key (c-lang-const c-opt-bitfield-key))
2233 (c-lang-defconst c-other-kwds
2234 "Keywords not accounted for by any other `*-kwds' language constant."
2237 ;; In CORBA CIDL: (These are declaration keywords that never
2238 ;; can start a declaration.)
2239 "entity" "process" "service" "session" "storage"))
2242 ;;; Constants built from keywords.
2244 ;; Note: No `*-kwds' language constants may be defined below this point.
2247 (defconst c-kwds-lang-consts
2248 ;; List of all the language constants that contain keyword lists.
2250 (mapatoms (lambda (sym)
2251 (when (and (boundp sym)
2252 (string-match "-kwds\\'" (symbol-name sym)))
2253 ;; Make the list of globally interned symbols
2254 ;; instead of ones interned in `c-lang-constants'.
2255 (setq list (cons (intern (symbol-name sym)) list))))
2259 (c-lang-defconst c-keywords
2260 ;; All keywords as a list.
2261 t (delete-duplicates
2262 (c-lang-defconst-eval-immediately
2263 `(append ,@(mapcar (lambda (kwds-lang-const)
2264 `(c-lang-const ,kwds-lang-const))
2267 :test 'string-equal))
2269 (c-lang-defconst c-keywords-regexp
2270 ;; All keywords as an adorned regexp.
2271 t (c-make-keywords-re t (c-lang-const c-keywords)))
2272 (c-lang-defvar c-keywords-regexp (c-lang-const c-keywords-regexp))
2274 (c-lang-defconst c-keyword-member-alist
2275 ;; An alist with all the keywords in the cars. The cdr for each
2276 ;; keyword is a list of the symbols for the `*-kwds' lists that
2278 t (let ((kwd-list-alist
2279 (c-lang-defconst-eval-immediately
2280 `(list ,@(mapcar (lambda (kwds-lang-const)
2281 `(cons ',kwds-lang-const
2282 (c-lang-const ,kwds-lang-const)))
2283 c-kwds-lang-consts))))
2284 lang-const kwd-list kwd
2286 (while kwd-list-alist
2287 (setq lang-const (caar kwd-list-alist)
2288 kwd-list (cdar kwd-list-alist)
2289 kwd-list-alist (cdr kwd-list-alist))
2291 (setq kwd (car kwd-list)
2292 kwd-list (cdr kwd-list))
2293 (unless (setq elem (assoc kwd result-alist))
2294 (setq result-alist (cons (setq elem (list kwd)) result-alist)))
2295 (unless (memq lang-const (cdr elem))
2296 (setcdr elem (cons lang-const (cdr elem))))))
2299 (c-lang-defvar c-keywords-obarray
2300 ;; An obarray containing all keywords as symbols. The property list
2301 ;; of each symbol has a non-nil entry for the specific `*-kwds'
2302 ;; lists it's a member of.
2304 ;; E.g. to see whether the string str contains a keyword on
2305 ;; `c-class-decl-kwds', one can do like this:
2306 ;; (get (intern-soft str c-keyword-obarray) 'c-class-decl-kwds)
2307 ;; Which preferably is written using the associated functions in
2309 ;; (c-keyword-member (c-keyword-sym str) 'c-class-decl-kwds)
2311 ;; The obarray is not stored directly as a language constant since
2312 ;; the printed representation for obarrays used in .elc files isn't
2315 (let* ((alist (c-lang-const c-keyword-member-alist))
2317 (obarray (make-vector (* (length alist) 2) 0)))
2319 (setq kwd (caar alist)
2320 lang-const-list (cdar alist)
2322 (setplist (intern kwd obarray)
2323 ;; Emacs has an odd bug that causes `mapcan' to fail
2324 ;; with unintelligible errors. (XEmacs works.)
2325 ;;(mapcan (lambda (lang-const)
2326 ;; (list lang-const t))
2328 (apply 'nconc (mapcar (lambda (lang-const)
2329 (list lang-const t))
2333 (c-lang-defconst c-regular-keywords-regexp
2334 ;; Adorned regexp matching all keywords that should be fontified
2335 ;; with the keywords face. I.e. that aren't types or constants.
2336 t (c-make-keywords-re t
2337 (set-difference (c-lang-const c-keywords)
2338 (append (c-lang-const c-primitive-type-kwds)
2339 (c-lang-const c-constant-kwds))
2340 :test 'string-equal)))
2341 (c-lang-defvar c-regular-keywords-regexp
2342 (c-lang-const c-regular-keywords-regexp))
2344 (c-lang-defconst c-primary-expr-regexp
2345 ;; Regexp matching the start of any primary expression, i.e. any
2346 ;; literal, symbol, prefix operator, and '('. It doesn't need to
2347 ;; exclude keywords; they are excluded afterwards unless the second
2348 ;; submatch matches. If the first but not the second submatch
2349 ;; matches then it is an ambiguous primary expression; it could also
2350 ;; be a match of e.g. an infix operator. (The case with ambiguous
2351 ;; keyword operators isn't handled.)
2353 t (let* ((prefix-ops
2354 (c-filter-ops (c-lang-const c-operators)
2357 ;; Filter out the special case prefix
2358 ;; operators that are close parens.
2359 (not (string-match "\\s)" op)))))
2361 (nonkeyword-prefix-ops
2362 (c-filter-ops prefix-ops
2364 "\\`\\(\\s.\\|\\s(\\|\\s)\\)+\\'"))
2367 (c-filter-ops (c-lang-const c-operators)
2372 right-assoc-sequence)
2375 (unambiguous-prefix-ops (set-difference nonkeyword-prefix-ops
2377 :test 'string-equal))
2378 (ambiguous-prefix-ops (intersection nonkeyword-prefix-ops
2380 :test 'string-equal)))
2384 ;; Take out all symbol class operators from `prefix-ops' and make the
2385 ;; first submatch from them together with `c-primary-expr-kwds'.
2386 (c-make-keywords-re t
2387 (append (c-lang-const c-primary-expr-kwds)
2388 (set-difference prefix-ops nonkeyword-prefix-ops
2389 :test 'string-equal)))
2392 ;; Match all ambiguous operators.
2393 (c-make-keywords-re nil
2394 (intersection nonkeyword-prefix-ops in-or-postfix-ops
2395 :test 'string-equal))
2399 ;; Now match all other symbols.
2400 (c-lang-const c-symbol-start)
2403 ;; The chars that can start integer and floating point
2408 ;; The nonambiguous operators from `prefix-ops'.
2409 (c-make-keywords-re nil
2410 (set-difference nonkeyword-prefix-ops in-or-postfix-ops
2411 :test 'string-equal))
2414 ;; Match string and character literals.
2416 (if (memq 'gen-string-delim c-emacs-features)
2419 (c-lang-defvar c-primary-expr-regexp (c-lang-const c-primary-expr-regexp))
2422 ;;; Additional constants for parser-level constructs.
2424 (c-lang-defconst c-decl-prefix-re
2425 "Regexp matching something that might precede a declaration, cast or
2426 label, such as the last token of a preceding statement or declaration.
2427 This is used in the common situation where a declaration or cast
2428 doesn't start with any specific token that can be searched for.
2430 The regexp should not match bob; that is done implicitly. It can't
2431 require a match longer than one token. The end of the token is taken
2432 to be at the end of the first submatch, which is assumed to always
2433 match. It's undefined whether identifier syntax (see
2434 `c-identifier-syntax-table') is in effect or not. This regexp is
2435 assumed to be a superset of `c-label-prefix-re' if
2436 `c-recognize-colon-labels' is set.
2438 Besides this, `c-decl-start-kwds' is used to find declarations.
2440 Note: This variable together with `c-decl-start-re' and
2441 `c-decl-start-kwds' is only used to detect \"likely\"
2442 declaration/cast/label starts. I.e. they might produce more matches
2443 but should not miss anything (or else it's necessary to use text
2444 properties - see the next note). Wherever they match, the following
2445 construct is analyzed to see if it indeed is a declaration, cast or
2446 label. That analysis is not cheap, so it's important that not too
2447 many false matches are triggered.
2449 Note: If a declaration/cast/label start can't be detected with this
2450 variable, it's necessary to use the `c-type' text property with the
2451 value `c-decl-end' on the last char of the last token preceding the
2452 declaration. See the comment blurb at the start of cc-engine.el for
2455 ;; We match a sequence of characters to skip over things like \"};\"
2456 ;; more quickly. We match ")" in C for K&R region declarations, and
2457 ;; in all languages except Java for when a cpp macro definition
2458 ;; begins with a declaration.
2459 t "\\([\{\}\(\);,]+\\)"
2460 java "\\([\{\}\(;,]+\\)"
2461 ;; Match "<" in C++ to get the first argument in a template arglist.
2462 ;; In that case there's an additional check in `c-find-decl-spots'
2463 ;; that it got open paren syntax.
2464 c++ "\\([\{\}\(\);,<]+\\)"
2465 ;; Additionally match the protection directives in Objective-C.
2466 ;; Note that this doesn't cope with the longer directives, which we
2467 ;; would have to match from start to end since they don't end with
2468 ;; any easily recognized characters.
2469 objc (concat "\\([\{\}\(\);,]+\\|"
2470 (c-make-keywords-re nil (c-lang-const c-protection-kwds))
2472 ;; Pike is like C but we also match "[" for multiple value
2473 ;; assignments and type casts.
2474 pike "\\([\{\}\(\)\[;,]+\\)")
2475 (c-lang-defvar c-decl-prefix-re (c-lang-const c-decl-prefix-re)
2478 (c-lang-defconst c-decl-start-re
2479 "Regexp matching the start of any declaration, cast or label.
2480 It's used on the token after the one `c-decl-prefix-re' matched. This
2481 regexp should not try to match those constructs accurately as it's
2482 only used as a sieve to avoid spending more time checking other
2484 t (c-lang-const c-identifier-start))
2485 (c-lang-defvar c-decl-start-re (c-lang-const c-decl-start-re))
2487 (c-lang-defconst c-decl-prefix-or-start-re
2488 ;; Regexp matching something that might precede or start a
2489 ;; declaration, cast or label.
2491 ;; If the first submatch matches, it's taken to match the end of a
2492 ;; token that might precede such a construct, e.g. ';', '}' or '{'.
2493 ;; It's built from `c-decl-prefix-re'.
2495 ;; If the first submatch did not match, the match of the whole
2496 ;; regexp is taken to be at the first token in the declaration.
2497 ;; `c-decl-start-re' is not checked in this case.
2499 ;; Design note: The reason the same regexp is used to match both
2500 ;; tokens that precede declarations and start them is to avoid an
2501 ;; extra regexp search from the previous declaration spot in
2502 ;; `c-find-decl-spots'. Users of `c-find-decl-spots' also count on
2503 ;; that it finds all declaration/cast/label starts in approximately
2504 ;; linear order, so we can't do the searches in two separate passes.
2505 t (if (c-lang-const c-decl-start-kwds)
2506 (concat (c-lang-const c-decl-prefix-re)
2508 (c-make-keywords-re t (c-lang-const c-decl-start-kwds)))
2509 (c-lang-const c-decl-prefix-re)))
2510 (c-lang-defvar c-decl-prefix-or-start-re
2511 (c-lang-const c-decl-prefix-or-start-re)
2514 (c-lang-defconst c-cast-parens
2515 ;; List containing the paren characters that can open a cast, or nil in
2516 ;; languages without casts.
2517 t (c-filter-ops (c-lang-const c-operators)
2520 (lambda (op) (elt op 0))))
2521 (c-lang-defvar c-cast-parens (c-lang-const c-cast-parens))
2523 (c-lang-defconst c-block-prefix-disallowed-chars
2524 "List of syntactically relevant characters that never can occur before
2525 the open brace in any construct that contains a brace block, e.g. in
2526 the \"class Foo: public Bar\" part of:
2528 class Foo: public Bar {int x();} a, *b;
2530 If parens can occur, the chars inside those aren't filtered with this
2533 '<' and '>' should be disallowed even if angle bracket arglists can
2534 occur. That since the search function needs to stop at them anyway to
2535 ensure they are given paren syntax.
2537 This is used to skip backward from the open brace to find the region
2538 in which to look for a construct like \"class\", \"enum\",
2539 \"namespace\" or whatever. That skipping should be as tight as
2540 possible for good performance."
2542 ;; Default to all chars that only occurs in nonsymbol tokens outside
2545 (c-lang-const c-nonsymbol-token-char-list)
2546 (c-filter-ops (append (c-lang-const c-identifier-ops)
2548 (c-lang-const c-after-id-concat-ops))))
2553 (while (string-match "\\(\\s.\\|\\s(\\|\\s)\\)"
2555 (setq res (cons (aref op (match-beginning 1)) res)
2559 ;; Allow cpp operatios (where applicable).
2560 t (if (c-lang-const c-opt-cpp-prefix)
2561 (set-difference (c-lang-const c-block-prefix-disallowed-chars)
2563 (c-lang-const c-block-prefix-disallowed-chars))
2565 ;; Allow ':' for inherit list starters.
2566 (c++ objc idl) (set-difference (c-lang-const c-block-prefix-disallowed-chars)
2569 ;; Allow ',' for multiple inherits.
2570 (c++ java) (set-difference (c-lang-const c-block-prefix-disallowed-chars)
2573 ;; Allow parentheses for anonymous inner classes in Java and class
2574 ;; initializer lists in Pike.
2575 (java pike) (set-difference (c-lang-const c-block-prefix-disallowed-chars)
2578 ;; Allow '"' for extern clauses (e.g. extern "C" {...}).
2579 (c c++ objc) (set-difference (c-lang-const c-block-prefix-disallowed-chars)
2582 (c-lang-defconst c-block-prefix-charset
2583 ;; `c-block-prefix-disallowed-chars' as an inverted charset suitable
2584 ;; for `c-syntactic-skip-backward'.
2585 t (c-make-bare-char-alt (c-lang-const c-block-prefix-disallowed-chars) t))
2586 (c-lang-defvar c-block-prefix-charset (c-lang-const c-block-prefix-charset))
2588 (c-lang-defconst c-type-decl-prefix-key
2589 "Regexp matching the declarator operators that might precede the
2590 identifier in a declaration, e.g. the \"*\" in \"char *argv\". This
2591 regexp should match \"(\" if parentheses are valid in declarators.
2592 The end of the first submatch is taken as the end of the operator.
2593 Identifier syntax is in effect when this is matched \(see
2594 `c-identifier-syntax-table')."
2595 t (if (c-lang-const c-type-modifier-kwds)
2596 (concat (regexp-opt (c-lang-const c-type-modifier-kwds) t) "\\>")
2597 ;; Default to a regexp that never matches.
2599 ;; Check that there's no "=" afterwards to avoid matching tokens
2601 (c objc) (concat "\\("
2604 (c-lang-const c-type-decl-prefix-key)
2611 ;; If this matches there's special treatment in
2612 ;; `c-font-lock-declarators' and
2613 ;; `c-font-lock-declarations' that check for a
2614 ;; complete name followed by ":: *".
2615 (c-lang-const c-identifier-start)
2618 (c-lang-const c-type-decl-prefix-key)
2621 pike "\\(\\*\\)\\([^=]\\|$\\)")
2622 (c-lang-defvar c-type-decl-prefix-key (c-lang-const c-type-decl-prefix-key)
2625 (c-lang-defconst c-type-decl-suffix-key
2626 "Regexp matching the declarator operators that might follow after the
2627 identifier in a declaration, e.g. the \"[\" in \"char argv[]\". This
2628 regexp should match \")\" if parentheses are valid in declarators. If
2629 it matches an open paren of some kind, the type declaration check
2630 continues at the corresponding close paren, otherwise the end of the
2631 first submatch is taken as the end of the operator. Identifier syntax
2632 is in effect when this is matched (see `c-identifier-syntax-table')."
2633 ;; Default to a regexp that matches `c-type-modifier-kwds' and a
2634 ;; function argument list parenthesis.
2635 t (if (c-lang-const c-type-modifier-kwds)
2637 (regexp-opt (c-lang-const c-type-modifier-kwds) t) "\\>"
2640 (c c++ objc) (concat
2643 (if (c-lang-const c-type-modifier-kwds)
2646 ;; "throw" in `c-type-modifier-kwds' is followed
2647 ;; by a parenthesis list, but no extra measures
2648 ;; are necessary to handle that.
2649 (regexp-opt (c-lang-const c-type-modifier-kwds) t)
2653 (java idl) "\\([\[\(]\\)")
2654 (c-lang-defvar c-type-decl-suffix-key (c-lang-const c-type-decl-suffix-key)
2657 (c-lang-defconst c-after-suffixed-type-decl-key
2658 "This regexp is matched after a declarator expression where
2659 `c-type-decl-suffix-key' has matched. If it matches then the
2660 construct is taken as a declaration. It's typically used to match the
2661 beginning of a function body or whatever might occur after the
2662 function header in a function declaration or definition. It's
2663 undefined whether identifier syntax (see `c-identifier-syntax-table')
2664 is in effect or not.
2666 Note that it's used in cases like after \"foo (bar)\" so it should
2667 only match when it's certain that it's a declaration, e.g \"{\" but
2668 not \",\" or \";\"."
2670 ;; If K&R style declarations should be recognized then one could
2671 ;; consider to match the start of any symbol since we want to match
2672 ;; the start of the first declaration in the "K&R region". That
2673 ;; could however produce false matches on code like "FOO(bar) x"
2674 ;; where FOO is a cpp macro, so it's better to leave it out and rely
2675 ;; on the other heuristics in that case.
2676 t (if (c-lang-const c-postfix-spec-kwds)
2677 ;; Add on the keywords in `c-postfix-spec-kwds'.
2678 (concat (c-lang-const c-after-suffixed-type-decl-key)
2680 (c-make-keywords-re t (c-lang-const c-postfix-spec-kwds)))
2681 (c-lang-const c-after-suffixed-type-decl-key))
2682 ;; Also match the colon that starts a base class initializer list in
2683 ;; C++. That can be confused with a function call before the colon
2684 ;; in a ? : operator, but we count on that `c-decl-prefix-re' won't
2685 ;; match before such a thing (as a declaration-level construct;
2686 ;; matches inside arglist contexts are already excluded).
2688 (c-lang-defvar c-after-suffixed-type-decl-key
2689 (c-lang-const c-after-suffixed-type-decl-key)
2692 (c-lang-defconst c-after-suffixed-type-maybe-decl-key
2693 ;; Regexp that in addition to `c-after-suffixed-type-decl-key'
2694 ;; matches ";" and ",".
2695 t (concat "\\(" (c-lang-const c-after-suffixed-type-decl-key) "\\)"
2697 (c-lang-defvar c-after-suffixed-type-maybe-decl-key
2698 (c-lang-const c-after-suffixed-type-maybe-decl-key))
2700 (c-lang-defconst c-opt-type-concat-key
2701 "Regexp matching operators that concatenate types, e.g. the \"|\" in
2702 \"int|string\" in Pike. The end of the first submatch is taken as the
2703 end of the operator. nil in languages without such operators. It's
2704 undefined whether identifier syntax (see `c-identifier-syntax-table')
2705 is in effect or not."
2707 pike "\\([|.&]\\)\\($\\|[^|.&]\\)")
2708 (c-lang-defvar c-opt-type-concat-key (c-lang-const c-opt-type-concat-key)
2711 (c-lang-defconst c-opt-type-suffix-key
2712 "Regexp matching operators that might follow after a type, or nil in
2713 languages that don't have such operators. The end of the first
2714 submatch is taken as the end of the operator. This should not match
2715 things like C++ template arglists if `c-recognize-<>-arglists' is set.
2716 It's undefined whether identifier syntax (see `c-identifier-syntax-table')
2717 is in effect or not."
2719 (c c++ objc pike) "\\(\\.\\.\\.\\)"
2720 java (concat "\\(\\[" (c-lang-const c-simple-ws) "*\\]\\)"))
2721 (c-lang-defvar c-opt-type-suffix-key (c-lang-const c-opt-type-suffix-key))
2723 (c-lang-defvar c-known-type-key
2724 ;; Regexp matching the known type identifiers. This is initialized
2725 ;; from the type keywords and `*-font-lock-extra-types'. The first
2726 ;; submatch is the one that matches the type. Note that this regexp
2727 ;; assumes that symbol constituents like '_' and '$' have word
2730 (when (boundp (c-mode-symbol "font-lock-extra-types"))
2731 (c-mode-var "font-lock-extra-types")))
2734 (mapcar (lambda (re)
2735 (when (string-match "[][.*+?^$\\]" re)
2740 (mapcar (lambda (re)
2741 (unless (string-match "[][.*+?^$\\]" re)
2746 (append (list (c-make-keywords-re nil
2747 (append (c-lang-const c-primitive-type-kwds)
2753 (c-lang-defconst c-special-brace-lists
2754 "List of open- and close-chars that makes up a pike-style brace list,
2755 i.e. for a ([ ]) list there should be a cons (?\\[ . ?\\]) in this
2758 pike '((?{ . ?}) (?\[ . ?\]) (?< . ?>)))
2759 (c-lang-defvar c-special-brace-lists (c-lang-const c-special-brace-lists))
2761 (c-lang-defconst c-recognize-knr-p
2762 "Non-nil means K&R style argument declarations are valid."
2765 (c-lang-defvar c-recognize-knr-p (c-lang-const c-recognize-knr-p))
2767 (c-lang-defconst c-recognize-typeless-decls
2768 "Non-nil means function declarations without return type should be
2769 recognized. That can introduce an ambiguity with parenthesized macro
2770 calls before a brace block. This setting does not affect declarations
2771 that are preceded by a declaration starting keyword, so
2772 e.g. `c-typeless-decl-kwds' may still be used when it's set to nil."
2775 (c-lang-defvar c-recognize-typeless-decls
2776 (c-lang-const c-recognize-typeless-decls))
2778 (c-lang-defconst c-recognize-<>-arglists
2779 "Non-nil means C++ style template arglists should be handled. More
2780 specifically, this means a comma separated list of types or
2781 expressions surrounded by \"<\" and \">\". It's always preceded by an
2782 identifier or one of the keywords on `c-<>-type-kwds' or
2783 `c-<>-arglist-kwds'. If there's an identifier before then the whole
2784 expression is considered to be a type."
2785 t (or (consp (c-lang-const c-<>-type-kwds))
2786 (consp (c-lang-const c-<>-arglist-kwds))))
2787 (c-lang-defvar c-recognize-<>-arglists (c-lang-const c-recognize-<>-arglists))
2789 (c-lang-defconst c-recognize-paren-inits
2790 "Non-nil means that parenthesis style initializers exist,
2791 i.e. constructs like
2795 in addition to the more classic
2800 (c-lang-defvar c-recognize-paren-inits (c-lang-const c-recognize-paren-inits))
2802 (c-lang-defconst c-recognize-paren-inexpr-blocks
2803 "Non-nil to recognize gcc style in-expression blocks,
2804 i.e. compound statements surrounded by parentheses inside expressions."
2807 (c-lang-defvar c-recognize-paren-inexpr-blocks
2808 (c-lang-const c-recognize-paren-inexpr-blocks))
2810 (c-lang-defconst c-opt-<>-arglist-start
2811 ;; Regexp matching the start of angle bracket arglists in languages
2812 ;; where `c-recognize-<>-arglists' is set. Does not exclude
2813 ;; keywords outside `c-<>-arglist-kwds'. The first submatch is
2814 ;; assumed to surround the preceding symbol. The whole match is
2815 ;; assumed to end directly after the opening "<".
2816 t (if (c-lang-const c-recognize-<>-arglists)
2818 (c-lang-const c-symbol-key)
2820 (c-lang-const c-syntactic-ws)
2822 (c-lang-defvar c-opt-<>-arglist-start (c-lang-const c-opt-<>-arglist-start))
2824 (c-lang-defconst c-opt-<>-arglist-start-in-paren
2825 ;; Regexp that in addition to `c-opt-<>-arglist-start' matches close
2826 ;; parens. The first submatch is assumed to surround
2827 ;; `c-opt-<>-arglist-start'.
2828 t (if (c-lang-const c-opt-<>-arglist-start)
2830 (c-lang-const c-opt-<>-arglist-start)
2832 (c-lang-defvar c-opt-<>-arglist-start-in-paren
2833 (c-lang-const c-opt-<>-arglist-start-in-paren))
2835 (c-lang-defconst c-opt-postfix-decl-spec-key
2836 ;; Regexp matching the beginning of a declaration specifier in the
2837 ;; region between the header and the body of a declaration.
2839 ;; TODO: This is currently not used uniformly; c++-mode and
2840 ;; java-mode each have their own ways of using it.
2843 (c-lang-const c-simple-ws) "*"
2844 "\\(virtual" (c-lang-const c-simple-ws) "+\\)?\\("
2845 (c-make-keywords-re nil (c-lang-const c-protection-kwds))
2846 "\\)" (c-lang-const c-simple-ws) "+"
2847 "\\(" (c-lang-const c-symbol-key) "\\)")
2848 java (c-make-keywords-re t (c-lang-const c-postfix-spec-kwds)))
2849 (c-lang-defvar c-opt-postfix-decl-spec-key
2850 (c-lang-const c-opt-postfix-decl-spec-key))
2852 (c-lang-defconst c-recognize-colon-labels
2853 "Non-nil if generic labels ending with \":\" should be recognized.
2854 That includes labels in code and access keys in classes. This does
2855 not apply to labels recognized by `c-label-kwds' and
2856 `c-opt-extra-label-key'."
2858 (c c++ objc java pike) t)
2859 (c-lang-defvar c-recognize-colon-labels
2860 (c-lang-const c-recognize-colon-labels))
2862 (c-lang-defconst c-label-prefix-re
2863 "Regexp like `c-decl-prefix-re' that matches any token that can precede
2864 a generic colon label. Not used if `c-recognize-colon-labels' is
2867 (c-lang-defvar c-label-prefix-re
2868 (c-lang-const c-label-prefix-re))
2870 (c-lang-defconst c-nonlabel-token-key
2871 "Regexp matching things that can't occur in generic colon labels,
2872 neither in a statement nor in a declaration context. The regexp is
2873 tested at the beginning of every sexp in a suspected label,
2874 i.e. before \":\". Only used if `c-recognize-colon-labels' is set."
2876 ;; Don't allow string literals.
2878 ;; All keywords except `c-label-kwds' and `c-protection-kwds'.
2879 (c-make-keywords-re t
2880 (set-difference (c-lang-const c-keywords)
2881 (append (c-lang-const c-label-kwds)
2882 (c-lang-const c-protection-kwds))
2883 :test 'string-equal)))
2884 ;; Also check for open parens in C++, to catch member init lists in
2885 ;; constructors. We normally allow it so that macros with arguments
2887 c++ (concat "\\s\(\\|" (c-lang-const c-nonlabel-token-key)))
2888 (c-lang-defvar c-nonlabel-token-key (c-lang-const c-nonlabel-token-key))
2890 (c-lang-defconst c-opt-extra-label-key
2891 "Optional regexp matching labels.
2892 Normally, labels are detected according to `c-nonlabel-token-key',
2893 `c-decl-prefix-re' and `c-nonlabel-decl-prefix-re'. This regexp can
2894 be used if there are additional labels that aren't recognized that
2897 objc (c-make-keywords-re t (c-lang-const c-protection-kwds)))
2898 (c-lang-defvar c-opt-extra-label-key (c-lang-const c-opt-extra-label-key))
2900 (c-lang-defconst c-opt-friend-key
2901 ;; Regexp describing friend declarations classes, or nil in
2902 ;; languages that don't have such things.
2904 ;; TODO: Ought to use `c-prefix-spec-kwds-re' or similar, and the
2905 ;; template skipping isn't done properly. This will disappear soon.
2907 c++ (concat "friend" (c-lang-const c-simple-ws) "+"
2910 (c-lang-const c-simple-ws) "*"
2912 (c-lang-const c-simple-ws) "*"
2914 (c-lang-const c-simple-ws) "+")))
2915 (c-lang-defvar c-opt-friend-key (c-lang-const c-opt-friend-key))
2917 (c-lang-defconst c-opt-method-key
2918 ;; Special regexp to match the start of Objective-C methods. The
2919 ;; first submatch is assumed to end after the + or - key.
2922 ;; TODO: Ought to use a better method than anchoring on bol.
2925 (c-lang-const c-simple-ws) "*"
2926 (concat "\\(" ; Return type.
2928 (c-lang-const c-simple-ws) "*"
2930 "\\(" (c-lang-const c-symbol-key) "\\)"))
2931 (c-lang-defvar c-opt-method-key (c-lang-const c-opt-method-key))
2933 (c-lang-defconst c-type-decl-end-used
2934 ;; Must be set in buffers where the `c-type' text property might be
2935 ;; used with the value `c-decl-end'.
2937 ;; `c-decl-end' is used to mark the ends of labels and access keys
2938 ;; to make interactive refontification work better.
2939 t (or (c-lang-const c-recognize-colon-labels)
2940 (and (c-lang-const c-label-kwds) t))
2941 ;; `c-decl-end' is used to mark the end of the @-style directives in
2944 (c-lang-defvar c-type-decl-end-used (c-lang-const c-type-decl-end-used))
2947 ;;; Wrap up the `c-lang-defvar' system.
2949 ;; Compile in the list of language variables that has been collected
2950 ;; with the `c-lang-defvar' and `c-lang-setvar' macros. Note that the
2951 ;; first element of each is nil.
2952 (defconst c-lang-variable-inits (cc-eval-when-compile c-lang-variable-inits))
2953 (defconst c-emacs-variable-inits (cc-eval-when-compile c-emacs-variable-inits))
2955 ;; Make the `c-lang-setvar' variables buffer local in the current buffer.
2956 ;; These are typically standard emacs variables such as `comment-start'.
2957 (defmacro c-make-emacs-variables-local ()
2959 ,@(mapcar (lambda (init)
2960 `(make-local-variable ',(car init)))
2961 (cdr c-emacs-variable-inits))))
2963 (defun c-make-init-lang-vars-fun (mode)
2964 "Create a function that initializes all the language dependent variables
2967 This function should be evaluated at compile time, so that the
2968 function it returns is byte compiled with all the evaluated results
2969 from the language constants. Use the `c-init-language-vars' macro to
2970 accomplish that conveniently."
2972 (if (and (not load-in-progress)
2973 (boundp 'byte-compile-dest-file)
2974 (stringp byte-compile-dest-file))
2976 ;; No need to byte compile this lambda since the byte compiler is
2977 ;; smart enough to detect the `funcall' construct in the
2978 ;; `c-init-language-vars' macro below and compile it all straight
2979 ;; into the function that contains `c-init-language-vars'.
2982 ;; This let sets up the context for `c-mode-var' and similar
2983 ;; that could be in the result from `cl-macroexpand-all'.
2984 (let ((c-buffer-is-cc-mode ',mode)
2985 current-var source-eval)
2986 (c-make-emacs-variables-local)
2989 (if (eq c-version-sym ',c-version-sym)
2990 (setq ,@(let ((c-buffer-is-cc-mode mode)
2991 (c-lang-const-expansion 'immediate))
2992 ;; `c-lang-const' will expand to the evaluated
2993 ;; constant immediately in `cl-macroexpand-all'
2997 `(current-var ',(car init)
2998 ,(car init) ,(cl-macroexpand-all
3000 ;; Note: The following `append' copies the
3001 ;; first argument. That list is small, so
3002 ;; this doesn't matter too much.
3003 (append (cdr c-emacs-variable-inits)
3004 (cdr c-lang-variable-inits)))))
3006 ;; This diagnostic message isn't useful for end
3007 ;; users, so it's disabled.
3008 ;;(unless (get ',mode 'c-has-warned-lang-consts)
3009 ;; (message ,(concat "%s compiled with CC Mode %s "
3010 ;; "but loaded with %s - evaluating "
3011 ;; "language constants from source")
3012 ;; ',mode ,c-version c-version)
3013 ;; (put ',mode 'c-has-warned-lang-consts t))
3016 (setq source-eval t)
3017 (let ((init (append (cdr c-emacs-variable-inits)
3018 (cdr c-lang-variable-inits))))
3020 (setq current-var (caar init))
3021 (set (caar init) (eval (cadar init)))
3022 (setq init (cdr init)))))
3026 (message "Eval error in the `c-lang-defvar' or `c-lang-setvar' for `%s'%s: %S"
3030 (fallback source eval - %s compiled with CC Mode %s but loaded with %s)"
3031 ',mode ,c-version c-version)
3034 (signal (car err) (cdr err)))))))
3036 ;; Being evaluated from source. Always use the dynamic method to
3037 ;; work well when `c-lang-defvar's in this file are reevaluated
3041 (let ((c-buffer-is-cc-mode ',mode)
3042 (init (append (cdr c-emacs-variable-inits)
3043 (cdr c-lang-variable-inits)))
3045 (c-make-emacs-variables-local)
3049 (setq current-var (caar init))
3050 (set (caar init) (eval (cadar init)))
3051 (setq init (cdr init)))
3056 "Eval error in the `c-lang-defvar' or `c-lang-setver' for `%s' (source eval): %S"
3058 (signal (car err) (cdr err)))))))
3061 (defmacro c-init-language-vars (mode)
3062 "Initialize all the language dependent variables for the given mode.
3063 This macro is expanded at compile time to a form tailored for the mode
3064 in question, so MODE must be a constant. Therefore MODE is not
3065 evaluated and should not be quoted."
3066 `(funcall ,(c-make-init-lang-vars-fun mode)))
3069 (cc-provide 'cc-langs)
3071 ;; arch-tag: 1ab57482-cfc2-4c5b-b628-3539c3098822
3072 ;;; cc-langs.el ends here