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