]> code.delx.au - gnu-emacs/blob - lisp/progmodes/cc-langs.el
Handle initial comments.
[gnu-emacs] / lisp / progmodes / cc-langs.el
1 ;;; cc-langs.el --- language specific settings for CC Mode
2
3 ;; Copyright (C) 1985,1987,1992-2003 Free Software Foundation, Inc.
4
5 ;; Authors: 1998- Martin Stjernholm
6 ;; 1992-1999 Barry A. Warsaw
7 ;; 1987 Dave Detlefs and Stewart Clamen
8 ;; 1985 Richard M. Stallman
9 ;; Maintainer: bug-cc-mode@gnu.org
10 ;; Created: 22-Apr-1997 (split from cc-mode.el)
11 ;; Version: See cc-mode.el
12 ;; Keywords: c languages oop
13
14 ;; This file is part of GNU Emacs.
15
16 ;; GNU Emacs is free software; you can redistribute it and/or modify
17 ;; it under the terms of the GNU General Public License as published by
18 ;; the Free Software Foundation; either version 2, or (at your option)
19 ;; any later version.
20
21 ;; GNU Emacs is distributed in the hope that it will be useful,
22 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
23 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 ;; GNU General Public License for more details.
25
26 ;; You should have received a copy of the GNU General Public License
27 ;; along with GNU Emacs; see the file COPYING. If not, write to
28 ;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
29 ;; Boston, MA 02111-1307, USA.
30
31 ;;; Commentary:
32
33 ;; HACKERS NOTE: There's heavy macro magic here. If you need to make
34 ;; changes in this or other files containing `c-lang-defconst' but
35 ;; don't want to read through the longer discussion below then read
36 ;; this:
37 ;;
38 ;; o A change in a `c-lang-defconst' or `c-lang-defvar' will not take
39 ;; effect if the file containing the mode init function (typically
40 ;; cc-mode.el) is byte compiled.
41 ;; o To make changes show in font locking you need to reevaluate the
42 ;; `*-font-lock-keywords-*' constants, which normally is easiest to
43 ;; do with M-x eval-buffer in cc-fonts.el.
44 ;; o In either case it's necessary to reinitialize the mode to make
45 ;; the changes show in an existing buffer.
46
47 ;;; Introduction to the language dependent variable system:
48 ;;
49 ;; This file contains all the language dependent variables, except
50 ;; those specific for font locking which reside in cc-fonts.el. As
51 ;; far as possible, all the differences between the languages that CC
52 ;; Mode supports are described with these variables only, so that the
53 ;; code can be shared.
54 ;;
55 ;; The language constant system (see cc-defs.el) is used to specify
56 ;; various language dependent info at a high level, such as lists of
57 ;; keywords, and then from them generate - at compile time - the
58 ;; various regexps and other low-level structures actually employed in
59 ;; the code at runtime.
60 ;;
61 ;; This system is also designed to make it easy for developers of
62 ;; derived modes to customize the source constants for new language
63 ;; variants, without having to keep up with the exact regexps etc that
64 ;; are used in each CC Mode version. It's possible from an external
65 ;; package to add a new language by inheriting an existing one, and
66 ;; then change specific constants as necessary for the new language.
67 ;; The old values for those constants (and the values of all the other
68 ;; high-level constants) may be used to build the new ones, and those
69 ;; new values will in turn be used by the low-level definitions here
70 ;; to build the runtime constants appropriately for the new language
71 ;; in the current version of CC Mode.
72 ;;
73 ;; Like elsewhere in CC Mode, the existence of a doc string signifies
74 ;; that a language constant is part of the external API, and that it
75 ;; therefore can be used with a high confidence that it will continue
76 ;; to work with future versions of CC Mode. Even so, it's not
77 ;; unlikely that such constants will change meaning slightly as this
78 ;; system is refined further; a certain degree of dependence on the CC
79 ;; Mode version is unavoidable when hooking in at this level. Also
80 ;; note that there's still work to be done to actually use these
81 ;; constants everywhere inside CC Mode; there are still hardcoded
82 ;; values in many places in the code.
83 ;;
84 ;; Separate packages will also benefit from the compile time
85 ;; evaluation; the byte compiled file(s) for them will contain the
86 ;; compiled runtime constants ready for use by (the byte compiled) CC
87 ;; Mode, and the source definitions in this file don't have to be
88 ;; loaded then. However, if a byte compiled package is loaded that
89 ;; has been compiled with a different version of CC Mode than the one
90 ;; currently loaded, then the compiled-in values will be discarded and
91 ;; new ones will be built when the mode is initialized. That will
92 ;; automatically trig a load of the file(s) containing the source
93 ;; definitions (i.e. this file and/or cc-fonts.el) if necessary.
94 ;;
95 ;; A small example of a derived mode is available at
96 ;; <http://cc-mode.sourceforge.net/derived-mode-ex.el>. It also
97 ;; contains some useful hints for derived mode developers.
98
99 ;;; Using language variables:
100 ;;
101 ;; The `c-lang-defvar' forms in this file comprise the language
102 ;; variables that CC Mode uses. It does not work to use
103 ;; `c-lang-defvar' anywhere else (which isn't much of a limitation
104 ;; since these variables sole purpose is to interface with the CC Mode
105 ;; core functions). The values in these `c-lang-defvar's are not
106 ;; evaluated right away but instead collected to a single large `setq'
107 ;; that can be inserted for a particular language with the
108 ;; `c-init-language-vars' macro.
109
110 ;; This file is only required at compile time, or when not running
111 ;; from byte compiled files, or when the source definitions for the
112 ;; language constants are requested.
113
114 ;;; Code:
115
116 (eval-when-compile
117 (let ((load-path
118 (if (and (boundp 'byte-compile-dest-file)
119 (stringp byte-compile-dest-file))
120 (cons (file-name-directory byte-compile-dest-file) load-path)
121 load-path)))
122 (load "cc-bytecomp" nil t)))
123
124 (cc-require 'cc-defs)
125 (cc-require 'cc-vars)
126
127 \f
128 ;;; Setup for the `c-lang-defvar' system.
129
130 (eval-and-compile
131 ;; These are used to collect the init forms from the subsequent
132 ;; `c-lang-defvar'. They are used to build the lambda in
133 ;; `c-make-init-lang-vars-fun' below.
134 (defvar c-lang-variable-inits nil)
135 (defvar c-lang-variable-inits-tail nil)
136 (setq c-lang-variable-inits (list nil)
137 c-lang-variable-inits-tail c-lang-variable-inits))
138
139 (defmacro c-lang-defvar (var val &optional doc)
140 "Declares the buffer local variable VAR to get the value VAL at mode
141 initialization, at which point VAL is evaluated. More accurately, VAL
142 is evaluated and bound to VAR when the result from the macro
143 `c-init-language-vars' is evaluated.
144
145 `c-lang-const' is typically used in VAL to get the right value for the
146 language being initialized, and such calls will be macro expanded to
147 the evaluated constant value at compile time.
148
149 This macro does not do any hidden buffer changes."
150
151 (when (and (not doc)
152 (eq (car-safe val) 'c-lang-const)
153 (eq (nth 1 val) var)
154 (not (nth 2 val)))
155 ;; Special case: If there's no docstring and the value is a
156 ;; simple (c-lang-const foo) where foo is the same name as VAR
157 ;; then take the docstring from the language constant foo.
158 (setq doc (get (intern (symbol-name (nth 1 val)) c-lang-constants)
159 'variable-documentation)))
160 (or (stringp doc)
161 (setq doc nil))
162
163 (let ((elem (assq var (cdr c-lang-variable-inits))))
164 (if elem
165 (setcdr elem (list val doc))
166 (setcdr c-lang-variable-inits-tail (list (list var val doc)))
167 (setq c-lang-variable-inits-tail (cdr c-lang-variable-inits-tail))))
168
169 ;; Return the symbol, like the other def* forms.
170 `',var)
171
172 (put 'c-lang-defvar 'lisp-indent-function 'defun)
173 (eval-after-load "edebug"
174 '(def-edebug-spec c-lang-defvar
175 (&define name def-form &optional stringp)))
176
177 \f
178 ;;; Various mode specific values that aren't language related.
179
180 (c-lang-defconst c-mode-menu
181 ;; The definition for the mode menu. The menu title is prepended to
182 ;; this before it's fed to `easy-menu-define'.
183 t `(["Comment Out Region" comment-region
184 (c-fn-region-is-active-p)]
185 ["Uncomment Region" (comment-region (region-beginning)
186 (region-end) '(4))
187 (c-fn-region-is-active-p)]
188 ["Indent Expression" c-indent-exp
189 (memq (char-after) '(?\( ?\[ ?\{))]
190 ["Indent Line or Region" c-indent-line-or-region t]
191 ["Fill Comment Paragraph" c-fill-paragraph t]
192 "----"
193 ["Backward Statement" c-beginning-of-statement t]
194 ["Forward Statement" c-end-of-statement t]
195 ,@(when (c-lang-const c-opt-cpp-prefix)
196 ;; Only applicable if there's a cpp preprocessor.
197 `(["Up Conditional" c-up-conditional t]
198 ["Backward Conditional" c-backward-conditional t]
199 ["Forward Conditional" c-forward-conditional t]
200 "----"
201 ["Macro Expand Region" c-macro-expand
202 (c-fn-region-is-active-p)]
203 ["Backslashify" c-backslash-region
204 (c-fn-region-is-active-p)]))
205 "----"
206 ("Toggle..."
207 ["Syntactic indentation" c-toggle-syntactic-indentation t]
208 ["Auto newline" c-toggle-auto-state t]
209 ["Hungry delete" c-toggle-hungry-state t])))
210
211 \f
212 ;;; Syntax tables.
213
214 (defun c-populate-syntax-table (table)
215 "Populate the given syntax table as necessary for a C-like language.
216 This includes setting ' and \" as string delimiters, and setting up
217 the comment syntax to handle both line style \"//\" and block style
218 \"/*\" \"*/\" comments."
219
220 (modify-syntax-entry ?_ "_" table)
221 (modify-syntax-entry ?\\ "\\" table)
222 (modify-syntax-entry ?+ "." table)
223 (modify-syntax-entry ?- "." table)
224 (modify-syntax-entry ?= "." table)
225 (modify-syntax-entry ?% "." table)
226 (modify-syntax-entry ?< "." table)
227 (modify-syntax-entry ?> "." table)
228 (modify-syntax-entry ?& "." table)
229 (modify-syntax-entry ?| "." table)
230 (modify-syntax-entry ?\' "\"" table)
231 (modify-syntax-entry ?\240 "." table)
232
233 ;; Set up block and line oriented comments. The new C
234 ;; standard mandates both comment styles even in C, so since
235 ;; all languages now require dual comments, we make this the
236 ;; default.
237 (cond
238 ;; XEmacs
239 ((memq '8-bit c-emacs-features)
240 (modify-syntax-entry ?/ ". 1456" table)
241 (modify-syntax-entry ?* ". 23" table))
242 ;; Emacs
243 ((memq '1-bit c-emacs-features)
244 (modify-syntax-entry ?/ ". 124b" table)
245 (modify-syntax-entry ?* ". 23" table))
246 ;; incompatible
247 (t (error "CC Mode is incompatible with this version of Emacs")))
248
249 (modify-syntax-entry ?\n "> b" table)
250 ;; Give CR the same syntax as newline, for selective-display
251 (modify-syntax-entry ?\^m "> b" table))
252
253 (c-lang-defconst c-make-mode-syntax-table
254 "Functions that generates the mode specific syntax tables.
255 The syntax tables aren't stored directly since they're quite large."
256 t `(lambda ()
257 (let ((table (make-syntax-table)))
258 (c-populate-syntax-table table)
259 ;; Mode specific syntaxes.
260 ,(cond ((c-major-mode-is 'objc-mode)
261 `(modify-syntax-entry ?@ "_" table))
262 ((c-major-mode-is 'pike-mode)
263 `(modify-syntax-entry ?@ "." table)))
264 table)))
265
266 (c-lang-defconst c-mode-syntax-table
267 ;; The syntax tables in evaluated form. Only used temporarily when
268 ;; the constants in this file are evaluated.
269 t (funcall (c-lang-const c-make-mode-syntax-table)))
270
271 (c-lang-defconst c++-make-template-syntax-table
272 ;; A variant of `c++-mode-syntax-table' that defines `<' and `>' as
273 ;; parenthesis characters. Used temporarily when template argument
274 ;; lists are parsed. Note that this encourages incorrect parsing of
275 ;; templates since they might contain normal operators that uses the
276 ;; '<' and '>' characters. Therefore this syntax table might go
277 ;; away when CC Mode handles templates correctly everywhere.
278 t nil
279 c++ `(lambda ()
280 (let ((table (funcall ,(c-lang-const c-make-mode-syntax-table))))
281 (modify-syntax-entry ?< "(>" table)
282 (modify-syntax-entry ?> ")<" table)
283 table)))
284 (c-lang-defvar c++-template-syntax-table
285 (and (c-lang-const c++-make-template-syntax-table)
286 (funcall (c-lang-const c++-make-template-syntax-table))))
287
288 (c-lang-defconst c-identifier-syntax-modifications
289 "A list that describes the modifications that should be done to the
290 mode syntax table to get a syntax table that matches all identifiers
291 and keywords as words.
292
293 The list is just like the one used in `font-lock-defaults': Each
294 element is a cons where the car is the character to modify and the cdr
295 the new syntax, as accepted by `modify-syntax-entry'."
296 ;; The $ character is not allowed in most languages (one exception
297 ;; is Java which allows it for legacy reasons) but we still classify
298 ;; it as an indentifier character since it's often used in various
299 ;; machine generated identifiers.
300 t '((?_ . "w") (?$ . "w"))
301 objc (append '((?@ . "w"))
302 (c-lang-const c-identifier-syntax-modifications))
303 awk '((?_ . "w")))
304 (c-lang-defvar c-identifier-syntax-modifications
305 (c-lang-const c-identifier-syntax-modifications))
306
307 (c-lang-defvar c-identifier-syntax-table
308 (let ((table (copy-syntax-table (c-mode-var "mode-syntax-table")))
309 (mods c-identifier-syntax-modifications)
310 mod)
311 (while mods
312 (setq mod (car mods)
313 mods (cdr mods))
314 (modify-syntax-entry (car mod) (cdr mod) table))
315 table)
316 "Syntax table built on the mode syntax table but additionally
317 classifies symbol constituents like '_' and '$' as word constituents,
318 so that all identifiers are recognized as words.")
319
320 \f
321 ;;; Lexer-level syntax (identifiers, tokens etc).
322
323 (c-lang-defconst c-symbol-start
324 "Regexp that matches the start of a symbol, i.e. any identifier or
325 keyword. It's unspecified how far it matches. Does not contain a \\|
326 operator at the top level."
327 t (concat "[" c-alpha "_]")
328 pike (concat "[" c-alpha "_`]"))
329 (c-lang-defvar c-symbol-start (c-lang-const c-symbol-start))
330
331 (c-lang-defconst c-symbol-chars
332 "Set of characters that can be part of a symbol.
333 This is on the form that fits inside [ ] in a regexp."
334 ;; Pike note: With the backquote identifiers this would include most
335 ;; operator chars too, but they are handled with other means instead.
336 t (concat c-alnum "_$")
337 objc (concat c-alnum "_$@"))
338
339 (c-lang-defconst c-symbol-key
340 "Regexp matching identifiers and keywords. Assumed to match if
341 `c-symbol-start' matches on the same position."
342 t (concat (c-lang-const c-symbol-start)
343 "[" (c-lang-const c-symbol-chars) "]*")
344 pike (concat
345 ;; Use the value from C here since the operator backquote is
346 ;; covered by the other alternative.
347 (c-lang-const c-symbol-key c)
348 "\\|"
349 (c-make-keywords-re nil
350 (c-lang-const c-overloadable-operators))))
351 (c-lang-defvar c-symbol-key (c-lang-const c-symbol-key))
352
353 (c-lang-defconst c-symbol-key-depth
354 ;; Number of regexp grouping parens in `c-symbol-key'.
355 t (c-regexp-opt-depth (c-lang-const c-symbol-key)))
356
357 (c-lang-defconst c-nonsymbol-chars
358 "This is the set of chars that can't be part of a symbol, i.e. the
359 negation of `c-symbol-chars'."
360 t (concat "^" (c-lang-const c-symbol-chars)))
361 (c-lang-defvar c-nonsymbol-chars (c-lang-const c-nonsymbol-chars))
362
363 (c-lang-defconst c-nonsymbol-key
364 "Regexp that matches any character that can't be part of a symbol.
365 It's usually appended to other regexps to avoid matching a prefix.
366 It's assumed to not contain any submatchers."
367 ;; The same thing regarding Unicode identifiers applies here as to
368 ;; `c-symbol-key'.
369 t (concat "[" (c-lang-const c-nonsymbol-chars) "]"))
370
371 (c-lang-defconst c-opt-identifier-concat-key
372 "Regexp matching the operators that join symbols to fully qualified
373 identifiers, or nil in languages that don't have such things. Does
374 not contain a \\| operator at the top level."
375 t nil
376 c++ "::"
377 java "\\."
378 idl "::"
379 pike "\\(::\\|\\.\\)")
380 (c-lang-defvar c-opt-identifier-concat-key
381 (c-lang-const c-opt-identifier-concat-key)
382 'dont-doc)
383
384 (c-lang-defconst c-opt-after-id-concat-key
385 "Regexp that must match the token after `c-opt-identifier-concat-key'
386 for it to be considered an identifier concatenation operator (which
387 e.g. causes the preceding identifier to be fontified as a reference).
388 Assumed to be a string if `c-opt-identifier-concat-key' is."
389 t (if (c-lang-const c-opt-identifier-concat-key)
390 (c-lang-const c-symbol-start))
391 c++ (concat (c-lang-const c-symbol-start)
392 "\\|[~*]")
393 java (concat (c-lang-const c-symbol-start)
394 "\\|\\*"))
395
396 (c-lang-defconst c-identifier-start
397 "Regexp that matches the start of an \(optionally qualified)
398 identifier. It should also match all keywords. It's unspecified how
399 far it matches."
400 t (concat (c-lang-const c-symbol-start)
401 (if (c-lang-const c-opt-identifier-concat-key)
402 (concat "\\|" (c-lang-const c-opt-identifier-concat-key))
403 ""))
404 c++ (concat (c-lang-const c-identifier-start)
405 "\\|"
406 "[~*][ \t\n\r\f\v]*" (c-lang-const c-symbol-start))
407 ;; Java does not allow a leading qualifier operator.
408 java (c-lang-const c-symbol-start))
409 (c-lang-defvar c-identifier-start (c-lang-const c-identifier-start))
410
411 (c-lang-defconst c-identifier-key
412 "Regexp matching a fully qualified identifier, like \"A::B::c\" in
413 C++. It does not recognize the full range of syntactic whitespace
414 between the tokens; `c-forward-name' has to be used for that."
415 t (c-lang-const c-symbol-key) ; Default to `c-symbol-key'.
416 ;; C++ allows a leading qualifier operator and a `~' before the last
417 ;; symbol. This regexp is more complex than strictly necessary to
418 ;; ensure that it can be matched with a minimum of backtracking.
419 c++ (concat
420 "\\(" (c-lang-const c-opt-identifier-concat-key) "[ \t\n\r\f\v]*\\)?"
421 (concat
422 "\\("
423 ;; The submatch below is depth of `c-opt-identifier-concat-key' + 3.
424 "\\(" (c-lang-const c-symbol-key) "\\)"
425 (concat "\\("
426 "[ \t\n\r\f\v]*"
427 (c-lang-const c-opt-identifier-concat-key)
428 "[ \t\n\r\f\v]*"
429 ;; The submatch below is: `c-symbol-key-depth' +
430 ;; 2 * depth of `c-opt-identifier-concat-key' + 5.
431 "\\(" (c-lang-const c-symbol-key) "\\)"
432 "\\)*")
433 (concat "\\("
434 "[ \t\n\r\f\v]*"
435 (c-lang-const c-opt-identifier-concat-key)
436 "[ \t\n\r\f\v]*"
437 "[~*]"
438 "[ \t\n\r\f\v]*"
439 ;; The submatch below is: 2 * `c-symbol-key-depth' +
440 ;; 3 * depth of `c-opt-identifier-concat-key' + 7.
441 "\\(" (c-lang-const c-symbol-key) "\\)"
442 "\\)?")
443 "\\|"
444 "~[ \t\n\r\f\v]*"
445 ;; The submatch below is: 3 * `c-symbol-key-depth' +
446 ;; 3 * depth of `c-opt-identifier-concat-key' + 8.
447 "\\(" (c-lang-const c-symbol-key) "\\)"
448 "\\)"))
449 ;; IDL and Pike allows a leading qualifier operator.
450 (idl pike) (concat
451 "\\("
452 (c-lang-const c-opt-identifier-concat-key)
453 "[ \t\n\r\f\v]*"
454 "\\)?"
455 ;; The submatch below is depth of
456 ;; `c-opt-identifier-concat-key' + 2.
457 "\\(" (c-lang-const c-symbol-key) "\\)"
458 (concat "\\("
459 "[ \t\n\r\f\v]*"
460 (c-lang-const c-opt-identifier-concat-key)
461 "[ \t\n\r\f\v]*"
462 ;; The submatch below is: `c-symbol-key-depth' +
463 ;; 2 * depth of `c-opt-identifier-concat-key' + 4.
464 "\\(" (c-lang-const c-symbol-key) "\\)"
465 "\\)*"))
466 ;; Java does not allow a leading qualifier operator. If it ends
467 ;; with ".*" (used in import declarations) we also consider that as
468 ;; part of the name. ("*" is actually recognized in any position
469 ;; except the first by this regexp, but we don't bother.)
470 java (concat "\\(" (c-lang-const c-symbol-key) "\\)" ; 1
471 (concat "\\("
472 "[ \t\n\r\f\v]*"
473 (c-lang-const c-opt-identifier-concat-key)
474 "[ \t\n\r\f\v]*"
475 (concat "\\("
476 ;; The submatch below is `c-symbol-key-depth' +
477 ;; depth of `c-opt-identifier-concat-key' + 4.
478 "\\(" (c-lang-const c-symbol-key) "\\)"
479 "\\|\\*\\)")
480 "\\)*")))
481 (c-lang-defvar c-identifier-key (c-lang-const c-identifier-key))
482
483 (c-lang-defconst c-identifier-last-sym-match
484 "Used to identify the submatch in `c-identifier-key' that surrounds
485 the last symbol in the qualified identifier. It's a list of submatch
486 numbers, of which the first that has a match is taken. It's assumed
487 that at least one does when the regexp has matched."
488 t '(0)
489 c++ (list (+ (* 3 (c-lang-const c-symbol-key-depth))
490 (* 3 (c-regexp-opt-depth
491 (c-lang-const c-opt-identifier-concat-key)))
492 8)
493 (+ (* 2 (c-lang-const c-symbol-key-depth))
494 (* 3 (c-regexp-opt-depth
495 (c-lang-const c-opt-identifier-concat-key)))
496 7)
497 (+ (c-lang-const c-symbol-key-depth)
498 (* 2 (c-regexp-opt-depth
499 (c-lang-const c-opt-identifier-concat-key)))
500 5)
501 (+ (c-regexp-opt-depth
502 (c-lang-const c-opt-identifier-concat-key))
503 3))
504 (idl pike) (list (+ (c-lang-const c-symbol-key-depth)
505 (* 2 (c-regexp-opt-depth
506 (c-lang-const c-opt-identifier-concat-key)))
507 4)
508 (+ (c-regexp-opt-depth
509 (c-lang-const c-opt-identifier-concat-key))
510 2))
511 java (list (+ (c-lang-const c-symbol-key-depth)
512 (c-regexp-opt-depth
513 (c-lang-const c-opt-identifier-concat-key))
514 4)
515 1))
516 (c-lang-defvar c-identifier-last-sym-match
517 (c-lang-const c-identifier-last-sym-match)
518 'dont-doc)
519
520 (c-lang-defconst c-opt-cpp-prefix
521 "Regexp matching the prefix of a cpp directive in the languages that
522 normally use that macro preprocessor. Tested at bol or at boi.
523 Assumed to not contain any submatches or \\| operators."
524 t "\\s *#\\s *"
525 (java awk) nil)
526 (c-lang-defvar c-opt-cpp-prefix (c-lang-const c-opt-cpp-prefix))
527
528 (c-lang-defconst c-opt-cpp-start
529 "Regexp matching the prefix of a cpp directive including the directive
530 name, or nil in languages without preprocessor support. The first
531 submatch surrounds the directive name."
532 t (if (c-lang-const c-opt-cpp-prefix)
533 (concat (c-lang-const c-opt-cpp-prefix)
534 "\\([" c-alnum "]+\\)"))
535 ;; Pike, being a scripting language, recognizes hash-bangs too.
536 pike (concat (c-lang-const c-opt-cpp-prefix)
537 "\\([" c-alnum "]+\\|!\\)"))
538 (c-lang-defvar c-opt-cpp-start (c-lang-const c-opt-cpp-start))
539
540 (c-lang-defconst c-cpp-defined-fns
541 ;; Name of functions in cpp expressions that take an identifier as
542 ;; the argument.
543 t (if (c-lang-const c-opt-cpp-prefix)
544 '("defined"))
545 pike '("defined" "efun" "constant"))
546
547 (c-lang-defconst c-assignment-operators
548 "List of all assignment operators."
549 t '("=" "*=" "/=" "%=" "+=" "-=" ">>=" "<<=" "&=" "^=" "|=")
550 java (append (c-lang-const c-assignment-operators)
551 '(">>>="))
552 c++ (append (c-lang-const c-assignment-operators)
553 '("and_eq" "or_eq" "xor_eq"))
554 idl nil)
555
556 (c-lang-defconst c-operators
557 "List describing all operators, along with their precedence and
558 associativity. The order in the list corresponds to the precedence of
559 the operators: The operators in each element is a group with the same
560 precedence, and the group has higher precedence than the groups in all
561 following elements. The car of each element describes the type of of
562 the operator group, and the cdr is a list of the operator tokens in
563 it. The operator group types are:
564
565 'prefix Unary prefix operators.
566 'postfix Unary postfix operators.
567 'left-assoc Binary left associative operators (i.e. a+b+c means (a+b)+c).
568 'right-assoc Binary right associative operators (i.e. a=b=c means a=(b=c)).
569 'right-assoc-sequence
570 Right associative operator that constitutes of a
571 sequence of tokens that separate expressions. All the
572 tokens in the group are in this case taken as
573 describing the sequence in one such operator, and the
574 order between them is therefore significant.
575
576 Operators containing a character with paren syntax are taken to match
577 with a corresponding open/close paren somewhere else. A postfix
578 operator with close paren syntax is taken to end a postfix expression
579 started somewhere earlier, rather than start a new one at point. Vice
580 versa for prefix operators with open paren syntax.
581
582 Note that operators like \".\" and \"->\" which in language references
583 often are described as postfix operators are considered binary here,
584 since CC Mode treats every identifier as an expression."
585
586 ;; There's currently no code in CC Mode that exploit all the info
587 ;; in this variable; precedence, associativity etc are present as a
588 ;; preparation for future work.
589
590 t `(;; Preprocessor.
591 ,@(when (c-lang-const c-opt-cpp-prefix)
592 `((prefix "#"
593 ,@(when (c-major-mode-is '(c-mode c++-mode))
594 '("%:" "??=")))
595 (left-assoc "##"
596 ,@(when (c-major-mode-is '(c-mode c++-mode))
597 '("%:%:" "??=??=")))))
598
599 ;; Primary. Info duplicated in `c-opt-identifier-concat-key'
600 ;; and `c-identifier-key'.
601 ,@(cond ((c-major-mode-is 'c++-mode)
602 `((postfix-if-paren "<" ">") ; Templates.
603 (prefix "~" "??-" "compl")
604 (right-assoc "::")
605 (prefix "::")))
606 ((c-major-mode-is 'pike-mode)
607 `((left-assoc "::")
608 (prefix "::" "global" "predef")))
609 ((c-major-mode-is 'java-mode)
610 `(;; Not necessary since it's also in the postfix group below.
611 ;;(left-assoc ".")
612 (prefix "super"))))
613
614 ;; Postfix.
615 ,@(when (c-major-mode-is 'c++-mode)
616 ;; The following need special treatment.
617 `((prefix "dynamic_cast" "static_cast"
618 "reinterpret_cast" "const_cast" "typeid")))
619 (left-assoc "."
620 ,@(unless (c-major-mode-is 'java-mode)
621 '("->")))
622 (postfix "++" "--" "[" "]" "(" ")"
623 ,@(when (c-major-mode-is '(c-mode c++-mode))
624 '("<:" ":>" "??(" "??)")))
625
626 ;; Unary.
627 (prefix "++" "--" "+" "-" "!" "~"
628 ,@(when (c-major-mode-is 'c++-mode) '("not" "compl"))
629 ,@(when (c-major-mode-is '(c-mode c++-mode))
630 '("*" "&" "sizeof" "??-"))
631 ,@(when (c-major-mode-is 'objc-mode)
632 '("@selector" "@protocol" "@encode"))
633 ;; The following need special treatment.
634 ,@(cond ((c-major-mode-is 'c++-mode)
635 '("new" "delete"))
636 ((c-major-mode-is 'java-mode)
637 '("new"))
638 ((c-major-mode-is 'pike-mode)
639 '("class" "lambda" "catch" "throw" "gauge")))
640 "(" ")" ; Cast.
641 ,@(when (c-major-mode-is 'pike-mode)
642 '("[" "]"))) ; Type cast.
643
644 ;; Member selection.
645 ,@(when (c-major-mode-is 'c++-mode)
646 `((left-assoc ".*" "->*")))
647
648 ;; Multiplicative.
649 (left-assoc "*" "/" "%")
650
651 ;; Additive.
652 (left-assoc "+" "-")
653
654 ;; Shift.
655 (left-assoc "<<" ">>"
656 ,@(when (c-major-mode-is 'java-mode)
657 '(">>>")))
658
659 ;; Relational.
660 (left-assoc "<" ">" "<=" ">="
661 ,@(when (c-major-mode-is 'java-mode)
662 '("instanceof")))
663
664 ;; Equality.
665 (left-assoc "==" "!="
666 ,@(when (c-major-mode-is 'c++-mode) '("not_eq")))
667
668 ;; Bitwise and.
669 (left-assoc "&"
670 ,@(when (c-major-mode-is 'c++-mode) '("bitand")))
671
672 ;; Bitwise exclusive or.
673 (left-assoc "^"
674 ,@(when (c-major-mode-is '(c-mode c++-mode))
675 '("??'"))
676 ,@(when (c-major-mode-is 'c++-mode) '("xor")))
677
678 ;; Bitwise or.
679 (left-assoc "|"
680 ,@(when (c-major-mode-is '(c-mode c++-mode))
681 '("??!"))
682 ,@(when (c-major-mode-is 'c++-mode) '("bitor")))
683
684 ;; Logical and.
685 (left-assoc "&&"
686 ,@(when (c-major-mode-is 'c++-mode) '("and")))
687
688 ;; Logical or.
689 (left-assoc "||"
690 ,@(when (c-major-mode-is '(c-mode c++-mode))
691 '("??!??!"))
692 ,@(when (c-major-mode-is 'c++-mode) '("or")))
693
694 ;; Conditional.
695 (right-assoc-sequence "?" ":")
696
697 ;; Assignment.
698 (right-assoc ,@(c-lang-const c-assignment-operators))
699
700 ;; Exception.
701 ,@(when (c-major-mode-is 'c++-mode)
702 '((prefix "throw")))
703
704 ;; Sequence.
705 (left-assoc ","))
706
707 ;; IDL got its own definition since it has a much smaller operator
708 ;; set than the other languages.
709 idl `(;; Preprocessor.
710 (prefix "#")
711 (left-assoc "##")
712 ;; Primary. Info duplicated in `c-opt-identifier-concat-key'
713 ;; and `c-identifier-key'.
714 (left-assoc "::")
715 (prefix "::")
716 ;; Unary.
717 (prefix "+" "-" "~")
718 ;; Multiplicative.
719 (left-assoc "*" "/" "%")
720 ;; Additive.
721 (left-assoc "+" "-")
722 ;; Shift.
723 (left-assoc "<<" ">>")
724 ;; And.
725 (left-assoc "&")
726 ;; Xor.
727 (left-assoc "^")
728 ;; Or.
729 (left-assoc "|")))
730
731 (c-lang-defconst c-operator-list
732 ;; The operators as a flat list (without duplicates).
733 t (delete-duplicates (mapcan (lambda (elem) (append (cdr elem) nil))
734 (c-lang-const c-operators))
735 :test 'string-equal))
736
737 (c-lang-defconst c-overloadable-operators
738 "List of the operators that are overloadable, in their \"identifier form\"."
739 t nil
740 ;; The preceding "operator" keyword is treated separately in C++.
741 c++ '("new" "delete" ;; Can be followed by "[]" but we ignore that.
742 "+" "-" "*" "/" "%"
743 "^" "??'" "xor" "&" "bitand" "|" "??!" "bitor" "~" "??-" "compl"
744 "!" "=" "<" ">" "+=" "-=" "*=" "/=" "%=" "^="
745 "??'=" "xor_eq" "&=" "and_eq" "|=" "??!=" "or_eq"
746 "<<" ">>" ">>=" "<<=" "==" "!=" "not_eq" "<=" ">="
747 "&&" "and" "||" "??!??!" "or" "++" "--" "," "->*" "->"
748 "()" "[]" "<::>" "??(??)")
749 ;; These work like identifiers in Pike.
750 pike '("`+" "`-" "`&" "`|" "`^" "`<<" "`>>" "`*" "`/" "`%" "`~"
751 "`==" "`<" "`>" "`!" "`[]" "`[]=" "`->" "`->=" "`()" "``+"
752 "``-" "``&" "``|" "``^" "``<<" "``>>" "``*" "``/" "``%"
753 "`+="))
754
755 (c-lang-defconst c-overloadable-operators-regexp
756 ;; Regexp tested after an "operator" token in C++.
757 t nil
758 c++ (c-make-keywords-re nil (c-lang-const c-overloadable-operators)))
759 (c-lang-defvar c-overloadable-operators-regexp
760 (c-lang-const c-overloadable-operators-regexp))
761
762 (c-lang-defconst c-other-op-syntax-tokens
763 "List of the tokens made up of characters in the punctuation or
764 parenthesis syntax classes that have uses other than as expression
765 operators."
766 t '("{" "}" "(" ")" "[" "]" ";" ":" "," "=" "/*" "*/" "//")
767 (c c++ pike) (append '("#" "##" ; Used by cpp.
768 "::" "...")
769 (c-lang-const c-other-op-syntax-tokens))
770 (c c++) (append '("<%" "%>" "<:" ":>" "%:" "%:%:" "*")
771 (c-lang-const c-other-op-syntax-tokens))
772 c++ (append '("&") (c-lang-const c-other-op-syntax-tokens))
773 objc (append '("#" "##" ; Used by cpp.
774 "+" "-") (c-lang-const c-other-op-syntax-tokens))
775 idl (append '("#" "##") ; Used by cpp.
776 (c-lang-const c-other-op-syntax-tokens))
777 pike (append '("..")
778 (c-lang-const c-other-op-syntax-tokens)
779 (c-lang-const c-overloadable-operators))
780 awk '("{" "}" "(" ")" "[" "]" ";" "," "=" "/"))
781
782 (c-lang-defconst c-nonsymbol-token-regexp
783 ;; Regexp matching all tokens in the punctuation and parenthesis
784 ;; syntax classes. Note that this also matches ".", which can start
785 ;; a float.
786 t (c-make-keywords-re nil
787 (c-with-syntax-table (c-lang-const c-mode-syntax-table)
788 (mapcan (lambda (op)
789 (if (string-match "\\`\\(\\s.\\|\\s\(\\|\\s\)\\)+\\'" op)
790 (list op)))
791 (append (c-lang-const c-other-op-syntax-tokens)
792 (c-lang-const c-operator-list))))))
793 (c-lang-defvar c-nonsymbol-token-regexp
794 (c-lang-const c-nonsymbol-token-regexp))
795
796 (c-lang-defconst c-assignment-op-regexp
797 ;; Regexp matching all assignment operators and only them. The
798 ;; beginning of the first submatch is used to detect the end of the
799 ;; token, along with the end of the whole match.
800 t (if (c-lang-const c-assignment-operators)
801 (concat
802 ;; Need special case for "=" since it's a prefix of "==".
803 "=\\([^=]\\|$\\)"
804 "\\|"
805 (c-make-keywords-re nil
806 (set-difference (c-lang-const c-assignment-operators)
807 '("=")
808 :test 'string-equal)))
809 "\\<\\>"))
810 (c-lang-defvar c-assignment-op-regexp
811 (c-lang-const c-assignment-op-regexp))
812
813 (c-lang-defconst c-<-op-cont-regexp
814 ;; Regexp matching the second and subsequent characters of all
815 ;; multicharacter tokens that begin with "<".
816 t (c-make-keywords-re nil
817 (mapcan (lambda (op)
818 (if (string-match "\\`<." op)
819 (list (substring op 1))))
820 (append (c-lang-const c-other-op-syntax-tokens)
821 (c-lang-const c-operator-list)))))
822 (c-lang-defvar c-<-op-cont-regexp (c-lang-const c-<-op-cont-regexp))
823
824 (c-lang-defconst c->-op-cont-regexp
825 ;; Regexp matching the second and subsequent characters of all
826 ;; multicharacter tokens that begin with ">".
827 t (c-make-keywords-re nil
828 (mapcan (lambda (op)
829 (if (string-match "\\`>." op)
830 (list (substring op 1))))
831 (append (c-lang-const c-other-op-syntax-tokens)
832 (c-lang-const c-operator-list)))))
833 (c-lang-defvar c->-op-cont-regexp (c-lang-const c->-op-cont-regexp))
834
835 (c-lang-defconst c-stmt-delim-chars
836 ;; The characters that should be considered to bound statements. To
837 ;; optimize `c-crosses-statement-barrier-p' somewhat, it's assumed to
838 ;; begin with "^" to negate the set. If ? : operators should be
839 ;; detected then the string must end with "?:".
840 t "^;{}?:"
841 awk "^;{}\n\r?:") ; The newline chars gets special treatment.
842 (c-lang-defvar c-stmt-delim-chars (c-lang-const c-stmt-delim-chars))
843
844 (c-lang-defconst c-stmt-delim-chars-with-comma
845 ;; Variant of `c-stmt-delim-chars' that additionally contains ','.
846 t "^;,{}?:"
847 awk "^;,{}\n\r?:") ; The newline chars gets special treatment.
848 (c-lang-defvar c-stmt-delim-chars-with-comma
849 (c-lang-const c-stmt-delim-chars-with-comma))
850
851 \f
852 ;;; Syntactic whitespace.
853
854 (c-lang-defconst c-comment-start-regexp
855 ;; Regexp to match the start of any type of comment.
856 ;;
857 ;; TODO: Ought to use `c-comment-prefix-regexp' with some
858 ;; modifications instead of this.
859 t "/[/*]"
860 awk "#")
861 (c-lang-defvar c-comment-start-regexp (c-lang-const c-comment-start-regexp))
862
863 (c-lang-defconst c-literal-start-regexp
864 ;; Regexp to match the start of comments and string literals.
865 t (concat (c-lang-const c-comment-start-regexp)
866 "\\|"
867 (if (memq 'gen-string-delim c-emacs-features)
868 "\"|"
869 "\"")))
870 (c-lang-defvar c-literal-start-regexp (c-lang-const c-literal-start-regexp))
871
872 (c-lang-defconst c-doc-comment-start-regexp
873 "Regexp to match the start of documentation comments."
874 t "\\<\\>"
875 ;; From font-lock.el: `doxygen' uses /*! while others use /**.
876 (c c++ objc) "/\\*[*!]"
877 java "/\\*\\*"
878 pike "/[/*]!")
879 (c-lang-defvar c-doc-comment-start-regexp
880 (c-lang-const c-doc-comment-start-regexp))
881
882 (c-lang-defconst comment-start
883 "String that starts comments inserted with M-; etc.
884 `comment-start' is initialized from this."
885 t "// "
886 c "/* "
887 awk "# ")
888 (c-lang-defvar comment-start (c-lang-const comment-start)
889 'dont-doc)
890
891 (c-lang-defconst comment-end
892 "String that ends comments inserted with M-; etc.
893 `comment-end' is initialized from this."
894 t ""
895 c " */")
896 (c-lang-defvar comment-end (c-lang-const comment-end)
897 'dont-doc)
898
899 (c-lang-defconst comment-start-skip
900 "Regexp to match the start of a comment plus everything up to its body.
901 `comment-start-skip' is initialized from this."
902 t "/\\*+ *\\|//+ *"
903 awk "#+ *")
904 (c-lang-defvar comment-start-skip (c-lang-const comment-start-skip)
905 'dont-doc)
906
907 (c-lang-defconst c-syntactic-ws-start
908 "Regexp matching any sequence that can start syntactic whitespace.
909 The only uncertain case is '#' when there are cpp directives."
910 t "[ \n\t\r\v\f#]\\|/[/*]\\|\\\\[\n\r]"
911 awk "[ \n\t\r\v\f#]\\|\\\\[\n\r]")
912 (c-lang-defvar c-syntactic-ws-start (c-lang-const c-syntactic-ws-start)
913 'dont-doc)
914
915 (c-lang-defconst c-syntactic-ws-end
916 "Regexp matching any single character that might end syntactic whitespace."
917 t "[ \n\t\r\v\f/]"
918 awk "[ \n\t\r\v\f]")
919 (c-lang-defvar c-syntactic-ws-end (c-lang-const c-syntactic-ws-end)
920 'dont-doc)
921
922 (c-lang-defconst c-nonwhite-syntactic-ws
923 ;; Regexp matching a piece of syntactic whitespace that isn't a
924 ;; sequence of simple whitespace characters. As opposed to
925 ;; `c-(forward|backward)-syntactic-ws', this doesn't regard cpp
926 ;; directives as syntactic whitespace.
927 t (concat "/" (concat
928 "\\("
929 "/[^\n\r]*[\n\r]" ; Line comment.
930 "\\|"
931 ;; Block comment. We intentionally don't allow line
932 ;; breaks in them to avoid going very far and risk
933 ;; running out of regexp stack; this regexp is
934 ;; intended to handle only short comments that
935 ;; might be put in the middle of limited constructs
936 ;; like declarations.
937 "\\*\\([^*\n\r]\\|\\*[^/\n\r]\\)*\\*/"
938 "\\)")
939 "\\|"
940 "\\\\[\n\r]") ; Line continuations.
941 awk ("#.*[\n\r]\\|\\\\[\n\r]"))
942
943 (c-lang-defconst c-syntactic-ws
944 ;; Regexp matching syntactic whitespace, including possibly the
945 ;; empty string. As opposed to `c-(forward|backward)-syntactic-ws',
946 ;; this doesn't regard cpp directives as syntactic whitespace. Does
947 ;; not contain a \| operator at the top level.
948 t (concat "[ \t\n\r\f\v]*\\("
949 "\\(" (c-lang-const c-nonwhite-syntactic-ws) "\\)"
950 "[ \t\n\r\f\v]*\\)*"))
951
952 (c-lang-defconst c-syntactic-ws-depth
953 ;; Number of regexp grouping parens in `c-syntactic-ws'.
954 t (c-regexp-opt-depth (c-lang-const c-syntactic-ws)))
955
956 (c-lang-defconst c-nonempty-syntactic-ws
957 ;; Regexp matching syntactic whitespace, which is at least one
958 ;; character long. As opposed to `c-(forward|backward)-syntactic-ws',
959 ;; this doesn't regard cpp directives as syntactic whitespace. Does
960 ;; not contain a \| operator at the top level.
961 t (concat "\\([ \t\n\r\f\v]\\|"
962 (c-lang-const c-nonwhite-syntactic-ws)
963 "\\)+"))
964
965 (c-lang-defconst c-nonempty-syntactic-ws-depth
966 ;; Number of regexp grouping parens in `c-nonempty-syntactic-ws'.
967 t (c-regexp-opt-depth (c-lang-const c-nonempty-syntactic-ws)))
968
969 (c-lang-defconst c-single-line-syntactic-ws
970 ;; Regexp matching syntactic whitespace without any line breaks. As
971 ;; opposed to `c-(forward|backward)-syntactic-ws', this doesn't
972 ;; regard cpp directives as syntactic whitespace. Does not contain
973 ;; a \| operator at the top level.
974 t (concat "[ \t]*\\("
975 "/\\*\\([^*\n\r]\\|\\*[^/\n\r]\\)*\\*/" ; Block comment
976 "[ \t]*\\)*")
977 awk ("[ \t]*\\(#.*$\\)?"))
978
979 (c-lang-defconst c-single-line-syntactic-ws-depth
980 ;; Number of regexp grouping parens in `c-single-line-syntactic-ws'.
981 t (c-regexp-opt-depth (c-lang-const c-single-line-syntactic-ws)))
982
983 (c-lang-defvar c-syntactic-eol
984 ;; Regexp that matches when there is no syntactically significant
985 ;; text before eol. Macros are regarded as syntactically
986 ;; significant text here.
987 (concat (concat
988 ;; Match horizontal whitespace and block comments that
989 ;; don't contain newlines.
990 "\\(\\s \\|"
991 (concat "/\\*"
992 "\\([^*\n\r]\\|\\*[^/\n\r]\\)*"
993 "\\*/")
994 "\\)*")
995 (concat
996 ;; Match eol (possibly inside a block comment or preceded
997 ;; by a line continuation backslash), or the beginning of a
998 ;; line comment. Note: This has to be modified for awk
999 ;; where line comments start with '#'.
1000 "\\("
1001 (concat "\\("
1002 "/\\*\\([^*\n\r]\\|\\*[^/\n\r]\\)*"
1003 "\\|"
1004 "\\\\"
1005 "\\)?"
1006 "$")
1007 "\\|//\\)")))
1008
1009 \f
1010 ;;; In-comment text handling.
1011
1012 (c-lang-defconst c-paragraph-start
1013 "Regexp to append to `paragraph-start'."
1014 t "$"
1015 java "\\(@[a-zA-Z]+\\>\\|$\\)" ; For Javadoc.
1016 pike "\\(@[a-zA-Z_-]+\\>\\([^{]\\|$\\)\\|$\\)") ; For Pike refdoc.
1017 (c-lang-defvar c-paragraph-start (c-lang-const c-paragraph-start))
1018
1019 (c-lang-defconst c-paragraph-separate
1020 "Regexp to append to `paragraph-separate'."
1021 t "$"
1022 pike (c-lang-const c-paragraph-start))
1023 (c-lang-defvar c-paragraph-separate (c-lang-const c-paragraph-separate))
1024
1025 \f
1026 ;;; Keyword lists.
1027
1028 ;; Note: All and only all language constants containing keyword lists
1029 ;; should end with "-kwds"; they're automatically collected into the
1030 ;; `c-kwds-lang-consts' list below and used to build `c-keywords' etc.
1031
1032 (c-lang-defconst c-primitive-type-kwds
1033 "Primitive type keywords. As opposed to the other keyword lists, the
1034 keywords listed here are fontified with the type face instead of the
1035 keyword face.
1036
1037 If any of these also are on `c-type-list-kwds', `c-ref-list-kwds',
1038 `c-colon-type-list-kwds', `c-paren-nontype-kwds', `c-paren-type-kwds',
1039 `c-<>-type-kwds', or `c-<>-arglist-kwds' then the associated clauses
1040 will be handled.
1041
1042 Do not try to modify this list for end user customizations; the
1043 `*-font-lock-extra-types' variable, where `*' is the mode prefix, is
1044 the appropriate place for that."
1045 t '("char" "double" "float" "int" "long" "short" "signed"
1046 "unsigned" "void")
1047 c (append
1048 '("_Bool" "_Complex" "_Imaginary") ; Conditionally defined in C99.
1049 (c-lang-const c-primitive-type-kwds))
1050 c++ (append
1051 '("bool" "wchar_t")
1052 (c-lang-const c-primitive-type-kwds))
1053 ;; Objective-C extends C, but probably not the new stuff in C99.
1054 objc (append
1055 '("id" "Class" "SEL" "IMP" "BOOL")
1056 (c-lang-const c-primitive-type-kwds))
1057 java '("boolean" "byte" "char" "double" "float" "int" "long" "short" "void")
1058 idl '("Object" "ValueBase" "any" "boolean" "char" "double" "fixed" "float"
1059 "long" "octet" "sequence" "short" "string" "void" "wchar" "wstring"
1060 ;; In CORBA PSDL:
1061 "ref"
1062 ;; The following can't really end a type, but we have to specify them
1063 ;; here due to the assumption in `c-primitive-type-prefix-kwds'. It
1064 ;; doesn't matter that much.
1065 "unsigned" "strong")
1066 pike '(;; this_program isn't really a keyword, but it's practically
1067 ;; used as a builtin type.
1068 "array" "float" "function" "int" "mapping" "mixed" "multiset"
1069 "object" "program" "string" "this_program" "void"))
1070
1071 (c-lang-defconst c-primitive-type-key
1072 ;; An adorned regexp that matches `c-primitive-type-kwds'.
1073 t (c-make-keywords-re t (c-lang-const c-primitive-type-kwds)))
1074 (c-lang-defvar c-primitive-type-key (c-lang-const c-primitive-type-key))
1075
1076 (c-lang-defconst c-primitive-type-prefix-kwds
1077 "Keywords that might act as prefixes for primitive types. Assumed to
1078 be a subset of `c-primitive-type-kwds'."
1079 t nil
1080 (c c++) '("long" "short" "signed" "unsigned")
1081 idl '("long" "unsigned"
1082 ;; In CORBA PSDL:
1083 "strong"))
1084
1085 (c-lang-defconst c-type-prefix-kwds
1086 "Keywords where the following name - if any - is a type name, and
1087 where the keyword together with the symbol works as a type in
1088 declarations.
1089
1090 Note that an alternative if the second part doesn't hold is
1091 `c-type-list-kwds'. Keywords on this list are typically also present
1092 on one of the `*-decl-kwds' lists."
1093 t nil
1094 c '("struct" "union" "enum")
1095 c++ (append '("class" "typename")
1096 (c-lang-const c-type-prefix-kwds c)))
1097
1098 (c-lang-defconst c-type-prefix-key
1099 ;; Adorned regexp matching `c-type-prefix-kwds'.
1100 t (c-make-keywords-re t (c-lang-const c-type-prefix-kwds)))
1101 (c-lang-defvar c-type-prefix-key (c-lang-const c-type-prefix-key))
1102
1103 (c-lang-defconst c-type-modifier-kwds
1104 "Type modifier keywords. These can occur almost anywhere in types
1105 but they don't build a type of themselves. Unlike the keywords on
1106 `c-primitive-type-kwds', they are fontified with the keyword face and
1107 not the type face."
1108 t nil
1109 c '("const" "restrict" "volatile")
1110 c++ '("const" "volatile" "throw")
1111 objc '("const" "volatile"))
1112
1113 (c-lang-defconst c-opt-type-modifier-key
1114 ;; Adorned regexp matching `c-type-modifier-kwds', or nil in
1115 ;; languages without such keywords.
1116 t (and (c-lang-const c-type-modifier-kwds)
1117 (c-make-keywords-re t (c-lang-const c-type-modifier-kwds))))
1118 (c-lang-defvar c-opt-type-modifier-key (c-lang-const c-opt-type-modifier-key))
1119
1120 (c-lang-defconst c-opt-type-component-key
1121 ;; An adorned regexp that matches `c-primitive-type-prefix-kwds' and
1122 ;; `c-type-modifier-kwds', or nil in languages without any of them.
1123 t (and (or (c-lang-const c-primitive-type-prefix-kwds)
1124 (c-lang-const c-type-modifier-kwds))
1125 (c-make-keywords-re t
1126 (append (c-lang-const c-primitive-type-prefix-kwds)
1127 (c-lang-const c-type-modifier-kwds)))))
1128 (c-lang-defvar c-opt-type-component-key
1129 (c-lang-const c-opt-type-component-key))
1130
1131 (c-lang-defconst c-class-decl-kwds
1132 "Keywords introducing declarations where the following block (if any)
1133 contains another declaration level that should be considered a class.
1134
1135 If any of these also are on `c-type-list-kwds', `c-ref-list-kwds',
1136 `c-colon-type-list-kwds', `c-paren-nontype-kwds', `c-paren-type-kwds',
1137 `c-<>-type-kwds', or `c-<>-arglist-kwds' then the associated clauses
1138 will be handled.
1139
1140 Note that presence on this list does not automatically treat the
1141 following identifier as a type; the keyword must also be present on
1142 `c-type-prefix-kwds' or `c-type-list-kwds' to accomplish that."
1143 t nil
1144 c '("struct" "union")
1145 c++ '("class" "struct" "union")
1146 objc '("struct" "union"
1147 "@interface" "@implementation" "@protocol")
1148 java '("class" "interface")
1149 idl '("component" "eventtype" "exception" "home" "interface" "struct"
1150 "union" "valuetype"
1151 ;; In CORBA PSDL:
1152 "storagehome" "storagetype"
1153 ;; In CORBA CIDL:
1154 "catalog" "executor" "manages" "segment")
1155 pike '("class"))
1156
1157 (c-lang-defconst c-class-key
1158 ;; Regexp matching the start of a class.
1159 t (c-make-keywords-re t (c-lang-const c-class-decl-kwds)))
1160 (c-lang-defvar c-class-key (c-lang-const c-class-key))
1161
1162 (c-lang-defconst c-brace-list-decl-kwds
1163 "Keywords introducing declarations where the following block (if
1164 any) is a brace list.
1165
1166 If any of these also are on `c-type-list-kwds', `c-ref-list-kwds',
1167 `c-colon-type-list-kwds', `c-paren-nontype-kwds', `c-paren-type-kwds',
1168 `c-<>-type-kwds', or `c-<>-arglist-kwds' then the associated clauses
1169 will be handled."
1170 t '("enum")
1171 (java awk) nil)
1172
1173 (c-lang-defconst c-brace-list-key
1174 ;; Regexp matching the start of declarations where the following
1175 ;; block is a brace list.
1176 t (c-make-keywords-re t (c-lang-const c-brace-list-decl-kwds)))
1177 (c-lang-defvar c-brace-list-key (c-lang-const c-brace-list-key))
1178
1179 (c-lang-defconst c-other-block-decl-kwds
1180 "Keywords where the following block (if any) contain another
1181 declaration level that should not be considered a class.
1182
1183 If any of these also are on `c-type-list-kwds', `c-ref-list-kwds',
1184 `c-colon-type-list-kwds', `c-paren-nontype-kwds', `c-paren-type-kwds',
1185 `c-<>-type-kwds', or `c-<>-arglist-kwds' then the associated clauses
1186 will be handled."
1187 t nil
1188 c '("extern")
1189 c++ '("namespace" "extern")
1190 idl '("module"
1191 ;; In CORBA CIDL:
1192 "composition"))
1193
1194 (c-lang-defconst c-other-decl-block-key
1195 ;; Regexp matching the start of blocks besides classes that contain
1196 ;; another declaration level.
1197 t (c-make-keywords-re t (c-lang-const c-other-block-decl-kwds)))
1198 (c-lang-defvar c-other-decl-block-key (c-lang-const c-other-decl-block-key))
1199
1200 (c-lang-defconst c-typedef-decl-kwds
1201 "Keywords introducing declarations where the identifiers are defined
1202 to be types.
1203
1204 If any of these also are on `c-type-list-kwds', `c-ref-list-kwds',
1205 `c-colon-type-list-kwds', `c-paren-nontype-kwds', `c-paren-type-kwds',
1206 `c-<>-type-kwds', or `c-<>-arglist-kwds' then the associated clauses
1207 will be handled."
1208 t '("typedef")
1209 (java awk) nil)
1210
1211 (c-lang-defconst c-typeless-decl-kwds
1212 "Keywords introducing declarations where the identifier (declarator)
1213 list follows directly after the keyword, without any type.
1214
1215 If any of these also are on `c-type-list-kwds', `c-ref-list-kwds',
1216 `c-colon-type-list-kwds', `c-paren-nontype-kwds', `c-paren-type-kwds',
1217 `c-<>-type-kwds', or `c-<>-arglist-kwds' then the associated clauses
1218 will be handled."
1219 t nil
1220 ;; Unlike most other languages, exception names are not handled as
1221 ;; types in IDL since they only can occur in "raises" specs.
1222 idl '("exception" "factory" "finder" "native"
1223 ;; In CORBA PSDL:
1224 "key" "stores"
1225 ;; In CORBA CIDL:
1226 ;; Note that "manages" here clashes with its presence on
1227 ;; `c-type-list-kwds' for IDL.
1228 "executor" "facet" "manages" "segment")
1229 pike '("constant"))
1230
1231 (c-lang-defconst c-modifier-kwds
1232 "Keywords that can prefix normal declarations of identifiers
1233 \(and typically acts as flags). Things like argument declarations
1234 inside function headers are also considered declarations in this
1235 sense.
1236
1237 If any of these also are on `c-type-list-kwds', `c-ref-list-kwds',
1238 `c-colon-type-list-kwds', `c-paren-nontype-kwds', `c-paren-type-kwds',
1239 `c-<>-type-kwds', or `c-<>-arglist-kwds' then the associated clauses
1240 will be handled."
1241 t nil
1242 (c c++) '("auto" "extern" "inline" "register" "static")
1243 c++ (append '("explicit" "friend" "mutable" "template" "using" "virtual")
1244 (c-lang-const c-modifier-kwds))
1245 objc '("auto" "bycopy" "byref" "extern" "in" "inout" "oneway" "out" "static")
1246 ;; FIXME: Some of those below ought to be on `c-other-decl-kwds' instead.
1247 idl '("abstract" "attribute" "const" "consumes" "custom" "emits" "import"
1248 "in" "inout" "local" "multiple" "oneway" "out" "private" "provides"
1249 "public" "publishes" "readonly" "typeid" "typeprefix" "uses"
1250 ;; In CORBA PSDL:
1251 "primary" "state"
1252 ;; In CORBA CIDL:
1253 "bindsTo" "delegatesTo" "implements" "proxy" "storedOn")
1254 ;; Note: "const" is not used in Java, but it's still a reserved keyword.
1255 java '("abstract" "const" "final" "native" "private" "protected" "public"
1256 "static" "strictfp" "synchronized" "transient" "volatile")
1257 pike '("final" "inline" "local" "nomask" "optional" "private" "protected"
1258 "public" "static" "variant"))
1259
1260 (c-lang-defconst c-other-decl-kwds
1261 "Keywords that can start or prefix any declaration level construct,
1262 besides those on `c-class-decl-kwds', `c-brace-list-decl-kwds',
1263 `c-other-block-decl-kwds', `c-typedef-decl-kwds',
1264 `c-typeless-decl-kwds' and `c-modifier-kwds'. In a declaration, these
1265 keywords are also recognized inside or after the identifiers that
1266 makes up the type.
1267
1268 If any of these also are on `c-type-list-kwds', `c-ref-list-kwds',
1269 `c-colon-type-list-kwds', `c-paren-nontype-kwds', `c-paren-type-kwds',
1270 `c-<>-type-kwds', or `c-<>-arglist-kwds' then the associated clauses
1271 will be handled."
1272 t nil
1273 (c c++) '("__declspec") ; MSVC extension.
1274 objc '("@class" "@end" "@defs")
1275 java '("import" "package")
1276 pike '("import" "inherit"))
1277
1278 (c-lang-defconst c-specifier-key
1279 ;; Adorned regexp matching keywords that can start a declaration but
1280 ;; not a type.
1281 t (c-make-keywords-re t
1282 (set-difference (append (c-lang-const c-class-decl-kwds)
1283 (c-lang-const c-brace-list-decl-kwds)
1284 (c-lang-const c-other-block-decl-kwds)
1285 (c-lang-const c-typedef-decl-kwds)
1286 (c-lang-const c-typeless-decl-kwds)
1287 (c-lang-const c-modifier-kwds)
1288 (c-lang-const c-other-decl-kwds))
1289 (append (c-lang-const c-primitive-type-kwds)
1290 (c-lang-const c-type-prefix-kwds)
1291 (c-lang-const c-type-modifier-kwds))
1292 :test 'string-equal)))
1293 (c-lang-defvar c-specifier-key (c-lang-const c-specifier-key))
1294
1295 (c-lang-defconst c-protection-kwds
1296 "Protection label keywords in classes."
1297 t nil
1298 c++ '("private" "protected" "public")
1299 objc '("@private" "@protected" "@public"))
1300
1301 (c-lang-defconst c-opt-access-key
1302 ;; Regexp matching an access protection label in a class, or nil in
1303 ;; languages that don't have such things.
1304 t (if (c-lang-const c-protection-kwds)
1305 (c-make-keywords-re t (c-lang-const c-protection-kwds)))
1306 c++ (concat "\\("
1307 (c-make-keywords-re nil (c-lang-const c-protection-kwds))
1308 "\\)[ \t\n\r\f\v]*:"))
1309 (c-lang-defvar c-opt-access-key (c-lang-const c-opt-access-key))
1310
1311 (c-lang-defconst c-block-decls-with-vars
1312 "Keywords introducing declarations that can contain a block which
1313 might be followed by variable declarations, e.g. like \"foo\" in
1314 \"class Foo { ... } foo;\". So if there is a block in a declaration
1315 like that, it ends with the following ';' and not right away.
1316
1317 The keywords on list are assumed to also be present on one of the
1318 `*-decl-kwds' lists."
1319 t nil
1320 (c objc) '("struct" "union" "enum" "typedef")
1321 c++ '("class" "struct" "union" "enum" "typedef"))
1322
1323 (c-lang-defconst c-opt-block-decls-with-vars-key
1324 ;; Regexp matching the `c-block-decls-with-vars' keywords, or nil in
1325 ;; languages without such constructs.
1326 t (and (c-lang-const c-block-decls-with-vars)
1327 (c-make-keywords-re t (c-lang-const c-block-decls-with-vars))))
1328 (c-lang-defvar c-opt-block-decls-with-vars-key
1329 (c-lang-const c-opt-block-decls-with-vars-key))
1330
1331 (c-lang-defconst c-postfix-decl-spec-kwds
1332 "Keywords introducing extra declaration specifiers in the region
1333 between the header and the body \(i.e. the \"K&R-region\") in
1334 declarations."
1335 t nil
1336 (c c++) '("__attribute__") ; GCC extension.
1337 java '("extends" "implements" "throws")
1338 idl '("context" "getraises" "manages" "primarykey" "raises" "setraises"
1339 "supports"
1340 ;; In CORBA PSDL:
1341 "as" "const" "implements" "of" "ref"))
1342
1343 (c-lang-defconst c-nonsymbol-sexp-kwds
1344 "Keywords that may be followed by a nonsymbol sexp before whatever
1345 construct it's part of continues."
1346 t nil
1347 (c c++ objc) '("extern"))
1348
1349 (c-lang-defconst c-type-list-kwds
1350 "Keywords that may be followed by a comma separated list of type
1351 identifiers, where each optionally can be prefixed by keywords. (Can
1352 also be used for the special case when the list can contain only one
1353 element.)
1354
1355 Assumed to be mutually exclusive with `c-ref-list-kwds'. There's no
1356 reason to put keywords on this list if they are on `c-type-prefix-kwds'.
1357 There's also no reason to add keywords that prefixes a normal
1358 declaration consisting of a type followed by a declarator (list), so
1359 the keywords on `c-modifier-kwds' should normally not be listed here
1360 too.
1361
1362 Note: Use `c-typeless-decl-kwds' for keywords followed by a function
1363 or variable identifier (that's being defined)."
1364 t '("struct" "union" "enum")
1365 (c awk) nil
1366 c++ '("operator")
1367 objc (append '("@class" "@interface" "@implementation" "@protocol")
1368 (c-lang-const c-type-list-kwds))
1369 java '("class" "import" "interface" "new" "extends" "implements" "throws")
1370 idl (append '("component" "eventtype" "home" "interface" "manages" "native"
1371 "primarykey" "supports" "valuetype"
1372 ;; In CORBA PSDL:
1373 "as" "implements" "of" "scope" "storagehome" "storagetype")
1374 (c-lang-const c-type-list-kwds))
1375 pike '("class" "enum" "inherit"))
1376
1377 (c-lang-defconst c-ref-list-kwds
1378 "Keywords that may be followed by a comma separated list of
1379 reference (i.e. namespace/scope/module) identifiers, where each
1380 optionally can be prefixed by keywords. (Can also be used for the
1381 special case when the list can contain only one element.) Assumed to
1382 be mutually exclusive with `c-type-list-kwds'.
1383
1384 Note: Use `c-typeless-decl-kwds' for keywords followed by a function
1385 or variable identifier (that's being defined)."
1386 t nil
1387 c++ '("namespace")
1388 java '("package")
1389 idl '("import" "module"
1390 ;; In CORBA CIDL:
1391 "composition")
1392 pike '("import"))
1393
1394 (c-lang-defconst c-colon-type-list-kwds
1395 "Keywords that may be followed (not necessarily directly) by a colon
1396 and then a comma separated list of type identifiers, where each
1397 optionally can be prefixed by keywords. (Can also be used for the
1398 special case when the list can contain only one element.)"
1399 t nil
1400 c++ '("class" "struct")
1401 idl '("component" "eventtype" "home" "interface" "valuetype"
1402 ;; In CORBA PSDL:
1403 "storagehome" "storagetype"))
1404
1405 (c-lang-defconst c-colon-type-list-re
1406 "Regexp matched after the keywords in `c-colon-type-list-kwds' to skip
1407 forward to the colon. The end of the match is assumed to be directly
1408 after the colon, so the regexp should end with \":\" although that
1409 isn't necessary. Must be a regexp if `c-colon-type-list-kwds' isn't
1410 nil."
1411 t (if (c-lang-const c-colon-type-list-kwds)
1412 ;; Disallow various common punctuation chars that can't come
1413 ;; before the ":" that starts the inherit list after "class"
1414 ;; or "struct" in C++. (Also used as default for other
1415 ;; languages.)
1416 "[^\]\[{}();,/#=:]*:"))
1417 (c-lang-defvar c-colon-type-list-re (c-lang-const c-colon-type-list-re))
1418
1419 (c-lang-defconst c-paren-nontype-kwds
1420 "Keywords that may be followed by a parenthesis expression that doesn't
1421 contain type identifiers."
1422 t nil
1423 (c c++) '("__declspec")) ; MSVC extension.
1424
1425 (c-lang-defconst c-paren-type-kwds
1426 "Keywords that may be followed by a parenthesis expression containing
1427 type identifiers separated by arbitrary tokens."
1428 t nil
1429 c++ '("throw")
1430 objc '("@defs")
1431 idl '("switch")
1432 pike '("array" "function" "int" "mapping" "multiset" "object" "program"))
1433
1434 (c-lang-defconst c-paren-any-kwds
1435 t (delete-duplicates (append (c-lang-const c-paren-nontype-kwds)
1436 (c-lang-const c-paren-type-kwds))
1437 :test 'string-equal))
1438
1439 (c-lang-defconst c-<>-type-kwds
1440 "Keywords that may be followed by an angle bracket expression
1441 containing type identifiers separated by \",\". The difference from
1442 `c-<>-arglist-kwds' is that unknown names are taken to be types and
1443 not other identifiers. `c-recognize-<>-arglists' is assumed to be set
1444 if this isn't nil."
1445 t nil
1446 objc '("id")
1447 idl '("sequence"
1448 ;; In CORBA PSDL:
1449 "ref"))
1450
1451 (c-lang-defconst c-<>-arglist-kwds
1452 "Keywords that can be followed by a C++ style template arglist; see
1453 `c-recognize-<>-arglists' for details. That language constant is
1454 assumed to be set if this isn't nil."
1455 t nil
1456 c++ '("template")
1457 idl '("fixed" "string" "wstring"))
1458
1459 (c-lang-defconst c-<>-sexp-kwds
1460 ;; All keywords that can be followed by an angle bracket sexp.
1461 t (delete-duplicates (append (c-lang-const c-<>-type-kwds)
1462 (c-lang-const c-<>-arglist-kwds))
1463 :test 'string-equal))
1464
1465 (c-lang-defconst c-opt-<>-sexp-key
1466 ;; Adorned regexp matching keywords that can be followed by an angle
1467 ;; bracket sexp. Always set when `c-recognize-<>-arglists' is.
1468 t (if (c-lang-const c-recognize-<>-arglists)
1469 (c-make-keywords-re t (c-lang-const c-<>-sexp-kwds))))
1470 (c-lang-defvar c-opt-<>-sexp-key (c-lang-const c-opt-<>-sexp-key))
1471
1472 (c-lang-defconst c-brace-id-list-kwds
1473 "Keywords that may be followed by a brace block containing a comma
1474 separated list of identifier definitions, i.e. like the list of
1475 identifiers that follows the type in a normal declaration."
1476 t (c-lang-const c-brace-list-decl-kwds))
1477
1478 (c-lang-defconst c-block-stmt-1-kwds
1479 "Statement keywords followed directly by a substatement."
1480 t '("do" "else")
1481 c++ '("do" "else" "try")
1482 java '("do" "else" "finally" "try")
1483 idl nil)
1484
1485 (c-lang-defconst c-block-stmt-1-key
1486 ;; Regexp matching the start of any statement followed directly by a
1487 ;; substatement (doesn't match a bare block, however).
1488 t (c-make-keywords-re t (c-lang-const c-block-stmt-1-kwds)))
1489 (c-lang-defvar c-block-stmt-1-key (c-lang-const c-block-stmt-1-key))
1490
1491 (c-lang-defconst c-block-stmt-2-kwds
1492 "Statement keywords followed by a paren sexp and then by a substatement."
1493 t '("for" "if" "switch" "while")
1494 c++ '("for" "if" "switch" "while" "catch")
1495 java '("for" "if" "switch" "while" "catch" "synchronized")
1496 idl nil
1497 pike '("for" "if" "switch" "while" "foreach")
1498 awk '("for" "if" "while"))
1499
1500 (c-lang-defconst c-block-stmt-2-key
1501 ;; Regexp matching the start of any statement followed by a paren sexp
1502 ;; and then by a substatement.
1503 t (c-make-keywords-re t (c-lang-const c-block-stmt-2-kwds)))
1504 (c-lang-defvar c-block-stmt-2-key (c-lang-const c-block-stmt-2-key))
1505
1506 (c-lang-defconst c-opt-block-stmt-key
1507 ;; Regexp matching the start of any statement that has a
1508 ;; substatement (except a bare block). Nil in languages that
1509 ;; don't have such constructs.
1510 t (if (or (c-lang-const c-block-stmt-1-kwds)
1511 (c-lang-const c-block-stmt-2-kwds))
1512 (c-make-keywords-re t
1513 (append (c-lang-const c-block-stmt-1-kwds)
1514 (c-lang-const c-block-stmt-2-kwds)))))
1515 (c-lang-defvar c-opt-block-stmt-key (c-lang-const c-opt-block-stmt-key))
1516
1517 (c-lang-defconst c-simple-stmt-kwds
1518 "Statement keywords followed by an expression or nothing."
1519 t '("break" "continue" "goto" "return")
1520 ;; Note: `goto' is not valid in Java, but the keyword is still reserved.
1521 java '("break" "continue" "goto" "return" "throw")
1522 idl nil
1523 pike '("break" "continue" "return")
1524 awk '(;; Not sure about "delete", "exit", "getline", etc. ; ACM 2002/5/30
1525 "break" "continue" "return" "delete" "exit" "getline" "next"
1526 "nextfile" "print" "printf"))
1527
1528 (c-lang-defconst c-simple-stmt-key
1529 ;; Adorned regexp matching `c-simple-stmt-kwds'.
1530 t (c-make-keywords-re t (c-lang-const c-simple-stmt-kwds)))
1531 (c-lang-defvar c-simple-stmt-key (c-lang-const c-simple-stmt-key))
1532
1533 (c-lang-defconst c-paren-stmt-kwds
1534 "Statement keywords followed by a parenthesis expression that
1535 nevertheless contains a list separated with ';' and not ','."
1536 t '("for")
1537 idl nil)
1538
1539 (c-lang-defconst c-paren-stmt-key
1540 ;; Adorned regexp matching `c-paren-stmt-kwds'.
1541 t (c-make-keywords-re t (c-lang-const c-paren-stmt-kwds)))
1542 (c-lang-defvar c-paren-stmt-key (c-lang-const c-paren-stmt-key))
1543
1544 (c-lang-defconst c-asm-stmt-kwds
1545 "Statement keywords followed by an assembler expression."
1546 t nil
1547 (c c++) '("asm" "__asm__")) ;; Not standard, but common.
1548
1549 (c-lang-defconst c-opt-asm-stmt-key
1550 ;; Regexp matching the start of an assembler statement. Nil in
1551 ;; languages that don't support that.
1552 t (if (c-lang-const c-asm-stmt-kwds)
1553 (c-make-keywords-re t (c-lang-const c-asm-stmt-kwds))))
1554 (c-lang-defvar c-opt-asm-stmt-key (c-lang-const c-opt-asm-stmt-key))
1555
1556 (c-lang-defconst c-label-kwds
1557 "Keywords introducing labels in blocks."
1558 t '("case" "default")
1559 awk nil)
1560
1561 (c-lang-defconst c-before-label-kwds
1562 "Keywords that might be followed by a label identifier."
1563 t '("goto")
1564 (java pike) (append '("break" "continue")
1565 (c-lang-const c-before-label-kwds))
1566 idl nil
1567 awk nil)
1568
1569 (c-lang-defconst c-label-kwds-regexp
1570 ;; Regexp matching any keyword that introduces a label.
1571 t (c-make-keywords-re t (c-lang-const c-label-kwds)))
1572 (c-lang-defvar c-label-kwds-regexp (c-lang-const c-label-kwds-regexp))
1573
1574 (c-lang-defconst c-constant-kwds
1575 "Keywords for constants."
1576 t nil
1577 (c c++) '("NULL" ;; Not a keyword, but practically works as one.
1578 "false" "true") ; Defined in C99.
1579 objc '("nil" "Nil")
1580 idl '("TRUE" "FALSE")
1581 pike '("UNDEFINED")) ;; Not a keyword, but practically works as one.
1582
1583 (c-lang-defconst c-primary-expr-kwds
1584 "Keywords besides constants and operators that start primary expressions."
1585 t nil
1586 c++ '("operator" "this")
1587 objc '("super" "self")
1588 java '("this")
1589 pike '("this")) ;; Not really a keyword, but practically works as one.
1590
1591 (c-lang-defconst c-expr-kwds
1592 ;; Keywords that can occur anywhere in expressions. Built from
1593 ;; `c-primary-expr-kwds' and all keyword operators in `c-operators'.
1594 t (delete-duplicates
1595 (append (c-lang-const c-primary-expr-kwds)
1596 (c-with-syntax-table (c-lang-const c-mode-syntax-table)
1597 (mapcan (lambda (op)
1598 (and (string-match "\\`\\(\\w\\|\\s_\\)+\\'" op)
1599 (list op)))
1600 (c-lang-const c-operator-list))))
1601 :test 'string-equal))
1602
1603 (c-lang-defconst c-lambda-kwds
1604 "Keywords that start lambda constructs, i.e. function definitions in
1605 expressions."
1606 t nil
1607 pike '("lambda"))
1608
1609 (c-lang-defconst c-opt-lambda-key
1610 ;; Adorned regexp matching the start of lambda constructs, or nil in
1611 ;; languages that don't have such things.
1612 t (and (c-lang-const c-lambda-kwds)
1613 (c-make-keywords-re t (c-lang-const c-lambda-kwds))))
1614 (c-lang-defvar c-opt-lambda-key (c-lang-const c-opt-lambda-key))
1615
1616 (c-lang-defconst c-inexpr-block-kwds
1617 "Keywords that start constructs followed by statement blocks which can
1618 be used in expressions \(the gcc extension for this in C and C++ is
1619 handled separately)."
1620 t nil
1621 pike '("catch" "gauge"))
1622
1623 (c-lang-defconst c-opt-inexpr-block-key
1624 ;; Regexp matching the start of in-expression statements, or nil in
1625 ;; languages that don't have such things.
1626 t nil
1627 pike (c-make-keywords-re t (c-lang-const c-inexpr-block-kwds)))
1628 (c-lang-defvar c-opt-inexpr-block-key (c-lang-const c-opt-inexpr-block-key))
1629
1630 (c-lang-defconst c-inexpr-class-kwds
1631 "Keywords that can start classes inside expressions."
1632 t nil
1633 java '("new")
1634 pike '("class"))
1635
1636 (c-lang-defconst c-opt-inexpr-class-key
1637 ;; Regexp matching the start of a class in an expression, or nil in
1638 ;; languages that don't have such things.
1639 t (and (c-lang-const c-inexpr-class-kwds)
1640 (c-make-keywords-re t (c-lang-const c-inexpr-class-kwds))))
1641 (c-lang-defvar c-opt-inexpr-class-key (c-lang-const c-opt-inexpr-class-key))
1642
1643 (c-lang-defconst c-inexpr-brace-list-kwds
1644 "Keywords that can start brace list blocks inside expressions.
1645 Note that Java specific rules are currently applied to tell this from
1646 `c-inexpr-class-kwds'."
1647 t nil
1648 java '("new"))
1649
1650 (c-lang-defconst c-opt-inexpr-brace-list-key
1651 ;; Regexp matching the start of a brace list in an expression, or
1652 ;; nil in languages that don't have such things. This should not
1653 ;; match brace lists recognized through `c-special-brace-lists'.
1654 t (and (c-lang-const c-inexpr-brace-list-kwds)
1655 (c-make-keywords-re t (c-lang-const c-inexpr-brace-list-kwds))))
1656 (c-lang-defvar c-opt-inexpr-brace-list-key
1657 (c-lang-const c-opt-inexpr-brace-list-key))
1658
1659 (c-lang-defconst c-any-class-key
1660 ;; Regexp matching the start of any class, both at top level and in
1661 ;; expressions.
1662 t (c-make-keywords-re t
1663 (append (c-lang-const c-class-decl-kwds)
1664 (c-lang-const c-inexpr-class-kwds))))
1665 (c-lang-defvar c-any-class-key (c-lang-const c-any-class-key))
1666
1667 (c-lang-defconst c-decl-block-key
1668 ;; Regexp matching the start of any declaration-level block that
1669 ;; contain another declaration level, i.e. that isn't a function
1670 ;; block or brace list.
1671 t (c-make-keywords-re t
1672 (append (c-lang-const c-class-decl-kwds)
1673 (c-lang-const c-other-block-decl-kwds)
1674 (c-lang-const c-inexpr-class-kwds)))
1675 ;; In Pike modifiers might be followed by a block
1676 ;; to apply to several declarations.
1677 pike (concat (c-lang-const c-decl-block-key)
1678 "\\|"
1679 "\\(" (c-make-keywords-re nil
1680 (c-lang-const c-modifier-kwds)) "\\)"
1681 (c-lang-const c-syntactic-ws)
1682 "{"))
1683 (c-lang-defvar c-decl-block-key (c-lang-const c-decl-block-key))
1684
1685 (c-lang-defconst c-bitfield-kwds
1686 "Keywords that can introduce bitfields."
1687 t nil
1688 (c c++ objc) '("char" "int" "long" "signed" "unsigned"))
1689
1690 (c-lang-defconst c-opt-bitfield-key
1691 ;; Regexp matching the start of a bitfield (not uniquely), or nil in
1692 ;; languages without bitfield support.
1693 t nil
1694 (c c++) (c-make-keywords-re t (c-lang-const c-bitfield-kwds)))
1695 (c-lang-defvar c-opt-bitfield-key (c-lang-const c-opt-bitfield-key))
1696
1697 (c-lang-defconst c-other-kwds
1698 "Keywords not accounted for by any other `*-kwds' language constant."
1699 t nil
1700 idl '("truncatable"
1701 ;; In CORBA CIDL: (These are declaration keywords that never
1702 ;; can start a declaration.)
1703 "entity" "process" "service" "session" "storage"))
1704
1705 \f
1706 ;;; Constants built from keywords.
1707
1708 ;; Note: No `*-kwds' language constants may be defined below this point.
1709
1710 (eval-and-compile
1711 (defconst c-kwds-lang-consts
1712 ;; List of all the language constants that contain keyword lists.
1713 (let (list)
1714 (mapatoms (lambda (sym)
1715 (when (and (boundp sym)
1716 (string-match "-kwds\\'" (symbol-name sym)))
1717 ;; Make the list of globally interned symbols
1718 ;; instead of ones interned in `c-lang-constants'.
1719 (setq list (cons (intern (symbol-name sym)) list))))
1720 c-lang-constants)
1721 list)))
1722
1723 (c-lang-defconst c-keywords
1724 ;; All keywords as a list.
1725 t (delete-duplicates
1726 (c-lang-defconst-eval-immediately
1727 `(append ,@(mapcar (lambda (kwds-lang-const)
1728 `(c-lang-const ,kwds-lang-const))
1729 c-kwds-lang-consts)
1730 nil))
1731 :test 'string-equal))
1732
1733 (c-lang-defconst c-keywords-regexp
1734 ;; All keywords as an adorned regexp.
1735 t (c-make-keywords-re t (c-lang-const c-keywords)))
1736 (c-lang-defvar c-keywords-regexp (c-lang-const c-keywords-regexp))
1737
1738 (c-lang-defconst c-keyword-member-alist
1739 ;; An alist with all the keywords in the cars. The cdr for each
1740 ;; keyword is a list of the symbols for the `*-kwds' lists that
1741 ;; contains it.
1742 t (let ((kwd-list-alist
1743 (c-lang-defconst-eval-immediately
1744 `(list ,@(mapcar (lambda (kwds-lang-const)
1745 `(cons ',kwds-lang-const
1746 (c-lang-const ,kwds-lang-const)))
1747 c-kwds-lang-consts))))
1748 lang-const kwd-list kwd
1749 result-alist elem)
1750 (while kwd-list-alist
1751 (setq lang-const (caar kwd-list-alist)
1752 kwd-list (cdar kwd-list-alist)
1753 kwd-list-alist (cdr kwd-list-alist))
1754 (while kwd-list
1755 (setq kwd (car kwd-list)
1756 kwd-list (cdr kwd-list))
1757 (unless (setq elem (assoc kwd result-alist))
1758 (setq result-alist (cons (setq elem (list kwd)) result-alist)))
1759 (unless (memq lang-const (cdr elem))
1760 (setcdr elem (cons lang-const (cdr elem))))))
1761 result-alist))
1762
1763 (c-lang-defvar c-keywords-obarray
1764 ;; An obarray containing all keywords as symbols. The property list
1765 ;; of each symbol has a non-nil entry for the specific `*-kwds'
1766 ;; lists it's a member of.
1767 ;;
1768 ;; E.g. to see whether the string str contains a keyword on
1769 ;; `c-class-decl-kwds', one can do like this:
1770 ;; (get (intern-soft str c-keyword-obarray) 'c-class-decl-kwds)
1771 ;; Which preferably is written using the associated functions in
1772 ;; cc-engine:
1773 ;; (c-keyword-member (c-keyword-sym str) 'c-class-decl-kwds)
1774
1775 ;; The obarray is not stored directly as a language constant since
1776 ;; the printed representation for obarrays used in .elc files isn't
1777 ;; complete.
1778
1779 (let* ((alist (c-lang-const c-keyword-member-alist))
1780 kwd lang-const-list
1781 (obarray (make-vector (* (length alist) 2) 0)))
1782 (while alist
1783 (setq kwd (caar alist)
1784 lang-const-list (cdar alist)
1785 alist (cdr alist))
1786 (setplist (intern kwd obarray)
1787 ;; Emacs has an odd bug that causes `mapcan' to fail
1788 ;; with unintelligible errors. (XEmacs >= 20 works.)
1789 ;;(mapcan (lambda (lang-const)
1790 ;; (list lang-const t))
1791 ;; lang-const-list)
1792 (apply 'nconc (mapcar (lambda (lang-const)
1793 (list lang-const t))
1794 lang-const-list))))
1795 obarray))
1796
1797 (c-lang-defconst c-regular-keywords-regexp
1798 ;; Adorned regexp matching all keywords that aren't types or
1799 ;; constants.
1800 t (c-make-keywords-re t
1801 (set-difference (c-lang-const c-keywords)
1802 (append (c-lang-const c-primitive-type-kwds)
1803 (c-lang-const c-constant-kwds))
1804 :test 'string-equal)))
1805 (c-lang-defvar c-regular-keywords-regexp
1806 (c-lang-const c-regular-keywords-regexp))
1807
1808 (c-lang-defconst c-not-decl-init-keywords
1809 ;; Adorned regexp matching all keywords that can't appear at the
1810 ;; start of a declaration.
1811 t (c-make-keywords-re t
1812 (set-difference (c-lang-const c-keywords)
1813 (append (c-lang-const c-primitive-type-kwds)
1814 (c-lang-const c-type-prefix-kwds)
1815 (c-lang-const c-type-modifier-kwds)
1816 (c-lang-const c-class-decl-kwds)
1817 (c-lang-const c-brace-list-decl-kwds)
1818 (c-lang-const c-other-block-decl-kwds)
1819 (c-lang-const c-typedef-decl-kwds)
1820 (c-lang-const c-typeless-decl-kwds)
1821 (c-lang-const c-modifier-kwds)
1822 (c-lang-const c-other-decl-kwds))
1823 :test 'string-equal)))
1824 (c-lang-defvar c-not-decl-init-keywords
1825 (c-lang-const c-not-decl-init-keywords))
1826
1827 (c-lang-defconst c-primary-expr-regexp
1828 ;; Regexp matching the start of any primary expression, i.e. any
1829 ;; literal, symbol, prefix operator, and '('. It doesn't need to
1830 ;; exclude keywords; they are excluded afterwards unless the second
1831 ;; submatch matches. If the first but not the second submatch
1832 ;; matches then it is an ambiguous primary expression; it could also
1833 ;; be a match of e.g. an infix operator. (The case with ambiguous
1834 ;; keyword operators isn't handled.)
1835
1836 t (c-with-syntax-table (c-lang-const c-mode-syntax-table)
1837 (let* ((prefix-ops
1838 (mapcan (lambda (op)
1839 ;; Filter out the special case prefix
1840 ;; operators that are close parens.
1841 (unless (string-match "\\s\)" op)
1842 (list op)))
1843 (mapcan
1844 (lambda (opclass)
1845 (when (eq (car opclass) 'prefix)
1846 (append (cdr opclass) nil)))
1847 (c-lang-const c-operators))))
1848
1849 (nonkeyword-prefix-ops
1850 (mapcan (lambda (op)
1851 (unless (string-match "\\`\\(\\w\\|\\s_\\)+\\'" op)
1852 (list op)))
1853 prefix-ops))
1854
1855 (in-or-postfix-ops
1856 (mapcan (lambda (opclass)
1857 (when (memq (car opclass)
1858 '(postfix
1859 left-assoc
1860 right-assoc
1861 right-assoc-sequence))
1862 (append (cdr opclass) nil)))
1863 (c-lang-const c-operators)))
1864
1865 (unambiguous-prefix-ops (set-difference nonkeyword-prefix-ops
1866 in-or-postfix-ops
1867 :test 'string-equal))
1868 (ambiguous-prefix-ops (intersection nonkeyword-prefix-ops
1869 in-or-postfix-ops
1870 :test 'string-equal)))
1871
1872 (concat
1873 "\\("
1874 ;; Take out all symbol class operators from `prefix-ops' and make the
1875 ;; first submatch from them together with `c-primary-expr-kwds'.
1876 (c-make-keywords-re t
1877 (append (c-lang-const c-primary-expr-kwds)
1878 (set-difference prefix-ops nonkeyword-prefix-ops
1879 :test 'string-equal)))
1880
1881 "\\|"
1882 ;; Match all ambiguous operators.
1883 (c-make-keywords-re nil
1884 (intersection nonkeyword-prefix-ops in-or-postfix-ops
1885 :test 'string-equal))
1886 "\\)"
1887
1888 "\\|"
1889 ;; Now match all other symbols.
1890 (c-lang-const c-symbol-start)
1891
1892 "\\|"
1893 ;; The chars that can start integer and floating point
1894 ;; constants.
1895 "\\.?[0-9]"
1896
1897 "\\|"
1898 ;; The nonambiguous operators from `prefix-ops'.
1899 (c-make-keywords-re nil
1900 (set-difference nonkeyword-prefix-ops in-or-postfix-ops
1901 :test 'string-equal))
1902
1903 "\\|"
1904 ;; Match string and character literals.
1905 "\\s\""
1906 (if (memq 'gen-string-delim c-emacs-features)
1907 "\\|\\s|"
1908 "")))))
1909 (c-lang-defvar c-primary-expr-regexp (c-lang-const c-primary-expr-regexp))
1910
1911 \f
1912 ;;; Additional constants for parser-level constructs.
1913
1914 (c-lang-defconst c-decl-prefix-re
1915 "Regexp matching something that might precede a declaration or a cast,
1916 such as the last token of a preceding statement or declaration. It
1917 should not match bob, though. It can't require a match longer than
1918 one token. The end of the token is taken to be at the end of the
1919 first submatch. It must not include any following whitespace. It's
1920 undefined whether identifier syntax (see `c-identifier-syntax-table')
1921 is in effect or not."
1922 ;; We match a sequence of characters to skip over things like \"};\"
1923 ;; more quickly. We match ")" in C for K&R region declarations, and
1924 ;; in all languages except Java for when a cpp macro definition
1925 ;; begins with a declaration.
1926 t "\\([\{\}\(\);,]+\\)"
1927 java "\\([\{\}\(;,]+\\)"
1928 ;; Match "<" in C++ to get the first argument in a template arglist.
1929 ;; In that case there's an additional check in `c-find-decl-spots'
1930 ;; that it got open paren syntax.
1931 ;;
1932 ;; Also match a single ":" for protection labels. We cheat a little
1933 ;; and require a symbol immediately before to avoid false matches
1934 ;; when starting directly on a single ":", which can be the start of
1935 ;; the base class initializer list in a constructor.
1936 c++ "\\([\{\}\(\);,<]+\\|\\(\\w\\|\\s_\\):\\)\\([^:]\\|\\'\\)"
1937 ;; Additionally match the protection directives in Objective-C.
1938 ;; Note that this doesn't cope with the longer directives, which we
1939 ;; would have to match from start to end since they don't end with
1940 ;; any easily recognized characters.
1941 objc (concat "\\([\{\}\(\);,]+\\|"
1942 (c-make-keywords-re nil (c-lang-const c-protection-kwds))
1943 "\\)")
1944 ;; Match ":" for switch labels inside union declarations in IDL.
1945 idl "\\([\{\}\(\);:,]+\\)\\([^:]\\|\\'\\)"
1946 ;; Pike is like C but we also match "[" for multiple value
1947 ;; assignments and type casts.
1948 pike "\\([\{\}\(\)\[;,]+\\)")
1949 (c-lang-defvar c-decl-prefix-re (c-lang-const c-decl-prefix-re)
1950 'dont-doc)
1951
1952 (c-lang-defconst c-cast-parens
1953 ;; List containing the paren characters that can open a cast, or nil in
1954 ;; languages without casts.
1955 t (c-with-syntax-table (c-lang-const c-mode-syntax-table)
1956 (mapcan (lambda (opclass)
1957 (when (eq (car opclass) 'prefix)
1958 (mapcan (lambda (op)
1959 (when (string-match "\\`\\s\(\\'" op)
1960 (list (elt op 0))))
1961 (cdr opclass))))
1962 (c-lang-const c-operators))))
1963 (c-lang-defvar c-cast-parens (c-lang-const c-cast-parens))
1964
1965 (c-lang-defconst c-type-decl-prefix-key
1966 "Regexp matching the operators that might precede the identifier in a
1967 declaration, e.g. the \"*\" in \"char *argv\". This regexp should
1968 match \"(\" if parentheses are valid in type declarations. The end of
1969 the first submatch is taken as the end of the operator. Identifier
1970 syntax is in effect when this is matched (see `c-identifier-syntax-table')."
1971 t (if (c-lang-const c-type-modifier-kwds)
1972 (concat (c-regexp-opt (c-lang-const c-type-modifier-kwds) t) "\\>")
1973 ;; Default to a regexp that never matches.
1974 "\\<\\>")
1975 (c objc) (concat "\\("
1976 "[*\(]"
1977 "\\|"
1978 (c-lang-const c-type-decl-prefix-key)
1979 "\\)"
1980 "\\([^=]\\|$\\)")
1981 c++ (concat "\\("
1982 "[*\(&]"
1983 "\\|"
1984 (concat "\\(" ; 2
1985 ;; If this matches there's special treatment in
1986 ;; `c-font-lock-declarators' and
1987 ;; `c-font-lock-declarations' that check for a
1988 ;; complete name followed by ":: *".
1989 (c-lang-const c-identifier-start)
1990 "\\)")
1991 "\\|"
1992 (c-lang-const c-type-decl-prefix-key)
1993 "\\)"
1994 "\\([^=]\\|$\\)")
1995 pike "\\([*\(!~]\\)\\([^=]\\|$\\)")
1996 (c-lang-defvar c-type-decl-prefix-key (c-lang-const c-type-decl-prefix-key)
1997 'dont-doc)
1998
1999 (c-lang-defconst c-type-decl-suffix-key
2000 "Regexp matching the operators that might follow after the identifier
2001 in a declaration, e.g. the \"[\" in \"char argv[]\". This regexp
2002 should match \")\" if parentheses are valid in type declarations. If
2003 it matches an open paren of some kind, the type declaration check
2004 continues at the corresponding close paren, otherwise the end of the
2005 first submatch is taken as the end of the operator. Identifier syntax
2006 is in effect when this is matched (see `c-identifier-syntax-table')."
2007 ;; Default to a regexp that matches `c-type-modifier-kwds' and a
2008 ;; function argument list parenthesis.
2009 t (if (c-lang-const c-type-modifier-kwds)
2010 (concat "\\(\(\\|"
2011 (c-regexp-opt (c-lang-const c-type-modifier-kwds) t) "\\>"
2012 "\\)")
2013 "\\(\(\\)")
2014 (c c++ objc) (concat
2015 "\\("
2016 "[\)\[\(]"
2017 "\\|"
2018 ;; "throw" in `c-type-modifier-kwds' is followed by a
2019 ;; parenthesis list, but no extra measures are
2020 ;; necessary to handle that.
2021 (c-regexp-opt (c-lang-const c-type-modifier-kwds) t) "\\>"
2022 "\\)")
2023 (java idl) "\\([\[\(]\\)")
2024 (c-lang-defvar c-type-decl-suffix-key (c-lang-const c-type-decl-suffix-key)
2025 'dont-doc)
2026
2027 (c-lang-defconst c-after-suffixed-type-decl-key
2028 "This regexp is matched after a type declaration expression where
2029 `c-type-decl-suffix-key' has matched. If it matches then the
2030 construct is taken as a declaration. It's typically used to match the
2031 beginning of a function body or whatever might occur after the
2032 function header in a function declaration or definition. It's
2033 undefined whether identifier syntax (see `c-identifier-syntax-table')
2034 is in effect or not.
2035
2036 Note that it's used in cases like after \"foo (bar)\" so it should
2037 only match when it's certain that it's a declaration, e.g \"{\" but
2038 not \",\" or \";\"."
2039 t "{"
2040 ;; If K&R style declarations should be recognized then one could
2041 ;; consider to match the start of any symbol since we want to match
2042 ;; the start of the first declaration in the "K&R region". That
2043 ;; could however produce false matches on code like "FOO(bar) x"
2044 ;; where FOO is a cpp macro, so it's better to leave it out and rely
2045 ;; on the other heuristics in that case.
2046 t (if (c-lang-const c-postfix-decl-spec-kwds)
2047 ;; Add on the keywords in `c-postfix-decl-spec-kwds'.
2048 (concat (c-lang-const c-after-suffixed-type-decl-key)
2049 "\\|"
2050 (c-make-keywords-re t (c-lang-const c-postfix-decl-spec-kwds)))
2051 (c-lang-const c-after-suffixed-type-decl-key))
2052 ;; Also match the colon that starts a base class initializer list in
2053 ;; C++. That can be confused with a function call before the colon
2054 ;; in a ? : operator, but we count on that `c-decl-prefix-re' won't
2055 ;; match before such a thing (as a declaration-level construct;
2056 ;; matches inside arglist contexts are already excluded).
2057 c++ "[{:]")
2058 (c-lang-defvar c-after-suffixed-type-decl-key
2059 (c-lang-const c-after-suffixed-type-decl-key)
2060 'dont-doc)
2061
2062 (c-lang-defconst c-after-suffixed-type-maybe-decl-key
2063 ;; Regexp that in addition to `c-after-suffixed-type-decl-key'
2064 ;; matches ";" and ",".
2065 t (concat "\\(" (c-lang-const c-after-suffixed-type-decl-key) "\\)"
2066 "\\|[;,]"))
2067 (c-lang-defvar c-after-suffixed-type-maybe-decl-key
2068 (c-lang-const c-after-suffixed-type-maybe-decl-key))
2069
2070 (c-lang-defconst c-opt-type-concat-key
2071 "Regexp matching operators that concatenate types, e.g. the \"|\" in
2072 \"int|string\" in Pike. The end of the first submatch is taken as the
2073 end of the operator. nil in languages without such operators. It's
2074 undefined whether identifier syntax (see `c-identifier-syntax-table')
2075 is in effect or not."
2076 t nil
2077 pike "\\([|.&]\\)\\($\\|[^|.&]\\)")
2078 (c-lang-defvar c-opt-type-concat-key (c-lang-const c-opt-type-concat-key)
2079 'dont-doc)
2080
2081 (c-lang-defconst c-opt-type-suffix-key
2082 "Regexp matching operators that might follow after a type, or nil in
2083 languages that don't have such operators. The end of the first
2084 submatch is taken as the end of the operator. This should not match
2085 things like C++ template arglists if `c-recognize-<>-arglists' is set.
2086 It's undefined whether identifier syntax (see `c-identifier-syntax-table')
2087 is in effect or not."
2088 t nil
2089 (c c++ objc pike) "\\(\\.\\.\\.\\)"
2090 java "\\(\\[[ \t\n\r\f\v]*\\]\\)")
2091 (c-lang-defvar c-opt-type-suffix-key (c-lang-const c-opt-type-suffix-key))
2092
2093 (c-lang-defvar c-known-type-key
2094 ;; Regexp matching the known type identifiers. This is initialized
2095 ;; from the type keywords and `*-font-lock-extra-types'. The first
2096 ;; submatch is the one that matches the type. Note that this regexp
2097 ;; assumes that symbol constituents like '_' and '$' have word
2098 ;; syntax.
2099 (let ((extra-types (when (boundp (c-mode-symbol "font-lock-extra-types"))
2100 (c-mode-var "font-lock-extra-types"))))
2101 (concat "\\<\\("
2102 (c-make-keywords-re nil (c-lang-const c-primitive-type-kwds))
2103 (if (consp extra-types)
2104 (concat "\\|" (mapconcat 'identity extra-types "\\|"))
2105 "")
2106 "\\)\\>")))
2107
2108 (c-lang-defconst c-special-brace-lists
2109 "List of open- and close-chars that makes up a pike-style brace list,
2110 i.e. for a ([ ]) list there should be a cons (?\\[ . ?\\]) in this
2111 list."
2112 t nil
2113 pike '((?{ . ?}) (?\[ . ?\]) (?< . ?>)))
2114 (c-lang-defvar c-special-brace-lists (c-lang-const c-special-brace-lists))
2115
2116 (c-lang-defconst c-recognize-knr-p
2117 "Non-nil means K&R style argument declarations are valid."
2118 t nil
2119 c t)
2120 (c-lang-defvar c-recognize-knr-p (c-lang-const c-recognize-knr-p))
2121
2122 (c-lang-defconst c-recognize-typeless-decls
2123 "Non-nil means function declarations without return type should be
2124 recognized. That can introduce an ambiguity with parenthesized macro
2125 calls before a brace block. This setting does not affect declarations
2126 that are preceded by a declaration starting keyword, so
2127 e.g. `c-typeless-decl-kwds' may still be used when it's set to nil."
2128 t nil
2129 (c c++ objc) t)
2130 (c-lang-defvar c-recognize-typeless-decls
2131 (c-lang-const c-recognize-typeless-decls))
2132
2133 (c-lang-defconst c-recognize-<>-arglists
2134 "Non-nil means C++ style template arglists should be handled. More
2135 specifically, this means a comma separated list of types or
2136 expressions surrounded by \"<\" and \">\". It's always preceded by an
2137 identifier or one of the keywords on `c-<>-type-kwds' or
2138 `c-<>-arglist-kwds'. If there's an identifier before then the whole
2139 expression is considered to be a type."
2140 t (or (consp (c-lang-const c-<>-type-kwds))
2141 (consp (c-lang-const c-<>-arglist-kwds))))
2142 (c-lang-defvar c-recognize-<>-arglists (c-lang-const c-recognize-<>-arglists))
2143
2144 (c-lang-defconst c-recognize-paren-inits
2145 "Non-nil means that parenthesis style initializers exist,
2146 i.e. constructs like
2147
2148 Foo bar (gnu);
2149
2150 in addition to the more classic
2151
2152 Foo bar = gnu;"
2153 t nil
2154 c++ t)
2155 (c-lang-defvar c-recognize-paren-inits (c-lang-const c-recognize-paren-inits))
2156
2157 (c-lang-defconst c-opt-<>-arglist-start
2158 ;; Regexp matching the start of angle bracket arglists in languages
2159 ;; where `c-recognize-<>-arglists' is set. Does not exclude
2160 ;; keywords outside `c-<>-arglist-kwds'. The first submatch is
2161 ;; assumed to surround the preceding symbol. The whole match is
2162 ;; assumed to end directly after the opening "<".
2163 t (if (c-lang-const c-recognize-<>-arglists)
2164 (concat "\\("
2165 (c-lang-const c-symbol-key)
2166 "\\)"
2167 (c-lang-const c-syntactic-ws)
2168 "<")))
2169 (c-lang-defvar c-opt-<>-arglist-start (c-lang-const c-opt-<>-arglist-start))
2170
2171 (c-lang-defconst c-opt-<>-arglist-start-in-paren
2172 ;; Regexp that in addition to `c-opt-<>-arglist-start' matches close
2173 ;; parens. The first submatch is assumed to surround
2174 ;; `c-opt-<>-arglist-start'.
2175 t (if (c-lang-const c-opt-<>-arglist-start)
2176 (concat "\\("
2177 (c-lang-const c-opt-<>-arglist-start)
2178 "\\)\\|\\s\)")))
2179 (c-lang-defvar c-opt-<>-arglist-start-in-paren
2180 (c-lang-const c-opt-<>-arglist-start-in-paren))
2181
2182 (c-lang-defconst c-label-key
2183 "Regexp matching a normal label, i.e. a label that doesn't begin with
2184 a keyword like switch labels. It's only used at the beginning of a
2185 statement."
2186 t "\\<\\>"
2187 (c c++ objc java pike) (concat "\\(" (c-lang-const c-symbol-key) "\\)"
2188 "[ \t\n\r\f\v]*:\\([^:]\\|$\\)"))
2189 (c-lang-defvar c-label-key (c-lang-const c-label-key)
2190 'dont-doc)
2191
2192 (c-lang-defconst c-opt-postfix-decl-spec-key
2193 ;; Regexp matching the beginning of a declaration specifier in the
2194 ;; region between the header and the body of a declaration.
2195 ;;
2196 ;; TODO: This is currently not used uniformly; c++-mode and
2197 ;; java-mode each have their own ways of using it.
2198 t nil
2199 c++ (concat ":?[ \t\n\r\f\v]*\\(virtual[ \t\n\r\f\v]+\\)?\\("
2200 (c-make-keywords-re nil (c-lang-const c-protection-kwds))
2201 "\\)[ \t\n\r\f\v]+"
2202 "\\(" (c-lang-const c-symbol-key) "\\)")
2203 java (c-make-keywords-re t (c-lang-const c-postfix-decl-spec-kwds)))
2204 (c-lang-defvar c-opt-postfix-decl-spec-key
2205 (c-lang-const c-opt-postfix-decl-spec-key))
2206
2207 (c-lang-defconst c-opt-friend-key
2208 ;; Regexp describing friend declarations classes, or nil in
2209 ;; languages that don't have such things.
2210 ;;
2211 ;; TODO: Ought to use `c-specifier-key' or similar, and the template
2212 ;; skipping isn't done properly. This will disappear soon.
2213 t nil
2214 c++ "friend[ \t]+\\|template[ \t]*<.+>[ \t]*friend[ \t]+")
2215 (c-lang-defvar c-opt-friend-key (c-lang-const c-opt-friend-key))
2216
2217 (c-lang-defconst c-opt-method-key
2218 ;; Special regexp to match the start of Objective-C methods. The
2219 ;; first submatch is assumed to end after the + or - key.
2220 t nil
2221 objc (concat
2222 ;; TODO: Ought to use a better method than anchoring on bol.
2223 "^[ \t]*\\([+-]\\)[ \t\n\r\f\v]*"
2224 "\\(([^)]*)[ \t\n\r\f\v]*\\)?" ; return type
2225 "\\(" (c-lang-const c-symbol-key) "\\)"))
2226 (c-lang-defvar c-opt-method-key (c-lang-const c-opt-method-key))
2227
2228 \f
2229 ;;; Wrap up the `c-lang-defvar' system.
2230
2231 ;; Compile in the list of language variables that has been collected
2232 ;; with the `c-lang-defvar' macro. Note that the first element is
2233 ;; nil.
2234 (defconst c-lang-variable-inits (cc-eval-when-compile c-lang-variable-inits))
2235
2236 (defun c-make-init-lang-vars-fun (mode)
2237 "Create a function that initializes all the language dependent variables
2238 for the given mode.
2239
2240 This function should be evaluated at compile time, so that the
2241 function it returns is byte compiled with all the evaluated results
2242 from the language constants. Use the `c-init-language-vars' macro to
2243 accomplish that conveniently.
2244
2245 This function does not do any hidden buffer changes."
2246
2247 (if (and (not load-in-progress)
2248 (boundp 'byte-compile-dest-file)
2249 (stringp byte-compile-dest-file))
2250
2251 ;; No need to byte compile this lambda since the byte compiler is
2252 ;; smart enough to detect the `funcall' construct in the
2253 ;; `c-init-language-vars' macro below and compile it all straight
2254 ;; into the function that contains `c-init-language-vars'.
2255 `(lambda ()
2256
2257 ;; This let sets up the context for `c-mode-var' and similar
2258 ;; that could be in the result from `cl-macroexpand-all'.
2259 (let ((c-buffer-is-cc-mode ',mode)
2260 current-var)
2261 (condition-case err
2262
2263 (if (eq c-version-sym ',c-version-sym)
2264 (setq ,@(let ((c-buffer-is-cc-mode mode)
2265 (c-lang-const-expansion 'immediate))
2266 ;; `c-lang-const' will expand to the evaluated
2267 ;; constant immediately in `cl-macroexpand-all'
2268 ;; below.
2269 (mapcan
2270 (lambda (init)
2271 `(current-var ',(car init)
2272 ,(car init) ,(cl-macroexpand-all
2273 (elt init 1))))
2274 (cdr c-lang-variable-inits))))
2275
2276 (unless (get ',mode 'c-has-warned-lang-consts)
2277 (message ,(concat "%s compiled with CC Mode %s "
2278 "but loaded with %s - evaluating "
2279 "language constants from source")
2280 ',mode ,c-version c-version)
2281 (put ',mode 'c-has-warned-lang-consts t))
2282
2283 (require 'cc-langs)
2284 (let ((init (cdr c-lang-variable-inits)))
2285 (while init
2286 (setq current-var (caar init))
2287 (set (caar init) (eval (cadar init)))
2288 (setq init (cdr init)))))
2289
2290 (error
2291 (if current-var
2292 (message "Eval error in the `c-lang-defvar' for `%s': %S"
2293 current-var err)
2294 (signal (car err) (cdr err)))))))
2295
2296 ;; Being evaluated from source. Always use the dynamic method to
2297 ;; work well when `c-lang-defvar's in this file are reevaluated
2298 ;; interactively.
2299 `(lambda ()
2300 (require 'cc-langs)
2301 (let ((c-buffer-is-cc-mode ',mode)
2302 (init (cdr c-lang-variable-inits))
2303 current-var)
2304 (condition-case err
2305
2306 (while init
2307 (setq current-var (caar init))
2308 (set (caar init) (eval (cadar init)))
2309 (setq init (cdr init)))
2310
2311 (error
2312 (if current-var
2313 (message "Eval error in the `c-lang-defvar' for `%s': %S"
2314 current-var err)
2315 (signal (car err) (cdr err)))))))
2316 ))
2317
2318 (defmacro c-init-language-vars (mode)
2319 "Initialize all the language dependent variables for the given mode.
2320 This macro is expanded at compile time to a form tailored for the mode
2321 in question, so MODE must be a constant. Therefore MODE is not
2322 evaluated and should not be quoted.
2323
2324 This macro does not do any hidden buffer changes."
2325 `(funcall ,(c-make-init-lang-vars-fun mode)))
2326
2327 \f
2328 (cc-provide 'cc-langs)
2329
2330 ;;; arch-tag: 1ab57482-cfc2-4c5b-b628-3539c3098822
2331 ;;; cc-langs.el ends here