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