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