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