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