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