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