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