* src/doc.c (Fsubstitute_command_keys): Clarify GC comments.
[emacs.git] / lisp / progmodes / cc-langs.el
blob934186da7bde57d19cf85f254670a4c48cccade2
1 ;;; cc-langs.el --- language specific settings for CC Mode -*- coding: utf-8 -*-
3 ;; Copyright (C) 1985, 1987, 1992-2016 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 (cc-external-require (if (eq c--mapcan-status 'cl-mapcan) 'cl-lib 'cl))
136 ;;; Setup for the `c-lang-defvar' system.
138 (eval-and-compile
139 ;; These are used to collect the init forms from the subsequent
140 ;; `c-lang-defvar' and `c-lang-setvar'. They are used to build the
141 ;; lambda in `c-make-init-lang-vars-fun' below, and to build `defvar's
142 ;; and `make-variable-buffer-local's in cc-engine and
143 ;; `make-local-variable's in `c-init-language-vars-for'.
144 (defvar c-lang-variable-inits nil)
145 (defvar c-lang-variable-inits-tail nil)
146 (setq c-lang-variable-inits (list nil)
147 c-lang-variable-inits-tail c-lang-variable-inits)
148 (defvar c-emacs-variable-inits nil)
149 (defvar c-emacs-variable-inits-tail nil)
150 (setq c-emacs-variable-inits (list nil)
151 c-emacs-variable-inits-tail c-emacs-variable-inits))
153 (defmacro c-lang-defvar (var val &optional doc)
154 "Declares the buffer local variable VAR to get the value VAL. VAL is
155 evaluated and assigned at mode initialization. More precisely, VAL is
156 evaluated and bound to VAR when the result from the macro
157 `c-init-language-vars' is evaluated.
159 `c-lang-const' is typically used in VAL to get the right value for the
160 language being initialized, and such calls will be macro expanded to
161 the evaluated constant value at compile time."
163 (when (and (not doc)
164 (eq (car-safe val) 'c-lang-const)
165 (eq (nth 1 val) var)
166 (not (nth 2 val)))
167 ;; Special case: If there's no docstring and the value is a
168 ;; simple (c-lang-const foo) where foo is the same name as VAR
169 ;; then take the docstring from the language constant foo.
170 (setq doc (get (intern (symbol-name (nth 1 val)) c-lang-constants)
171 'variable-documentation)))
172 (or (stringp doc)
173 (setq doc nil))
175 (let ((elem (assq var (cdr c-lang-variable-inits))))
176 (if elem
177 (setcdr elem (list val doc))
178 (setcdr c-lang-variable-inits-tail (list (list var val doc)))
179 (setq c-lang-variable-inits-tail (cdr c-lang-variable-inits-tail))))
181 ;; Return the symbol, like the other def* forms.
182 `',var)
184 (defmacro c-lang-setvar (var val)
185 "Causes the variable VAR to be made buffer local and to get set to the
186 value VAL. VAL is evaluated and assigned at mode initialization. More
187 precisely, VAL is evaluated and bound to VAR when the result from the
188 macro `c-init-language-vars' is evaluated. VAR is typically a standard
189 Emacs variable like `comment-start'.
191 `c-lang-const' is typically used in VAL to get the right value for the
192 language being initialized, and such calls will be macro expanded to
193 the evaluated constant value at compile time."
194 (let ((elem (assq var (cdr c-emacs-variable-inits))))
195 (if elem
196 (setcdr elem (list val)) ; Maybe remove "list", sometime. 2006-07-19
197 (setcdr c-emacs-variable-inits-tail (list (list var val)))
198 (setq c-emacs-variable-inits-tail (cdr c-emacs-variable-inits-tail))))
200 ;; Return the symbol, like the other def* forms.
201 `',var)
203 (put 'c-lang-defvar 'lisp-indent-function 'defun)
204 ; (eval-after-load "edebug" ; 2006-07-09: def-edebug-spec is now in subr.el.
206 (def-edebug-spec c-lang-defvar
207 (&define name def-form &optional stringp)) ;)
209 ;; Suppress "might not be defined at runtime" warning.
210 ;; This file is only used when compiling other cc files.
211 ;; These are defined in cl as aliases to the cl- versions.
212 ;(declare-function delete-duplicates "cl-seq" (cl-seq &rest cl-keys) t)
213 ;(declare-function mapcan "cl-extra" (cl-func cl-seq &rest cl-rest) t)
215 (eval-and-compile
216 ;; Some helper functions used when building the language constants.
218 (defun c-filter-ops (ops opgroup-filter op-filter &optional xlate)
219 ;; Extract a subset of the operators in the list OPS in a DWIM:ey
220 ;; way. The return value is a plain list of operators:
222 ;; OPS either has the structure of `c-operators', is a single
223 ;; group in `c-operators', or is a plain list of operators.
225 ;; OPGROUP-FILTER specifies how to select the operator groups. It
226 ;; can be t to choose all groups, a list of group type symbols
227 ;; (such as 'prefix) to accept, or a function which will be called
228 ;; with the group symbol for each group and should return non-nil
229 ;; if that group is to be included.
231 ;; OP-FILTER selects the operators. It is either t to select all
232 ;; operators, a string to select all operators for which `string-match'
233 ;; matches the operator with the string, or a function which will be
234 ;; called with the operator and should return non-nil when the operator
235 ;; is to be selected.
237 ;; If XLATE is given, it's a function which is called for each
238 ;; matching operator and its return value is collected instead.
239 ;; If it returns a list, the elements are spliced directly into
240 ;; the final result, which is returned as a list with duplicates
241 ;; removed using `equal'.
243 ;; `c-mode-syntax-table' for the current mode is in effect during
244 ;; the whole procedure.
245 (unless (listp (car-safe ops))
246 (setq ops (list ops)))
247 (cond ((eq opgroup-filter t)
248 (setq opgroup-filter (lambda (opgroup) t)))
249 ((not (functionp opgroup-filter))
250 (setq opgroup-filter `(lambda (opgroup)
251 (memq opgroup ',opgroup-filter)))))
252 (cond ((eq op-filter t)
253 (setq op-filter (lambda (op) t)))
254 ((stringp op-filter)
255 (setq op-filter `(lambda (op)
256 (string-match ,op-filter op)))))
257 (unless xlate
258 (setq xlate 'identity))
259 (c-with-syntax-table (c-lang-const c-mode-syntax-table)
260 (c--delete-duplicates
261 (c--mapcan (lambda (opgroup)
262 (when (if (symbolp (car opgroup))
263 (when (funcall opgroup-filter (car opgroup))
264 (setq opgroup (cdr opgroup))
267 (c--mapcan (lambda (op)
268 (when (funcall op-filter op)
269 (let ((res (funcall xlate op)))
270 (if (listp res) res (list res)))))
271 opgroup)))
272 ops)
273 :test 'equal))))
276 ;;; Various mode specific values that aren't language related.
278 (c-lang-defconst c-mode-menu
279 ;; The definition for the mode menu. The menu title is prepended to
280 ;; this before it's fed to `easy-menu-define'.
281 t `(["Comment Out Region" comment-region
282 (c-fn-region-is-active-p)]
283 ["Uncomment Region" (comment-region (region-beginning)
284 (region-end) '(4))
285 (c-fn-region-is-active-p)]
286 ["Indent Expression" c-indent-exp
287 (memq (char-after) '(?\( ?\[ ?\{))]
288 ["Indent Line or Region" c-indent-line-or-region t]
289 ["Fill Comment Paragraph" c-fill-paragraph t]
290 "----"
291 ["Backward Statement" c-beginning-of-statement t]
292 ["Forward Statement" c-end-of-statement t]
293 ,@(when (c-lang-const c-opt-cpp-prefix)
294 ;; Only applicable if there's a cpp preprocessor.
295 `(["Up Conditional" c-up-conditional t]
296 ["Backward Conditional" c-backward-conditional t]
297 ["Forward Conditional" c-forward-conditional t]
298 "----"
299 ["Macro Expand Region" c-macro-expand
300 (c-fn-region-is-active-p)]
301 ["Backslashify" c-backslash-region
302 (c-fn-region-is-active-p)]))
303 "----"
304 ("Style..."
305 ["Set Style..." c-set-style t]
306 ["Show Current Style Name" (message
307 "Style Name: %s"
308 c-indentation-style)
310 ["Guess Style from this Buffer" c-guess-buffer-no-install t]
311 ["Install the Last Guessed Style..." c-guess-install
312 (and c-guess-guessed-offsets-alist
313 c-guess-guessed-basic-offset) ]
314 ["View the Last Guessed Style" c-guess-view
315 (and c-guess-guessed-offsets-alist
316 c-guess-guessed-basic-offset) ])
317 "----"
318 ("Toggle..."
319 ["Syntactic indentation" c-toggle-syntactic-indentation
320 :style toggle :selected c-syntactic-indentation]
321 ["Electric mode" c-toggle-electric-state
322 :style toggle :selected c-electric-flag]
323 ["Auto newline" c-toggle-auto-newline
324 :style toggle :selected c-auto-newline]
325 ["Hungry delete" c-toggle-hungry-state
326 :style toggle :selected c-hungry-delete-key]
327 ["Subword mode" c-subword-mode
328 :style toggle :selected (and (boundp 'c-subword-mode)
329 c-subword-mode)])))
332 ;;; Syntax tables.
334 (defun c-populate-syntax-table (table)
335 "Populate the given syntax table as necessary for a C-like language.
336 This includes setting \\=' and \" as string delimiters, and setting up
337 the comment syntax to handle both line style \"//\" and block style
338 \"/*\" \"*/\" comments."
340 (modify-syntax-entry ?_ "_" table)
341 (modify-syntax-entry ?\\ "\\" table)
342 (modify-syntax-entry ?+ "." table)
343 (modify-syntax-entry ?- "." table)
344 (modify-syntax-entry ?= "." table)
345 (modify-syntax-entry ?% "." table)
346 (modify-syntax-entry ?< "." table)
347 (modify-syntax-entry ?> "." table)
348 (modify-syntax-entry ?& "." table)
349 (modify-syntax-entry ?| "." table)
350 (modify-syntax-entry ?\' "\"" table)
351 (modify-syntax-entry ?\240 "." table)
353 ;; Set up block and line oriented comments. The new C
354 ;; standard mandates both comment styles even in C, so since
355 ;; all languages now require dual comments, we make this the
356 ;; default.
357 (cond
358 ;; XEmacs
359 ((memq '8-bit c-emacs-features)
360 (modify-syntax-entry ?/ ". 1456" table)
361 (modify-syntax-entry ?* ". 23" table))
362 ;; Emacs
363 ((memq '1-bit c-emacs-features)
364 (modify-syntax-entry ?/ ". 124b" table)
365 (modify-syntax-entry ?* ". 23" table))
366 ;; incompatible
367 (t (error "CC Mode is incompatible with this version of Emacs")))
369 (modify-syntax-entry ?\n "> b" table)
370 ;; Give CR the same syntax as newline, for selective-display
371 (modify-syntax-entry ?\^m "> b" table))
373 (c-lang-defconst c-make-mode-syntax-table
374 "Functions that generates the mode specific syntax tables.
375 The syntax tables aren't stored directly since they're quite large."
376 t `(lambda ()
377 (let ((table (make-syntax-table)))
378 (c-populate-syntax-table table)
379 ;; Mode specific syntaxes.
380 ,(cond ((or (c-major-mode-is 'objc-mode) (c-major-mode-is 'java-mode))
381 ;; Let '@' be part of symbols in ObjC to cope with
382 ;; its compiler directives as single keyword tokens.
383 ;; This is then necessary since it's assumed that
384 ;; every keyword is a single symbol.
385 `(modify-syntax-entry ?@ "_" table))
386 ((c-major-mode-is 'pike-mode)
387 `(modify-syntax-entry ?@ "." table)))
388 table)))
390 (c-lang-defconst c-mode-syntax-table
391 ;; The syntax tables in evaluated form. Only used temporarily when
392 ;; the constants in this file are evaluated.
393 t (funcall (c-lang-const c-make-mode-syntax-table)))
395 (c-lang-defconst c++-make-template-syntax-table
396 ;; A variant of `c++-mode-syntax-table' that defines `<' and `>' as
397 ;; parenthesis characters. Used temporarily when template argument
398 ;; lists are parsed. Note that this encourages incorrect parsing of
399 ;; templates since they might contain normal operators that uses the
400 ;; '<' and '>' characters. Therefore this syntax table might go
401 ;; away when CC Mode handles templates correctly everywhere. WHILE
402 ;; THIS SYNTAX TABLE IS CURRENT, `c-parse-state' MUST _NOT_ BE
403 ;; CALLED!!!
404 t nil
405 (java c++) `(lambda ()
406 (let ((table (funcall ,(c-lang-const c-make-mode-syntax-table))))
407 (modify-syntax-entry ?< "(>" table)
408 (modify-syntax-entry ?> ")<" table)
409 table)))
410 (c-lang-defvar c++-template-syntax-table
411 (and (c-lang-const c++-make-template-syntax-table)
412 ;; The next eval remove a superfluous ' from '(lambda. This
413 ;; gets rid of compilation warnings.
414 (funcall (eval (c-lang-const c++-make-template-syntax-table)))))
416 (c-lang-defconst c-make-no-parens-syntax-table
417 ;; A variant of the standard syntax table which is used to find matching
418 ;; "<"s and ">"s which have been marked as parens using syntax table
419 ;; properties. The other paren characters (e.g. "{", ")" "]") are given a
420 ;; non-paren syntax here. so that the list commands will work on "< ... >"
421 ;; even when there's unbalanced other parens inside them.
423 ;; This variable is nil for languages which don't have template stuff.
424 t (if (c-lang-const c-recognize-<>-arglists)
425 `(lambda ()
426 ;(if (c-lang-const c-recognize-<>-arglists)
427 (let ((table (funcall ,(c-lang-const c-make-mode-syntax-table))))
428 (modify-syntax-entry ?\( "." table)
429 (modify-syntax-entry ?\) "." table)
430 (modify-syntax-entry ?\[ "." table)
431 (modify-syntax-entry ?\] "." table)
432 (modify-syntax-entry ?\{ "." table)
433 (modify-syntax-entry ?\} "." table)
434 table))))
435 (c-lang-defvar c-no-parens-syntax-table
436 (and (c-lang-const c-make-no-parens-syntax-table)
437 ;; See comment in `c++template-syntax-table' about the next `eval'.
438 (funcall (eval (c-lang-const c-make-no-parens-syntax-table)))))
440 (c-lang-defconst c-identifier-syntax-modifications
441 "A list that describes the modifications that should be done to the
442 mode syntax table to get a syntax table that matches all identifiers
443 and keywords as words.
445 The list is just like the one used in `font-lock-defaults': Each
446 element is a cons where the car is the character to modify and the cdr
447 the new syntax, as accepted by `modify-syntax-entry'."
448 ;; The $ character is not allowed in most languages (one exception
449 ;; is Java which allows it for legacy reasons) but we still classify
450 ;; it as an identifier character since it's often used in various
451 ;; machine generated identifiers.
452 t '((?_ . "w") (?$ . "w"))
453 (objc java) (append '((?@ . "w"))
454 (c-lang-const c-identifier-syntax-modifications))
455 awk '((?_ . "w")))
456 (c-lang-defvar c-identifier-syntax-modifications
457 (c-lang-const c-identifier-syntax-modifications))
459 (c-lang-defvar c-identifier-syntax-table
460 (let ((table (copy-syntax-table (c-mode-var "mode-syntax-table")))
461 (mods c-identifier-syntax-modifications)
462 mod)
463 (while mods
464 (setq mod (car mods)
465 mods (cdr mods))
466 (modify-syntax-entry (car mod) (cdr mod) table))
467 table)
468 "Syntax table built on the mode syntax table but additionally
469 classifies symbol constituents like `_' and `$' as word constituents,
470 so that all identifiers are recognized as words.")
472 (c-lang-defconst c-get-state-before-change-functions
473 ;; For documentation see the following c-lang-defvar of the same name.
474 ;; The value here may be a list of functions or a single function.
475 t nil
476 c++ '(c-extend-region-for-CPP
477 ; c-before-after-change-extend-region-for-lambda-capture ; doesn't seem needed.
478 c-before-change-check-raw-strings
479 c-before-change-check-<>-operators
480 c-depropertize-CPP
481 c-before-after-change-digit-quote
482 c-invalidate-macro-cache)
483 (c objc) '(c-extend-region-for-CPP
484 c-depropertize-CPP
485 c-invalidate-macro-cache)
486 ;; java 'c-before-change-check-<>-operators
487 awk 'c-awk-record-region-clear-NL)
488 (c-lang-defvar c-get-state-before-change-functions
489 (let ((fs (c-lang-const c-get-state-before-change-functions)))
490 (if (listp fs)
492 (list fs)))
493 "If non-nil, a list of functions called from c-before-change-hook.
494 Typically these will record enough state to allow
495 `c-before-font-lock-function' to extend the region to fontify,
496 and may do such things as removing text-properties which must be
497 recalculated.
499 These functions will be run in the order given. Each of them
500 takes 2 parameters, the BEG and END supplied to every
501 before-change function; on entry, the buffer will have been
502 widened and match-data will have been saved; point is undefined
503 on both entry and exit; the return value is ignored.
505 The functions are called even when font locking isn't enabled.
507 When the mode is initialized, the functions are called with
508 parameters \(point-min) and \(point-max).")
510 (c-lang-defconst c-before-font-lock-functions
511 ;; For documentation see the following c-lang-defvar of the same name.
512 ;; The value here may be a list of functions or a single function.
513 t '(c-depropertize-new-text
514 c-change-expand-fl-region)
515 (c objc) '(c-depropertize-new-text
516 c-extend-font-lock-region-for-macros
517 c-neutralize-syntax-in-and-mark-CPP
518 c-change-expand-fl-region)
519 c++ '(c-depropertize-new-text
520 c-extend-font-lock-region-for-macros
521 ; c-before-after-change-extend-region-for-lambda-capture ; doens't seem needed.
522 c-before-after-change-digit-quote
523 c-after-change-re-mark-raw-strings
524 c-neutralize-syntax-in-and-mark-CPP
525 c-restore-<>-properties
526 c-change-expand-fl-region)
527 java '(c-depropertize-new-text
528 c-restore-<>-properties
529 c-change-expand-fl-region)
530 awk '(c-depropertize-new-text
531 c-awk-extend-and-syntax-tablify-region))
532 (c-lang-defvar c-before-font-lock-functions
533 (let ((fs (c-lang-const c-before-font-lock-functions)))
534 (if (listp fs)
536 (list fs)))
537 "If non-nil, a list of functions called just before font locking.
538 Typically they will extend the region about to be fontified \(see
539 below) and will set `syntax-table' text properties on the region.
541 These functions will be run in the order given. Each of them
542 takes 3 parameters, the BEG, END, and OLD-LEN supplied to every
543 after-change function; point is undefined on both entry and exit;
544 on entry, the buffer will have been widened and match-data will
545 have been saved; the return value is ignored.
547 The functions may extend the region to be fontified by setting the
548 buffer local variables c-new-BEG and c-new-END.
550 The functions are called even when font locking is disabled.
552 When the mode is initialized, these functions are called with
553 parameters \(point-min), \(point-max) and <buffer size>.")
555 (c-lang-defconst c-before-context-fontification-functions
556 t 'c-context-expand-fl-region
557 awk nil)
558 ;; For documentation see the following c-lang-defvar of the same name.
559 ;; The value here may be a list of functions or a single function.
560 (c-lang-defvar c-before-context-fontification-functions
561 (let ((fs (c-lang-const c-before-context-fontification-functions)))
562 (if (listp fs)
564 (list fs)))
565 "If non-nil, a list of functions called just before context (or
566 other non-change) fontification is done. Typically they will
567 extend the region.
569 These functions will be run in the order given. Each of them
570 takes 2 parameters, the BEG and END of the region to be
571 fontified. Point is undefined on both entry and exit. On entry,
572 the buffer will have been widened and match-data will have been
573 saved; the return value is a cons of the adjusted
574 region, (NEW-BEG . NEW-END).")
577 ;;; Syntactic analysis ("virtual semicolons") for line-oriented languages (AWK).
578 (c-lang-defconst c-at-vsemi-p-fn
579 "Contains a function \"Is there a virtual semicolon at POS or point?\".
580 Such a function takes one optional parameter, a buffer position (defaults to
581 point), and returns nil or t. This variable contains nil for languages which
582 don't have EOL terminated statements. "
583 t nil
584 (c c++ objc) 'c-at-macro-vsemi-p
585 awk 'c-awk-at-vsemi-p)
586 (c-lang-defvar c-at-vsemi-p-fn (c-lang-const c-at-vsemi-p-fn))
588 (c-lang-defconst c-vsemi-status-unknown-p-fn
589 "Contains a function \"are we unsure whether there is a virtual semicolon on this line?\".
590 The (admittedly kludgy) purpose of such a function is to prevent an infinite
591 recursion in c-beginning-of-statement-1 when point starts at a `while' token.
592 The function MUST NOT UNDER ANY CIRCUMSTANCES call c-beginning-of-statement-1,
593 even indirectly. This variable contains nil for languages which don't have
594 EOL terminated statements."
595 t nil
596 (c c++ objc) 'c-macro-vsemi-status-unknown-p
597 awk 'c-awk-vsemi-status-unknown-p)
598 (c-lang-defvar c-vsemi-status-unknown-p-fn
599 (c-lang-const c-vsemi-status-unknown-p-fn))
602 ;;; Lexer-level syntax (identifiers, tokens etc).
604 (c-lang-defconst c-has-bitfields
605 "Whether the language has bitfield declarations."
606 t nil
607 (c c++ objc) t)
608 (c-lang-defvar c-has-bitfields (c-lang-const c-has-bitfields))
610 (c-lang-defconst c-modified-constant
611 "Regexp that matches a “modified” constant literal such as \"L\\='a\\='\",
612 a “long character”. In particular, this recognizes forms of constant
613 which `c-backward-sexp' needs to be called twice to move backwards over."
614 t nil
615 (c c++ objc) "L'\\([^\\'\t\f\n\r]\\|\\\\.\\)'")
616 ;; FIXME!!! Extend this to cover strings, if needed. 2008-04-11
617 (c-lang-defvar c-modified-constant (c-lang-const c-modified-constant))
619 (c-lang-defconst c-symbol-start
620 "Regexp that matches the start of a symbol, i.e. any identifier or
621 keyword. It's unspecified how far it matches. Does not contain a \\|
622 operator at the top level."
623 t (concat "[" c-alpha "_]")
624 java (concat "[" c-alpha "_@]")
625 objc (concat "[" c-alpha "_@]")
626 pike (concat "[" c-alpha "_`]"))
627 (c-lang-defvar c-symbol-start (c-lang-const c-symbol-start))
629 (c-lang-defconst c-symbol-chars
630 "Set of characters that can be part of a symbol.
631 This is of the form that fits inside [ ] in a regexp."
632 ;; Pike note: With the backquote identifiers this would include most
633 ;; operator chars too, but they are handled with other means instead.
634 t (concat c-alnum "_$")
635 objc (concat c-alnum "_$@"))
636 (c-lang-defvar c-symbol-chars (c-lang-const c-symbol-chars))
638 (c-lang-defconst c-symbol-char-key
639 "Regexp matching a sequence of at least one identifier character."
640 t (concat "[" (c-lang-const c-symbol-chars) "]+"))
641 (c-lang-defvar c-symbol-char-key (c-lang-const c-symbol-char-key))
643 (c-lang-defconst c-symbol-key
644 "Regexp matching identifiers and keywords (with submatch 0). Assumed
645 to match if `c-symbol-start' matches on the same position."
646 t (concat (c-lang-const c-symbol-start)
647 "[" (c-lang-const c-symbol-chars) "]*")
648 pike (concat
649 ;; Use the value from C here since the operator backquote is
650 ;; covered by the other alternative.
651 (c-lang-const c-symbol-key c)
652 "\\|"
653 (c-make-keywords-re nil
654 (c-lang-const c-overloadable-operators))))
655 (c-lang-defvar c-symbol-key (c-lang-const c-symbol-key))
657 (c-lang-defconst c-symbol-key-depth
658 ;; Number of regexp grouping parens in `c-symbol-key'.
659 t (regexp-opt-depth (c-lang-const c-symbol-key)))
661 (c-lang-defconst c-nonsymbol-chars
662 "This is the set of chars that can't be part of a symbol, i.e. the
663 negation of `c-symbol-chars'."
664 t (concat "^" (c-lang-const c-symbol-chars)))
665 (c-lang-defvar c-nonsymbol-chars (c-lang-const c-nonsymbol-chars))
667 (c-lang-defconst c-nonsymbol-key
668 "Regexp that matches any character that can't be part of a symbol.
669 It's usually appended to other regexps to avoid matching a prefix.
670 It's assumed to not contain any submatchers."
671 ;; The same thing regarding Unicode identifiers applies here as to
672 ;; `c-symbol-key'.
673 t (concat "[" (c-lang-const c-nonsymbol-chars) "]"))
675 (c-lang-defconst c-identifier-ops
676 "The operators that make up fully qualified identifiers. nil in
677 languages that don't have such things. See `c-operators' for a
678 description of the format. Binary operators can concatenate symbols,
679 e.g. \"::\" in \"A::B::C\". Prefix operators can precede identifiers,
680 e.g. \"~\" in \"~A::B\". Other types of operators aren't supported.
682 This value is by default merged into `c-operators'."
683 t nil
684 c++ '((prefix "~" "??-" "compl")
685 (right-assoc "::")
686 (prefix "::"))
687 ;; Java has "." to concatenate identifiers but it's also used for
688 ;; normal indexing. There's special code in the Java font lock
689 ;; rules to fontify qualified identifiers based on the standard
690 ;; naming conventions. We still define "." here to make
691 ;; `c-forward-name' move over as long names as possible which is
692 ;; necessary to e.g. handle throws clauses correctly.
693 java '((left-assoc "."))
694 idl '((left-assoc "::")
695 (prefix "::"))
696 pike '((left-assoc "::")
697 (prefix "::")
698 (left-assoc ".")))
700 (c-lang-defconst c-opt-identifier-concat-key
701 ;; Appendable adorned regexp matching the operators that join
702 ;; symbols to fully qualified identifiers, or nil in languages that
703 ;; don't have such things.
705 ;; This was a docstring constant in 5.30. It still works but is now
706 ;; considered internal - change `c-identifier-ops' instead.
707 t (let ((ops (c-filter-ops (c-lang-const c-identifier-ops)
708 '(left-assoc right-assoc)
709 t)))
710 (when ops
711 (c-make-keywords-re 'appendable ops))))
712 (c-lang-defvar c-opt-identifier-concat-key
713 (c-lang-const c-opt-identifier-concat-key)
714 'dont-doc)
716 (c-lang-defconst c-opt-identifier-concat-key-depth
717 ;; Number of regexp grouping parens in `c-opt-identifier-concat-key'.
718 t (regexp-opt-depth (c-lang-const c-opt-identifier-concat-key)))
720 (c-lang-defconst c-opt-identifier-prefix-key
721 ;; Appendable adorned regexp matching operators that might precede
722 ;; an identifier and that are part of the identifier in that case.
723 ;; nil in languages without such things.
724 t (let ((ops (c-filter-ops (c-lang-const c-identifier-ops)
725 '(prefix)
726 t)))
727 (when ops
728 (c-make-keywords-re 'appendable ops))))
730 (c-lang-defconst c-after-id-concat-ops
731 "Operators that can occur after a binary operator on `c-identifier-ops'
732 in identifiers. nil in languages that don't have such things.
734 Operators here should also have appropriate entries in `c-operators' -
735 it's not taken care of by default."
736 t nil
737 ;; '~' for destructors in C++, '*' for member pointers.
738 c++ '("~" "*")
739 ;; In Java we recognize '*' to deal with "foo.bar.*" that can occur
740 ;; in import declarations. (This will also match bogus things like
741 ;; "foo.*bar" but we don't bother.)
742 java '("*"))
744 (c-lang-defconst c-opt-after-id-concat-key
745 ;; Regexp that must match the token after
746 ;; `c-opt-identifier-concat-key' for it to be considered an
747 ;; identifier concatenation operator (which e.g. causes the
748 ;; preceding identifier to be fontified as a reference). Assumed to
749 ;; be a string if `c-opt-identifier-concat-key' is.
751 ;; This was a docstring constant in 5.30. It still works but is now
752 ;; considered internal - change `c-after-id-concat-ops' instead.
753 t (concat (c-lang-const c-symbol-start)
754 (if (c-lang-const c-after-id-concat-ops)
755 (concat "\\|" (c-make-keywords-re 'appendable
756 (c-lang-const c-after-id-concat-ops)))
757 "")))
759 (c-lang-defconst c-identifier-start
760 "Regexp that matches the start of an (optionally qualified) identifier.
761 It should also match all keywords. It's unspecified how far it
762 matches."
763 t (concat (c-lang-const c-symbol-start)
764 (if (c-lang-const c-opt-identifier-prefix-key)
765 (concat "\\|"
766 (c-lang-const c-opt-identifier-prefix-key))
767 "")))
768 (c-lang-defvar c-identifier-start (c-lang-const c-identifier-start))
770 (c-lang-defconst c-identifier-key
771 "Regexp matching a fully qualified identifier, like \"A::B::c\" in
772 C++. It does not recognize the full range of syntactic whitespace
773 between the tokens; `c-forward-name' has to be used for that. It
774 should also not match identifiers containing parenthesis groupings,
775 e.g. identifiers with template arguments such as \"A<X,Y>\" in C++."
776 ;; This regexp is more complex than strictly necessary to ensure
777 ;; that it can be matched with a minimum of backtracking.
778 t (concat (if (c-lang-const c-opt-identifier-prefix-key)
779 (concat
780 "\\("
781 (c-lang-const c-opt-identifier-prefix-key)
782 (c-lang-const c-simple-ws) "*"
783 "\\)?")
785 "\\(" (c-lang-const c-symbol-key) "\\)"
786 (if (c-lang-const c-opt-identifier-concat-key)
787 (concat
788 "\\("
789 (c-lang-const c-simple-ws) "*"
790 (c-lang-const c-opt-identifier-concat-key)
791 (c-lang-const c-simple-ws) "*"
792 (if (c-lang-const c-after-id-concat-ops)
793 (concat
794 "\\("
795 (c-make-keywords-re 'appendable
796 (c-lang-const c-after-id-concat-ops))
797 (concat
798 ;; For flexibility, consider the symbol match
799 ;; optional if we've hit a
800 ;; `c-after-id-concat-ops' operator. This is
801 ;; also necessary to handle the "*" that can
802 ;; end import declaration identifiers in Java.
803 "\\("
804 (c-lang-const c-simple-ws) "*"
805 "\\(" (c-lang-const c-symbol-key) "\\)"
806 "\\)?")
807 "\\|"
808 "\\(" (c-lang-const c-symbol-key) "\\)"
809 "\\)")
810 (concat "\\(" (c-lang-const c-symbol-key) "\\)"))
811 "\\)*")
812 "")))
813 (c-lang-defvar c-identifier-key (c-lang-const c-identifier-key))
815 (c-lang-defconst c-identifier-last-sym-match
816 ;; This was a docstring constant in 5.30 but it's no longer used.
817 ;; It's only kept to avoid breaking third party code.
819 ;; Used to identify the submatch in `c-identifier-key' that
820 ;; surrounds the last symbol in the qualified identifier. It's a
821 ;; list of submatch numbers, of which the first that has a match is
822 ;; taken. It's assumed that at least one does when the regexp has
823 ;; matched.
824 t nil)
826 (c-lang-defconst c-string-escaped-newlines
827 "Set if the language support backslash escaped newlines inside string
828 literals."
829 t nil
830 (c c++ objc pike) t)
831 (c-lang-defvar c-string-escaped-newlines
832 (c-lang-const c-string-escaped-newlines))
834 (c-lang-defconst c-multiline-string-start-char
835 "Set if the language supports multiline string literals without escaped
836 newlines. If t, all string literals are multiline. If a character,
837 only literals where the open quote is immediately preceded by that
838 literal are multiline."
839 t nil
840 pike ?#)
841 (c-lang-defvar c-multiline-string-start-char
842 (c-lang-const c-multiline-string-start-char))
844 (c-lang-defconst c-opt-cpp-symbol
845 "The symbol which starts preprocessor constructs when in the margin."
846 t "#"
847 (java awk) nil)
848 (c-lang-defvar c-opt-cpp-symbol (c-lang-const c-opt-cpp-symbol))
850 (c-lang-defconst c-opt-cpp-prefix
851 "Regexp matching the prefix of a cpp directive in the languages that
852 normally use that macro preprocessor. Tested at bol or at boi.
853 Assumed to not contain any submatches or \\| operators."
854 ;; TODO (ACM, 2005-04-01). Amend the following to recognize escaped NLs;
855 ;; amend all uses of c-opt-cpp-prefix which count regexp-depth.
856 t "\\s *#\\s *"
857 (java awk) nil)
858 (c-lang-defvar c-opt-cpp-prefix (c-lang-const c-opt-cpp-prefix))
860 (c-lang-defconst c-anchored-cpp-prefix
861 "Regexp matching the prefix of a cpp directive anchored to BOL,
862 in the languages that have a macro preprocessor."
863 t "^\\s *\\(#\\)\\s *"
864 (java awk) nil)
865 (c-lang-defvar c-anchored-cpp-prefix (c-lang-const c-anchored-cpp-prefix))
867 (c-lang-defconst c-opt-cpp-start
868 "Regexp matching the prefix of a cpp directive including the directive
869 name, or nil in languages without preprocessor support. The first
870 submatch surrounds the directive name."
871 t (if (c-lang-const c-opt-cpp-prefix)
872 (concat (c-lang-const c-opt-cpp-prefix)
873 "\\([" c-alnum "]+\\)"))
874 ;; Pike, being a scripting language, recognizes hash-bangs too.
875 pike (concat (c-lang-const c-opt-cpp-prefix)
876 "\\([" c-alnum "]+\\|!\\)"))
877 (c-lang-defvar c-opt-cpp-start (c-lang-const c-opt-cpp-start))
879 (c-lang-defconst c-cpp-message-directives
880 "List of cpp directives (without the prefix) that are followed by a
881 string message."
882 t (if (c-lang-const c-opt-cpp-prefix)
883 '("error"))
884 (c c++ objc pike) '("error" "warning"))
886 (c-lang-defconst c-cpp-include-directives
887 "List of cpp directives (without the prefix) that are followed by a
888 file name in angle brackets or quotes."
889 t (if (c-lang-const c-opt-cpp-prefix)
890 '("include"))
891 objc '("include" "import"))
893 (c-lang-defconst c-opt-cpp-macro-define
894 "Cpp directive (without the prefix) that is followed by a macro
895 definition, or nil if the language doesn't have any."
896 t (if (c-lang-const c-opt-cpp-prefix)
897 "define"))
898 (c-lang-defvar c-opt-cpp-macro-define
899 (c-lang-const c-opt-cpp-macro-define))
901 (c-lang-defconst c-opt-cpp-macro-define-start
902 ;; Regexp matching everything up to the macro body of a cpp define, or the
903 ;; end of the logical line if there is none. Submatch 1 is the name of the
904 ;; macro. Set if c-opt-cpp-macro-define is.
905 t (if (c-lang-const c-opt-cpp-macro-define)
906 (concat (c-lang-const c-opt-cpp-prefix)
907 (c-lang-const c-opt-cpp-macro-define)
908 "[ \t]+\\(\\(\\sw\\|_\\)+\\)\\(([^)]*)\\)?"
909 ;; ^ ^ #defined name
910 "\\([ \t]\\|\\\\\n\\)*")))
911 (c-lang-defvar c-opt-cpp-macro-define-start
912 (c-lang-const c-opt-cpp-macro-define-start))
914 (c-lang-defconst c-opt-cpp-macro-define-id
915 ;; Regexp matching everything up to the end of the identifier defined
916 ;; by a cpp define.
917 t (if (c-lang-const c-opt-cpp-macro-define)
918 (concat (c-lang-const c-opt-cpp-prefix) ; #
919 (c-lang-const c-opt-cpp-macro-define) ; define
920 "[ \t]+\\(\\sw\\|_\\)+")))
921 (c-lang-defvar c-opt-cpp-macro-define-id
922 (c-lang-const c-opt-cpp-macro-define-id))
924 (c-lang-defconst c-cpp-expr-directives
925 "List of cpp directives (without the prefix) that are followed by an
926 expression."
927 t (if (c-lang-const c-opt-cpp-prefix)
928 '("if" "elif")))
930 (c-lang-defconst c-cpp-expr-intro-re
931 "Regexp which matches the start of a CPP directive which contains an
932 expression, or nil if there aren't any in the language."
933 t (if (c-lang-const c-cpp-expr-directives)
934 (concat
935 (c-lang-const c-opt-cpp-prefix)
936 (c-make-keywords-re t (c-lang-const c-cpp-expr-directives)))))
937 (c-lang-defvar c-cpp-expr-intro-re
938 (c-lang-const c-cpp-expr-intro-re))
940 (c-lang-defconst c-cpp-expr-functions
941 "List of functions in cpp expressions."
942 t (if (c-lang-const c-opt-cpp-prefix)
943 '("defined"))
944 pike '("defined" "efun" "constant"))
946 (c-lang-defconst c-assignment-operators
947 "List of all assignment operators."
948 t '("=" "*=" "/=" "%=" "+=" "-=" ">>=" "<<=" "&=" "^=" "|=")
949 java (append (c-lang-const c-assignment-operators)
950 '(">>>="))
951 c++ (append (c-lang-const c-assignment-operators)
952 '("and_eq" "or_eq" "xor_eq" "??!=" "??'="))
953 idl nil)
955 (c-lang-defconst c-operators
956 "List describing all operators, along with their precedence and
957 associativity. The order in the list corresponds to the precedence of
958 the operators: The operators in each element are a group with the same
959 precedence, and the group has higher precedence than the groups in all
960 following elements. The car of each element describes the type of the
961 operator group, and the cdr is a list of the operator tokens in it.
962 The operator group types are:
964 `prefix' Unary prefix operators.
965 `postfix' Unary postfix operators.
966 `postfix-if-paren'
967 Unary postfix operators if and only if the chars have
968 parenthesis syntax.
969 `left-assoc' Binary left associative operators (i.e. a+b+c means (a+b)+c).
970 `right-assoc' Binary right associative operators (i.e. a=b=c means a=(b=c)).
971 `right-assoc-sequence'
972 Right associative operator that constitutes of a
973 sequence of tokens that separate expressions. All the
974 tokens in the group are in this case taken as
975 describing the sequence in one such operator, and the
976 order between them is therefore significant.
978 Operators containing a character with paren syntax are taken to match
979 with a corresponding open/close paren somewhere else. A postfix
980 operator with close paren syntax is taken to end a postfix expression
981 started somewhere earlier, rather than start a new one at point. Vice
982 versa for prefix operators with open paren syntax.
984 Note that operators like \".\" and \"->\" which in language references
985 often are described as postfix operators are considered binary here,
986 since CC Mode treats every identifier as an expression."
988 ;; There's currently no code in CC Mode that exploits all the info
989 ;; in this variable; precedence, associativity etc are present as a
990 ;; preparation for future work.
992 ;; FIXME!!! C++11's "auto" operators "=" and "->" need to go in here
993 ;; somewhere. 2012-03-24.
995 t `(;; Preprocessor.
996 ,@(when (c-lang-const c-opt-cpp-prefix)
997 `((prefix "#"
998 ,@(when (c-major-mode-is '(c-mode c++-mode))
999 '("%:" "??=")))
1000 (left-assoc "##"
1001 ,@(when (c-major-mode-is '(c-mode c++-mode))
1002 '("%:%:" "??=??=")))))
1004 ;; Primary.
1005 ,@(c-lang-const c-identifier-ops)
1006 ,@(cond ((or (c-major-mode-is 'c++-mode) (c-major-mode-is 'java-mode))
1007 `((postfix-if-paren "<" ">"))) ; Templates.
1008 ((c-major-mode-is 'pike-mode)
1009 `((prefix "global" "predef")))
1010 ((c-major-mode-is 'java-mode)
1011 `((prefix "super"))))
1013 ;; Postfix.
1014 ,@(when (c-major-mode-is 'c++-mode)
1015 ;; The following need special treatment.
1016 `((prefix "dynamic_cast" "static_cast"
1017 "reinterpret_cast" "const_cast" "typeid"
1018 "alignof")))
1019 (left-assoc "."
1020 ,@(unless (c-major-mode-is 'java-mode)
1021 '("->")))
1022 (postfix "++" "--" "[" "]" "(" ")"
1023 ,@(when (c-major-mode-is '(c-mode c++-mode))
1024 '("<:" ":>" "??(" "??)")))
1026 ;; Unary.
1027 (prefix "++" "--" "+" "-" "!" "~"
1028 ,@(when (c-major-mode-is 'c++-mode) '("not" "compl"))
1029 ,@(when (c-major-mode-is '(c-mode c++-mode))
1030 '("*" "&" "sizeof" "??-"))
1031 ,@(when (c-major-mode-is 'objc-mode)
1032 '("@selector" "@protocol" "@encode"))
1033 ;; The following need special treatment.
1034 ,@(cond ((c-major-mode-is 'c++-mode)
1035 '("new" "delete"))
1036 ((c-major-mode-is 'java-mode)
1037 '("new"))
1038 ((c-major-mode-is 'pike-mode)
1039 '("class" "lambda" "catch" "throw" "gauge")))
1040 "(" ")" ; Cast.
1041 ,@(when (c-major-mode-is 'pike-mode)
1042 '("[" "]"))) ; Type cast.
1044 ;; Member selection.
1045 ,@(when (c-major-mode-is 'c++-mode)
1046 `((left-assoc ".*" "->*")))
1048 ;; Multiplicative.
1049 (left-assoc "*" "/" "%")
1051 ;; Additive.
1052 (left-assoc "+" "-")
1054 ;; Shift.
1055 (left-assoc "<<" ">>"
1056 ,@(when (c-major-mode-is 'java-mode)
1057 '(">>>")))
1059 ;; Relational.
1060 (left-assoc "<" ">" "<=" ">="
1061 ,@(when (c-major-mode-is 'java-mode)
1062 '("instanceof")))
1064 ;; Equality.
1065 (left-assoc "==" "!="
1066 ,@(when (c-major-mode-is 'c++-mode) '("not_eq")))
1068 ;; Bitwise and.
1069 (left-assoc "&"
1070 ,@(when (c-major-mode-is 'c++-mode) '("bitand")))
1072 ;; Bitwise exclusive or.
1073 (left-assoc "^"
1074 ,@(when (c-major-mode-is '(c-mode c++-mode))
1075 '("??'"))
1076 ,@(when (c-major-mode-is 'c++-mode) '("xor")))
1078 ;; Bitwise or.
1079 (left-assoc "|"
1080 ,@(when (c-major-mode-is '(c-mode c++-mode))
1081 '("??!"))
1082 ,@(when (c-major-mode-is 'c++-mode) '("bitor")))
1084 ;; Logical and.
1085 (left-assoc "&&"
1086 ,@(when (c-major-mode-is 'c++-mode) '("and")))
1088 ;; Logical or.
1089 (left-assoc "||"
1090 ,@(when (c-major-mode-is '(c-mode c++-mode))
1091 '("??!??!"))
1092 ,@(when (c-major-mode-is 'c++-mode) '("or")))
1094 ;; Conditional.
1095 (right-assoc-sequence "?" ":")
1097 ;; Assignment.
1098 (right-assoc ,@(c-lang-const c-assignment-operators))
1100 ;; Exception.
1101 ,@(when (c-major-mode-is 'c++-mode)
1102 '((prefix "throw")))
1104 ;; Sequence.
1105 (left-assoc ","))
1107 ;; IDL got its own definition since it has a much smaller operator
1108 ;; set than the other languages.
1109 idl `(;; Preprocessor.
1110 (prefix "#")
1111 (left-assoc "##")
1112 ;; Primary.
1113 ,@(c-lang-const c-identifier-ops)
1114 ;; Unary.
1115 (prefix "+" "-" "~")
1116 ;; Multiplicative.
1117 (left-assoc "*" "/" "%")
1118 ;; Additive.
1119 (left-assoc "+" "-")
1120 ;; Shift.
1121 (left-assoc "<<" ">>")
1122 ;; And.
1123 (left-assoc "&")
1124 ;; Xor.
1125 (left-assoc "^")
1126 ;; Or.
1127 (left-assoc "|")))
1129 (c-lang-defconst c-operator-list
1130 ;; The operators as a flat list (without duplicates).
1131 t (c-filter-ops (c-lang-const c-operators) t t))
1133 (c-lang-defconst c-overloadable-operators
1134 "List of the operators that are overloadable, in their \"identifier
1135 form\". See also `c-op-identifier-prefix'."
1136 t nil
1137 c++ '("new" "delete" ;; Can be followed by "[]" but we ignore that.
1138 "+" "-" "*" "/" "%"
1139 "^" "??'" "xor" "&" "bitand" "|" "??!" "bitor" "~" "??-" "compl"
1140 "!" "=" "<" ">" "+=" "-=" "*=" "/=" "%=" "^="
1141 "??'=" "xor_eq" "&=" "and_eq" "|=" "??!=" "or_eq"
1142 "<<" ">>" ">>=" "<<=" "==" "!=" "not_eq" "<=" ">="
1143 "&&" "and" "||" "??!??!" "or" "++" "--" "," "->*" "->"
1144 "()" "[]" "<::>" "??(??)")
1145 ;; These work like identifiers in Pike.
1146 pike '("`+" "`-" "`&" "`|" "`^" "`<<" "`>>" "`*" "`/" "`%" "`~"
1147 "`==" "`<" "`>" "`!" "`[]" "`[]=" "`->" "`->=" "`()" "``+"
1148 "``-" "``&" "``|" "``^" "``<<" "``>>" "``*" "``/" "``%"
1149 "`+="))
1151 (c-lang-defconst c-overloadable-operators-regexp
1152 ;; Regexp tested after an "operator" token in C++.
1153 t nil
1154 c++ (c-make-keywords-re nil (c-lang-const c-overloadable-operators)))
1155 (c-lang-defvar c-overloadable-operators-regexp
1156 (c-lang-const c-overloadable-operators-regexp))
1158 (c-lang-defconst c-opt-op-identifier-prefix
1159 "Regexp matching the token before the ones in
1160 `c-overloadable-operators' when operators are specified in their
1161 \"identifier form\". This typically matches \"operator\" in C++ where
1162 operator functions are specified as e.g. \"operator +\". It's nil in
1163 languages without operator functions or where the complete operator
1164 identifier is listed in `c-overloadable-operators'.
1166 This regexp is assumed to not match any non-operator identifier."
1167 t nil
1168 c++ (c-make-keywords-re t '("operator")))
1169 (c-lang-defvar c-opt-op-identifier-prefix
1170 (c-lang-const c-opt-op-identifier-prefix))
1172 ;; Note: the following alias is an old name which was a mis-spelling. It has
1173 ;; been corrected above and throughout cc-engine.el. It will be removed at
1174 ;; some release very shortly in the future. ACM, 2006-04-14.
1175 (defvaralias 'c-opt-op-identitier-prefix 'c-opt-op-identifier-prefix)
1176 (make-obsolete-variable 'c-opt-op-identitier-prefix 'c-opt-op-identifier-prefix
1177 "CC Mode 5.31.4, 2006-04-14")
1179 (c-lang-defconst c-other-op-syntax-tokens
1180 "List of the tokens made up of characters in the punctuation or
1181 parenthesis syntax classes that have uses other than as expression
1182 operators."
1183 t '("{" "}" "(" ")" "[" "]" ";" ":" "," "=" "/*" "*/" "//")
1184 (c c++ pike) (append '("#" "##" ; Used by cpp.
1185 "::" "...")
1186 (c-lang-const c-other-op-syntax-tokens))
1187 (c c++) (append '("*") (c-lang-const c-other-op-syntax-tokens))
1188 c++ (append '("&" "<%" "%>" "<:" ":>" "%:" "%:%:")
1189 (c-lang-const c-other-op-syntax-tokens))
1190 objc (append '("#" "##" ; Used by cpp.
1191 "+" "-")
1192 (c-lang-const c-other-op-syntax-tokens))
1193 idl (append '("#" "##") ; Used by cpp.
1194 (c-lang-const c-other-op-syntax-tokens))
1195 pike (append '("..")
1196 (c-lang-const c-other-op-syntax-tokens)
1197 (c-lang-const c-overloadable-operators))
1198 awk '("{" "}" "(" ")" "[" "]" ";" "," "=" "/"))
1200 (c-lang-defconst c-all-op-syntax-tokens
1201 ;; List of all tokens in the punctuation and parenthesis syntax
1202 ;; classes.
1203 t (c--delete-duplicates (append (c-lang-const c-other-op-syntax-tokens)
1204 (c-lang-const c-operator-list))
1205 :test 'string-equal))
1207 (c-lang-defconst c-nonsymbol-token-char-list
1208 ;; List containing all chars not in the word, symbol or
1209 ;; syntactically irrelevant syntax classes, i.e. all punctuation,
1210 ;; parenthesis and string delimiter chars.
1211 t (c-with-syntax-table (c-lang-const c-mode-syntax-table)
1212 ;; Only go through the chars in the printable ASCII range. No
1213 ;; language so far has 8-bit or widestring operators.
1214 (let (list (char 32))
1215 (while (< char 127)
1216 (or (memq (char-syntax char) '(?w ?_ ?< ?> ?\ ))
1217 (setq list (cons (c-int-to-char char) list)))
1218 (setq char (1+ char)))
1219 list)))
1221 (c-lang-defconst c-nonsymbol-token-regexp
1222 ;; Regexp matching all tokens in the punctuation and parenthesis
1223 ;; syntax classes. Note that this also matches ".", which can start
1224 ;; a float.
1225 t (c-make-keywords-re nil
1226 (c-filter-ops (c-lang-const c-all-op-syntax-tokens)
1228 "\\`\\(\\s.\\)+\\'")))
1229 (c-lang-defvar c-nonsymbol-token-regexp
1230 (c-lang-const c-nonsymbol-token-regexp))
1232 (c-lang-defconst c-assignment-op-regexp
1233 ;; Regexp matching all assignment operators and only them. The
1234 ;; beginning of the first submatch is used to detect the end of the
1235 ;; token, along with the end of the whole match.
1236 t (if (c-lang-const c-assignment-operators)
1237 (concat
1238 ;; Need special case for "=" since it's a prefix of "==".
1239 "=\\([^=]\\|$\\)"
1240 "\\|"
1241 (c-make-keywords-re nil
1242 (c--set-difference (c-lang-const c-assignment-operators)
1243 '("=")
1244 :test 'string-equal)))
1245 "\\<\\>"))
1246 (c-lang-defvar c-assignment-op-regexp
1247 (c-lang-const c-assignment-op-regexp))
1249 (c-lang-defconst c-:$-multichar-token-regexp
1250 ;; Regexp matching all tokens ending in ":" which are longer than one char.
1251 ;; Currently (2016-01-07) only used in C++ Mode.
1252 t (c-make-keywords-re nil
1253 (c-filter-ops (c-lang-const c-operators) t ".+:$")))
1254 (c-lang-defvar c-:$-multichar-token-regexp
1255 (c-lang-const c-:$-multichar-token-regexp))
1257 (c-lang-defconst c-<>-multichar-token-regexp
1258 ;; Regexp matching all tokens containing "<" or ">" which are longer
1259 ;; than one char.
1260 t (c-make-keywords-re nil
1261 (c-filter-ops (c-lang-const c-all-op-syntax-tokens)
1263 ".[<>]\\|[<>].")))
1264 (c-lang-defvar c-<>-multichar-token-regexp
1265 (c-lang-const c-<>-multichar-token-regexp))
1267 (c-lang-defconst c-<-op-cont-regexp
1268 ;; Regexp matching the second and subsequent characters of all
1269 ;; multicharacter tokens that begin with "<".
1270 t (c-make-keywords-re nil
1271 (c-filter-ops (c-lang-const c-all-op-syntax-tokens)
1273 "\\`<."
1274 (lambda (op) (substring op 1)))))
1275 (c-lang-defvar c-<-op-cont-regexp (c-lang-const c-<-op-cont-regexp))
1277 (c-lang-defconst c->-op-cont-tokens
1278 ;; A list of second and subsequent characters of all multicharacter tokens
1279 ;; that begin with ">".
1280 t (c-filter-ops (c-lang-const c-all-op-syntax-tokens)
1282 "\\`>."
1283 (lambda (op) (substring op 1)))
1284 java (c-filter-ops (c-lang-const c-all-op-syntax-tokens)
1286 "\\`>[^>]\\|\\`>>[^>]"
1287 (lambda (op) (substring op 1))))
1289 (c-lang-defconst c->-op-cont-regexp
1290 ;; Regexp matching the second and subsequent characters of all
1291 ;; multicharacter tokens that begin with ">".
1292 t (c-make-keywords-re nil (c-lang-const c->-op-cont-tokens)))
1293 (c-lang-defvar c->-op-cont-regexp (c-lang-const c->-op-cont-regexp))
1295 (c-lang-defconst c->-op-without->-cont-regexp
1296 ;; Regexp matching the second and subsequent characters of all
1297 ;; multicharacter tokens that begin with ">" except for those beginning with
1298 ;; ">>".
1299 t (c-make-keywords-re nil
1300 (c--set-difference
1301 (c-lang-const c->-op-cont-tokens)
1302 (c-filter-ops (c-lang-const c-all-op-syntax-tokens)
1304 "\\`>>"
1305 (lambda (op) (substring op 1)))
1306 :test 'string-equal)))
1307 (c-lang-defvar c->-op-without->-cont-regexp
1308 (c-lang-const c->-op-without->-cont-regexp))
1310 (c-lang-defconst c-multichar->-op-not->>-regexp
1311 ;; Regexp matching multichar tokens containing ">", except ">>"
1312 t (c-make-keywords-re nil
1313 (delete ">>"
1314 (c-filter-ops (c-lang-const c-all-op-syntax-tokens)
1316 "\\(.>\\|>.\\)"))))
1317 (c-lang-defvar c-multichar->-op-not->>-regexp
1318 (c-lang-const c-multichar->-op-not->>-regexp))
1320 (c-lang-defconst c-stmt-delim-chars
1321 ;; The characters that should be considered to bound statements. To
1322 ;; optimize `c-crosses-statement-barrier-p' somewhat, it's assumed to
1323 ;; begin with "^" to negate the set. If ? : operators should be
1324 ;; detected then the string must end with "?:".
1325 t "^;{}?:")
1326 (c-lang-defvar c-stmt-delim-chars (c-lang-const c-stmt-delim-chars))
1328 (c-lang-defconst c-stmt-delim-chars-with-comma
1329 ;; Variant of `c-stmt-delim-chars' that additionally contains ','.
1330 t "^;,{}?:")
1331 (c-lang-defvar c-stmt-delim-chars-with-comma
1332 (c-lang-const c-stmt-delim-chars-with-comma))
1334 (c-lang-defconst c-pack-ops
1335 "Ops which signal C++11's \"parameter pack\""
1336 t nil
1337 c++ '("..."))
1338 (c-lang-defconst c-pack-key
1339 t (c-make-keywords-re 'appendable (c-lang-const c-pack-ops)))
1340 (c-lang-defvar c-pack-key (c-lang-const c-pack-key))
1342 (c-lang-defconst c-auto-ops
1343 ;; Ops which signal C++11's new auto uses.
1344 t nil
1345 c++ '("=" "->"))
1346 (c-lang-defconst c-auto-ops-re
1347 t (c-make-keywords-re nil (c-lang-const c-auto-ops)))
1348 (c-lang-defvar c-auto-ops-re (c-lang-const c-auto-ops-re))
1350 (c-lang-defconst c-haskell-op
1351 ;; Op used in the new C++11 auto function definition, indicating type.
1352 t nil
1353 c++ '("->"))
1354 (c-lang-defconst c-haskell-op-re
1355 t (c-make-keywords-re nil (c-lang-const c-haskell-op)))
1356 (c-lang-defvar c-haskell-op-re (c-lang-const c-haskell-op-re))
1358 (c-lang-defconst c-pre-start-tokens
1359 "List of operators following which an apparent declaration \(e.g.
1360 \"t1 *fn (t2 *b);\") is most likely to be an actual declaration
1361 \(as opposed to an arithmetic expression)."
1362 t '(";" "{" "}"))
1363 (c-lang-defvar c-pre-start-tokens (c-lang-const c-pre-start-tokens))
1365 (c-lang-defconst c-pre-lambda-tokens
1366 "List of tokens which may precede a lambda declaration.
1367 In C++ this is something like \"[a,b] (foo, bar) -> int { ... };\".
1368 Currently (2016-08) only used in C++ mode."
1369 t (c--set-difference
1370 (c--delete-duplicates
1371 (append (c-lang-const c-operator-list)
1372 (c-lang-const c-other-op-syntax-tokens)))
1373 (append
1374 '("#" "%:" "??=" "##" "%:%:" "??=??=" "::" "." "->"
1375 "]" "<:" ":>" "??(" "??)" "??-" "new" "delete"
1376 ")" ".*" "->*" "??'" "??!" "??!??!" "??!=" "??'=")
1377 '("<%" "%>" "<:" ":>" "%:" "%:%:" "#" "##" "::" "..."))
1378 :test #'string-equal))
1380 (c-lang-defconst c-pre-lambda-tokens-re
1381 ;; Regexp matching any token in the list `c-pre-lambda-tokens'.
1382 t (regexp-opt (c-lang-const c-pre-lambda-tokens)))
1383 (c-lang-defvar c-pre-lambda-tokens-re (c-lang-const c-pre-lambda-tokens-re))
1385 ;;; Syntactic whitespace.
1387 (c-lang-defconst c-simple-ws
1388 "Regexp matching an ordinary whitespace character.
1389 Does not contain a \\| operator at the top level."
1390 ;; "\\s " is not enough since it doesn't match line breaks.
1391 t "\\(\\s \\|[\n\r]\\)")
1393 (c-lang-defconst c-simple-ws-depth
1394 ;; Number of regexp grouping parens in `c-simple-ws'.
1395 t (regexp-opt-depth (c-lang-const c-simple-ws)))
1397 (c-lang-defconst c-line-comment-starter
1398 "String that starts line comments, or nil if such don't exist.
1399 Line comments are always terminated by newlines. At least one of
1400 `c-block-comment-starter' and this one is assumed to be set.
1402 Note that it's currently not enough to set this to support a new
1403 comment style. Other stuff like the syntax table must also be set up
1404 properly."
1405 t "//"
1406 awk "#")
1407 (c-lang-defvar c-line-comment-starter (c-lang-const c-line-comment-starter))
1409 (c-lang-defconst c-block-comment-starter
1410 "String that starts block comments, or nil if such don't exist.
1411 Block comments are ended by `c-block-comment-ender', which is assumed
1412 to be set if this is. At least one of `c-line-comment-starter' and
1413 this one is assumed to be set.
1415 Note that it's currently not enough to set this to support a new
1416 comment style. Other stuff like the syntax table must also be set up
1417 properly."
1418 t "/*"
1419 awk nil)
1421 (c-lang-defconst c-block-comment-ender
1422 "String that ends block comments, or nil if such don't exist.
1424 Note that it's currently not enough to set this to support a new
1425 comment style. Other stuff like the syntax table must also be set up
1426 properly."
1427 t "*/"
1428 awk nil)
1430 (c-lang-defconst c-comment-start-regexp
1431 ;; Regexp to match the start of any type of comment.
1432 t (let ((re (c-make-keywords-re nil
1433 (list (c-lang-const c-line-comment-starter)
1434 (c-lang-const c-block-comment-starter)))))
1435 (if (memq 'gen-comment-delim c-emacs-features)
1436 (concat re "\\|\\s!")
1437 re)))
1438 (c-lang-defvar c-comment-start-regexp (c-lang-const c-comment-start-regexp))
1440 (c-lang-defconst c-block-comment-start-regexp
1441 ;; Regexp which matches the start of a block comment (if such exists in the
1442 ;; language)
1443 t (if (c-lang-const c-block-comment-starter)
1444 (regexp-quote (c-lang-const c-block-comment-starter))
1445 "\\<\\>"))
1446 (c-lang-defvar c-block-comment-start-regexp
1447 (c-lang-const c-block-comment-start-regexp))
1449 (c-lang-defconst c-line-comment-start-regexp
1450 ;; Regexp which matches the start of a line comment (if such exists in the
1451 ;; language; it does in all 7 CC Mode languages).
1452 t (if (c-lang-const c-line-comment-starter)
1453 (regexp-quote (c-lang-const c-line-comment-starter))
1454 "\\<\\>"))
1455 (c-lang-defvar c-line-comment-start-regexp
1456 (c-lang-const c-line-comment-start-regexp))
1458 (c-lang-defconst c-literal-start-regexp
1459 ;; Regexp to match the start of comments and string literals.
1460 t (concat (c-lang-const c-comment-start-regexp)
1461 "\\|"
1462 (if (memq 'gen-string-delim c-emacs-features)
1463 "\"|"
1464 "\"")))
1465 (c-lang-defvar c-literal-start-regexp (c-lang-const c-literal-start-regexp))
1467 (c-lang-defconst c-doc-comment-start-regexp
1468 "Regexp to match the start of documentation comments."
1469 t "\\<\\>"
1470 ;; From font-lock.el: `doxygen' uses /*! while others use /**.
1471 (c c++ objc) "/\\*[*!]"
1472 java "/\\*\\*"
1473 pike "/[/*]!")
1474 (c-lang-defvar c-doc-comment-start-regexp
1475 (c-lang-const c-doc-comment-start-regexp))
1477 (c-lang-defconst comment-start
1478 "String that starts comments inserted with M-; etc.
1479 `comment-start' is initialized from this."
1480 ;; Default: Prefer line comments to block comments, and pad with a space.
1481 t (concat (or (c-lang-const c-line-comment-starter)
1482 (c-lang-const c-block-comment-starter))
1483 " ")
1484 ;; In C we still default to the block comment style since line
1485 ;; comments aren't entirely portable.
1486 c "/* ")
1487 (c-lang-setvar comment-start (c-lang-const comment-start))
1489 (c-lang-defconst comment-end
1490 "String that ends comments inserted with M-; etc.
1491 `comment-end' is initialized from this."
1492 ;; Default: Use block comment style if comment-start uses block
1493 ;; comments, and pad with a space in that case.
1494 t (if (string-match (concat "\\`\\("
1495 (c-lang-const c-block-comment-start-regexp)
1496 "\\)")
1497 (c-lang-const comment-start))
1498 (concat " " (c-lang-const c-block-comment-ender))
1499 ""))
1500 (c-lang-setvar comment-end (c-lang-const comment-end))
1502 (c-lang-defconst comment-start-skip
1503 "Regexp to match the start of a comment plus everything up to its body.
1504 `comment-start-skip' is initialized from this."
1505 ;; Default: Allow the last char of the comment starter(s) to be
1506 ;; repeated, then allow any amount of horizontal whitespace.
1507 t (concat "\\("
1508 (c-concat-separated
1509 (mapcar (lambda (cs)
1510 (when cs
1511 (concat (regexp-quote cs) "+")))
1512 (list (c-lang-const c-line-comment-starter)
1513 (c-lang-const c-block-comment-starter)))
1514 "\\|")
1515 "\\)\\s *"))
1516 (c-lang-setvar comment-start-skip (c-lang-const comment-start-skip))
1518 (c-lang-defconst comment-end-can-be-escaped
1519 "When non-nil, escaped EOLs inside comments are valid.
1520 This works in Emacs >= 25.1."
1521 t nil
1522 (c c++ objc) t)
1523 (c-lang-setvar comment-end-can-be-escaped
1524 (c-lang-const comment-end-can-be-escaped))
1526 (c-lang-defconst c-syntactic-ws-start
1527 ;; Regexp matching any sequence that can start syntactic whitespace.
1528 ;; The only uncertain case is '#' when there are cpp directives.
1529 t (concat "\\s \\|"
1530 (c-make-keywords-re nil
1531 (append (list (c-lang-const c-line-comment-starter)
1532 (c-lang-const c-block-comment-starter)
1533 (when (c-lang-const c-opt-cpp-prefix)
1534 "#"))
1535 '("\n" "\r")))
1536 "\\|\\\\[\n\r]"
1537 (when (memq 'gen-comment-delim c-emacs-features)
1538 "\\|\\s!")))
1539 (c-lang-defvar c-syntactic-ws-start (c-lang-const c-syntactic-ws-start))
1541 (c-lang-defconst c-syntactic-ws-end
1542 ;; Regexp matching any single character that might end syntactic whitespace.
1543 t (concat "\\s \\|"
1544 (c-make-keywords-re nil
1545 (append (when (c-lang-const c-block-comment-ender)
1546 (list
1547 (string
1548 (elt (c-lang-const c-block-comment-ender)
1549 (1- (length
1550 (c-lang-const c-block-comment-ender)))))))
1551 '("\n" "\r")))
1552 (when (memq 'gen-comment-delim c-emacs-features)
1553 "\\|\\s!")))
1554 (c-lang-defvar c-syntactic-ws-end (c-lang-const c-syntactic-ws-end))
1556 (c-lang-defconst c-unterminated-block-comment-regexp
1557 ;; Regexp matching an unterminated block comment that doesn't
1558 ;; contain line breaks, or nil in languages without block comments.
1559 ;; Does not contain a \| operator at the top level.
1560 t (when (c-lang-const c-block-comment-starter)
1561 (concat
1562 (regexp-quote (c-lang-const c-block-comment-starter))
1563 ;; It's messy to cook together a regexp that matches anything
1564 ;; but c-block-comment-ender.
1565 (let ((end (c-lang-const c-block-comment-ender)))
1566 (cond ((= (length end) 1)
1567 (concat "[^" end "\n\r]*"))
1568 ((= (length end) 2)
1569 (concat "[^" (substring end 0 1) "\n\r]*"
1570 "\\("
1571 (regexp-quote (substring end 0 1)) "+"
1572 "[^"
1573 ;; The quoting rules inside char classes are silly. :P
1574 (cond ((= (elt end 0) (elt end 1))
1575 (concat (substring end 0 1) "\n\r"))
1576 ((= (elt end 1) ?\])
1577 (concat (substring end 1 2) "\n\r"
1578 (substring end 0 1)))
1580 (concat (substring end 0 1) "\n\r"
1581 (substring end 1 2))))
1583 "[^" (substring end 0 1) "\n\r]*"
1584 "\\)*"))
1586 (error "Can't handle a block comment ender of length %s"
1587 (length end))))))))
1589 (c-lang-defconst c-block-comment-regexp
1590 ;; Regexp matching a block comment that doesn't contain line breaks,
1591 ;; or nil in languages without block comments. The reason we don't
1592 ;; allow line breaks is to avoid going very far and risk running out
1593 ;; of regexp stack; this regexp is intended to handle only short
1594 ;; comments that might be put in the middle of limited constructs
1595 ;; like declarations. Does not contain a \| operator at the top
1596 ;; level.
1597 t (when (c-lang-const c-unterminated-block-comment-regexp)
1598 (concat
1599 (c-lang-const c-unterminated-block-comment-regexp)
1600 (let ((end (c-lang-const c-block-comment-ender)))
1601 (cond ((= (length end) 1)
1602 (regexp-quote end))
1603 ((= (length end) 2)
1604 (concat (regexp-quote (substring end 0 1)) "+"
1605 (regexp-quote (substring end 1 2))))
1607 (error "Can't handle a block comment ender of length %s"
1608 (length end))))))))
1610 (c-lang-defconst c-nonwhite-syntactic-ws
1611 ;; Regexp matching a piece of syntactic whitespace that isn't a
1612 ;; sequence of simple whitespace characters. As opposed to
1613 ;; `c-(forward|backward)-syntactic-ws', this doesn't regard cpp
1614 ;; directives as syntactic whitespace.
1615 t (c-concat-separated
1616 (list (when (c-lang-const c-line-comment-starter)
1617 (concat (regexp-quote (c-lang-const c-line-comment-starter))
1618 "[^\n\r]*[\n\r]"))
1619 (c-lang-const c-block-comment-regexp)
1620 "\\\\[\n\r]"
1621 (when (memq 'gen-comment-delim c-emacs-features)
1622 "\\s!\\S!*\\s!"))
1623 "\\|"))
1625 (c-lang-defconst c-syntactic-ws
1626 ;; Regexp matching syntactic whitespace, including possibly the
1627 ;; empty string. As opposed to `c-(forward|backward)-syntactic-ws',
1628 ;; this doesn't regard cpp directives as syntactic whitespace. Does
1629 ;; not contain a \| operator at the top level.
1630 t (concat (c-lang-const c-simple-ws) "*"
1631 "\\("
1632 (concat "\\(" (c-lang-const c-nonwhite-syntactic-ws) "\\)"
1633 (c-lang-const c-simple-ws) "*")
1634 "\\)*"))
1636 (c-lang-defconst c-syntactic-ws-depth
1637 ;; Number of regexp grouping parens in `c-syntactic-ws'.
1638 t (regexp-opt-depth (c-lang-const c-syntactic-ws)))
1640 (c-lang-defconst c-nonempty-syntactic-ws
1641 ;; Regexp matching syntactic whitespace, which is at least one
1642 ;; character long. As opposed to `c-(forward|backward)-syntactic-ws',
1643 ;; this doesn't regard cpp directives as syntactic whitespace. Does
1644 ;; not contain a \| operator at the top level.
1645 t (concat "\\("
1646 (c-lang-const c-simple-ws)
1647 "\\|"
1648 (c-lang-const c-nonwhite-syntactic-ws)
1649 "\\)+"))
1651 (c-lang-defconst c-nonempty-syntactic-ws-depth
1652 ;; Number of regexp grouping parens in `c-nonempty-syntactic-ws'.
1653 t (regexp-opt-depth (c-lang-const c-nonempty-syntactic-ws)))
1655 (c-lang-defconst c-single-line-syntactic-ws
1656 ;; Regexp matching syntactic whitespace without any line breaks. As
1657 ;; opposed to `c-(forward|backward)-syntactic-ws', this doesn't
1658 ;; regard cpp directives as syntactic whitespace. Does not contain
1659 ;; a \| operator at the top level.
1660 t (if (c-lang-const c-block-comment-regexp)
1661 (concat "\\s *\\("
1662 (c-lang-const c-block-comment-regexp)
1663 "\\s *\\)*")
1664 "\\s *"))
1666 (c-lang-defconst c-single-line-syntactic-ws-depth
1667 ;; Number of regexp grouping parens in `c-single-line-syntactic-ws'.
1668 t (regexp-opt-depth (c-lang-const c-single-line-syntactic-ws)))
1670 (c-lang-defconst c-syntactic-eol
1671 ;; Regexp that matches when there is no syntactically significant
1672 ;; text before eol. Macros are regarded as syntactically
1673 ;; significant text here.
1674 t (concat (c-lang-const c-single-line-syntactic-ws)
1675 ;; Match eol (possibly inside a block comment or preceded
1676 ;; by a line continuation backslash), or the beginning of a
1677 ;; line comment. Note: This has to be modified for awk
1678 ;; where line comments start with '#'.
1679 "\\("
1680 (c-concat-separated
1681 (list (when (c-lang-const c-line-comment-starter)
1682 (regexp-quote (c-lang-const c-line-comment-starter)))
1683 (when (c-lang-const c-unterminated-block-comment-regexp)
1684 (concat (c-lang-const c-unterminated-block-comment-regexp)
1685 "$"))
1686 "\\\\$"
1687 "$")
1688 "\\|")
1689 "\\)"))
1690 (c-lang-defvar c-syntactic-eol (c-lang-const c-syntactic-eol))
1693 ;;; Defun handling.
1695 ;; The Emacs variables beginning-of-defun-function and end-of-defun-function
1696 ;; will be set so that commands like `mark-defun' and `narrow-to-defun' work
1697 ;; right. In older Emacsen, the key sequences C-M-a and C-M-e are, however,
1698 ;; bound directly to the CC Mode functions, allowing optimization for large n.
1699 ;; From Emacs 23, this isn't necessary any more, since n is passed to the two
1700 ;; functions.
1701 (c-lang-defconst beginning-of-defun-function
1702 "Function to which beginning-of-defun-function will be set."
1703 t 'c-beginning-of-defun
1704 awk 'c-awk-beginning-of-defun)
1705 (c-lang-setvar beginning-of-defun-function
1706 (c-lang-const beginning-of-defun-function))
1708 (c-lang-defconst end-of-defun-function
1709 "Function to which end-of-defun-function will be set."
1710 t 'c-end-of-defun
1711 awk 'c-awk-end-of-defun)
1712 (c-lang-setvar end-of-defun-function (c-lang-const end-of-defun-function))
1714 ;;; In-comment text handling.
1716 (c-lang-defconst c-paragraph-start
1717 "Regexp to append to `paragraph-start'."
1718 t "$"
1719 java "\\(@[a-zA-Z]+\\>\\|$\\)" ; For Javadoc.
1720 pike "\\(@[a-zA-Z_-]+\\>\\([^{]\\|$\\)\\|$\\)") ; For Pike refdoc.
1721 (c-lang-defvar c-paragraph-start (c-lang-const c-paragraph-start))
1723 (c-lang-defconst c-paragraph-separate
1724 "Regexp to append to `paragraph-separate'."
1725 t "$"
1726 pike (c-lang-const c-paragraph-start))
1727 (c-lang-defvar c-paragraph-separate (c-lang-const c-paragraph-separate))
1730 ;;; Keyword lists.
1732 ;; Note: All and only all language constants containing keyword lists
1733 ;; should end with "-kwds"; they're automatically collected into the
1734 ;; `c-kwds-lang-consts' list below and used to build `c-keywords' etc.
1736 (c-lang-defconst c-primitive-type-kwds
1737 "Primitive type keywords. As opposed to the other keyword lists, the
1738 keywords listed here are fontified with the type face instead of the
1739 keyword face.
1741 If any of these also are on `c-type-list-kwds', `c-ref-list-kwds',
1742 `c-colon-type-list-kwds', `c-paren-nontype-kwds', `c-paren-type-kwds',
1743 `c-<>-type-kwds', or `c-<>-arglist-kwds' then the associated clauses
1744 will be handled.
1746 Do not try to modify this list for end user customizations; the
1747 `*-font-lock-extra-types' variable, where `*' is the mode prefix, is
1748 the appropriate place for that."
1749 t '("char" "double" "float" "int" "long" "short" "signed"
1750 "unsigned" "void")
1751 c (append
1752 '("_Bool" "_Complex" "_Imaginary") ; Conditionally defined in C99.
1753 (c-lang-const c-primitive-type-kwds))
1754 c++ (append
1755 '("bool" "wchar_t" "char16_t" "char32_t")
1756 (c-lang-const c-primitive-type-kwds))
1757 ;; Objective-C extends C, but probably not the new stuff in C99.
1758 objc (append
1759 '("id" "Class" "SEL" "IMP" "BOOL")
1760 (c-lang-const c-primitive-type-kwds))
1761 java '("boolean" "byte" "char" "double" "float" "int" "long" "short" "void")
1762 idl '("Object" "ValueBase" "any" "boolean" "char" "double" "fixed" "float"
1763 "long" "octet" "sequence" "short" "string" "void" "wchar" "wstring"
1764 ;; In CORBA PSDL:
1765 "ref"
1766 ;; The following can't really end a type, but we have to specify them
1767 ;; here due to the assumption in `c-primitive-type-prefix-kwds'. It
1768 ;; doesn't matter that much.
1769 "unsigned" "strong")
1770 pike '(;; this_program isn't really a keyword, but it's practically
1771 ;; used as a builtin type.
1772 "array" "float" "function" "int" "mapping" "mixed" "multiset"
1773 "object" "program" "string" "this_program" "void"))
1775 (c-lang-defconst c-primitive-type-key
1776 ;; An adorned regexp that matches `c-primitive-type-kwds'.
1777 t (c-make-keywords-re t (c-lang-const c-primitive-type-kwds)))
1778 (c-lang-defvar c-primitive-type-key (c-lang-const c-primitive-type-key))
1780 (c-lang-defconst c-primitive-type-prefix-kwds
1781 "Keywords that might act as prefixes for primitive types. Assumed to
1782 be a subset of `c-primitive-type-kwds'."
1783 t nil
1784 (c c++) '("long" "short" "signed" "unsigned")
1785 idl '("long" "unsigned"
1786 ;; In CORBA PSDL:
1787 "strong"))
1789 (c-lang-defconst c-typedef-kwds
1790 "Prefix keyword(s) like \"typedef\" which make a type declaration out
1791 of a variable declaration."
1792 t '("typedef")
1793 (awk idl java) nil)
1795 (c-lang-defconst c-typedef-key
1796 ;; Adorned regexp matching `c-typedef-kwds'.
1797 t (c-make-keywords-re t (c-lang-const c-typedef-kwds)))
1798 (c-lang-defvar c-typedef-key (c-lang-const c-typedef-key))
1800 (c-lang-defconst c-typeof-kwds
1801 "Keywords followed by a parenthesized expression, which stands for
1802 the type of that expression."
1803 t nil
1804 c '("typeof") ; longstanding GNU C(++) extension.
1805 c++ '("decltype" "typeof"))
1807 (c-lang-defconst c-typeof-key
1808 ;; Adorned regexp matching `c-typeof-kwds'.
1809 t (c-make-keywords-re t (c-lang-const c-typeof-kwds)))
1810 (c-lang-defvar c-typeof-key (c-lang-const c-typeof-key))
1812 (c-lang-defconst c-type-prefix-kwds
1813 "Keywords where the following name - if any - is a type name, and
1814 where the keyword together with the symbol works as a type in
1815 declarations.
1817 Note that an alternative if the second part doesn't hold is
1818 `c-type-list-kwds'. Keywords on this list are typically also present
1819 on one of the `*-decl-kwds' lists."
1820 t nil
1821 c '("struct" "union" "enum")
1822 c++ (append '("class" "typename")
1823 (c-lang-const c-type-prefix-kwds c)))
1825 (c-lang-defconst c-type-prefix-key
1826 ;; Adorned regexp matching `c-type-prefix-kwds'.
1827 t (c-make-keywords-re t (c-lang-const c-type-prefix-kwds)))
1828 (c-lang-defvar c-type-prefix-key (c-lang-const c-type-prefix-key))
1830 (c-lang-defconst c-type-modifier-kwds
1831 "Type modifier keywords. These can occur almost anywhere in types
1832 but they don't build a type of themselves. Unlike the keywords on
1833 `c-primitive-type-kwds', they are fontified with the keyword face and
1834 not the type face."
1835 t nil
1836 c '("const" "restrict" "volatile")
1837 c++ '("const" "noexcept" "volatile" "throw" "final" "override")
1838 objc '("const" "volatile"))
1840 (c-lang-defconst c-opt-type-modifier-key
1841 ;; Adorned regexp matching `c-type-modifier-kwds', or nil in
1842 ;; languages without such keywords.
1843 t (and (c-lang-const c-type-modifier-kwds)
1844 (c-make-keywords-re t (c-lang-const c-type-modifier-kwds))))
1845 (c-lang-defvar c-opt-type-modifier-key (c-lang-const c-opt-type-modifier-key))
1847 (c-lang-defconst c-opt-type-component-key
1848 ;; An adorned regexp that matches `c-primitive-type-prefix-kwds' and
1849 ;; `c-type-modifier-kwds', or nil in languages without any of them.
1850 t (and (or (c-lang-const c-primitive-type-prefix-kwds)
1851 (c-lang-const c-type-modifier-kwds))
1852 (c-make-keywords-re t
1853 (append (c-lang-const c-primitive-type-prefix-kwds)
1854 (c-lang-const c-type-modifier-kwds)))))
1855 (c-lang-defvar c-opt-type-component-key
1856 (c-lang-const c-opt-type-component-key))
1858 (c-lang-defconst c-type-start-kwds
1859 ;; All keywords that can start a type (i.e. are either a type prefix
1860 ;; or a complete type).
1861 t (c--delete-duplicates (append (c-lang-const c-primitive-type-kwds)
1862 (c-lang-const c-type-prefix-kwds)
1863 (c-lang-const c-type-modifier-kwds))
1864 :test 'string-equal))
1866 (c-lang-defconst c-class-decl-kwds
1867 "Keywords introducing declarations where the following block (if any)
1868 contains another declaration level that should be considered a class.
1870 If any of these also are on `c-type-list-kwds', `c-ref-list-kwds',
1871 `c-colon-type-list-kwds', `c-paren-nontype-kwds', `c-paren-type-kwds',
1872 `c-<>-type-kwds', or `c-<>-arglist-kwds' then the associated clauses
1873 will be handled.
1875 Note that presence on this list does not automatically treat the
1876 following identifier as a type; the keyword must also be present on
1877 `c-type-prefix-kwds' or `c-type-list-kwds' to accomplish that."
1878 t nil
1879 c '("struct" "union")
1880 c++ '("class" "struct" "union")
1881 objc '("struct" "union"
1882 "@interface" "@implementation" "@protocol")
1883 java '("class" "@interface" "interface")
1884 idl '("component" "eventtype" "exception" "home" "interface" "struct"
1885 "union" "valuetype"
1886 ;; In CORBA PSDL:
1887 "storagehome" "storagetype"
1888 ;; In CORBA CIDL:
1889 "catalog" "executor" "manages" "segment")
1890 pike '("class"))
1892 (c-lang-defconst c-class-key
1893 ;; Regexp matching the start of a class.
1894 t (c-make-keywords-re t (c-lang-const c-class-decl-kwds)))
1895 (c-lang-defvar c-class-key (c-lang-const c-class-key))
1897 (c-lang-defconst c-brace-list-decl-kwds
1898 "Keywords introducing declarations where the following block (if
1899 any) is a brace list.
1901 If any of these also are on `c-type-list-kwds', `c-ref-list-kwds',
1902 `c-colon-type-list-kwds', `c-paren-nontype-kwds', `c-paren-type-kwds',
1903 `c-<>-type-kwds', or `c-<>-arglist-kwds' then the associated clauses
1904 will be handled."
1905 t '("enum")
1906 (awk) nil)
1908 (c-lang-defconst c-brace-list-key
1909 ;; Regexp matching the start of declarations where the following
1910 ;; block is a brace list.
1911 t (c-make-keywords-re t (c-lang-const c-brace-list-decl-kwds)))
1912 (c-lang-defvar c-brace-list-key (c-lang-const c-brace-list-key))
1914 (c-lang-defconst c-after-brace-list-decl-kwds
1915 "Keywords that might follow keywords in `c-brace-list-decl-kwds'
1916 and precede the opening brace."
1917 t nil
1918 c++ '("class" "struct"))
1920 (c-lang-defconst c-after-brace-list-key
1921 ;; Regexp matching keywords that can fall between a brace-list
1922 ;; keyword and the associated brace list.
1923 t (c-make-keywords-re t (c-lang-const c-after-brace-list-decl-kwds)))
1924 (c-lang-defvar c-after-brace-list-key (c-lang-const c-after-brace-list-key))
1926 (c-lang-defconst c-recognize-post-brace-list-type-p
1927 "Set to t when we recognize a colon and then a type after an enum,
1928 e.g., enum foo : int { A, B, C };"
1929 t nil
1930 c++ t)
1931 (c-lang-defvar c-recognize-post-brace-list-type-p
1932 (c-lang-const c-recognize-post-brace-list-type-p))
1934 (c-lang-defconst c-other-block-decl-kwds
1935 "Keywords where the following block (if any) contains another
1936 declaration level that should not be considered a class. For every
1937 keyword here, CC Mode will add a set of special syntactic symbols for
1938 those blocks. E.g. if the keyword is \"foo\" then there will be
1939 `foo-open', `foo-close', and `infoo' symbols.
1941 The intention is that this category should be used for block
1942 constructs that aren't related to object orientation concepts like
1943 classes (which thus also include e.g. interfaces, templates,
1944 contracts, structs, etc). The more pragmatic distinction is that
1945 while most want some indentation inside classes, it's fairly common
1946 that they don't want it in some of these constructs, so it should be
1947 simple to configure that differently from classes. See also
1948 `c-class-decl-kwds'.
1950 If any of these also are on `c-type-list-kwds', `c-ref-list-kwds',
1951 `c-colon-type-list-kwds', `c-paren-nontype-kwds', `c-paren-type-kwds',
1952 `c-<>-type-kwds', or `c-<>-arglist-kwds' then the associated clauses
1953 will be handled."
1954 t nil
1955 (c objc) '("extern")
1956 c++ '("namespace" "extern")
1957 idl '("module"
1958 ;; In CORBA CIDL:
1959 "composition"))
1961 (c-lang-defconst c-other-decl-block-key
1962 ;; Regexp matching the start of blocks besides classes that contain
1963 ;; another declaration level.
1964 t (c-make-keywords-re t (c-lang-const c-other-block-decl-kwds)))
1965 (c-lang-defvar c-other-decl-block-key (c-lang-const c-other-decl-block-key))
1967 (c-lang-defvar c-other-decl-block-key-in-symbols-alist
1968 (mapcar
1969 (lambda (elt)
1970 (cons elt
1971 (if (string= elt "extern")
1972 'inextern-lang
1973 (intern (concat "in" elt)))))
1974 (c-lang-const c-other-block-decl-kwds))
1975 "Alist associating keywords in c-other-decl-block-decl-kwds with
1976 their matching \"in\" syntactic symbols.")
1978 (c-lang-defconst c-typedef-decl-kwds
1979 "Keywords introducing declarations where the identifier(s) being
1980 declared are types.
1982 If any of these also are on `c-type-list-kwds', `c-ref-list-kwds',
1983 `c-colon-type-list-kwds', `c-paren-nontype-kwds', `c-paren-type-kwds',
1984 `c-<>-type-kwds', or `c-<>-arglist-kwds' then the associated clauses
1985 will be handled."
1986 ;; Default to `c-class-decl-kwds' and `c-brace-list-decl-kwds'
1987 ;; (since e.g. "Foo" is a type that's being defined in "class Foo
1988 ;; {...}").
1989 t (append (c-lang-const c-class-decl-kwds)
1990 (c-lang-const c-brace-list-decl-kwds))
1991 ;; Languages that have a "typedef" construct.
1992 (c c++ objc idl pike) (append (c-lang-const c-typedef-decl-kwds)
1993 '("typedef"))
1994 ;; Unlike most other languages, exception names are not handled as
1995 ;; types in IDL since they only can occur in "raises" specs.
1996 idl (delete "exception" (append (c-lang-const c-typedef-decl-kwds) nil)))
1998 (c-lang-defconst c-typedef-decl-key
1999 t (c-make-keywords-re t (c-lang-const c-typedef-decl-kwds)))
2000 (c-lang-defvar c-typedef-decl-key (c-lang-const c-typedef-decl-key))
2002 (c-lang-defconst c-typeless-decl-kwds
2003 "Keywords introducing declarations where the \(first) identifier
2004 \(declarator) follows directly after the keyword, without any type.
2006 If any of these also are on `c-type-list-kwds', `c-ref-list-kwds',
2007 `c-colon-type-list-kwds', `c-paren-nontype-kwds', `c-paren-type-kwds',
2008 `c-<>-type-kwds', or `c-<>-arglist-kwds' then the associated clauses
2009 will be handled."
2010 ;; Default to `c-class-decl-kwds' and `c-brace-list-decl-kwds'
2011 ;; (since e.g. "Foo" is the identifier being defined in "class Foo
2012 ;; {...}").
2013 t (append (c-lang-const c-class-decl-kwds)
2014 (c-lang-const c-brace-list-decl-kwds))
2015 c++ (append (c-lang-const c-typeless-decl-kwds) '("auto")) ; C++11.
2016 ;; Note: "manages" for CORBA CIDL clashes with its presence on
2017 ;; `c-type-list-kwds' for IDL.
2018 idl (append (c-lang-const c-typeless-decl-kwds)
2019 '("factory" "finder" "native"
2020 ;; In CORBA PSDL:
2021 "key" "stores"
2022 ;; In CORBA CIDL:
2023 "facet"))
2024 pike (append (c-lang-const c-class-decl-kwds)
2025 '("constant")))
2027 (c-lang-defconst c-modifier-kwds
2028 "Keywords that can prefix normal declarations of identifiers
2029 \(and typically act as flags). Things like argument declarations
2030 inside function headers are also considered declarations in this
2031 sense.
2033 If any of these also are on `c-type-list-kwds', `c-ref-list-kwds',
2034 `c-colon-type-list-kwds', `c-paren-nontype-kwds', `c-paren-type-kwds',
2035 `c-<>-type-kwds', or `c-<>-arglist-kwds' then the associated clauses
2036 will be handled."
2037 t nil
2038 (c c++) '("auto" "extern" "inline" "register" "static")
2039 c++ (append '("constexpr" "explicit" "friend" "mutable" "template"
2040 "thread_local" "using" "virtual")
2041 (c-lang-const c-modifier-kwds))
2042 objc '("auto" "bycopy" "byref" "extern" "in" "inout" "oneway" "out" "static")
2043 ;; FIXME: Some of those below ought to be on `c-other-decl-kwds' instead.
2044 idl '("abstract" "attribute" "const" "consumes" "custom" "emits" "import"
2045 "in" "inout" "local" "multiple" "oneway" "out" "private" "provides"
2046 "public" "publishes" "readonly" "typeid" "typeprefix" "uses"
2047 ;; In CORBA PSDL:
2048 "primary" "state"
2049 ;; In CORBA CIDL:
2050 "bindsTo" "delegatesTo" "implements" "proxy" "storedOn")
2051 ;; Note: "const" is not used in Java, but it's still a reserved keyword.
2052 java '("abstract" "const" "default" "final" "native" "private" "protected"
2053 "public" "static" "strictfp" "synchronized" "transient" "volatile")
2054 pike '("final" "inline" "local" "nomask" "optional" "private" "protected"
2055 "public" "static" "variant"))
2057 (c-lang-defconst c-other-decl-kwds
2058 "Keywords that can start or prefix any declaration level construct,
2059 besides those on `c-class-decl-kwds', `c-brace-list-decl-kwds',
2060 `c-other-block-decl-kwds', `c-typedef-decl-kwds',
2061 `c-typeless-decl-kwds' and `c-modifier-kwds'.
2063 If any of these also are on `c-type-list-kwds', `c-ref-list-kwds',
2064 `c-colon-type-list-kwds', `c-paren-nontype-kwds', `c-paren-type-kwds',
2065 `c-<>-type-kwds', or `c-<>-arglist-kwds' then the associated clauses
2066 will be handled."
2067 t nil
2068 objc '("@class" "@end" "@defs")
2069 java '("import" "package")
2070 pike '("import" "inherit"))
2072 (c-lang-defconst c-decl-start-kwds
2073 "Keywords that always start declarations, wherever they occur.
2074 This can be used for declarations that aren't recognized by the normal
2075 combination of `c-decl-prefix-re' and `c-decl-start-re'."
2076 t nil
2077 ;; Classes can be declared anywhere in a Pike expression.
2078 pike '("class"))
2080 (c-lang-defconst c-decl-hangon-kwds
2081 "Keywords that can occur anywhere in a declaration level construct.
2082 This is used for self-contained things that can be tacked on anywhere
2083 on a declaration and that should be ignored to be able to recognize it
2084 correctly. Typical cases are compiler extensions like
2085 \"__attribute__\" or \"__declspec\":
2087 __declspec(noreturn) void foo();
2088 class __declspec(dllexport) classname {...};
2089 void foo() __attribute__((noreturn));
2091 Note that unrecognized plain symbols are skipped anyway if they occur
2092 before the type, so such things are not necessary to mention here.
2093 Mentioning them here is necessary only if they can occur in other
2094 places, or if they are followed by a construct that must be skipped
2095 over \(like the parens in the \"__attribute__\" and \"__declspec\"
2096 examples above). In the last case, they alse need to be present on
2097 one of `c-type-list-kwds', `c-ref-list-kwds',
2098 `c-colon-type-list-kwds', `c-paren-nontype-kwds', `c-paren-type-kwds',
2099 `c-<>-type-kwds', or `c-<>-arglist-kwds'."
2100 ;; NB: These are currently not recognized in all parts of a
2101 ;; declaration. Specifically, they aren't recognized in the middle
2102 ;; of multi-token types, inside declarators, and between the
2103 ;; identifier and the arglist paren of a function declaration.
2105 ;; FIXME: This ought to be user customizable since compiler stuff
2106 ;; like this usually is wrapped in project specific macros. (It'd
2107 ;; of course be even better if we could cope without knowing this.)
2108 t nil
2109 (c c++) '(;; GCC extension.
2110 "__attribute__"
2111 ;; MSVC extension.
2112 "__declspec"))
2114 (c-lang-defconst c-decl-hangon-key
2115 ;; Adorned regexp matching `c-decl-hangon-kwds'.
2116 t (c-make-keywords-re t (c-lang-const c-decl-hangon-kwds)))
2117 (c-lang-defvar c-decl-hangon-key (c-lang-const c-decl-hangon-key))
2119 (c-lang-defconst c-prefix-spec-kwds
2120 ;; All keywords that can occur in the preamble of a declaration.
2121 ;; They typically occur before the type, but they are also matched
2122 ;; after presumptive types since we often can't be sure that
2123 ;; something is a type or just some sort of macro in front of the
2124 ;; declaration. They might be ambiguous with types or type
2125 ;; prefixes.
2126 t (c--delete-duplicates (append (c-lang-const c-class-decl-kwds)
2127 (c-lang-const c-brace-list-decl-kwds)
2128 (c-lang-const c-other-block-decl-kwds)
2129 (c-lang-const c-typedef-decl-kwds)
2130 (c-lang-const c-typeless-decl-kwds)
2131 (c-lang-const c-modifier-kwds)
2132 (c-lang-const c-other-decl-kwds)
2133 (c-lang-const c-decl-start-kwds)
2134 (c-lang-const c-decl-hangon-kwds))
2135 :test 'string-equal))
2137 (c-lang-defconst c-prefix-spec-kwds-re
2138 ;; Adorned regexp of `c-prefix-spec-kwds'.
2139 t (c-make-keywords-re t (c-lang-const c-prefix-spec-kwds)))
2141 (c-lang-defvar c-prefix-spec-kwds-re (c-lang-const c-prefix-spec-kwds-re))
2143 (c-lang-defconst c-specifier-key
2144 ;; Adorned regexp of the keywords in `c-prefix-spec-kwds' that aren't
2145 ;; ambiguous with types or type prefixes. These are the keywords (like
2146 ;; extern, namespace, but NOT template) that can modify a declaration.
2147 t (c-make-keywords-re t
2148 (c--set-difference (c-lang-const c-prefix-spec-kwds)
2149 (append (c-lang-const c-type-start-kwds)
2150 (c-lang-const c-<>-arglist-kwds))
2151 :test 'string-equal)))
2152 (c-lang-defvar c-specifier-key (c-lang-const c-specifier-key))
2154 (c-lang-defconst c-postfix-spec-kwds
2155 ;; Keywords that can occur after argument list of a function header
2156 ;; declaration, i.e. in the "K&R region".
2157 t (append (c-lang-const c-postfix-decl-spec-kwds)
2158 (c-lang-const c-decl-hangon-kwds)))
2160 (c-lang-defconst c-not-decl-init-keywords
2161 ;; Adorned regexp matching all keywords that can't appear at the
2162 ;; start of a declaration.
2163 t (c-make-keywords-re t
2164 (c--set-difference (c-lang-const c-keywords)
2165 (append (c-lang-const c-type-start-kwds)
2166 (c-lang-const c-prefix-spec-kwds)
2167 (c-lang-const c-typeof-kwds))
2168 :test 'string-equal)))
2169 (c-lang-defvar c-not-decl-init-keywords
2170 (c-lang-const c-not-decl-init-keywords))
2172 (c-lang-defconst c-not-primitive-type-keywords
2173 "List of all keywords apart from primitive types (like \"int\")."
2174 t (c--set-difference (c-lang-const c-keywords)
2175 (c-lang-const c-primitive-type-kwds)
2176 :test 'string-equal)
2177 ;; The "more" for C++ is the QT keyword (as in "more slots:").
2178 ;; This variable is intended for use in c-beginning-of-statement-1.
2179 c++ (append (c-lang-const c-not-primitive-type-keywords) '("more")))
2181 (c-lang-defconst c-not-primitive-type-keywords-regexp
2182 t (c-make-keywords-re t
2183 (c-lang-const c-not-primitive-type-keywords)))
2184 (c-lang-defvar c-not-primitive-type-keywords-regexp
2185 (c-lang-const c-not-primitive-type-keywords-regexp))
2187 (c-lang-defconst c-protection-kwds
2188 "Access protection label keywords in classes."
2189 t nil
2190 c++ '("private" "protected" "public")
2191 objc '("@private" "@protected" "@public"))
2193 (c-lang-defconst c-block-decls-with-vars
2194 "Keywords introducing declarations that can contain a block which
2195 might be followed by variable declarations, e.g. like \"foo\" in
2196 \"class Foo { ... } foo;\". So if there is a block in a declaration
2197 like that, it ends with the following `;' and not right away.
2199 The keywords on list are assumed to also be present on one of the
2200 `*-decl-kwds' lists."
2201 t nil
2202 (c objc) '("struct" "union" "enum" "typedef")
2203 c++ '("class" "struct" "union" "enum" "typedef"))
2205 (c-lang-defconst c-opt-block-decls-with-vars-key
2206 ;; Regexp matching the `c-block-decls-with-vars' keywords, or nil in
2207 ;; languages without such constructs.
2208 t (and (c-lang-const c-block-decls-with-vars)
2209 (c-make-keywords-re t (c-lang-const c-block-decls-with-vars))))
2210 (c-lang-defvar c-opt-block-decls-with-vars-key
2211 (c-lang-const c-opt-block-decls-with-vars-key))
2213 (c-lang-defconst c-postfix-decl-spec-kwds
2214 "Keywords introducing extra declaration specifiers in the region
2215 between the header and the body \(i.e. the \"K&R-region\") in
2216 declarations."
2217 t nil
2218 java '("extends" "implements" "throws")
2219 idl '("context" "getraises" "manages" "primarykey" "raises" "setraises"
2220 "supports"
2221 ;; In CORBA PSDL:
2222 "as" "const" "implements" "of" "ref"))
2224 (c-lang-defconst c-postfix-decl-spec-key
2225 ;; Regexp matching the keywords in `c-postfix-decl-spec-kwds'.
2226 t (c-make-keywords-re t (c-lang-const c-postfix-decl-spec-kwds)))
2227 (c-lang-defvar c-postfix-decl-spec-key
2228 (c-lang-const c-postfix-decl-spec-key))
2230 (c-lang-defconst c-nonsymbol-sexp-kwds
2231 "Keywords that may be followed by a nonsymbol sexp before whatever
2232 construct it's part of continues."
2233 t nil
2234 (c c++ objc) '("extern"))
2236 (c-lang-defconst c-type-list-kwds
2237 "Keywords that may be followed by a comma separated list of type
2238 identifiers, where each optionally can be prefixed by keywords. (Can
2239 also be used for the special case when the list can contain only one
2240 element.)
2242 Assumed to be mutually exclusive with `c-ref-list-kwds'. There's no
2243 reason to put keywords on this list if they are on `c-type-prefix-kwds'.
2244 There's also no reason to add keywords that prefixes a normal
2245 declaration consisting of a type followed by a declarator (list), so
2246 the keywords on `c-modifier-kwds' should normally not be listed here
2247 either.
2249 Note: Use `c-typeless-decl-kwds' for keywords followed by a function
2250 or variable identifier (that's being defined)."
2251 t nil
2252 c++ '("operator")
2253 objc '("@class")
2254 java '("import" "new" "extends" "super" "implements" "throws")
2255 idl '("manages" "native" "primarykey" "supports"
2256 ;; In CORBA PSDL:
2257 "as" "implements" "of" "scope")
2258 pike '("inherit"))
2260 (c-lang-defconst c-ref-list-kwds
2261 "Keywords that may be followed by a comma separated list of
2262 reference (i.e. namespace/scope/module) identifiers, where each
2263 optionally can be prefixed by keywords. (Can also be used for the
2264 special case when the list can contain only one element.) Assumed to
2265 be mutually exclusive with `c-type-list-kwds'.
2267 Note: Use `c-typeless-decl-kwds' for keywords followed by a function
2268 or variable identifier (that's being defined)."
2269 t nil
2270 c++ '("namespace")
2271 java '("package")
2272 idl '("import" "module"
2273 ;; In CORBA CIDL:
2274 "composition")
2275 pike '("import"))
2277 (c-lang-defconst c-colon-type-list-kwds
2278 "Keywords that may be followed (not necessarily directly) by a colon
2279 and then a comma separated list of type identifiers, where each
2280 optionally can be prefixed by keywords. (Can also be used for the
2281 special case when the list can contain only one element.)"
2282 t nil
2283 c++ '("class" "struct")
2284 idl '("component" "eventtype" "home" "interface" "valuetype"
2285 ;; In CORBA PSDL:
2286 "storagehome" "storagetype"))
2288 (c-lang-defconst c-colon-type-list-re
2289 "Regexp matched after the keywords in `c-colon-type-list-kwds' to skip
2290 forward to the colon. The end of the match is assumed to be directly
2291 after the colon, so the regexp should end with \":\". Must be a
2292 regexp if `c-colon-type-list-kwds' isn't nil."
2293 t (if (c-lang-const c-colon-type-list-kwds)
2294 ;; Disallow various common punctuation chars that can't come
2295 ;; before the ":" that starts the inherit list after "class"
2296 ;; or "struct" in C++. (Also used as default for other
2297 ;; languages.)
2298 "[^][{}();,/#=:]*:"))
2299 (c-lang-defvar c-colon-type-list-re (c-lang-const c-colon-type-list-re))
2301 (c-lang-defconst c-paren-nontype-kwds
2302 "Keywords that may be followed by a parenthesis expression that doesn't
2303 contain type identifiers."
2304 t nil
2305 (c c++) '(;; GCC extension.
2306 "__attribute__"
2307 ;; MSVC extension.
2308 "__declspec")
2309 c++ (append (c-lang-const c-paren-nontype-kwds) '("noexcept")))
2311 (c-lang-defconst c-paren-nontype-key
2312 t (c-make-keywords-re t (c-lang-const c-paren-nontype-kwds)))
2313 (c-lang-defvar c-paren-nontype-key (c-lang-const c-paren-nontype-key))
2315 (c-lang-defconst c-paren-type-kwds
2316 "Keywords that may be followed by a parenthesis expression containing
2317 type identifiers separated by arbitrary tokens."
2318 t nil
2319 c++ '("throw")
2320 objc '("@defs")
2321 idl '("switch")
2322 pike '("array" "function" "int" "mapping" "multiset" "object" "program"))
2324 (c-lang-defconst c-paren-any-kwds
2325 t (c--delete-duplicates (append (c-lang-const c-paren-nontype-kwds)
2326 (c-lang-const c-paren-type-kwds))
2327 :test 'string-equal))
2329 (c-lang-defconst c-<>-type-kwds
2330 "Keywords that may be followed by an angle bracket expression
2331 containing type identifiers separated by \",\". The difference from
2332 `c-<>-arglist-kwds' is that unknown names are taken to be types and
2333 not other identifiers. `c-recognize-<>-arglists' is assumed to be set
2334 if this isn't nil."
2335 t nil
2336 objc '("id")
2337 idl '("sequence"
2338 ;; In CORBA PSDL:
2339 "ref"))
2341 (c-lang-defconst c-<>-arglist-kwds
2342 "Keywords that can be followed by a C++ style template arglist; see
2343 `c-recognize-<>-arglists' for details. That language constant is
2344 assumed to be set if this isn't nil."
2345 t nil
2346 c++ '("template")
2347 idl '("fixed" "string" "wstring"))
2349 (c-lang-defconst c-<>-sexp-kwds
2350 ;; All keywords that can be followed by an angle bracket sexp.
2351 t (c--delete-duplicates (append (c-lang-const c-<>-type-kwds)
2352 (c-lang-const c-<>-arglist-kwds))
2353 :test 'string-equal))
2355 (c-lang-defconst c-opt-<>-sexp-key
2356 ;; Adorned regexp matching keywords that can be followed by an angle
2357 ;; bracket sexp. Always set when `c-recognize-<>-arglists' is.
2358 t (c-make-keywords-re t (c-lang-const c-<>-sexp-kwds)))
2359 (c-lang-defvar c-opt-<>-sexp-key (c-lang-const c-opt-<>-sexp-key))
2361 (c-lang-defconst c-inside-<>-type-kwds
2362 "Keywords which, used inside a C++ style template arglist, introduce a type."
2363 t nil
2364 java '("extends" "super"))
2366 (c-lang-defconst c-inside-<>-type-key
2367 t (c-make-keywords-re t (c-lang-const c-inside-<>-type-kwds)))
2368 (c-lang-defvar c-inside-<>-type-key (c-lang-const c-inside-<>-type-key))
2370 (c-lang-defconst c-brace-id-list-kwds
2371 "Keywords that may be followed by a brace block containing a comma
2372 separated list of identifier definitions, i.e. like the list of
2373 identifiers that follows the type in a normal declaration."
2374 t (c-lang-const c-brace-list-decl-kwds))
2376 (c-lang-defconst c-block-stmt-1-kwds
2377 "Statement keywords followed directly by a substatement."
2378 t '("do" "else")
2379 c++ '("do" "else" "try")
2380 objc '("do" "else" "@finally" "@try")
2381 java '("do" "else" "finally" "try")
2382 idl nil)
2384 (c-lang-defconst c-block-stmt-1-key
2385 ;; Regexp matching the start of any statement followed directly by a
2386 ;; substatement (doesn't match a bare block, however).
2387 t (c-make-keywords-re t (c-lang-const c-block-stmt-1-kwds)))
2388 (c-lang-defvar c-block-stmt-1-key (c-lang-const c-block-stmt-1-key))
2390 (c-lang-defconst c-block-stmt-1-2-kwds
2391 "Statement keywords optionally followed by a paren sexp.
2392 Keywords here should also be in `c-block-stmt-1-kwds'."
2393 t nil
2394 java '("try"))
2396 (c-lang-defconst c-block-stmt-1-2-key
2397 ;; Regexp matching the start of a statement which may be followed by a
2398 ;; paren sexp and will then be followed by a substatement.
2399 t (c-make-keywords-re t (c-lang-const c-block-stmt-1-2-kwds)))
2400 (c-lang-defvar c-block-stmt-1-2-key (c-lang-const c-block-stmt-1-2-key))
2402 (c-lang-defconst c-block-stmt-2-kwds
2403 "Statement keywords followed by a paren sexp and then by a substatement."
2404 t '("for" "if" "switch" "while")
2405 c++ '("for" "if" "switch" "while" "catch")
2406 objc '("for" "if" "switch" "while" "@catch" "@synchronized")
2407 java '("for" "if" "switch" "while" "catch" "synchronized")
2408 idl nil
2409 pike '("for" "if" "switch" "while" "foreach")
2410 awk '("for" "if" "while"))
2412 (c-lang-defconst c-block-stmt-2-key
2413 ;; Regexp matching the start of any statement followed by a paren sexp
2414 ;; and then by a substatement.
2415 t (c-make-keywords-re t (c-lang-const c-block-stmt-2-kwds)))
2416 (c-lang-defvar c-block-stmt-2-key (c-lang-const c-block-stmt-2-key))
2418 (c-lang-defconst c-block-stmt-kwds
2419 ;; Union of `c-block-stmt-1-kwds' and `c-block-stmt-2-kwds'.
2420 t (c--delete-duplicates (append (c-lang-const c-block-stmt-1-kwds)
2421 (c-lang-const c-block-stmt-2-kwds))
2422 :test 'string-equal))
2424 (c-lang-defconst c-opt-block-stmt-key
2425 ;; Regexp matching the start of any statement that has a
2426 ;; substatement (except a bare block). Nil in languages that
2427 ;; don't have such constructs.
2428 t (if (or (c-lang-const c-block-stmt-1-kwds)
2429 (c-lang-const c-block-stmt-2-kwds))
2430 (c-make-keywords-re t
2431 (append (c-lang-const c-block-stmt-1-kwds)
2432 (c-lang-const c-block-stmt-2-kwds)))))
2433 (c-lang-defvar c-opt-block-stmt-key (c-lang-const c-opt-block-stmt-key))
2435 (c-lang-defconst c-simple-stmt-kwds
2436 "Statement keywords followed by an expression or nothing."
2437 t '("break" "continue" "goto" "return")
2438 objc '("break" "continue" "goto" "return" "@throw")
2439 ;; Note: `goto' is not valid in Java, but the keyword is still reserved.
2440 java '("break" "continue" "goto" "return" "throw")
2441 idl nil
2442 pike '("break" "continue" "return")
2443 awk '(;; Not sure about "delete", "exit", "getline", etc. ; ACM 2002/5/30
2444 "break" "continue" "return" "delete" "exit" "getline" "next"
2445 "nextfile" "print" "printf"))
2447 (c-lang-defconst c-simple-stmt-key
2448 ;; Adorned regexp matching `c-simple-stmt-kwds'.
2449 t (c-make-keywords-re t (c-lang-const c-simple-stmt-kwds)))
2450 (c-lang-defvar c-simple-stmt-key (c-lang-const c-simple-stmt-key))
2452 (c-lang-defconst c-paren-stmt-kwds
2453 "Statement keywords followed by a parenthesis expression that
2454 nevertheless contains a list separated with `;' and not `,'."
2455 t '("for")
2456 idl nil)
2458 (c-lang-defconst c-paren-stmt-key
2459 ;; Adorned regexp matching `c-paren-stmt-kwds'.
2460 t (c-make-keywords-re t (c-lang-const c-paren-stmt-kwds)))
2461 (c-lang-defvar c-paren-stmt-key (c-lang-const c-paren-stmt-key))
2463 (c-lang-defconst c-asm-stmt-kwds
2464 "Statement keywords followed by an assembler expression."
2465 t nil
2466 (c c++) '("asm" "__asm__")) ;; Not standard, but common.
2468 (c-lang-defconst c-opt-asm-stmt-key
2469 ;; Regexp matching the start of an assembler statement. Nil in
2470 ;; languages that don't support that.
2471 t (if (c-lang-const c-asm-stmt-kwds)
2472 (c-make-keywords-re t (c-lang-const c-asm-stmt-kwds))))
2473 (c-lang-defvar c-opt-asm-stmt-key (c-lang-const c-opt-asm-stmt-key))
2475 (c-lang-defconst c-case-kwds
2476 "The keyword(s) which introduce a \"case\" like construct.
2477 This construct is \"<keyword> <expression> :\"."
2478 t '("case")
2479 awk nil)
2481 (c-lang-defconst c-case-kwds-regexp
2482 ;; Adorned regexp matching any "case"-like keyword.
2483 t (c-make-keywords-re t (c-lang-const c-case-kwds)))
2484 (c-lang-defvar c-case-kwds-regexp (c-lang-const c-case-kwds-regexp))
2486 (c-lang-defconst c-label-kwds
2487 "Keywords introducing colon terminated labels in blocks."
2488 t '("case" "default"))
2490 (c-lang-defconst c-label-kwds-regexp
2491 ;; Adorned regexp matching any keyword that introduces a label.
2492 t (c-make-keywords-re t (c-lang-const c-label-kwds)))
2493 (c-lang-defvar c-label-kwds-regexp (c-lang-const c-label-kwds-regexp))
2495 (c-lang-defconst c-before-label-kwds
2496 "Keywords that might be followed by a label identifier."
2497 t '("goto")
2498 (java pike) (append '("break" "continue")
2499 (c-lang-const c-before-label-kwds))
2500 idl nil
2501 awk nil)
2503 (c-lang-defconst c-constant-kwds
2504 "Keywords for constants."
2505 t nil
2506 c '("NULL" ;; Not a keyword, but practically works as one.
2507 "false" "true") ; Defined in C99.
2508 c++ (append
2509 '("nullptr")
2510 (c-lang-const c-constant-kwds c))
2511 objc '("nil" "Nil" "YES" "NO" "NS_DURING" "NS_HANDLER" "NS_ENDHANDLER")
2512 idl '("TRUE" "FALSE")
2513 java '("true" "false" "null") ; technically "literals", not keywords
2514 pike '("UNDEFINED")) ;; Not a keyword, but practically works as one.
2516 (c-lang-defconst c-primary-expr-kwds
2517 "Keywords besides constants and operators that start primary expressions."
2518 t nil
2519 c++ '("operator" "this")
2520 objc '("super" "self")
2521 java '("this")
2522 pike '("this")) ;; Not really a keyword, but practically works as one.
2524 (c-lang-defconst c-expr-kwds
2525 ;; Keywords that can occur anywhere in expressions. Built from
2526 ;; `c-primary-expr-kwds' and all keyword operators in `c-operators'.
2527 t (c--delete-duplicates
2528 (append (c-lang-const c-primary-expr-kwds)
2529 (c-filter-ops (c-lang-const c-operator-list)
2531 "\\`\\(\\w\\|\\s_\\)+\\'"))
2532 :test 'string-equal))
2534 (c-lang-defconst c-lambda-kwds
2535 "Keywords that start lambda constructs, i.e. function definitions in
2536 expressions."
2537 t nil
2538 pike '("lambda"))
2540 (c-lang-defconst c-inexpr-block-kwds
2541 "Keywords that start constructs followed by statement blocks which can
2542 be used in expressions \(the gcc extension for this in C and C++ is
2543 handled separately by `c-recognize-paren-inexpr-blocks')."
2544 t nil
2545 pike '("catch" "gauge"))
2547 (c-lang-defconst c-inexpr-class-kwds
2548 "Keywords that can start classes inside expressions."
2549 t nil
2550 java '("new")
2551 pike '("class"))
2553 (c-lang-defconst c-inexpr-brace-list-kwds
2554 "Keywords that can start brace list blocks inside expressions.
2555 Note that Java specific rules are currently applied to tell this from
2556 `c-inexpr-class-kwds'."
2557 t nil
2558 java '("new"))
2560 (c-lang-defconst c-opt-inexpr-brace-list-key
2561 ;; Regexp matching the start of a brace list in an expression, or
2562 ;; nil in languages that don't have such things. This should not
2563 ;; match brace lists recognized through `c-special-brace-lists'.
2564 t (and (c-lang-const c-inexpr-brace-list-kwds)
2565 (c-make-keywords-re t (c-lang-const c-inexpr-brace-list-kwds))))
2566 (c-lang-defvar c-opt-inexpr-brace-list-key
2567 (c-lang-const c-opt-inexpr-brace-list-key))
2569 (c-lang-defconst c-decl-block-key
2570 ;; Regexp matching keywords in any construct that contain another
2571 ;; declaration level, i.e. that isn't followed by a function block
2572 ;; or brace list. When the first submatch matches, it's an
2573 ;; unambiguous construct, otherwise it's an ambiguous match that
2574 ;; might also be the return type of a function declaration.
2575 t (let* ((decl-kwds (append (c-lang-const c-class-decl-kwds)
2576 (c-lang-const c-other-block-decl-kwds)
2577 (c-lang-const c-inexpr-class-kwds)))
2578 (unambiguous (c--set-difference decl-kwds
2579 (c-lang-const c-type-start-kwds)
2580 :test 'string-equal))
2581 (ambiguous (c--intersection decl-kwds
2582 (c-lang-const c-type-start-kwds)
2583 :test 'string-equal)))
2584 (if ambiguous
2585 (concat (c-make-keywords-re t unambiguous)
2586 "\\|"
2587 (c-make-keywords-re t ambiguous))
2588 (c-make-keywords-re t unambiguous))))
2589 (c-lang-defvar c-decl-block-key (c-lang-const c-decl-block-key))
2591 (c-lang-defconst c-bitfield-kwds
2592 "Keywords that can introduce bitfields."
2593 t nil
2594 (c c++ objc) '("char" "int" "long" "signed" "unsigned"))
2596 (c-lang-defconst c-opt-bitfield-key
2597 ;; Regexp matching the start of a bitfield (not uniquely), or nil in
2598 ;; languages without bitfield support.
2599 t nil
2600 (c c++) (c-make-keywords-re t (c-lang-const c-bitfield-kwds)))
2601 (c-lang-defvar c-opt-bitfield-key (c-lang-const c-opt-bitfield-key))
2603 (c-lang-defconst c-other-kwds
2604 "Keywords not accounted for by any other `*-kwds' language constant."
2605 t nil
2606 idl '("truncatable"
2607 ;; In CORBA CIDL: (These are declaration keywords that never
2608 ;; can start a declaration.)
2609 "entity" "process" "service" "session" "storage"))
2612 ;;; Constants built from keywords.
2614 ;; Note: No `*-kwds' language constants may be defined below this point.
2616 (eval-and-compile
2617 (defconst c-kwds-lang-consts
2618 ;; List of all the language constants that contain keyword lists.
2619 (let (list)
2620 (mapatoms (lambda (sym)
2621 (when (and (boundp sym)
2622 (string-match "-kwds\\'" (symbol-name sym)))
2623 ;; Make the list of globally interned symbols
2624 ;; instead of ones interned in `c-lang-constants'.
2625 (setq list (cons (intern (symbol-name sym)) list))))
2626 c-lang-constants)
2627 list)))
2629 (c-lang-defconst c-keywords
2630 ;; All keywords as a list.
2631 t (c--delete-duplicates
2632 (c-lang-defconst-eval-immediately
2633 `(append ,@(mapcar (lambda (kwds-lang-const)
2634 `(c-lang-const ,kwds-lang-const))
2635 c-kwds-lang-consts)
2636 nil))
2637 :test 'string-equal))
2639 (c-lang-defconst c-keywords-regexp
2640 ;; All keywords as an adorned regexp.
2641 t (c-make-keywords-re t (c-lang-const c-keywords)))
2642 (c-lang-defvar c-keywords-regexp (c-lang-const c-keywords-regexp))
2644 (c-lang-defconst c-keyword-member-alist
2645 ;; An alist with all the keywords in the cars. The cdr for each
2646 ;; keyword is a list of the symbols for the `*-kwds' lists that
2647 ;; contains it.
2648 t (let ((kwd-list-alist
2649 (c-lang-defconst-eval-immediately
2650 `(list ,@(mapcar (lambda (kwds-lang-const)
2651 `(cons ',kwds-lang-const
2652 (c-lang-const ,kwds-lang-const)))
2653 c-kwds-lang-consts))))
2654 lang-const kwd-list kwd
2655 result-alist elem)
2656 (while kwd-list-alist
2657 (setq lang-const (caar kwd-list-alist)
2658 kwd-list (cdar kwd-list-alist)
2659 kwd-list-alist (cdr kwd-list-alist))
2660 (while kwd-list
2661 (setq kwd (car kwd-list)
2662 kwd-list (cdr kwd-list))
2663 (unless (setq elem (assoc kwd result-alist))
2664 (setq result-alist (cons (setq elem (list kwd)) result-alist)))
2665 (unless (memq lang-const (cdr elem))
2666 (setcdr elem (cons lang-const (cdr elem))))))
2667 result-alist))
2669 (c-lang-defvar c-keywords-obarray
2670 ;; An obarray containing all keywords as symbols. The property list
2671 ;; of each symbol has a non-nil entry for the specific `*-kwds'
2672 ;; lists it's a member of.
2674 ;; E.g. to see whether the string str contains a keyword on
2675 ;; `c-class-decl-kwds', one can do like this:
2676 ;; (get (intern-soft str c-keyword-obarray) 'c-class-decl-kwds)
2677 ;; Which preferably is written using the associated functions in
2678 ;; cc-engine:
2679 ;; (c-keyword-member (c-keyword-sym str) 'c-class-decl-kwds)
2681 ;; The obarray is not stored directly as a language constant since
2682 ;; the printed representation for obarrays used in .elc files isn't
2683 ;; complete.
2685 (let* ((alist (c-lang-const c-keyword-member-alist))
2686 kwd lang-const-list
2687 (obarray (make-vector (* (length alist) 2) 0)))
2688 (while alist
2689 (setq kwd (caar alist)
2690 lang-const-list (cdar alist)
2691 alist (cdr alist))
2692 (setplist (intern kwd obarray)
2693 ;; Emacs has an odd bug that causes `mapcan' to fail
2694 ;; with unintelligible errors. (XEmacs works.)
2695 ;; (2015-06-24): This bug has not yet been fixed.
2696 ;;(mapcan (lambda (lang-const)
2697 ;; (list lang-const t))
2698 ;; lang-const-list)
2699 (apply 'nconc (mapcar (lambda (lang-const)
2700 (list lang-const t))
2701 lang-const-list))))
2702 obarray))
2704 (c-lang-defconst c-regular-keywords-regexp
2705 ;; Adorned regexp matching all keywords that should be fontified
2706 ;; with the keywords face. I.e. that aren't types or constants.
2707 t (c-make-keywords-re t
2708 (c--set-difference (c-lang-const c-keywords)
2709 (append (c-lang-const c-primitive-type-kwds)
2710 (c-lang-const c-constant-kwds))
2711 :test 'string-equal)))
2712 (c-lang-defvar c-regular-keywords-regexp
2713 (c-lang-const c-regular-keywords-regexp))
2715 (c-lang-defconst c-primary-expr-regexp
2716 ;; Regexp matching the start of any primary expression, i.e. any
2717 ;; literal, symbol, prefix operator, and '('. It doesn't need to
2718 ;; exclude keywords; they are excluded afterwards unless the second
2719 ;; submatch matches. If the first but not the second submatch
2720 ;; matches then it is an ambiguous primary expression; it could also
2721 ;; be a match of e.g. an infix operator. (The case with ambiguous
2722 ;; keyword operators isn't handled.)
2724 t (let* ((prefix-ops
2725 (c-filter-ops (c-lang-const c-operators)
2726 '(prefix)
2727 (lambda (op)
2728 ;; Filter out the special case prefix
2729 ;; operators that are close parens.
2730 (not (string-match "\\s)" op)))))
2732 (nonkeyword-prefix-ops
2733 (c-filter-ops prefix-ops
2735 "\\`\\(\\s.\\|\\s(\\|\\s)\\)+\\'"))
2737 (in-or-postfix-ops
2738 (c-filter-ops (c-lang-const c-operators)
2739 '(postfix
2740 postfix-if-paren
2741 left-assoc
2742 right-assoc
2743 right-assoc-sequence)
2746 (unambiguous-prefix-ops (c--set-difference nonkeyword-prefix-ops
2747 in-or-postfix-ops
2748 :test 'string-equal))
2749 (ambiguous-prefix-ops (c--intersection nonkeyword-prefix-ops
2750 in-or-postfix-ops
2751 :test 'string-equal)))
2753 (concat
2754 "\\("
2755 ;; Take out all symbol class operators from `prefix-ops' and make the
2756 ;; first submatch from them together with `c-primary-expr-kwds'.
2757 (c-make-keywords-re t
2758 (append (c-lang-const c-primary-expr-kwds)
2759 (c--set-difference prefix-ops nonkeyword-prefix-ops
2760 :test 'string-equal)))
2762 "\\|"
2763 ;; Match all ambiguous operators.
2764 (c-make-keywords-re nil
2765 (c--intersection nonkeyword-prefix-ops in-or-postfix-ops
2766 :test 'string-equal))
2767 "\\)"
2769 "\\|"
2770 ;; Now match all other symbols.
2771 (c-lang-const c-symbol-start)
2773 "\\|"
2774 ;; The chars that can start integer and floating point
2775 ;; constants.
2776 "\\.?[0-9]"
2778 "\\|"
2779 ;; The unambiguous operators from `prefix-ops'.
2780 (c-make-keywords-re nil
2781 (c--set-difference nonkeyword-prefix-ops in-or-postfix-ops
2782 :test 'string-equal))
2784 "\\|"
2785 ;; Match string and character literals.
2786 "\\s\""
2787 (if (memq 'gen-string-delim c-emacs-features)
2788 "\\|\\s|"
2789 ""))))
2790 (c-lang-defvar c-primary-expr-regexp (c-lang-const c-primary-expr-regexp))
2793 ;;; Additional constants for parser-level constructs.
2795 (c-lang-defconst c-decl-start-colon-kwd-re
2796 "Regexp matching a keyword that is followed by a colon, where
2797 the whole construct can precede a declaration.
2798 E.g. \"public:\" in C++."
2799 t "\\<\\>"
2800 c++ (c-make-keywords-re t (c-lang-const c-protection-kwds)))
2801 (c-lang-defvar c-decl-start-colon-kwd-re
2802 (c-lang-const c-decl-start-colon-kwd-re))
2804 (c-lang-defconst c-decl-prefix-re
2805 "Regexp matching something that might precede a declaration, cast or
2806 label, such as the last token of a preceding statement or declaration.
2807 This is used in the common situation where a declaration or cast
2808 doesn't start with any specific token that can be searched for.
2810 The regexp should not match bob; that is done implicitly. It can't
2811 require a match longer than one token. The end of the token is taken
2812 to be at the end of the first submatch, which is assumed to always
2813 match. It's undefined whether identifier syntax (see
2814 `c-identifier-syntax-table') is in effect or not. This regexp is
2815 assumed to be a superset of `c-label-prefix-re' if
2816 `c-recognize-colon-labels' is set.
2818 Besides this, `c-decl-start-kwds' is used to find declarations.
2820 Note: This variable together with `c-decl-start-re' and
2821 `c-decl-start-kwds' is only used to detect \"likely\"
2822 declaration/cast/label starts. I.e. they might produce more matches
2823 but should not miss anything (or else it's necessary to use text
2824 properties - see the next note). Wherever they match, the following
2825 construct is analyzed to see if it indeed is a declaration, cast or
2826 label. That analysis is not cheap, so it's important that not too
2827 many false matches are triggered.
2829 Note: If a declaration/cast/label start can't be detected with this
2830 variable, it's necessary to use the `c-type' text property with the
2831 value `c-decl-end' on the last char of the last token preceding the
2832 declaration. See the comment blurb at the start of cc-engine.el for
2833 more info."
2835 ;; We match a sequence of characters to skip over things like \"};\"
2836 ;; more quickly. We match ")" in C for K&R region declarations, and
2837 ;; in all languages except Java for when a cpp macro definition
2838 ;; begins with a declaration.
2839 t "\\([{}();,]+\\)"
2840 java "\\([{}(;,<]+\\)"
2841 ;; Match "<" in C++ to get the first argument in a template arglist.
2842 ;; In that case there's an additional check in `c-find-decl-spots'
2843 ;; that it got open paren syntax. Match ":" to aid in picking up
2844 ;; "public:", etc. This involves additional checks in
2845 ;; `c-find-decl-prefix-search' to prevent a match of identifiers
2846 ;; or labels.
2847 c++ "\\([{}();:,<]+\\)"
2848 ;; Additionally match the protection directives in Objective-C.
2849 ;; Note that this doesn't cope with the longer directives, which we
2850 ;; would have to match from start to end since they don't end with
2851 ;; any easily recognized characters.
2852 objc (concat "\\([{}();,]+\\|"
2853 (c-make-keywords-re nil (c-lang-const c-protection-kwds))
2854 "\\)")
2855 ;; Pike is like C but we also match "[" for multiple value
2856 ;; assignments and type casts.
2857 pike "\\([{}()[;,]+\\)")
2858 (c-lang-defvar c-decl-prefix-re (c-lang-const c-decl-prefix-re)
2859 'dont-doc)
2861 (c-lang-defconst c-decl-start-re
2862 "Regexp matching the start of any declaration, cast or label.
2863 It's used on the token after the one `c-decl-prefix-re' matched. This
2864 regexp should not try to match those constructs accurately as it's
2865 only used as a sieve to avoid spending more time checking other
2866 constructs."
2867 t (c-lang-const c-identifier-start))
2868 (c-lang-defvar c-decl-start-re (c-lang-const c-decl-start-re))
2870 (c-lang-defconst c-decl-prefix-or-start-re
2871 ;; Regexp matching something that might precede or start a
2872 ;; declaration, cast or label.
2874 ;; If the first submatch matches, it's taken to match the end of a
2875 ;; token that might precede such a construct, e.g. ';', '}' or '{'.
2876 ;; It's built from `c-decl-prefix-re'.
2878 ;; If the first submatch did not match, the match of the whole
2879 ;; regexp is taken to be at the first token in the declaration.
2880 ;; `c-decl-start-re' is not checked in this case.
2882 ;; Design note: The reason the same regexp is used to match both
2883 ;; tokens that precede declarations and start them is to avoid an
2884 ;; extra regexp search from the previous declaration spot in
2885 ;; `c-find-decl-spots'. Users of `c-find-decl-spots' also count on
2886 ;; that it finds all declaration/cast/label starts in approximately
2887 ;; linear order, so we can't do the searches in two separate passes.
2888 t (if (c-lang-const c-decl-start-kwds)
2889 (concat (c-lang-const c-decl-prefix-re)
2890 "\\|"
2891 (c-make-keywords-re t (c-lang-const c-decl-start-kwds)))
2892 (c-lang-const c-decl-prefix-re)))
2893 (c-lang-defvar c-decl-prefix-or-start-re
2894 (c-lang-const c-decl-prefix-or-start-re)
2895 'dont-doc)
2897 (c-lang-defconst c-cast-parens
2898 ;; List containing the paren characters that can open a cast, or nil in
2899 ;; languages without casts.
2900 t (c-filter-ops (c-lang-const c-operators)
2901 '(prefix)
2902 "\\`\\s(\\'"
2903 (lambda (op) (elt op 0))))
2904 (c-lang-defvar c-cast-parens (c-lang-const c-cast-parens))
2906 (c-lang-defconst c-block-prefix-disallowed-chars
2907 "List of syntactically relevant characters that never can occur before
2908 the open brace in any construct that contains a brace block, e.g. in
2909 the \"class Foo: public Bar\" part of:
2911 class Foo: public Bar {int x();} a, *b;
2913 If parens can occur, the chars inside those aren't filtered with this
2914 list.
2916 `<' and `>' should be disallowed even if angle bracket arglists can
2917 occur. That since the search function needs to stop at them anyway to
2918 ensure they are given paren syntax.
2920 This is used to skip backward from the open brace to find the region
2921 in which to look for a construct like \"class\", \"enum\",
2922 \"namespace\" or whatever. That skipping should be as tight as
2923 possible for good performance."
2925 ;; Default to all chars that only occurs in nonsymbol tokens outside
2926 ;; identifiers.
2927 t (c--set-difference
2928 (c-lang-const c-nonsymbol-token-char-list)
2929 (c-filter-ops (append (c-lang-const c-identifier-ops)
2930 (list (cons nil
2931 (c-lang-const c-after-id-concat-ops))))
2934 (lambda (op)
2935 (let ((pos 0) res)
2936 (while (string-match "\\(\\s.\\|\\s(\\|\\s)\\)"
2937 op pos)
2938 (setq res (cons (aref op (match-beginning 1)) res)
2939 pos (match-end 0)))
2940 res))))
2942 ;; Allow cpp operations (where applicable).
2943 t (if (c-lang-const c-opt-cpp-prefix)
2944 (c--set-difference (c-lang-const c-block-prefix-disallowed-chars)
2945 '(?#))
2946 (c-lang-const c-block-prefix-disallowed-chars))
2948 ;; Allow ':' for inherit list starters.
2949 (c++ objc idl) (c--set-difference (c-lang-const c-block-prefix-disallowed-chars)
2950 '(?:))
2952 ;; Allow ',' for multiple inherits.
2953 (c++ java) (c--set-difference (c-lang-const c-block-prefix-disallowed-chars)
2954 '(?,))
2956 ;; Allow parentheses for anonymous inner classes in Java and class
2957 ;; initializer lists in Pike.
2958 (java pike) (c--set-difference (c-lang-const c-block-prefix-disallowed-chars)
2959 '(?\( ?\)))
2961 ;; Allow '"' for extern clauses (e.g. extern "C" {...}).
2962 (c c++ objc) (c--set-difference (c-lang-const c-block-prefix-disallowed-chars)
2963 '(?\" ?')))
2965 (c-lang-defconst c-block-prefix-charset
2966 ;; `c-block-prefix-disallowed-chars' as an inverted charset suitable
2967 ;; for `c-syntactic-skip-backward'.
2968 t (c-make-bare-char-alt (c-lang-const c-block-prefix-disallowed-chars) t))
2969 (c-lang-defvar c-block-prefix-charset (c-lang-const c-block-prefix-charset))
2971 (c-lang-defconst c-type-decl-prefix-key
2972 "Regexp matching any declarator operator that might precede the
2973 identifier in a declaration, e.g. the \"*\" in \"char *argv\". This
2974 regexp should match \"(\" if parentheses are valid in declarators.
2975 The end of the first submatch is taken as the end of the operator.
2976 Identifier syntax is in effect when this is matched \(see
2977 `c-identifier-syntax-table')."
2978 t (if (c-lang-const c-type-modifier-kwds)
2979 (concat (regexp-opt (c-lang-const c-type-modifier-kwds) t) "\\>")
2980 ;; Default to a regexp that never matches.
2981 "\\<\\>")
2982 ;; Check that there's no "=" afterwards to avoid matching tokens
2983 ;; like "*=".
2984 (c objc) (concat "\\("
2985 "[*(]"
2986 "\\|"
2987 (c-lang-const c-type-decl-prefix-key)
2988 "\\)"
2989 "\\([^=]\\|$\\)")
2990 c++ (concat "\\("
2991 "&&"
2992 "\\|"
2993 "\\.\\.\\."
2994 "\\|"
2995 "[*(&]"
2996 "\\|"
2997 (c-lang-const c-type-decl-prefix-key)
2998 "\\|"
2999 (concat "\\(" ; 3
3000 ;; If this matches there's special treatment in
3001 ;; `c-font-lock-declarators' and
3002 ;; `c-font-lock-declarations' that check for a
3003 ;; complete name followed by ":: *".
3004 (c-lang-const c-identifier-start)
3005 "\\)")
3006 "\\)"
3007 "\\([^=]\\|$\\)")
3008 pike "\\(\\*\\)\\([^=]\\|$\\)")
3009 (c-lang-defvar c-type-decl-prefix-key (c-lang-const c-type-decl-prefix-key)
3010 'dont-doc)
3012 (c-lang-defconst c-type-decl-suffix-key
3013 "Regexp matching the declarator operators that might follow after the
3014 identifier in a declaration, e.g. the \"[\" in \"char argv[]\". This
3015 regexp should match \")\" if parentheses are valid in declarators. If
3016 it matches an open paren of some kind, the type declaration check
3017 continues at the corresponding close paren, otherwise the end of the
3018 first submatch is taken as the end of the operator. Identifier syntax
3019 is in effect when this is matched (see `c-identifier-syntax-table')."
3020 ;; Default to a regexp that matches `c-type-modifier-kwds' and a
3021 ;; function argument list parenthesis.
3022 t (if (c-lang-const c-type-modifier-kwds)
3023 (concat "\\((\\|"
3024 (regexp-opt (c-lang-const c-type-modifier-kwds) t) "\\>"
3025 "\\)")
3026 "\\((\\)")
3027 (c c++ objc) (concat
3028 "\\("
3029 "[)[(]"
3030 (if (c-lang-const c-type-modifier-kwds)
3031 (concat
3032 "\\|"
3033 ;; "throw" in `c-type-modifier-kwds' is followed
3034 ;; by a parenthesis list, but no extra measures
3035 ;; are necessary to handle that.
3036 (regexp-opt (c-lang-const c-type-modifier-kwds) t)
3037 "\\>")
3039 "\\)")
3040 java "\\([[()]\\)"
3041 idl "\\([[(]\\)")
3042 (c-lang-defvar c-type-decl-suffix-key (c-lang-const c-type-decl-suffix-key)
3043 'dont-doc)
3045 (c-lang-defconst c-after-suffixed-type-decl-key
3046 "This regexp is matched after a declarator expression where
3047 `c-type-decl-suffix-key' has matched. If it matches then the
3048 construct is taken as a declaration. It's typically used to match the
3049 beginning of a function body or whatever might occur after the
3050 function header in a function declaration or definition. It's
3051 undefined whether identifier syntax (see `c-identifier-syntax-table')
3052 is in effect or not.
3054 Note that it's used in cases like after \"foo (bar)\" so it should
3055 only match when it's certain that it's a declaration, e.g., \"{\" but
3056 not \",\" or \";\"."
3057 t "{"
3058 ;; If K&R style declarations should be recognized then one could
3059 ;; consider to match the start of any symbol since we want to match
3060 ;; the start of the first declaration in the "K&R region". That
3061 ;; could however produce false matches on code like "FOO(bar) x"
3062 ;; where FOO is a cpp macro, so it's better to leave it out and rely
3063 ;; on the other heuristics in that case.
3064 t (if (c-lang-const c-postfix-spec-kwds)
3065 ;; Add on the keywords in `c-postfix-spec-kwds'.
3066 (concat (c-lang-const c-after-suffixed-type-decl-key)
3067 "\\|"
3068 (c-make-keywords-re t (c-lang-const c-postfix-spec-kwds)))
3069 (c-lang-const c-after-suffixed-type-decl-key))
3070 ;; Also match the colon that starts a base class initializer list in
3071 ;; C++. That can be confused with a function call before the colon
3072 ;; in a ? : operator, but we count on that `c-decl-prefix-re' won't
3073 ;; match before such a thing (as a declaration-level construct;
3074 ;; matches inside arglist contexts are already excluded).
3075 c++ "[{:]")
3076 (c-lang-defvar c-after-suffixed-type-decl-key
3077 (c-lang-const c-after-suffixed-type-decl-key)
3078 'dont-doc)
3080 (c-lang-defconst c-after-suffixed-type-maybe-decl-key
3081 ;; Regexp that in addition to `c-after-suffixed-type-decl-key'
3082 ;; matches ";" and ",".
3083 t (concat "\\(" (c-lang-const c-after-suffixed-type-decl-key) "\\)"
3084 "\\|[;,]"))
3085 (c-lang-defvar c-after-suffixed-type-maybe-decl-key
3086 (c-lang-const c-after-suffixed-type-maybe-decl-key))
3088 (c-lang-defconst c-opt-type-concat-key
3089 "Regexp matching operators that concatenate types, e.g. the \"|\" in
3090 \"int|string\" in Pike. The end of the first submatch is taken as the
3091 end of the operator. nil in languages without such operators. It's
3092 undefined whether identifier syntax (see `c-identifier-syntax-table')
3093 is in effect or not."
3094 t nil
3095 pike "\\([|.&]\\)\\($\\|[^|.&]\\)")
3096 (c-lang-defvar c-opt-type-concat-key (c-lang-const c-opt-type-concat-key)
3097 'dont-doc)
3099 (c-lang-defconst c-opt-type-suffix-key
3100 "Regexp matching operators that might follow after a type, or nil in
3101 languages that don't have such operators. The end of the first
3102 submatch is taken as the end of the operator. This should not match
3103 things like C++ template arglists if `c-recognize-<>-arglists' is set.
3104 It's undefined whether identifier syntax (see `c-identifier-syntax-table')
3105 is in effect or not."
3106 t nil
3107 (c c++ objc pike) "\\(\\.\\.\\.\\)"
3108 java (concat "\\(\\[" (c-lang-const c-simple-ws) "*\\]\\|\\.\\.\\.\\)"))
3109 (c-lang-defvar c-opt-type-suffix-key (c-lang-const c-opt-type-suffix-key))
3111 (c-lang-defvar c-known-type-key
3112 ;; Regexp matching the known type identifiers. This is initialized
3113 ;; from the type keywords and `*-font-lock-extra-types'. The first
3114 ;; submatch is the one that matches the type. Note that this regexp
3115 ;; assumes that symbol constituents like '_' and '$' have word
3116 ;; syntax.
3117 (let* ((extra-types
3118 (when (boundp (c-mode-symbol "font-lock-extra-types"))
3119 (c-mode-var "font-lock-extra-types")))
3120 (regexp-strings
3121 (delq nil (mapcar (lambda (re)
3122 (when (string-match "[][.*+?^$\\]" re)
3123 re))
3124 extra-types)))
3125 (plain-strings
3126 (delq nil (mapcar (lambda (re)
3127 (unless (string-match "[][.*+?^$\\]" re)
3128 re))
3129 extra-types))))
3130 (concat "\\<\\("
3131 (c-concat-separated
3132 (append (list (c-make-keywords-re nil
3133 (append (c-lang-const c-primitive-type-kwds)
3134 plain-strings)))
3135 regexp-strings)
3136 "\\|")
3137 "\\)\\>")))
3139 (c-lang-defconst c-special-brace-lists
3140 "List of open- and close-chars that makes up a pike-style brace list,
3141 i.e., for a ([ ]) list there should be a cons (?\\[ . ?\\]) in this
3142 list."
3143 t nil
3144 pike '((?{ . ?}) (?\[ . ?\]) (?< . ?>)))
3145 (c-lang-defvar c-special-brace-lists (c-lang-const c-special-brace-lists))
3147 (c-lang-defconst c-recognize-knr-p
3148 "Non-nil means K&R style argument declarations are valid."
3149 t nil
3150 c t)
3151 (c-lang-defvar c-recognize-knr-p (c-lang-const c-recognize-knr-p))
3153 (c-lang-defconst c-recognize-typeless-decls
3154 "Non-nil means function declarations without return type should be
3155 recognized. That can introduce an ambiguity with parenthesized macro
3156 calls before a brace block. This setting does not affect declarations
3157 that are preceded by a declaration starting keyword, so
3158 e.g. `c-typeless-decl-kwds' may still be used when it's set to nil."
3159 t nil
3160 (c c++ objc java) t)
3161 (c-lang-defvar c-recognize-typeless-decls
3162 (c-lang-const c-recognize-typeless-decls))
3164 (c-lang-defconst c-recognize-<>-arglists
3165 "Non-nil means C++ style template arglists should be handled. More
3166 specifically, this means a comma separated list of types or
3167 expressions surrounded by \"<\" and \">\". It's always preceded by an
3168 identifier or one of the keywords on `c-<>-type-kwds' or
3169 `c-<>-arglist-kwds'. If there's an identifier before then the whole
3170 expression is considered to be a type."
3171 t (or (consp (c-lang-const c-<>-type-kwds))
3172 (consp (c-lang-const c-<>-arglist-kwds)))
3173 java t) ; 2008-10-19. This is crude. The syntax for java
3174 ; generics is not yet coded in CC Mode.
3175 (c-lang-defvar c-recognize-<>-arglists (c-lang-const c-recognize-<>-arglists))
3177 (c-lang-defconst c-<>-notable-chars-re
3178 "A regexp matching any single character notable inside a <...> construct.
3179 This must include \"<\" and \">\", and should include \",\", and
3180 any character which cannot be valid inside such a construct.
3181 This is used in `c-forward-<>-arglist-recur' to try to detect
3182 sequences of tokens which cannot be a template/generic construct.
3183 When \"(\" is present, that defun will attempt to parse a
3184 parenthesized expression inside the template. When \")\" is
3185 present it will treat an unbalanced closing paren as a sign of
3186 the invalidity of the putative template construct."
3187 t "[<;{},|+&->)]"
3188 c++ "[<;{},>()]")
3189 (c-lang-defvar c-<>-notable-chars-re (c-lang-const c-<>-notable-chars-re))
3191 (c-lang-defconst c-enums-contain-decls
3192 "Non-nil means that an enum structure can contain declarations."
3193 t nil
3194 java t)
3195 (c-lang-defvar c-enums-contain-decls (c-lang-const c-enums-contain-decls))
3197 (c-lang-defconst c-recognize-paren-inits
3198 "Non-nil means that parenthesis style initializers exist,
3199 i.e. constructs like
3201 Foo bar (gnu);
3203 in addition to the more classic
3205 Foo bar = gnu;"
3206 t nil
3207 c++ t)
3208 (c-lang-defvar c-recognize-paren-inits (c-lang-const c-recognize-paren-inits))
3210 (c-lang-defconst c-recognize-paren-inexpr-blocks
3211 "Non-nil to recognize gcc style in-expression blocks,
3212 i.e. compound statements surrounded by parentheses inside expressions."
3213 t nil
3214 (c c++) t)
3215 (c-lang-defvar c-recognize-paren-inexpr-blocks
3216 (c-lang-const c-recognize-paren-inexpr-blocks))
3218 (c-lang-defconst c-opt-<>-arglist-start
3219 ;; Regexp matching the start of angle bracket arglists in languages
3220 ;; where `c-recognize-<>-arglists' is set. Does not exclude
3221 ;; keywords outside `c-<>-arglist-kwds'. The first submatch is
3222 ;; assumed to surround the preceding symbol. The whole match is
3223 ;; assumed to end directly after the opening "<".
3224 t (if (c-lang-const c-recognize-<>-arglists)
3225 (concat "\\("
3226 (c-lang-const c-symbol-key)
3227 "\\)"
3228 (c-lang-const c-syntactic-ws)
3229 "<")))
3230 (c-lang-defvar c-opt-<>-arglist-start (c-lang-const c-opt-<>-arglist-start))
3232 (c-lang-defconst c-opt-<>-arglist-start-in-paren
3233 ;; Regexp that in addition to `c-opt-<>-arglist-start' matches close
3234 ;; parens. The first submatch is assumed to surround
3235 ;; `c-opt-<>-arglist-start'.
3236 t (if (c-lang-const c-opt-<>-arglist-start)
3237 (concat "\\("
3238 (c-lang-const c-opt-<>-arglist-start)
3239 "\\)\\|\\s)")))
3240 (c-lang-defvar c-opt-<>-arglist-start-in-paren
3241 (c-lang-const c-opt-<>-arglist-start-in-paren))
3243 (c-lang-defconst c-opt-postfix-decl-spec-key
3244 ;; Regexp matching the beginning of a declaration specifier in the
3245 ;; region between the header and the body of a declaration.
3247 ;; TODO: This is currently not used uniformly; c++-mode and
3248 ;; java-mode each have their own ways of using it.
3249 t nil
3250 c++ (concat ":?"
3251 (c-lang-const c-simple-ws) "*"
3252 "\\(virtual" (c-lang-const c-simple-ws) "+\\)?\\("
3253 (c-make-keywords-re nil (c-lang-const c-protection-kwds))
3254 "\\)" (c-lang-const c-simple-ws) "+"
3255 "\\(" (c-lang-const c-symbol-key) "\\)")
3256 java (c-make-keywords-re t (c-lang-const c-postfix-spec-kwds)))
3257 (c-lang-defvar c-opt-postfix-decl-spec-key
3258 (c-lang-const c-opt-postfix-decl-spec-key))
3260 (c-lang-defconst c-recognize-colon-labels
3261 "Non-nil if generic labels ending with \":\" should be recognized.
3262 That includes labels in code and access keys in classes. This does
3263 not apply to labels recognized by `c-label-kwds' and
3264 `c-opt-extra-label-key'."
3265 t nil
3266 (c c++ objc java pike) t)
3267 (c-lang-defvar c-recognize-colon-labels
3268 (c-lang-const c-recognize-colon-labels))
3270 (c-lang-defconst c-label-prefix-re
3271 "Regexp like `c-decl-prefix-re' that matches any token that can precede
3272 a generic colon label. Not used if `c-recognize-colon-labels' is
3273 nil."
3274 t "\\([{};]+\\)")
3275 (c-lang-defvar c-label-prefix-re
3276 (c-lang-const c-label-prefix-re))
3278 (c-lang-defconst c-nonlabel-token-key
3279 "Regexp matching things that can't occur in generic colon labels,
3280 neither in a statement nor in a declaration context. The regexp is
3281 tested at the beginning of every sexp in a suspected label,
3282 i.e. before \":\". Only used if `c-recognize-colon-labels' is set."
3283 t (concat
3284 ;; All keywords except `c-label-kwds' and `c-protection-kwds'.
3285 (c-make-keywords-re t
3286 (c--set-difference (c-lang-const c-keywords)
3287 (append (c-lang-const c-label-kwds)
3288 (c-lang-const c-protection-kwds))
3289 :test 'string-equal)))
3290 ;; Don't allow string literals, except in AWK and Java. Character constants are OK.
3291 (c objc pike idl) (concat "\"\\|"
3292 (c-lang-const c-nonlabel-token-key))
3293 ;; Also check for open parens in C++, to catch member init lists in
3294 ;; constructors. We normally allow it so that macros with arguments
3295 ;; work in labels.
3296 c++ (concat "\\s(\\|\"\\|" (c-lang-const c-nonlabel-token-key)))
3297 (c-lang-defvar c-nonlabel-token-key (c-lang-const c-nonlabel-token-key))
3299 (c-lang-defconst c-nonlabel-token-2-key
3300 "Regexp matching things that can't occur two symbols before a colon in
3301 a label construct. This catches C++'s inheritance construct \"class foo
3302 : bar\". Only used if `c-recognize-colon-labels' is set."
3303 t "\\<\\>" ; matches nothing
3304 c++ (c-make-keywords-re t '("class")))
3305 (c-lang-defvar c-nonlabel-token-2-key (c-lang-const c-nonlabel-token-2-key))
3307 (c-lang-defconst c-opt-extra-label-key
3308 "Optional regexp matching labels.
3309 Normally, labels are detected according to `c-nonlabel-token-key',
3310 `c-decl-prefix-re' and `c-nonlabel-decl-prefix-re'. This regexp can
3311 be used if there are additional labels that aren't recognized that
3312 way."
3313 t nil
3314 objc (c-make-keywords-re t (c-lang-const c-protection-kwds)))
3315 (c-lang-defvar c-opt-extra-label-key (c-lang-const c-opt-extra-label-key))
3317 (c-lang-defconst c-opt-friend-key
3318 ;; Regexp describing friend declarations classes, or nil in
3319 ;; languages that don't have such things.
3321 ;; TODO: Ought to use `c-prefix-spec-kwds-re' or similar, and the
3322 ;; template skipping isn't done properly. This will disappear soon.
3323 t nil
3324 c++ (concat "friend" (c-lang-const c-simple-ws) "+"
3325 "\\|"
3326 (concat "template"
3327 (c-lang-const c-simple-ws) "*"
3328 "<.+>"
3329 (c-lang-const c-simple-ws) "*"
3330 "friend"
3331 (c-lang-const c-simple-ws) "+")))
3332 (c-lang-defvar c-opt-friend-key (c-lang-const c-opt-friend-key))
3334 (c-lang-defconst c-opt-method-key
3335 ;; Special regexp to match the start of Objective-C methods. The
3336 ;; first submatch is assumed to end after the + or - key.
3337 t nil
3338 objc (concat
3339 ;; TODO: Ought to use a better method than anchoring on bol.
3340 "^\\s *"
3341 "\\([+-]\\)"
3342 (c-lang-const c-simple-ws) "*"
3343 (concat "\\(" ; Return type.
3344 "([^)]*)"
3345 (c-lang-const c-simple-ws) "*"
3346 "\\)?")
3347 "\\(" (c-lang-const c-symbol-key) "\\)"))
3348 (c-lang-defvar c-opt-method-key (c-lang-const c-opt-method-key))
3350 (c-lang-defconst c-type-decl-end-used
3351 ;; Must be set in buffers where the `c-type' text property might be
3352 ;; used with the value `c-decl-end'.
3354 ;; `c-decl-end' is used to mark the ends of labels and access keys
3355 ;; to make interactive refontification work better.
3356 t (or (c-lang-const c-recognize-colon-labels)
3357 (and (c-lang-const c-label-kwds) t))
3358 ;; `c-decl-end' is used to mark the end of the @-style directives in
3359 ;; Objective-C.
3360 objc t)
3361 (c-lang-defvar c-type-decl-end-used (c-lang-const c-type-decl-end-used))
3363 (c-lang-defconst c-maybe-decl-faces
3364 "List of faces that might be put at the start of a type when
3365 `c-font-lock-declarations' runs. This must be evaluated (with `eval') at
3366 runtime to get the actual list of faces. This ensures that face name
3367 aliases in Emacs are resolved."
3368 t '(list nil
3369 font-lock-type-face
3370 c-reference-face-name
3371 font-lock-keyword-face)
3372 java (append (c-lang-const c-maybe-decl-faces)
3373 '(font-lock-preprocessor-face)))
3374 (c-lang-defvar c-maybe-decl-faces (c-lang-const c-maybe-decl-faces))
3377 ;;; Wrap up the `c-lang-defvar' system.
3379 ;; Compile in the list of language variables that has been collected
3380 ;; with the `c-lang-defvar' and `c-lang-setvar' macros. Note that the
3381 ;; first element of each is nil.
3382 (defconst c-lang-variable-inits (cc-eval-when-compile c-lang-variable-inits))
3383 (defconst c-emacs-variable-inits (cc-eval-when-compile c-emacs-variable-inits))
3385 ;; Make the `c-lang-setvar' variables buffer local in the current buffer.
3386 ;; These are typically standard emacs variables such as `comment-start'.
3387 (defmacro c-make-emacs-variables-local ()
3388 `(progn
3389 ,@(mapcar (lambda (init)
3390 `(make-local-variable ',(car init)))
3391 (cdr c-emacs-variable-inits))))
3393 (defun c-make-init-lang-vars-fun (mode)
3394 "Create a function that initializes all the language dependent variables
3395 for the given mode.
3397 This function should be evaluated at compile time, so that the
3398 function it returns is byte compiled with all the evaluated results
3399 from the language constants. Use the `c-init-language-vars' macro to
3400 accomplish that conveniently."
3402 (if (cc-bytecomp-is-compiling)
3403 ;; No need to byte compile this lambda since the byte compiler is
3404 ;; smart enough to detect the `funcall' construct in the
3405 ;; `c-init-language-vars' macro below and compile it all straight
3406 ;; into the function that contains `c-init-language-vars'.
3407 `(lambda ()
3409 ;; This let sets up the context for `c-mode-var' and similar
3410 ;; that could be in the result from `c--macroexpand-all'.
3411 (let ((c-buffer-is-cc-mode ',mode)
3412 current-var source-eval)
3413 (c-make-emacs-variables-local)
3414 (condition-case err
3416 (if (eq c-version-sym ',c-version-sym)
3417 (setq ,@(let ((c-buffer-is-cc-mode mode)
3418 (c-lang-const-expansion 'immediate))
3419 ;; `c-lang-const' will expand to the evaluated
3420 ;; constant immediately in `c--macroexpand-all'
3421 ;; below.
3422 (c--mapcan
3423 (lambda (init)
3424 `(current-var ',(car init)
3425 ,(car init) ,(c--macroexpand-all
3426 (elt init 1))))
3427 ;; Note: The following `append' copies the
3428 ;; first argument. That list is small, so
3429 ;; this doesn't matter too much.
3430 (append (cdr c-emacs-variable-inits)
3431 (cdr c-lang-variable-inits)))))
3433 ;; This diagnostic message isn't useful for end
3434 ;; users, so it's disabled.
3435 ;;(unless (get ',mode 'c-has-warned-lang-consts)
3436 ;; (message ,(concat "%s compiled with CC Mode %s "
3437 ;; "but loaded with %s - evaluating "
3438 ;; "language constants from source")
3439 ;; ',mode ,c-version c-version)
3440 ;; (put ',mode 'c-has-warned-lang-consts t))
3442 (setq source-eval t)
3443 (let ((init ',(append (cdr c-emacs-variable-inits)
3444 (cdr c-lang-variable-inits))))
3445 (dolist (var-init init)
3446 (setq current-var (car var-init))
3447 (set (car var-init) (eval (cadr var-init))))))
3449 (error
3450 (if current-var
3451 (message "Eval error in the `c-lang-defvar' or `c-lang-setvar' for `%s'%s: %S"
3452 current-var
3453 (if source-eval
3454 (format "\
3455 (fallback source eval - %s compiled with CC Mode %s but loaded with %s)"
3456 ',mode ,c-version c-version)
3458 err)
3459 (signal (car err) (cdr err)))))))
3461 ;; Being evaluated from source. Always use the dynamic method to
3462 ;; work well when `c-lang-defvar's in this file are reevaluated
3463 ;; interactively.
3464 `(lambda ()
3465 (require 'cc-langs)
3466 (let ((c-buffer-is-cc-mode ',mode)
3467 (init (append (cdr c-emacs-variable-inits)
3468 (cdr c-lang-variable-inits)))
3469 current-var)
3470 (c-make-emacs-variables-local)
3471 (condition-case err
3473 (dolist (var-init init)
3474 (setq current-var (car var-init))
3475 (set (car var-init) (eval (cadr var-init))))
3477 (error
3478 (if current-var
3479 (message
3480 "Eval error in the `c-lang-defvar' or `c-lang-setver' for `%s' (source eval): %S"
3481 current-var err)
3482 (signal (car err) (cdr err)))))))
3485 (defmacro c-init-language-vars (mode)
3486 "Initialize all the language dependent variables for the given mode.
3487 This macro is expanded at compile time to a form tailored for the mode
3488 in question, so MODE must be a constant. Therefore MODE is not
3489 evaluated and should not be quoted."
3490 `(funcall ,(c-make-init-lang-vars-fun mode)))
3493 (cc-provide 'cc-langs)
3495 ;; Local Variables:
3496 ;; indent-tabs-mode: t
3497 ;; tab-width: 8
3498 ;; End:
3499 ;;; cc-langs.el ends here