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