Merge changes from emacs-23 branch
[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-intro-re
819 "Regexp which matches the start of a CPP directive which contains an
820 expression, or nil if there aren't any in the language."
821 t (if (c-lang-const c-cpp-expr-directives)
822 (concat
823 (c-lang-const c-opt-cpp-prefix)
824 (c-make-keywords-re t (c-lang-const c-cpp-expr-directives)))))
825 (c-lang-defvar c-cpp-expr-intro-re
826 (c-lang-const c-cpp-expr-intro-re))
827
828 (c-lang-defconst c-cpp-expr-functions
829 "List of functions in cpp expressions."
830 t (if (c-lang-const c-opt-cpp-prefix)
831 '("defined"))
832 pike '("defined" "efun" "constant"))
833
834 (c-lang-defconst c-assignment-operators
835 "List of all assignment operators."
836 t '("=" "*=" "/=" "%=" "+=" "-=" ">>=" "<<=" "&=" "^=" "|=")
837 java (append (c-lang-const c-assignment-operators)
838 '(">>>="))
839 c++ (append (c-lang-const c-assignment-operators)
840 '("and_eq" "or_eq" "xor_eq" "??!=" "??'="))
841 idl nil)
842
843 (c-lang-defconst c-operators
844 "List describing all operators, along with their precedence and
845 associativity. The order in the list corresponds to the precedence of
846 the operators: The operators in each element are a group with the same
847 precedence, and the group has higher precedence than the groups in all
848 following elements. The car of each element describes the type of the
849 operator group, and the cdr is a list of the operator tokens in it.
850 The operator group types are:
851
852 'prefix Unary prefix operators.
853 'postfix Unary postfix operators.
854 'postfix-if-paren
855 Unary postfix operators if and only if the chars have
856 parenthesis syntax.
857 'left-assoc Binary left associative operators (i.e. a+b+c means (a+b)+c).
858 'right-assoc Binary right associative operators (i.e. a=b=c means a=(b=c)).
859 'right-assoc-sequence
860 Right associative operator that constitutes of a
861 sequence of tokens that separate expressions. All the
862 tokens in the group are in this case taken as
863 describing the sequence in one such operator, and the
864 order between them is therefore significant.
865
866 Operators containing a character with paren syntax are taken to match
867 with a corresponding open/close paren somewhere else. A postfix
868 operator with close paren syntax is taken to end a postfix expression
869 started somewhere earlier, rather than start a new one at point. Vice
870 versa for prefix operators with open paren syntax.
871
872 Note that operators like \".\" and \"->\" which in language references
873 often are described as postfix operators are considered binary here,
874 since CC Mode treats every identifier as an expression."
875
876 ;; There's currently no code in CC Mode that exploit all the info
877 ;; in this variable; precedence, associativity etc are present as a
878 ;; preparation for future work.
879
880 t `(;; Preprocessor.
881 ,@(when (c-lang-const c-opt-cpp-prefix)
882 `((prefix "#"
883 ,@(when (c-major-mode-is '(c-mode c++-mode))
884 '("%:" "??=")))
885 (left-assoc "##"
886 ,@(when (c-major-mode-is '(c-mode c++-mode))
887 '("%:%:" "??=??=")))))
888
889 ;; Primary.
890 ,@(c-lang-const c-identifier-ops)
891 ,@(cond ((or (c-major-mode-is 'c++-mode) (c-major-mode-is 'java-mode))
892 `((postfix-if-paren "<" ">"))) ; Templates.
893 ((c-major-mode-is 'pike-mode)
894 `((prefix "global" "predef")))
895 ((c-major-mode-is 'java-mode)
896 `((prefix "super"))))
897
898 ;; Postfix.
899 ,@(when (c-major-mode-is 'c++-mode)
900 ;; The following need special treatment.
901 `((prefix "dynamic_cast" "static_cast"
902 "reinterpret_cast" "const_cast" "typeid")))
903 (left-assoc "."
904 ,@(unless (c-major-mode-is 'java-mode)
905 '("->")))
906 (postfix "++" "--" "[" "]" "(" ")"
907 ,@(when (c-major-mode-is '(c-mode c++-mode))
908 '("<:" ":>" "??(" "??)")))
909
910 ;; Unary.
911 (prefix "++" "--" "+" "-" "!" "~"
912 ,@(when (c-major-mode-is 'c++-mode) '("not" "compl"))
913 ,@(when (c-major-mode-is '(c-mode c++-mode))
914 '("*" "&" "sizeof" "??-"))
915 ,@(when (c-major-mode-is 'objc-mode)
916 '("@selector" "@protocol" "@encode"))
917 ;; The following need special treatment.
918 ,@(cond ((c-major-mode-is 'c++-mode)
919 '("new" "delete"))
920 ((c-major-mode-is 'java-mode)
921 '("new"))
922 ((c-major-mode-is 'pike-mode)
923 '("class" "lambda" "catch" "throw" "gauge")))
924 "(" ")" ; Cast.
925 ,@(when (c-major-mode-is 'pike-mode)
926 '("[" "]"))) ; Type cast.
927
928 ;; Member selection.
929 ,@(when (c-major-mode-is 'c++-mode)
930 `((left-assoc ".*" "->*")))
931
932 ;; Multiplicative.
933 (left-assoc "*" "/" "%")
934
935 ;; Additive.
936 (left-assoc "+" "-")
937
938 ;; Shift.
939 (left-assoc "<<" ">>"
940 ,@(when (c-major-mode-is 'java-mode)
941 '(">>>")))
942
943 ;; Relational.
944 (left-assoc "<" ">" "<=" ">="
945 ,@(when (c-major-mode-is 'java-mode)
946 '("instanceof")))
947
948 ;; Equality.
949 (left-assoc "==" "!="
950 ,@(when (c-major-mode-is 'c++-mode) '("not_eq")))
951
952 ;; Bitwise and.
953 (left-assoc "&"
954 ,@(when (c-major-mode-is 'c++-mode) '("bitand")))
955
956 ;; Bitwise exclusive or.
957 (left-assoc "^"
958 ,@(when (c-major-mode-is '(c-mode c++-mode))
959 '("??'"))
960 ,@(when (c-major-mode-is 'c++-mode) '("xor")))
961
962 ;; Bitwise or.
963 (left-assoc "|"
964 ,@(when (c-major-mode-is '(c-mode c++-mode))
965 '("??!"))
966 ,@(when (c-major-mode-is 'c++-mode) '("bitor")))
967
968 ;; Logical and.
969 (left-assoc "&&"
970 ,@(when (c-major-mode-is 'c++-mode) '("and")))
971
972 ;; Logical or.
973 (left-assoc "||"
974 ,@(when (c-major-mode-is '(c-mode c++-mode))
975 '("??!??!"))
976 ,@(when (c-major-mode-is 'c++-mode) '("or")))
977
978 ;; Conditional.
979 (right-assoc-sequence "?" ":")
980
981 ;; Assignment.
982 (right-assoc ,@(c-lang-const c-assignment-operators))
983
984 ;; Exception.
985 ,@(when (c-major-mode-is 'c++-mode)
986 '((prefix "throw")))
987
988 ;; Sequence.
989 (left-assoc ","))
990
991 ;; IDL got its own definition since it has a much smaller operator
992 ;; set than the other languages.
993 idl `(;; Preprocessor.
994 (prefix "#")
995 (left-assoc "##")
996 ;; Primary.
997 ,@(c-lang-const c-identifier-ops)
998 ;; Unary.
999 (prefix "+" "-" "~")
1000 ;; Multiplicative.
1001 (left-assoc "*" "/" "%")
1002 ;; Additive.
1003 (left-assoc "+" "-")
1004 ;; Shift.
1005 (left-assoc "<<" ">>")
1006 ;; And.
1007 (left-assoc "&")
1008 ;; Xor.
1009 (left-assoc "^")
1010 ;; Or.
1011 (left-assoc "|")))
1012
1013 (c-lang-defconst c-operator-list
1014 ;; The operators as a flat list (without duplicates).
1015 t (c-filter-ops (c-lang-const c-operators) t t))
1016
1017 (c-lang-defconst c-overloadable-operators
1018 "List of the operators that are overloadable, in their \"identifier
1019 form\". See also `c-op-identifier-prefix'."
1020 t nil
1021 c++ '("new" "delete" ;; Can be followed by "[]" but we ignore that.
1022 "+" "-" "*" "/" "%"
1023 "^" "??'" "xor" "&" "bitand" "|" "??!" "bitor" "~" "??-" "compl"
1024 "!" "=" "<" ">" "+=" "-=" "*=" "/=" "%=" "^="
1025 "??'=" "xor_eq" "&=" "and_eq" "|=" "??!=" "or_eq"
1026 "<<" ">>" ">>=" "<<=" "==" "!=" "not_eq" "<=" ">="
1027 "&&" "and" "||" "??!??!" "or" "++" "--" "," "->*" "->"
1028 "()" "[]" "<::>" "??(??)")
1029 ;; These work like identifiers in Pike.
1030 pike '("`+" "`-" "`&" "`|" "`^" "`<<" "`>>" "`*" "`/" "`%" "`~"
1031 "`==" "`<" "`>" "`!" "`[]" "`[]=" "`->" "`->=" "`()" "``+"
1032 "``-" "``&" "``|" "``^" "``<<" "``>>" "``*" "``/" "``%"
1033 "`+="))
1034
1035 (c-lang-defconst c-overloadable-operators-regexp
1036 ;; Regexp tested after an "operator" token in C++.
1037 t nil
1038 c++ (c-make-keywords-re nil (c-lang-const c-overloadable-operators)))
1039 (c-lang-defvar c-overloadable-operators-regexp
1040 (c-lang-const c-overloadable-operators-regexp))
1041
1042 (c-lang-defconst c-opt-op-identifier-prefix
1043 "Regexp matching the token before the ones in
1044 `c-overloadable-operators' when operators are specified in their
1045 \"identifier form\". This typically matches \"operator\" in C++ where
1046 operator functions are specified as e.g. \"operator +\". It's nil in
1047 languages without operator functions or where the complete operator
1048 identifier is listed in `c-overloadable-operators'.
1049
1050 This regexp is assumed to not match any non-operator identifier."
1051 t nil
1052 c++ (c-make-keywords-re t '("operator")))
1053 (c-lang-defvar c-opt-op-identifier-prefix
1054 (c-lang-const c-opt-op-identifier-prefix))
1055
1056 ;; Note: the following alias is an old name which was a mis-spelling. It has
1057 ;; been corrected above and throughout cc-engine.el. It will be removed at
1058 ;; some release very shortly in the future. ACM, 2006-04-14.
1059 (defvaralias 'c-opt-op-identitier-prefix 'c-opt-op-identifier-prefix)
1060 (make-obsolete-variable 'c-opt-op-identitier-prefix 'c-opt-op-identifier-prefix
1061 "CC Mode 5.31.4, 2006-04-14")
1062
1063 (c-lang-defconst c-other-op-syntax-tokens
1064 "List of the tokens made up of characters in the punctuation or
1065 parenthesis syntax classes that have uses other than as expression
1066 operators."
1067 t '("{" "}" "(" ")" "[" "]" ";" ":" "," "=" "/*" "*/" "//")
1068 (c c++ pike) (append '("#" "##" ; Used by cpp.
1069 "::" "...")
1070 (c-lang-const c-other-op-syntax-tokens))
1071 (c c++) (append '("*") (c-lang-const c-other-op-syntax-tokens))
1072 c++ (append '("&" "<%" "%>" "<:" ":>" "%:" "%:%:")
1073 (c-lang-const c-other-op-syntax-tokens))
1074 objc (append '("#" "##" ; Used by cpp.
1075 "+" "-") (c-lang-const c-other-op-syntax-tokens))
1076 idl (append '("#" "##") ; Used by cpp.
1077 (c-lang-const c-other-op-syntax-tokens))
1078 pike (append '("..")
1079 (c-lang-const c-other-op-syntax-tokens)
1080 (c-lang-const c-overloadable-operators))
1081 awk '("{" "}" "(" ")" "[" "]" ";" "," "=" "/"))
1082
1083 (c-lang-defconst c-all-op-syntax-tokens
1084 ;; List of all tokens in the punctuation and parenthesis syntax
1085 ;; classes.
1086 t (delete-duplicates (append (c-lang-const c-other-op-syntax-tokens)
1087 (c-lang-const c-operator-list))
1088 :test 'string-equal))
1089
1090 (c-lang-defconst c-nonsymbol-token-char-list
1091 ;; List containing all chars not in the word, symbol or
1092 ;; syntactically irrelevant syntax classes, i.e. all punctuation,
1093 ;; parenthesis and string delimiter chars.
1094 t (c-with-syntax-table (c-lang-const c-mode-syntax-table)
1095 ;; Only go through the chars in the printable ASCII range. No
1096 ;; language so far has 8-bit or widestring operators.
1097 (let (list (char 32))
1098 (while (< char 127)
1099 (or (memq (char-syntax char) '(?w ?_ ?< ?> ?\ ))
1100 (setq list (cons (c-int-to-char char) list)))
1101 (setq char (1+ char)))
1102 list)))
1103
1104 (c-lang-defconst c-nonsymbol-token-regexp
1105 ;; Regexp matching all tokens in the punctuation and parenthesis
1106 ;; syntax classes. Note that this also matches ".", which can start
1107 ;; a float.
1108 t (c-make-keywords-re nil
1109 (c-filter-ops (c-lang-const c-all-op-syntax-tokens)
1110 t
1111 "\\`\\(\\s.\\|\\s\(\\|\\s\)\\)+\\'")))
1112 (c-lang-defvar c-nonsymbol-token-regexp
1113 (c-lang-const c-nonsymbol-token-regexp))
1114
1115 (c-lang-defconst c-assignment-op-regexp
1116 ;; Regexp matching all assignment operators and only them. The
1117 ;; beginning of the first submatch is used to detect the end of the
1118 ;; token, along with the end of the whole match.
1119 t (if (c-lang-const c-assignment-operators)
1120 (concat
1121 ;; Need special case for "=" since it's a prefix of "==".
1122 "=\\([^=]\\|$\\)"
1123 "\\|"
1124 (c-make-keywords-re nil
1125 (set-difference (c-lang-const c-assignment-operators)
1126 '("=")
1127 :test 'string-equal)))
1128 "\\<\\>"))
1129 (c-lang-defvar c-assignment-op-regexp
1130 (c-lang-const c-assignment-op-regexp))
1131
1132 (c-lang-defconst c-<>-multichar-token-regexp
1133 ;; Regexp matching all tokens containing "<" or ">" which are longer
1134 ;; than one char.
1135 t (c-make-keywords-re nil
1136 (c-filter-ops (c-lang-const c-all-op-syntax-tokens)
1137 t
1138 ".[<>]\\|[<>].")))
1139 (c-lang-defvar c-<>-multichar-token-regexp
1140 (c-lang-const c-<>-multichar-token-regexp))
1141
1142 (c-lang-defconst c-<-op-cont-regexp
1143 ;; Regexp matching the second and subsequent characters of all
1144 ;; multicharacter tokens that begin with "<".
1145 t (c-make-keywords-re nil
1146 (c-filter-ops (c-lang-const c-all-op-syntax-tokens)
1147 t
1148 "\\`<."
1149 (lambda (op) (substring op 1)))))
1150
1151 (c-lang-defvar c-<-op-cont-regexp (c-lang-const c-<-op-cont-regexp))
1152
1153 (c-lang-defconst c->-op-cont-regexp
1154 ;; Regexp matching the second and subsequent characters of all
1155 ;; multicharacter tokens that begin with ">".
1156 t (c-make-keywords-re nil
1157 (c-filter-ops (c-lang-const c-all-op-syntax-tokens)
1158 t
1159 "\\`>."
1160 (lambda (op) (substring op 1))))
1161 java (c-make-keywords-re nil
1162 (c-filter-ops (c-lang-const c-all-op-syntax-tokens)
1163 t
1164 "\\`>[^>]\\|\\`>>[^>]"
1165 (lambda (op) (substring op 1)))))
1166
1167 (c-lang-defvar c->-op-cont-regexp (c-lang-const c->-op-cont-regexp))
1168
1169 (c-lang-defconst c-stmt-delim-chars
1170 ;; The characters that should be considered to bound statements. To
1171 ;; optimize `c-crosses-statement-barrier-p' somewhat, it's assumed to
1172 ;; begin with "^" to negate the set. If ? : operators should be
1173 ;; detected then the string must end with "?:".
1174 t "^;{}?:"
1175 awk "^;{}#\n\r?:") ; The newline chars gets special treatment.
1176 (c-lang-defvar c-stmt-delim-chars (c-lang-const c-stmt-delim-chars))
1177
1178 (c-lang-defconst c-stmt-delim-chars-with-comma
1179 ;; Variant of `c-stmt-delim-chars' that additionally contains ','.
1180 t "^;,{}?:"
1181 awk "^;,{}\n\r?:") ; The newline chars gets special treatment.
1182 (c-lang-defvar c-stmt-delim-chars-with-comma
1183 (c-lang-const c-stmt-delim-chars-with-comma))
1184
1185 \f
1186 ;;; Syntactic whitespace.
1187
1188 (c-lang-defconst c-simple-ws
1189 "Regexp matching an ordinary whitespace character.
1190 Does not contain a \\| operator at the top level."
1191 ;; "\\s " is not enough since it doesn't match line breaks.
1192 t "\\(\\s \\|[\n\r]\\)")
1193
1194 (c-lang-defconst c-simple-ws-depth
1195 ;; Number of regexp grouping parens in `c-simple-ws'.
1196 t (regexp-opt-depth (c-lang-const c-simple-ws)))
1197
1198 (c-lang-defconst c-line-comment-starter
1199 "String that starts line comments, or nil if such don't exist.
1200 Line comments are always terminated by newlines. At least one of
1201 `c-block-comment-starter' and this one is assumed to be set.
1202
1203 Note that it's currently not enough to set this to support a new
1204 comment style. Other stuff like the syntax table must also be set up
1205 properly."
1206 t "//"
1207 awk "#")
1208 (c-lang-defvar c-line-comment-starter (c-lang-const c-line-comment-starter))
1209
1210 (c-lang-defconst c-block-comment-starter
1211 "String that starts block comments, or nil if such don't exist.
1212 Block comments are ended by `c-block-comment-ender', which is assumed
1213 to be set if this is. At least one of `c-line-comment-starter' and
1214 this one is assumed to be set.
1215
1216 Note that it's currently not enough to set this to support a new
1217 comment style. Other stuff like the syntax table must also be set up
1218 properly."
1219 t "/*"
1220 awk nil)
1221
1222 (c-lang-defconst c-block-comment-ender
1223 "String that ends block comments, or nil if such don't exist.
1224
1225 Note that it's currently not enough to set this to support a new
1226 comment style. Other stuff like the syntax table must also be set up
1227 properly."
1228 t "*/"
1229 awk nil)
1230
1231 (c-lang-defconst c-comment-start-regexp
1232 ;; Regexp to match the start of any type of comment.
1233 t (let ((re (c-make-keywords-re nil
1234 (list (c-lang-const c-line-comment-starter)
1235 (c-lang-const c-block-comment-starter)))))
1236 (if (memq 'gen-comment-delim c-emacs-features)
1237 (concat re "\\|\\s!")
1238 re)))
1239 (c-lang-defvar c-comment-start-regexp (c-lang-const c-comment-start-regexp))
1240
1241 ;;;; Added by ACM, 2003/9/18.
1242 (c-lang-defconst c-block-comment-start-regexp
1243 ;; Regexp which matches the start of a block comment (if such exists in the
1244 ;; language)
1245 t (if (c-lang-const c-block-comment-starter)
1246 (regexp-quote (c-lang-const c-block-comment-starter))
1247 "\\<\\>"))
1248 (c-lang-defvar c-block-comment-start-regexp
1249 (c-lang-const c-block-comment-start-regexp))
1250
1251 (c-lang-defconst c-literal-start-regexp
1252 ;; Regexp to match the start of comments and string literals.
1253 t (concat (c-lang-const c-comment-start-regexp)
1254 "\\|"
1255 (if (memq 'gen-string-delim c-emacs-features)
1256 "\"|"
1257 "\"")))
1258 (c-lang-defvar c-literal-start-regexp (c-lang-const c-literal-start-regexp))
1259
1260 (c-lang-defconst c-doc-comment-start-regexp
1261 "Regexp to match the start of documentation comments."
1262 t "\\<\\>"
1263 ;; From font-lock.el: `doxygen' uses /*! while others use /**.
1264 (c c++ objc) "/\\*[*!]"
1265 java "/\\*\\*"
1266 pike "/[/*]!")
1267 (c-lang-defvar c-doc-comment-start-regexp
1268 (c-lang-const c-doc-comment-start-regexp))
1269
1270 (c-lang-defconst comment-start
1271 "String that starts comments inserted with M-; etc.
1272 `comment-start' is initialized from this."
1273 ;; Default: Prefer line comments to block comments, and pad with a space.
1274 t (concat (or (c-lang-const c-line-comment-starter)
1275 (c-lang-const c-block-comment-starter))
1276 " ")
1277 ;; In C we still default to the block comment style since line
1278 ;; comments aren't entirely portable.
1279 c "/* ")
1280 (c-lang-setvar comment-start (c-lang-const comment-start))
1281
1282 (c-lang-defconst comment-end
1283 "String that ends comments inserted with M-; etc.
1284 `comment-end' is initialized from this."
1285 ;; Default: Use block comment style if comment-start uses block
1286 ;; comments, and pad with a space in that case.
1287 t (if (string-match (concat "\\`\\("
1288 (c-lang-const c-block-comment-start-regexp)
1289 "\\)")
1290 (c-lang-const comment-start))
1291 (concat " " (c-lang-const c-block-comment-ender))
1292 ""))
1293 (c-lang-setvar comment-end (c-lang-const comment-end))
1294
1295 (c-lang-defconst comment-start-skip
1296 "Regexp to match the start of a comment plus everything up to its body.
1297 `comment-start-skip' is initialized from this."
1298 ;; Default: Allow the last char of the comment starter(s) to be
1299 ;; repeated, then allow any amount of horizontal whitespace.
1300 t (concat "\\("
1301 (c-concat-separated
1302 (mapcar (lambda (cs)
1303 (when cs
1304 (concat (regexp-quote cs) "+")))
1305 (list (c-lang-const c-line-comment-starter)
1306 (c-lang-const c-block-comment-starter)))
1307 "\\|")
1308 "\\)\\s *"))
1309 (c-lang-setvar comment-start-skip (c-lang-const comment-start-skip))
1310
1311 (c-lang-defconst c-syntactic-ws-start
1312 ;; Regexp matching any sequence that can start syntactic whitespace.
1313 ;; The only uncertain case is '#' when there are cpp directives.
1314 t (concat "\\s \\|"
1315 (c-make-keywords-re nil
1316 (append (list (c-lang-const c-line-comment-starter)
1317 (c-lang-const c-block-comment-starter)
1318 (when (c-lang-const c-opt-cpp-prefix)
1319 "#"))
1320 '("\n" "\r")))
1321 "\\|\\\\[\n\r]"
1322 (when (memq 'gen-comment-delim c-emacs-features)
1323 "\\|\\s!")))
1324 (c-lang-defvar c-syntactic-ws-start (c-lang-const c-syntactic-ws-start))
1325
1326 (c-lang-defconst c-syntactic-ws-end
1327 ;; Regexp matching any single character that might end syntactic whitespace.
1328 t (concat "\\s \\|"
1329 (c-make-keywords-re nil
1330 (append (when (c-lang-const c-block-comment-ender)
1331 (list
1332 (string
1333 (elt (c-lang-const c-block-comment-ender)
1334 (1- (length
1335 (c-lang-const c-block-comment-ender)))))))
1336 '("\n" "\r")))
1337 (when (memq 'gen-comment-delim c-emacs-features)
1338 "\\|\\s!")))
1339 (c-lang-defvar c-syntactic-ws-end (c-lang-const c-syntactic-ws-end))
1340
1341 (c-lang-defconst c-unterminated-block-comment-regexp
1342 ;; Regexp matching an unterminated block comment that doesn't
1343 ;; contain line breaks, or nil in languages without block comments.
1344 ;; Does not contain a \| operator at the top level.
1345 t (when (c-lang-const c-block-comment-starter)
1346 (concat
1347 (regexp-quote (c-lang-const c-block-comment-starter))
1348 ;; It's messy to cook together a regexp that matches anything
1349 ;; but c-block-comment-ender.
1350 (let ((end (c-lang-const c-block-comment-ender)))
1351 (cond ((= (length end) 1)
1352 (concat "[^" end "\n\r]*"))
1353 ((= (length end) 2)
1354 (concat "[^" (substring end 0 1) "\n\r]*"
1355 "\\("
1356 (regexp-quote (substring end 0 1)) "+"
1357 "[^"
1358 ;; The quoting rules inside char classes are silly. :P
1359 (cond ((= (elt end 0) (elt end 1))
1360 (concat (substring end 0 1) "\n\r"))
1361 ((= (elt end 1) ?\])
1362 (concat (substring end 1 2) "\n\r"
1363 (substring end 0 1)))
1364 (t
1365 (concat (substring end 0 1) "\n\r"
1366 (substring end 1 2))))
1367 "]"
1368 "[^" (substring end 0 1) "\n\r]*"
1369 "\\)*"))
1370 (t
1371 (error "Can't handle a block comment ender of length %s"
1372 (length end))))))))
1373
1374 (c-lang-defconst c-block-comment-regexp
1375 ;; Regexp matching a block comment that doesn't contain line breaks,
1376 ;; or nil in languages without block comments. The reason we don't
1377 ;; allow line breaks is to avoid going very far and risk running out
1378 ;; of regexp stack; this regexp is intended to handle only short
1379 ;; comments that might be put in the middle of limited constructs
1380 ;; like declarations. Does not contain a \| operator at the top
1381 ;; level.
1382 t (when (c-lang-const c-unterminated-block-comment-regexp)
1383 (concat
1384 (c-lang-const c-unterminated-block-comment-regexp)
1385 (let ((end (c-lang-const c-block-comment-ender)))
1386 (cond ((= (length end) 1)
1387 (regexp-quote end))
1388 ((= (length end) 2)
1389 (concat (regexp-quote (substring end 0 1)) "+"
1390 (regexp-quote (substring end 1 2))))
1391 (t
1392 (error "Can't handle a block comment ender of length %s"
1393 (length end))))))))
1394
1395 (c-lang-defconst c-nonwhite-syntactic-ws
1396 ;; Regexp matching a piece of syntactic whitespace that isn't a
1397 ;; sequence of simple whitespace characters. As opposed to
1398 ;; `c-(forward|backward)-syntactic-ws', this doesn't regard cpp
1399 ;; directives as syntactic whitespace.
1400 t (c-concat-separated
1401 (list (when (c-lang-const c-line-comment-starter)
1402 (concat (regexp-quote (c-lang-const c-line-comment-starter))
1403 "[^\n\r]*[\n\r]"))
1404 (c-lang-const c-block-comment-regexp)
1405 "\\\\[\n\r]"
1406 (when (memq 'gen-comment-delim c-emacs-features)
1407 "\\s!\\S!*\\s!"))
1408 "\\|"))
1409
1410 (c-lang-defconst c-syntactic-ws
1411 ;; Regexp matching syntactic whitespace, including possibly the
1412 ;; empty string. As opposed to `c-(forward|backward)-syntactic-ws',
1413 ;; this doesn't regard cpp directives as syntactic whitespace. Does
1414 ;; not contain a \| operator at the top level.
1415 t (concat (c-lang-const c-simple-ws) "*"
1416 "\\("
1417 (concat "\\(" (c-lang-const c-nonwhite-syntactic-ws) "\\)"
1418 (c-lang-const c-simple-ws) "*")
1419 "\\)*"))
1420
1421 (c-lang-defconst c-syntactic-ws-depth
1422 ;; Number of regexp grouping parens in `c-syntactic-ws'.
1423 t (regexp-opt-depth (c-lang-const c-syntactic-ws)))
1424
1425 (c-lang-defconst c-nonempty-syntactic-ws
1426 ;; Regexp matching syntactic whitespace, which is at least one
1427 ;; character long. As opposed to `c-(forward|backward)-syntactic-ws',
1428 ;; this doesn't regard cpp directives as syntactic whitespace. Does
1429 ;; not contain a \| operator at the top level.
1430 t (concat "\\("
1431 (c-lang-const c-simple-ws)
1432 "\\|"
1433 (c-lang-const c-nonwhite-syntactic-ws)
1434 "\\)+"))
1435
1436 (c-lang-defconst c-nonempty-syntactic-ws-depth
1437 ;; Number of regexp grouping parens in `c-nonempty-syntactic-ws'.
1438 t (regexp-opt-depth (c-lang-const c-nonempty-syntactic-ws)))
1439
1440 (c-lang-defconst c-single-line-syntactic-ws
1441 ;; Regexp matching syntactic whitespace without any line breaks. As
1442 ;; opposed to `c-(forward|backward)-syntactic-ws', this doesn't
1443 ;; regard cpp directives as syntactic whitespace. Does not contain
1444 ;; a \| operator at the top level.
1445 t (if (c-lang-const c-block-comment-regexp)
1446 (concat "\\s *\\("
1447 (c-lang-const c-block-comment-regexp)
1448 "\\s *\\)*")
1449 "\\s *"))
1450
1451 (c-lang-defconst c-single-line-syntactic-ws-depth
1452 ;; Number of regexp grouping parens in `c-single-line-syntactic-ws'.
1453 t (regexp-opt-depth (c-lang-const c-single-line-syntactic-ws)))
1454
1455 (c-lang-defconst c-syntactic-eol
1456 ;; Regexp that matches when there is no syntactically significant
1457 ;; text before eol. Macros are regarded as syntactically
1458 ;; significant text here.
1459 t (concat (c-lang-const c-single-line-syntactic-ws)
1460 ;; Match eol (possibly inside a block comment or preceded
1461 ;; by a line continuation backslash), or the beginning of a
1462 ;; line comment. Note: This has to be modified for awk
1463 ;; where line comments start with '#'.
1464 "\\("
1465 (c-concat-separated
1466 (list (when (c-lang-const c-line-comment-starter)
1467 (regexp-quote (c-lang-const c-line-comment-starter)))
1468 (when (c-lang-const c-unterminated-block-comment-regexp)
1469 (concat (c-lang-const c-unterminated-block-comment-regexp)
1470 "$"))
1471 "\\\\$"
1472 "$")
1473 "\\|")
1474 "\\)"))
1475 (c-lang-defvar c-syntactic-eol (c-lang-const c-syntactic-eol))
1476
1477 \f
1478 ;;; Syntactic analysis ("virtual semicolons") for line-oriented languages (AWK).
1479 (c-lang-defconst c-at-vsemi-p-fn
1480 "Contains a function \"Is there a virtual semicolon at POS or point?\".
1481 Such a function takes one optional parameter, a buffer position (defaults to
1482 point), and returns nil or t. This variable contains nil for languages which
1483 don't have EOL terminated statements. "
1484 t nil
1485 awk 'c-awk-at-vsemi-p)
1486 (c-lang-defvar c-at-vsemi-p-fn (c-lang-const c-at-vsemi-p-fn))
1487
1488 (c-lang-defconst c-vsemi-status-unknown-p-fn
1489 "Contains a function \"are we unsure whether there is a virtual semicolon on this line?\".
1490 The (admittedly kludgey) purpose of such a function is to prevent an infinite
1491 recursion in c-beginning-of-statement-1 when point starts at a `while' token.
1492 The function MUST NOT UNDER ANY CIRCUMSTANCES call c-beginning-of-statement-1,
1493 even indirectly. This variable contains nil for languages which don't have
1494 EOL terminated statements."
1495 t nil
1496 awk 'c-awk-vsemi-status-unknown-p)
1497 (c-lang-defvar c-vsemi-status-unknown-p-fn
1498 (c-lang-const c-vsemi-status-unknown-p-fn))
1499
1500 \f
1501 ;;; Defun functions
1502
1503 ;; The Emacs variables beginning-of-defun-function and
1504 ;; end-of-defun-function will be set so that commands like
1505 ;; `mark-defun' and `narrow-to-defun' work right. The key sequences
1506 ;; C-M-a and C-M-e are, however, bound directly to the CC Mode
1507 ;; functions, allowing optimisation for large n.
1508 (c-lang-defconst beginning-of-defun-function
1509 "Function to which beginning-of-defun-function will be set."
1510 t 'c-beginning-of-defun
1511 awk 'c-awk-beginning-of-defun)
1512 (c-lang-setvar beginning-of-defun-function
1513 (c-lang-const beginning-of-defun-function))
1514
1515 (c-lang-defconst end-of-defun-function
1516 "Function to which end-of-defun-function will be set."
1517 t 'c-end-of-defun
1518 awk 'c-awk-end-of-defun)
1519 (c-lang-setvar end-of-defun-function (c-lang-const end-of-defun-function))
1520 \f
1521 ;;; In-comment text handling.
1522
1523 (c-lang-defconst c-paragraph-start
1524 "Regexp to append to `paragraph-start'."
1525 t "$"
1526 java "\\(@[a-zA-Z]+\\>\\|$\\)" ; For Javadoc.
1527 pike "\\(@[a-zA-Z_-]+\\>\\([^{]\\|$\\)\\|$\\)") ; For Pike refdoc.
1528 (c-lang-defvar c-paragraph-start (c-lang-const c-paragraph-start))
1529
1530 (c-lang-defconst c-paragraph-separate
1531 "Regexp to append to `paragraph-separate'."
1532 t "$"
1533 pike (c-lang-const c-paragraph-start))
1534 (c-lang-defvar c-paragraph-separate (c-lang-const c-paragraph-separate))
1535
1536 \f
1537 ;;; Keyword lists.
1538
1539 ;; Note: All and only all language constants containing keyword lists
1540 ;; should end with "-kwds"; they're automatically collected into the
1541 ;; `c-kwds-lang-consts' list below and used to build `c-keywords' etc.
1542
1543 (c-lang-defconst c-primitive-type-kwds
1544 "Primitive type keywords. As opposed to the other keyword lists, the
1545 keywords listed here are fontified with the type face instead of the
1546 keyword face.
1547
1548 If any of these also are on `c-type-list-kwds', `c-ref-list-kwds',
1549 `c-colon-type-list-kwds', `c-paren-nontype-kwds', `c-paren-type-kwds',
1550 `c-<>-type-kwds', or `c-<>-arglist-kwds' then the associated clauses
1551 will be handled.
1552
1553 Do not try to modify this list for end user customizations; the
1554 `*-font-lock-extra-types' variable, where `*' is the mode prefix, is
1555 the appropriate place for that."
1556 t '("char" "double" "float" "int" "long" "short" "signed"
1557 "unsigned" "void")
1558 c (append
1559 '("_Bool" "_Complex" "_Imaginary") ; Conditionally defined in C99.
1560 (c-lang-const c-primitive-type-kwds))
1561 c++ (append
1562 '("bool" "wchar_t")
1563 (c-lang-const c-primitive-type-kwds))
1564 ;; Objective-C extends C, but probably not the new stuff in C99.
1565 objc (append
1566 '("id" "Class" "SEL" "IMP" "BOOL")
1567 (c-lang-const c-primitive-type-kwds))
1568 java '("boolean" "byte" "char" "double" "float" "int" "long" "short" "void")
1569 idl '("Object" "ValueBase" "any" "boolean" "char" "double" "fixed" "float"
1570 "long" "octet" "sequence" "short" "string" "void" "wchar" "wstring"
1571 ;; In CORBA PSDL:
1572 "ref"
1573 ;; The following can't really end a type, but we have to specify them
1574 ;; here due to the assumption in `c-primitive-type-prefix-kwds'. It
1575 ;; doesn't matter that much.
1576 "unsigned" "strong")
1577 pike '(;; this_program isn't really a keyword, but it's practically
1578 ;; used as a builtin type.
1579 "array" "float" "function" "int" "mapping" "mixed" "multiset"
1580 "object" "program" "string" "this_program" "void"))
1581
1582 (c-lang-defconst c-primitive-type-key
1583 ;; An adorned regexp that matches `c-primitive-type-kwds'.
1584 t (c-make-keywords-re t (c-lang-const c-primitive-type-kwds)))
1585 (c-lang-defvar c-primitive-type-key (c-lang-const c-primitive-type-key))
1586
1587 (c-lang-defconst c-primitive-type-prefix-kwds
1588 "Keywords that might act as prefixes for primitive types. Assumed to
1589 be a subset of `c-primitive-type-kwds'."
1590 t nil
1591 (c c++) '("long" "short" "signed" "unsigned")
1592 idl '("long" "unsigned"
1593 ;; In CORBA PSDL:
1594 "strong"))
1595
1596 (c-lang-defconst c-typedef-kwds
1597 "Prefix keyword\(s\) like \"typedef\" which make a type declaration out
1598 of a variable declaration."
1599 t '("typedef")
1600 (awk idl java) nil)
1601
1602 (c-lang-defconst c-typedef-key
1603 ;; Adorned regexp matching `c-typedef-kwds'.
1604 t (c-make-keywords-re t (c-lang-const c-typedef-kwds)))
1605 (c-lang-defvar c-typedef-key (c-lang-const c-typedef-key))
1606
1607 (c-lang-defconst c-type-prefix-kwds
1608 "Keywords where the following name - if any - is a type name, and
1609 where the keyword together with the symbol works as a type in
1610 declarations.
1611
1612 Note that an alternative if the second part doesn't hold is
1613 `c-type-list-kwds'. Keywords on this list are typically also present
1614 on one of the `*-decl-kwds' lists."
1615 t nil
1616 c '("struct" "union" "enum")
1617 c++ (append '("class" "typename")
1618 (c-lang-const c-type-prefix-kwds c)))
1619
1620 (c-lang-defconst c-type-prefix-key
1621 ;; Adorned regexp matching `c-type-prefix-kwds'.
1622 t (c-make-keywords-re t (c-lang-const c-type-prefix-kwds)))
1623 (c-lang-defvar c-type-prefix-key (c-lang-const c-type-prefix-key))
1624
1625 (c-lang-defconst c-type-modifier-kwds
1626 "Type modifier keywords. These can occur almost anywhere in types
1627 but they don't build a type of themselves. Unlike the keywords on
1628 `c-primitive-type-kwds', they are fontified with the keyword face and
1629 not the type face."
1630 t nil
1631 c '("const" "restrict" "volatile")
1632 c++ '("const" "volatile" "throw")
1633 objc '("const" "volatile"))
1634
1635 (c-lang-defconst c-opt-type-modifier-key
1636 ;; Adorned regexp matching `c-type-modifier-kwds', or nil in
1637 ;; languages without such keywords.
1638 t (and (c-lang-const c-type-modifier-kwds)
1639 (c-make-keywords-re t (c-lang-const c-type-modifier-kwds))))
1640 (c-lang-defvar c-opt-type-modifier-key (c-lang-const c-opt-type-modifier-key))
1641
1642 (c-lang-defconst c-opt-type-component-key
1643 ;; An adorned regexp that matches `c-primitive-type-prefix-kwds' and
1644 ;; `c-type-modifier-kwds', or nil in languages without any of them.
1645 t (and (or (c-lang-const c-primitive-type-prefix-kwds)
1646 (c-lang-const c-type-modifier-kwds))
1647 (c-make-keywords-re t
1648 (append (c-lang-const c-primitive-type-prefix-kwds)
1649 (c-lang-const c-type-modifier-kwds)))))
1650 (c-lang-defvar c-opt-type-component-key
1651 (c-lang-const c-opt-type-component-key))
1652
1653 (c-lang-defconst c-type-start-kwds
1654 ;; All keywords that can start a type (i.e. are either a type prefix
1655 ;; or a complete type).
1656 t (delete-duplicates (append (c-lang-const c-primitive-type-kwds)
1657 (c-lang-const c-type-prefix-kwds)
1658 (c-lang-const c-type-modifier-kwds))
1659 :test 'string-equal))
1660
1661 (c-lang-defconst c-class-decl-kwds
1662 "Keywords introducing declarations where the following block (if any)
1663 contains another declaration level that should be considered a class.
1664
1665 If any of these also are on `c-type-list-kwds', `c-ref-list-kwds',
1666 `c-colon-type-list-kwds', `c-paren-nontype-kwds', `c-paren-type-kwds',
1667 `c-<>-type-kwds', or `c-<>-arglist-kwds' then the associated clauses
1668 will be handled.
1669
1670 Note that presence on this list does not automatically treat the
1671 following identifier as a type; the keyword must also be present on
1672 `c-type-prefix-kwds' or `c-type-list-kwds' to accomplish that."
1673 t nil
1674 c '("struct" "union")
1675 c++ '("class" "struct" "union")
1676 objc '("struct" "union"
1677 "@interface" "@implementation" "@protocol")
1678 java '("class" "@interface" "interface")
1679 idl '("component" "eventtype" "exception" "home" "interface" "struct"
1680 "union" "valuetype"
1681 ;; In CORBA PSDL:
1682 "storagehome" "storagetype"
1683 ;; In CORBA CIDL:
1684 "catalog" "executor" "manages" "segment")
1685 pike '("class"))
1686
1687 (c-lang-defconst c-class-key
1688 ;; Regexp matching the start of a class.
1689 t (c-make-keywords-re t (c-lang-const c-class-decl-kwds)))
1690 (c-lang-defvar c-class-key (c-lang-const c-class-key))
1691
1692 (c-lang-defconst c-brace-list-decl-kwds
1693 "Keywords introducing declarations where the following block (if
1694 any) is a brace list.
1695
1696 If any of these also are on `c-type-list-kwds', `c-ref-list-kwds',
1697 `c-colon-type-list-kwds', `c-paren-nontype-kwds', `c-paren-type-kwds',
1698 `c-<>-type-kwds', or `c-<>-arglist-kwds' then the associated clauses
1699 will be handled."
1700 t '("enum")
1701 (awk) nil)
1702
1703 (c-lang-defconst c-brace-list-key
1704 ;; Regexp matching the start of declarations where the following
1705 ;; block is a brace list.
1706 t (c-make-keywords-re t (c-lang-const c-brace-list-decl-kwds)))
1707 (c-lang-defvar c-brace-list-key (c-lang-const c-brace-list-key))
1708
1709 (c-lang-defconst c-other-block-decl-kwds
1710 "Keywords where the following block (if any) contains another
1711 declaration level that should not be considered a class. For every
1712 keyword here, CC Mode will add a set of special syntactic symbols for
1713 those blocks. E.g. if the keyword is \"foo\" then there will be
1714 `foo-open', `foo-close', and `infoo' symbols.
1715
1716 The intention is that this category should be used for block
1717 constructs that aren't related to object orientation concepts like
1718 classes (which thus also include e.g. interfaces, templates,
1719 contracts, structs, etc). The more pragmatic distinction is that
1720 while most want some indentation inside classes, it's fairly common
1721 that they don't want it in some of these constructs, so it should be
1722 simple to configure that differently from classes. See also
1723 `c-class-decl-kwds'.
1724
1725 If any of these also are on `c-type-list-kwds', `c-ref-list-kwds',
1726 `c-colon-type-list-kwds', `c-paren-nontype-kwds', `c-paren-type-kwds',
1727 `c-<>-type-kwds', or `c-<>-arglist-kwds' then the associated clauses
1728 will be handled."
1729 t nil
1730 (c objc) '("extern")
1731 c++ '("namespace" "extern")
1732 idl '("module"
1733 ;; In CORBA CIDL:
1734 "composition"))
1735
1736 (c-lang-defconst c-other-decl-block-key
1737 ;; Regexp matching the start of blocks besides classes that contain
1738 ;; another declaration level.
1739 t (c-make-keywords-re t (c-lang-const c-other-block-decl-kwds)))
1740 (c-lang-defvar c-other-decl-block-key (c-lang-const c-other-decl-block-key))
1741
1742 (c-lang-defvar c-other-decl-block-key-in-symbols-alist
1743 (mapcar
1744 (lambda (elt)
1745 (cons elt
1746 (if (string= elt "extern")
1747 'inextern-lang
1748 (intern (concat "in" elt)))))
1749 (c-lang-const c-other-block-decl-kwds))
1750 "Alist associating keywords in c-other-decl-block-decl-kwds with
1751 their matching \"in\" syntactic symbols.")
1752
1753 (c-lang-defconst c-typedef-decl-kwds
1754 "Keywords introducing declarations where the identifier(s) being
1755 declared are types.
1756
1757 If any of these also are on `c-type-list-kwds', `c-ref-list-kwds',
1758 `c-colon-type-list-kwds', `c-paren-nontype-kwds', `c-paren-type-kwds',
1759 `c-<>-type-kwds', or `c-<>-arglist-kwds' then the associated clauses
1760 will be handled."
1761 ;; Default to `c-class-decl-kwds' and `c-brace-list-decl-kwds'
1762 ;; (since e.g. "Foo" is a type that's being defined in "class Foo
1763 ;; {...}").
1764 t (append (c-lang-const c-class-decl-kwds)
1765 (c-lang-const c-brace-list-decl-kwds))
1766 ;; Languages that have a "typedef" construct.
1767 (c c++ objc idl pike) (append (c-lang-const c-typedef-decl-kwds)
1768 '("typedef"))
1769 ;; Unlike most other languages, exception names are not handled as
1770 ;; types in IDL since they only can occur in "raises" specs.
1771 idl (delete "exception" (append (c-lang-const c-typedef-decl-kwds) nil)))
1772
1773 (c-lang-defconst c-typedef-decl-key
1774 t (c-make-keywords-re t (c-lang-const c-typedef-decl-kwds)))
1775 (c-lang-defvar c-typedef-decl-key (c-lang-const c-typedef-decl-key))
1776
1777 (c-lang-defconst c-typeless-decl-kwds
1778 "Keywords introducing declarations where the \(first) identifier
1779 \(declarator) follows directly after the keyword, without any type.
1780
1781 If any of these also are on `c-type-list-kwds', `c-ref-list-kwds',
1782 `c-colon-type-list-kwds', `c-paren-nontype-kwds', `c-paren-type-kwds',
1783 `c-<>-type-kwds', or `c-<>-arglist-kwds' then the associated clauses
1784 will be handled."
1785 ;; Default to `c-class-decl-kwds' and `c-brace-list-decl-kwds'
1786 ;; (since e.g. "Foo" is the identifier being defined in "class Foo
1787 ;; {...}").
1788 t (append (c-lang-const c-class-decl-kwds)
1789 (c-lang-const c-brace-list-decl-kwds))
1790 ;; Note: "manages" for CORBA CIDL clashes with its presence on
1791 ;; `c-type-list-kwds' for IDL.
1792 idl (append (c-lang-const c-typeless-decl-kwds)
1793 '("factory" "finder" "native"
1794 ;; In CORBA PSDL:
1795 "key" "stores"
1796 ;; In CORBA CIDL:
1797 "facet"))
1798 pike (append (c-lang-const c-class-decl-kwds)
1799 '("constant")))
1800
1801 (c-lang-defconst c-modifier-kwds
1802 "Keywords that can prefix normal declarations of identifiers
1803 \(and typically act as flags). Things like argument declarations
1804 inside function headers are also considered declarations in this
1805 sense.
1806
1807 If any of these also are on `c-type-list-kwds', `c-ref-list-kwds',
1808 `c-colon-type-list-kwds', `c-paren-nontype-kwds', `c-paren-type-kwds',
1809 `c-<>-type-kwds', or `c-<>-arglist-kwds' then the associated clauses
1810 will be handled."
1811 t nil
1812 (c c++) '("auto" "extern" "inline" "register" "static")
1813 c++ (append '("explicit" "friend" "mutable" "template" "using" "virtual")
1814 (c-lang-const c-modifier-kwds))
1815 objc '("auto" "bycopy" "byref" "extern" "in" "inout" "oneway" "out" "static")
1816 ;; FIXME: Some of those below ought to be on `c-other-decl-kwds' instead.
1817 idl '("abstract" "attribute" "const" "consumes" "custom" "emits" "import"
1818 "in" "inout" "local" "multiple" "oneway" "out" "private" "provides"
1819 "public" "publishes" "readonly" "typeid" "typeprefix" "uses"
1820 ;; In CORBA PSDL:
1821 "primary" "state"
1822 ;; In CORBA CIDL:
1823 "bindsTo" "delegatesTo" "implements" "proxy" "storedOn")
1824 ;; Note: "const" is not used in Java, but it's still a reserved keyword.
1825 java '("abstract" "const" "final" "native" "private" "protected" "public"
1826 "static" "strictfp" "synchronized" "transient" "volatile")
1827 pike '("final" "inline" "local" "nomask" "optional" "private" "protected"
1828 "public" "static" "variant"))
1829
1830 (c-lang-defconst c-other-decl-kwds
1831 "Keywords that can start or prefix any declaration level construct,
1832 besides those on `c-class-decl-kwds', `c-brace-list-decl-kwds',
1833 `c-other-block-decl-kwds', `c-typedef-decl-kwds',
1834 `c-typeless-decl-kwds' and `c-modifier-kwds'.
1835
1836 If any of these also are on `c-type-list-kwds', `c-ref-list-kwds',
1837 `c-colon-type-list-kwds', `c-paren-nontype-kwds', `c-paren-type-kwds',
1838 `c-<>-type-kwds', or `c-<>-arglist-kwds' then the associated clauses
1839 will be handled."
1840 t nil
1841 objc '("@class" "@end" "@defs")
1842 java '("import" "package")
1843 pike '("import" "inherit"))
1844
1845 (c-lang-defconst c-decl-start-kwds
1846 "Keywords that always start declarations, wherever they occur.
1847 This can be used for declarations that aren't recognized by the normal
1848 combination of `c-decl-prefix-re' and `c-decl-start-re'."
1849 t nil
1850 ;; Classes can be declared anywhere in a Pike expression.
1851 pike '("class"))
1852
1853 (c-lang-defconst c-decl-hangon-kwds
1854 "Keywords that can occur anywhere in a declaration level construct.
1855 This is used for self-contained things that can be tacked on anywhere
1856 on a declaration and that should be ignored to be able to recognize it
1857 correctly. Typical cases are compiler extensions like
1858 \"__attribute__\" or \"__declspec\":
1859
1860 __declspec(noreturn) void foo();
1861 class __declspec(dllexport) classname {...};
1862 void foo() __attribute__((noreturn));
1863
1864 Note that unrecognized plain symbols are skipped anyway if they occur
1865 before the type, so such things are not necessary to mention here.
1866 Mentioning them here is necessary only if they can occur in other
1867 places, or if they are followed by a construct that must be skipped
1868 over \(like the parens in the \"__attribute__\" and \"__declspec\"
1869 examples above). In the last case, they alse need to be present on
1870 one of `c-type-list-kwds', `c-ref-list-kwds',
1871 `c-colon-type-list-kwds', `c-paren-nontype-kwds', `c-paren-type-kwds',
1872 `c-<>-type-kwds', or `c-<>-arglist-kwds'."
1873 ;; NB: These are currently not recognized in all parts of a
1874 ;; declaration. Specifically, they aren't recognized in the middle
1875 ;; of multi-token types, inside declarators, and between the
1876 ;; identifier and the arglist paren of a function declaration.
1877 ;;
1878 ;; FIXME: This ought to be user customizable since compiler stuff
1879 ;; like this usually is wrapped in project specific macros. (It'd
1880 ;; of course be even better if we could cope without knowing this.)
1881 t nil
1882 (c c++) '(;; GCC extension.
1883 "__attribute__"
1884 ;; MSVC extension.
1885 "__declspec"))
1886
1887 (c-lang-defconst c-decl-hangon-key
1888 ;; Adorned regexp matching `c-decl-hangon-kwds'.
1889 t (c-make-keywords-re t (c-lang-const c-decl-hangon-kwds)))
1890 (c-lang-defvar c-decl-hangon-key (c-lang-const c-decl-hangon-key))
1891
1892 (c-lang-defconst c-prefix-spec-kwds
1893 ;; All keywords that can occur in the preamble of a declaration.
1894 ;; They typically occur before the type, but they are also matched
1895 ;; after presumptive types since we often can't be sure that
1896 ;; something is a type or just some sort of macro in front of the
1897 ;; declaration. They might be ambiguous with types or type
1898 ;; prefixes.
1899 t (delete-duplicates (append (c-lang-const c-class-decl-kwds)
1900 (c-lang-const c-brace-list-decl-kwds)
1901 (c-lang-const c-other-block-decl-kwds)
1902 (c-lang-const c-typedef-decl-kwds)
1903 (c-lang-const c-typeless-decl-kwds)
1904 (c-lang-const c-modifier-kwds)
1905 (c-lang-const c-other-decl-kwds)
1906 (c-lang-const c-decl-start-kwds)
1907 (c-lang-const c-decl-hangon-kwds))
1908 :test 'string-equal))
1909
1910 (c-lang-defconst c-prefix-spec-kwds-re
1911 ;; Adorned regexp of `c-prefix-spec-kwds'.
1912 t (c-make-keywords-re t (c-lang-const c-prefix-spec-kwds)))
1913
1914 (c-lang-defvar c-prefix-spec-kwds-re (c-lang-const c-prefix-spec-kwds-re))
1915
1916 (c-lang-defconst c-specifier-key
1917 ;; Adorned regexp of the keywords in `c-prefix-spec-kwds' that aren't
1918 ;; ambiguous with types or type prefixes. These are the keywords (like
1919 ;; extern, namespace, but NOT template) that can modify a declaration.
1920 t (c-make-keywords-re t
1921 (set-difference (c-lang-const c-prefix-spec-kwds)
1922 (append (c-lang-const c-type-start-kwds)
1923 (c-lang-const c-<>-arglist-kwds))
1924 :test 'string-equal)))
1925 (c-lang-defvar c-specifier-key (c-lang-const c-specifier-key))
1926
1927 (c-lang-defconst c-postfix-spec-kwds
1928 ;; Keywords that can occur after argument list of a function header
1929 ;; declaration, i.e. in the "K&R region".
1930 t (append (c-lang-const c-postfix-decl-spec-kwds)
1931 (c-lang-const c-decl-hangon-kwds)))
1932
1933 (c-lang-defconst c-not-decl-init-keywords
1934 ;; Adorned regexp matching all keywords that can't appear at the
1935 ;; start of a declaration.
1936 t (c-make-keywords-re t
1937 (set-difference (c-lang-const c-keywords)
1938 (append (c-lang-const c-type-start-kwds)
1939 (c-lang-const c-prefix-spec-kwds))
1940 :test 'string-equal)))
1941 (c-lang-defvar c-not-decl-init-keywords
1942 (c-lang-const c-not-decl-init-keywords))
1943
1944 (c-lang-defconst c-not-primitive-type-keywords
1945 "List of all keywords apart from primitive types (like \"int\")."
1946 t (set-difference (c-lang-const c-keywords)
1947 (c-lang-const c-primitive-type-kwds)
1948 :test 'string-equal)
1949 ;; The "more" for C++ is the QT keyword (as in "more slots:").
1950 ;; This variable is intended for use in c-beginning-of-statement-1.
1951 c++ (append (c-lang-const c-not-primitive-type-keywords) '("more")))
1952
1953 (c-lang-defconst c-not-primitive-type-keywords-regexp
1954 t (c-make-keywords-re t
1955 (c-lang-const c-not-primitive-type-keywords)))
1956 (c-lang-defvar c-not-primitive-type-keywords-regexp
1957 (c-lang-const c-not-primitive-type-keywords-regexp))
1958
1959 (c-lang-defconst c-protection-kwds
1960 "Access protection label keywords in classes."
1961 t nil
1962 c++ '("private" "protected" "public")
1963 objc '("@private" "@protected" "@public"))
1964
1965 (c-lang-defconst c-block-decls-with-vars
1966 "Keywords introducing declarations that can contain a block which
1967 might be followed by variable declarations, e.g. like \"foo\" in
1968 \"class Foo { ... } foo;\". So if there is a block in a declaration
1969 like that, it ends with the following ';' and not right away.
1970
1971 The keywords on list are assumed to also be present on one of the
1972 `*-decl-kwds' lists."
1973 t nil
1974 (c objc) '("struct" "union" "enum" "typedef")
1975 c++ '("class" "struct" "union" "enum" "typedef"))
1976
1977 (c-lang-defconst c-opt-block-decls-with-vars-key
1978 ;; Regexp matching the `c-block-decls-with-vars' keywords, or nil in
1979 ;; languages without such constructs.
1980 t (and (c-lang-const c-block-decls-with-vars)
1981 (c-make-keywords-re t (c-lang-const c-block-decls-with-vars))))
1982 (c-lang-defvar c-opt-block-decls-with-vars-key
1983 (c-lang-const c-opt-block-decls-with-vars-key))
1984
1985 (c-lang-defconst c-postfix-decl-spec-kwds
1986 "Keywords introducing extra declaration specifiers in the region
1987 between the header and the body \(i.e. the \"K&R-region\") in
1988 declarations."
1989 t nil
1990 java '("extends" "implements" "throws")
1991 idl '("context" "getraises" "manages" "primarykey" "raises" "setraises"
1992 "supports"
1993 ;; In CORBA PSDL:
1994 "as" "const" "implements" "of" "ref"))
1995
1996 (c-lang-defconst c-nonsymbol-sexp-kwds
1997 "Keywords that may be followed by a nonsymbol sexp before whatever
1998 construct it's part of continues."
1999 t nil
2000 (c c++ objc) '("extern"))
2001
2002 (c-lang-defconst c-type-list-kwds
2003 "Keywords that may be followed by a comma separated list of type
2004 identifiers, where each optionally can be prefixed by keywords. (Can
2005 also be used for the special case when the list can contain only one
2006 element.)
2007
2008 Assumed to be mutually exclusive with `c-ref-list-kwds'. There's no
2009 reason to put keywords on this list if they are on `c-type-prefix-kwds'.
2010 There's also no reason to add keywords that prefixes a normal
2011 declaration consisting of a type followed by a declarator (list), so
2012 the keywords on `c-modifier-kwds' should normally not be listed here
2013 either.
2014
2015 Note: Use `c-typeless-decl-kwds' for keywords followed by a function
2016 or variable identifier (that's being defined)."
2017 t nil
2018 c++ '("operator")
2019 objc '("@class")
2020 java '("import" "new" "extends" "super" "implements" "throws")
2021 idl '("manages" "native" "primarykey" "supports"
2022 ;; In CORBA PSDL:
2023 "as" "implements" "of" "scope")
2024 pike '("inherit"))
2025
2026 (c-lang-defconst c-ref-list-kwds
2027 "Keywords that may be followed by a comma separated list of
2028 reference (i.e. namespace/scope/module) identifiers, where each
2029 optionally can be prefixed by keywords. (Can also be used for the
2030 special case when the list can contain only one element.) Assumed to
2031 be mutually exclusive with `c-type-list-kwds'.
2032
2033 Note: Use `c-typeless-decl-kwds' for keywords followed by a function
2034 or variable identifier (that's being defined)."
2035 t nil
2036 c++ '("namespace")
2037 java '("package")
2038 idl '("import" "module"
2039 ;; In CORBA CIDL:
2040 "composition")
2041 pike '("import"))
2042
2043 (c-lang-defconst c-colon-type-list-kwds
2044 "Keywords that may be followed (not necessarily directly) by a colon
2045 and then a comma separated list of type identifiers, where each
2046 optionally can be prefixed by keywords. (Can also be used for the
2047 special case when the list can contain only one element.)"
2048 t nil
2049 c++ '("class" "struct")
2050 idl '("component" "eventtype" "home" "interface" "valuetype"
2051 ;; In CORBA PSDL:
2052 "storagehome" "storagetype"))
2053
2054 (c-lang-defconst c-colon-type-list-re
2055 "Regexp matched after the keywords in `c-colon-type-list-kwds' to skip
2056 forward to the colon. The end of the match is assumed to be directly
2057 after the colon, so the regexp should end with \":\". Must be a
2058 regexp if `c-colon-type-list-kwds' isn't nil."
2059 t (if (c-lang-const c-colon-type-list-kwds)
2060 ;; Disallow various common punctuation chars that can't come
2061 ;; before the ":" that starts the inherit list after "class"
2062 ;; or "struct" in C++. (Also used as default for other
2063 ;; languages.)
2064 "[^\]\[{}();,/#=:]*:"))
2065 (c-lang-defvar c-colon-type-list-re (c-lang-const c-colon-type-list-re))
2066
2067 (c-lang-defconst c-paren-nontype-kwds
2068 "Keywords that may be followed by a parenthesis expression that doesn't
2069 contain type identifiers."
2070 t nil
2071 (c c++) '(;; GCC extension.
2072 "__attribute__"
2073 ;; MSVC extension.
2074 "__declspec"))
2075
2076 (c-lang-defconst c-paren-type-kwds
2077 "Keywords that may be followed by a parenthesis expression containing
2078 type identifiers separated by arbitrary tokens."
2079 t nil
2080 c++ '("throw")
2081 objc '("@defs")
2082 idl '("switch")
2083 pike '("array" "function" "int" "mapping" "multiset" "object" "program"))
2084
2085 (c-lang-defconst c-paren-any-kwds
2086 t (delete-duplicates (append (c-lang-const c-paren-nontype-kwds)
2087 (c-lang-const c-paren-type-kwds))
2088 :test 'string-equal))
2089
2090 (c-lang-defconst c-<>-type-kwds
2091 "Keywords that may be followed by an angle bracket expression
2092 containing type identifiers separated by \",\". The difference from
2093 `c-<>-arglist-kwds' is that unknown names are taken to be types and
2094 not other identifiers. `c-recognize-<>-arglists' is assumed to be set
2095 if this isn't nil."
2096 t nil
2097 objc '("id")
2098 idl '("sequence"
2099 ;; In CORBA PSDL:
2100 "ref"))
2101
2102 (c-lang-defconst c-<>-arglist-kwds
2103 "Keywords that can be followed by a C++ style template arglist; see
2104 `c-recognize-<>-arglists' for details. That language constant is
2105 assumed to be set if this isn't nil."
2106 t nil
2107 c++ '("template")
2108 idl '("fixed" "string" "wstring"))
2109
2110 (c-lang-defconst c-<>-sexp-kwds
2111 ;; All keywords that can be followed by an angle bracket sexp.
2112 t (delete-duplicates (append (c-lang-const c-<>-type-kwds)
2113 (c-lang-const c-<>-arglist-kwds))
2114 :test 'string-equal))
2115
2116 (c-lang-defconst c-opt-<>-sexp-key
2117 ;; Adorned regexp matching keywords that can be followed by an angle
2118 ;; bracket sexp. Always set when `c-recognize-<>-arglists' is.
2119 t (if (c-lang-const c-recognize-<>-arglists)
2120 (c-make-keywords-re t (c-lang-const c-<>-sexp-kwds))))
2121 (c-lang-defvar c-opt-<>-sexp-key (c-lang-const c-opt-<>-sexp-key))
2122
2123 (c-lang-defconst c-brace-id-list-kwds
2124 "Keywords that may be followed by a brace block containing a comma
2125 separated list of identifier definitions, i.e. like the list of
2126 identifiers that follows the type in a normal declaration."
2127 t (c-lang-const c-brace-list-decl-kwds))
2128
2129 (c-lang-defconst c-block-stmt-1-kwds
2130 "Statement keywords followed directly by a substatement."
2131 t '("do" "else")
2132 c++ '("do" "else" "try")
2133 objc '("do" "else" "@finally" "@try")
2134 java '("do" "else" "finally" "try")
2135 idl nil)
2136
2137 (c-lang-defconst c-block-stmt-1-key
2138 ;; Regexp matching the start of any statement followed directly by a
2139 ;; substatement (doesn't match a bare block, however).
2140 t (c-make-keywords-re t (c-lang-const c-block-stmt-1-kwds)))
2141 (c-lang-defvar c-block-stmt-1-key (c-lang-const c-block-stmt-1-key))
2142
2143 (c-lang-defconst c-block-stmt-2-kwds
2144 "Statement keywords followed by a paren sexp and then by a substatement."
2145 t '("for" "if" "switch" "while")
2146 c++ '("for" "if" "switch" "while" "catch")
2147 objc '("for" "if" "switch" "while" "@catch" "@synchronized")
2148 java '("for" "if" "switch" "while" "catch" "synchronized")
2149 idl nil
2150 pike '("for" "if" "switch" "while" "foreach")
2151 awk '("for" "if" "while"))
2152
2153 (c-lang-defconst c-block-stmt-2-key
2154 ;; Regexp matching the start of any statement followed by a paren sexp
2155 ;; and then by a substatement.
2156 t (c-make-keywords-re t (c-lang-const c-block-stmt-2-kwds)))
2157 (c-lang-defvar c-block-stmt-2-key (c-lang-const c-block-stmt-2-key))
2158
2159 (c-lang-defconst c-block-stmt-kwds
2160 ;; Union of `c-block-stmt-1-kwds' and `c-block-stmt-2-kwds'.
2161 t (delete-duplicates (append (c-lang-const c-block-stmt-1-kwds)
2162 (c-lang-const c-block-stmt-2-kwds))
2163 :test 'string-equal))
2164
2165 (c-lang-defconst c-opt-block-stmt-key
2166 ;; Regexp matching the start of any statement that has a
2167 ;; substatement (except a bare block). Nil in languages that
2168 ;; don't have such constructs.
2169 t (if (or (c-lang-const c-block-stmt-1-kwds)
2170 (c-lang-const c-block-stmt-2-kwds))
2171 (c-make-keywords-re t
2172 (append (c-lang-const c-block-stmt-1-kwds)
2173 (c-lang-const c-block-stmt-2-kwds)))))
2174 (c-lang-defvar c-opt-block-stmt-key (c-lang-const c-opt-block-stmt-key))
2175
2176 (c-lang-defconst c-simple-stmt-kwds
2177 "Statement keywords followed by an expression or nothing."
2178 t '("break" "continue" "goto" "return")
2179 objc '("break" "continue" "goto" "return" "@throw")
2180 ;; Note: `goto' is not valid in Java, but the keyword is still reserved.
2181 java '("break" "continue" "goto" "return" "throw")
2182 idl nil
2183 pike '("break" "continue" "return")
2184 awk '(;; Not sure about "delete", "exit", "getline", etc. ; ACM 2002/5/30
2185 "break" "continue" "return" "delete" "exit" "getline" "next"
2186 "nextfile" "print" "printf"))
2187
2188 (c-lang-defconst c-simple-stmt-key
2189 ;; Adorned regexp matching `c-simple-stmt-kwds'.
2190 t (c-make-keywords-re t (c-lang-const c-simple-stmt-kwds)))
2191 (c-lang-defvar c-simple-stmt-key (c-lang-const c-simple-stmt-key))
2192
2193 (c-lang-defconst c-paren-stmt-kwds
2194 "Statement keywords followed by a parenthesis expression that
2195 nevertheless contains a list separated with ';' and not ','."
2196 t '("for")
2197 idl nil)
2198
2199 (c-lang-defconst c-paren-stmt-key
2200 ;; Adorned regexp matching `c-paren-stmt-kwds'.
2201 t (c-make-keywords-re t (c-lang-const c-paren-stmt-kwds)))
2202 (c-lang-defvar c-paren-stmt-key (c-lang-const c-paren-stmt-key))
2203
2204 (c-lang-defconst c-asm-stmt-kwds
2205 "Statement keywords followed by an assembler expression."
2206 t nil
2207 (c c++) '("asm" "__asm__")) ;; Not standard, but common.
2208
2209 (c-lang-defconst c-opt-asm-stmt-key
2210 ;; Regexp matching the start of an assembler statement. Nil in
2211 ;; languages that don't support that.
2212 t (if (c-lang-const c-asm-stmt-kwds)
2213 (c-make-keywords-re t (c-lang-const c-asm-stmt-kwds))))
2214 (c-lang-defvar c-opt-asm-stmt-key (c-lang-const c-opt-asm-stmt-key))
2215
2216 (c-lang-defconst c-case-kwds
2217 "The keyword\(s) which introduce a \"case\" like construct.
2218 This construct is \"<keyword> <expression> :\"."
2219 t '("case")
2220 awk nil)
2221
2222 (c-lang-defconst c-case-kwds-regexp
2223 ;; Adorned regexp matching any "case"-like keyword.
2224 t (c-make-keywords-re t (c-lang-const c-case-kwds)))
2225 (c-lang-defvar c-case-kwds-regexp (c-lang-const c-case-kwds-regexp))
2226
2227 (c-lang-defconst c-label-kwds
2228 "Keywords introducing colon terminated labels in blocks."
2229 t '("case" "default")
2230 awk nil)
2231
2232 (c-lang-defconst c-label-kwds-regexp
2233 ;; Adorned regexp matching any keyword that introduces a label.
2234 t (c-make-keywords-re t (c-lang-const c-label-kwds)))
2235 (c-lang-defvar c-label-kwds-regexp (c-lang-const c-label-kwds-regexp))
2236
2237 (c-lang-defconst c-before-label-kwds
2238 "Keywords that might be followed by a label identifier."
2239 t '("goto")
2240 (java pike) (append '("break" "continue")
2241 (c-lang-const c-before-label-kwds))
2242 idl nil
2243 awk nil)
2244
2245 (c-lang-defconst c-constant-kwds
2246 "Keywords for constants."
2247 t nil
2248 (c c++) '("NULL" ;; Not a keyword, but practically works as one.
2249 "false" "true") ; Defined in C99.
2250 objc '("nil" "Nil" "YES" "NO" "NS_DURING" "NS_HANDLER" "NS_ENDHANDLER")
2251 idl '("TRUE" "FALSE")
2252 java '("true" "false" "null") ; technically "literals", not keywords
2253 pike '("UNDEFINED")) ;; Not a keyword, but practically works as one.
2254
2255 (c-lang-defconst c-primary-expr-kwds
2256 "Keywords besides constants and operators that start primary expressions."
2257 t nil
2258 c++ '("operator" "this")
2259 objc '("super" "self")
2260 java '("this")
2261 pike '("this")) ;; Not really a keyword, but practically works as one.
2262
2263 (c-lang-defconst c-expr-kwds
2264 ;; Keywords that can occur anywhere in expressions. Built from
2265 ;; `c-primary-expr-kwds' and all keyword operators in `c-operators'.
2266 t (delete-duplicates
2267 (append (c-lang-const c-primary-expr-kwds)
2268 (c-filter-ops (c-lang-const c-operator-list)
2269 t
2270 "\\`\\(\\w\\|\\s_\\)+\\'"))
2271 :test 'string-equal))
2272
2273 (c-lang-defconst c-lambda-kwds
2274 "Keywords that start lambda constructs, i.e. function definitions in
2275 expressions."
2276 t nil
2277 pike '("lambda"))
2278
2279 (c-lang-defconst c-inexpr-block-kwds
2280 "Keywords that start constructs followed by statement blocks which can
2281 be used in expressions \(the gcc extension for this in C and C++ is
2282 handled separately by `c-recognize-paren-inexpr-blocks')."
2283 t nil
2284 pike '("catch" "gauge"))
2285
2286 (c-lang-defconst c-inexpr-class-kwds
2287 "Keywords that can start classes inside expressions."
2288 t nil
2289 java '("new")
2290 pike '("class"))
2291
2292 (c-lang-defconst c-inexpr-brace-list-kwds
2293 "Keywords that can start brace list blocks inside expressions.
2294 Note that Java specific rules are currently applied to tell this from
2295 `c-inexpr-class-kwds'."
2296 t nil
2297 java '("new"))
2298
2299 (c-lang-defconst c-opt-inexpr-brace-list-key
2300 ;; Regexp matching the start of a brace list in an expression, or
2301 ;; nil in languages that don't have such things. This should not
2302 ;; match brace lists recognized through `c-special-brace-lists'.
2303 t (and (c-lang-const c-inexpr-brace-list-kwds)
2304 (c-make-keywords-re t (c-lang-const c-inexpr-brace-list-kwds))))
2305 (c-lang-defvar c-opt-inexpr-brace-list-key
2306 (c-lang-const c-opt-inexpr-brace-list-key))
2307
2308 (c-lang-defconst c-decl-block-key
2309 ;; Regexp matching keywords in any construct that contain another
2310 ;; declaration level, i.e. that isn't followed by a function block
2311 ;; or brace list. When the first submatch matches, it's an
2312 ;; unambiguous construct, otherwise it's an ambiguous match that
2313 ;; might also be the return type of a function declaration.
2314 t (let* ((decl-kwds (append (c-lang-const c-class-decl-kwds)
2315 (c-lang-const c-other-block-decl-kwds)
2316 (c-lang-const c-inexpr-class-kwds)))
2317 (unambiguous (set-difference decl-kwds
2318 (c-lang-const c-type-start-kwds)
2319 :test 'string-equal))
2320 (ambiguous (intersection decl-kwds
2321 (c-lang-const c-type-start-kwds)
2322 :test 'string-equal)))
2323 (if ambiguous
2324 (concat (c-make-keywords-re t unambiguous)
2325 "\\|"
2326 (c-make-keywords-re t ambiguous))
2327 (c-make-keywords-re t unambiguous))))
2328 (c-lang-defvar c-decl-block-key (c-lang-const c-decl-block-key))
2329
2330 (c-lang-defconst c-bitfield-kwds
2331 "Keywords that can introduce bitfields."
2332 t nil
2333 (c c++ objc) '("char" "int" "long" "signed" "unsigned"))
2334
2335 (c-lang-defconst c-opt-bitfield-key
2336 ;; Regexp matching the start of a bitfield (not uniquely), or nil in
2337 ;; languages without bitfield support.
2338 t nil
2339 (c c++) (c-make-keywords-re t (c-lang-const c-bitfield-kwds)))
2340 (c-lang-defvar c-opt-bitfield-key (c-lang-const c-opt-bitfield-key))
2341
2342 (c-lang-defconst c-other-kwds
2343 "Keywords not accounted for by any other `*-kwds' language constant."
2344 t nil
2345 idl '("truncatable"
2346 ;; In CORBA CIDL: (These are declaration keywords that never
2347 ;; can start a declaration.)
2348 "entity" "process" "service" "session" "storage"))
2349
2350 \f
2351 ;;; Constants built from keywords.
2352
2353 ;; Note: No `*-kwds' language constants may be defined below this point.
2354
2355 (eval-and-compile
2356 (defconst c-kwds-lang-consts
2357 ;; List of all the language constants that contain keyword lists.
2358 (let (list)
2359 (mapatoms (lambda (sym)
2360 (when (and (boundp sym)
2361 (string-match "-kwds\\'" (symbol-name sym)))
2362 ;; Make the list of globally interned symbols
2363 ;; instead of ones interned in `c-lang-constants'.
2364 (setq list (cons (intern (symbol-name sym)) list))))
2365 c-lang-constants)
2366 list)))
2367
2368 (c-lang-defconst c-keywords
2369 ;; All keywords as a list.
2370 t (delete-duplicates
2371 (c-lang-defconst-eval-immediately
2372 `(append ,@(mapcar (lambda (kwds-lang-const)
2373 `(c-lang-const ,kwds-lang-const))
2374 c-kwds-lang-consts)
2375 nil))
2376 :test 'string-equal))
2377
2378 (c-lang-defconst c-keywords-regexp
2379 ;; All keywords as an adorned regexp.
2380 t (c-make-keywords-re t (c-lang-const c-keywords)))
2381 (c-lang-defvar c-keywords-regexp (c-lang-const c-keywords-regexp))
2382
2383 (c-lang-defconst c-keyword-member-alist
2384 ;; An alist with all the keywords in the cars. The cdr for each
2385 ;; keyword is a list of the symbols for the `*-kwds' lists that
2386 ;; contains it.
2387 t (let ((kwd-list-alist
2388 (c-lang-defconst-eval-immediately
2389 `(list ,@(mapcar (lambda (kwds-lang-const)
2390 `(cons ',kwds-lang-const
2391 (c-lang-const ,kwds-lang-const)))
2392 c-kwds-lang-consts))))
2393 lang-const kwd-list kwd
2394 result-alist elem)
2395 (while kwd-list-alist
2396 (setq lang-const (caar kwd-list-alist)
2397 kwd-list (cdar kwd-list-alist)
2398 kwd-list-alist (cdr kwd-list-alist))
2399 (while kwd-list
2400 (setq kwd (car kwd-list)
2401 kwd-list (cdr kwd-list))
2402 (unless (setq elem (assoc kwd result-alist))
2403 (setq result-alist (cons (setq elem (list kwd)) result-alist)))
2404 (unless (memq lang-const (cdr elem))
2405 (setcdr elem (cons lang-const (cdr elem))))))
2406 result-alist))
2407
2408 (c-lang-defvar c-keywords-obarray
2409 ;; An obarray containing all keywords as symbols. The property list
2410 ;; of each symbol has a non-nil entry for the specific `*-kwds'
2411 ;; lists it's a member of.
2412 ;;
2413 ;; E.g. to see whether the string str contains a keyword on
2414 ;; `c-class-decl-kwds', one can do like this:
2415 ;; (get (intern-soft str c-keyword-obarray) 'c-class-decl-kwds)
2416 ;; Which preferably is written using the associated functions in
2417 ;; cc-engine:
2418 ;; (c-keyword-member (c-keyword-sym str) 'c-class-decl-kwds)
2419
2420 ;; The obarray is not stored directly as a language constant since
2421 ;; the printed representation for obarrays used in .elc files isn't
2422 ;; complete.
2423
2424 (let* ((alist (c-lang-const c-keyword-member-alist))
2425 kwd lang-const-list
2426 (obarray (make-vector (* (length alist) 2) 0)))
2427 (while alist
2428 (setq kwd (caar alist)
2429 lang-const-list (cdar alist)
2430 alist (cdr alist))
2431 (setplist (intern kwd obarray)
2432 ;; Emacs has an odd bug that causes `mapcan' to fail
2433 ;; with unintelligible errors. (XEmacs works.)
2434 ;;(mapcan (lambda (lang-const)
2435 ;; (list lang-const t))
2436 ;; lang-const-list)
2437 (apply 'nconc (mapcar (lambda (lang-const)
2438 (list lang-const t))
2439 lang-const-list))))
2440 obarray))
2441
2442 (c-lang-defconst c-regular-keywords-regexp
2443 ;; Adorned regexp matching all keywords that should be fontified
2444 ;; with the keywords face. I.e. that aren't types or constants.
2445 t (c-make-keywords-re t
2446 (set-difference (c-lang-const c-keywords)
2447 (append (c-lang-const c-primitive-type-kwds)
2448 (c-lang-const c-constant-kwds))
2449 :test 'string-equal)))
2450 (c-lang-defvar c-regular-keywords-regexp
2451 (c-lang-const c-regular-keywords-regexp))
2452
2453 (c-lang-defconst c-primary-expr-regexp
2454 ;; Regexp matching the start of any primary expression, i.e. any
2455 ;; literal, symbol, prefix operator, and '('. It doesn't need to
2456 ;; exclude keywords; they are excluded afterwards unless the second
2457 ;; submatch matches. If the first but not the second submatch
2458 ;; matches then it is an ambiguous primary expression; it could also
2459 ;; be a match of e.g. an infix operator. (The case with ambiguous
2460 ;; keyword operators isn't handled.)
2461
2462 t (let* ((prefix-ops
2463 (c-filter-ops (c-lang-const c-operators)
2464 '(prefix)
2465 (lambda (op)
2466 ;; Filter out the special case prefix
2467 ;; operators that are close parens.
2468 (not (string-match "\\s)" op)))))
2469
2470 (nonkeyword-prefix-ops
2471 (c-filter-ops prefix-ops
2472 t
2473 "\\`\\(\\s.\\|\\s(\\|\\s)\\)+\\'"))
2474
2475 (in-or-postfix-ops
2476 (c-filter-ops (c-lang-const c-operators)
2477 '(postfix
2478 postfix-if-paren
2479 left-assoc
2480 right-assoc
2481 right-assoc-sequence)
2482 t))
2483
2484 (unambiguous-prefix-ops (set-difference nonkeyword-prefix-ops
2485 in-or-postfix-ops
2486 :test 'string-equal))
2487 (ambiguous-prefix-ops (intersection nonkeyword-prefix-ops
2488 in-or-postfix-ops
2489 :test 'string-equal)))
2490
2491 (concat
2492 "\\("
2493 ;; Take out all symbol class operators from `prefix-ops' and make the
2494 ;; first submatch from them together with `c-primary-expr-kwds'.
2495 (c-make-keywords-re t
2496 (append (c-lang-const c-primary-expr-kwds)
2497 (set-difference prefix-ops nonkeyword-prefix-ops
2498 :test 'string-equal)))
2499
2500 "\\|"
2501 ;; Match all ambiguous operators.
2502 (c-make-keywords-re nil
2503 (intersection nonkeyword-prefix-ops in-or-postfix-ops
2504 :test 'string-equal))
2505 "\\)"
2506
2507 "\\|"
2508 ;; Now match all other symbols.
2509 (c-lang-const c-symbol-start)
2510
2511 "\\|"
2512 ;; The chars that can start integer and floating point
2513 ;; constants.
2514 "\\.?[0-9]"
2515
2516 "\\|"
2517 ;; The nonambiguous operators from `prefix-ops'.
2518 (c-make-keywords-re nil
2519 (set-difference nonkeyword-prefix-ops in-or-postfix-ops
2520 :test 'string-equal))
2521
2522 "\\|"
2523 ;; Match string and character literals.
2524 "\\s\""
2525 (if (memq 'gen-string-delim c-emacs-features)
2526 "\\|\\s|"
2527 ""))))
2528 (c-lang-defvar c-primary-expr-regexp (c-lang-const c-primary-expr-regexp))
2529
2530 \f
2531 ;;; Additional constants for parser-level constructs.
2532
2533 (c-lang-defconst c-decl-prefix-re
2534 "Regexp matching something that might precede a declaration, cast or
2535 label, such as the last token of a preceding statement or declaration.
2536 This is used in the common situation where a declaration or cast
2537 doesn't start with any specific token that can be searched for.
2538
2539 The regexp should not match bob; that is done implicitly. It can't
2540 require a match longer than one token. The end of the token is taken
2541 to be at the end of the first submatch, which is assumed to always
2542 match. It's undefined whether identifier syntax (see
2543 `c-identifier-syntax-table') is in effect or not. This regexp is
2544 assumed to be a superset of `c-label-prefix-re' if
2545 `c-recognize-colon-labels' is set.
2546
2547 Besides this, `c-decl-start-kwds' is used to find declarations.
2548
2549 Note: This variable together with `c-decl-start-re' and
2550 `c-decl-start-kwds' is only used to detect \"likely\"
2551 declaration/cast/label starts. I.e. they might produce more matches
2552 but should not miss anything (or else it's necessary to use text
2553 properties - see the next note). Wherever they match, the following
2554 construct is analyzed to see if it indeed is a declaration, cast or
2555 label. That analysis is not cheap, so it's important that not too
2556 many false matches are triggered.
2557
2558 Note: If a declaration/cast/label start can't be detected with this
2559 variable, it's necessary to use the `c-type' text property with the
2560 value `c-decl-end' on the last char of the last token preceding the
2561 declaration. See the comment blurb at the start of cc-engine.el for
2562 more info."
2563
2564 ;; We match a sequence of characters to skip over things like \"};\"
2565 ;; more quickly. We match ")" in C for K&R region declarations, and
2566 ;; in all languages except Java for when a cpp macro definition
2567 ;; begins with a declaration.
2568 t "\\([\{\}\(\);,]+\\)"
2569 java "\\([\{\}\(;,<]+\\)"
2570 ;; Match "<" in C++ to get the first argument in a template arglist.
2571 ;; In that case there's an additional check in `c-find-decl-spots'
2572 ;; that it got open paren syntax.
2573 c++ "\\([\{\}\(\);,<]+\\)"
2574 ;; Additionally match the protection directives in Objective-C.
2575 ;; Note that this doesn't cope with the longer directives, which we
2576 ;; would have to match from start to end since they don't end with
2577 ;; any easily recognized characters.
2578 objc (concat "\\([\{\}\(\);,]+\\|"
2579 (c-make-keywords-re nil (c-lang-const c-protection-kwds))
2580 "\\)")
2581 ;; Pike is like C but we also match "[" for multiple value
2582 ;; assignments and type casts.
2583 pike "\\([\{\}\(\)\[;,]+\\)")
2584 (c-lang-defvar c-decl-prefix-re (c-lang-const c-decl-prefix-re)
2585 'dont-doc)
2586
2587 (c-lang-defconst c-decl-start-re
2588 "Regexp matching the start of any declaration, cast or label.
2589 It's used on the token after the one `c-decl-prefix-re' matched. This
2590 regexp should not try to match those constructs accurately as it's
2591 only used as a sieve to avoid spending more time checking other
2592 constructs."
2593 t (c-lang-const c-identifier-start))
2594 (c-lang-defvar c-decl-start-re (c-lang-const c-decl-start-re))
2595
2596 (c-lang-defconst c-decl-prefix-or-start-re
2597 ;; Regexp matching something that might precede or start a
2598 ;; declaration, cast or label.
2599 ;;
2600 ;; If the first submatch matches, it's taken to match the end of a
2601 ;; token that might precede such a construct, e.g. ';', '}' or '{'.
2602 ;; It's built from `c-decl-prefix-re'.
2603 ;;
2604 ;; If the first submatch did not match, the match of the whole
2605 ;; regexp is taken to be at the first token in the declaration.
2606 ;; `c-decl-start-re' is not checked in this case.
2607 ;;
2608 ;; Design note: The reason the same regexp is used to match both
2609 ;; tokens that precede declarations and start them is to avoid an
2610 ;; extra regexp search from the previous declaration spot in
2611 ;; `c-find-decl-spots'. Users of `c-find-decl-spots' also count on
2612 ;; that it finds all declaration/cast/label starts in approximately
2613 ;; linear order, so we can't do the searches in two separate passes.
2614 t (if (c-lang-const c-decl-start-kwds)
2615 (concat (c-lang-const c-decl-prefix-re)
2616 "\\|"
2617 (c-make-keywords-re t (c-lang-const c-decl-start-kwds)))
2618 (c-lang-const c-decl-prefix-re)))
2619 (c-lang-defvar c-decl-prefix-or-start-re
2620 (c-lang-const c-decl-prefix-or-start-re)
2621 'dont-doc)
2622
2623 (c-lang-defconst c-cast-parens
2624 ;; List containing the paren characters that can open a cast, or nil in
2625 ;; languages without casts.
2626 t (c-filter-ops (c-lang-const c-operators)
2627 '(prefix)
2628 "\\`\\s\(\\'"
2629 (lambda (op) (elt op 0))))
2630 (c-lang-defvar c-cast-parens (c-lang-const c-cast-parens))
2631
2632 (c-lang-defconst c-block-prefix-disallowed-chars
2633 "List of syntactically relevant characters that never can occur before
2634 the open brace in any construct that contains a brace block, e.g. in
2635 the \"class Foo: public Bar\" part of:
2636
2637 class Foo: public Bar {int x();} a, *b;
2638
2639 If parens can occur, the chars inside those aren't filtered with this
2640 list.
2641
2642 '<' and '>' should be disallowed even if angle bracket arglists can
2643 occur. That since the search function needs to stop at them anyway to
2644 ensure they are given paren syntax.
2645
2646 This is used to skip backward from the open brace to find the region
2647 in which to look for a construct like \"class\", \"enum\",
2648 \"namespace\" or whatever. That skipping should be as tight as
2649 possible for good performance."
2650
2651 ;; Default to all chars that only occurs in nonsymbol tokens outside
2652 ;; identifiers.
2653 t (set-difference
2654 (c-lang-const c-nonsymbol-token-char-list)
2655 (c-filter-ops (append (c-lang-const c-identifier-ops)
2656 (list (cons nil
2657 (c-lang-const c-after-id-concat-ops))))
2658 t
2659 t
2660 (lambda (op)
2661 (let ((pos 0) res)
2662 (while (string-match "\\(\\s.\\|\\s(\\|\\s)\\)"
2663 op pos)
2664 (setq res (cons (aref op (match-beginning 1)) res)
2665 pos (match-end 0)))
2666 res))))
2667
2668 ;; Allow cpp operatios (where applicable).
2669 t (if (c-lang-const c-opt-cpp-prefix)
2670 (set-difference (c-lang-const c-block-prefix-disallowed-chars)
2671 '(?#))
2672 (c-lang-const c-block-prefix-disallowed-chars))
2673
2674 ;; Allow ':' for inherit list starters.
2675 (c++ objc idl) (set-difference (c-lang-const c-block-prefix-disallowed-chars)
2676 '(?:))
2677
2678 ;; Allow ',' for multiple inherits.
2679 (c++ java) (set-difference (c-lang-const c-block-prefix-disallowed-chars)
2680 '(?,))
2681
2682 ;; Allow parentheses for anonymous inner classes in Java and class
2683 ;; initializer lists in Pike.
2684 (java pike) (set-difference (c-lang-const c-block-prefix-disallowed-chars)
2685 '(?\( ?\)))
2686
2687 ;; Allow '"' for extern clauses (e.g. extern "C" {...}).
2688 (c c++ objc) (set-difference (c-lang-const c-block-prefix-disallowed-chars)
2689 '(?\" ?')))
2690
2691 (c-lang-defconst c-block-prefix-charset
2692 ;; `c-block-prefix-disallowed-chars' as an inverted charset suitable
2693 ;; for `c-syntactic-skip-backward'.
2694 t (c-make-bare-char-alt (c-lang-const c-block-prefix-disallowed-chars) t))
2695 (c-lang-defvar c-block-prefix-charset (c-lang-const c-block-prefix-charset))
2696
2697 (c-lang-defconst c-type-decl-prefix-key
2698 "Regexp matching the declarator operators that might precede the
2699 identifier in a declaration, e.g. the \"*\" in \"char *argv\". This
2700 regexp should match \"(\" if parentheses are valid in declarators.
2701 The end of the first submatch is taken as the end of the operator.
2702 Identifier syntax is in effect when this is matched \(see
2703 `c-identifier-syntax-table')."
2704 t (if (c-lang-const c-type-modifier-kwds)
2705 (concat (regexp-opt (c-lang-const c-type-modifier-kwds) t) "\\>")
2706 ;; Default to a regexp that never matches.
2707 "\\<\\>")
2708 ;; Check that there's no "=" afterwards to avoid matching tokens
2709 ;; like "*=".
2710 (c objc) (concat "\\("
2711 "[*\(]"
2712 "\\|"
2713 (c-lang-const c-type-decl-prefix-key)
2714 "\\)"
2715 "\\([^=]\\|$\\)")
2716 c++ (concat "\\("
2717 "[*\(&]"
2718 "\\|"
2719 (c-lang-const c-type-decl-prefix-key)
2720 "\\|"
2721 (concat "\\(" ; 3
2722 ;; If this matches there's special treatment in
2723 ;; `c-font-lock-declarators' and
2724 ;; `c-font-lock-declarations' that check for a
2725 ;; complete name followed by ":: *".
2726 (c-lang-const c-identifier-start)
2727 "\\)")
2728 "\\)"
2729 "\\([^=]\\|$\\)")
2730 pike "\\(\\*\\)\\([^=]\\|$\\)")
2731 (c-lang-defvar c-type-decl-prefix-key (c-lang-const c-type-decl-prefix-key)
2732 'dont-doc)
2733
2734 (c-lang-defconst c-type-decl-suffix-key
2735 "Regexp matching the declarator operators that might follow after the
2736 identifier in a declaration, e.g. the \"[\" in \"char argv[]\". This
2737 regexp should match \")\" if parentheses are valid in declarators. If
2738 it matches an open paren of some kind, the type declaration check
2739 continues at the corresponding close paren, otherwise the end of the
2740 first submatch is taken as the end of the operator. Identifier syntax
2741 is in effect when this is matched (see `c-identifier-syntax-table')."
2742 ;; Default to a regexp that matches `c-type-modifier-kwds' and a
2743 ;; function argument list parenthesis.
2744 t (if (c-lang-const c-type-modifier-kwds)
2745 (concat "\\(\(\\|"
2746 (regexp-opt (c-lang-const c-type-modifier-kwds) t) "\\>"
2747 "\\)")
2748 "\\(\(\\)")
2749 (c c++ objc) (concat
2750 "\\("
2751 "[\)\[\(]"
2752 (if (c-lang-const c-type-modifier-kwds)
2753 (concat
2754 "\\|"
2755 ;; "throw" in `c-type-modifier-kwds' is followed
2756 ;; by a parenthesis list, but no extra measures
2757 ;; are necessary to handle that.
2758 (regexp-opt (c-lang-const c-type-modifier-kwds) t)
2759 "\\>")
2760 "")
2761 "\\)")
2762 (java idl) "\\([\[\(]\\)")
2763 (c-lang-defvar c-type-decl-suffix-key (c-lang-const c-type-decl-suffix-key)
2764 'dont-doc)
2765
2766 (c-lang-defconst c-after-suffixed-type-decl-key
2767 "This regexp is matched after a declarator expression where
2768 `c-type-decl-suffix-key' has matched. If it matches then the
2769 construct is taken as a declaration. It's typically used to match the
2770 beginning of a function body or whatever might occur after the
2771 function header in a function declaration or definition. It's
2772 undefined whether identifier syntax (see `c-identifier-syntax-table')
2773 is in effect or not.
2774
2775 Note that it's used in cases like after \"foo (bar)\" so it should
2776 only match when it's certain that it's a declaration, e.g \"{\" but
2777 not \",\" or \";\"."
2778 t "{"
2779 ;; If K&R style declarations should be recognized then one could
2780 ;; consider to match the start of any symbol since we want to match
2781 ;; the start of the first declaration in the "K&R region". That
2782 ;; could however produce false matches on code like "FOO(bar) x"
2783 ;; where FOO is a cpp macro, so it's better to leave it out and rely
2784 ;; on the other heuristics in that case.
2785 t (if (c-lang-const c-postfix-spec-kwds)
2786 ;; Add on the keywords in `c-postfix-spec-kwds'.
2787 (concat (c-lang-const c-after-suffixed-type-decl-key)
2788 "\\|"
2789 (c-make-keywords-re t (c-lang-const c-postfix-spec-kwds)))
2790 (c-lang-const c-after-suffixed-type-decl-key))
2791 ;; Also match the colon that starts a base class initializer list in
2792 ;; C++. That can be confused with a function call before the colon
2793 ;; in a ? : operator, but we count on that `c-decl-prefix-re' won't
2794 ;; match before such a thing (as a declaration-level construct;
2795 ;; matches inside arglist contexts are already excluded).
2796 c++ "[{:]")
2797 (c-lang-defvar c-after-suffixed-type-decl-key
2798 (c-lang-const c-after-suffixed-type-decl-key)
2799 'dont-doc)
2800
2801 (c-lang-defconst c-after-suffixed-type-maybe-decl-key
2802 ;; Regexp that in addition to `c-after-suffixed-type-decl-key'
2803 ;; matches ";" and ",".
2804 t (concat "\\(" (c-lang-const c-after-suffixed-type-decl-key) "\\)"
2805 "\\|[;,]"))
2806 (c-lang-defvar c-after-suffixed-type-maybe-decl-key
2807 (c-lang-const c-after-suffixed-type-maybe-decl-key))
2808
2809 (c-lang-defconst c-opt-type-concat-key
2810 "Regexp matching operators that concatenate types, e.g. the \"|\" in
2811 \"int|string\" in Pike. The end of the first submatch is taken as the
2812 end of the operator. nil in languages without such operators. It's
2813 undefined whether identifier syntax (see `c-identifier-syntax-table')
2814 is in effect or not."
2815 t nil
2816 pike "\\([|.&]\\)\\($\\|[^|.&]\\)")
2817 (c-lang-defvar c-opt-type-concat-key (c-lang-const c-opt-type-concat-key)
2818 'dont-doc)
2819
2820 (c-lang-defconst c-opt-type-suffix-key
2821 "Regexp matching operators that might follow after a type, or nil in
2822 languages that don't have such operators. The end of the first
2823 submatch is taken as the end of the operator. This should not match
2824 things like C++ template arglists if `c-recognize-<>-arglists' is set.
2825 It's undefined whether identifier syntax (see `c-identifier-syntax-table')
2826 is in effect or not."
2827 t nil
2828 (c c++ objc pike) "\\(\\.\\.\\.\\)"
2829 java (concat "\\(\\[" (c-lang-const c-simple-ws) "*\\]\\|\\.\\.\\.\\)"))
2830 (c-lang-defvar c-opt-type-suffix-key (c-lang-const c-opt-type-suffix-key))
2831
2832 (c-lang-defvar c-known-type-key
2833 ;; Regexp matching the known type identifiers. This is initialized
2834 ;; from the type keywords and `*-font-lock-extra-types'. The first
2835 ;; submatch is the one that matches the type. Note that this regexp
2836 ;; assumes that symbol constituents like '_' and '$' have word
2837 ;; syntax.
2838 (let* ((extra-types
2839 (when (boundp (c-mode-symbol "font-lock-extra-types"))
2840 (c-mode-var "font-lock-extra-types")))
2841 (regexp-strings
2842 (apply 'nconc
2843 (mapcar (lambda (re)
2844 (when (string-match "[][.*+?^$\\]" re)
2845 (list re)))
2846 extra-types)))
2847 (plain-strings
2848 (apply 'nconc
2849 (mapcar (lambda (re)
2850 (unless (string-match "[][.*+?^$\\]" re)
2851 (list re)))
2852 extra-types))))
2853 (concat "\\<\\("
2854 (c-concat-separated
2855 (append (list (c-make-keywords-re nil
2856 (append (c-lang-const c-primitive-type-kwds)
2857 plain-strings)))
2858 regexp-strings)
2859 "\\|")
2860 "\\)\\>")))
2861
2862 (c-lang-defconst c-special-brace-lists
2863 "List of open- and close-chars that makes up a pike-style brace list,
2864 i.e. for a ([ ]) list there should be a cons (?\\[ . ?\\]) in this
2865 list."
2866 t nil
2867 pike '((?{ . ?}) (?\[ . ?\]) (?< . ?>)))
2868 (c-lang-defvar c-special-brace-lists (c-lang-const c-special-brace-lists))
2869
2870 (c-lang-defconst c-recognize-knr-p
2871 "Non-nil means K&R style argument declarations are valid."
2872 t nil
2873 c t)
2874 (c-lang-defvar c-recognize-knr-p (c-lang-const c-recognize-knr-p))
2875
2876 (c-lang-defconst c-recognize-typeless-decls
2877 "Non-nil means function declarations without return type should be
2878 recognized. That can introduce an ambiguity with parenthesized macro
2879 calls before a brace block. This setting does not affect declarations
2880 that are preceded by a declaration starting keyword, so
2881 e.g. `c-typeless-decl-kwds' may still be used when it's set to nil."
2882 t nil
2883 (c c++ objc) t)
2884 (c-lang-defvar c-recognize-typeless-decls
2885 (c-lang-const c-recognize-typeless-decls))
2886
2887 (c-lang-defconst c-recognize-<>-arglists
2888 "Non-nil means C++ style template arglists should be handled. More
2889 specifically, this means a comma separated list of types or
2890 expressions surrounded by \"<\" and \">\". It's always preceded by an
2891 identifier or one of the keywords on `c-<>-type-kwds' or
2892 `c-<>-arglist-kwds'. If there's an identifier before then the whole
2893 expression is considered to be a type."
2894 t (or (consp (c-lang-const c-<>-type-kwds))
2895 (consp (c-lang-const c-<>-arglist-kwds))))
2896 (c-lang-defvar c-recognize-<>-arglists (c-lang-const c-recognize-<>-arglists))
2897
2898 (c-lang-defconst c-recognize-paren-inits
2899 "Non-nil means that parenthesis style initializers exist,
2900 i.e. constructs like
2901
2902 Foo bar (gnu);
2903
2904 in addition to the more classic
2905
2906 Foo bar = gnu;"
2907 t nil
2908 c++ t)
2909 (c-lang-defvar c-recognize-paren-inits (c-lang-const c-recognize-paren-inits))
2910
2911 (c-lang-defconst c-recognize-paren-inexpr-blocks
2912 "Non-nil to recognize gcc style in-expression blocks,
2913 i.e. compound statements surrounded by parentheses inside expressions."
2914 t nil
2915 (c c++) t)
2916 (c-lang-defvar c-recognize-paren-inexpr-blocks
2917 (c-lang-const c-recognize-paren-inexpr-blocks))
2918
2919 (c-lang-defconst c-opt-<>-arglist-start
2920 ;; Regexp matching the start of angle bracket arglists in languages
2921 ;; where `c-recognize-<>-arglists' is set. Does not exclude
2922 ;; keywords outside `c-<>-arglist-kwds'. The first submatch is
2923 ;; assumed to surround the preceding symbol. The whole match is
2924 ;; assumed to end directly after the opening "<".
2925 t (if (c-lang-const c-recognize-<>-arglists)
2926 (concat "\\("
2927 (c-lang-const c-symbol-key)
2928 "\\)"
2929 (c-lang-const c-syntactic-ws)
2930 "<")))
2931 (c-lang-defvar c-opt-<>-arglist-start (c-lang-const c-opt-<>-arglist-start))
2932
2933 (c-lang-defconst c-opt-<>-arglist-start-in-paren
2934 ;; Regexp that in addition to `c-opt-<>-arglist-start' matches close
2935 ;; parens. The first submatch is assumed to surround
2936 ;; `c-opt-<>-arglist-start'.
2937 t (if (c-lang-const c-opt-<>-arglist-start)
2938 (concat "\\("
2939 (c-lang-const c-opt-<>-arglist-start)
2940 "\\)\\|\\s\)")))
2941 (c-lang-defvar c-opt-<>-arglist-start-in-paren
2942 (c-lang-const c-opt-<>-arglist-start-in-paren))
2943
2944 (c-lang-defconst c-opt-postfix-decl-spec-key
2945 ;; Regexp matching the beginning of a declaration specifier in the
2946 ;; region between the header and the body of a declaration.
2947 ;;
2948 ;; TODO: This is currently not used uniformly; c++-mode and
2949 ;; java-mode each have their own ways of using it.
2950 t nil
2951 c++ (concat ":?"
2952 (c-lang-const c-simple-ws) "*"
2953 "\\(virtual" (c-lang-const c-simple-ws) "+\\)?\\("
2954 (c-make-keywords-re nil (c-lang-const c-protection-kwds))
2955 "\\)" (c-lang-const c-simple-ws) "+"
2956 "\\(" (c-lang-const c-symbol-key) "\\)")
2957 java (c-make-keywords-re t (c-lang-const c-postfix-spec-kwds)))
2958 (c-lang-defvar c-opt-postfix-decl-spec-key
2959 (c-lang-const c-opt-postfix-decl-spec-key))
2960
2961 (c-lang-defconst c-recognize-colon-labels
2962 "Non-nil if generic labels ending with \":\" should be recognized.
2963 That includes labels in code and access keys in classes. This does
2964 not apply to labels recognized by `c-label-kwds' and
2965 `c-opt-extra-label-key'."
2966 t nil
2967 (c c++ objc java pike) t)
2968 (c-lang-defvar c-recognize-colon-labels
2969 (c-lang-const c-recognize-colon-labels))
2970
2971 (c-lang-defconst c-label-prefix-re
2972 "Regexp like `c-decl-prefix-re' that matches any token that can precede
2973 a generic colon label. Not used if `c-recognize-colon-labels' is
2974 nil."
2975 t "\\([{};]+\\)")
2976 (c-lang-defvar c-label-prefix-re
2977 (c-lang-const c-label-prefix-re))
2978
2979 (c-lang-defconst c-nonlabel-token-key
2980 "Regexp matching things that can't occur in generic colon labels,
2981 neither in a statement nor in a declaration context. The regexp is
2982 tested at the beginning of every sexp in a suspected label,
2983 i.e. before \":\". Only used if `c-recognize-colon-labels' is set."
2984 t (concat
2985 ;; Don't allow string literals.
2986 "\"\\|"
2987 ;; All keywords except `c-label-kwds' and `c-protection-kwds'.
2988 (c-make-keywords-re t
2989 (set-difference (c-lang-const c-keywords)
2990 (append (c-lang-const c-label-kwds)
2991 (c-lang-const c-protection-kwds))
2992 :test 'string-equal)))
2993 ;; Also check for open parens in C++, to catch member init lists in
2994 ;; constructors. We normally allow it so that macros with arguments
2995 ;; work in labels.
2996 c++ (concat "\\s\(\\|" (c-lang-const c-nonlabel-token-key)))
2997 (c-lang-defvar c-nonlabel-token-key (c-lang-const c-nonlabel-token-key))
2998
2999 (c-lang-defconst c-opt-extra-label-key
3000 "Optional regexp matching labels.
3001 Normally, labels are detected according to `c-nonlabel-token-key',
3002 `c-decl-prefix-re' and `c-nonlabel-decl-prefix-re'. This regexp can
3003 be used if there are additional labels that aren't recognized that
3004 way."
3005 t nil
3006 objc (c-make-keywords-re t (c-lang-const c-protection-kwds)))
3007 (c-lang-defvar c-opt-extra-label-key (c-lang-const c-opt-extra-label-key))
3008
3009 (c-lang-defconst c-opt-friend-key
3010 ;; Regexp describing friend declarations classes, or nil in
3011 ;; languages that don't have such things.
3012 ;;
3013 ;; TODO: Ought to use `c-prefix-spec-kwds-re' or similar, and the
3014 ;; template skipping isn't done properly. This will disappear soon.
3015 t nil
3016 c++ (concat "friend" (c-lang-const c-simple-ws) "+"
3017 "\\|"
3018 (concat "template"
3019 (c-lang-const c-simple-ws) "*"
3020 "<.+>"
3021 (c-lang-const c-simple-ws) "*"
3022 "friend"
3023 (c-lang-const c-simple-ws) "+")))
3024 (c-lang-defvar c-opt-friend-key (c-lang-const c-opt-friend-key))
3025
3026 (c-lang-defconst c-opt-method-key
3027 ;; Special regexp to match the start of Objective-C methods. The
3028 ;; first submatch is assumed to end after the + or - key.
3029 t nil
3030 objc (concat
3031 ;; TODO: Ought to use a better method than anchoring on bol.
3032 "^\\s *"
3033 "\\([+-]\\)"
3034 (c-lang-const c-simple-ws) "*"
3035 (concat "\\(" ; Return type.
3036 "([^\)]*)"
3037 (c-lang-const c-simple-ws) "*"
3038 "\\)?")
3039 "\\(" (c-lang-const c-symbol-key) "\\)"))
3040 (c-lang-defvar c-opt-method-key (c-lang-const c-opt-method-key))
3041
3042 (c-lang-defconst c-type-decl-end-used
3043 ;; Must be set in buffers where the `c-type' text property might be
3044 ;; used with the value `c-decl-end'.
3045 ;;
3046 ;; `c-decl-end' is used to mark the ends of labels and access keys
3047 ;; to make interactive refontification work better.
3048 t (or (c-lang-const c-recognize-colon-labels)
3049 (and (c-lang-const c-label-kwds) t))
3050 ;; `c-decl-end' is used to mark the end of the @-style directives in
3051 ;; Objective-C.
3052 objc t)
3053 (c-lang-defvar c-type-decl-end-used (c-lang-const c-type-decl-end-used))
3054
3055 \f
3056 ;;; Wrap up the `c-lang-defvar' system.
3057
3058 ;; Compile in the list of language variables that has been collected
3059 ;; with the `c-lang-defvar' and `c-lang-setvar' macros. Note that the
3060 ;; first element of each is nil.
3061 (defconst c-lang-variable-inits (cc-eval-when-compile c-lang-variable-inits))
3062 (defconst c-emacs-variable-inits (cc-eval-when-compile c-emacs-variable-inits))
3063
3064 ;; Make the `c-lang-setvar' variables buffer local in the current buffer.
3065 ;; These are typically standard emacs variables such as `comment-start'.
3066 (defmacro c-make-emacs-variables-local ()
3067 `(progn
3068 ,@(mapcar (lambda (init)
3069 `(make-local-variable ',(car init)))
3070 (cdr c-emacs-variable-inits))))
3071
3072 (defun c-make-init-lang-vars-fun (mode)
3073 "Create a function that initializes all the language dependent variables
3074 for the given mode.
3075
3076 This function should be evaluated at compile time, so that the
3077 function it returns is byte compiled with all the evaluated results
3078 from the language constants. Use the `c-init-language-vars' macro to
3079 accomplish that conveniently."
3080
3081 (if (and (not load-in-progress)
3082 (boundp 'byte-compile-dest-file)
3083 (stringp byte-compile-dest-file))
3084
3085 ;; No need to byte compile this lambda since the byte compiler is
3086 ;; smart enough to detect the `funcall' construct in the
3087 ;; `c-init-language-vars' macro below and compile it all straight
3088 ;; into the function that contains `c-init-language-vars'.
3089 `(lambda ()
3090
3091 ;; This let sets up the context for `c-mode-var' and similar
3092 ;; that could be in the result from `cl-macroexpand-all'.
3093 (let ((c-buffer-is-cc-mode ',mode)
3094 current-var source-eval)
3095 (c-make-emacs-variables-local)
3096 (condition-case err
3097
3098 (if (eq c-version-sym ',c-version-sym)
3099 (setq ,@(let ((c-buffer-is-cc-mode mode)
3100 (c-lang-const-expansion 'immediate))
3101 ;; `c-lang-const' will expand to the evaluated
3102 ;; constant immediately in `cl-macroexpand-all'
3103 ;; below.
3104 (mapcan
3105 (lambda (init)
3106 `(current-var ',(car init)
3107 ,(car init) ,(cl-macroexpand-all
3108 (elt init 1))))
3109 ;; Note: The following `append' copies the
3110 ;; first argument. That list is small, so
3111 ;; this doesn't matter too much.
3112 (append (cdr c-emacs-variable-inits)
3113 (cdr c-lang-variable-inits)))))
3114
3115 ;; This diagnostic message isn't useful for end
3116 ;; users, so it's disabled.
3117 ;;(unless (get ',mode 'c-has-warned-lang-consts)
3118 ;; (message ,(concat "%s compiled with CC Mode %s "
3119 ;; "but loaded with %s - evaluating "
3120 ;; "language constants from source")
3121 ;; ',mode ,c-version c-version)
3122 ;; (put ',mode 'c-has-warned-lang-consts t))
3123
3124 (setq source-eval t)
3125 (let ((init ',(append (cdr c-emacs-variable-inits)
3126 (cdr c-lang-variable-inits))))
3127 (while init
3128 (setq current-var (caar init))
3129 (set (caar init) (eval (cadar init)))
3130 (setq init (cdr init)))))
3131
3132 (error
3133 (if current-var
3134 (message "Eval error in the `c-lang-defvar' or `c-lang-setvar' for `%s'%s: %S"
3135 current-var
3136 (if source-eval
3137 (format "\
3138 (fallback source eval - %s compiled with CC Mode %s but loaded with %s)"
3139 ',mode ,c-version c-version)
3140 "")
3141 err)
3142 (signal (car err) (cdr err)))))))
3143
3144 ;; Being evaluated from source. Always use the dynamic method to
3145 ;; work well when `c-lang-defvar's in this file are reevaluated
3146 ;; interactively.
3147 `(lambda ()
3148 (require 'cc-langs)
3149 (let ((c-buffer-is-cc-mode ',mode)
3150 (init (append (cdr c-emacs-variable-inits)
3151 (cdr c-lang-variable-inits)))
3152 current-var)
3153 (c-make-emacs-variables-local)
3154 (condition-case err
3155
3156 (while init
3157 (setq current-var (caar init))
3158 (set (caar init) (eval (cadar init)))
3159 (setq init (cdr init)))
3160
3161 (error
3162 (if current-var
3163 (message
3164 "Eval error in the `c-lang-defvar' or `c-lang-setver' for `%s' (source eval): %S"
3165 current-var err)
3166 (signal (car err) (cdr err)))))))
3167 ))
3168
3169 (defmacro c-init-language-vars (mode)
3170 "Initialize all the language dependent variables for the given mode.
3171 This macro is expanded at compile time to a form tailored for the mode
3172 in question, so MODE must be a constant. Therefore MODE is not
3173 evaluated and should not be quoted."
3174 `(funcall ,(c-make-init-lang-vars-fun mode)))
3175
3176 \f
3177 (cc-provide 'cc-langs)
3178
3179 ;;; cc-langs.el ends here