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