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