(cvs-retrieve-revision): Use decode-coding-inserted-region.
[emacs.git] / lisp / progmodes / cc-langs.el
blob8120094f606d2dea2fa2c133468c74dad9c7b941
1 ;;; cc-langs.el --- language specific settings for CC Mode
3 ;; Copyright (C) 1985,1987,1992-2003, 2004, 2005, 2006 Free Software
4 ;; Foundation, Inc.
6 ;; Authors: 1998- Martin Stjernholm
7 ;; 1992-1999 Barry A. Warsaw
8 ;; 1987 Dave Detlefs and Stewart Clamen
9 ;; 1985 Richard M. Stallman
10 ;; Maintainer: bug-cc-mode@gnu.org
11 ;; Created: 22-Apr-1997 (split from cc-mode.el)
12 ;; Version: See cc-mode.el
13 ;; Keywords: c languages oop
15 ;; This file is part of GNU Emacs.
17 ;; GNU Emacs is free software; you can redistribute it and/or modify
18 ;; it under the terms of the GNU General Public License as published by
19 ;; the Free Software Foundation; either version 2, or (at your option)
20 ;; any later version.
22 ;; GNU Emacs is distributed in the hope that it will be useful,
23 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
24 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 ;; GNU General Public License for more details.
27 ;; You should have received a copy of the GNU General Public License
28 ;; along with this program; see the file COPYING. If not, write to
29 ;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
30 ;; Boston, MA 02110-1301, USA.
32 ;;; Commentary:
34 ;; HACKERS NOTE: There's heavy macro magic here. If you need to make
35 ;; changes in this or other files containing `c-lang-defconst' but
36 ;; don't want to read through the longer discussion below then read
37 ;; this:
39 ;; o A change in a `c-lang-defconst' or `c-lang-defvar' will not take
40 ;; effect if the file containing the mode init function (typically
41 ;; cc-mode.el) is byte compiled.
42 ;; o To make changes show in font locking you need to reevaluate the
43 ;; `*-font-lock-keywords-*' constants, which normally is easiest to
44 ;; do with M-x eval-buffer in cc-fonts.el.
45 ;; o In either case it's necessary to reinitialize the mode to make
46 ;; the changes show in an existing buffer.
48 ;;; Introduction to the language dependent variable system:
50 ;; This file contains all the language dependent variables, except
51 ;; those specific for font locking which reside in cc-fonts.el. As
52 ;; far as possible, all the differences between the languages that CC
53 ;; Mode supports are described with these variables only, so that the
54 ;; code can be shared.
56 ;; The language constant system (see cc-defs.el) is used to specify
57 ;; various language dependent info at a high level, such as lists of
58 ;; keywords, and then from them generate - at compile time - the
59 ;; various regexps and other low-level structures actually employed in
60 ;; the code at runtime.
62 ;; This system is also designed to make it easy for developers of
63 ;; derived modes to customize the source constants for new language
64 ;; variants, without having to keep up with the exact regexps etc that
65 ;; are used in each CC Mode version. It's possible from an external
66 ;; package to add a new language by inheriting an existing one, and
67 ;; then change specific constants as necessary for the new language.
68 ;; The old values for those constants (and the values of all the other
69 ;; high-level constants) may be used to build the new ones, and those
70 ;; new values will in turn be used by the low-level definitions here
71 ;; to build the runtime constants appropriately for the new language
72 ;; in the current version of CC Mode.
74 ;; Like elsewhere in CC Mode, the existence of a doc string signifies
75 ;; that a language constant is part of the external API, and that it
76 ;; therefore can be used with a high confidence that it will continue
77 ;; to work with future versions of CC Mode. Even so, it's not
78 ;; unlikely that such constants will change meaning slightly as this
79 ;; system is refined further; a certain degree of dependence on the CC
80 ;; Mode version is unavoidable when hooking in at this level. Also
81 ;; note that there's still work to be done to actually use these
82 ;; constants everywhere inside CC Mode; there are still hardcoded
83 ;; values in many places in the code.
85 ;; Separate packages will also benefit from the compile time
86 ;; evaluation; the byte compiled file(s) for them will contain the
87 ;; compiled runtime constants ready for use by (the byte compiled) CC
88 ;; Mode, and the source definitions in this file don't have to be
89 ;; loaded then. However, if a byte compiled package is loaded that
90 ;; has been compiled with a different version of CC Mode than the one
91 ;; currently loaded, then the compiled-in values will be discarded and
92 ;; new ones will be built when the mode is initialized. That will
93 ;; automatically trig a load of the file(s) containing the source
94 ;; definitions (i.e. this file and/or cc-fonts.el) if necessary.
96 ;; A small example of a derived mode is available at
97 ;; <http://cc-mode.sourceforge.net/derived-mode-ex.el>. It also
98 ;; contains some useful hints for derived mode developers.
100 ;;; Using language variables:
102 ;; The `c-lang-defvar' forms in this file comprise the language
103 ;; variables that CC Mode uses. It does not work to use
104 ;; `c-lang-defvar' anywhere else (which isn't much of a limitation
105 ;; since these variables sole purpose is to interface with the CC Mode
106 ;; core functions). The values in these `c-lang-defvar's are not
107 ;; evaluated right away but instead collected to a single large `setq'
108 ;; that can be inserted for a particular language with the
109 ;; `c-init-language-vars' macro.
111 ;; This file is only required at compile time, or when not running
112 ;; from byte compiled files, or when the source definitions for the
113 ;; language constants are requested.
115 ;;; Code:
117 (eval-when-compile
118 (let ((load-path
119 (if (and (boundp 'byte-compile-dest-file)
120 (stringp byte-compile-dest-file))
121 (cons (file-name-directory byte-compile-dest-file) load-path)
122 load-path)))
123 (load "cc-bytecomp" nil t)))
125 (cc-require 'cc-defs)
126 (cc-require 'cc-vars)
129 ;; This file is not always loaded. See note above.
130 (cc-external-require 'cl)
133 ;;; Setup for the `c-lang-defvar' system.
135 (eval-and-compile
136 ;; These are used to collect the init forms from the subsequent
137 ;; `c-lang-defvar'. They are used to build the lambda in
138 ;; `c-make-init-lang-vars-fun' below.
139 (defvar c-lang-variable-inits nil)
140 (defvar c-lang-variable-inits-tail nil)
141 (setq c-lang-variable-inits (list nil)
142 c-lang-variable-inits-tail c-lang-variable-inits))
144 (defmacro c-lang-defvar (var val &optional doc)
145 "Declares the buffer local variable VAR to get the value VAL. VAL is
146 evaluated and assigned at mode initialization. More precisely, VAL is
147 evaluated and bound to VAR when the result from the macro
148 `c-init-language-vars' is evaluated.
150 `c-lang-const' is typically used in VAL to get the right value for the
151 language being initialized, and such calls will be macro expanded to
152 the evaluated constant value at compile time."
154 (when (and (not doc)
155 (eq (car-safe val) 'c-lang-const)
156 (eq (nth 1 val) var)
157 (not (nth 2 val)))
158 ;; Special case: If there's no docstring and the value is a
159 ;; simple (c-lang-const foo) where foo is the same name as VAR
160 ;; then take the docstring from the language constant foo.
161 (setq doc (get (intern (symbol-name (nth 1 val)) c-lang-constants)
162 'variable-documentation)))
163 (or (stringp doc)
164 (setq doc nil))
166 (let ((elem (assq var (cdr c-lang-variable-inits))))
167 (if elem
168 (setcdr elem (list val doc))
169 (setcdr c-lang-variable-inits-tail (list (list var val doc)))
170 (setq c-lang-variable-inits-tail (cdr c-lang-variable-inits-tail))))
172 ;; Return the symbol, like the other def* forms.
173 `',var)
175 (put 'c-lang-defvar 'lisp-indent-function 'defun)
176 (eval-after-load "edebug"
177 '(def-edebug-spec c-lang-defvar
178 (&define name def-form &optional stringp)))
180 (eval-and-compile
181 ;; Some helper functions used when building the language constants.
183 (defun c-filter-ops (ops opgroup-filter op-filter &optional xlate)
184 ;; Used to filter operators from the list OPS in a DWIM:ey way:
185 ;; OPS either has the structure of `c-operators', as a single
186 ;; group in `c-operators', or is a plain list of operators.
187 ;; OPGROUP-FILTER is used filter out the operator groups. It can
188 ;; be t to choose all groups, a list of the group type symbols to
189 ;; accept, or a function which will be called with the group
190 ;; symbol for each group and should return non-nil for those to
191 ;; include. OP-FILTER filters the individual operators in each
192 ;; group. It can be t to choose all operators, a regexp to test
193 ;; against each operator, or a function which will be called for
194 ;; each operator and should return non-nil for those to include.
195 ;; If XLATE is given, it's a function which is called for each
196 ;; matching operator and its return value is collected instead.
197 ;; If it returns a list, the elements are spliced directly into
198 ;; the final result, which is returned as a list with duplicates
199 ;; removed using `equal'. `c-mode-syntax-table' for the current
200 ;; mode is in effect during the whole procedure.
201 (unless (listp (car-safe ops))
202 (setq ops (list ops)))
203 (cond ((eq opgroup-filter t)
204 (setq opgroup-filter (lambda (opgroup) t)))
205 ((not (functionp opgroup-filter))
206 (setq opgroup-filter `(lambda (opgroup)
207 (memq opgroup ',opgroup-filter)))))
208 (cond ((eq op-filter t)
209 (setq op-filter (lambda (op) t)))
210 ((stringp op-filter)
211 (setq op-filter `(lambda (op)
212 (string-match ,op-filter op)))))
213 (unless xlate
214 (setq xlate 'identity))
215 (c-with-syntax-table (c-lang-const c-mode-syntax-table)
216 (delete-duplicates
217 (mapcan (lambda (opgroup)
218 (when (if (symbolp (car opgroup))
219 (when (funcall opgroup-filter (car opgroup))
220 (setq opgroup (cdr opgroup))
223 (mapcan (lambda (op)
224 (when (funcall op-filter op)
225 (let ((res (funcall xlate op)))
226 (if (listp res) res (list res)))))
227 opgroup)))
228 ops)
229 :test 'equal))))
232 ;;; Various mode specific values that aren't language related.
234 (c-lang-defconst c-mode-menu
235 ;; The definition for the mode menu. The menu title is prepended to
236 ;; this before it's fed to `easy-menu-define'.
237 t `(["Comment Out Region" comment-region
238 (c-fn-region-is-active-p)]
239 ["Uncomment Region" (comment-region (region-beginning)
240 (region-end) '(4))
241 (c-fn-region-is-active-p)]
242 ["Indent Expression" c-indent-exp
243 (memq (char-after) '(?\( ?\[ ?\{))]
244 ["Indent Line or Region" c-indent-line-or-region t]
245 ["Fill Comment Paragraph" c-fill-paragraph t]
246 "----"
247 ["Backward Statement" c-beginning-of-statement t]
248 ["Forward Statement" c-end-of-statement t]
249 ,@(when (c-lang-const c-opt-cpp-prefix)
250 ;; Only applicable if there's a cpp preprocessor.
251 `(["Up Conditional" c-up-conditional t]
252 ["Backward Conditional" c-backward-conditional t]
253 ["Forward Conditional" c-forward-conditional t]
254 "----"
255 ["Macro Expand Region" c-macro-expand
256 (c-fn-region-is-active-p)]
257 ["Backslashify" c-backslash-region
258 (c-fn-region-is-active-p)]))
259 "----"
260 ("Toggle..."
261 ["Syntactic indentation" c-toggle-syntactic-indentation
262 :style toggle :selected c-syntactic-indentation]
263 ["Electric mode" c-toggle-electric-state
264 :style toggle :selected c-electric-flag]
265 ["Auto newline" c-toggle-auto-newline
266 :style toggle :selected c-auto-newline]
267 ["Hungry delete" c-toggle-hungry-state
268 :style toggle :selected c-hungry-delete-key]
269 ["Subword mode" c-subword-mode
270 :style toggle :selected (and (boundp 'c-subword-mode)
271 c-subword-mode)])))
274 ;;; Syntax tables.
276 (defun c-populate-syntax-table (table)
277 "Populate the given syntax table as necessary for a C-like language.
278 This includes setting ' and \" as string delimiters, and setting up
279 the comment syntax to handle both line style \"//\" and block style
280 \"/*\" \"*/\" comments."
282 (modify-syntax-entry ?_ "_" table)
283 (modify-syntax-entry ?\\ "\\" table)
284 (modify-syntax-entry ?+ "." table)
285 (modify-syntax-entry ?- "." table)
286 (modify-syntax-entry ?= "." table)
287 (modify-syntax-entry ?% "." table)
288 (modify-syntax-entry ?< "." table)
289 (modify-syntax-entry ?> "." table)
290 (modify-syntax-entry ?& "." table)
291 (modify-syntax-entry ?| "." table)
292 (modify-syntax-entry ?\' "\"" table)
293 (modify-syntax-entry ?\240 "." table)
295 ;; Set up block and line oriented comments. The new C
296 ;; standard mandates both comment styles even in C, so since
297 ;; all languages now require dual comments, we make this the
298 ;; default.
299 (cond
300 ;; XEmacs
301 ((memq '8-bit c-emacs-features)
302 (modify-syntax-entry ?/ ". 1456" table)
303 (modify-syntax-entry ?* ". 23" table))
304 ;; Emacs
305 ((memq '1-bit c-emacs-features)
306 (modify-syntax-entry ?/ ". 124b" table)
307 (modify-syntax-entry ?* ". 23" table))
308 ;; incompatible
309 (t (error "CC Mode is incompatible with this version of Emacs")))
311 (modify-syntax-entry ?\n "> b" table)
312 ;; Give CR the same syntax as newline, for selective-display
313 (modify-syntax-entry ?\^m "> b" table))
315 (c-lang-defconst c-make-mode-syntax-table
316 "Functions that generates the mode specific syntax tables.
317 The syntax tables aren't stored directly since they're quite large."
318 t `(lambda ()
319 (let ((table (make-syntax-table)))
320 (c-populate-syntax-table table)
321 ;; Mode specific syntaxes.
322 ,(cond ((c-major-mode-is 'objc-mode)
323 ;; Let '@' be part of symbols in ObjC to cope with
324 ;; its compiler directives as single keyword tokens.
325 ;; This is then necessary since it's assumed that
326 ;; every keyword is a single symbol.
327 `(modify-syntax-entry ?@ "_" table))
328 ((c-major-mode-is 'pike-mode)
329 `(modify-syntax-entry ?@ "." table)))
330 table)))
332 (c-lang-defconst c-mode-syntax-table
333 ;; The syntax tables in evaluated form. Only used temporarily when
334 ;; the constants in this file are evaluated.
335 t (funcall (c-lang-const c-make-mode-syntax-table)))
337 (c-lang-defconst c++-make-template-syntax-table
338 ;; A variant of `c++-mode-syntax-table' that defines `<' and `>' as
339 ;; parenthesis characters. Used temporarily when template argument
340 ;; lists are parsed. Note that this encourages incorrect parsing of
341 ;; templates since they might contain normal operators that uses the
342 ;; '<' and '>' characters. Therefore this syntax table might go
343 ;; away when CC Mode handles templates correctly everywhere.
344 t nil
345 c++ `(lambda ()
346 (let ((table (funcall ,(c-lang-const c-make-mode-syntax-table))))
347 (modify-syntax-entry ?< "(>" table)
348 (modify-syntax-entry ?> ")<" table)
349 table)))
350 (c-lang-defvar c++-template-syntax-table
351 (and (c-lang-const c++-make-template-syntax-table)
352 (funcall (c-lang-const c++-make-template-syntax-table))))
354 (c-lang-defconst c-identifier-syntax-modifications
355 "A list that describes the modifications that should be done to the
356 mode syntax table to get a syntax table that matches all identifiers
357 and keywords as words.
359 The list is just like the one used in `font-lock-defaults': Each
360 element is a cons where the car is the character to modify and the cdr
361 the new syntax, as accepted by `modify-syntax-entry'."
362 ;; The $ character is not allowed in most languages (one exception
363 ;; is Java which allows it for legacy reasons) but we still classify
364 ;; it as an indentifier character since it's often used in various
365 ;; machine generated identifiers.
366 t '((?_ . "w") (?$ . "w"))
367 objc (append '((?@ . "w"))
368 (c-lang-const c-identifier-syntax-modifications))
369 awk '((?_ . "w")))
370 (c-lang-defvar c-identifier-syntax-modifications
371 (c-lang-const c-identifier-syntax-modifications))
373 (c-lang-defvar c-identifier-syntax-table
374 (let ((table (copy-syntax-table (c-mode-var "mode-syntax-table")))
375 (mods c-identifier-syntax-modifications)
376 mod)
377 (while mods
378 (setq mod (car mods)
379 mods (cdr mods))
380 (modify-syntax-entry (car mod) (cdr mod) table))
381 table)
382 "Syntax table built on the mode syntax table but additionally
383 classifies symbol constituents like '_' and '$' as word constituents,
384 so that all identifiers are recognized as words.")
387 ;;; Lexer-level syntax (identifiers, tokens etc).
389 (c-lang-defconst c-symbol-start
390 "Regexp that matches the start of a symbol, i.e. any identifier or
391 keyword. It's unspecified how far it matches. Does not contain a \\|
392 operator at the top level."
393 t (concat "[" c-alpha "_]")
394 objc (concat "[" c-alpha "@]")
395 pike (concat "[" c-alpha "_`]"))
396 (c-lang-defvar c-symbol-start (c-lang-const c-symbol-start))
398 (c-lang-defconst c-symbol-chars
399 "Set of characters that can be part of a symbol.
400 This is on the form that fits inside [ ] in a regexp."
401 ;; Pike note: With the backquote identifiers this would include most
402 ;; operator chars too, but they are handled with other means instead.
403 t (concat c-alnum "_$")
404 objc (concat c-alnum "_$@"))
406 (c-lang-defconst c-symbol-key
407 "Regexp matching identifiers and keywords (with submatch 0). Assumed
408 to match if `c-symbol-start' matches on the same position."
409 t (concat (c-lang-const c-symbol-start)
410 "[" (c-lang-const c-symbol-chars) "]*")
411 pike (concat
412 ;; Use the value from C here since the operator backquote is
413 ;; covered by the other alternative.
414 (c-lang-const c-symbol-key c)
415 "\\|"
416 (c-make-keywords-re nil
417 (c-lang-const c-overloadable-operators))))
418 (c-lang-defvar c-symbol-key (c-lang-const c-symbol-key))
420 (c-lang-defconst c-symbol-key-depth
421 ;; Number of regexp grouping parens in `c-symbol-key'.
422 t (regexp-opt-depth (c-lang-const c-symbol-key)))
424 (c-lang-defconst c-nonsymbol-chars
425 "This is the set of chars that can't be part of a symbol, i.e. the
426 negation of `c-symbol-chars'."
427 t (concat "^" (c-lang-const c-symbol-chars)))
428 (c-lang-defvar c-nonsymbol-chars (c-lang-const c-nonsymbol-chars))
430 (c-lang-defconst c-nonsymbol-key
431 "Regexp that matches any character that can't be part of a symbol.
432 It's usually appended to other regexps to avoid matching a prefix.
433 It's assumed to not contain any submatchers."
434 ;; The same thing regarding Unicode identifiers applies here as to
435 ;; `c-symbol-key'.
436 t (concat "[" (c-lang-const c-nonsymbol-chars) "]"))
438 (c-lang-defconst c-identifier-ops
439 "The operators that make up fully qualified identifiers. nil in
440 languages that don't have such things. See `c-operators' for a
441 description of the format. Binary operators can concatenate symbols,
442 e.g. \"::\" in \"A::B::C\". Prefix operators can precede identifiers,
443 e.g. \"~\" in \"~A::B\". Other types of operators aren't supported.
445 This value is by default merged into `c-operators'."
446 t nil
447 c++ '((prefix "~" "??-" "compl")
448 (right-assoc "::")
449 (prefix "::"))
450 ;; Java has "." to concatenate identifiers but it's also used for
451 ;; normal indexing. There's special code in the Java font lock
452 ;; rules to fontify qualified identifiers based on the standard
453 ;; naming conventions. We still define "." here to make
454 ;; `c-forward-name' move over as long names as possible which is
455 ;; necessary to e.g. handle throws clauses correctly.
456 java '((left-assoc "."))
457 idl '((left-assoc "::")
458 (prefix "::"))
459 pike '((left-assoc "::")
460 (prefix "::")
461 (left-assoc ".")))
463 (c-lang-defconst c-opt-identifier-concat-key
464 ;; Appendable adorned regexp matching the operators that join
465 ;; symbols to fully qualified identifiers, or nil in languages that
466 ;; don't have such things.
468 ;; This was a docstring constant in 5.30. It still works but is now
469 ;; considered internal - change `c-identifier-ops' instead.
470 t (let ((ops (c-filter-ops (c-lang-const c-identifier-ops)
471 '(left-assoc right-assoc)
472 t)))
473 (when ops
474 (c-make-keywords-re 'appendable ops))))
475 (c-lang-defvar c-opt-identifier-concat-key
476 (c-lang-const c-opt-identifier-concat-key)
477 'dont-doc)
479 (c-lang-defconst c-opt-identifier-concat-key-depth
480 ;; Number of regexp grouping parens in `c-opt-identifier-concat-key'.
481 t (regexp-opt-depth (c-lang-const c-opt-identifier-concat-key)))
483 (c-lang-defconst c-opt-identifier-prefix-key
484 ;; Appendable adorned regexp matching operators that might precede
485 ;; an identifier and that are part of the identifier in that case.
486 ;; nil in languages without such things.
487 t (let ((ops (c-filter-ops (c-lang-const c-identifier-ops)
488 '(prefix)
489 t)))
490 (when ops
491 (c-make-keywords-re 'appendable ops))))
493 (c-lang-defconst c-after-id-concat-ops
494 "Operators that can occur after a binary operator on `c-identifier-ops'
495 in identifiers. nil in languages that don't have such things.
497 Operators here should also have appropriate entries in `c-operators' -
498 it's not taken care of by default."
499 t nil
500 ;; '~' for destructors in C++, '*' for member pointers.
501 c++ '("~" "*")
502 ;; In Java we recognize '*' to deal with "foo.bar.*" that can occur
503 ;; in import declarations. (This will also match bogus things like
504 ;; "foo.*bar" but we don't bother.)
505 java '("*"))
507 (c-lang-defconst c-opt-after-id-concat-key
508 ;; Regexp that must match the token after
509 ;; `c-opt-identifier-concat-key' for it to be considered an
510 ;; identifier concatenation operator (which e.g. causes the
511 ;; preceding identifier to be fontified as a reference). Assumed to
512 ;; be a string if `c-opt-identifier-concat-key' is.
514 ;; This was a docstring constant in 5.30. It still works but is now
515 ;; considered internal - change `c-after-id-concat-ops' instead.
516 t (concat (c-lang-const c-symbol-start)
517 (if (c-lang-const c-after-id-concat-ops)
518 (concat "\\|" (c-make-keywords-re 'appendable
519 (c-lang-const c-after-id-concat-ops)))
520 "")))
522 (c-lang-defconst c-identifier-start
523 "Regexp that matches the start of an (optionally qualified) identifier.
524 It should also match all keywords. It's unspecified how far it
525 matches."
526 t (concat (c-lang-const c-symbol-start)
527 (if (c-lang-const c-opt-identifier-prefix-key)
528 (concat "\\|"
529 (c-lang-const c-opt-identifier-prefix-key))
530 "")))
531 (c-lang-defvar c-identifier-start (c-lang-const c-identifier-start))
533 (c-lang-defconst c-identifier-key
534 "Regexp matching a fully qualified identifier, like \"A::B::c\" in
535 C++. It does not recognize the full range of syntactic whitespace
536 between the tokens; `c-forward-name' has to be used for that. It
537 should also not match identifiers containing parenthesis groupings,
538 e.g. identifiers with template arguments such as \"A<X,Y>\" in C++."
539 ;; This regexp is more complex than strictly necessary to ensure
540 ;; that it can be matched with a minimum of backtracking.
541 t (concat (if (c-lang-const c-opt-identifier-prefix-key)
542 (concat
543 "\\("
544 (c-lang-const c-opt-identifier-prefix-key)
545 (c-lang-const c-simple-ws) "*"
546 "\\)?")
548 "\\(" (c-lang-const c-symbol-key) "\\)"
549 (if (c-lang-const c-opt-identifier-concat-key)
550 (concat
551 "\\("
552 (c-lang-const c-simple-ws) "*"
553 (c-lang-const c-opt-identifier-concat-key)
554 (c-lang-const c-simple-ws) "*"
555 (if (c-lang-const c-after-id-concat-ops)
556 (concat
557 "\\("
558 (c-make-keywords-re 'appendable
559 (c-lang-const c-after-id-concat-ops))
560 (concat
561 ;; For flexibility, consider the symbol match
562 ;; optional if we've hit a
563 ;; `c-after-id-concat-ops' operator. This is
564 ;; also necessary to handle the "*" that can
565 ;; end import declaration identifiers in Java.
566 "\\("
567 (c-lang-const c-simple-ws) "*"
568 "\\(" (c-lang-const c-symbol-key) "\\)"
569 "\\)?")
570 "\\|"
571 "\\(" (c-lang-const c-symbol-key) "\\)"
572 "\\)")
573 (concat "\\(" (c-lang-const c-symbol-key) "\\)"))
574 "\\)*")
575 "")))
576 (c-lang-defvar c-identifier-key (c-lang-const c-identifier-key))
578 (c-lang-defconst c-identifier-last-sym-match
579 ;; This was a docstring constant in 5.30 but it's no longer used.
580 ;; It's only kept to avoid breaking third party code.
582 ;; Used to identify the submatch in `c-identifier-key' that
583 ;; surrounds the last symbol in the qualified identifier. It's a
584 ;; list of submatch numbers, of which the first that has a match is
585 ;; taken. It's assumed that at least one does when the regexp has
586 ;; matched.
587 t nil)
589 (c-lang-defconst c-string-escaped-newlines
590 "Set if the language support backslash escaped newlines inside string
591 literals."
592 t nil
593 (c c++ objc pike) t)
594 (c-lang-defvar c-string-escaped-newlines
595 (c-lang-const c-string-escaped-newlines))
597 (c-lang-defconst c-multiline-string-start-char
598 "Set if the language supports multiline string literals without escaped
599 newlines. If t, all string literals are multiline. If a character,
600 only literals where the open quote is immediately preceded by that
601 literal are multiline."
602 t nil
603 pike ?#)
604 (c-lang-defvar c-multiline-string-start-char
605 (c-lang-const c-multiline-string-start-char))
607 (c-lang-defconst c-opt-cpp-prefix
608 "Regexp matching the prefix of a cpp directive in the languages that
609 normally use that macro preprocessor. Tested at bol or at boi.
610 Assumed to not contain any submatches or \\| operators."
611 ;; TODO (ACM, 2005-04-01). Amend the following to recognise escaped NLs;
612 ;; amend all uses of c-opt-cpp-prefix which count regexp-depth.
613 t "\\s *#\\s *"
614 (java awk) nil)
615 (c-lang-defvar c-opt-cpp-prefix (c-lang-const c-opt-cpp-prefix))
617 (c-lang-defconst c-opt-cpp-start
618 "Regexp matching the prefix of a cpp directive including the directive
619 name, or nil in languages without preprocessor support. The first
620 submatch surrounds the directive name."
621 t (if (c-lang-const c-opt-cpp-prefix)
622 (concat (c-lang-const c-opt-cpp-prefix)
623 "\\([" c-alnum "]+\\)"))
624 ;; Pike, being a scripting language, recognizes hash-bangs too.
625 pike (concat (c-lang-const c-opt-cpp-prefix)
626 "\\([" c-alnum "]+\\|!\\)"))
627 (c-lang-defvar c-opt-cpp-start (c-lang-const c-opt-cpp-start))
629 (c-lang-defconst c-cpp-message-directives
630 "List of cpp directives (without the prefix) that are followed by a
631 string message."
632 t (if (c-lang-const c-opt-cpp-prefix)
633 '("error"))
634 pike '("error" "warning"))
636 (c-lang-defconst c-cpp-include-directives
637 "List of cpp directives (without the prefix) that are followed by a
638 file name in angle brackets or quotes."
639 t (if (c-lang-const c-opt-cpp-prefix)
640 '("include"))
641 objc '("include" "import"))
643 (c-lang-defconst c-opt-cpp-macro-define
644 "Cpp directive (without the prefix) that is followed by a macro
645 definition, or nil if the language doesn't have any."
646 t (if (c-lang-const c-opt-cpp-prefix)
647 "define"))
649 (c-lang-defconst c-opt-cpp-macro-define-start
650 ;; Regexp matching everything up to the macro body of a cpp define,
651 ;; or the end of the logical line if there is none. Set if
652 ;; c-opt-cpp-macro-define is.
653 t (if (c-lang-const c-opt-cpp-macro-define)
654 (concat (c-lang-const c-opt-cpp-prefix)
655 (c-lang-const c-opt-cpp-macro-define)
656 "[ \t]+\\(\\sw\\|_\\)+\\(\([^\)]*\)\\)?"
657 "\\([ \t]\\|\\\\\n\\)*")))
658 (c-lang-defvar c-opt-cpp-macro-define-start
659 (c-lang-const c-opt-cpp-macro-define-start))
661 (c-lang-defconst c-cpp-expr-directives
662 "List if cpp directives (without the prefix) that are followed by an
663 expression."
664 t (if (c-lang-const c-opt-cpp-prefix)
665 '("if" "elif")))
667 (c-lang-defconst c-cpp-expr-functions
668 "List of functions in cpp expressions."
669 t (if (c-lang-const c-opt-cpp-prefix)
670 '("defined"))
671 pike '("defined" "efun" "constant"))
673 (c-lang-defconst c-assignment-operators
674 "List of all assignment operators."
675 t '("=" "*=" "/=" "%=" "+=" "-=" ">>=" "<<=" "&=" "^=" "|=")
676 java (append (c-lang-const c-assignment-operators)
677 '(">>>="))
678 c++ (append (c-lang-const c-assignment-operators)
679 '("and_eq" "or_eq" "xor_eq" "??!=" "??'="))
680 idl nil)
682 (c-lang-defconst c-operators
683 "List describing all operators, along with their precedence and
684 associativity. The order in the list corresponds to the precedence of
685 the operators: The operators in each element is a group with the same
686 precedence, and the group has higher precedence than the groups in all
687 following elements. The car of each element describes the type of of
688 the operator group, and the cdr is a list of the operator tokens in
689 it. The operator group types are:
691 'prefix Unary prefix operators.
692 'postfix Unary postfix operators.
693 'postfix-if-paren
694 Unary postfix operators if and only if the chars have
695 parenthesis syntax.
696 'left-assoc Binary left associative operators (i.e. a+b+c means (a+b)+c).
697 'right-assoc Binary right associative operators (i.e. a=b=c means a=(b=c)).
698 'right-assoc-sequence
699 Right associative operator that constitutes of a
700 sequence of tokens that separate expressions. All the
701 tokens in the group are in this case taken as
702 describing the sequence in one such operator, and the
703 order between them is therefore significant.
705 Operators containing a character with paren syntax are taken to match
706 with a corresponding open/close paren somewhere else. A postfix
707 operator with close paren syntax is taken to end a postfix expression
708 started somewhere earlier, rather than start a new one at point. Vice
709 versa for prefix operators with open paren syntax.
711 Note that operators like \".\" and \"->\" which in language references
712 often are described as postfix operators are considered binary here,
713 since CC Mode treats every identifier as an expression."
715 ;; There's currently no code in CC Mode that exploit all the info
716 ;; in this variable; precedence, associativity etc are present as a
717 ;; preparation for future work.
719 t `(;; Preprocessor.
720 ,@(when (c-lang-const c-opt-cpp-prefix)
721 `((prefix "#"
722 ,@(when (c-major-mode-is '(c-mode c++-mode))
723 '("%:" "??=")))
724 (left-assoc "##"
725 ,@(when (c-major-mode-is '(c-mode c++-mode))
726 '("%:%:" "??=??=")))))
728 ;; Primary.
729 ,@(c-lang-const c-identifier-ops)
730 ,@(cond ((c-major-mode-is 'c++-mode)
731 `((postfix-if-paren "<" ">"))) ; Templates.
732 ((c-major-mode-is 'pike-mode)
733 `((prefix "global" "predef")))
734 ((c-major-mode-is 'java-mode)
735 `((prefix "super"))))
737 ;; Postfix.
738 ,@(when (c-major-mode-is 'c++-mode)
739 ;; The following need special treatment.
740 `((prefix "dynamic_cast" "static_cast"
741 "reinterpret_cast" "const_cast" "typeid")))
742 (left-assoc "."
743 ,@(unless (c-major-mode-is 'java-mode)
744 '("->")))
745 (postfix "++" "--" "[" "]" "(" ")"
746 ,@(when (c-major-mode-is '(c-mode c++-mode))
747 '("<:" ":>" "??(" "??)")))
749 ;; Unary.
750 (prefix "++" "--" "+" "-" "!" "~"
751 ,@(when (c-major-mode-is 'c++-mode) '("not" "compl"))
752 ,@(when (c-major-mode-is '(c-mode c++-mode))
753 '("*" "&" "sizeof" "??-"))
754 ,@(when (c-major-mode-is 'objc-mode)
755 '("@selector" "@protocol" "@encode"))
756 ;; The following need special treatment.
757 ,@(cond ((c-major-mode-is 'c++-mode)
758 '("new" "delete"))
759 ((c-major-mode-is 'java-mode)
760 '("new"))
761 ((c-major-mode-is 'pike-mode)
762 '("class" "lambda" "catch" "throw" "gauge")))
763 "(" ")" ; Cast.
764 ,@(when (c-major-mode-is 'pike-mode)
765 '("[" "]"))) ; Type cast.
767 ;; Member selection.
768 ,@(when (c-major-mode-is 'c++-mode)
769 `((left-assoc ".*" "->*")))
771 ;; Multiplicative.
772 (left-assoc "*" "/" "%")
774 ;; Additive.
775 (left-assoc "+" "-")
777 ;; Shift.
778 (left-assoc "<<" ">>"
779 ,@(when (c-major-mode-is 'java-mode)
780 '(">>>")))
782 ;; Relational.
783 (left-assoc "<" ">" "<=" ">="
784 ,@(when (c-major-mode-is 'java-mode)
785 '("instanceof")))
787 ;; Equality.
788 (left-assoc "==" "!="
789 ,@(when (c-major-mode-is 'c++-mode) '("not_eq")))
791 ;; Bitwise and.
792 (left-assoc "&"
793 ,@(when (c-major-mode-is 'c++-mode) '("bitand")))
795 ;; Bitwise exclusive or.
796 (left-assoc "^"
797 ,@(when (c-major-mode-is '(c-mode c++-mode))
798 '("??'"))
799 ,@(when (c-major-mode-is 'c++-mode) '("xor")))
801 ;; Bitwise or.
802 (left-assoc "|"
803 ,@(when (c-major-mode-is '(c-mode c++-mode))
804 '("??!"))
805 ,@(when (c-major-mode-is 'c++-mode) '("bitor")))
807 ;; Logical and.
808 (left-assoc "&&"
809 ,@(when (c-major-mode-is 'c++-mode) '("and")))
811 ;; Logical or.
812 (left-assoc "||"
813 ,@(when (c-major-mode-is '(c-mode c++-mode))
814 '("??!??!"))
815 ,@(when (c-major-mode-is 'c++-mode) '("or")))
817 ;; Conditional.
818 (right-assoc-sequence "?" ":")
820 ;; Assignment.
821 (right-assoc ,@(c-lang-const c-assignment-operators))
823 ;; Exception.
824 ,@(when (c-major-mode-is 'c++-mode)
825 '((prefix "throw")))
827 ;; Sequence.
828 (left-assoc ","))
830 ;; IDL got its own definition since it has a much smaller operator
831 ;; set than the other languages.
832 idl `(;; Preprocessor.
833 (prefix "#")
834 (left-assoc "##")
835 ;; Primary.
836 ,@(c-lang-const c-identifier-ops)
837 ;; Unary.
838 (prefix "+" "-" "~")
839 ;; Multiplicative.
840 (left-assoc "*" "/" "%")
841 ;; Additive.
842 (left-assoc "+" "-")
843 ;; Shift.
844 (left-assoc "<<" ">>")
845 ;; And.
846 (left-assoc "&")
847 ;; Xor.
848 (left-assoc "^")
849 ;; Or.
850 (left-assoc "|")))
852 (c-lang-defconst c-operator-list
853 ;; The operators as a flat list (without duplicates).
854 t (c-filter-ops (c-lang-const c-operators) t t))
856 (c-lang-defconst c-overloadable-operators
857 "List of the operators that are overloadable, in their \"identifier
858 form\". See also `c-op-identitier-prefix'."
859 t nil
860 c++ '("new" "delete" ;; Can be followed by "[]" but we ignore that.
861 "+" "-" "*" "/" "%"
862 "^" "??'" "xor" "&" "bitand" "|" "??!" "bitor" "~" "??-" "compl"
863 "!" "=" "<" ">" "+=" "-=" "*=" "/=" "%=" "^="
864 "??'=" "xor_eq" "&=" "and_eq" "|=" "??!=" "or_eq"
865 "<<" ">>" ">>=" "<<=" "==" "!=" "not_eq" "<=" ">="
866 "&&" "and" "||" "??!??!" "or" "++" "--" "," "->*" "->"
867 "()" "[]" "<::>" "??(??)")
868 ;; These work like identifiers in Pike.
869 pike '("`+" "`-" "`&" "`|" "`^" "`<<" "`>>" "`*" "`/" "`%" "`~"
870 "`==" "`<" "`>" "`!" "`[]" "`[]=" "`->" "`->=" "`()" "``+"
871 "``-" "``&" "``|" "``^" "``<<" "``>>" "``*" "``/" "``%"
872 "`+="))
874 (c-lang-defconst c-overloadable-operators-regexp
875 ;; Regexp tested after an "operator" token in C++.
876 t nil
877 c++ (c-make-keywords-re nil (c-lang-const c-overloadable-operators)))
878 (c-lang-defvar c-overloadable-operators-regexp
879 (c-lang-const c-overloadable-operators-regexp))
881 (c-lang-defconst c-opt-op-identitier-prefix
882 "Regexp matching the token before the ones in
883 `c-overloadable-operators' when operators are specified in their
884 \"identifier form\". This typically matches \"operator\" in C++ where
885 operator functions are specified as e.g. \"operator +\". It's nil in
886 languages without operator functions or where the complete operator
887 identifier is listed in `c-overloadable-operators'.
889 This regexp is assumed to not match any non-operator identifier."
890 t nil
891 c++ (c-make-keywords-re t '("operator")))
892 (c-lang-defvar c-opt-op-identitier-prefix
893 (c-lang-const c-opt-op-identitier-prefix))
895 (c-lang-defconst c-other-op-syntax-tokens
896 "List of the tokens made up of characters in the punctuation or
897 parenthesis syntax classes that have uses other than as expression
898 operators."
899 t '("{" "}" "(" ")" "[" "]" ";" ":" "," "=" "/*" "*/" "//")
900 (c c++ pike) (append '("#" "##" ; Used by cpp.
901 "::" "...")
902 (c-lang-const c-other-op-syntax-tokens))
903 (c c++) (append '("*") (c-lang-const c-other-op-syntax-tokens))
904 c++ (append '("&" "<%" "%>" "<:" ":>" "%:" "%:%:")
905 (c-lang-const c-other-op-syntax-tokens))
906 objc (append '("#" "##" ; Used by cpp.
907 "+" "-") (c-lang-const c-other-op-syntax-tokens))
908 idl (append '("#" "##") ; Used by cpp.
909 (c-lang-const c-other-op-syntax-tokens))
910 pike (append '("..")
911 (c-lang-const c-other-op-syntax-tokens)
912 (c-lang-const c-overloadable-operators))
913 awk '("{" "}" "(" ")" "[" "]" ";" "," "=" "/"))
915 (c-lang-defconst c-all-op-syntax-tokens
916 ;; List of all tokens in the punctuation and parenthesis syntax
917 ;; classes.
918 t (delete-duplicates (append (c-lang-const c-other-op-syntax-tokens)
919 (c-lang-const c-operator-list))
920 :test 'string-equal))
922 (c-lang-defconst c-nonsymbol-token-char-list
923 ;; List containing all chars not in the word, symbol or
924 ;; syntactically irrelevant syntax classes, i.e. all punctuation,
925 ;; parenthesis and string delimiter chars.
926 t (c-with-syntax-table (c-lang-const c-mode-syntax-table)
927 ;; Only go through the chars in the printable ASCII range. No
928 ;; language so far has 8-bit or widestring operators.
929 (let (list (char 32))
930 (while (< char 127)
931 (or (memq (char-syntax char) '(?w ?_ ?< ?> ?\ ))
932 (setq list (cons (c-int-to-char char) list)))
933 (setq char (1+ char)))
934 list)))
936 (c-lang-defconst c-nonsymbol-token-regexp
937 ;; Regexp matching all tokens in the punctuation and parenthesis
938 ;; syntax classes. Note that this also matches ".", which can start
939 ;; a float.
940 t (c-make-keywords-re nil
941 (c-filter-ops (c-lang-const c-all-op-syntax-tokens)
943 "\\`\\(\\s.\\|\\s\(\\|\\s\)\\)+\\'")))
944 (c-lang-defvar c-nonsymbol-token-regexp
945 (c-lang-const c-nonsymbol-token-regexp))
947 (c-lang-defconst c-assignment-op-regexp
948 ;; Regexp matching all assignment operators and only them. The
949 ;; beginning of the first submatch is used to detect the end of the
950 ;; token, along with the end of the whole match.
951 t (if (c-lang-const c-assignment-operators)
952 (concat
953 ;; Need special case for "=" since it's a prefix of "==".
954 "=\\([^=]\\|$\\)"
955 "\\|"
956 (c-make-keywords-re nil
957 (set-difference (c-lang-const c-assignment-operators)
958 '("=")
959 :test 'string-equal)))
960 "\\<\\>"))
961 (c-lang-defvar c-assignment-op-regexp
962 (c-lang-const c-assignment-op-regexp))
964 (c-lang-defconst c-<>-multichar-token-regexp
965 ;; Regexp matching all tokens containing "<" or ">" which are longer
966 ;; than one char.
967 t (c-make-keywords-re nil
968 (c-filter-ops (c-lang-const c-all-op-syntax-tokens)
970 ".[<>]\\|[<>].")))
971 (c-lang-defvar c-<>-multichar-token-regexp
972 (c-lang-const c-<>-multichar-token-regexp))
974 (c-lang-defconst c-<-op-cont-regexp
975 ;; Regexp matching the second and subsequent characters of all
976 ;; multicharacter tokens that begin with "<".
977 t (c-make-keywords-re nil
978 (c-filter-ops (c-lang-const c-all-op-syntax-tokens)
980 "\\`<."
981 (lambda (op) (substring op 1)))))
982 (c-lang-defvar c-<-op-cont-regexp (c-lang-const c-<-op-cont-regexp))
984 (c-lang-defconst c->-op-cont-regexp
985 ;; Regexp matching the second and subsequent characters of all
986 ;; multicharacter tokens that begin with ">".
987 t (c-make-keywords-re nil
988 (c-filter-ops (c-lang-const c-all-op-syntax-tokens)
990 "\\`>."
991 (lambda (op) (substring op 1)))))
992 (c-lang-defvar c->-op-cont-regexp (c-lang-const c->-op-cont-regexp))
994 (c-lang-defconst c-stmt-delim-chars
995 ;; The characters that should be considered to bound statements. To
996 ;; optimize `c-crosses-statement-barrier-p' somewhat, it's assumed to
997 ;; begin with "^" to negate the set. If ? : operators should be
998 ;; detected then the string must end with "?:".
999 t "^;{}?:"
1000 awk "^;{}#\n\r?:") ; The newline chars gets special treatment.
1001 (c-lang-defvar c-stmt-delim-chars (c-lang-const c-stmt-delim-chars))
1003 (c-lang-defconst c-stmt-delim-chars-with-comma
1004 ;; Variant of `c-stmt-delim-chars' that additionally contains ','.
1005 t "^;,{}?:"
1006 awk "^;,{}\n\r?:") ; The newline chars gets special treatment.
1007 (c-lang-defvar c-stmt-delim-chars-with-comma
1008 (c-lang-const c-stmt-delim-chars-with-comma))
1011 ;;; Syntactic whitespace.
1013 (c-lang-defconst c-simple-ws
1014 "Regexp matching an ordinary whitespace character.
1015 Does not contain a \\| operator at the top level."
1016 ;; "\\s " is not enough since it doesn't match line breaks.
1017 t "\\(\\s \\|[\n\r]\\)")
1019 (c-lang-defconst c-simple-ws-depth
1020 ;; Number of regexp grouping parens in `c-simple-ws'.
1021 t (regexp-opt-depth (c-lang-const c-simple-ws)))
1023 (c-lang-defconst c-line-comment-starter
1024 "String that starts line comments, or nil if such don't exist.
1025 Line comments are always terminated by newlines. At least one of
1026 `c-block-comment-starter' and this one is assumed to be set.
1028 Note that it's currently not enough to set this to support a new
1029 comment style. Other stuff like the syntax table must also be set up
1030 properly."
1031 t "//"
1032 awk "#")
1033 (c-lang-defvar c-line-comment-starter (c-lang-const c-line-comment-starter))
1035 (c-lang-defconst c-block-comment-starter
1036 "String that starts block comments, or nil if such don't exist.
1037 Block comments are ended by `c-block-comment-ender', which is assumed
1038 to be set if this is. At least one of `c-line-comment-starter' and
1039 this one is assumed to be set.
1041 Note that it's currently not enough to set this to support a new
1042 comment style. Other stuff like the syntax table must also be set up
1043 properly."
1044 t "/*"
1045 awk nil)
1047 (c-lang-defconst c-block-comment-ender
1048 "String that ends block comments, or nil if such don't exist.
1050 Note that it's currently not enough to set this to support a new
1051 comment style. Other stuff like the syntax table must also be set up
1052 properly."
1053 t "*/"
1054 awk nil)
1056 (c-lang-defconst c-comment-start-regexp
1057 ;; Regexp to match the start of any type of comment.
1058 t (let ((re (c-make-keywords-re nil
1059 (list (c-lang-const c-line-comment-starter)
1060 (c-lang-const c-block-comment-starter)))))
1061 (if (memq 'gen-comment-delim c-emacs-features)
1062 (concat re "\\|\\s!")
1063 re)))
1064 (c-lang-defvar c-comment-start-regexp (c-lang-const c-comment-start-regexp))
1066 ;;;; Added by ACM, 2003/9/18.
1067 (c-lang-defconst c-block-comment-start-regexp
1068 ;; Regexp which matches the start of a block comment (if such exists in the
1069 ;; language)
1070 t (if (c-lang-const c-block-comment-starter)
1071 (regexp-quote (c-lang-const c-block-comment-starter))
1072 "\\<\\>"))
1073 (c-lang-defvar c-block-comment-start-regexp
1074 (c-lang-const c-block-comment-start-regexp))
1076 (c-lang-defconst c-literal-start-regexp
1077 ;; Regexp to match the start of comments and string literals.
1078 t (concat (c-lang-const c-comment-start-regexp)
1079 "\\|"
1080 (if (memq 'gen-string-delim c-emacs-features)
1081 "\"|"
1082 "\"")))
1083 (c-lang-defvar c-literal-start-regexp (c-lang-const c-literal-start-regexp))
1085 (c-lang-defconst c-doc-comment-start-regexp
1086 "Regexp to match the start of documentation comments."
1087 t "\\<\\>"
1088 ;; From font-lock.el: `doxygen' uses /*! while others use /**.
1089 (c c++ objc) "/\\*[*!]"
1090 java "/\\*\\*"
1091 pike "/[/*]!")
1092 (c-lang-defvar c-doc-comment-start-regexp
1093 (c-lang-const c-doc-comment-start-regexp))
1095 (c-lang-defconst comment-start
1096 "String that starts comments inserted with M-; etc.
1097 `comment-start' is initialized from this."
1098 ;; Default: Prefer line comments to block comments, and pad with a space.
1099 t (concat (or (c-lang-const c-line-comment-starter)
1100 (c-lang-const c-block-comment-starter))
1101 " ")
1102 ;; In C we still default to the block comment style since line
1103 ;; comments aren't entirely portable.
1104 c "/* ")
1105 (c-lang-defvar comment-start (c-lang-const comment-start)
1106 'dont-doc)
1108 (c-lang-defconst comment-end
1109 "String that ends comments inserted with M-; etc.
1110 `comment-end' is initialized from this."
1111 ;; Default: Use block comment style if comment-start uses block
1112 ;; comments, and pad with a space in that case.
1113 t (if (string-match (concat "\\`\\("
1114 (c-lang-const c-block-comment-start-regexp)
1115 "\\)")
1116 (c-lang-const comment-start))
1117 (concat " " (c-lang-const c-block-comment-ender))
1118 ""))
1119 (c-lang-defvar comment-end (c-lang-const comment-end)
1120 'dont-doc)
1122 (c-lang-defconst comment-start-skip
1123 "Regexp to match the start of a comment plus everything up to its body.
1124 `comment-start-skip' is initialized from this."
1125 ;; Default: Allow the last char of the comment starter(s) to be
1126 ;; repeated, then allow any amount of horizontal whitespace.
1127 t (concat "\\("
1128 (c-concat-separated
1129 (mapcar (lambda (cs)
1130 (when cs
1131 (concat (regexp-quote cs) "+")))
1132 (list (c-lang-const c-line-comment-starter)
1133 (c-lang-const c-block-comment-starter)))
1134 "\\|")
1135 "\\)\\s *"))
1136 (c-lang-defvar comment-start-skip (c-lang-const comment-start-skip)
1137 'dont-doc)
1139 (c-lang-defconst c-syntactic-ws-start
1140 ;; Regexp matching any sequence that can start syntactic whitespace.
1141 ;; The only uncertain case is '#' when there are cpp directives.
1142 t (concat "\\s \\|"
1143 (c-make-keywords-re nil
1144 (append (list (c-lang-const c-line-comment-starter)
1145 (c-lang-const c-block-comment-starter)
1146 (when (c-lang-const c-opt-cpp-prefix)
1147 "#"))
1148 '("\n" "\r")))
1149 "\\|\\\\[\n\r]"
1150 (when (memq 'gen-comment-delim c-emacs-features)
1151 "\\|\\s!")))
1152 (c-lang-defvar c-syntactic-ws-start (c-lang-const c-syntactic-ws-start))
1154 (c-lang-defconst c-syntactic-ws-end
1155 ;; Regexp matching any single character that might end syntactic whitespace.
1156 t (concat "\\s \\|"
1157 (c-make-keywords-re nil
1158 (append (when (c-lang-const c-block-comment-ender)
1159 (list
1160 (string
1161 (elt (c-lang-const c-block-comment-ender)
1162 (1- (length
1163 (c-lang-const c-block-comment-ender)))))))
1164 '("\n" "\r")))
1165 (when (memq 'gen-comment-delim c-emacs-features)
1166 "\\|\\s!")))
1167 (c-lang-defvar c-syntactic-ws-end (c-lang-const c-syntactic-ws-end))
1169 (c-lang-defconst c-unterminated-block-comment-regexp
1170 ;; Regexp matching an unterminated block comment that doesn't
1171 ;; contain line breaks, or nil in languages without block comments.
1172 ;; Does not contain a \| operator at the top level.
1173 t (when (c-lang-const c-block-comment-starter)
1174 (concat
1175 (regexp-quote (c-lang-const c-block-comment-starter))
1176 ;; It's messy to cook together a regexp that matches anything
1177 ;; but c-block-comment-ender.
1178 (let ((end (c-lang-const c-block-comment-ender)))
1179 (cond ((= (length end) 1)
1180 (concat "[^" end "\n\r]*"))
1181 ((= (length end) 2)
1182 (concat "[^" (substring end 0 1) "\n\r]*"
1183 "\\("
1184 (regexp-quote (substring end 0 1)) "+"
1185 "[^"
1186 ;; The quoting rules inside char classes are silly. :P
1187 (cond ((= (elt end 0) (elt end 1))
1188 (concat (substring end 0 1) "\n\r"))
1189 ((= (elt end 1) ?\])
1190 (concat (substring end 1 2) "\n\r"
1191 (substring end 0 1)))
1193 (concat (substring end 0 1) "\n\r"
1194 (substring end 1 2))))
1196 "[^" (substring end 0 1) "\n\r]*"
1197 "\\)*"))
1199 (error "Can't handle a block comment ender of length %s"
1200 (length end))))))))
1202 (c-lang-defconst c-block-comment-regexp
1203 ;; Regexp matching a block comment that doesn't contain line breaks,
1204 ;; or nil in languages without block comments. The reason we don't
1205 ;; allow line breaks is to avoid going very far and risk running out
1206 ;; of regexp stack; this regexp is intended to handle only short
1207 ;; comments that might be put in the middle of limited constructs
1208 ;; like declarations. Does not contain a \| operator at the top
1209 ;; level.
1210 t (when (c-lang-const c-unterminated-block-comment-regexp)
1211 (concat
1212 (c-lang-const c-unterminated-block-comment-regexp)
1213 (let ((end (c-lang-const c-block-comment-ender)))
1214 (cond ((= (length end) 1)
1215 (regexp-quote end))
1216 ((= (length end) 2)
1217 (concat (regexp-quote (substring end 0 1)) "+"
1218 (regexp-quote (substring end 1 2))))
1220 (error "Can't handle a block comment ender of length %s"
1221 (length end))))))))
1223 (c-lang-defconst c-nonwhite-syntactic-ws
1224 ;; Regexp matching a piece of syntactic whitespace that isn't a
1225 ;; sequence of simple whitespace characters. As opposed to
1226 ;; `c-(forward|backward)-syntactic-ws', this doesn't regard cpp
1227 ;; directives as syntactic whitespace.
1228 t (c-concat-separated
1229 (list (when (c-lang-const c-line-comment-starter)
1230 (concat (regexp-quote (c-lang-const c-line-comment-starter))
1231 "[^\n\r]*[\n\r]"))
1232 (c-lang-const c-block-comment-regexp)
1233 "\\\\[\n\r]"
1234 (when (memq 'gen-comment-delim c-emacs-features)
1235 "\\s!\\S!*\\s!"))
1236 "\\|"))
1238 (c-lang-defconst c-syntactic-ws
1239 ;; Regexp matching syntactic whitespace, including possibly the
1240 ;; empty string. As opposed to `c-(forward|backward)-syntactic-ws',
1241 ;; this doesn't regard cpp directives as syntactic whitespace. Does
1242 ;; not contain a \| operator at the top level.
1243 t (concat (c-lang-const c-simple-ws) "*"
1244 "\\("
1245 (concat "\\(" (c-lang-const c-nonwhite-syntactic-ws) "\\)"
1246 (c-lang-const c-simple-ws) "*")
1247 "\\)*"))
1249 (c-lang-defconst c-syntactic-ws-depth
1250 ;; Number of regexp grouping parens in `c-syntactic-ws'.
1251 t (regexp-opt-depth (c-lang-const c-syntactic-ws)))
1253 (c-lang-defconst c-nonempty-syntactic-ws
1254 ;; Regexp matching syntactic whitespace, which is at least one
1255 ;; character long. As opposed to `c-(forward|backward)-syntactic-ws',
1256 ;; this doesn't regard cpp directives as syntactic whitespace. Does
1257 ;; not contain a \| operator at the top level.
1258 t (concat "\\("
1259 (c-lang-const c-simple-ws)
1260 "\\|"
1261 (c-lang-const c-nonwhite-syntactic-ws)
1262 "\\)+"))
1264 (c-lang-defconst c-nonempty-syntactic-ws-depth
1265 ;; Number of regexp grouping parens in `c-nonempty-syntactic-ws'.
1266 t (regexp-opt-depth (c-lang-const c-nonempty-syntactic-ws)))
1268 (c-lang-defconst c-single-line-syntactic-ws
1269 ;; Regexp matching syntactic whitespace without any line breaks. As
1270 ;; opposed to `c-(forward|backward)-syntactic-ws', this doesn't
1271 ;; regard cpp directives as syntactic whitespace. Does not contain
1272 ;; a \| operator at the top level.
1273 t (if (c-lang-const c-block-comment-regexp)
1274 (concat "\\s *\\("
1275 (c-lang-const c-block-comment-regexp)
1276 "\\s *\\)*")
1277 "\\s *"))
1279 (c-lang-defconst c-single-line-syntactic-ws-depth
1280 ;; Number of regexp grouping parens in `c-single-line-syntactic-ws'.
1281 t (regexp-opt-depth (c-lang-const c-single-line-syntactic-ws)))
1283 (c-lang-defconst c-syntactic-eol
1284 ;; Regexp that matches when there is no syntactically significant
1285 ;; text before eol. Macros are regarded as syntactically
1286 ;; significant text here.
1287 t (concat (c-lang-const c-single-line-syntactic-ws)
1288 ;; Match eol (possibly inside a block comment or preceded
1289 ;; by a line continuation backslash), or the beginning of a
1290 ;; line comment. Note: This has to be modified for awk
1291 ;; where line comments start with '#'.
1292 "\\("
1293 (c-concat-separated
1294 (list (when (c-lang-const c-line-comment-starter)
1295 (regexp-quote (c-lang-const c-line-comment-starter)))
1296 (when (c-lang-const c-unterminated-block-comment-regexp)
1297 (concat (c-lang-const c-unterminated-block-comment-regexp)
1298 "$"))
1299 "\\\\$"
1300 "$")
1301 "\\|")
1302 "\\)"))
1303 (c-lang-defvar c-syntactic-eol (c-lang-const c-syntactic-eol))
1306 ;;; Syntactic analysis ("virtual semicolons") for line-oriented languages (AWK).
1307 (c-lang-defconst c-at-vsemi-p-fn
1308 "Contains a function \"Is there a virtual semicolon at POS or point?\".
1309 Such a function takes one optional parameter, a buffer position (defaults to
1310 point), and returns NIL or t. This variable contains NIL for languages which
1311 don't have EOL terminated statements. "
1312 t nil
1313 awk 'c-awk-at-vsemi-p)
1314 (c-lang-defvar c-at-vsemi-p-fn (c-lang-const c-at-vsemi-p-fn))
1316 (c-lang-defconst c-vsemi-status-unknown-p-fn
1317 "Contains a function \"are we unsure whether there is a virtual semicolon on this line?\".
1318 The (admittedly kludgey) purpose of such a function is to prevent an infinite
1319 recursion in c-beginning-of-statement-1 when point starts at a `while' token.
1320 The function MUST NOT UNDER ANY CIRCUMSTANCES call c-beginning-of-statement-1,
1321 even indirectly. This variable contains NIL for languages which don't have
1322 EOL terminated statements."
1323 t nil
1324 awk 'c-awk-vsemi-status-unknown-p)
1325 (c-lang-defvar c-vsemi-status-unknown-p-fn
1326 (c-lang-const c-vsemi-status-unknown-p-fn))
1329 ;;; In-comment text handling.
1331 (c-lang-defconst c-paragraph-start
1332 "Regexp to append to `paragraph-start'."
1333 t "$"
1334 java "\\(@[a-zA-Z]+\\>\\|$\\)" ; For Javadoc.
1335 pike "\\(@[a-zA-Z_-]+\\>\\([^{]\\|$\\)\\|$\\)") ; For Pike refdoc.
1336 (c-lang-defvar c-paragraph-start (c-lang-const c-paragraph-start))
1338 (c-lang-defconst c-paragraph-separate
1339 "Regexp to append to `paragraph-separate'."
1340 t "$"
1341 pike (c-lang-const c-paragraph-start))
1342 (c-lang-defvar c-paragraph-separate (c-lang-const c-paragraph-separate))
1345 ;;; Keyword lists.
1347 ;; Note: All and only all language constants containing keyword lists
1348 ;; should end with "-kwds"; they're automatically collected into the
1349 ;; `c-kwds-lang-consts' list below and used to build `c-keywords' etc.
1351 (c-lang-defconst c-primitive-type-kwds
1352 "Primitive type keywords. As opposed to the other keyword lists, the
1353 keywords listed here are fontified with the type face instead of the
1354 keyword face.
1356 If any of these also are on `c-type-list-kwds', `c-ref-list-kwds',
1357 `c-colon-type-list-kwds', `c-paren-nontype-kwds', `c-paren-type-kwds',
1358 `c-<>-type-kwds', or `c-<>-arglist-kwds' then the associated clauses
1359 will be handled.
1361 Do not try to modify this list for end user customizations; the
1362 `*-font-lock-extra-types' variable, where `*' is the mode prefix, is
1363 the appropriate place for that."
1364 t '("char" "double" "float" "int" "long" "short" "signed"
1365 "unsigned" "void")
1366 c (append
1367 '("_Bool" "_Complex" "_Imaginary") ; Conditionally defined in C99.
1368 (c-lang-const c-primitive-type-kwds))
1369 c++ (append
1370 '("bool" "wchar_t")
1371 (c-lang-const c-primitive-type-kwds))
1372 ;; Objective-C extends C, but probably not the new stuff in C99.
1373 objc (append
1374 '("id" "Class" "SEL" "IMP" "BOOL")
1375 (c-lang-const c-primitive-type-kwds))
1376 java '("boolean" "byte" "char" "double" "float" "int" "long" "short" "void")
1377 idl '("Object" "ValueBase" "any" "boolean" "char" "double" "fixed" "float"
1378 "long" "octet" "sequence" "short" "string" "void" "wchar" "wstring"
1379 ;; In CORBA PSDL:
1380 "ref"
1381 ;; The following can't really end a type, but we have to specify them
1382 ;; here due to the assumption in `c-primitive-type-prefix-kwds'. It
1383 ;; doesn't matter that much.
1384 "unsigned" "strong")
1385 pike '(;; this_program isn't really a keyword, but it's practically
1386 ;; used as a builtin type.
1387 "array" "float" "function" "int" "mapping" "mixed" "multiset"
1388 "object" "program" "string" "this_program" "void"))
1390 (c-lang-defconst c-primitive-type-key
1391 ;; An adorned regexp that matches `c-primitive-type-kwds'.
1392 t (c-make-keywords-re t (c-lang-const c-primitive-type-kwds)))
1393 (c-lang-defvar c-primitive-type-key (c-lang-const c-primitive-type-key))
1395 (c-lang-defconst c-primitive-type-prefix-kwds
1396 "Keywords that might act as prefixes for primitive types. Assumed to
1397 be a subset of `c-primitive-type-kwds'."
1398 t nil
1399 (c c++) '("long" "short" "signed" "unsigned")
1400 idl '("long" "unsigned"
1401 ;; In CORBA PSDL:
1402 "strong"))
1404 (c-lang-defconst c-type-prefix-kwds
1405 "Keywords where the following name - if any - is a type name, and
1406 where the keyword together with the symbol works as a type in
1407 declarations.
1409 Note that an alternative if the second part doesn't hold is
1410 `c-type-list-kwds'. Keywords on this list are typically also present
1411 on one of the `*-decl-kwds' lists."
1412 t nil
1413 c '("struct" "union" "enum")
1414 c++ (append '("class" "typename")
1415 (c-lang-const c-type-prefix-kwds c)))
1417 (c-lang-defconst c-type-prefix-key
1418 ;; Adorned regexp matching `c-type-prefix-kwds'.
1419 t (c-make-keywords-re t (c-lang-const c-type-prefix-kwds)))
1420 (c-lang-defvar c-type-prefix-key (c-lang-const c-type-prefix-key))
1422 (c-lang-defconst c-type-modifier-kwds
1423 "Type modifier keywords. These can occur almost anywhere in types
1424 but they don't build a type of themselves. Unlike the keywords on
1425 `c-primitive-type-kwds', they are fontified with the keyword face and
1426 not the type face."
1427 t nil
1428 c '("const" "restrict" "volatile")
1429 c++ '("const" "volatile" "throw")
1430 objc '("const" "volatile"))
1432 (c-lang-defconst c-opt-type-modifier-key
1433 ;; Adorned regexp matching `c-type-modifier-kwds', or nil in
1434 ;; languages without such keywords.
1435 t (and (c-lang-const c-type-modifier-kwds)
1436 (c-make-keywords-re t (c-lang-const c-type-modifier-kwds))))
1437 (c-lang-defvar c-opt-type-modifier-key (c-lang-const c-opt-type-modifier-key))
1439 (c-lang-defconst c-opt-type-component-key
1440 ;; An adorned regexp that matches `c-primitive-type-prefix-kwds' and
1441 ;; `c-type-modifier-kwds', or nil in languages without any of them.
1442 t (and (or (c-lang-const c-primitive-type-prefix-kwds)
1443 (c-lang-const c-type-modifier-kwds))
1444 (c-make-keywords-re t
1445 (append (c-lang-const c-primitive-type-prefix-kwds)
1446 (c-lang-const c-type-modifier-kwds)))))
1447 (c-lang-defvar c-opt-type-component-key
1448 (c-lang-const c-opt-type-component-key))
1450 (c-lang-defconst c-type-start-kwds
1451 ;; All keywords that can start a type (i.e. are either a type prefix
1452 ;; or a complete type).
1453 t (delete-duplicates (append (c-lang-const c-primitive-type-kwds)
1454 (c-lang-const c-type-prefix-kwds)
1455 (c-lang-const c-type-modifier-kwds))
1456 :test 'string-equal))
1458 (c-lang-defconst c-class-decl-kwds
1459 "Keywords introducing declarations where the following block (if any)
1460 contains another declaration level that should be considered a class.
1462 If any of these also are on `c-type-list-kwds', `c-ref-list-kwds',
1463 `c-colon-type-list-kwds', `c-paren-nontype-kwds', `c-paren-type-kwds',
1464 `c-<>-type-kwds', or `c-<>-arglist-kwds' then the associated clauses
1465 will be handled.
1467 Note that presence on this list does not automatically treat the
1468 following identifier as a type; the keyword must also be present on
1469 `c-type-prefix-kwds' or `c-type-list-kwds' to accomplish that."
1470 t nil
1471 c '("struct" "union")
1472 c++ '("class" "struct" "union")
1473 objc '("struct" "union"
1474 "@interface" "@implementation" "@protocol")
1475 java '("class" "interface")
1476 idl '("component" "eventtype" "exception" "home" "interface" "struct"
1477 "union" "valuetype"
1478 ;; In CORBA PSDL:
1479 "storagehome" "storagetype"
1480 ;; In CORBA CIDL:
1481 "catalog" "executor" "manages" "segment")
1482 pike '("class"))
1484 (c-lang-defconst c-class-key
1485 ;; Regexp matching the start of a class.
1486 t (c-make-keywords-re t (c-lang-const c-class-decl-kwds)))
1487 (c-lang-defvar c-class-key (c-lang-const c-class-key))
1489 (c-lang-defconst c-brace-list-decl-kwds
1490 "Keywords introducing declarations where the following block (if
1491 any) is a brace list.
1493 If any of these also are on `c-type-list-kwds', `c-ref-list-kwds',
1494 `c-colon-type-list-kwds', `c-paren-nontype-kwds', `c-paren-type-kwds',
1495 `c-<>-type-kwds', or `c-<>-arglist-kwds' then the associated clauses
1496 will be handled."
1497 t '("enum")
1498 (java awk) nil)
1500 (c-lang-defconst c-brace-list-key
1501 ;; Regexp matching the start of declarations where the following
1502 ;; block is a brace list.
1503 t (c-make-keywords-re t (c-lang-const c-brace-list-decl-kwds)))
1504 (c-lang-defvar c-brace-list-key (c-lang-const c-brace-list-key))
1506 (c-lang-defconst c-other-block-decl-kwds
1507 "Keywords where the following block (if any) contains another
1508 declaration level that should not be considered a class. For every
1509 keyword here, CC Mode will add a set of special syntactic symbols for
1510 those blocks. E.g. if the keyword is \"foo\" then there will be
1511 `foo-open', `foo-close', and `infoo' symbols.
1513 The intention is that this category should be used for block
1514 constructs that aren't related to object orientation concepts like
1515 classes (which thus also include e.g. interfaces, templates,
1516 contracts, structs, etc). The more pragmatic distinction is that
1517 while most want some indentation inside classes, it's fairly common
1518 that they don't want it in some of these constructs, so it should be
1519 simple to configure that differently from classes. See also
1520 `c-class-decl-kwds'.
1522 If any of these also are on `c-type-list-kwds', `c-ref-list-kwds',
1523 `c-colon-type-list-kwds', `c-paren-nontype-kwds', `c-paren-type-kwds',
1524 `c-<>-type-kwds', or `c-<>-arglist-kwds' then the associated clauses
1525 will be handled."
1526 t nil
1527 (c objc) '("extern")
1528 c++ '("namespace" "extern")
1529 idl '("module"
1530 ;; In CORBA CIDL:
1531 "composition"))
1533 (c-lang-defconst c-other-decl-block-key
1534 ;; Regexp matching the start of blocks besides classes that contain
1535 ;; another declaration level.
1536 t (c-make-keywords-re t (c-lang-const c-other-block-decl-kwds)))
1537 (c-lang-defvar c-other-decl-block-key (c-lang-const c-other-decl-block-key))
1539 (c-lang-defconst c-typedef-decl-kwds
1540 "Keywords introducing declarations where the identifier(s) being
1541 declared are types.
1543 If any of these also are on `c-type-list-kwds', `c-ref-list-kwds',
1544 `c-colon-type-list-kwds', `c-paren-nontype-kwds', `c-paren-type-kwds',
1545 `c-<>-type-kwds', or `c-<>-arglist-kwds' then the associated clauses
1546 will be handled."
1547 ;; Default to `c-class-decl-kwds' and `c-brace-list-decl-kwds'
1548 ;; (since e.g. "Foo" is a type that's being defined in "class Foo
1549 ;; {...}").
1550 t (append (c-lang-const c-class-decl-kwds)
1551 (c-lang-const c-brace-list-decl-kwds))
1552 ;; Languages that have a "typedef" construct.
1553 (c c++ objc idl pike) (append (c-lang-const c-typedef-decl-kwds)
1554 '("typedef"))
1555 ;; Unlike most other languages, exception names are not handled as
1556 ;; types in IDL since they only can occur in "raises" specs.
1557 idl (delete "exception" (append (c-lang-const c-typedef-decl-kwds) nil)))
1559 (c-lang-defconst c-typeless-decl-kwds
1560 "Keywords introducing declarations where the \(first) identifier
1561 \(declarator) follows directly after the keyword, without any type.
1563 If any of these also are on `c-type-list-kwds', `c-ref-list-kwds',
1564 `c-colon-type-list-kwds', `c-paren-nontype-kwds', `c-paren-type-kwds',
1565 `c-<>-type-kwds', or `c-<>-arglist-kwds' then the associated clauses
1566 will be handled."
1567 ;; Default to `c-class-decl-kwds' and `c-brace-list-decl-kwds'
1568 ;; (since e.g. "Foo" is the identifier being defined in "class Foo
1569 ;; {...}").
1570 t (append (c-lang-const c-class-decl-kwds)
1571 (c-lang-const c-brace-list-decl-kwds))
1572 ;; Note: "manages" for CORBA CIDL clashes with its presence on
1573 ;; `c-type-list-kwds' for IDL.
1574 idl (append (c-lang-const c-typeless-decl-kwds)
1575 '("factory" "finder" "native"
1576 ;; In CORBA PSDL:
1577 "key" "stores"
1578 ;; In CORBA CIDL:
1579 "facet"))
1580 pike (append (c-lang-const c-class-decl-kwds)
1581 '("constant")))
1583 (c-lang-defconst c-modifier-kwds
1584 "Keywords that can prefix normal declarations of identifiers
1585 \(and typically act as flags). Things like argument declarations
1586 inside function headers are also considered declarations in this
1587 sense.
1589 If any of these also are on `c-type-list-kwds', `c-ref-list-kwds',
1590 `c-colon-type-list-kwds', `c-paren-nontype-kwds', `c-paren-type-kwds',
1591 `c-<>-type-kwds', or `c-<>-arglist-kwds' then the associated clauses
1592 will be handled."
1593 t nil
1594 (c c++) '("auto" "extern" "inline" "register" "static")
1595 c++ (append '("explicit" "friend" "mutable" "template" "using" "virtual")
1596 (c-lang-const c-modifier-kwds))
1597 objc '("auto" "bycopy" "byref" "extern" "in" "inout" "oneway" "out" "static")
1598 ;; FIXME: Some of those below ought to be on `c-other-decl-kwds' instead.
1599 idl '("abstract" "attribute" "const" "consumes" "custom" "emits" "import"
1600 "in" "inout" "local" "multiple" "oneway" "out" "private" "provides"
1601 "public" "publishes" "readonly" "typeid" "typeprefix" "uses"
1602 ;; In CORBA PSDL:
1603 "primary" "state"
1604 ;; In CORBA CIDL:
1605 "bindsTo" "delegatesTo" "implements" "proxy" "storedOn")
1606 ;; Note: "const" is not used in Java, but it's still a reserved keyword.
1607 java '("abstract" "const" "final" "native" "private" "protected" "public"
1608 "static" "strictfp" "synchronized" "transient" "volatile")
1609 pike '("final" "inline" "local" "nomask" "optional" "private" "protected"
1610 "public" "static" "variant"))
1612 (c-lang-defconst c-other-decl-kwds
1613 "Keywords that can start or prefix any declaration level construct,
1614 besides those on `c-class-decl-kwds', `c-brace-list-decl-kwds',
1615 `c-other-block-decl-kwds', `c-typedef-decl-kwds',
1616 `c-typeless-decl-kwds' and `c-modifier-kwds'.
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
1621 will be handled."
1622 t nil
1623 objc '("@class" "@end" "@defs")
1624 java '("import" "package")
1625 pike '("import" "inherit"))
1627 (c-lang-defconst c-decl-start-kwds
1628 "Keywords that always start declarations, wherever they occur.
1629 This can be used for declarations that aren't recognized by the normal
1630 combination of `c-decl-prefix-re' and `c-decl-start-re'."
1631 t nil
1632 ;; Classes can be declared anywhere in a Pike expression.
1633 pike '("class"))
1635 (c-lang-defconst c-decl-hangon-kwds
1636 "Keywords that can occur anywhere in a declaration level construct.
1637 This is used for self-contained things that can be tacked on anywhere
1638 on a declaration and that should be ignored to be able to recognize it
1639 correctly. Typical cases are compiler extensions like
1640 \"__attribute__\" or \"__declspec\":
1642 __declspec(noreturn) void foo();
1643 class __declspec(dllexport) classname {...};
1644 void foo() __attribute__((noreturn));
1646 Note that unrecognized plain symbols are skipped anyway if they occur
1647 before the type, so such things are not necessary to mention here.
1648 Mentioning them here is necessary only if they can occur in other
1649 places, or if they are followed by a construct that must be skipped
1650 over \(like the parens in the \"__attribute__\" and \"__declspec\"
1651 examples above). In the last case, they alse need to be present on
1652 one of `c-type-list-kwds', `c-ref-list-kwds',
1653 `c-colon-type-list-kwds', `c-paren-nontype-kwds', `c-paren-type-kwds',
1654 `c-<>-type-kwds', or `c-<>-arglist-kwds'."
1655 ;; NB: These are currently not recognized in all parts of a
1656 ;; declaration. Specifically, they aren't recognized in the middle
1657 ;; of multi-token types, inside declarators, and between the
1658 ;; identifier and the arglist paren of a function declaration.
1660 ;; FIXME: This ought to be user customizable since compiler stuff
1661 ;; like this usually is wrapped in project specific macros. (It'd
1662 ;; of course be even better if we could cope without knowing this.)
1663 t nil
1664 (c c++) '(;; GCC extension.
1665 "__attribute__"
1666 ;; MSVC extension.
1667 "__declspec"))
1669 (c-lang-defconst c-decl-hangon-key
1670 ;; Adorned regexp matching `c-decl-hangon-kwds'.
1671 t (c-make-keywords-re t (c-lang-const c-decl-hangon-kwds)))
1672 (c-lang-defvar c-decl-hangon-key (c-lang-const c-decl-hangon-key))
1674 (c-lang-defconst c-prefix-spec-kwds
1675 ;; All keywords that can occur in the preamble of a declaration.
1676 ;; They typically occur before the type, but they are also matched
1677 ;; after presumptive types since we often can't be sure that
1678 ;; something is a type or just some sort of macro in front of the
1679 ;; declaration. They might be ambiguous with types or type
1680 ;; prefixes.
1681 t (delete-duplicates (append (c-lang-const c-class-decl-kwds)
1682 (c-lang-const c-brace-list-decl-kwds)
1683 (c-lang-const c-other-block-decl-kwds)
1684 (c-lang-const c-typedef-decl-kwds)
1685 (c-lang-const c-typeless-decl-kwds)
1686 (c-lang-const c-modifier-kwds)
1687 (c-lang-const c-other-decl-kwds)
1688 (c-lang-const c-decl-start-kwds)
1689 (c-lang-const c-decl-hangon-kwds))
1690 :test 'string-equal))
1692 (c-lang-defconst c-prefix-spec-kwds-re
1693 ;; Adorned regexp of `c-prefix-spec-kwds'.
1694 t (c-make-keywords-re t (c-lang-const c-prefix-spec-kwds)))
1695 (c-lang-defvar c-prefix-spec-kwds-re (c-lang-const c-prefix-spec-kwds-re))
1697 (c-lang-defconst c-specifier-key
1698 ;; Adorned regexp of the keywords in `c-prefix-spec-kwds' that
1699 ;; aren't ambiguous with types or type prefixes.
1700 t (c-make-keywords-re t
1701 (set-difference (c-lang-const c-prefix-spec-kwds)
1702 (c-lang-const c-type-start-kwds)
1703 :test 'string-equal)))
1704 (c-lang-defvar c-specifier-key (c-lang-const c-specifier-key))
1706 (c-lang-defconst c-postfix-spec-kwds
1707 ;; Keywords that can occur after argument list of a function header
1708 ;; declaration, i.e. in the "K&R region".
1709 t (append (c-lang-const c-postfix-decl-spec-kwds)
1710 (c-lang-const c-decl-hangon-kwds)))
1712 (c-lang-defconst c-not-decl-init-keywords
1713 ;; Adorned regexp matching all keywords that can't appear at the
1714 ;; start of a declaration.
1715 t (c-make-keywords-re t
1716 (set-difference (c-lang-const c-keywords)
1717 (append (c-lang-const c-type-start-kwds)
1718 (c-lang-const c-prefix-spec-kwds))
1719 :test 'string-equal)))
1720 (c-lang-defvar c-not-decl-init-keywords
1721 (c-lang-const c-not-decl-init-keywords))
1723 (c-lang-defconst c-protection-kwds
1724 "Access protection label keywords in classes."
1725 t nil
1726 c++ '("private" "protected" "public")
1727 objc '("@private" "@protected" "@public"))
1729 (c-lang-defconst c-block-decls-with-vars
1730 "Keywords introducing declarations that can contain a block which
1731 might be followed by variable declarations, e.g. like \"foo\" in
1732 \"class Foo { ... } foo;\". So if there is a block in a declaration
1733 like that, it ends with the following ';' and not right away.
1735 The keywords on list are assumed to also be present on one of the
1736 `*-decl-kwds' lists."
1737 t nil
1738 (c objc) '("struct" "union" "enum" "typedef")
1739 c++ '("class" "struct" "union" "enum" "typedef"))
1741 (c-lang-defconst c-opt-block-decls-with-vars-key
1742 ;; Regexp matching the `c-block-decls-with-vars' keywords, or nil in
1743 ;; languages without such constructs.
1744 t (and (c-lang-const c-block-decls-with-vars)
1745 (c-make-keywords-re t (c-lang-const c-block-decls-with-vars))))
1746 (c-lang-defvar c-opt-block-decls-with-vars-key
1747 (c-lang-const c-opt-block-decls-with-vars-key))
1749 (c-lang-defconst c-postfix-decl-spec-kwds
1750 "Keywords introducing extra declaration specifiers in the region
1751 between the header and the body \(i.e. the \"K&R-region\") in
1752 declarations."
1753 t nil
1754 java '("extends" "implements" "throws")
1755 idl '("context" "getraises" "manages" "primarykey" "raises" "setraises"
1756 "supports"
1757 ;; In CORBA PSDL:
1758 "as" "const" "implements" "of" "ref"))
1760 (c-lang-defconst c-nonsymbol-sexp-kwds
1761 "Keywords that may be followed by a nonsymbol sexp before whatever
1762 construct it's part of continues."
1763 t nil
1764 (c c++ objc) '("extern"))
1766 (c-lang-defconst c-type-list-kwds
1767 "Keywords that may be followed by a comma separated list of type
1768 identifiers, where each optionally can be prefixed by keywords. (Can
1769 also be used for the special case when the list can contain only one
1770 element.)
1772 Assumed to be mutually exclusive with `c-ref-list-kwds'. There's no
1773 reason to put keywords on this list if they are on `c-type-prefix-kwds'.
1774 There's also no reason to add keywords that prefixes a normal
1775 declaration consisting of a type followed by a declarator (list), so
1776 the keywords on `c-modifier-kwds' should normally not be listed here
1777 either.
1779 Note: Use `c-typeless-decl-kwds' for keywords followed by a function
1780 or variable identifier (that's being defined)."
1781 t nil
1782 c++ '("operator")
1783 objc '("@class")
1784 java '("import" "new" "extends" "implements" "throws")
1785 idl '("manages" "native" "primarykey" "supports"
1786 ;; In CORBA PSDL:
1787 "as" "implements" "of" "scope")
1788 pike '("inherit"))
1790 (c-lang-defconst c-ref-list-kwds
1791 "Keywords that may be followed by a comma separated list of
1792 reference (i.e. namespace/scope/module) identifiers, where each
1793 optionally can be prefixed by keywords. (Can also be used for the
1794 special case when the list can contain only one element.) Assumed to
1795 be mutually exclusive with `c-type-list-kwds'.
1797 Note: Use `c-typeless-decl-kwds' for keywords followed by a function
1798 or variable identifier (that's being defined)."
1799 t nil
1800 c++ '("namespace")
1801 java '("package")
1802 idl '("import" "module"
1803 ;; In CORBA CIDL:
1804 "composition")
1805 pike '("import"))
1807 (c-lang-defconst c-colon-type-list-kwds
1808 "Keywords that may be followed (not necessarily directly) by a colon
1809 and then a comma separated list of type identifiers, where each
1810 optionally can be prefixed by keywords. (Can also be used for the
1811 special case when the list can contain only one element.)"
1812 t nil
1813 c++ '("class" "struct")
1814 idl '("component" "eventtype" "home" "interface" "valuetype"
1815 ;; In CORBA PSDL:
1816 "storagehome" "storagetype"))
1818 (c-lang-defconst c-colon-type-list-re
1819 "Regexp matched after the keywords in `c-colon-type-list-kwds' to skip
1820 forward to the colon. The end of the match is assumed to be directly
1821 after the colon, so the regexp should end with \":\". Must be a
1822 regexp if `c-colon-type-list-kwds' isn't nil."
1823 t (if (c-lang-const c-colon-type-list-kwds)
1824 ;; Disallow various common punctuation chars that can't come
1825 ;; before the ":" that starts the inherit list after "class"
1826 ;; or "struct" in C++. (Also used as default for other
1827 ;; languages.)
1828 "[^\]\[{}();,/#=:]*:"))
1829 (c-lang-defvar c-colon-type-list-re (c-lang-const c-colon-type-list-re))
1831 (c-lang-defconst c-paren-nontype-kwds
1832 "Keywords that may be followed by a parenthesis expression that doesn't
1833 contain type identifiers."
1834 t nil
1835 (c c++) '(;; GCC extension.
1836 "__attribute__"
1837 ;; MSVC extension.
1838 "__declspec"))
1840 (c-lang-defconst c-paren-type-kwds
1841 "Keywords that may be followed by a parenthesis expression containing
1842 type identifiers separated by arbitrary tokens."
1843 t nil
1844 c++ '("throw")
1845 objc '("@defs")
1846 idl '("switch")
1847 pike '("array" "function" "int" "mapping" "multiset" "object" "program"))
1849 (c-lang-defconst c-paren-any-kwds
1850 t (delete-duplicates (append (c-lang-const c-paren-nontype-kwds)
1851 (c-lang-const c-paren-type-kwds))
1852 :test 'string-equal))
1854 (c-lang-defconst c-<>-type-kwds
1855 "Keywords that may be followed by an angle bracket expression
1856 containing type identifiers separated by \",\". The difference from
1857 `c-<>-arglist-kwds' is that unknown names are taken to be types and
1858 not other identifiers. `c-recognize-<>-arglists' is assumed to be set
1859 if this isn't nil."
1860 t nil
1861 objc '("id")
1862 idl '("sequence"
1863 ;; In CORBA PSDL:
1864 "ref"))
1866 (c-lang-defconst c-<>-arglist-kwds
1867 "Keywords that can be followed by a C++ style template arglist; see
1868 `c-recognize-<>-arglists' for details. That language constant is
1869 assumed to be set if this isn't nil."
1870 t nil
1871 c++ '("template")
1872 idl '("fixed" "string" "wstring"))
1874 (c-lang-defconst c-<>-sexp-kwds
1875 ;; All keywords that can be followed by an angle bracket sexp.
1876 t (delete-duplicates (append (c-lang-const c-<>-type-kwds)
1877 (c-lang-const c-<>-arglist-kwds))
1878 :test 'string-equal))
1880 (c-lang-defconst c-opt-<>-sexp-key
1881 ;; Adorned regexp matching keywords that can be followed by an angle
1882 ;; bracket sexp. Always set when `c-recognize-<>-arglists' is.
1883 t (if (c-lang-const c-recognize-<>-arglists)
1884 (c-make-keywords-re t (c-lang-const c-<>-sexp-kwds))))
1885 (c-lang-defvar c-opt-<>-sexp-key (c-lang-const c-opt-<>-sexp-key))
1887 (c-lang-defconst c-brace-id-list-kwds
1888 "Keywords that may be followed by a brace block containing a comma
1889 separated list of identifier definitions, i.e. like the list of
1890 identifiers that follows the type in a normal declaration."
1891 t (c-lang-const c-brace-list-decl-kwds))
1893 (c-lang-defconst c-block-stmt-1-kwds
1894 "Statement keywords followed directly by a substatement."
1895 t '("do" "else")
1896 c++ '("do" "else" "try")
1897 java '("do" "else" "finally" "try")
1898 idl nil)
1900 (c-lang-defconst c-block-stmt-1-key
1901 ;; Regexp matching the start of any statement followed directly by a
1902 ;; substatement (doesn't match a bare block, however).
1903 t (c-make-keywords-re t (c-lang-const c-block-stmt-1-kwds)))
1904 (c-lang-defvar c-block-stmt-1-key (c-lang-const c-block-stmt-1-key))
1906 (c-lang-defconst c-block-stmt-2-kwds
1907 "Statement keywords followed by a paren sexp and then by a substatement."
1908 t '("for" "if" "switch" "while")
1909 c++ '("for" "if" "switch" "while" "catch")
1910 java '("for" "if" "switch" "while" "catch" "synchronized")
1911 idl nil
1912 pike '("for" "if" "switch" "while" "foreach")
1913 awk '("for" "if" "while"))
1915 (c-lang-defconst c-block-stmt-2-key
1916 ;; Regexp matching the start of any statement followed by a paren sexp
1917 ;; and then by a substatement.
1918 t (c-make-keywords-re t (c-lang-const c-block-stmt-2-kwds)))
1919 (c-lang-defvar c-block-stmt-2-key (c-lang-const c-block-stmt-2-key))
1921 (c-lang-defconst c-block-stmt-kwds
1922 ;; Union of `c-block-stmt-1-kwds' and `c-block-stmt-2-kwds'.
1923 t (delete-duplicates (append (c-lang-const c-block-stmt-1-kwds)
1924 (c-lang-const c-block-stmt-2-kwds))
1925 :test 'string-equal))
1927 (c-lang-defconst c-opt-block-stmt-key
1928 ;; Regexp matching the start of any statement that has a
1929 ;; substatement (except a bare block). Nil in languages that
1930 ;; don't have such constructs.
1931 t (if (or (c-lang-const c-block-stmt-1-kwds)
1932 (c-lang-const c-block-stmt-2-kwds))
1933 (c-make-keywords-re t
1934 (append (c-lang-const c-block-stmt-1-kwds)
1935 (c-lang-const c-block-stmt-2-kwds)))))
1936 (c-lang-defvar c-opt-block-stmt-key (c-lang-const c-opt-block-stmt-key))
1938 (c-lang-defconst c-simple-stmt-kwds
1939 "Statement keywords followed by an expression or nothing."
1940 t '("break" "continue" "goto" "return")
1941 ;; Note: `goto' is not valid in Java, but the keyword is still reserved.
1942 java '("break" "continue" "goto" "return" "throw")
1943 idl nil
1944 pike '("break" "continue" "return")
1945 awk '(;; Not sure about "delete", "exit", "getline", etc. ; ACM 2002/5/30
1946 "break" "continue" "return" "delete" "exit" "getline" "next"
1947 "nextfile" "print" "printf"))
1949 (c-lang-defconst c-simple-stmt-key
1950 ;; Adorned regexp matching `c-simple-stmt-kwds'.
1951 t (c-make-keywords-re t (c-lang-const c-simple-stmt-kwds)))
1952 (c-lang-defvar c-simple-stmt-key (c-lang-const c-simple-stmt-key))
1954 (c-lang-defconst c-paren-stmt-kwds
1955 "Statement keywords followed by a parenthesis expression that
1956 nevertheless contains a list separated with ';' and not ','."
1957 t '("for")
1958 idl nil)
1960 (c-lang-defconst c-paren-stmt-key
1961 ;; Adorned regexp matching `c-paren-stmt-kwds'.
1962 t (c-make-keywords-re t (c-lang-const c-paren-stmt-kwds)))
1963 (c-lang-defvar c-paren-stmt-key (c-lang-const c-paren-stmt-key))
1965 (c-lang-defconst c-asm-stmt-kwds
1966 "Statement keywords followed by an assembler expression."
1967 t nil
1968 (c c++) '("asm" "__asm__")) ;; Not standard, but common.
1970 (c-lang-defconst c-opt-asm-stmt-key
1971 ;; Regexp matching the start of an assembler statement. Nil in
1972 ;; languages that don't support that.
1973 t (if (c-lang-const c-asm-stmt-kwds)
1974 (c-make-keywords-re t (c-lang-const c-asm-stmt-kwds))))
1975 (c-lang-defvar c-opt-asm-stmt-key (c-lang-const c-opt-asm-stmt-key))
1977 (c-lang-defconst c-label-kwds
1978 "Keywords introducing colon terminated labels in blocks."
1979 t '("case" "default")
1980 awk nil)
1982 (c-lang-defconst c-label-kwds-regexp
1983 ;; Adorned regexp matching any keyword that introduces a label.
1984 t (c-make-keywords-re t (c-lang-const c-label-kwds)))
1985 (c-lang-defvar c-label-kwds-regexp (c-lang-const c-label-kwds-regexp))
1987 (c-lang-defconst c-before-label-kwds
1988 "Keywords that might be followed by a label identifier."
1989 t '("goto")
1990 (java pike) (append '("break" "continue")
1991 (c-lang-const c-before-label-kwds))
1992 idl nil
1993 awk nil)
1995 (c-lang-defconst c-constant-kwds
1996 "Keywords for constants."
1997 t nil
1998 (c c++) '("NULL" ;; Not a keyword, but practically works as one.
1999 "false" "true") ; Defined in C99.
2000 objc '("nil" "Nil")
2001 idl '("TRUE" "FALSE")
2002 pike '("UNDEFINED")) ;; Not a keyword, but practically works as one.
2004 (c-lang-defconst c-primary-expr-kwds
2005 "Keywords besides constants and operators that start primary expressions."
2006 t nil
2007 c++ '("operator" "this")
2008 objc '("super" "self")
2009 java '("this")
2010 pike '("this")) ;; Not really a keyword, but practically works as one.
2012 (c-lang-defconst c-expr-kwds
2013 ;; Keywords that can occur anywhere in expressions. Built from
2014 ;; `c-primary-expr-kwds' and all keyword operators in `c-operators'.
2015 t (delete-duplicates
2016 (append (c-lang-const c-primary-expr-kwds)
2017 (c-filter-ops (c-lang-const c-operator-list)
2019 "\\`\\(\\w\\|\\s_\\)+\\'"))
2020 :test 'string-equal))
2022 (c-lang-defconst c-lambda-kwds
2023 "Keywords that start lambda constructs, i.e. function definitions in
2024 expressions."
2025 t nil
2026 pike '("lambda"))
2028 (c-lang-defconst c-inexpr-block-kwds
2029 "Keywords that start constructs followed by statement blocks which can
2030 be used in expressions \(the gcc extension for this in C and C++ is
2031 handled separately by `c-recognize-paren-inexpr-blocks')."
2032 t nil
2033 pike '("catch" "gauge"))
2035 (c-lang-defconst c-inexpr-class-kwds
2036 "Keywords that can start classes inside expressions."
2037 t nil
2038 java '("new")
2039 pike '("class"))
2041 (c-lang-defconst c-inexpr-brace-list-kwds
2042 "Keywords that can start brace list blocks inside expressions.
2043 Note that Java specific rules are currently applied to tell this from
2044 `c-inexpr-class-kwds'."
2045 t nil
2046 java '("new"))
2048 (c-lang-defconst c-opt-inexpr-brace-list-key
2049 ;; Regexp matching the start of a brace list in an expression, or
2050 ;; nil in languages that don't have such things. This should not
2051 ;; match brace lists recognized through `c-special-brace-lists'.
2052 t (and (c-lang-const c-inexpr-brace-list-kwds)
2053 (c-make-keywords-re t (c-lang-const c-inexpr-brace-list-kwds))))
2054 (c-lang-defvar c-opt-inexpr-brace-list-key
2055 (c-lang-const c-opt-inexpr-brace-list-key))
2057 (c-lang-defconst c-decl-block-key
2058 ;; Regexp matching keywords in any construct that contain another
2059 ;; declaration level, i.e. that isn't followed by a function block
2060 ;; or brace list. When the first submatch matches, it's an
2061 ;; unambiguous construct, otherwise it's an ambiguous match that
2062 ;; might also be the return type of a function declaration.
2063 t (let* ((decl-kwds (append (c-lang-const c-class-decl-kwds)
2064 (c-lang-const c-other-block-decl-kwds)
2065 (c-lang-const c-inexpr-class-kwds)))
2066 (unambiguous (set-difference decl-kwds
2067 (c-lang-const c-type-start-kwds)
2068 :test 'string-equal))
2069 (ambiguous (intersection decl-kwds
2070 (c-lang-const c-type-start-kwds)
2071 :test 'string-equal)))
2072 (if ambiguous
2073 (concat (c-make-keywords-re t unambiguous)
2074 "\\|"
2075 (c-make-keywords-re t ambiguous))
2076 (c-make-keywords-re t unambiguous))))
2077 (c-lang-defvar c-decl-block-key (c-lang-const c-decl-block-key))
2079 (c-lang-defconst c-bitfield-kwds
2080 "Keywords that can introduce bitfields."
2081 t nil
2082 (c c++ objc) '("char" "int" "long" "signed" "unsigned"))
2084 (c-lang-defconst c-opt-bitfield-key
2085 ;; Regexp matching the start of a bitfield (not uniquely), or nil in
2086 ;; languages without bitfield support.
2087 t nil
2088 (c c++) (c-make-keywords-re t (c-lang-const c-bitfield-kwds)))
2089 (c-lang-defvar c-opt-bitfield-key (c-lang-const c-opt-bitfield-key))
2091 (c-lang-defconst c-other-kwds
2092 "Keywords not accounted for by any other `*-kwds' language constant."
2093 t nil
2094 idl '("truncatable"
2095 ;; In CORBA CIDL: (These are declaration keywords that never
2096 ;; can start a declaration.)
2097 "entity" "process" "service" "session" "storage"))
2100 ;;; Constants built from keywords.
2102 ;; Note: No `*-kwds' language constants may be defined below this point.
2104 (eval-and-compile
2105 (defconst c-kwds-lang-consts
2106 ;; List of all the language constants that contain keyword lists.
2107 (let (list)
2108 (mapatoms (lambda (sym)
2109 (when (and (boundp sym)
2110 (string-match "-kwds\\'" (symbol-name sym)))
2111 ;; Make the list of globally interned symbols
2112 ;; instead of ones interned in `c-lang-constants'.
2113 (setq list (cons (intern (symbol-name sym)) list))))
2114 c-lang-constants)
2115 list)))
2117 (c-lang-defconst c-keywords
2118 ;; All keywords as a list.
2119 t (delete-duplicates
2120 (c-lang-defconst-eval-immediately
2121 `(append ,@(mapcar (lambda (kwds-lang-const)
2122 `(c-lang-const ,kwds-lang-const))
2123 c-kwds-lang-consts)
2124 nil))
2125 :test 'string-equal))
2127 (c-lang-defconst c-keywords-regexp
2128 ;; All keywords as an adorned regexp.
2129 t (c-make-keywords-re t (c-lang-const c-keywords)))
2130 (c-lang-defvar c-keywords-regexp (c-lang-const c-keywords-regexp))
2132 (c-lang-defconst c-keyword-member-alist
2133 ;; An alist with all the keywords in the cars. The cdr for each
2134 ;; keyword is a list of the symbols for the `*-kwds' lists that
2135 ;; contains it.
2136 t (let ((kwd-list-alist
2137 (c-lang-defconst-eval-immediately
2138 `(list ,@(mapcar (lambda (kwds-lang-const)
2139 `(cons ',kwds-lang-const
2140 (c-lang-const ,kwds-lang-const)))
2141 c-kwds-lang-consts))))
2142 lang-const kwd-list kwd
2143 result-alist elem)
2144 (while kwd-list-alist
2145 (setq lang-const (caar kwd-list-alist)
2146 kwd-list (cdar kwd-list-alist)
2147 kwd-list-alist (cdr kwd-list-alist))
2148 (while kwd-list
2149 (setq kwd (car kwd-list)
2150 kwd-list (cdr kwd-list))
2151 (unless (setq elem (assoc kwd result-alist))
2152 (setq result-alist (cons (setq elem (list kwd)) result-alist)))
2153 (unless (memq lang-const (cdr elem))
2154 (setcdr elem (cons lang-const (cdr elem))))))
2155 result-alist))
2157 (c-lang-defvar c-keywords-obarray
2158 ;; An obarray containing all keywords as symbols. The property list
2159 ;; of each symbol has a non-nil entry for the specific `*-kwds'
2160 ;; lists it's a member of.
2162 ;; E.g. to see whether the string str contains a keyword on
2163 ;; `c-class-decl-kwds', one can do like this:
2164 ;; (get (intern-soft str c-keyword-obarray) 'c-class-decl-kwds)
2165 ;; Which preferably is written using the associated functions in
2166 ;; cc-engine:
2167 ;; (c-keyword-member (c-keyword-sym str) 'c-class-decl-kwds)
2169 ;; The obarray is not stored directly as a language constant since
2170 ;; the printed representation for obarrays used in .elc files isn't
2171 ;; complete.
2173 (let* ((alist (c-lang-const c-keyword-member-alist))
2174 kwd lang-const-list
2175 (obarray (make-vector (* (length alist) 2) 0)))
2176 (while alist
2177 (setq kwd (caar alist)
2178 lang-const-list (cdar alist)
2179 alist (cdr alist))
2180 (setplist (intern kwd obarray)
2181 ;; Emacs has an odd bug that causes `mapcan' to fail
2182 ;; with unintelligible errors. (XEmacs works.)
2183 ;;(mapcan (lambda (lang-const)
2184 ;; (list lang-const t))
2185 ;; lang-const-list)
2186 (apply 'nconc (mapcar (lambda (lang-const)
2187 (list lang-const t))
2188 lang-const-list))))
2189 obarray))
2191 (c-lang-defconst c-regular-keywords-regexp
2192 ;; Adorned regexp matching all keywords that should be fontified
2193 ;; with the keywords face. I.e. that aren't types or constants.
2194 t (c-make-keywords-re t
2195 (set-difference (c-lang-const c-keywords)
2196 (append (c-lang-const c-primitive-type-kwds)
2197 (c-lang-const c-constant-kwds))
2198 :test 'string-equal)))
2199 (c-lang-defvar c-regular-keywords-regexp
2200 (c-lang-const c-regular-keywords-regexp))
2202 (c-lang-defconst c-primary-expr-regexp
2203 ;; Regexp matching the start of any primary expression, i.e. any
2204 ;; literal, symbol, prefix operator, and '('. It doesn't need to
2205 ;; exclude keywords; they are excluded afterwards unless the second
2206 ;; submatch matches. If the first but not the second submatch
2207 ;; matches then it is an ambiguous primary expression; it could also
2208 ;; be a match of e.g. an infix operator. (The case with ambiguous
2209 ;; keyword operators isn't handled.)
2211 t (let* ((prefix-ops
2212 (c-filter-ops (c-lang-const c-operators)
2213 '(prefix)
2214 (lambda (op)
2215 ;; Filter out the special case prefix
2216 ;; operators that are close parens.
2217 (not (string-match "\\s)" op)))))
2219 (nonkeyword-prefix-ops
2220 (c-filter-ops prefix-ops
2222 "\\`\\(\\s.\\|\\s(\\|\\s)\\)+\\'"))
2224 (in-or-postfix-ops
2225 (c-filter-ops (c-lang-const c-operators)
2226 '(postfix
2227 postfix-if-paren
2228 left-assoc
2229 right-assoc
2230 right-assoc-sequence)
2233 (unambiguous-prefix-ops (set-difference nonkeyword-prefix-ops
2234 in-or-postfix-ops
2235 :test 'string-equal))
2236 (ambiguous-prefix-ops (intersection nonkeyword-prefix-ops
2237 in-or-postfix-ops
2238 :test 'string-equal)))
2240 (concat
2241 "\\("
2242 ;; Take out all symbol class operators from `prefix-ops' and make the
2243 ;; first submatch from them together with `c-primary-expr-kwds'.
2244 (c-make-keywords-re t
2245 (append (c-lang-const c-primary-expr-kwds)
2246 (set-difference prefix-ops nonkeyword-prefix-ops
2247 :test 'string-equal)))
2249 "\\|"
2250 ;; Match all ambiguous operators.
2251 (c-make-keywords-re nil
2252 (intersection nonkeyword-prefix-ops in-or-postfix-ops
2253 :test 'string-equal))
2254 "\\)"
2256 "\\|"
2257 ;; Now match all other symbols.
2258 (c-lang-const c-symbol-start)
2260 "\\|"
2261 ;; The chars that can start integer and floating point
2262 ;; constants.
2263 "\\.?[0-9]"
2265 "\\|"
2266 ;; The nonambiguous operators from `prefix-ops'.
2267 (c-make-keywords-re nil
2268 (set-difference nonkeyword-prefix-ops in-or-postfix-ops
2269 :test 'string-equal))
2271 "\\|"
2272 ;; Match string and character literals.
2273 "\\s\""
2274 (if (memq 'gen-string-delim c-emacs-features)
2275 "\\|\\s|"
2276 ""))))
2277 (c-lang-defvar c-primary-expr-regexp (c-lang-const c-primary-expr-regexp))
2280 ;;; Additional constants for parser-level constructs.
2282 (c-lang-defconst c-decl-prefix-re
2283 "Regexp matching something that might precede a declaration, cast or
2284 label, such as the last token of a preceding statement or declaration.
2285 This is used in the common situation where a declaration or cast
2286 doesn't start with any specific token that can be searched for.
2288 The regexp should not match bob; that is done implicitly. It can't
2289 require a match longer than one token. The end of the token is taken
2290 to be at the end of the first submatch, which is assumed to always
2291 match. It's undefined whether identifier syntax (see
2292 `c-identifier-syntax-table') is in effect or not. This regexp is
2293 assumed to be a superset of `c-label-prefix-re' if
2294 `c-recognize-colon-labels' is set.
2296 Besides this, `c-decl-start-kwds' is used to find declarations.
2298 Note: This variable together with `c-decl-start-re' and
2299 `c-decl-start-kwds' is only used to detect \"likely\"
2300 declaration/cast/label starts. I.e. they might produce more matches
2301 but should not miss anything (or else it's necessary to use text
2302 properties - see the next note). Wherever they match, the following
2303 construct is analyzed to see if it indeed is a declaration, cast or
2304 label. That analysis is not cheap, so it's important that not too
2305 many false matches are triggered.
2307 Note: If a declaration/cast/label start can't be detected with this
2308 variable, it's necessary to use the `c-type' text property with the
2309 value `c-decl-end' on the last char of the last token preceding the
2310 declaration. See the comment blurb at the start of cc-engine.el for
2311 more info."
2313 ;; We match a sequence of characters to skip over things like \"};\"
2314 ;; more quickly. We match ")" in C for K&R region declarations, and
2315 ;; in all languages except Java for when a cpp macro definition
2316 ;; begins with a declaration.
2317 t "\\([\{\}\(\);,]+\\)"
2318 java "\\([\{\}\(;,]+\\)"
2319 ;; Match "<" in C++ to get the first argument in a template arglist.
2320 ;; In that case there's an additional check in `c-find-decl-spots'
2321 ;; that it got open paren syntax.
2322 c++ "\\([\{\}\(\);,<]+\\)"
2323 ;; Additionally match the protection directives in Objective-C.
2324 ;; Note that this doesn't cope with the longer directives, which we
2325 ;; would have to match from start to end since they don't end with
2326 ;; any easily recognized characters.
2327 objc (concat "\\([\{\}\(\);,]+\\|"
2328 (c-make-keywords-re nil (c-lang-const c-protection-kwds))
2329 "\\)")
2330 ;; Pike is like C but we also match "[" for multiple value
2331 ;; assignments and type casts.
2332 pike "\\([\{\}\(\)\[;,]+\\)")
2333 (c-lang-defvar c-decl-prefix-re (c-lang-const c-decl-prefix-re)
2334 'dont-doc)
2336 (c-lang-defconst c-decl-start-re
2337 "Regexp matching the start of any declaration, cast or label.
2338 It's used on the token after the one `c-decl-prefix-re' matched. This
2339 regexp should not try to match those constructs accurately as it's
2340 only used as a sieve to avoid spending more time checking other
2341 constructs."
2342 t (c-lang-const c-identifier-start))
2343 (c-lang-defvar c-decl-start-re (c-lang-const c-decl-start-re))
2345 (c-lang-defconst c-decl-prefix-or-start-re
2346 ;; Regexp matching something that might precede or start a
2347 ;; declaration, cast or label.
2349 ;; If the first submatch matches, it's taken to match the end of a
2350 ;; token that might precede such a construct, e.g. ';', '}' or '{'.
2351 ;; It's built from `c-decl-prefix-re'.
2353 ;; If the first submatch did not match, the match of the whole
2354 ;; regexp is taken to be at the first token in the declaration.
2355 ;; `c-decl-start-re' is not checked in this case.
2357 ;; Design note: The reason the same regexp is used to match both
2358 ;; tokens that precede declarations and start them is to avoid an
2359 ;; extra regexp search from the previous declaration spot in
2360 ;; `c-find-decl-spots'. Users of `c-find-decl-spots' also count on
2361 ;; that it finds all declaration/cast/label starts in approximately
2362 ;; linear order, so we can't do the searches in two separate passes.
2363 t (if (c-lang-const c-decl-start-kwds)
2364 (concat (c-lang-const c-decl-prefix-re)
2365 "\\|"
2366 (c-make-keywords-re t (c-lang-const c-decl-start-kwds)))
2367 (c-lang-const c-decl-prefix-re)))
2368 (c-lang-defvar c-decl-prefix-or-start-re
2369 (c-lang-const c-decl-prefix-or-start-re)
2370 'dont-doc)
2372 (c-lang-defconst c-cast-parens
2373 ;; List containing the paren characters that can open a cast, or nil in
2374 ;; languages without casts.
2375 t (c-filter-ops (c-lang-const c-operators)
2376 '(prefix)
2377 "\\`\\s\(\\'"
2378 (lambda (op) (elt op 0))))
2379 (c-lang-defvar c-cast-parens (c-lang-const c-cast-parens))
2381 (c-lang-defconst c-block-prefix-disallowed-chars
2382 "List of syntactically relevant characters that never can occur before
2383 the open brace in any construct that contains a brace block, e.g. in
2384 the \"class Foo: public Bar\" part of:
2386 class Foo: public Bar {int x();} a, *b;
2388 If parens can occur, the chars inside those aren't filtered with this
2389 list.
2391 '<' and '>' should be disallowed even if angle bracket arglists can
2392 occur. That since the search function needs to stop at them anyway to
2393 ensure they are given paren syntax.
2395 This is used to skip backward from the open brace to find the region
2396 in which to look for a construct like \"class\", \"enum\",
2397 \"namespace\" or whatever. That skipping should be as tight as
2398 possible for good performance."
2400 ;; Default to all chars that only occurs in nonsymbol tokens outside
2401 ;; identifiers.
2402 t (set-difference
2403 (c-lang-const c-nonsymbol-token-char-list)
2404 (c-filter-ops (append (c-lang-const c-identifier-ops)
2405 (list (cons nil
2406 (c-lang-const c-after-id-concat-ops))))
2409 (lambda (op)
2410 (let ((pos 0) res)
2411 (while (string-match "\\(\\s.\\|\\s(\\|\\s)\\)"
2412 op pos)
2413 (setq res (cons (aref op (match-beginning 1)) res)
2414 pos (match-end 0)))
2415 res))))
2417 ;; Allow cpp operatios (where applicable).
2418 t (if (c-lang-const c-opt-cpp-prefix)
2419 (set-difference (c-lang-const c-block-prefix-disallowed-chars)
2420 '(?#))
2421 (c-lang-const c-block-prefix-disallowed-chars))
2423 ;; Allow ':' for inherit list starters.
2424 (c++ objc idl) (set-difference (c-lang-const c-block-prefix-disallowed-chars)
2425 '(?:))
2427 ;; Allow ',' for multiple inherits.
2428 (c++ java) (set-difference (c-lang-const c-block-prefix-disallowed-chars)
2429 '(?,))
2431 ;; Allow parentheses for anonymous inner classes in Java and class
2432 ;; initializer lists in Pike.
2433 (java pike) (set-difference (c-lang-const c-block-prefix-disallowed-chars)
2434 '(?\( ?\)))
2436 ;; Allow '"' for extern clauses (e.g. extern "C" {...}).
2437 (c c++ objc) (set-difference (c-lang-const c-block-prefix-disallowed-chars)
2438 '(?\" ?')))
2440 (c-lang-defconst c-block-prefix-charset
2441 ;; `c-block-prefix-disallowed-chars' as an inverted charset suitable
2442 ;; for `c-syntactic-skip-backward'.
2443 t (c-make-bare-char-alt (c-lang-const c-block-prefix-disallowed-chars) t))
2444 (c-lang-defvar c-block-prefix-charset (c-lang-const c-block-prefix-charset))
2446 (c-lang-defconst c-type-decl-prefix-key
2447 "Regexp matching the declarator operators that might precede the
2448 identifier in a declaration, e.g. the \"*\" in \"char *argv\". This
2449 regexp should match \"(\" if parentheses are valid in declarators.
2450 The end of the first submatch is taken as the end of the operator.
2451 Identifier syntax is in effect when this is matched \(see
2452 `c-identifier-syntax-table')."
2453 t (if (c-lang-const c-type-modifier-kwds)
2454 (concat (regexp-opt (c-lang-const c-type-modifier-kwds) t) "\\>")
2455 ;; Default to a regexp that never matches.
2456 "\\<\\>")
2457 ;; Check that there's no "=" afterwards to avoid matching tokens
2458 ;; like "*=".
2459 (c objc) (concat "\\("
2460 "[*\(]"
2461 "\\|"
2462 (c-lang-const c-type-decl-prefix-key)
2463 "\\)"
2464 "\\([^=]\\|$\\)")
2465 c++ (concat "\\("
2466 "[*\(&]"
2467 "\\|"
2468 (concat "\\(" ; 2
2469 ;; If this matches there's special treatment in
2470 ;; `c-font-lock-declarators' and
2471 ;; `c-font-lock-declarations' that check for a
2472 ;; complete name followed by ":: *".
2473 (c-lang-const c-identifier-start)
2474 "\\)")
2475 "\\|"
2476 (c-lang-const c-type-decl-prefix-key)
2477 "\\)"
2478 "\\([^=]\\|$\\)")
2479 pike "\\(\\*\\)\\([^=]\\|$\\)")
2480 (c-lang-defvar c-type-decl-prefix-key (c-lang-const c-type-decl-prefix-key)
2481 'dont-doc)
2483 (c-lang-defconst c-type-decl-suffix-key
2484 "Regexp matching the declarator operators that might follow after the
2485 identifier in a declaration, e.g. the \"[\" in \"char argv[]\". This
2486 regexp should match \")\" if parentheses are valid in declarators. If
2487 it matches an open paren of some kind, the type declaration check
2488 continues at the corresponding close paren, otherwise the end of the
2489 first submatch is taken as the end of the operator. Identifier syntax
2490 is in effect when this is matched (see `c-identifier-syntax-table')."
2491 ;; Default to a regexp that matches `c-type-modifier-kwds' and a
2492 ;; function argument list parenthesis.
2493 t (if (c-lang-const c-type-modifier-kwds)
2494 (concat "\\(\(\\|"
2495 (regexp-opt (c-lang-const c-type-modifier-kwds) t) "\\>"
2496 "\\)")
2497 "\\(\(\\)")
2498 (c c++ objc) (concat
2499 "\\("
2500 "[\)\[\(]"
2501 (if (c-lang-const c-type-modifier-kwds)
2502 (concat
2503 "\\|"
2504 ;; "throw" in `c-type-modifier-kwds' is followed
2505 ;; by a parenthesis list, but no extra measures
2506 ;; are necessary to handle that.
2507 (regexp-opt (c-lang-const c-type-modifier-kwds) t)
2508 "\\>")
2510 "\\)")
2511 (java idl) "\\([\[\(]\\)")
2512 (c-lang-defvar c-type-decl-suffix-key (c-lang-const c-type-decl-suffix-key)
2513 'dont-doc)
2515 (c-lang-defconst c-after-suffixed-type-decl-key
2516 "This regexp is matched after a declarator expression where
2517 `c-type-decl-suffix-key' has matched. If it matches then the
2518 construct is taken as a declaration. It's typically used to match the
2519 beginning of a function body or whatever might occur after the
2520 function header in a function declaration or definition. It's
2521 undefined whether identifier syntax (see `c-identifier-syntax-table')
2522 is in effect or not.
2524 Note that it's used in cases like after \"foo (bar)\" so it should
2525 only match when it's certain that it's a declaration, e.g \"{\" but
2526 not \",\" or \";\"."
2527 t "{"
2528 ;; If K&R style declarations should be recognized then one could
2529 ;; consider to match the start of any symbol since we want to match
2530 ;; the start of the first declaration in the "K&R region". That
2531 ;; could however produce false matches on code like "FOO(bar) x"
2532 ;; where FOO is a cpp macro, so it's better to leave it out and rely
2533 ;; on the other heuristics in that case.
2534 t (if (c-lang-const c-postfix-spec-kwds)
2535 ;; Add on the keywords in `c-postfix-spec-kwds'.
2536 (concat (c-lang-const c-after-suffixed-type-decl-key)
2537 "\\|"
2538 (c-make-keywords-re t (c-lang-const c-postfix-spec-kwds)))
2539 (c-lang-const c-after-suffixed-type-decl-key))
2540 ;; Also match the colon that starts a base class initializer list in
2541 ;; C++. That can be confused with a function call before the colon
2542 ;; in a ? : operator, but we count on that `c-decl-prefix-re' won't
2543 ;; match before such a thing (as a declaration-level construct;
2544 ;; matches inside arglist contexts are already excluded).
2545 c++ "[{:]")
2546 (c-lang-defvar c-after-suffixed-type-decl-key
2547 (c-lang-const c-after-suffixed-type-decl-key)
2548 'dont-doc)
2550 (c-lang-defconst c-after-suffixed-type-maybe-decl-key
2551 ;; Regexp that in addition to `c-after-suffixed-type-decl-key'
2552 ;; matches ";" and ",".
2553 t (concat "\\(" (c-lang-const c-after-suffixed-type-decl-key) "\\)"
2554 "\\|[;,]"))
2555 (c-lang-defvar c-after-suffixed-type-maybe-decl-key
2556 (c-lang-const c-after-suffixed-type-maybe-decl-key))
2558 (c-lang-defconst c-opt-type-concat-key
2559 "Regexp matching operators that concatenate types, e.g. the \"|\" in
2560 \"int|string\" in Pike. The end of the first submatch is taken as the
2561 end of the operator. nil in languages without such operators. It's
2562 undefined whether identifier syntax (see `c-identifier-syntax-table')
2563 is in effect or not."
2564 t nil
2565 pike "\\([|.&]\\)\\($\\|[^|.&]\\)")
2566 (c-lang-defvar c-opt-type-concat-key (c-lang-const c-opt-type-concat-key)
2567 'dont-doc)
2569 (c-lang-defconst c-opt-type-suffix-key
2570 "Regexp matching operators that might follow after a type, or nil in
2571 languages that don't have such operators. The end of the first
2572 submatch is taken as the end of the operator. This should not match
2573 things like C++ template arglists if `c-recognize-<>-arglists' is set.
2574 It's undefined whether identifier syntax (see `c-identifier-syntax-table')
2575 is in effect or not."
2576 t nil
2577 (c c++ objc pike) "\\(\\.\\.\\.\\)"
2578 java (concat "\\(\\[" (c-lang-const c-simple-ws) "*\\]\\)"))
2579 (c-lang-defvar c-opt-type-suffix-key (c-lang-const c-opt-type-suffix-key))
2581 (c-lang-defvar c-known-type-key
2582 ;; Regexp matching the known type identifiers. This is initialized
2583 ;; from the type keywords and `*-font-lock-extra-types'. The first
2584 ;; submatch is the one that matches the type. Note that this regexp
2585 ;; assumes that symbol constituents like '_' and '$' have word
2586 ;; syntax.
2587 (let* ((extra-types
2588 (when (boundp (c-mode-symbol "font-lock-extra-types"))
2589 (c-mode-var "font-lock-extra-types")))
2590 (regexp-strings
2591 (apply 'nconc
2592 (mapcar (lambda (re)
2593 (when (string-match "[][.*+?^$\\]" re)
2594 (list re)))
2595 extra-types)))
2596 (plain-strings
2597 (apply 'nconc
2598 (mapcar (lambda (re)
2599 (unless (string-match "[][.*+?^$\\]" re)
2600 (list re)))
2601 extra-types))))
2602 (concat "\\<\\("
2603 (c-concat-separated
2604 (append (list (c-make-keywords-re nil
2605 (append (c-lang-const c-primitive-type-kwds)
2606 plain-strings)))
2607 regexp-strings)
2608 "\\|")
2609 "\\)\\>")))
2611 (c-lang-defconst c-special-brace-lists
2612 "List of open- and close-chars that makes up a pike-style brace list,
2613 i.e. for a ([ ]) list there should be a cons (?\\[ . ?\\]) in this
2614 list."
2615 t nil
2616 pike '((?{ . ?}) (?\[ . ?\]) (?< . ?>)))
2617 (c-lang-defvar c-special-brace-lists (c-lang-const c-special-brace-lists))
2619 (c-lang-defconst c-recognize-knr-p
2620 "Non-nil means K&R style argument declarations are valid."
2621 t nil
2622 c t)
2623 (c-lang-defvar c-recognize-knr-p (c-lang-const c-recognize-knr-p))
2625 (c-lang-defconst c-recognize-typeless-decls
2626 "Non-nil means function declarations without return type should be
2627 recognized. That can introduce an ambiguity with parenthesized macro
2628 calls before a brace block. This setting does not affect declarations
2629 that are preceded by a declaration starting keyword, so
2630 e.g. `c-typeless-decl-kwds' may still be used when it's set to nil."
2631 t nil
2632 (c c++ objc) t)
2633 (c-lang-defvar c-recognize-typeless-decls
2634 (c-lang-const c-recognize-typeless-decls))
2636 (c-lang-defconst c-recognize-<>-arglists
2637 "Non-nil means C++ style template arglists should be handled. More
2638 specifically, this means a comma separated list of types or
2639 expressions surrounded by \"<\" and \">\". It's always preceded by an
2640 identifier or one of the keywords on `c-<>-type-kwds' or
2641 `c-<>-arglist-kwds'. If there's an identifier before then the whole
2642 expression is considered to be a type."
2643 t (or (consp (c-lang-const c-<>-type-kwds))
2644 (consp (c-lang-const c-<>-arglist-kwds))))
2645 (c-lang-defvar c-recognize-<>-arglists (c-lang-const c-recognize-<>-arglists))
2647 (c-lang-defconst c-recognize-paren-inits
2648 "Non-nil means that parenthesis style initializers exist,
2649 i.e. constructs like
2651 Foo bar (gnu);
2653 in addition to the more classic
2655 Foo bar = gnu;"
2656 t nil
2657 c++ t)
2658 (c-lang-defvar c-recognize-paren-inits (c-lang-const c-recognize-paren-inits))
2660 (c-lang-defconst c-recognize-paren-inexpr-blocks
2661 "Non-nil to recognize gcc style in-expression blocks,
2662 i.e. compound statements surrounded by parentheses inside expressions."
2663 t nil
2664 (c c++) t)
2665 (c-lang-defvar c-recognize-paren-inexpr-blocks
2666 (c-lang-const c-recognize-paren-inexpr-blocks))
2668 (c-lang-defconst c-opt-<>-arglist-start
2669 ;; Regexp matching the start of angle bracket arglists in languages
2670 ;; where `c-recognize-<>-arglists' is set. Does not exclude
2671 ;; keywords outside `c-<>-arglist-kwds'. The first submatch is
2672 ;; assumed to surround the preceding symbol. The whole match is
2673 ;; assumed to end directly after the opening "<".
2674 t (if (c-lang-const c-recognize-<>-arglists)
2675 (concat "\\("
2676 (c-lang-const c-symbol-key)
2677 "\\)"
2678 (c-lang-const c-syntactic-ws)
2679 "<")))
2680 (c-lang-defvar c-opt-<>-arglist-start (c-lang-const c-opt-<>-arglist-start))
2682 (c-lang-defconst c-opt-<>-arglist-start-in-paren
2683 ;; Regexp that in addition to `c-opt-<>-arglist-start' matches close
2684 ;; parens. The first submatch is assumed to surround
2685 ;; `c-opt-<>-arglist-start'.
2686 t (if (c-lang-const c-opt-<>-arglist-start)
2687 (concat "\\("
2688 (c-lang-const c-opt-<>-arglist-start)
2689 "\\)\\|\\s\)")))
2690 (c-lang-defvar c-opt-<>-arglist-start-in-paren
2691 (c-lang-const c-opt-<>-arglist-start-in-paren))
2693 (c-lang-defconst c-opt-postfix-decl-spec-key
2694 ;; Regexp matching the beginning of a declaration specifier in the
2695 ;; region between the header and the body of a declaration.
2697 ;; TODO: This is currently not used uniformly; c++-mode and
2698 ;; java-mode each have their own ways of using it.
2699 t nil
2700 c++ (concat ":?"
2701 (c-lang-const c-simple-ws) "*"
2702 "\\(virtual" (c-lang-const c-simple-ws) "+\\)?\\("
2703 (c-make-keywords-re nil (c-lang-const c-protection-kwds))
2704 "\\)" (c-lang-const c-simple-ws) "+"
2705 "\\(" (c-lang-const c-symbol-key) "\\)")
2706 java (c-make-keywords-re t (c-lang-const c-postfix-spec-kwds)))
2707 (c-lang-defvar c-opt-postfix-decl-spec-key
2708 (c-lang-const c-opt-postfix-decl-spec-key))
2710 (c-lang-defconst c-recognize-colon-labels
2711 "Non-nil if generic labels ending with \":\" should be recognized.
2712 That includes labels in code and access keys in classes. This does
2713 not apply to labels recognized by `c-label-kwds' and
2714 `c-opt-extra-label-key'."
2715 t nil
2716 (c c++ objc java pike) t)
2717 (c-lang-defvar c-recognize-colon-labels
2718 (c-lang-const c-recognize-colon-labels))
2720 (c-lang-defconst c-label-prefix-re
2721 "Regexp like `c-decl-prefix-re' that matches any token that can precede
2722 a generic colon label. Not used if `c-recognize-colon-labels' is
2723 nil."
2724 t "\\([{};]+\\)")
2725 (c-lang-defvar c-label-prefix-re
2726 (c-lang-const c-label-prefix-re))
2728 (c-lang-defconst c-nonlabel-token-key
2729 "Regexp matching things that can't occur in generic colon labels,
2730 neither in a statement nor in a declaration context. The regexp is
2731 tested at the beginning of every sexp in a suspected label,
2732 i.e. before \":\". Only used if `c-recognize-colon-labels' is set."
2733 t (concat
2734 ;; Don't allow string literals.
2735 "[\"']\\|"
2736 ;; All keywords except `c-label-kwds' and `c-protection-kwds'.
2737 (c-make-keywords-re t
2738 (set-difference (c-lang-const c-keywords)
2739 (append (c-lang-const c-label-kwds)
2740 (c-lang-const c-protection-kwds))
2741 :test 'string-equal)))
2742 ;; Also check for open parens in C++, to catch member init lists in
2743 ;; constructors. We normally allow it so that macros with arguments
2744 ;; work in labels.
2745 c++ (concat "\\s\(\\|" (c-lang-const c-nonlabel-token-key)))
2746 (c-lang-defvar c-nonlabel-token-key (c-lang-const c-nonlabel-token-key))
2748 (c-lang-defconst c-opt-extra-label-key
2749 "Optional regexp matching labels.
2750 Normally, labels are detected according to `c-nonlabel-token-key',
2751 `c-decl-prefix-re' and `c-nonlabel-decl-prefix-re'. This regexp can
2752 be used if there are additional labels that aren't recognized that
2753 way."
2754 t nil
2755 objc (c-make-keywords-re t (c-lang-const c-protection-kwds)))
2756 (c-lang-defvar c-opt-extra-label-key (c-lang-const c-opt-extra-label-key))
2758 (c-lang-defconst c-opt-friend-key
2759 ;; Regexp describing friend declarations classes, or nil in
2760 ;; languages that don't have such things.
2762 ;; TODO: Ought to use `c-prefix-spec-kwds-re' or similar, and the
2763 ;; template skipping isn't done properly. This will disappear soon.
2764 t nil
2765 c++ (concat "friend" (c-lang-const c-simple-ws) "+"
2766 "\\|"
2767 (concat "template"
2768 (c-lang-const c-simple-ws) "*"
2769 "<.+>"
2770 (c-lang-const c-simple-ws) "*"
2771 "friend"
2772 (c-lang-const c-simple-ws) "+")))
2773 (c-lang-defvar c-opt-friend-key (c-lang-const c-opt-friend-key))
2775 (c-lang-defconst c-opt-method-key
2776 ;; Special regexp to match the start of Objective-C methods. The
2777 ;; first submatch is assumed to end after the + or - key.
2778 t nil
2779 objc (concat
2780 ;; TODO: Ought to use a better method than anchoring on bol.
2781 "^\\s *"
2782 "\\([+-]\\)"
2783 (c-lang-const c-simple-ws) "*"
2784 (concat "\\(" ; Return type.
2785 "([^\)]*)"
2786 (c-lang-const c-simple-ws) "*"
2787 "\\)?")
2788 "\\(" (c-lang-const c-symbol-key) "\\)"))
2789 (c-lang-defvar c-opt-method-key (c-lang-const c-opt-method-key))
2791 (c-lang-defconst c-type-decl-end-used
2792 ;; Must be set in buffers where the `c-type' text property might be
2793 ;; used with the value `c-decl-end'.
2795 ;; `c-decl-end' is used to mark the ends of labels and access keys
2796 ;; to make interactive refontification work better.
2797 t (or (c-lang-const c-recognize-colon-labels)
2798 (and (c-lang-const c-label-kwds) t))
2799 ;; `c-decl-end' is used to mark the end of the @-style directives in
2800 ;; Objective-C.
2801 objc t)
2802 (c-lang-defvar c-type-decl-end-used (c-lang-const c-type-decl-end-used))
2805 ;;; Wrap up the `c-lang-defvar' system.
2807 ;; Compile in the list of language variables that has been collected
2808 ;; with the `c-lang-defvar' macro. Note that the first element is
2809 ;; nil.
2810 (defconst c-lang-variable-inits (cc-eval-when-compile c-lang-variable-inits))
2812 (defun c-make-init-lang-vars-fun (mode)
2813 "Create a function that initializes all the language dependent variables
2814 for the given mode.
2816 This function should be evaluated at compile time, so that the
2817 function it returns is byte compiled with all the evaluated results
2818 from the language constants. Use the `c-init-language-vars' macro to
2819 accomplish that conveniently."
2821 (if (and (not load-in-progress)
2822 (boundp 'byte-compile-dest-file)
2823 (stringp byte-compile-dest-file))
2825 ;; No need to byte compile this lambda since the byte compiler is
2826 ;; smart enough to detect the `funcall' construct in the
2827 ;; `c-init-language-vars' macro below and compile it all straight
2828 ;; into the function that contains `c-init-language-vars'.
2829 `(lambda ()
2831 ;; This let sets up the context for `c-mode-var' and similar
2832 ;; that could be in the result from `cl-macroexpand-all'.
2833 (let ((c-buffer-is-cc-mode ',mode)
2834 current-var source-eval)
2835 (condition-case err
2837 (if (eq c-version-sym ',c-version-sym)
2838 (setq ,@(let ((c-buffer-is-cc-mode mode)
2839 (c-lang-const-expansion 'immediate))
2840 ;; `c-lang-const' will expand to the evaluated
2841 ;; constant immediately in `cl-macroexpand-all'
2842 ;; below.
2843 (mapcan
2844 (lambda (init)
2845 `(current-var ',(car init)
2846 ,(car init) ,(cl-macroexpand-all
2847 (elt init 1))))
2848 (cdr c-lang-variable-inits))))
2850 ;; This diagnostic message isn't useful for end
2851 ;; users, so it's disabled.
2852 ;;(unless (get ',mode 'c-has-warned-lang-consts)
2853 ;; (message ,(concat "%s compiled with CC Mode %s "
2854 ;; "but loaded with %s - evaluating "
2855 ;; "language constants from source")
2856 ;; ',mode ,c-version c-version)
2857 ;; (put ',mode 'c-has-warned-lang-consts t))
2859 (require 'cc-langs)
2860 (setq source-eval t)
2861 (let ((init (cdr c-lang-variable-inits)))
2862 (while init
2863 (setq current-var (caar init))
2864 (set (caar init) (eval (cadar init)))
2865 (setq init (cdr init)))))
2867 (error
2868 (if current-var
2869 (message "Eval error in the `c-lang-defvar' for `%s'%s: %S"
2870 current-var
2871 (if source-eval
2872 (format "\
2873 (fallback source eval - %s compiled with CC Mode %s but loaded with %s)"
2874 ',mode ,c-version c-version)
2876 err)
2877 (signal (car err) (cdr err)))))))
2879 ;; Being evaluated from source. Always use the dynamic method to
2880 ;; work well when `c-lang-defvar's in this file are reevaluated
2881 ;; interactively.
2882 `(lambda ()
2883 (require 'cc-langs)
2884 (let ((c-buffer-is-cc-mode ',mode)
2885 (init (cdr c-lang-variable-inits))
2886 current-var)
2887 (condition-case err
2889 (while init
2890 (setq current-var (caar init))
2891 (set (caar init) (eval (cadar init)))
2892 (setq init (cdr init)))
2894 (error
2895 (if current-var
2896 (message
2897 "Eval error in the `c-lang-defvar' for `%s' (source eval): %S"
2898 current-var err)
2899 (signal (car err) (cdr err)))))))
2902 (defmacro c-init-language-vars (mode)
2903 "Initialize all the language dependent variables for the given mode.
2904 This macro is expanded at compile time to a form tailored for the mode
2905 in question, so MODE must be a constant. Therefore MODE is not
2906 evaluated and should not be quoted."
2907 `(funcall ,(c-make-init-lang-vars-fun mode)))
2910 (cc-provide 'cc-langs)
2912 ;;; arch-tag: 1ab57482-cfc2-4c5b-b628-3539c3098822
2913 ;;; cc-langs.el ends here