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