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