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