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