(Scan Line Formats): Replace @samp with @kbd.
[emacs.git] / lisp / progmodes / cc-langs.el
blobb02df16b4f5cb6d70c6b59452487149117b13b47
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 c-subword-mode])))
273 ;;; Syntax tables.
275 (defun c-populate-syntax-table (table)
276 "Populate the given syntax table as necessary for a C-like language.
277 This includes setting ' and \" as string delimiters, and setting up
278 the comment syntax to handle both line style \"//\" and block style
279 \"/*\" \"*/\" comments."
281 (modify-syntax-entry ?_ "_" table)
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 ?\240 "." table)
294 ;; Set up block and line oriented comments. The new C
295 ;; standard mandates both comment styles even in C, so since
296 ;; all languages now require dual comments, we make this the
297 ;; default.
298 (cond
299 ;; XEmacs
300 ((memq '8-bit c-emacs-features)
301 (modify-syntax-entry ?/ ". 1456" table)
302 (modify-syntax-entry ?* ". 23" table))
303 ;; Emacs
304 ((memq '1-bit c-emacs-features)
305 (modify-syntax-entry ?/ ". 124b" table)
306 (modify-syntax-entry ?* ". 23" table))
307 ;; incompatible
308 (t (error "CC Mode is incompatible with this version of Emacs")))
310 (modify-syntax-entry ?\n "> b" table)
311 ;; Give CR the same syntax as newline, for selective-display
312 (modify-syntax-entry ?\^m "> b" table))
314 (c-lang-defconst c-make-mode-syntax-table
315 "Functions that generates the mode specific syntax tables.
316 The syntax tables aren't stored directly since they're quite large."
317 t `(lambda ()
318 (let ((table (make-syntax-table)))
319 (c-populate-syntax-table table)
320 ;; Mode specific syntaxes.
321 ,(cond ((c-major-mode-is 'objc-mode)
322 ;; Let '@' be part of symbols in ObjC to cope with
323 ;; its compiler directives as single keyword tokens.
324 ;; This is then necessary since it's assumed that
325 ;; every keyword is a single symbol.
326 `(modify-syntax-entry ?@ "_" table))
327 ((c-major-mode-is 'pike-mode)
328 `(modify-syntax-entry ?@ "." table)))
329 table)))
331 (c-lang-defconst c-mode-syntax-table
332 ;; The syntax tables in evaluated form. Only used temporarily when
333 ;; the constants in this file are evaluated.
334 t (funcall (c-lang-const c-make-mode-syntax-table)))
336 (c-lang-defconst c++-make-template-syntax-table
337 ;; A variant of `c++-mode-syntax-table' that defines `<' and `>' as
338 ;; parenthesis characters. Used temporarily when template argument
339 ;; lists are parsed. Note that this encourages incorrect parsing of
340 ;; templates since they might contain normal operators that uses the
341 ;; '<' and '>' characters. Therefore this syntax table might go
342 ;; away when CC Mode handles templates correctly everywhere.
343 t nil
344 c++ `(lambda ()
345 (let ((table (funcall ,(c-lang-const c-make-mode-syntax-table))))
346 (modify-syntax-entry ?< "(>" table)
347 (modify-syntax-entry ?> ")<" table)
348 table)))
349 (c-lang-defvar c++-template-syntax-table
350 (and (c-lang-const c++-make-template-syntax-table)
351 (funcall (c-lang-const c++-make-template-syntax-table))))
353 (c-lang-defconst c-identifier-syntax-modifications
354 "A list that describes the modifications that should be done to the
355 mode syntax table to get a syntax table that matches all identifiers
356 and keywords as words.
358 The list is just like the one used in `font-lock-defaults': Each
359 element is a cons where the car is the character to modify and the cdr
360 the new syntax, as accepted by `modify-syntax-entry'."
361 ;; The $ character is not allowed in most languages (one exception
362 ;; is Java which allows it for legacy reasons) but we still classify
363 ;; it as an indentifier character since it's often used in various
364 ;; machine generated identifiers.
365 t '((?_ . "w") (?$ . "w"))
366 objc (append '((?@ . "w"))
367 (c-lang-const c-identifier-syntax-modifications))
368 awk '((?_ . "w")))
369 (c-lang-defvar c-identifier-syntax-modifications
370 (c-lang-const c-identifier-syntax-modifications))
372 (c-lang-defvar c-identifier-syntax-table
373 (let ((table (copy-syntax-table (c-mode-var "mode-syntax-table")))
374 (mods c-identifier-syntax-modifications)
375 mod)
376 (while mods
377 (setq mod (car mods)
378 mods (cdr mods))
379 (modify-syntax-entry (car mod) (cdr mod) table))
380 table)
381 "Syntax table built on the mode syntax table but additionally
382 classifies symbol constituents like '_' and '$' as word constituents,
383 so that all identifiers are recognized as words.")
386 ;;; Lexer-level syntax (identifiers, tokens etc).
388 (c-lang-defconst c-symbol-start
389 "Regexp that matches the start of a symbol, i.e. any identifier or
390 keyword. It's unspecified how far it matches. Does not contain a \\|
391 operator at the top level."
392 t (concat "[" c-alpha "_]")
393 objc (concat "[" c-alpha "@]")
394 pike (concat "[" c-alpha "_`]"))
395 (c-lang-defvar c-symbol-start (c-lang-const c-symbol-start))
397 (c-lang-defconst c-symbol-chars
398 "Set of characters that can be part of a symbol.
399 This is on the form that fits inside [ ] in a regexp."
400 ;; Pike note: With the backquote identifiers this would include most
401 ;; operator chars too, but they are handled with other means instead.
402 t (concat c-alnum "_$")
403 objc (concat c-alnum "_$@"))
405 (c-lang-defconst c-symbol-key
406 "Regexp matching identifiers and keywords (with submatch 0). Assumed
407 to match if `c-symbol-start' matches on the same position."
408 t (concat (c-lang-const c-symbol-start)
409 "[" (c-lang-const c-symbol-chars) "]*")
410 pike (concat
411 ;; Use the value from C here since the operator backquote is
412 ;; covered by the other alternative.
413 (c-lang-const c-symbol-key c)
414 "\\|"
415 (c-make-keywords-re nil
416 (c-lang-const c-overloadable-operators))))
417 (c-lang-defvar c-symbol-key (c-lang-const c-symbol-key))
419 (c-lang-defconst c-symbol-key-depth
420 ;; Number of regexp grouping parens in `c-symbol-key'.
421 t (regexp-opt-depth (c-lang-const c-symbol-key)))
423 (c-lang-defconst c-nonsymbol-chars
424 "This is the set of chars that can't be part of a symbol, i.e. the
425 negation of `c-symbol-chars'."
426 t (concat "^" (c-lang-const c-symbol-chars)))
427 (c-lang-defvar c-nonsymbol-chars (c-lang-const c-nonsymbol-chars))
429 (c-lang-defconst c-nonsymbol-key
430 "Regexp that matches any character that can't be part of a symbol.
431 It's usually appended to other regexps to avoid matching a prefix.
432 It's assumed to not contain any submatchers."
433 ;; The same thing regarding Unicode identifiers applies here as to
434 ;; `c-symbol-key'.
435 t (concat "[" (c-lang-const c-nonsymbol-chars) "]"))
437 (c-lang-defconst c-identifier-ops
438 "The operators that make up fully qualified identifiers. nil in
439 languages that don't have such things. See `c-operators' for a
440 description of the format. Binary operators can concatenate symbols,
441 e.g. \"::\" in \"A::B::C\". Prefix operators can precede identifiers,
442 e.g. \"~\" in \"~A::B\". Other types of operators aren't supported.
444 This value is by default merged into `c-operators'."
445 t nil
446 c++ '((prefix "~" "??-" "compl")
447 (right-assoc "::")
448 (prefix "::"))
449 ;; Java has "." to concatenate identifiers but it's also used for
450 ;; normal indexing. There's special code in the Java font lock
451 ;; rules to fontify qualified identifiers based on the standard
452 ;; naming conventions. We still define "." here to make
453 ;; `c-forward-name' move over as long names as possible which is
454 ;; necessary to e.g. handle throws clauses correctly.
455 java '((left-assoc "."))
456 idl '((left-assoc "::")
457 (prefix "::"))
458 pike '((left-assoc "::")
459 (prefix "::")
460 (left-assoc ".")))
462 (c-lang-defconst c-opt-identifier-concat-key
463 ;; Appendable adorned regexp matching the operators that join
464 ;; symbols to fully qualified identifiers, or nil in languages that
465 ;; don't have such things.
467 ;; This was a docstring constant in 5.30. It still works but is now
468 ;; considered internal - change `c-identifier-ops' instead.
469 t (let ((ops (c-filter-ops (c-lang-const c-identifier-ops)
470 '(left-assoc right-assoc)
471 t)))
472 (when ops
473 (c-make-keywords-re 'appendable ops))))
474 (c-lang-defvar c-opt-identifier-concat-key
475 (c-lang-const c-opt-identifier-concat-key)
476 'dont-doc)
478 (c-lang-defconst c-opt-identifier-concat-key-depth
479 ;; Number of regexp grouping parens in `c-opt-identifier-concat-key'.
480 t (regexp-opt-depth (c-lang-const c-opt-identifier-concat-key)))
482 (c-lang-defconst c-opt-identifier-prefix-key
483 ;; Appendable adorned regexp matching operators that might precede
484 ;; an identifier and that are part of the identifier in that case.
485 ;; nil in languages without such things.
486 t (let ((ops (c-filter-ops (c-lang-const c-identifier-ops)
487 '(prefix)
488 t)))
489 (when ops
490 (c-make-keywords-re 'appendable ops))))
492 (c-lang-defconst c-after-id-concat-ops
493 "Operators that can occur after a binary operator on `c-identifier-ops'
494 in identifiers. nil in languages that don't have such things.
496 Operators here should also have appropriate entries in `c-operators' -
497 it's not taken care of by default."
498 t nil
499 ;; '~' for destructors in C++, '*' for member pointers.
500 c++ '("~" "*")
501 ;; In Java we recognize '*' to deal with "foo.bar.*" that can occur
502 ;; in import declarations. (This will also match bogus things like
503 ;; "foo.*bar" but we don't bother.)
504 java '("*"))
506 (c-lang-defconst c-opt-after-id-concat-key
507 ;; Regexp that must match the token after
508 ;; `c-opt-identifier-concat-key' for it to be considered an
509 ;; identifier concatenation operator (which e.g. causes the
510 ;; preceding identifier to be fontified as a reference). Assumed to
511 ;; be a string if `c-opt-identifier-concat-key' is.
513 ;; This was a docstring constant in 5.30. It still works but is now
514 ;; considered internal - change `c-after-id-concat-ops' instead.
515 t (concat (c-lang-const c-symbol-start)
516 (if (c-lang-const c-after-id-concat-ops)
517 (concat "\\|" (c-make-keywords-re 'appendable
518 (c-lang-const c-after-id-concat-ops)))
519 "")))
521 (c-lang-defconst c-identifier-start
522 "Regexp that matches the start of an (optionally qualified) identifier.
523 It should also match all keywords. It's unspecified how far it
524 matches."
525 t (concat (c-lang-const c-symbol-start)
526 (if (c-lang-const c-opt-identifier-prefix-key)
527 (concat "\\|"
528 (c-lang-const c-opt-identifier-prefix-key))
529 "")))
530 (c-lang-defvar c-identifier-start (c-lang-const c-identifier-start))
532 (c-lang-defconst c-identifier-key
533 "Regexp matching a fully qualified identifier, like \"A::B::c\" in
534 C++. It does not recognize the full range of syntactic whitespace
535 between the tokens; `c-forward-name' has to be used for that. It
536 should also not match identifiers containing parenthesis groupings,
537 e.g. identifiers with template arguments such as \"A<X,Y>\" in C++."
538 ;; This regexp is more complex than strictly necessary to ensure
539 ;; that it can be matched with a minimum of backtracking.
540 t (concat (if (c-lang-const c-opt-identifier-prefix-key)
541 (concat
542 "\\("
543 (c-lang-const c-opt-identifier-prefix-key)
544 (c-lang-const c-simple-ws) "*"
545 "\\)?")
547 "\\(" (c-lang-const c-symbol-key) "\\)"
548 (if (c-lang-const c-opt-identifier-concat-key)
549 (concat
550 "\\("
551 (c-lang-const c-simple-ws) "*"
552 (c-lang-const c-opt-identifier-concat-key)
553 (c-lang-const c-simple-ws) "*"
554 (if (c-lang-const c-after-id-concat-ops)
555 (concat
556 "\\("
557 (c-make-keywords-re 'appendable
558 (c-lang-const c-after-id-concat-ops))
559 (concat
560 ;; For flexibility, consider the symbol match
561 ;; optional if we've hit a
562 ;; `c-after-id-concat-ops' operator. This is
563 ;; also necessary to handle the "*" that can
564 ;; end import declaration identifiers in Java.
565 "\\("
566 (c-lang-const c-simple-ws) "*"
567 "\\(" (c-lang-const c-symbol-key) "\\)"
568 "\\)?")
569 "\\|"
570 "\\(" (c-lang-const c-symbol-key) "\\)"
571 "\\)")
572 (concat "\\(" (c-lang-const c-symbol-key) "\\)"))
573 "\\)*")
574 "")))
575 (c-lang-defvar c-identifier-key (c-lang-const c-identifier-key))
577 (c-lang-defconst c-identifier-last-sym-match
578 ;; This was a docstring constant in 5.30 but it's no longer used.
579 ;; It's only kept to avoid breaking third party code.
581 ;; Used to identify the submatch in `c-identifier-key' that
582 ;; surrounds the last symbol in the qualified identifier. It's a
583 ;; list of submatch numbers, of which the first that has a match is
584 ;; taken. It's assumed that at least one does when the regexp has
585 ;; matched.
586 t nil)
588 (c-lang-defconst c-string-escaped-newlines
589 "Set if the language support backslash escaped newlines inside string
590 literals."
591 t nil
592 (c c++ objc pike) t)
593 (c-lang-defvar c-string-escaped-newlines
594 (c-lang-const c-string-escaped-newlines))
596 (c-lang-defconst c-multiline-string-start-char
597 "Set if the language supports multiline string literals without escaped
598 newlines. If t, all string literals are multiline. If a character,
599 only literals where the open quote is immediately preceded by that
600 literal are multiline."
601 t nil
602 pike ?#)
603 (c-lang-defvar c-multiline-string-start-char
604 (c-lang-const c-multiline-string-start-char))
606 (c-lang-defconst c-opt-cpp-prefix
607 "Regexp matching the prefix of a cpp directive in the languages that
608 normally use that macro preprocessor. Tested at bol or at boi.
609 Assumed to not contain any submatches or \\| operators."
610 ;; TODO (ACM, 2005-04-01). Amend the following to recognise escaped NLs;
611 ;; amend all uses of c-opt-cpp-prefix which count regexp-depth.
612 t "\\s *#\\s *"
613 (java awk) nil)
614 (c-lang-defvar c-opt-cpp-prefix (c-lang-const c-opt-cpp-prefix))
616 (c-lang-defconst c-opt-cpp-start
617 "Regexp matching the prefix of a cpp directive including the directive
618 name, or nil in languages without preprocessor support. The first
619 submatch surrounds the directive name."
620 t (if (c-lang-const c-opt-cpp-prefix)
621 (concat (c-lang-const c-opt-cpp-prefix)
622 "\\([" c-alnum "]+\\)"))
623 ;; Pike, being a scripting language, recognizes hash-bangs too.
624 pike (concat (c-lang-const c-opt-cpp-prefix)
625 "\\([" c-alnum "]+\\|!\\)"))
626 (c-lang-defvar c-opt-cpp-start (c-lang-const c-opt-cpp-start))
628 (c-lang-defconst c-cpp-message-directives
629 "List of cpp directives (without the prefix) that are followed by a
630 string message."
631 t (if (c-lang-const c-opt-cpp-prefix)
632 '("error"))
633 pike '("error" "warning"))
635 (c-lang-defconst c-cpp-include-directives
636 "List of cpp directives (without the prefix) that are followed by a
637 file name in angle brackets or quotes."
638 t (if (c-lang-const c-opt-cpp-prefix)
639 '("include"))
640 objc '("include" "import"))
642 (c-lang-defconst c-opt-cpp-macro-define
643 "Cpp directive (without the prefix) that is followed by a macro
644 definition, or nil if the language doesn't have any."
645 t (if (c-lang-const c-opt-cpp-prefix)
646 "define"))
648 (c-lang-defconst c-opt-cpp-macro-define-start
649 ;; Regexp matching everything up to the macro body of a cpp define,
650 ;; or the end of the logical line if there is none. Set if
651 ;; c-opt-cpp-macro-define is.
652 t (if (c-lang-const c-opt-cpp-macro-define)
653 (concat (c-lang-const c-opt-cpp-prefix)
654 (c-lang-const c-opt-cpp-macro-define)
655 "[ \t]+\\(\\sw\\|_\\)+\\(\([^\)]*\)\\)?"
656 "\\([ \t]\\|\\\\\n\\)*")))
657 (c-lang-defvar c-opt-cpp-macro-define-start
658 (c-lang-const c-opt-cpp-macro-define-start))
660 (c-lang-defconst c-cpp-expr-directives
661 "List if cpp directives (without the prefix) that are followed by an
662 expression."
663 t (if (c-lang-const c-opt-cpp-prefix)
664 '("if" "elif")))
666 (c-lang-defconst c-cpp-expr-functions
667 "List of functions in cpp expressions."
668 t (if (c-lang-const c-opt-cpp-prefix)
669 '("defined"))
670 pike '("defined" "efun" "constant"))
672 (c-lang-defconst c-assignment-operators
673 "List of all assignment operators."
674 t '("=" "*=" "/=" "%=" "+=" "-=" ">>=" "<<=" "&=" "^=" "|=")
675 java (append (c-lang-const c-assignment-operators)
676 '(">>>="))
677 c++ (append (c-lang-const c-assignment-operators)
678 '("and_eq" "or_eq" "xor_eq" "??!=" "??'="))
679 idl nil)
681 (c-lang-defconst c-operators
682 "List describing all operators, along with their precedence and
683 associativity. The order in the list corresponds to the precedence of
684 the operators: The operators in each element is a group with the same
685 precedence, and the group has higher precedence than the groups in all
686 following elements. The car of each element describes the type of of
687 the operator group, and the cdr is a list of the operator tokens in
688 it. The operator group types are:
690 'prefix Unary prefix operators.
691 'postfix Unary postfix operators.
692 'postfix-if-paren
693 Unary postfix operators if and only if the chars have
694 parenthesis syntax.
695 'left-assoc Binary left associative operators (i.e. a+b+c means (a+b)+c).
696 'right-assoc Binary right associative operators (i.e. a=b=c means a=(b=c)).
697 'right-assoc-sequence
698 Right associative operator that constitutes of a
699 sequence of tokens that separate expressions. All the
700 tokens in the group are in this case taken as
701 describing the sequence in one such operator, and the
702 order between them is therefore significant.
704 Operators containing a character with paren syntax are taken to match
705 with a corresponding open/close paren somewhere else. A postfix
706 operator with close paren syntax is taken to end a postfix expression
707 started somewhere earlier, rather than start a new one at point. Vice
708 versa for prefix operators with open paren syntax.
710 Note that operators like \".\" and \"->\" which in language references
711 often are described as postfix operators are considered binary here,
712 since CC Mode treats every identifier as an expression."
714 ;; There's currently no code in CC Mode that exploit all the info
715 ;; in this variable; precedence, associativity etc are present as a
716 ;; preparation for future work.
718 t `(;; Preprocessor.
719 ,@(when (c-lang-const c-opt-cpp-prefix)
720 `((prefix "#"
721 ,@(when (c-major-mode-is '(c-mode c++-mode))
722 '("%:" "??=")))
723 (left-assoc "##"
724 ,@(when (c-major-mode-is '(c-mode c++-mode))
725 '("%:%:" "??=??=")))))
727 ;; Primary.
728 ,@(c-lang-const c-identifier-ops)
729 ,@(cond ((c-major-mode-is 'c++-mode)
730 `((postfix-if-paren "<" ">"))) ; Templates.
731 ((c-major-mode-is 'pike-mode)
732 `((prefix "global" "predef")))
733 ((c-major-mode-is 'java-mode)
734 `((prefix "super"))))
736 ;; Postfix.
737 ,@(when (c-major-mode-is 'c++-mode)
738 ;; The following need special treatment.
739 `((prefix "dynamic_cast" "static_cast"
740 "reinterpret_cast" "const_cast" "typeid")))
741 (left-assoc "."
742 ,@(unless (c-major-mode-is 'java-mode)
743 '("->")))
744 (postfix "++" "--" "[" "]" "(" ")"
745 ,@(when (c-major-mode-is '(c-mode c++-mode))
746 '("<:" ":>" "??(" "??)")))
748 ;; Unary.
749 (prefix "++" "--" "+" "-" "!" "~"
750 ,@(when (c-major-mode-is 'c++-mode) '("not" "compl"))
751 ,@(when (c-major-mode-is '(c-mode c++-mode))
752 '("*" "&" "sizeof" "??-"))
753 ,@(when (c-major-mode-is 'objc-mode)
754 '("@selector" "@protocol" "@encode"))
755 ;; The following need special treatment.
756 ,@(cond ((c-major-mode-is 'c++-mode)
757 '("new" "delete"))
758 ((c-major-mode-is 'java-mode)
759 '("new"))
760 ((c-major-mode-is 'pike-mode)
761 '("class" "lambda" "catch" "throw" "gauge")))
762 "(" ")" ; Cast.
763 ,@(when (c-major-mode-is 'pike-mode)
764 '("[" "]"))) ; Type cast.
766 ;; Member selection.
767 ,@(when (c-major-mode-is 'c++-mode)
768 `((left-assoc ".*" "->*")))
770 ;; Multiplicative.
771 (left-assoc "*" "/" "%")
773 ;; Additive.
774 (left-assoc "+" "-")
776 ;; Shift.
777 (left-assoc "<<" ">>"
778 ,@(when (c-major-mode-is 'java-mode)
779 '(">>>")))
781 ;; Relational.
782 (left-assoc "<" ">" "<=" ">="
783 ,@(when (c-major-mode-is 'java-mode)
784 '("instanceof")))
786 ;; Equality.
787 (left-assoc "==" "!="
788 ,@(when (c-major-mode-is 'c++-mode) '("not_eq")))
790 ;; Bitwise and.
791 (left-assoc "&"
792 ,@(when (c-major-mode-is 'c++-mode) '("bitand")))
794 ;; Bitwise exclusive or.
795 (left-assoc "^"
796 ,@(when (c-major-mode-is '(c-mode c++-mode))
797 '("??'"))
798 ,@(when (c-major-mode-is 'c++-mode) '("xor")))
800 ;; Bitwise or.
801 (left-assoc "|"
802 ,@(when (c-major-mode-is '(c-mode c++-mode))
803 '("??!"))
804 ,@(when (c-major-mode-is 'c++-mode) '("bitor")))
806 ;; Logical and.
807 (left-assoc "&&"
808 ,@(when (c-major-mode-is 'c++-mode) '("and")))
810 ;; Logical or.
811 (left-assoc "||"
812 ,@(when (c-major-mode-is '(c-mode c++-mode))
813 '("??!??!"))
814 ,@(when (c-major-mode-is 'c++-mode) '("or")))
816 ;; Conditional.
817 (right-assoc-sequence "?" ":")
819 ;; Assignment.
820 (right-assoc ,@(c-lang-const c-assignment-operators))
822 ;; Exception.
823 ,@(when (c-major-mode-is 'c++-mode)
824 '((prefix "throw")))
826 ;; Sequence.
827 (left-assoc ","))
829 ;; IDL got its own definition since it has a much smaller operator
830 ;; set than the other languages.
831 idl `(;; Preprocessor.
832 (prefix "#")
833 (left-assoc "##")
834 ;; Primary.
835 ,@(c-lang-const c-identifier-ops)
836 ;; Unary.
837 (prefix "+" "-" "~")
838 ;; Multiplicative.
839 (left-assoc "*" "/" "%")
840 ;; Additive.
841 (left-assoc "+" "-")
842 ;; Shift.
843 (left-assoc "<<" ">>")
844 ;; And.
845 (left-assoc "&")
846 ;; Xor.
847 (left-assoc "^")
848 ;; Or.
849 (left-assoc "|")))
851 (c-lang-defconst c-operator-list
852 ;; The operators as a flat list (without duplicates).
853 t (c-filter-ops (c-lang-const c-operators) t t))
855 (c-lang-defconst c-overloadable-operators
856 "List of the operators that are overloadable, in their \"identifier
857 form\". See also `c-op-identitier-prefix'."
858 t nil
859 c++ '("new" "delete" ;; Can be followed by "[]" but we ignore that.
860 "+" "-" "*" "/" "%"
861 "^" "??'" "xor" "&" "bitand" "|" "??!" "bitor" "~" "??-" "compl"
862 "!" "=" "<" ">" "+=" "-=" "*=" "/=" "%=" "^="
863 "??'=" "xor_eq" "&=" "and_eq" "|=" "??!=" "or_eq"
864 "<<" ">>" ">>=" "<<=" "==" "!=" "not_eq" "<=" ">="
865 "&&" "and" "||" "??!??!" "or" "++" "--" "," "->*" "->"
866 "()" "[]" "<::>" "??(??)")
867 ;; These work like identifiers in Pike.
868 pike '("`+" "`-" "`&" "`|" "`^" "`<<" "`>>" "`*" "`/" "`%" "`~"
869 "`==" "`<" "`>" "`!" "`[]" "`[]=" "`->" "`->=" "`()" "``+"
870 "``-" "``&" "``|" "``^" "``<<" "``>>" "``*" "``/" "``%"
871 "`+="))
873 (c-lang-defconst c-overloadable-operators-regexp
874 ;; Regexp tested after an "operator" token in C++.
875 t nil
876 c++ (c-make-keywords-re nil (c-lang-const c-overloadable-operators)))
877 (c-lang-defvar c-overloadable-operators-regexp
878 (c-lang-const c-overloadable-operators-regexp))
880 (c-lang-defconst c-opt-op-identitier-prefix
881 "Regexp matching the token before the ones in
882 `c-overloadable-operators' when operators are specified in their
883 \"identifier form\". This typically matches \"operator\" in C++ where
884 operator functions are specified as e.g. \"operator +\". It's nil in
885 languages without operator functions or where the complete operator
886 identifier is listed in `c-overloadable-operators'.
888 This regexp is assumed to not match any non-operator identifier."
889 t nil
890 c++ (c-make-keywords-re t '("operator")))
891 (c-lang-defvar c-opt-op-identitier-prefix
892 (c-lang-const c-opt-op-identitier-prefix))
894 (c-lang-defconst c-other-op-syntax-tokens
895 "List of the tokens made up of characters in the punctuation or
896 parenthesis syntax classes that have uses other than as expression
897 operators."
898 t '("{" "}" "(" ")" "[" "]" ";" ":" "," "=" "/*" "*/" "//")
899 (c c++ pike) (append '("#" "##" ; Used by cpp.
900 "::" "...")
901 (c-lang-const c-other-op-syntax-tokens))
902 (c c++) (append '("*") (c-lang-const c-other-op-syntax-tokens))
903 c++ (append '("&" "<%" "%>" "<:" ":>" "%:" "%:%:")
904 (c-lang-const c-other-op-syntax-tokens))
905 objc (append '("#" "##" ; Used by cpp.
906 "+" "-") (c-lang-const c-other-op-syntax-tokens))
907 idl (append '("#" "##") ; Used by cpp.
908 (c-lang-const c-other-op-syntax-tokens))
909 pike (append '("..")
910 (c-lang-const c-other-op-syntax-tokens)
911 (c-lang-const c-overloadable-operators))
912 awk '("{" "}" "(" ")" "[" "]" ";" "," "=" "/"))
914 (c-lang-defconst c-all-op-syntax-tokens
915 ;; List of all tokens in the punctuation and parenthesis syntax
916 ;; classes.
917 t (delete-duplicates (append (c-lang-const c-other-op-syntax-tokens)
918 (c-lang-const c-operator-list))
919 :test 'string-equal))
921 (c-lang-defconst c-nonsymbol-token-char-list
922 ;; List containing all chars not in the word, symbol or
923 ;; syntactically irrelevant syntax classes, i.e. all punctuation,
924 ;; parenthesis and string delimiter chars.
925 t (c-with-syntax-table (c-lang-const c-mode-syntax-table)
926 ;; Only go through the chars in the printable ASCII range. No
927 ;; language so far has 8-bit or widestring operators.
928 (let (list (char 32))
929 (while (< char 127)
930 (or (memq (char-syntax char) '(?w ?_ ?< ?> ?\ ))
931 (setq list (cons (c-int-to-char char) list)))
932 (setq char (1+ char)))
933 list)))
935 (c-lang-defconst c-nonsymbol-token-regexp
936 ;; Regexp matching all tokens in the punctuation and parenthesis
937 ;; syntax classes. Note that this also matches ".", which can start
938 ;; a float.
939 t (c-make-keywords-re nil
940 (c-filter-ops (c-lang-const c-all-op-syntax-tokens)
942 "\\`\\(\\s.\\|\\s\(\\|\\s\)\\)+\\'")))
943 (c-lang-defvar c-nonsymbol-token-regexp
944 (c-lang-const c-nonsymbol-token-regexp))
946 (c-lang-defconst c-assignment-op-regexp
947 ;; Regexp matching all assignment operators and only them. The
948 ;; beginning of the first submatch is used to detect the end of the
949 ;; token, along with the end of the whole match.
950 t (if (c-lang-const c-assignment-operators)
951 (concat
952 ;; Need special case for "=" since it's a prefix of "==".
953 "=\\([^=]\\|$\\)"
954 "\\|"
955 (c-make-keywords-re nil
956 (set-difference (c-lang-const c-assignment-operators)
957 '("=")
958 :test 'string-equal)))
959 "\\<\\>"))
960 (c-lang-defvar c-assignment-op-regexp
961 (c-lang-const c-assignment-op-regexp))
963 (c-lang-defconst c-<>-multichar-token-regexp
964 ;; Regexp matching all tokens containing "<" or ">" which are longer
965 ;; than one char.
966 t (c-make-keywords-re nil
967 (c-filter-ops (c-lang-const c-all-op-syntax-tokens)
969 ".[<>]\\|[<>].")))
970 (c-lang-defvar c-<>-multichar-token-regexp
971 (c-lang-const c-<>-multichar-token-regexp))
973 (c-lang-defconst c-<-op-cont-regexp
974 ;; Regexp matching the second and subsequent characters of all
975 ;; multicharacter tokens that begin with "<".
976 t (c-make-keywords-re nil
977 (c-filter-ops (c-lang-const c-all-op-syntax-tokens)
979 "\\`<."
980 (lambda (op) (substring op 1)))))
981 (c-lang-defvar c-<-op-cont-regexp (c-lang-const c-<-op-cont-regexp))
983 (c-lang-defconst c->-op-cont-regexp
984 ;; Regexp matching the second and subsequent characters of all
985 ;; multicharacter tokens that begin with ">".
986 t (c-make-keywords-re nil
987 (c-filter-ops (c-lang-const c-all-op-syntax-tokens)
989 "\\`>."
990 (lambda (op) (substring op 1)))))
991 (c-lang-defvar c->-op-cont-regexp (c-lang-const c->-op-cont-regexp))
993 (c-lang-defconst c-stmt-delim-chars
994 ;; The characters that should be considered to bound statements. To
995 ;; optimize `c-crosses-statement-barrier-p' somewhat, it's assumed to
996 ;; begin with "^" to negate the set. If ? : operators should be
997 ;; detected then the string must end with "?:".
998 t "^;{}?:"
999 awk "^;{}#\n\r?:") ; The newline chars gets special treatment.
1000 (c-lang-defvar c-stmt-delim-chars (c-lang-const c-stmt-delim-chars))
1002 (c-lang-defconst c-stmt-delim-chars-with-comma
1003 ;; Variant of `c-stmt-delim-chars' that additionally contains ','.
1004 t "^;,{}?:"
1005 awk "^;,{}\n\r?:") ; The newline chars gets special treatment.
1006 (c-lang-defvar c-stmt-delim-chars-with-comma
1007 (c-lang-const c-stmt-delim-chars-with-comma))
1010 ;;; Syntactic whitespace.
1012 (c-lang-defconst c-simple-ws
1013 "Regexp matching an ordinary whitespace character.
1014 Does not contain a \\| operator at the top level."
1015 ;; "\\s " is not enough since it doesn't match line breaks.
1016 t "\\(\\s \\|[\n\r]\\)")
1018 (c-lang-defconst c-simple-ws-depth
1019 ;; Number of regexp grouping parens in `c-simple-ws'.
1020 t (regexp-opt-depth (c-lang-const c-simple-ws)))
1022 (c-lang-defconst c-line-comment-starter
1023 "String that starts line comments, or nil if such don't exist.
1024 Line comments are always terminated by newlines. At least one of
1025 `c-block-comment-starter' and this one is assumed to be set.
1027 Note that it's currently not enough to set this to support a new
1028 comment style. Other stuff like the syntax table must also be set up
1029 properly."
1030 t "//"
1031 awk "#")
1032 (c-lang-defvar c-line-comment-starter (c-lang-const c-line-comment-starter))
1034 (c-lang-defconst c-block-comment-starter
1035 "String that starts block comments, or nil if such don't exist.
1036 Block comments are ended by `c-block-comment-ender', which is assumed
1037 to be set if this is. At least one of `c-line-comment-starter' and
1038 this one is assumed to be set.
1040 Note that it's currently not enough to set this to support a new
1041 comment style. Other stuff like the syntax table must also be set up
1042 properly."
1043 t "/*"
1044 awk nil)
1046 (c-lang-defconst c-block-comment-ender
1047 "String that ends block comments, or nil if such don't exist.
1049 Note that it's currently not enough to set this to support a new
1050 comment style. Other stuff like the syntax table must also be set up
1051 properly."
1052 t "*/"
1053 awk nil)
1055 (c-lang-defconst c-comment-start-regexp
1056 ;; Regexp to match the start of any type of comment.
1057 t (let ((re (c-make-keywords-re nil
1058 (list (c-lang-const c-line-comment-starter)
1059 (c-lang-const c-block-comment-starter)))))
1060 (if (memq 'gen-comment-delim c-emacs-features)
1061 (concat re "\\|\\s!")
1062 re)))
1063 (c-lang-defvar c-comment-start-regexp (c-lang-const c-comment-start-regexp))
1065 ;;;; Added by ACM, 2003/9/18.
1066 (c-lang-defconst c-block-comment-start-regexp
1067 ;; Regexp which matches the start of a block comment (if such exists in the
1068 ;; language)
1069 t (if (c-lang-const c-block-comment-starter)
1070 (regexp-quote (c-lang-const c-block-comment-starter))
1071 "\\<\\>"))
1072 (c-lang-defvar c-block-comment-start-regexp
1073 (c-lang-const c-block-comment-start-regexp))
1075 (c-lang-defconst c-literal-start-regexp
1076 ;; Regexp to match the start of comments and string literals.
1077 t (concat (c-lang-const c-comment-start-regexp)
1078 "\\|"
1079 (if (memq 'gen-string-delim c-emacs-features)
1080 "\"|"
1081 "\"")))
1082 (c-lang-defvar c-literal-start-regexp (c-lang-const c-literal-start-regexp))
1084 (c-lang-defconst c-doc-comment-start-regexp
1085 "Regexp to match the start of documentation comments."
1086 t "\\<\\>"
1087 ;; From font-lock.el: `doxygen' uses /*! while others use /**.
1088 (c c++ objc) "/\\*[*!]"
1089 java "/\\*\\*"
1090 pike "/[/*]!")
1091 (c-lang-defvar c-doc-comment-start-regexp
1092 (c-lang-const c-doc-comment-start-regexp))
1094 (c-lang-defconst comment-start
1095 "String that starts comments inserted with M-; etc.
1096 `comment-start' is initialized from this."
1097 ;; Default: Prefer line comments to block comments, and pad with a space.
1098 t (concat (or (c-lang-const c-line-comment-starter)
1099 (c-lang-const c-block-comment-starter))
1100 " ")
1101 ;; In C we still default to the block comment style since line
1102 ;; comments aren't entirely portable.
1103 c "/* ")
1104 (c-lang-defvar comment-start (c-lang-const comment-start)
1105 'dont-doc)
1107 (c-lang-defconst comment-end
1108 "String that ends comments inserted with M-; etc.
1109 `comment-end' is initialized from this."
1110 ;; Default: Use block comment style if comment-start uses block
1111 ;; comments, and pad with a space in that case.
1112 t (if (string-match (concat "\\`\\("
1113 (c-lang-const c-block-comment-start-regexp)
1114 "\\)")
1115 (c-lang-const comment-start))
1116 (concat " " (c-lang-const c-block-comment-ender))
1117 ""))
1118 (c-lang-defvar comment-end (c-lang-const comment-end)
1119 'dont-doc)
1121 (c-lang-defconst comment-start-skip
1122 "Regexp to match the start of a comment plus everything up to its body.
1123 `comment-start-skip' is initialized from this."
1124 ;; Default: Allow the last char of the comment starter(s) to be
1125 ;; repeated, then allow any amount of horizontal whitespace.
1126 t (concat "\\("
1127 (c-concat-separated
1128 (mapcar (lambda (cs)
1129 (when cs
1130 (concat (regexp-quote cs) "+")))
1131 (list (c-lang-const c-line-comment-starter)
1132 (c-lang-const c-block-comment-starter)))
1133 "\\|")
1134 "\\)\\s *"))
1135 (c-lang-defvar comment-start-skip (c-lang-const comment-start-skip)
1136 'dont-doc)
1138 (c-lang-defconst c-syntactic-ws-start
1139 ;; Regexp matching any sequence that can start syntactic whitespace.
1140 ;; The only uncertain case is '#' when there are cpp directives.
1141 t (concat "\\s \\|"
1142 (c-make-keywords-re nil
1143 (append (list (c-lang-const c-line-comment-starter)
1144 (c-lang-const c-block-comment-starter)
1145 (when (c-lang-const c-opt-cpp-prefix)
1146 "#"))
1147 '("\n" "\r")))
1148 "\\|\\\\[\n\r]"
1149 (when (memq 'gen-comment-delim c-emacs-features)
1150 "\\|\\s!")))
1151 (c-lang-defvar c-syntactic-ws-start (c-lang-const c-syntactic-ws-start))
1153 (c-lang-defconst c-syntactic-ws-end
1154 ;; Regexp matching any single character that might end syntactic whitespace.
1155 t (concat "\\s \\|"
1156 (c-make-keywords-re nil
1157 (append (when (c-lang-const c-block-comment-ender)
1158 (list
1159 (string
1160 (elt (c-lang-const c-block-comment-ender)
1161 (1- (length
1162 (c-lang-const c-block-comment-ender)))))))
1163 '("\n" "\r")))
1164 (when (memq 'gen-comment-delim c-emacs-features)
1165 "\\|\\s!")))
1166 (c-lang-defvar c-syntactic-ws-end (c-lang-const c-syntactic-ws-end))
1168 (c-lang-defconst c-unterminated-block-comment-regexp
1169 ;; Regexp matching an unterminated block comment that doesn't
1170 ;; contain line breaks, or nil in languages without block comments.
1171 ;; Does not contain a \| operator at the top level.
1172 t (when (c-lang-const c-block-comment-starter)
1173 (concat
1174 (regexp-quote (c-lang-const c-block-comment-starter))
1175 ;; It's messy to cook together a regexp that matches anything
1176 ;; but c-block-comment-ender.
1177 (let ((end (c-lang-const c-block-comment-ender)))
1178 (cond ((= (length end) 1)
1179 (concat "[^" end "\n\r]*"))
1180 ((= (length end) 2)
1181 (concat "[^" (substring end 0 1) "\n\r]*"
1182 "\\("
1183 (regexp-quote (substring end 0 1)) "+"
1184 "[^"
1185 ;; The quoting rules inside char classes are silly. :P
1186 (cond ((= (elt end 0) (elt end 1))
1187 (concat (substring end 0 1) "\n\r"))
1188 ((= (elt end 1) ?\])
1189 (concat (substring end 1 2) "\n\r"
1190 (substring end 0 1)))
1192 (concat (substring end 0 1) "\n\r"
1193 (substring end 1 2))))
1195 "[^" (substring end 0 1) "\n\r]*"
1196 "\\)*"))
1198 (error "Can't handle a block comment ender of length %s"
1199 (length end))))))))
1201 (c-lang-defconst c-block-comment-regexp
1202 ;; Regexp matching a block comment that doesn't contain line breaks,
1203 ;; or nil in languages without block comments. The reason we don't
1204 ;; allow line breaks is to avoid going very far and risk running out
1205 ;; of regexp stack; this regexp is intended to handle only short
1206 ;; comments that might be put in the middle of limited constructs
1207 ;; like declarations. Does not contain a \| operator at the top
1208 ;; level.
1209 t (when (c-lang-const c-unterminated-block-comment-regexp)
1210 (concat
1211 (c-lang-const c-unterminated-block-comment-regexp)
1212 (let ((end (c-lang-const c-block-comment-ender)))
1213 (cond ((= (length end) 1)
1214 (regexp-quote end))
1215 ((= (length end) 2)
1216 (concat (regexp-quote (substring end 0 1)) "+"
1217 (regexp-quote (substring end 1 2))))
1219 (error "Can't handle a block comment ender of length %s"
1220 (length end))))))))
1222 (c-lang-defconst c-nonwhite-syntactic-ws
1223 ;; Regexp matching a piece of syntactic whitespace that isn't a
1224 ;; sequence of simple whitespace characters. As opposed to
1225 ;; `c-(forward|backward)-syntactic-ws', this doesn't regard cpp
1226 ;; directives as syntactic whitespace.
1227 t (c-concat-separated
1228 (list (when (c-lang-const c-line-comment-starter)
1229 (concat (regexp-quote (c-lang-const c-line-comment-starter))
1230 "[^\n\r]*[\n\r]"))
1231 (c-lang-const c-block-comment-regexp)
1232 "\\\\[\n\r]"
1233 (when (memq 'gen-comment-delim c-emacs-features)
1234 "\\s!\\S!*\\s!"))
1235 "\\|"))
1237 (c-lang-defconst c-syntactic-ws
1238 ;; Regexp matching syntactic whitespace, including possibly the
1239 ;; empty string. As opposed to `c-(forward|backward)-syntactic-ws',
1240 ;; this doesn't regard cpp directives as syntactic whitespace. Does
1241 ;; not contain a \| operator at the top level.
1242 t (concat (c-lang-const c-simple-ws) "*"
1243 "\\("
1244 (concat "\\(" (c-lang-const c-nonwhite-syntactic-ws) "\\)"
1245 (c-lang-const c-simple-ws) "*")
1246 "\\)*"))
1248 (c-lang-defconst c-syntactic-ws-depth
1249 ;; Number of regexp grouping parens in `c-syntactic-ws'.
1250 t (regexp-opt-depth (c-lang-const c-syntactic-ws)))
1252 (c-lang-defconst c-nonempty-syntactic-ws
1253 ;; Regexp matching syntactic whitespace, which is at least one
1254 ;; character long. As opposed to `c-(forward|backward)-syntactic-ws',
1255 ;; this doesn't regard cpp directives as syntactic whitespace. Does
1256 ;; not contain a \| operator at the top level.
1257 t (concat "\\("
1258 (c-lang-const c-simple-ws)
1259 "\\|"
1260 (c-lang-const c-nonwhite-syntactic-ws)
1261 "\\)+"))
1263 (c-lang-defconst c-nonempty-syntactic-ws-depth
1264 ;; Number of regexp grouping parens in `c-nonempty-syntactic-ws'.
1265 t (regexp-opt-depth (c-lang-const c-nonempty-syntactic-ws)))
1267 (c-lang-defconst c-single-line-syntactic-ws
1268 ;; Regexp matching syntactic whitespace without any line breaks. As
1269 ;; opposed to `c-(forward|backward)-syntactic-ws', this doesn't
1270 ;; regard cpp directives as syntactic whitespace. Does not contain
1271 ;; a \| operator at the top level.
1272 t (if (c-lang-const c-block-comment-regexp)
1273 (concat "\\s *\\("
1274 (c-lang-const c-block-comment-regexp)
1275 "\\s *\\)*")
1276 "\\s *"))
1278 (c-lang-defconst c-single-line-syntactic-ws-depth
1279 ;; Number of regexp grouping parens in `c-single-line-syntactic-ws'.
1280 t (regexp-opt-depth (c-lang-const c-single-line-syntactic-ws)))
1282 (c-lang-defconst c-syntactic-eol
1283 ;; Regexp that matches when there is no syntactically significant
1284 ;; text before eol. Macros are regarded as syntactically
1285 ;; significant text here.
1286 t (concat (c-lang-const c-single-line-syntactic-ws)
1287 ;; Match eol (possibly inside a block comment or preceded
1288 ;; by a line continuation backslash), or the beginning of a
1289 ;; line comment. Note: This has to be modified for awk
1290 ;; where line comments start with '#'.
1291 "\\("
1292 (c-concat-separated
1293 (list (when (c-lang-const c-line-comment-starter)
1294 (regexp-quote (c-lang-const c-line-comment-starter)))
1295 (when (c-lang-const c-unterminated-block-comment-regexp)
1296 (concat (c-lang-const c-unterminated-block-comment-regexp)
1297 "$"))
1298 "\\\\$"
1299 "$")
1300 "\\|")
1301 "\\)"))
1302 (c-lang-defvar c-syntactic-eol (c-lang-const c-syntactic-eol))
1305 ;;; Syntactic analysis ("virtual semicolons") for line-oriented languages (AWK).
1306 (c-lang-defconst c-at-vsemi-p-fn
1307 "Contains a function \"Is there a virtual semicolon at POS or point?\".
1308 Such a function takes one optional parameter, a buffer position (defaults to
1309 point), and returns NIL or t. This variable contains NIL for languages which
1310 don't have EOL terminated statements. "
1311 t nil
1312 awk 'c-awk-at-vsemi-p)
1313 (c-lang-defvar c-at-vsemi-p-fn (c-lang-const c-at-vsemi-p-fn))
1315 (c-lang-defconst c-vsemi-status-unknown-p-fn
1316 "Contains a function \"are we unsure whether there is a virtual semicolon on this line?\".
1317 The (admittedly kludgey) purpose of such a function is to prevent an infinite
1318 recursion in c-beginning-of-statement-1 when point starts at a `while' token.
1319 The function MUST NOT UNDER ANY CIRCUMSTANCES call c-beginning-of-statement-1,
1320 even indirectly. This variable contains NIL for languages which don't have
1321 EOL terminated statements."
1322 t nil
1323 awk 'c-awk-vsemi-status-unknown-p)
1324 (c-lang-defvar c-vsemi-status-unknown-p-fn
1325 (c-lang-const c-vsemi-status-unknown-p-fn))
1328 ;;; In-comment text handling.
1330 (c-lang-defconst c-paragraph-start
1331 "Regexp to append to `paragraph-start'."
1332 t "$"
1333 java "\\(@[a-zA-Z]+\\>\\|$\\)" ; For Javadoc.
1334 pike "\\(@[a-zA-Z_-]+\\>\\([^{]\\|$\\)\\|$\\)") ; For Pike refdoc.
1335 (c-lang-defvar c-paragraph-start (c-lang-const c-paragraph-start))
1337 (c-lang-defconst c-paragraph-separate
1338 "Regexp to append to `paragraph-separate'."
1339 t "$"
1340 pike (c-lang-const c-paragraph-start))
1341 (c-lang-defvar c-paragraph-separate (c-lang-const c-paragraph-separate))
1344 ;;; Keyword lists.
1346 ;; Note: All and only all language constants containing keyword lists
1347 ;; should end with "-kwds"; they're automatically collected into the
1348 ;; `c-kwds-lang-consts' list below and used to build `c-keywords' etc.
1350 (c-lang-defconst c-primitive-type-kwds
1351 "Primitive type keywords. As opposed to the other keyword lists, the
1352 keywords listed here are fontified with the type face instead of the
1353 keyword face.
1355 If any of these also are on `c-type-list-kwds', `c-ref-list-kwds',
1356 `c-colon-type-list-kwds', `c-paren-nontype-kwds', `c-paren-type-kwds',
1357 `c-<>-type-kwds', or `c-<>-arglist-kwds' then the associated clauses
1358 will be handled.
1360 Do not try to modify this list for end user customizations; the
1361 `*-font-lock-extra-types' variable, where `*' is the mode prefix, is
1362 the appropriate place for that."
1363 t '("char" "double" "float" "int" "long" "short" "signed"
1364 "unsigned" "void")
1365 c (append
1366 '("_Bool" "_Complex" "_Imaginary") ; Conditionally defined in C99.
1367 (c-lang-const c-primitive-type-kwds))
1368 c++ (append
1369 '("bool" "wchar_t")
1370 (c-lang-const c-primitive-type-kwds))
1371 ;; Objective-C extends C, but probably not the new stuff in C99.
1372 objc (append
1373 '("id" "Class" "SEL" "IMP" "BOOL")
1374 (c-lang-const c-primitive-type-kwds))
1375 java '("boolean" "byte" "char" "double" "float" "int" "long" "short" "void")
1376 idl '("Object" "ValueBase" "any" "boolean" "char" "double" "fixed" "float"
1377 "long" "octet" "sequence" "short" "string" "void" "wchar" "wstring"
1378 ;; In CORBA PSDL:
1379 "ref"
1380 ;; The following can't really end a type, but we have to specify them
1381 ;; here due to the assumption in `c-primitive-type-prefix-kwds'. It
1382 ;; doesn't matter that much.
1383 "unsigned" "strong")
1384 pike '(;; this_program isn't really a keyword, but it's practically
1385 ;; used as a builtin type.
1386 "array" "float" "function" "int" "mapping" "mixed" "multiset"
1387 "object" "program" "string" "this_program" "void"))
1389 (c-lang-defconst c-primitive-type-key
1390 ;; An adorned regexp that matches `c-primitive-type-kwds'.
1391 t (c-make-keywords-re t (c-lang-const c-primitive-type-kwds)))
1392 (c-lang-defvar c-primitive-type-key (c-lang-const c-primitive-type-key))
1394 (c-lang-defconst c-primitive-type-prefix-kwds
1395 "Keywords that might act as prefixes for primitive types. Assumed to
1396 be a subset of `c-primitive-type-kwds'."
1397 t nil
1398 (c c++) '("long" "short" "signed" "unsigned")
1399 idl '("long" "unsigned"
1400 ;; In CORBA PSDL:
1401 "strong"))
1403 (c-lang-defconst c-type-prefix-kwds
1404 "Keywords where the following name - if any - is a type name, and
1405 where the keyword together with the symbol works as a type in
1406 declarations.
1408 Note that an alternative if the second part doesn't hold is
1409 `c-type-list-kwds'. Keywords on this list are typically also present
1410 on one of the `*-decl-kwds' lists."
1411 t nil
1412 c '("struct" "union" "enum")
1413 c++ (append '("class" "typename")
1414 (c-lang-const c-type-prefix-kwds c)))
1416 (c-lang-defconst c-type-prefix-key
1417 ;; Adorned regexp matching `c-type-prefix-kwds'.
1418 t (c-make-keywords-re t (c-lang-const c-type-prefix-kwds)))
1419 (c-lang-defvar c-type-prefix-key (c-lang-const c-type-prefix-key))
1421 (c-lang-defconst c-type-modifier-kwds
1422 "Type modifier keywords. These can occur almost anywhere in types
1423 but they don't build a type of themselves. Unlike the keywords on
1424 `c-primitive-type-kwds', they are fontified with the keyword face and
1425 not the type face."
1426 t nil
1427 c '("const" "restrict" "volatile")
1428 c++ '("const" "volatile" "throw")
1429 objc '("const" "volatile"))
1431 (c-lang-defconst c-opt-type-modifier-key
1432 ;; Adorned regexp matching `c-type-modifier-kwds', or nil in
1433 ;; languages without such keywords.
1434 t (and (c-lang-const c-type-modifier-kwds)
1435 (c-make-keywords-re t (c-lang-const c-type-modifier-kwds))))
1436 (c-lang-defvar c-opt-type-modifier-key (c-lang-const c-opt-type-modifier-key))
1438 (c-lang-defconst c-opt-type-component-key
1439 ;; An adorned regexp that matches `c-primitive-type-prefix-kwds' and
1440 ;; `c-type-modifier-kwds', or nil in languages without any of them.
1441 t (and (or (c-lang-const c-primitive-type-prefix-kwds)
1442 (c-lang-const c-type-modifier-kwds))
1443 (c-make-keywords-re t
1444 (append (c-lang-const c-primitive-type-prefix-kwds)
1445 (c-lang-const c-type-modifier-kwds)))))
1446 (c-lang-defvar c-opt-type-component-key
1447 (c-lang-const c-opt-type-component-key))
1449 (c-lang-defconst c-type-start-kwds
1450 ;; All keywords that can start a type (i.e. are either a type prefix
1451 ;; or a complete type).
1452 t (delete-duplicates (append (c-lang-const c-primitive-type-kwds)
1453 (c-lang-const c-type-prefix-kwds)
1454 (c-lang-const c-type-modifier-kwds))
1455 :test 'string-equal))
1457 (c-lang-defconst c-class-decl-kwds
1458 "Keywords introducing declarations where the following block (if any)
1459 contains another declaration level that should be considered a class.
1461 If any of these also are on `c-type-list-kwds', `c-ref-list-kwds',
1462 `c-colon-type-list-kwds', `c-paren-nontype-kwds', `c-paren-type-kwds',
1463 `c-<>-type-kwds', or `c-<>-arglist-kwds' then the associated clauses
1464 will be handled.
1466 Note that presence on this list does not automatically treat the
1467 following identifier as a type; the keyword must also be present on
1468 `c-type-prefix-kwds' or `c-type-list-kwds' to accomplish that."
1469 t nil
1470 c '("struct" "union")
1471 c++ '("class" "struct" "union")
1472 objc '("struct" "union"
1473 "@interface" "@implementation" "@protocol")
1474 java '("class" "interface")
1475 idl '("component" "eventtype" "exception" "home" "interface" "struct"
1476 "union" "valuetype"
1477 ;; In CORBA PSDL:
1478 "storagehome" "storagetype"
1479 ;; In CORBA CIDL:
1480 "catalog" "executor" "manages" "segment")
1481 pike '("class"))
1483 (c-lang-defconst c-class-key
1484 ;; Regexp matching the start of a class.
1485 t (c-make-keywords-re t (c-lang-const c-class-decl-kwds)))
1486 (c-lang-defvar c-class-key (c-lang-const c-class-key))
1488 (c-lang-defconst c-brace-list-decl-kwds
1489 "Keywords introducing declarations where the following block (if
1490 any) is a brace list.
1492 If any of these also are on `c-type-list-kwds', `c-ref-list-kwds',
1493 `c-colon-type-list-kwds', `c-paren-nontype-kwds', `c-paren-type-kwds',
1494 `c-<>-type-kwds', or `c-<>-arglist-kwds' then the associated clauses
1495 will be handled."
1496 t '("enum")
1497 (java awk) nil)
1499 (c-lang-defconst c-brace-list-key
1500 ;; Regexp matching the start of declarations where the following
1501 ;; block is a brace list.
1502 t (c-make-keywords-re t (c-lang-const c-brace-list-decl-kwds)))
1503 (c-lang-defvar c-brace-list-key (c-lang-const c-brace-list-key))
1505 (c-lang-defconst c-other-block-decl-kwds
1506 "Keywords where the following block (if any) contains another
1507 declaration level that should not be considered a class. For every
1508 keyword here, CC Mode will add a set of special syntactic symbols for
1509 those blocks. E.g. if the keyword is \"foo\" then there will be
1510 `foo-open', `foo-close', and `infoo' symbols.
1512 The intention is that this category should be used for block
1513 constructs that aren't related to object orientation concepts like
1514 classes (which thus also include e.g. interfaces, templates,
1515 contracts, structs, etc). The more pragmatic distinction is that
1516 while most want some indentation inside classes, it's fairly common
1517 that they don't want it in some of these constructs, so it should be
1518 simple to configure that differently from classes. See also
1519 `c-class-decl-kwds'.
1521 If any of these also are on `c-type-list-kwds', `c-ref-list-kwds',
1522 `c-colon-type-list-kwds', `c-paren-nontype-kwds', `c-paren-type-kwds',
1523 `c-<>-type-kwds', or `c-<>-arglist-kwds' then the associated clauses
1524 will be handled."
1525 t nil
1526 (c objc) '("extern")
1527 c++ '("namespace" "extern")
1528 idl '("module"
1529 ;; In CORBA CIDL:
1530 "composition"))
1532 (c-lang-defconst c-other-decl-block-key
1533 ;; Regexp matching the start of blocks besides classes that contain
1534 ;; another declaration level.
1535 t (c-make-keywords-re t (c-lang-const c-other-block-decl-kwds)))
1536 (c-lang-defvar c-other-decl-block-key (c-lang-const c-other-decl-block-key))
1538 (c-lang-defconst c-typedef-decl-kwds
1539 "Keywords introducing declarations where the identifier(s) being
1540 declared are types.
1542 If any of these also are on `c-type-list-kwds', `c-ref-list-kwds',
1543 `c-colon-type-list-kwds', `c-paren-nontype-kwds', `c-paren-type-kwds',
1544 `c-<>-type-kwds', or `c-<>-arglist-kwds' then the associated clauses
1545 will be handled."
1546 ;; Default to `c-class-decl-kwds' and `c-brace-list-decl-kwds'
1547 ;; (since e.g. "Foo" is a type that's being defined in "class Foo
1548 ;; {...}").
1549 t (append (c-lang-const c-class-decl-kwds)
1550 (c-lang-const c-brace-list-decl-kwds))
1551 ;; Languages that have a "typedef" construct.
1552 (c c++ objc idl pike) (append (c-lang-const c-typedef-decl-kwds)
1553 '("typedef"))
1554 ;; Unlike most other languages, exception names are not handled as
1555 ;; types in IDL since they only can occur in "raises" specs.
1556 idl (delete "exception" (append (c-lang-const c-typedef-decl-kwds) nil)))
1558 (c-lang-defconst c-typeless-decl-kwds
1559 "Keywords introducing declarations where the \(first) identifier
1560 \(declarator) follows directly after the keyword, without any type.
1562 If any of these also are on `c-type-list-kwds', `c-ref-list-kwds',
1563 `c-colon-type-list-kwds', `c-paren-nontype-kwds', `c-paren-type-kwds',
1564 `c-<>-type-kwds', or `c-<>-arglist-kwds' then the associated clauses
1565 will be handled."
1566 ;; Default to `c-class-decl-kwds' and `c-brace-list-decl-kwds'
1567 ;; (since e.g. "Foo" is the identifier being defined in "class Foo
1568 ;; {...}").
1569 t (append (c-lang-const c-class-decl-kwds)
1570 (c-lang-const c-brace-list-decl-kwds))
1571 ;; Note: "manages" for CORBA CIDL clashes with its presence on
1572 ;; `c-type-list-kwds' for IDL.
1573 idl (append (c-lang-const c-typeless-decl-kwds)
1574 '("factory" "finder" "native"
1575 ;; In CORBA PSDL:
1576 "key" "stores"
1577 ;; In CORBA CIDL:
1578 "facet"))
1579 pike (append (c-lang-const c-class-decl-kwds)
1580 '("constant")))
1582 (c-lang-defconst c-modifier-kwds
1583 "Keywords that can prefix normal declarations of identifiers
1584 \(and typically act as flags). Things like argument declarations
1585 inside function headers are also considered declarations in this
1586 sense.
1588 If any of these also are on `c-type-list-kwds', `c-ref-list-kwds',
1589 `c-colon-type-list-kwds', `c-paren-nontype-kwds', `c-paren-type-kwds',
1590 `c-<>-type-kwds', or `c-<>-arglist-kwds' then the associated clauses
1591 will be handled."
1592 t nil
1593 (c c++) '("auto" "extern" "inline" "register" "static")
1594 c++ (append '("explicit" "friend" "mutable" "template" "using" "virtual")
1595 (c-lang-const c-modifier-kwds))
1596 objc '("auto" "bycopy" "byref" "extern" "in" "inout" "oneway" "out" "static")
1597 ;; FIXME: Some of those below ought to be on `c-other-decl-kwds' instead.
1598 idl '("abstract" "attribute" "const" "consumes" "custom" "emits" "import"
1599 "in" "inout" "local" "multiple" "oneway" "out" "private" "provides"
1600 "public" "publishes" "readonly" "typeid" "typeprefix" "uses"
1601 ;; In CORBA PSDL:
1602 "primary" "state"
1603 ;; In CORBA CIDL:
1604 "bindsTo" "delegatesTo" "implements" "proxy" "storedOn")
1605 ;; Note: "const" is not used in Java, but it's still a reserved keyword.
1606 java '("abstract" "const" "final" "native" "private" "protected" "public"
1607 "static" "strictfp" "synchronized" "transient" "volatile")
1608 pike '("final" "inline" "local" "nomask" "optional" "private" "protected"
1609 "public" "static" "variant"))
1611 (c-lang-defconst c-other-decl-kwds
1612 "Keywords that can start or prefix any declaration level construct,
1613 besides those on `c-class-decl-kwds', `c-brace-list-decl-kwds',
1614 `c-other-block-decl-kwds', `c-typedef-decl-kwds',
1615 `c-typeless-decl-kwds' and `c-modifier-kwds'.
1617 If any of these also are on `c-type-list-kwds', `c-ref-list-kwds',
1618 `c-colon-type-list-kwds', `c-paren-nontype-kwds', `c-paren-type-kwds',
1619 `c-<>-type-kwds', or `c-<>-arglist-kwds' then the associated clauses
1620 will be handled."
1621 t nil
1622 objc '("@class" "@end" "@defs")
1623 java '("import" "package")
1624 pike '("import" "inherit"))
1626 (c-lang-defconst c-decl-start-kwds
1627 "Keywords that always start declarations, wherever they occur.
1628 This can be used for declarations that aren't recognized by the normal
1629 combination of `c-decl-prefix-re' and `c-decl-start-re'."
1630 t nil
1631 ;; Classes can be declared anywhere in a Pike expression.
1632 pike '("class"))
1634 (c-lang-defconst c-decl-hangon-kwds
1635 "Keywords that can occur anywhere in a declaration level construct.
1636 This is used for self-contained things that can be tacked on anywhere
1637 on a declaration and that should be ignored to be able to recognize it
1638 correctly. Typical cases are compiler extensions like
1639 \"__attribute__\" or \"__declspec\":
1641 __declspec(noreturn) void foo();
1642 class __declspec(dllexport) classname {...};
1643 void foo() __attribute__((noreturn));
1645 Note that unrecognized plain symbols are skipped anyway if they occur
1646 before the type, so such things are not necessary to mention here.
1647 Mentioning them here is necessary only if they can occur in other
1648 places, or if they are followed by a construct that must be skipped
1649 over \(like the parens in the \"__attribute__\" and \"__declspec\"
1650 examples above). In the last case, they alse need to be present on
1651 one of `c-type-list-kwds', `c-ref-list-kwds',
1652 `c-colon-type-list-kwds', `c-paren-nontype-kwds', `c-paren-type-kwds',
1653 `c-<>-type-kwds', or `c-<>-arglist-kwds'."
1654 ;; NB: These are currently not recognized in all parts of a
1655 ;; declaration. Specifically, they aren't recognized in the middle
1656 ;; of multi-token types, inside declarators, and between the
1657 ;; identifier and the arglist paren of a function declaration.
1659 ;; FIXME: This ought to be user customizable since compiler stuff
1660 ;; like this usually is wrapped in project specific macros. (It'd
1661 ;; of course be even better if we could cope without knowing this.)
1662 t nil
1663 (c c++) '(;; GCC extension.
1664 "__attribute__"
1665 ;; MSVC extension.
1666 "__declspec"))
1668 (c-lang-defconst c-decl-hangon-key
1669 ;; Adorned regexp matching `c-decl-hangon-kwds'.
1670 t (c-make-keywords-re t (c-lang-const c-decl-hangon-kwds)))
1671 (c-lang-defvar c-decl-hangon-key (c-lang-const c-decl-hangon-key))
1673 (c-lang-defconst c-prefix-spec-kwds
1674 ;; All keywords that can occur in the preamble of a declaration.
1675 ;; They typically occur before the type, but they are also matched
1676 ;; after presumptive types since we often can't be sure that
1677 ;; something is a type or just some sort of macro in front of the
1678 ;; declaration. They might be ambiguous with types or type
1679 ;; prefixes.
1680 t (delete-duplicates (append (c-lang-const c-class-decl-kwds)
1681 (c-lang-const c-brace-list-decl-kwds)
1682 (c-lang-const c-other-block-decl-kwds)
1683 (c-lang-const c-typedef-decl-kwds)
1684 (c-lang-const c-typeless-decl-kwds)
1685 (c-lang-const c-modifier-kwds)
1686 (c-lang-const c-other-decl-kwds)
1687 (c-lang-const c-decl-start-kwds)
1688 (c-lang-const c-decl-hangon-kwds))
1689 :test 'string-equal))
1691 (c-lang-defconst c-prefix-spec-kwds-re
1692 ;; Adorned regexp of `c-prefix-spec-kwds'.
1693 t (c-make-keywords-re t (c-lang-const c-prefix-spec-kwds)))
1694 (c-lang-defvar c-prefix-spec-kwds-re (c-lang-const c-prefix-spec-kwds-re))
1696 (c-lang-defconst c-specifier-key
1697 ;; Adorned regexp of the keywords in `c-prefix-spec-kwds' that
1698 ;; aren't ambiguous with types or type prefixes.
1699 t (c-make-keywords-re t
1700 (set-difference (c-lang-const c-prefix-spec-kwds)
1701 (c-lang-const c-type-start-kwds)
1702 :test 'string-equal)))
1703 (c-lang-defvar c-specifier-key (c-lang-const c-specifier-key))
1705 (c-lang-defconst c-postfix-spec-kwds
1706 ;; Keywords that can occur after argument list of a function header
1707 ;; declaration, i.e. in the "K&R region".
1708 t (append (c-lang-const c-postfix-decl-spec-kwds)
1709 (c-lang-const c-decl-hangon-kwds)))
1711 (c-lang-defconst c-not-decl-init-keywords
1712 ;; Adorned regexp matching all keywords that can't appear at the
1713 ;; start of a declaration.
1714 t (c-make-keywords-re t
1715 (set-difference (c-lang-const c-keywords)
1716 (append (c-lang-const c-type-start-kwds)
1717 (c-lang-const c-prefix-spec-kwds))
1718 :test 'string-equal)))
1719 (c-lang-defvar c-not-decl-init-keywords
1720 (c-lang-const c-not-decl-init-keywords))
1722 (c-lang-defconst c-protection-kwds
1723 "Access protection label keywords in classes."
1724 t nil
1725 c++ '("private" "protected" "public")
1726 objc '("@private" "@protected" "@public"))
1728 (c-lang-defconst c-block-decls-with-vars
1729 "Keywords introducing declarations that can contain a block which
1730 might be followed by variable declarations, e.g. like \"foo\" in
1731 \"class Foo { ... } foo;\". So if there is a block in a declaration
1732 like that, it ends with the following ';' and not right away.
1734 The keywords on list are assumed to also be present on one of the
1735 `*-decl-kwds' lists."
1736 t nil
1737 (c objc) '("struct" "union" "enum" "typedef")
1738 c++ '("class" "struct" "union" "enum" "typedef"))
1740 (c-lang-defconst c-opt-block-decls-with-vars-key
1741 ;; Regexp matching the `c-block-decls-with-vars' keywords, or nil in
1742 ;; languages without such constructs.
1743 t (and (c-lang-const c-block-decls-with-vars)
1744 (c-make-keywords-re t (c-lang-const c-block-decls-with-vars))))
1745 (c-lang-defvar c-opt-block-decls-with-vars-key
1746 (c-lang-const c-opt-block-decls-with-vars-key))
1748 (c-lang-defconst c-postfix-decl-spec-kwds
1749 "Keywords introducing extra declaration specifiers in the region
1750 between the header and the body \(i.e. the \"K&R-region\") in
1751 declarations."
1752 t nil
1753 java '("extends" "implements" "throws")
1754 idl '("context" "getraises" "manages" "primarykey" "raises" "setraises"
1755 "supports"
1756 ;; In CORBA PSDL:
1757 "as" "const" "implements" "of" "ref"))
1759 (c-lang-defconst c-nonsymbol-sexp-kwds
1760 "Keywords that may be followed by a nonsymbol sexp before whatever
1761 construct it's part of continues."
1762 t nil
1763 (c c++ objc) '("extern"))
1765 (c-lang-defconst c-type-list-kwds
1766 "Keywords that may be followed by a comma separated list of type
1767 identifiers, where each optionally can be prefixed by keywords. (Can
1768 also be used for the special case when the list can contain only one
1769 element.)
1771 Assumed to be mutually exclusive with `c-ref-list-kwds'. There's no
1772 reason to put keywords on this list if they are on `c-type-prefix-kwds'.
1773 There's also no reason to add keywords that prefixes a normal
1774 declaration consisting of a type followed by a declarator (list), so
1775 the keywords on `c-modifier-kwds' should normally not be listed here
1776 either.
1778 Note: Use `c-typeless-decl-kwds' for keywords followed by a function
1779 or variable identifier (that's being defined)."
1780 t nil
1781 c++ '("operator")
1782 objc '("@class")
1783 java '("import" "new" "extends" "implements" "throws")
1784 idl '("manages" "native" "primarykey" "supports"
1785 ;; In CORBA PSDL:
1786 "as" "implements" "of" "scope")
1787 pike '("inherit"))
1789 (c-lang-defconst c-ref-list-kwds
1790 "Keywords that may be followed by a comma separated list of
1791 reference (i.e. namespace/scope/module) identifiers, where each
1792 optionally can be prefixed by keywords. (Can also be used for the
1793 special case when the list can contain only one element.) Assumed to
1794 be mutually exclusive with `c-type-list-kwds'.
1796 Note: Use `c-typeless-decl-kwds' for keywords followed by a function
1797 or variable identifier (that's being defined)."
1798 t nil
1799 c++ '("namespace")
1800 java '("package")
1801 idl '("import" "module"
1802 ;; In CORBA CIDL:
1803 "composition")
1804 pike '("import"))
1806 (c-lang-defconst c-colon-type-list-kwds
1807 "Keywords that may be followed (not necessarily directly) by a colon
1808 and then a comma separated list of type identifiers, where each
1809 optionally can be prefixed by keywords. (Can also be used for the
1810 special case when the list can contain only one element.)"
1811 t nil
1812 c++ '("class" "struct")
1813 idl '("component" "eventtype" "home" "interface" "valuetype"
1814 ;; In CORBA PSDL:
1815 "storagehome" "storagetype"))
1817 (c-lang-defconst c-colon-type-list-re
1818 "Regexp matched after the keywords in `c-colon-type-list-kwds' to skip
1819 forward to the colon. The end of the match is assumed to be directly
1820 after the colon, so the regexp should end with \":\". Must be a
1821 regexp if `c-colon-type-list-kwds' isn't nil."
1822 t (if (c-lang-const c-colon-type-list-kwds)
1823 ;; Disallow various common punctuation chars that can't come
1824 ;; before the ":" that starts the inherit list after "class"
1825 ;; or "struct" in C++. (Also used as default for other
1826 ;; languages.)
1827 "[^\]\[{}();,/#=:]*:"))
1828 (c-lang-defvar c-colon-type-list-re (c-lang-const c-colon-type-list-re))
1830 (c-lang-defconst c-paren-nontype-kwds
1831 "Keywords that may be followed by a parenthesis expression that doesn't
1832 contain type identifiers."
1833 t nil
1834 (c c++) '(;; GCC extension.
1835 "__attribute__"
1836 ;; MSVC extension.
1837 "__declspec"))
1839 (c-lang-defconst c-paren-type-kwds
1840 "Keywords that may be followed by a parenthesis expression containing
1841 type identifiers separated by arbitrary tokens."
1842 t nil
1843 c++ '("throw")
1844 objc '("@defs")
1845 idl '("switch")
1846 pike '("array" "function" "int" "mapping" "multiset" "object" "program"))
1848 (c-lang-defconst c-paren-any-kwds
1849 t (delete-duplicates (append (c-lang-const c-paren-nontype-kwds)
1850 (c-lang-const c-paren-type-kwds))
1851 :test 'string-equal))
1853 (c-lang-defconst c-<>-type-kwds
1854 "Keywords that may be followed by an angle bracket expression
1855 containing type identifiers separated by \",\". The difference from
1856 `c-<>-arglist-kwds' is that unknown names are taken to be types and
1857 not other identifiers. `c-recognize-<>-arglists' is assumed to be set
1858 if this isn't nil."
1859 t nil
1860 objc '("id")
1861 idl '("sequence"
1862 ;; In CORBA PSDL:
1863 "ref"))
1865 (c-lang-defconst c-<>-arglist-kwds
1866 "Keywords that can be followed by a C++ style template arglist; see
1867 `c-recognize-<>-arglists' for details. That language constant is
1868 assumed to be set if this isn't nil."
1869 t nil
1870 c++ '("template")
1871 idl '("fixed" "string" "wstring"))
1873 (c-lang-defconst c-<>-sexp-kwds
1874 ;; All keywords that can be followed by an angle bracket sexp.
1875 t (delete-duplicates (append (c-lang-const c-<>-type-kwds)
1876 (c-lang-const c-<>-arglist-kwds))
1877 :test 'string-equal))
1879 (c-lang-defconst c-opt-<>-sexp-key
1880 ;; Adorned regexp matching keywords that can be followed by an angle
1881 ;; bracket sexp. Always set when `c-recognize-<>-arglists' is.
1882 t (if (c-lang-const c-recognize-<>-arglists)
1883 (c-make-keywords-re t (c-lang-const c-<>-sexp-kwds))))
1884 (c-lang-defvar c-opt-<>-sexp-key (c-lang-const c-opt-<>-sexp-key))
1886 (c-lang-defconst c-brace-id-list-kwds
1887 "Keywords that may be followed by a brace block containing a comma
1888 separated list of identifier definitions, i.e. like the list of
1889 identifiers that follows the type in a normal declaration."
1890 t (c-lang-const c-brace-list-decl-kwds))
1892 (c-lang-defconst c-block-stmt-1-kwds
1893 "Statement keywords followed directly by a substatement."
1894 t '("do" "else")
1895 c++ '("do" "else" "try")
1896 java '("do" "else" "finally" "try")
1897 idl nil)
1899 (c-lang-defconst c-block-stmt-1-key
1900 ;; Regexp matching the start of any statement followed directly by a
1901 ;; substatement (doesn't match a bare block, however).
1902 t (c-make-keywords-re t (c-lang-const c-block-stmt-1-kwds)))
1903 (c-lang-defvar c-block-stmt-1-key (c-lang-const c-block-stmt-1-key))
1905 (c-lang-defconst c-block-stmt-2-kwds
1906 "Statement keywords followed by a paren sexp and then by a substatement."
1907 t '("for" "if" "switch" "while")
1908 c++ '("for" "if" "switch" "while" "catch")
1909 java '("for" "if" "switch" "while" "catch" "synchronized")
1910 idl nil
1911 pike '("for" "if" "switch" "while" "foreach")
1912 awk '("for" "if" "while"))
1914 (c-lang-defconst c-block-stmt-2-key
1915 ;; Regexp matching the start of any statement followed by a paren sexp
1916 ;; and then by a substatement.
1917 t (c-make-keywords-re t (c-lang-const c-block-stmt-2-kwds)))
1918 (c-lang-defvar c-block-stmt-2-key (c-lang-const c-block-stmt-2-key))
1920 (c-lang-defconst c-block-stmt-kwds
1921 ;; Union of `c-block-stmt-1-kwds' and `c-block-stmt-2-kwds'.
1922 t (delete-duplicates (append (c-lang-const c-block-stmt-1-kwds)
1923 (c-lang-const c-block-stmt-2-kwds))
1924 :test 'string-equal))
1926 (c-lang-defconst c-opt-block-stmt-key
1927 ;; Regexp matching the start of any statement that has a
1928 ;; substatement (except a bare block). Nil in languages that
1929 ;; don't have such constructs.
1930 t (if (or (c-lang-const c-block-stmt-1-kwds)
1931 (c-lang-const c-block-stmt-2-kwds))
1932 (c-make-keywords-re t
1933 (append (c-lang-const c-block-stmt-1-kwds)
1934 (c-lang-const c-block-stmt-2-kwds)))))
1935 (c-lang-defvar c-opt-block-stmt-key (c-lang-const c-opt-block-stmt-key))
1937 (c-lang-defconst c-simple-stmt-kwds
1938 "Statement keywords followed by an expression or nothing."
1939 t '("break" "continue" "goto" "return")
1940 ;; Note: `goto' is not valid in Java, but the keyword is still reserved.
1941 java '("break" "continue" "goto" "return" "throw")
1942 idl nil
1943 pike '("break" "continue" "return")
1944 awk '(;; Not sure about "delete", "exit", "getline", etc. ; ACM 2002/5/30
1945 "break" "continue" "return" "delete" "exit" "getline" "next"
1946 "nextfile" "print" "printf"))
1948 (c-lang-defconst c-simple-stmt-key
1949 ;; Adorned regexp matching `c-simple-stmt-kwds'.
1950 t (c-make-keywords-re t (c-lang-const c-simple-stmt-kwds)))
1951 (c-lang-defvar c-simple-stmt-key (c-lang-const c-simple-stmt-key))
1953 (c-lang-defconst c-paren-stmt-kwds
1954 "Statement keywords followed by a parenthesis expression that
1955 nevertheless contains a list separated with ';' and not ','."
1956 t '("for")
1957 idl nil)
1959 (c-lang-defconst c-paren-stmt-key
1960 ;; Adorned regexp matching `c-paren-stmt-kwds'.
1961 t (c-make-keywords-re t (c-lang-const c-paren-stmt-kwds)))
1962 (c-lang-defvar c-paren-stmt-key (c-lang-const c-paren-stmt-key))
1964 (c-lang-defconst c-asm-stmt-kwds
1965 "Statement keywords followed by an assembler expression."
1966 t nil
1967 (c c++) '("asm" "__asm__")) ;; Not standard, but common.
1969 (c-lang-defconst c-opt-asm-stmt-key
1970 ;; Regexp matching the start of an assembler statement. Nil in
1971 ;; languages that don't support that.
1972 t (if (c-lang-const c-asm-stmt-kwds)
1973 (c-make-keywords-re t (c-lang-const c-asm-stmt-kwds))))
1974 (c-lang-defvar c-opt-asm-stmt-key (c-lang-const c-opt-asm-stmt-key))
1976 (c-lang-defconst c-label-kwds
1977 "Keywords introducing colon terminated labels in blocks."
1978 t '("case" "default")
1979 awk nil)
1981 (c-lang-defconst c-label-kwds-regexp
1982 ;; Adorned regexp matching any keyword that introduces a label.
1983 t (c-make-keywords-re t (c-lang-const c-label-kwds)))
1984 (c-lang-defvar c-label-kwds-regexp (c-lang-const c-label-kwds-regexp))
1986 (c-lang-defconst c-before-label-kwds
1987 "Keywords that might be followed by a label identifier."
1988 t '("goto")
1989 (java pike) (append '("break" "continue")
1990 (c-lang-const c-before-label-kwds))
1991 idl nil
1992 awk nil)
1994 (c-lang-defconst c-constant-kwds
1995 "Keywords for constants."
1996 t nil
1997 (c c++) '("NULL" ;; Not a keyword, but practically works as one.
1998 "false" "true") ; Defined in C99.
1999 objc '("nil" "Nil")
2000 idl '("TRUE" "FALSE")
2001 pike '("UNDEFINED")) ;; Not a keyword, but practically works as one.
2003 (c-lang-defconst c-primary-expr-kwds
2004 "Keywords besides constants and operators that start primary expressions."
2005 t nil
2006 c++ '("operator" "this")
2007 objc '("super" "self")
2008 java '("this")
2009 pike '("this")) ;; Not really a keyword, but practically works as one.
2011 (c-lang-defconst c-expr-kwds
2012 ;; Keywords that can occur anywhere in expressions. Built from
2013 ;; `c-primary-expr-kwds' and all keyword operators in `c-operators'.
2014 t (delete-duplicates
2015 (append (c-lang-const c-primary-expr-kwds)
2016 (c-filter-ops (c-lang-const c-operator-list)
2018 "\\`\\(\\w\\|\\s_\\)+\\'"))
2019 :test 'string-equal))
2021 (c-lang-defconst c-lambda-kwds
2022 "Keywords that start lambda constructs, i.e. function definitions in
2023 expressions."
2024 t nil
2025 pike '("lambda"))
2027 (c-lang-defconst c-inexpr-block-kwds
2028 "Keywords that start constructs followed by statement blocks which can
2029 be used in expressions \(the gcc extension for this in C and C++ is
2030 handled separately by `c-recognize-paren-inexpr-blocks')."
2031 t nil
2032 pike '("catch" "gauge"))
2034 (c-lang-defconst c-inexpr-class-kwds
2035 "Keywords that can start classes inside expressions."
2036 t nil
2037 java '("new")
2038 pike '("class"))
2040 (c-lang-defconst c-inexpr-brace-list-kwds
2041 "Keywords that can start brace list blocks inside expressions.
2042 Note that Java specific rules are currently applied to tell this from
2043 `c-inexpr-class-kwds'."
2044 t nil
2045 java '("new"))
2047 (c-lang-defconst c-opt-inexpr-brace-list-key
2048 ;; Regexp matching the start of a brace list in an expression, or
2049 ;; nil in languages that don't have such things. This should not
2050 ;; match brace lists recognized through `c-special-brace-lists'.
2051 t (and (c-lang-const c-inexpr-brace-list-kwds)
2052 (c-make-keywords-re t (c-lang-const c-inexpr-brace-list-kwds))))
2053 (c-lang-defvar c-opt-inexpr-brace-list-key
2054 (c-lang-const c-opt-inexpr-brace-list-key))
2056 (c-lang-defconst c-decl-block-key
2057 ;; Regexp matching keywords in any construct that contain another
2058 ;; declaration level, i.e. that isn't followed by a function block
2059 ;; or brace list. When the first submatch matches, it's an
2060 ;; unambiguous construct, otherwise it's an ambiguous match that
2061 ;; might also be the return type of a function declaration.
2062 t (let* ((decl-kwds (append (c-lang-const c-class-decl-kwds)
2063 (c-lang-const c-other-block-decl-kwds)
2064 (c-lang-const c-inexpr-class-kwds)))
2065 (unambiguous (set-difference decl-kwds
2066 (c-lang-const c-type-start-kwds)
2067 :test 'string-equal))
2068 (ambiguous (intersection decl-kwds
2069 (c-lang-const c-type-start-kwds)
2070 :test 'string-equal)))
2071 (if ambiguous
2072 (concat (c-make-keywords-re t unambiguous)
2073 "\\|"
2074 (c-make-keywords-re t ambiguous))
2075 (c-make-keywords-re t unambiguous))))
2076 (c-lang-defvar c-decl-block-key (c-lang-const c-decl-block-key))
2078 (c-lang-defconst c-bitfield-kwds
2079 "Keywords that can introduce bitfields."
2080 t nil
2081 (c c++ objc) '("char" "int" "long" "signed" "unsigned"))
2083 (c-lang-defconst c-opt-bitfield-key
2084 ;; Regexp matching the start of a bitfield (not uniquely), or nil in
2085 ;; languages without bitfield support.
2086 t nil
2087 (c c++) (c-make-keywords-re t (c-lang-const c-bitfield-kwds)))
2088 (c-lang-defvar c-opt-bitfield-key (c-lang-const c-opt-bitfield-key))
2090 (c-lang-defconst c-other-kwds
2091 "Keywords not accounted for by any other `*-kwds' language constant."
2092 t nil
2093 idl '("truncatable"
2094 ;; In CORBA CIDL: (These are declaration keywords that never
2095 ;; can start a declaration.)
2096 "entity" "process" "service" "session" "storage"))
2099 ;;; Constants built from keywords.
2101 ;; Note: No `*-kwds' language constants may be defined below this point.
2103 (eval-and-compile
2104 (defconst c-kwds-lang-consts
2105 ;; List of all the language constants that contain keyword lists.
2106 (let (list)
2107 (mapatoms (lambda (sym)
2108 (when (and (boundp sym)
2109 (string-match "-kwds\\'" (symbol-name sym)))
2110 ;; Make the list of globally interned symbols
2111 ;; instead of ones interned in `c-lang-constants'.
2112 (setq list (cons (intern (symbol-name sym)) list))))
2113 c-lang-constants)
2114 list)))
2116 (c-lang-defconst c-keywords
2117 ;; All keywords as a list.
2118 t (delete-duplicates
2119 (c-lang-defconst-eval-immediately
2120 `(append ,@(mapcar (lambda (kwds-lang-const)
2121 `(c-lang-const ,kwds-lang-const))
2122 c-kwds-lang-consts)
2123 nil))
2124 :test 'string-equal))
2126 (c-lang-defconst c-keywords-regexp
2127 ;; All keywords as an adorned regexp.
2128 t (c-make-keywords-re t (c-lang-const c-keywords)))
2129 (c-lang-defvar c-keywords-regexp (c-lang-const c-keywords-regexp))
2131 (c-lang-defconst c-keyword-member-alist
2132 ;; An alist with all the keywords in the cars. The cdr for each
2133 ;; keyword is a list of the symbols for the `*-kwds' lists that
2134 ;; contains it.
2135 t (let ((kwd-list-alist
2136 (c-lang-defconst-eval-immediately
2137 `(list ,@(mapcar (lambda (kwds-lang-const)
2138 `(cons ',kwds-lang-const
2139 (c-lang-const ,kwds-lang-const)))
2140 c-kwds-lang-consts))))
2141 lang-const kwd-list kwd
2142 result-alist elem)
2143 (while kwd-list-alist
2144 (setq lang-const (caar kwd-list-alist)
2145 kwd-list (cdar kwd-list-alist)
2146 kwd-list-alist (cdr kwd-list-alist))
2147 (while kwd-list
2148 (setq kwd (car kwd-list)
2149 kwd-list (cdr kwd-list))
2150 (unless (setq elem (assoc kwd result-alist))
2151 (setq result-alist (cons (setq elem (list kwd)) result-alist)))
2152 (unless (memq lang-const (cdr elem))
2153 (setcdr elem (cons lang-const (cdr elem))))))
2154 result-alist))
2156 (c-lang-defvar c-keywords-obarray
2157 ;; An obarray containing all keywords as symbols. The property list
2158 ;; of each symbol has a non-nil entry for the specific `*-kwds'
2159 ;; lists it's a member of.
2161 ;; E.g. to see whether the string str contains a keyword on
2162 ;; `c-class-decl-kwds', one can do like this:
2163 ;; (get (intern-soft str c-keyword-obarray) 'c-class-decl-kwds)
2164 ;; Which preferably is written using the associated functions in
2165 ;; cc-engine:
2166 ;; (c-keyword-member (c-keyword-sym str) 'c-class-decl-kwds)
2168 ;; The obarray is not stored directly as a language constant since
2169 ;; the printed representation for obarrays used in .elc files isn't
2170 ;; complete.
2172 (let* ((alist (c-lang-const c-keyword-member-alist))
2173 kwd lang-const-list
2174 (obarray (make-vector (* (length alist) 2) 0)))
2175 (while alist
2176 (setq kwd (caar alist)
2177 lang-const-list (cdar alist)
2178 alist (cdr alist))
2179 (setplist (intern kwd obarray)
2180 ;; Emacs has an odd bug that causes `mapcan' to fail
2181 ;; with unintelligible errors. (XEmacs works.)
2182 ;;(mapcan (lambda (lang-const)
2183 ;; (list lang-const t))
2184 ;; lang-const-list)
2185 (apply 'nconc (mapcar (lambda (lang-const)
2186 (list lang-const t))
2187 lang-const-list))))
2188 obarray))
2190 (c-lang-defconst c-regular-keywords-regexp
2191 ;; Adorned regexp matching all keywords that should be fontified
2192 ;; with the keywords face. I.e. that aren't types or constants.
2193 t (c-make-keywords-re t
2194 (set-difference (c-lang-const c-keywords)
2195 (append (c-lang-const c-primitive-type-kwds)
2196 (c-lang-const c-constant-kwds))
2197 :test 'string-equal)))
2198 (c-lang-defvar c-regular-keywords-regexp
2199 (c-lang-const c-regular-keywords-regexp))
2201 (c-lang-defconst c-primary-expr-regexp
2202 ;; Regexp matching the start of any primary expression, i.e. any
2203 ;; literal, symbol, prefix operator, and '('. It doesn't need to
2204 ;; exclude keywords; they are excluded afterwards unless the second
2205 ;; submatch matches. If the first but not the second submatch
2206 ;; matches then it is an ambiguous primary expression; it could also
2207 ;; be a match of e.g. an infix operator. (The case with ambiguous
2208 ;; keyword operators isn't handled.)
2210 t (let* ((prefix-ops
2211 (c-filter-ops (c-lang-const c-operators)
2212 '(prefix)
2213 (lambda (op)
2214 ;; Filter out the special case prefix
2215 ;; operators that are close parens.
2216 (not (string-match "\\s)" op)))))
2218 (nonkeyword-prefix-ops
2219 (c-filter-ops prefix-ops
2221 "\\`\\(\\s.\\|\\s(\\|\\s)\\)+\\'"))
2223 (in-or-postfix-ops
2224 (c-filter-ops (c-lang-const c-operators)
2225 '(postfix
2226 postfix-if-paren
2227 left-assoc
2228 right-assoc
2229 right-assoc-sequence)
2232 (unambiguous-prefix-ops (set-difference nonkeyword-prefix-ops
2233 in-or-postfix-ops
2234 :test 'string-equal))
2235 (ambiguous-prefix-ops (intersection nonkeyword-prefix-ops
2236 in-or-postfix-ops
2237 :test 'string-equal)))
2239 (concat
2240 "\\("
2241 ;; Take out all symbol class operators from `prefix-ops' and make the
2242 ;; first submatch from them together with `c-primary-expr-kwds'.
2243 (c-make-keywords-re t
2244 (append (c-lang-const c-primary-expr-kwds)
2245 (set-difference prefix-ops nonkeyword-prefix-ops
2246 :test 'string-equal)))
2248 "\\|"
2249 ;; Match all ambiguous operators.
2250 (c-make-keywords-re nil
2251 (intersection nonkeyword-prefix-ops in-or-postfix-ops
2252 :test 'string-equal))
2253 "\\)"
2255 "\\|"
2256 ;; Now match all other symbols.
2257 (c-lang-const c-symbol-start)
2259 "\\|"
2260 ;; The chars that can start integer and floating point
2261 ;; constants.
2262 "\\.?[0-9]"
2264 "\\|"
2265 ;; The nonambiguous operators from `prefix-ops'.
2266 (c-make-keywords-re nil
2267 (set-difference nonkeyword-prefix-ops in-or-postfix-ops
2268 :test 'string-equal))
2270 "\\|"
2271 ;; Match string and character literals.
2272 "\\s\""
2273 (if (memq 'gen-string-delim c-emacs-features)
2274 "\\|\\s|"
2275 ""))))
2276 (c-lang-defvar c-primary-expr-regexp (c-lang-const c-primary-expr-regexp))
2279 ;;; Additional constants for parser-level constructs.
2281 (c-lang-defconst c-decl-prefix-re
2282 "Regexp matching something that might precede a declaration, cast or
2283 label, such as the last token of a preceding statement or declaration.
2284 This is used in the common situation where a declaration or cast
2285 doesn't start with any specific token that can be searched for.
2287 The regexp should not match bob; that is done implicitly. It can't
2288 require a match longer than one token. The end of the token is taken
2289 to be at the end of the first submatch, which is assumed to always
2290 match. It's undefined whether identifier syntax (see
2291 `c-identifier-syntax-table') is in effect or not. This regexp is
2292 assumed to be a superset of `c-label-prefix-re' if
2293 `c-recognize-colon-labels' is set.
2295 Besides this, `c-decl-start-kwds' is used to find declarations.
2297 Note: This variable together with `c-decl-start-re' and
2298 `c-decl-start-kwds' is only used to detect \"likely\"
2299 declaration/cast/label starts. I.e. they might produce more matches
2300 but should not miss anything (or else it's necessary to use text
2301 properties - see the next note). Wherever they match, the following
2302 construct is analyzed to see if it indeed is a declaration, cast or
2303 label. That analysis is not cheap, so it's important that not too
2304 many false matches are triggered.
2306 Note: If a declaration/cast/label start can't be detected with this
2307 variable, it's necessary to use the `c-type' text property with the
2308 value `c-decl-end' on the last char of the last token preceding the
2309 declaration. See the comment blurb at the start of cc-engine.el for
2310 more info."
2312 ;; We match a sequence of characters to skip over things like \"};\"
2313 ;; more quickly. We match ")" in C for K&R region declarations, and
2314 ;; in all languages except Java for when a cpp macro definition
2315 ;; begins with a declaration.
2316 t "\\([\{\}\(\);,]+\\)"
2317 java "\\([\{\}\(;,]+\\)"
2318 ;; Match "<" in C++ to get the first argument in a template arglist.
2319 ;; In that case there's an additional check in `c-find-decl-spots'
2320 ;; that it got open paren syntax.
2321 c++ "\\([\{\}\(\);,<]+\\)"
2322 ;; Additionally match the protection directives in Objective-C.
2323 ;; Note that this doesn't cope with the longer directives, which we
2324 ;; would have to match from start to end since they don't end with
2325 ;; any easily recognized characters.
2326 objc (concat "\\([\{\}\(\);,]+\\|"
2327 (c-make-keywords-re nil (c-lang-const c-protection-kwds))
2328 "\\)")
2329 ;; Pike is like C but we also match "[" for multiple value
2330 ;; assignments and type casts.
2331 pike "\\([\{\}\(\)\[;,]+\\)")
2332 (c-lang-defvar c-decl-prefix-re (c-lang-const c-decl-prefix-re)
2333 'dont-doc)
2335 (c-lang-defconst c-decl-start-re
2336 "Regexp matching the start of any declaration, cast or label.
2337 It's used on the token after the one `c-decl-prefix-re' matched. This
2338 regexp should not try to match those constructs accurately as it's
2339 only used as a sieve to avoid spending more time checking other
2340 constructs."
2341 t (c-lang-const c-identifier-start))
2342 (c-lang-defvar c-decl-start-re (c-lang-const c-decl-start-re))
2344 (c-lang-defconst c-decl-prefix-or-start-re
2345 ;; Regexp matching something that might precede or start a
2346 ;; declaration, cast or label.
2348 ;; If the first submatch matches, it's taken to match the end of a
2349 ;; token that might precede such a construct, e.g. ';', '}' or '{'.
2350 ;; It's built from `c-decl-prefix-re'.
2352 ;; If the first submatch did not match, the match of the whole
2353 ;; regexp is taken to be at the first token in the declaration.
2354 ;; `c-decl-start-re' is not checked in this case.
2356 ;; Design note: The reason the same regexp is used to match both
2357 ;; tokens that precede declarations and start them is to avoid an
2358 ;; extra regexp search from the previous declaration spot in
2359 ;; `c-find-decl-spots'. Users of `c-find-decl-spots' also count on
2360 ;; that it finds all declaration/cast/label starts in approximately
2361 ;; linear order, so we can't do the searches in two separate passes.
2362 t (if (c-lang-const c-decl-start-kwds)
2363 (concat (c-lang-const c-decl-prefix-re)
2364 "\\|"
2365 (c-make-keywords-re t (c-lang-const c-decl-start-kwds)))
2366 (c-lang-const c-decl-prefix-re)))
2367 (c-lang-defvar c-decl-prefix-or-start-re
2368 (c-lang-const c-decl-prefix-or-start-re)
2369 'dont-doc)
2371 (c-lang-defconst c-cast-parens
2372 ;; List containing the paren characters that can open a cast, or nil in
2373 ;; languages without casts.
2374 t (c-filter-ops (c-lang-const c-operators)
2375 '(prefix)
2376 "\\`\\s\(\\'"
2377 (lambda (op) (elt op 0))))
2378 (c-lang-defvar c-cast-parens (c-lang-const c-cast-parens))
2380 (c-lang-defconst c-block-prefix-disallowed-chars
2381 "List of syntactically relevant characters that never can occur before
2382 the open brace in any construct that contains a brace block, e.g. in
2383 the \"class Foo: public Bar\" part of:
2385 class Foo: public Bar {int x();} a, *b;
2387 If parens can occur, the chars inside those aren't filtered with this
2388 list.
2390 '<' and '>' should be disallowed even if angle bracket arglists can
2391 occur. That since the search function needs to stop at them anyway to
2392 ensure they are given paren syntax.
2394 This is used to skip backward from the open brace to find the region
2395 in which to look for a construct like \"class\", \"enum\",
2396 \"namespace\" or whatever. That skipping should be as tight as
2397 possible for good performance."
2399 ;; Default to all chars that only occurs in nonsymbol tokens outside
2400 ;; identifiers.
2401 t (set-difference
2402 (c-lang-const c-nonsymbol-token-char-list)
2403 (c-filter-ops (append (c-lang-const c-identifier-ops)
2404 (list (cons nil
2405 (c-lang-const c-after-id-concat-ops))))
2408 (lambda (op)
2409 (let ((pos 0) res)
2410 (while (string-match "\\(\\s.\\|\\s(\\|\\s)\\)"
2411 op pos)
2412 (setq res (cons (aref op (match-beginning 1)) res)
2413 pos (match-end 0)))
2414 res))))
2416 ;; Allow cpp operatios (where applicable).
2417 t (if (c-lang-const c-opt-cpp-prefix)
2418 (set-difference (c-lang-const c-block-prefix-disallowed-chars)
2419 '(?#))
2420 (c-lang-const c-block-prefix-disallowed-chars))
2422 ;; Allow ':' for inherit list starters.
2423 (c++ objc idl) (set-difference (c-lang-const c-block-prefix-disallowed-chars)
2424 '(?:))
2426 ;; Allow ',' for multiple inherits.
2427 (c++ java) (set-difference (c-lang-const c-block-prefix-disallowed-chars)
2428 '(?,))
2430 ;; Allow parentheses for anonymous inner classes in Java and class
2431 ;; initializer lists in Pike.
2432 (java pike) (set-difference (c-lang-const c-block-prefix-disallowed-chars)
2433 '(?\( ?\)))
2435 ;; Allow '"' for extern clauses (e.g. extern "C" {...}).
2436 (c c++ objc) (set-difference (c-lang-const c-block-prefix-disallowed-chars)
2437 '(?\" ?')))
2439 (c-lang-defconst c-block-prefix-charset
2440 ;; `c-block-prefix-disallowed-chars' as an inverted charset suitable
2441 ;; for `c-syntactic-skip-backward'.
2442 t (c-make-bare-char-alt (c-lang-const c-block-prefix-disallowed-chars) t))
2443 (c-lang-defvar c-block-prefix-charset (c-lang-const c-block-prefix-charset))
2445 (c-lang-defconst c-type-decl-prefix-key
2446 "Regexp matching the declarator operators that might precede the
2447 identifier in a declaration, e.g. the \"*\" in \"char *argv\". This
2448 regexp should match \"(\" if parentheses are valid in declarators.
2449 The end of the first submatch is taken as the end of the operator.
2450 Identifier syntax is in effect when this is matched \(see
2451 `c-identifier-syntax-table')."
2452 t (if (c-lang-const c-type-modifier-kwds)
2453 (concat (regexp-opt (c-lang-const c-type-modifier-kwds) t) "\\>")
2454 ;; Default to a regexp that never matches.
2455 "\\<\\>")
2456 ;; Check that there's no "=" afterwards to avoid matching tokens
2457 ;; like "*=".
2458 (c objc) (concat "\\("
2459 "[*\(]"
2460 "\\|"
2461 (c-lang-const c-type-decl-prefix-key)
2462 "\\)"
2463 "\\([^=]\\|$\\)")
2464 c++ (concat "\\("
2465 "[*\(&]"
2466 "\\|"
2467 (concat "\\(" ; 2
2468 ;; If this matches there's special treatment in
2469 ;; `c-font-lock-declarators' and
2470 ;; `c-font-lock-declarations' that check for a
2471 ;; complete name followed by ":: *".
2472 (c-lang-const c-identifier-start)
2473 "\\)")
2474 "\\|"
2475 (c-lang-const c-type-decl-prefix-key)
2476 "\\)"
2477 "\\([^=]\\|$\\)")
2478 pike "\\(\\*\\)\\([^=]\\|$\\)")
2479 (c-lang-defvar c-type-decl-prefix-key (c-lang-const c-type-decl-prefix-key)
2480 'dont-doc)
2482 (c-lang-defconst c-type-decl-suffix-key
2483 "Regexp matching the declarator operators that might follow after the
2484 identifier in a declaration, e.g. the \"[\" in \"char argv[]\". This
2485 regexp should match \")\" if parentheses are valid in declarators. If
2486 it matches an open paren of some kind, the type declaration check
2487 continues at the corresponding close paren, otherwise the end of the
2488 first submatch is taken as the end of the operator. Identifier syntax
2489 is in effect when this is matched (see `c-identifier-syntax-table')."
2490 ;; Default to a regexp that matches `c-type-modifier-kwds' and a
2491 ;; function argument list parenthesis.
2492 t (if (c-lang-const c-type-modifier-kwds)
2493 (concat "\\(\(\\|"
2494 (regexp-opt (c-lang-const c-type-modifier-kwds) t) "\\>"
2495 "\\)")
2496 "\\(\(\\)")
2497 (c c++ objc) (concat
2498 "\\("
2499 "[\)\[\(]"
2500 (if (c-lang-const c-type-modifier-kwds)
2501 (concat
2502 "\\|"
2503 ;; "throw" in `c-type-modifier-kwds' is followed
2504 ;; by a parenthesis list, but no extra measures
2505 ;; are necessary to handle that.
2506 (regexp-opt (c-lang-const c-type-modifier-kwds) t)
2507 "\\>")
2509 "\\)")
2510 (java idl) "\\([\[\(]\\)")
2511 (c-lang-defvar c-type-decl-suffix-key (c-lang-const c-type-decl-suffix-key)
2512 'dont-doc)
2514 (c-lang-defconst c-after-suffixed-type-decl-key
2515 "This regexp is matched after a declarator expression where
2516 `c-type-decl-suffix-key' has matched. If it matches then the
2517 construct is taken as a declaration. It's typically used to match the
2518 beginning of a function body or whatever might occur after the
2519 function header in a function declaration or definition. It's
2520 undefined whether identifier syntax (see `c-identifier-syntax-table')
2521 is in effect or not.
2523 Note that it's used in cases like after \"foo (bar)\" so it should
2524 only match when it's certain that it's a declaration, e.g \"{\" but
2525 not \",\" or \";\"."
2526 t "{"
2527 ;; If K&R style declarations should be recognized then one could
2528 ;; consider to match the start of any symbol since we want to match
2529 ;; the start of the first declaration in the "K&R region". That
2530 ;; could however produce false matches on code like "FOO(bar) x"
2531 ;; where FOO is a cpp macro, so it's better to leave it out and rely
2532 ;; on the other heuristics in that case.
2533 t (if (c-lang-const c-postfix-spec-kwds)
2534 ;; Add on the keywords in `c-postfix-spec-kwds'.
2535 (concat (c-lang-const c-after-suffixed-type-decl-key)
2536 "\\|"
2537 (c-make-keywords-re t (c-lang-const c-postfix-spec-kwds)))
2538 (c-lang-const c-after-suffixed-type-decl-key))
2539 ;; Also match the colon that starts a base class initializer list in
2540 ;; C++. That can be confused with a function call before the colon
2541 ;; in a ? : operator, but we count on that `c-decl-prefix-re' won't
2542 ;; match before such a thing (as a declaration-level construct;
2543 ;; matches inside arglist contexts are already excluded).
2544 c++ "[{:]")
2545 (c-lang-defvar c-after-suffixed-type-decl-key
2546 (c-lang-const c-after-suffixed-type-decl-key)
2547 'dont-doc)
2549 (c-lang-defconst c-after-suffixed-type-maybe-decl-key
2550 ;; Regexp that in addition to `c-after-suffixed-type-decl-key'
2551 ;; matches ";" and ",".
2552 t (concat "\\(" (c-lang-const c-after-suffixed-type-decl-key) "\\)"
2553 "\\|[;,]"))
2554 (c-lang-defvar c-after-suffixed-type-maybe-decl-key
2555 (c-lang-const c-after-suffixed-type-maybe-decl-key))
2557 (c-lang-defconst c-opt-type-concat-key
2558 "Regexp matching operators that concatenate types, e.g. the \"|\" in
2559 \"int|string\" in Pike. The end of the first submatch is taken as the
2560 end of the operator. nil in languages without such operators. It's
2561 undefined whether identifier syntax (see `c-identifier-syntax-table')
2562 is in effect or not."
2563 t nil
2564 pike "\\([|.&]\\)\\($\\|[^|.&]\\)")
2565 (c-lang-defvar c-opt-type-concat-key (c-lang-const c-opt-type-concat-key)
2566 'dont-doc)
2568 (c-lang-defconst c-opt-type-suffix-key
2569 "Regexp matching operators that might follow after a type, or nil in
2570 languages that don't have such operators. The end of the first
2571 submatch is taken as the end of the operator. This should not match
2572 things like C++ template arglists if `c-recognize-<>-arglists' is set.
2573 It's undefined whether identifier syntax (see `c-identifier-syntax-table')
2574 is in effect or not."
2575 t nil
2576 (c c++ objc pike) "\\(\\.\\.\\.\\)"
2577 java (concat "\\(\\[" (c-lang-const c-simple-ws) "*\\]\\)"))
2578 (c-lang-defvar c-opt-type-suffix-key (c-lang-const c-opt-type-suffix-key))
2580 (c-lang-defvar c-known-type-key
2581 ;; Regexp matching the known type identifiers. This is initialized
2582 ;; from the type keywords and `*-font-lock-extra-types'. The first
2583 ;; submatch is the one that matches the type. Note that this regexp
2584 ;; assumes that symbol constituents like '_' and '$' have word
2585 ;; syntax.
2586 (let* ((extra-types
2587 (when (boundp (c-mode-symbol "font-lock-extra-types"))
2588 (c-mode-var "font-lock-extra-types")))
2589 (regexp-strings
2590 (apply 'nconc
2591 (mapcar (lambda (re)
2592 (when (string-match "[][.*+?^$\\]" re)
2593 (list re)))
2594 extra-types)))
2595 (plain-strings
2596 (apply 'nconc
2597 (mapcar (lambda (re)
2598 (unless (string-match "[][.*+?^$\\]" re)
2599 (list re)))
2600 extra-types))))
2601 (concat "\\<\\("
2602 (c-concat-separated
2603 (append (list (c-make-keywords-re nil
2604 (append (c-lang-const c-primitive-type-kwds)
2605 plain-strings)))
2606 regexp-strings)
2607 "\\|")
2608 "\\)\\>")))
2610 (c-lang-defconst c-special-brace-lists
2611 "List of open- and close-chars that makes up a pike-style brace list,
2612 i.e. for a ([ ]) list there should be a cons (?\\[ . ?\\]) in this
2613 list."
2614 t nil
2615 pike '((?{ . ?}) (?\[ . ?\]) (?< . ?>)))
2616 (c-lang-defvar c-special-brace-lists (c-lang-const c-special-brace-lists))
2618 (c-lang-defconst c-recognize-knr-p
2619 "Non-nil means K&R style argument declarations are valid."
2620 t nil
2621 c t)
2622 (c-lang-defvar c-recognize-knr-p (c-lang-const c-recognize-knr-p))
2624 (c-lang-defconst c-recognize-typeless-decls
2625 "Non-nil means function declarations without return type should be
2626 recognized. That can introduce an ambiguity with parenthesized macro
2627 calls before a brace block. This setting does not affect declarations
2628 that are preceded by a declaration starting keyword, so
2629 e.g. `c-typeless-decl-kwds' may still be used when it's set to nil."
2630 t nil
2631 (c c++ objc) t)
2632 (c-lang-defvar c-recognize-typeless-decls
2633 (c-lang-const c-recognize-typeless-decls))
2635 (c-lang-defconst c-recognize-<>-arglists
2636 "Non-nil means C++ style template arglists should be handled. More
2637 specifically, this means a comma separated list of types or
2638 expressions surrounded by \"<\" and \">\". It's always preceded by an
2639 identifier or one of the keywords on `c-<>-type-kwds' or
2640 `c-<>-arglist-kwds'. If there's an identifier before then the whole
2641 expression is considered to be a type."
2642 t (or (consp (c-lang-const c-<>-type-kwds))
2643 (consp (c-lang-const c-<>-arglist-kwds))))
2644 (c-lang-defvar c-recognize-<>-arglists (c-lang-const c-recognize-<>-arglists))
2646 (c-lang-defconst c-recognize-paren-inits
2647 "Non-nil means that parenthesis style initializers exist,
2648 i.e. constructs like
2650 Foo bar (gnu);
2652 in addition to the more classic
2654 Foo bar = gnu;"
2655 t nil
2656 c++ t)
2657 (c-lang-defvar c-recognize-paren-inits (c-lang-const c-recognize-paren-inits))
2659 (c-lang-defconst c-recognize-paren-inexpr-blocks
2660 "Non-nil to recognize gcc style in-expression blocks,
2661 i.e. compound statements surrounded by parentheses inside expressions."
2662 t nil
2663 (c c++) t)
2664 (c-lang-defvar c-recognize-paren-inexpr-blocks
2665 (c-lang-const c-recognize-paren-inexpr-blocks))
2667 (c-lang-defconst c-opt-<>-arglist-start
2668 ;; Regexp matching the start of angle bracket arglists in languages
2669 ;; where `c-recognize-<>-arglists' is set. Does not exclude
2670 ;; keywords outside `c-<>-arglist-kwds'. The first submatch is
2671 ;; assumed to surround the preceding symbol. The whole match is
2672 ;; assumed to end directly after the opening "<".
2673 t (if (c-lang-const c-recognize-<>-arglists)
2674 (concat "\\("
2675 (c-lang-const c-symbol-key)
2676 "\\)"
2677 (c-lang-const c-syntactic-ws)
2678 "<")))
2679 (c-lang-defvar c-opt-<>-arglist-start (c-lang-const c-opt-<>-arglist-start))
2681 (c-lang-defconst c-opt-<>-arglist-start-in-paren
2682 ;; Regexp that in addition to `c-opt-<>-arglist-start' matches close
2683 ;; parens. The first submatch is assumed to surround
2684 ;; `c-opt-<>-arglist-start'.
2685 t (if (c-lang-const c-opt-<>-arglist-start)
2686 (concat "\\("
2687 (c-lang-const c-opt-<>-arglist-start)
2688 "\\)\\|\\s\)")))
2689 (c-lang-defvar c-opt-<>-arglist-start-in-paren
2690 (c-lang-const c-opt-<>-arglist-start-in-paren))
2692 (c-lang-defconst c-opt-postfix-decl-spec-key
2693 ;; Regexp matching the beginning of a declaration specifier in the
2694 ;; region between the header and the body of a declaration.
2696 ;; TODO: This is currently not used uniformly; c++-mode and
2697 ;; java-mode each have their own ways of using it.
2698 t nil
2699 c++ (concat ":?"
2700 (c-lang-const c-simple-ws) "*"
2701 "\\(virtual" (c-lang-const c-simple-ws) "+\\)?\\("
2702 (c-make-keywords-re nil (c-lang-const c-protection-kwds))
2703 "\\)" (c-lang-const c-simple-ws) "+"
2704 "\\(" (c-lang-const c-symbol-key) "\\)")
2705 java (c-make-keywords-re t (c-lang-const c-postfix-spec-kwds)))
2706 (c-lang-defvar c-opt-postfix-decl-spec-key
2707 (c-lang-const c-opt-postfix-decl-spec-key))
2709 (c-lang-defconst c-recognize-colon-labels
2710 "Non-nil if generic labels ending with \":\" should be recognized.
2711 That includes labels in code and access keys in classes. This does
2712 not apply to labels recognized by `c-label-kwds' and
2713 `c-opt-extra-label-key'."
2714 t nil
2715 (c c++ objc java pike) t)
2716 (c-lang-defvar c-recognize-colon-labels
2717 (c-lang-const c-recognize-colon-labels))
2719 (c-lang-defconst c-label-prefix-re
2720 "Regexp like `c-decl-prefix-re' that matches any token that can precede
2721 a generic colon label. Not used if `c-recognize-colon-labels' is
2722 nil."
2723 t "\\([{};]+\\)")
2724 (c-lang-defvar c-label-prefix-re
2725 (c-lang-const c-label-prefix-re))
2727 (c-lang-defconst c-nonlabel-token-key
2728 "Regexp matching things that can't occur in generic colon labels,
2729 neither in a statement nor in a declaration context. The regexp is
2730 tested at the beginning of every sexp in a suspected label,
2731 i.e. before \":\". Only used if `c-recognize-colon-labels' is set."
2732 t (concat
2733 ;; Don't allow string literals.
2734 "[\"']\\|"
2735 ;; All keywords except `c-label-kwds' and `c-protection-kwds'.
2736 (c-make-keywords-re t
2737 (set-difference (c-lang-const c-keywords)
2738 (append (c-lang-const c-label-kwds)
2739 (c-lang-const c-protection-kwds))
2740 :test 'string-equal)))
2741 ;; Also check for open parens in C++, to catch member init lists in
2742 ;; constructors. We normally allow it so that macros with arguments
2743 ;; work in labels.
2744 c++ (concat "\\s\(\\|" (c-lang-const c-nonlabel-token-key)))
2745 (c-lang-defvar c-nonlabel-token-key (c-lang-const c-nonlabel-token-key))
2747 (c-lang-defconst c-opt-extra-label-key
2748 "Optional regexp matching labels.
2749 Normally, labels are detected according to `c-nonlabel-token-key',
2750 `c-decl-prefix-re' and `c-nonlabel-decl-prefix-re'. This regexp can
2751 be used if there are additional labels that aren't recognized that
2752 way."
2753 t nil
2754 objc (c-make-keywords-re t (c-lang-const c-protection-kwds)))
2755 (c-lang-defvar c-opt-extra-label-key (c-lang-const c-opt-extra-label-key))
2757 (c-lang-defconst c-opt-friend-key
2758 ;; Regexp describing friend declarations classes, or nil in
2759 ;; languages that don't have such things.
2761 ;; TODO: Ought to use `c-prefix-spec-kwds-re' or similar, and the
2762 ;; template skipping isn't done properly. This will disappear soon.
2763 t nil
2764 c++ (concat "friend" (c-lang-const c-simple-ws) "+"
2765 "\\|"
2766 (concat "template"
2767 (c-lang-const c-simple-ws) "*"
2768 "<.+>"
2769 (c-lang-const c-simple-ws) "*"
2770 "friend"
2771 (c-lang-const c-simple-ws) "+")))
2772 (c-lang-defvar c-opt-friend-key (c-lang-const c-opt-friend-key))
2774 (c-lang-defconst c-opt-method-key
2775 ;; Special regexp to match the start of Objective-C methods. The
2776 ;; first submatch is assumed to end after the + or - key.
2777 t nil
2778 objc (concat
2779 ;; TODO: Ought to use a better method than anchoring on bol.
2780 "^\\s *"
2781 "\\([+-]\\)"
2782 (c-lang-const c-simple-ws) "*"
2783 (concat "\\(" ; Return type.
2784 "([^\)]*)"
2785 (c-lang-const c-simple-ws) "*"
2786 "\\)?")
2787 "\\(" (c-lang-const c-symbol-key) "\\)"))
2788 (c-lang-defvar c-opt-method-key (c-lang-const c-opt-method-key))
2790 (c-lang-defconst c-type-decl-end-used
2791 ;; Must be set in buffers where the `c-type' text property might be
2792 ;; used with the value `c-decl-end'.
2794 ;; `c-decl-end' is used to mark the ends of labels and access keys
2795 ;; to make interactive refontification work better.
2796 t (or (c-lang-const c-recognize-colon-labels)
2797 (and (c-lang-const c-label-kwds) t))
2798 ;; `c-decl-end' is used to mark the end of the @-style directives in
2799 ;; Objective-C.
2800 objc t)
2801 (c-lang-defvar c-type-decl-end-used (c-lang-const c-type-decl-end-used))
2804 ;;; Wrap up the `c-lang-defvar' system.
2806 ;; Compile in the list of language variables that has been collected
2807 ;; with the `c-lang-defvar' macro. Note that the first element is
2808 ;; nil.
2809 (defconst c-lang-variable-inits (cc-eval-when-compile c-lang-variable-inits))
2811 (defun c-make-init-lang-vars-fun (mode)
2812 "Create a function that initializes all the language dependent variables
2813 for the given mode.
2815 This function should be evaluated at compile time, so that the
2816 function it returns is byte compiled with all the evaluated results
2817 from the language constants. Use the `c-init-language-vars' macro to
2818 accomplish that conveniently."
2820 (if (and (not load-in-progress)
2821 (boundp 'byte-compile-dest-file)
2822 (stringp byte-compile-dest-file))
2824 ;; No need to byte compile this lambda since the byte compiler is
2825 ;; smart enough to detect the `funcall' construct in the
2826 ;; `c-init-language-vars' macro below and compile it all straight
2827 ;; into the function that contains `c-init-language-vars'.
2828 `(lambda ()
2830 ;; This let sets up the context for `c-mode-var' and similar
2831 ;; that could be in the result from `cl-macroexpand-all'.
2832 (let ((c-buffer-is-cc-mode ',mode)
2833 current-var source-eval)
2834 (condition-case err
2836 (if (eq c-version-sym ',c-version-sym)
2837 (setq ,@(let ((c-buffer-is-cc-mode mode)
2838 (c-lang-const-expansion 'immediate))
2839 ;; `c-lang-const' will expand to the evaluated
2840 ;; constant immediately in `cl-macroexpand-all'
2841 ;; below.
2842 (mapcan
2843 (lambda (init)
2844 `(current-var ',(car init)
2845 ,(car init) ,(cl-macroexpand-all
2846 (elt init 1))))
2847 (cdr c-lang-variable-inits))))
2849 ;; This diagnostic message isn't useful for end
2850 ;; users, so it's disabled.
2851 ;;(unless (get ',mode 'c-has-warned-lang-consts)
2852 ;; (message ,(concat "%s compiled with CC Mode %s "
2853 ;; "but loaded with %s - evaluating "
2854 ;; "language constants from source")
2855 ;; ',mode ,c-version c-version)
2856 ;; (put ',mode 'c-has-warned-lang-consts t))
2858 (require 'cc-langs)
2859 (setq source-eval t)
2860 (let ((init (cdr c-lang-variable-inits)))
2861 (while init
2862 (setq current-var (caar init))
2863 (set (caar init) (eval (cadar init)))
2864 (setq init (cdr init)))))
2866 (error
2867 (if current-var
2868 (message "Eval error in the `c-lang-defvar' for `%s'%s: %S"
2869 current-var
2870 (if source-eval
2871 (format "\
2872 (fallback source eval - %s compiled with CC Mode %s but loaded with %s)"
2873 ',mode ,c-version c-version)
2875 err)
2876 (signal (car err) (cdr err)))))))
2878 ;; Being evaluated from source. Always use the dynamic method to
2879 ;; work well when `c-lang-defvar's in this file are reevaluated
2880 ;; interactively.
2881 `(lambda ()
2882 (require 'cc-langs)
2883 (let ((c-buffer-is-cc-mode ',mode)
2884 (init (cdr c-lang-variable-inits))
2885 current-var)
2886 (condition-case err
2888 (while init
2889 (setq current-var (caar init))
2890 (set (caar init) (eval (cadar init)))
2891 (setq init (cdr init)))
2893 (error
2894 (if current-var
2895 (message
2896 "Eval error in the `c-lang-defvar' for `%s' (source eval): %S"
2897 current-var err)
2898 (signal (car err) (cdr err)))))))
2901 (defmacro c-init-language-vars (mode)
2902 "Initialize all the language dependent variables for the given mode.
2903 This macro is expanded at compile time to a form tailored for the mode
2904 in question, so MODE must be a constant. Therefore MODE is not
2905 evaluated and should not be quoted."
2906 `(funcall ,(c-make-init-lang-vars-fun mode)))
2909 (cc-provide 'cc-langs)
2911 ;;; arch-tag: 1ab57482-cfc2-4c5b-b628-3539c3098822
2912 ;;; cc-langs.el ends here