1 ;;; cc-langs.el --- language specific settings for CC Mode
3 ;; Copyright (C) 1985, 1987, 1992-2011 Free Software Foundation, Inc.
5 ;; Authors: 2002- Alan Mackenzie
6 ;; 1998- Martin Stjernholm
7 ;; 1992-1999 Barry A. Warsaw
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
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/>.
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
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.
118 (unless (fboundp 'declare-function
) (defmacro declare-function
(&rest r
))))
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
)
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 'cl
)
136 ;;; Setup for the `c-lang-defvar' system.
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."
164 (eq (car-safe val
) 'c-lang-const
)
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
)))
175 (let ((elem (assq var
(cdr c-lang-variable-inits
))))
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.
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
))))
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.
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 (declare-function delete-duplicates
"cl-seq" (cl-seq &rest cl-keys
))
212 (declare-function mapcan
"cl-extra" (cl-func cl-seq
&rest cl-rest
))
213 (declare-function cl-macroexpand-all
"cl-extra" (form &optional env
))
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 ;; If XLATE is given, it's a function which is called for each
232 ;; matching operator and its return value is collected instead.
233 ;; If it returns a list, the elements are spliced directly into
234 ;; the final result, which is returned as a list with duplicates
235 ;; removed using `equal'.
237 ;; `c-mode-syntax-table' for the current mode is in effect during
238 ;; the whole procedure.
239 (unless (listp (car-safe ops
))
240 (setq ops
(list ops
)))
241 (cond ((eq opgroup-filter t
)
242 (setq opgroup-filter
(lambda (opgroup) t
)))
243 ((not (functionp opgroup-filter
))
244 (setq opgroup-filter
`(lambda (opgroup)
245 (memq opgroup
',opgroup-filter
)))))
246 (cond ((eq op-filter t
)
247 (setq op-filter
(lambda (op) t
)))
249 (setq op-filter
`(lambda (op)
250 (string-match ,op-filter op
)))))
252 (setq xlate
'identity
))
253 (c-with-syntax-table (c-lang-const c-mode-syntax-table
)
255 (mapcan (lambda (opgroup)
256 (when (if (symbolp (car opgroup
))
257 (when (funcall opgroup-filter
(car opgroup
))
258 (setq opgroup
(cdr opgroup
))
262 (when (funcall op-filter op
)
263 (let ((res (funcall xlate op
)))
264 (if (listp res
) res
(list res
)))))
270 ;;; Various mode specific values that aren't language related.
272 (c-lang-defconst c-mode-menu
273 ;; The definition for the mode menu. The menu title is prepended to
274 ;; this before it's fed to `easy-menu-define'.
275 t
`(["Comment Out Region" comment-region
276 (c-fn-region-is-active-p)]
277 ["Uncomment Region" (comment-region (region-beginning)
279 (c-fn-region-is-active-p)]
280 ["Indent Expression" c-indent-exp
281 (memq (char-after) '(?\
( ?\
[ ?\
{))]
282 ["Indent Line or Region" c-indent-line-or-region t
]
283 ["Fill Comment Paragraph" c-fill-paragraph t
]
285 ["Backward Statement" c-beginning-of-statement t
]
286 ["Forward Statement" c-end-of-statement t
]
287 ,@(when (c-lang-const c-opt-cpp-prefix
)
288 ;; Only applicable if there's a cpp preprocessor.
289 `(["Up Conditional" c-up-conditional t
]
290 ["Backward Conditional" c-backward-conditional t
]
291 ["Forward Conditional" c-forward-conditional t
]
293 ["Macro Expand Region" c-macro-expand
294 (c-fn-region-is-active-p)]
295 ["Backslashify" c-backslash-region
296 (c-fn-region-is-active-p)]))
299 ["Set Style..." c-set-style t
]
300 ["Show Current Style Name" (message
302 c-indentation-style
) t
]
303 ["Guess Style from this Buffer" c-guess-buffer-no-install t
]
304 ["Install the Last Guessed Style..." c-guess-install
305 (and c-guess-guessed-offsets-alist
306 c-guess-guessed-basic-offset
) ]
307 ["View the Last Guessed Style" c-guess-view
308 (and c-guess-guessed-offsets-alist
309 c-guess-guessed-basic-offset
) ])
312 ["Syntactic indentation" c-toggle-syntactic-indentation
313 :style toggle
:selected c-syntactic-indentation
]
314 ["Electric mode" c-toggle-electric-state
315 :style toggle
:selected c-electric-flag
]
316 ["Auto newline" c-toggle-auto-newline
317 :style toggle
:selected c-auto-newline
]
318 ["Hungry delete" c-toggle-hungry-state
319 :style toggle
:selected c-hungry-delete-key
]
320 ["Subword mode" subword-mode
321 :style toggle
:selected
(and (boundp 'subword-mode
)
327 (defun c-populate-syntax-table (table)
328 "Populate the given syntax table as necessary for a C-like language.
329 This includes setting ' and \" as string delimiters, and setting up
330 the comment syntax to handle both line style \"//\" and block style
331 \"/*\" \"*/\" comments."
333 (modify-syntax-entry ?_
"_" table
)
334 (modify-syntax-entry ?
\\ "\\" table
)
335 (modify-syntax-entry ?
+ "." table
)
336 (modify-syntax-entry ?-
"." table
)
337 (modify-syntax-entry ?
= "." table
)
338 (modify-syntax-entry ?%
"." table
)
339 (modify-syntax-entry ?
< "." table
)
340 (modify-syntax-entry ?
> "." table
)
341 (modify-syntax-entry ?
& "." table
)
342 (modify-syntax-entry ?|
"." table
)
343 (modify-syntax-entry ?
\' "\"" table
)
344 (modify-syntax-entry ?
\240 "." table
)
346 ;; Set up block and line oriented comments. The new C
347 ;; standard mandates both comment styles even in C, so since
348 ;; all languages now require dual comments, we make this the
352 ((memq '8-bit c-emacs-features
)
353 (modify-syntax-entry ?
/ ". 1456" table
)
354 (modify-syntax-entry ?
* ". 23" table
))
356 ((memq '1-bit c-emacs-features
)
357 (modify-syntax-entry ?
/ ". 124b" table
)
358 (modify-syntax-entry ?
* ". 23" table
))
360 (t (error "CC Mode is incompatible with this version of Emacs")))
362 (modify-syntax-entry ?
\n "> b" table
)
363 ;; Give CR the same syntax as newline, for selective-display
364 (modify-syntax-entry ?\^m
"> b" table
))
366 (c-lang-defconst c-make-mode-syntax-table
367 "Functions that generates the mode specific syntax tables.
368 The syntax tables aren't stored directly since they're quite large."
370 (let ((table (make-syntax-table)))
371 (c-populate-syntax-table table
)
372 ;; Mode specific syntaxes.
373 ,(cond ((or (c-major-mode-is 'objc-mode
) (c-major-mode-is 'java-mode
))
374 ;; Let '@' be part of symbols in ObjC to cope with
375 ;; its compiler directives as single keyword tokens.
376 ;; This is then necessary since it's assumed that
377 ;; every keyword is a single symbol.
378 `(modify-syntax-entry ?
@ "_" table
))
379 ((c-major-mode-is 'pike-mode
)
380 `(modify-syntax-entry ?
@ "." table
)))
383 (c-lang-defconst c-mode-syntax-table
384 ;; The syntax tables in evaluated form. Only used temporarily when
385 ;; the constants in this file are evaluated.
386 t
(funcall (c-lang-const c-make-mode-syntax-table
)))
388 (c-lang-defconst c
++-make-template-syntax-table
389 ;; A variant of `c++-mode-syntax-table' that defines `<' and `>' as
390 ;; parenthesis characters. Used temporarily when template argument
391 ;; lists are parsed. Note that this encourages incorrect parsing of
392 ;; templates since they might contain normal operators that uses the
393 ;; '<' and '>' characters. Therefore this syntax table might go
394 ;; away when CC Mode handles templates correctly everywhere.
396 (java c
++) `(lambda ()
397 (let ((table (funcall ,(c-lang-const c-make-mode-syntax-table
))))
398 (modify-syntax-entry ?
< "(>" table
)
399 (modify-syntax-entry ?
> ")<" table
)
401 (c-lang-defvar c
++-template-syntax-table
402 (and (c-lang-const c
++-make-template-syntax-table
)
403 (funcall (c-lang-const c
++-make-template-syntax-table
))))
405 (c-lang-defconst c-no-parens-syntax-table
406 ;; A variant of the standard syntax table which is used to find matching
407 ;; "<"s and ">"s which have been marked as parens using syntax table
408 ;; properties. The other paren characters (e.g. "{", ")" "]") are given a
409 ;; non-paren syntax here. so that the list commands will work on "< ... >"
410 ;; even when there's unbalanced other parens inside them.
412 ;; This variable is nil for languages which don't have template stuff.
414 (if (c-lang-const c-recognize-
<>-arglists
)
415 (let ((table (funcall ,(c-lang-const c-make-mode-syntax-table
))))
416 (modify-syntax-entry ?\
( "." table
)
417 (modify-syntax-entry ?\
) "." table
)
418 (modify-syntax-entry ?\
[ "." table
)
419 (modify-syntax-entry ?\
] "." table
)
420 (modify-syntax-entry ?\
{ "." table
)
421 (modify-syntax-entry ?\
} "." table
)
423 (c-lang-defvar c-no-parens-syntax-table
424 (funcall (c-lang-const c-no-parens-syntax-table
)))
426 (c-lang-defconst c-identifier-syntax-modifications
427 "A list that describes the modifications that should be done to the
428 mode syntax table to get a syntax table that matches all identifiers
429 and keywords as words.
431 The list is just like the one used in `font-lock-defaults': Each
432 element is a cons where the car is the character to modify and the cdr
433 the new syntax, as accepted by `modify-syntax-entry'."
434 ;; The $ character is not allowed in most languages (one exception
435 ;; is Java which allows it for legacy reasons) but we still classify
436 ;; it as an indentifier character since it's often used in various
437 ;; machine generated identifiers.
438 t
'((?_ .
"w") (?$ .
"w"))
439 (objc java
) (append '((?
@ .
"w"))
440 (c-lang-const c-identifier-syntax-modifications
))
442 (c-lang-defvar c-identifier-syntax-modifications
443 (c-lang-const c-identifier-syntax-modifications
))
445 (c-lang-defvar c-identifier-syntax-table
446 (let ((table (copy-syntax-table (c-mode-var "mode-syntax-table")))
447 (mods c-identifier-syntax-modifications
)
452 (modify-syntax-entry (car mod
) (cdr mod
) table
))
454 "Syntax table built on the mode syntax table but additionally
455 classifies symbol constituents like '_' and '$' as word constituents,
456 so that all identifiers are recognized as words.")
458 (c-lang-defconst c-get-state-before-change-functions
459 ;; For documentation see the following c-lang-defvar of the same name.
460 ;; The value here may be a list of functions or a single function.
462 c
++ '(c-extend-region-for-CPP c-before-change-check-
<>-operators
)
463 (c objc
) 'c-extend-region-for-CPP
464 ;; java 'c-before-change-check-<>-operators
465 awk
'c-awk-record-region-clear-NL
)
466 (c-lang-defvar c-get-state-before-change-functions
467 (let ((fs (c-lang-const c-get-state-before-change-functions
)))
471 "If non-nil, a list of functions called from c-before-change-hook.
472 Typically these will record enough state to allow
473 `c-before-font-lock-function' to extend the region to fontify,
474 and may do such things as removing text-properties which must be
477 These functions will be run in the order given. Each of them
478 takes 2 parameters, the BEG and END supplied to every
479 before-change function; on entry, the buffer will have been
480 widened and match-data will have been saved; point is undefined
481 on both entry and exit; the return value is ignored.
483 The functions are called even when font locking isn't enabled.
485 When the mode is initialized, the functions are called with
486 parameters \(point-min) and \(point-max).")
488 (c-lang-defconst c-before-font-lock-function
489 "If non-nil, a function called just before font locking.
490 Typically it will extend the region about to be fontified \(see
491 below) and will set `syntax-table' text properties on the region.
493 It takes 3 parameters, the BEG, END, and OLD-LEN supplied to
494 every after-change function; point is undefined on both entry and
495 exit; on entry, the buffer will have been widened and match-data
496 will have been saved; the return value is ignored.
498 The function may extend the region to be fontified by setting the
499 buffer local variables c-new-BEG and c-new-END.
501 The function is called even when font locking is disabled.
503 When the mode is initialized, this function is called with
504 parameters \(point-min), \(point-max) and <buffer size>."
506 (c c
++ objc
) 'c-neutralize-syntax-in-and-mark-CPP
507 awk
'c-awk-extend-and-syntax-tablify-region
)
508 (c-lang-defvar c-before-font-lock-function
509 (c-lang-const c-before-font-lock-function
))
512 ;;; Lexer-level syntax (identifiers, tokens etc).
514 (c-lang-defconst c-symbol-start
515 "Regexp that matches the start of a symbol, i.e. any identifier or
516 keyword. It's unspecified how far it matches. Does not contain a \\|
517 operator at the top level."
518 t
(concat "[" c-alpha
"_]")
519 java
(concat "[" c-alpha
"_@]")
520 objc
(concat "[" c-alpha
"@]")
521 pike
(concat "[" c-alpha
"_`]"))
522 (c-lang-defvar c-symbol-start
(c-lang-const c-symbol-start
))
524 (c-lang-defconst c-symbol-chars
525 "Set of characters that can be part of a symbol.
526 This is on the form that fits inside [ ] in a regexp."
527 ;; Pike note: With the backquote identifiers this would include most
528 ;; operator chars too, but they are handled with other means instead.
529 t
(concat c-alnum
"_$")
530 objc
(concat c-alnum
"_$@"))
532 (c-lang-defconst c-symbol-key
533 "Regexp matching identifiers and keywords (with submatch 0). Assumed
534 to match if `c-symbol-start' matches on the same position."
535 t
(concat (c-lang-const c-symbol-start
)
536 "[" (c-lang-const c-symbol-chars
) "]*")
538 ;; Use the value from C here since the operator backquote is
539 ;; covered by the other alternative.
540 (c-lang-const c-symbol-key c
)
542 (c-make-keywords-re nil
543 (c-lang-const c-overloadable-operators
))))
544 (c-lang-defvar c-symbol-key
(c-lang-const c-symbol-key
))
546 (c-lang-defconst c-symbol-key-depth
547 ;; Number of regexp grouping parens in `c-symbol-key'.
548 t
(regexp-opt-depth (c-lang-const c-symbol-key
)))
550 (c-lang-defconst c-nonsymbol-chars
551 "This is the set of chars that can't be part of a symbol, i.e. the
552 negation of `c-symbol-chars'."
553 t
(concat "^" (c-lang-const c-symbol-chars
)))
554 (c-lang-defvar c-nonsymbol-chars
(c-lang-const c-nonsymbol-chars
))
556 (c-lang-defconst c-nonsymbol-key
557 "Regexp that matches any character that can't be part of a symbol.
558 It's usually appended to other regexps to avoid matching a prefix.
559 It's assumed to not contain any submatchers."
560 ;; The same thing regarding Unicode identifiers applies here as to
562 t
(concat "[" (c-lang-const c-nonsymbol-chars
) "]"))
564 (c-lang-defconst c-identifier-ops
565 "The operators that make up fully qualified identifiers. nil in
566 languages that don't have such things. See `c-operators' for a
567 description of the format. Binary operators can concatenate symbols,
568 e.g. \"::\" in \"A::B::C\". Prefix operators can precede identifiers,
569 e.g. \"~\" in \"~A::B\". Other types of operators aren't supported.
571 This value is by default merged into `c-operators'."
573 c
++ '((prefix "~" "??-" "compl")
576 ;; Java has "." to concatenate identifiers but it's also used for
577 ;; normal indexing. There's special code in the Java font lock
578 ;; rules to fontify qualified identifiers based on the standard
579 ;; naming conventions. We still define "." here to make
580 ;; `c-forward-name' move over as long names as possible which is
581 ;; necessary to e.g. handle throws clauses correctly.
582 java
'((left-assoc "."))
583 idl
'((left-assoc "::")
585 pike
'((left-assoc "::")
589 (c-lang-defconst c-opt-identifier-concat-key
590 ;; Appendable adorned regexp matching the operators that join
591 ;; symbols to fully qualified identifiers, or nil in languages that
592 ;; don't have such things.
594 ;; This was a docstring constant in 5.30. It still works but is now
595 ;; considered internal - change `c-identifier-ops' instead.
596 t
(let ((ops (c-filter-ops (c-lang-const c-identifier-ops
)
597 '(left-assoc right-assoc
)
600 (c-make-keywords-re 'appendable ops
))))
601 (c-lang-defvar c-opt-identifier-concat-key
602 (c-lang-const c-opt-identifier-concat-key
)
605 (c-lang-defconst c-opt-identifier-concat-key-depth
606 ;; Number of regexp grouping parens in `c-opt-identifier-concat-key'.
607 t
(regexp-opt-depth (c-lang-const c-opt-identifier-concat-key
)))
609 (c-lang-defconst c-opt-identifier-prefix-key
610 ;; Appendable adorned regexp matching operators that might precede
611 ;; an identifier and that are part of the identifier in that case.
612 ;; nil in languages without such things.
613 t
(let ((ops (c-filter-ops (c-lang-const c-identifier-ops
)
617 (c-make-keywords-re 'appendable ops
))))
619 (c-lang-defconst c-after-id-concat-ops
620 "Operators that can occur after a binary operator on `c-identifier-ops'
621 in identifiers. nil in languages that don't have such things.
623 Operators here should also have appropriate entries in `c-operators' -
624 it's not taken care of by default."
626 ;; '~' for destructors in C++, '*' for member pointers.
628 ;; In Java we recognize '*' to deal with "foo.bar.*" that can occur
629 ;; in import declarations. (This will also match bogus things like
630 ;; "foo.*bar" but we don't bother.)
633 (c-lang-defconst c-opt-after-id-concat-key
634 ;; Regexp that must match the token after
635 ;; `c-opt-identifier-concat-key' for it to be considered an
636 ;; identifier concatenation operator (which e.g. causes the
637 ;; preceding identifier to be fontified as a reference). Assumed to
638 ;; be a string if `c-opt-identifier-concat-key' is.
640 ;; This was a docstring constant in 5.30. It still works but is now
641 ;; considered internal - change `c-after-id-concat-ops' instead.
642 t
(concat (c-lang-const c-symbol-start
)
643 (if (c-lang-const c-after-id-concat-ops
)
644 (concat "\\|" (c-make-keywords-re 'appendable
645 (c-lang-const c-after-id-concat-ops
)))
648 (c-lang-defconst c-identifier-start
649 "Regexp that matches the start of an (optionally qualified) identifier.
650 It should also match all keywords. It's unspecified how far it
652 t
(concat (c-lang-const c-symbol-start
)
653 (if (c-lang-const c-opt-identifier-prefix-key
)
655 (c-lang-const c-opt-identifier-prefix-key
))
657 (c-lang-defvar c-identifier-start
(c-lang-const c-identifier-start
))
659 (c-lang-defconst c-identifier-key
660 "Regexp matching a fully qualified identifier, like \"A::B::c\" in
661 C++. It does not recognize the full range of syntactic whitespace
662 between the tokens; `c-forward-name' has to be used for that. It
663 should also not match identifiers containing parenthesis groupings,
664 e.g. identifiers with template arguments such as \"A<X,Y>\" in C++."
665 ;; This regexp is more complex than strictly necessary to ensure
666 ;; that it can be matched with a minimum of backtracking.
667 t
(concat (if (c-lang-const c-opt-identifier-prefix-key
)
670 (c-lang-const c-opt-identifier-prefix-key
)
671 (c-lang-const c-simple-ws
) "*"
674 "\\(" (c-lang-const c-symbol-key
) "\\)"
675 (if (c-lang-const c-opt-identifier-concat-key
)
678 (c-lang-const c-simple-ws
) "*"
679 (c-lang-const c-opt-identifier-concat-key
)
680 (c-lang-const c-simple-ws
) "*"
681 (if (c-lang-const c-after-id-concat-ops
)
684 (c-make-keywords-re 'appendable
685 (c-lang-const c-after-id-concat-ops
))
687 ;; For flexibility, consider the symbol match
688 ;; optional if we've hit a
689 ;; `c-after-id-concat-ops' operator. This is
690 ;; also necessary to handle the "*" that can
691 ;; end import declaration identifiers in Java.
693 (c-lang-const c-simple-ws
) "*"
694 "\\(" (c-lang-const c-symbol-key
) "\\)"
697 "\\(" (c-lang-const c-symbol-key
) "\\)"
699 (concat "\\(" (c-lang-const c-symbol-key
) "\\)"))
702 (c-lang-defvar c-identifier-key
(c-lang-const c-identifier-key
))
704 (c-lang-defconst c-identifier-last-sym-match
705 ;; This was a docstring constant in 5.30 but it's no longer used.
706 ;; It's only kept to avoid breaking third party code.
708 ;; Used to identify the submatch in `c-identifier-key' that
709 ;; surrounds the last symbol in the qualified identifier. It's a
710 ;; list of submatch numbers, of which the first that has a match is
711 ;; taken. It's assumed that at least one does when the regexp has
715 (c-lang-defconst c-string-escaped-newlines
716 "Set if the language support backslash escaped newlines inside string
720 (c-lang-defvar c-string-escaped-newlines
721 (c-lang-const c-string-escaped-newlines
))
723 (c-lang-defconst c-multiline-string-start-char
724 "Set if the language supports multiline string literals without escaped
725 newlines. If t, all string literals are multiline. If a character,
726 only literals where the open quote is immediately preceded by that
727 literal are multiline."
730 (c-lang-defvar c-multiline-string-start-char
731 (c-lang-const c-multiline-string-start-char
))
733 (c-lang-defconst c-opt-cpp-prefix
734 "Regexp matching the prefix of a cpp directive in the languages that
735 normally use that macro preprocessor. Tested at bol or at boi.
736 Assumed to not contain any submatches or \\| operators."
737 ;; TODO (ACM, 2005-04-01). Amend the following to recognise escaped NLs;
738 ;; amend all uses of c-opt-cpp-prefix which count regexp-depth.
741 (c-lang-defvar c-opt-cpp-prefix
(c-lang-const c-opt-cpp-prefix
))
743 (c-lang-defconst c-anchored-cpp-prefix
744 "Regexp matching the prefix of a cpp directive anchored to BOL,
745 in the languages that have a macro preprocessor."
746 t
(if (c-lang-const c-opt-cpp-prefix
)
747 (concat "^" (c-lang-const c-opt-cpp-prefix
))))
748 (c-lang-defvar c-anchored-cpp-prefix
(c-lang-const c-anchored-cpp-prefix
))
750 (c-lang-defconst c-opt-cpp-start
751 "Regexp matching the prefix of a cpp directive including the directive
752 name, or nil in languages without preprocessor support. The first
753 submatch surrounds the directive name."
754 t
(if (c-lang-const c-opt-cpp-prefix
)
755 (concat (c-lang-const c-opt-cpp-prefix
)
756 "\\([" c-alnum
"]+\\)"))
757 ;; Pike, being a scripting language, recognizes hash-bangs too.
758 pike
(concat (c-lang-const c-opt-cpp-prefix
)
759 "\\([" c-alnum
"]+\\|!\\)"))
760 (c-lang-defvar c-opt-cpp-start
(c-lang-const c-opt-cpp-start
))
762 (c-lang-defconst c-cpp-message-directives
763 "List of cpp directives (without the prefix) that are followed by a
765 t
(if (c-lang-const c-opt-cpp-prefix
)
767 (c c
++ objc pike
) '("error" "warning"))
769 (c-lang-defconst c-cpp-include-directives
770 "List of cpp directives (without the prefix) that are followed by a
771 file name in angle brackets or quotes."
772 t
(if (c-lang-const c-opt-cpp-prefix
)
774 objc
'("include" "import"))
776 (c-lang-defconst c-opt-cpp-macro-define
777 "Cpp directive (without the prefix) that is followed by a macro
778 definition, or nil if the language doesn't have any."
779 t
(if (c-lang-const c-opt-cpp-prefix
)
782 (c-lang-defconst c-opt-cpp-macro-define-start
783 ;; Regexp matching everything up to the macro body of a cpp define, or the
784 ;; end of the logical line if there is none. Submatch 1 is the name of the
785 ;; macro. Set if c-opt-cpp-macro-define is.
786 t
(if (c-lang-const c-opt-cpp-macro-define
)
787 (concat (c-lang-const c-opt-cpp-prefix
)
788 (c-lang-const c-opt-cpp-macro-define
)
789 "[ \t]+\\(\\(\\sw\\|_\\)+\\)\\(\([^\)]*\)\\)?"
791 "\\([ \t]\\|\\\\\n\\)*")))
792 (c-lang-defvar c-opt-cpp-macro-define-start
793 (c-lang-const c-opt-cpp-macro-define-start
))
795 (c-lang-defconst c-opt-cpp-macro-define-id
796 ;; Regexp matching everything up to the end of the identifier defined
798 t
(if (c-lang-const c-opt-cpp-macro-define
)
799 (concat (c-lang-const c-opt-cpp-prefix
) ; #
800 (c-lang-const c-opt-cpp-macro-define
) ; define
801 "[ \t]+\\(\\sw\\|_\\)+")))
802 (c-lang-defvar c-opt-cpp-macro-define-id
803 (c-lang-const c-opt-cpp-macro-define-id
))
805 (c-lang-defconst c-cpp-expr-directives
806 "List of cpp directives (without the prefix) that are followed by an
808 t
(if (c-lang-const c-opt-cpp-prefix
)
811 (c-lang-defconst c-cpp-expr-functions
812 "List of functions in cpp expressions."
813 t
(if (c-lang-const c-opt-cpp-prefix
)
815 pike
'("defined" "efun" "constant"))
817 (c-lang-defconst c-assignment-operators
818 "List of all assignment operators."
819 t
'("=" "*=" "/=" "%=" "+=" "-=" ">>=" "<<=" "&=" "^=" "|=")
820 java
(append (c-lang-const c-assignment-operators
)
822 c
++ (append (c-lang-const c-assignment-operators
)
823 '("and_eq" "or_eq" "xor_eq" "??!=" "??'="))
826 (c-lang-defconst c-operators
827 "List describing all operators, along with their precedence and
828 associativity. The order in the list corresponds to the precedence of
829 the operators: The operators in each element are a group with the same
830 precedence, and the group has higher precedence than the groups in all
831 following elements. The car of each element describes the type of the
832 operator group, and the cdr is a list of the operator tokens in it.
833 The operator group types are:
835 'prefix Unary prefix operators.
836 'postfix Unary postfix operators.
838 Unary postfix operators if and only if the chars have
840 'left-assoc Binary left associative operators (i.e. a+b+c means (a+b)+c).
841 'right-assoc Binary right associative operators (i.e. a=b=c means a=(b=c)).
842 'right-assoc-sequence
843 Right associative operator that constitutes of a
844 sequence of tokens that separate expressions. All the
845 tokens in the group are in this case taken as
846 describing the sequence in one such operator, and the
847 order between them is therefore significant.
849 Operators containing a character with paren syntax are taken to match
850 with a corresponding open/close paren somewhere else. A postfix
851 operator with close paren syntax is taken to end a postfix expression
852 started somewhere earlier, rather than start a new one at point. Vice
853 versa for prefix operators with open paren syntax.
855 Note that operators like \".\" and \"->\" which in language references
856 often are described as postfix operators are considered binary here,
857 since CC Mode treats every identifier as an expression."
859 ;; There's currently no code in CC Mode that exploit all the info
860 ;; in this variable; precedence, associativity etc are present as a
861 ;; preparation for future work.
864 ,@(when (c-lang-const c-opt-cpp-prefix
)
866 ,@(when (c-major-mode-is '(c-mode c
++-mode
))
869 ,@(when (c-major-mode-is '(c-mode c
++-mode
))
870 '("%:%:" "??=??=")))))
873 ,@(c-lang-const c-identifier-ops
)
874 ,@(cond ((or (c-major-mode-is 'c
++-mode
) (c-major-mode-is 'java-mode
))
875 `((postfix-if-paren "<" ">"))) ; Templates.
876 ((c-major-mode-is 'pike-mode
)
877 `((prefix "global" "predef")))
878 ((c-major-mode-is 'java-mode
)
879 `((prefix "super"))))
882 ,@(when (c-major-mode-is 'c
++-mode
)
883 ;; The following need special treatment.
884 `((prefix "dynamic_cast" "static_cast"
885 "reinterpret_cast" "const_cast" "typeid")))
887 ,@(unless (c-major-mode-is 'java-mode
)
889 (postfix "++" "--" "[" "]" "(" ")"
890 ,@(when (c-major-mode-is '(c-mode c
++-mode
))
891 '("<:" ":>" "??(" "??)")))
894 (prefix "++" "--" "+" "-" "!" "~"
895 ,@(when (c-major-mode-is 'c
++-mode
) '("not" "compl"))
896 ,@(when (c-major-mode-is '(c-mode c
++-mode
))
897 '("*" "&" "sizeof" "??-"))
898 ,@(when (c-major-mode-is 'objc-mode
)
899 '("@selector" "@protocol" "@encode"))
900 ;; The following need special treatment.
901 ,@(cond ((c-major-mode-is 'c
++-mode
)
903 ((c-major-mode-is 'java-mode
)
905 ((c-major-mode-is 'pike-mode
)
906 '("class" "lambda" "catch" "throw" "gauge")))
908 ,@(when (c-major-mode-is 'pike-mode
)
909 '("[" "]"))) ; Type cast.
912 ,@(when (c-major-mode-is 'c
++-mode
)
913 `((left-assoc ".*" "->*")))
916 (left-assoc "*" "/" "%")
922 (left-assoc "<<" ">>"
923 ,@(when (c-major-mode-is 'java-mode
)
927 (left-assoc "<" ">" "<=" ">="
928 ,@(when (c-major-mode-is 'java-mode
)
932 (left-assoc "==" "!="
933 ,@(when (c-major-mode-is 'c
++-mode
) '("not_eq")))
937 ,@(when (c-major-mode-is 'c
++-mode
) '("bitand")))
939 ;; Bitwise exclusive or.
941 ,@(when (c-major-mode-is '(c-mode c
++-mode
))
943 ,@(when (c-major-mode-is 'c
++-mode
) '("xor")))
947 ,@(when (c-major-mode-is '(c-mode c
++-mode
))
949 ,@(when (c-major-mode-is 'c
++-mode
) '("bitor")))
953 ,@(when (c-major-mode-is 'c
++-mode
) '("and")))
957 ,@(when (c-major-mode-is '(c-mode c
++-mode
))
959 ,@(when (c-major-mode-is 'c
++-mode
) '("or")))
962 (right-assoc-sequence "?" ":")
965 (right-assoc ,@(c-lang-const c-assignment-operators
))
968 ,@(when (c-major-mode-is 'c
++-mode
)
974 ;; IDL got its own definition since it has a much smaller operator
975 ;; set than the other languages.
976 idl
`(;; Preprocessor.
980 ,@(c-lang-const c-identifier-ops
)
984 (left-assoc "*" "/" "%")
988 (left-assoc "<<" ">>")
996 (c-lang-defconst c-operator-list
997 ;; The operators as a flat list (without duplicates).
998 t
(c-filter-ops (c-lang-const c-operators
) t t
))
1000 (c-lang-defconst c-overloadable-operators
1001 "List of the operators that are overloadable, in their \"identifier
1002 form\". See also `c-op-identifier-prefix'."
1004 c
++ '("new" "delete" ;; Can be followed by "[]" but we ignore that.
1006 "^" "??'" "xor" "&" "bitand" "|" "??!" "bitor" "~" "??-" "compl"
1007 "!" "=" "<" ">" "+=" "-=" "*=" "/=" "%=" "^="
1008 "??'=" "xor_eq" "&=" "and_eq" "|=" "??!=" "or_eq"
1009 "<<" ">>" ">>=" "<<=" "==" "!=" "not_eq" "<=" ">="
1010 "&&" "and" "||" "??!??!" "or" "++" "--" "," "->*" "->"
1011 "()" "[]" "<::>" "??(??)")
1012 ;; These work like identifiers in Pike.
1013 pike
'("`+" "`-" "`&" "`|" "`^" "`<<" "`>>" "`*" "`/" "`%" "`~"
1014 "`==" "`<" "`>" "`!" "`[]" "`[]=" "`->" "`->=" "`()" "``+"
1015 "``-" "``&" "``|" "``^" "``<<" "``>>" "``*" "``/" "``%"
1018 (c-lang-defconst c-overloadable-operators-regexp
1019 ;; Regexp tested after an "operator" token in C++.
1021 c
++ (c-make-keywords-re nil
(c-lang-const c-overloadable-operators
)))
1022 (c-lang-defvar c-overloadable-operators-regexp
1023 (c-lang-const c-overloadable-operators-regexp
))
1025 (c-lang-defconst c-opt-op-identifier-prefix
1026 "Regexp matching the token before the ones in
1027 `c-overloadable-operators' when operators are specified in their
1028 \"identifier form\". This typically matches \"operator\" in C++ where
1029 operator functions are specified as e.g. \"operator +\". It's nil in
1030 languages without operator functions or where the complete operator
1031 identifier is listed in `c-overloadable-operators'.
1033 This regexp is assumed to not match any non-operator identifier."
1035 c
++ (c-make-keywords-re t
'("operator")))
1036 (c-lang-defvar c-opt-op-identifier-prefix
1037 (c-lang-const c-opt-op-identifier-prefix
))
1039 ;; Note: the following alias is an old name which was a mis-spelling. It has
1040 ;; been corrected above and throughout cc-engine.el. It will be removed at
1041 ;; some release very shortly in the future. ACM, 2006-04-14.
1042 (defvaralias 'c-opt-op-identitier-prefix
'c-opt-op-identifier-prefix
)
1043 (make-obsolete-variable 'c-opt-op-identitier-prefix
'c-opt-op-identifier-prefix
1044 "CC Mode 5.31.4, 2006-04-14")
1046 (c-lang-defconst c-other-op-syntax-tokens
1047 "List of the tokens made up of characters in the punctuation or
1048 parenthesis syntax classes that have uses other than as expression
1050 t
'("{" "}" "(" ")" "[" "]" ";" ":" "," "=" "/*" "*/" "//")
1051 (c c
++ pike
) (append '("#" "##" ; Used by cpp.
1053 (c-lang-const c-other-op-syntax-tokens
))
1054 (c c
++) (append '("*") (c-lang-const c-other-op-syntax-tokens
))
1055 c
++ (append '("&" "<%" "%>" "<:" ":>" "%:" "%:%:")
1056 (c-lang-const c-other-op-syntax-tokens
))
1057 objc
(append '("#" "##" ; Used by cpp.
1058 "+" "-") (c-lang-const c-other-op-syntax-tokens
))
1059 idl
(append '("#" "##") ; Used by cpp.
1060 (c-lang-const c-other-op-syntax-tokens
))
1061 pike
(append '("..")
1062 (c-lang-const c-other-op-syntax-tokens
)
1063 (c-lang-const c-overloadable-operators
))
1064 awk
'("{" "}" "(" ")" "[" "]" ";" "," "=" "/"))
1066 (c-lang-defconst c-all-op-syntax-tokens
1067 ;; List of all tokens in the punctuation and parenthesis syntax
1069 t
(delete-duplicates (append (c-lang-const c-other-op-syntax-tokens
)
1070 (c-lang-const c-operator-list
))
1071 :test
'string-equal
))
1073 (c-lang-defconst c-nonsymbol-token-char-list
1074 ;; List containing all chars not in the word, symbol or
1075 ;; syntactically irrelevant syntax classes, i.e. all punctuation,
1076 ;; parenthesis and string delimiter chars.
1077 t
(c-with-syntax-table (c-lang-const c-mode-syntax-table
)
1078 ;; Only go through the chars in the printable ASCII range. No
1079 ;; language so far has 8-bit or widestring operators.
1080 (let (list (char 32))
1082 (or (memq (char-syntax char
) '(?w ?_ ?
< ?
> ?\
))
1083 (setq list
(cons (c-int-to-char char
) list
)))
1084 (setq char
(1+ char
)))
1087 (c-lang-defconst c-nonsymbol-token-regexp
1088 ;; Regexp matching all tokens in the punctuation and parenthesis
1089 ;; syntax classes. Note that this also matches ".", which can start
1091 t
(c-make-keywords-re nil
1092 (c-filter-ops (c-lang-const c-all-op-syntax-tokens
)
1094 "\\`\\(\\s.\\|\\s\(\\|\\s\)\\)+\\'")))
1095 (c-lang-defvar c-nonsymbol-token-regexp
1096 (c-lang-const c-nonsymbol-token-regexp
))
1098 (c-lang-defconst c-assignment-op-regexp
1099 ;; Regexp matching all assignment operators and only them. The
1100 ;; beginning of the first submatch is used to detect the end of the
1101 ;; token, along with the end of the whole match.
1102 t
(if (c-lang-const c-assignment-operators
)
1104 ;; Need special case for "=" since it's a prefix of "==".
1107 (c-make-keywords-re nil
1108 (set-difference (c-lang-const c-assignment-operators
)
1110 :test
'string-equal
)))
1112 (c-lang-defvar c-assignment-op-regexp
1113 (c-lang-const c-assignment-op-regexp
))
1115 (c-lang-defconst c-
<>-multichar-token-regexp
1116 ;; Regexp matching all tokens containing "<" or ">" which are longer
1118 t
(c-make-keywords-re nil
1119 (c-filter-ops (c-lang-const c-all-op-syntax-tokens
)
1122 (c-lang-defvar c-
<>-multichar-token-regexp
1123 (c-lang-const c-
<>-multichar-token-regexp
))
1125 (c-lang-defconst c-
<-op-cont-regexp
1126 ;; Regexp matching the second and subsequent characters of all
1127 ;; multicharacter tokens that begin with "<".
1128 t
(c-make-keywords-re nil
1129 (c-filter-ops (c-lang-const c-all-op-syntax-tokens
)
1132 (lambda (op) (substring op
1)))))
1134 (c-lang-defvar c-
<-op-cont-regexp
(c-lang-const c-
<-op-cont-regexp
))
1136 (c-lang-defconst c-
>-op-cont-regexp
1137 ;; Regexp matching the second and subsequent characters of all
1138 ;; multicharacter tokens that begin with ">".
1139 t
(c-make-keywords-re nil
1140 (c-filter-ops (c-lang-const c-all-op-syntax-tokens
)
1143 (lambda (op) (substring op
1))))
1144 java
(c-make-keywords-re nil
1145 (c-filter-ops (c-lang-const c-all-op-syntax-tokens
)
1147 "\\`>[^>]\\|\\`>>[^>]"
1148 (lambda (op) (substring op
1)))))
1150 (c-lang-defvar c-
>-op-cont-regexp
(c-lang-const c-
>-op-cont-regexp
))
1152 (c-lang-defconst c-stmt-delim-chars
1153 ;; The characters that should be considered to bound statements. To
1154 ;; optimize `c-crosses-statement-barrier-p' somewhat, it's assumed to
1155 ;; begin with "^" to negate the set. If ? : operators should be
1156 ;; detected then the string must end with "?:".
1158 awk
"^;{}#\n\r?:") ; The newline chars gets special treatment.
1159 (c-lang-defvar c-stmt-delim-chars
(c-lang-const c-stmt-delim-chars
))
1161 (c-lang-defconst c-stmt-delim-chars-with-comma
1162 ;; Variant of `c-stmt-delim-chars' that additionally contains ','.
1164 awk
"^;,{}\n\r?:") ; The newline chars gets special treatment.
1165 (c-lang-defvar c-stmt-delim-chars-with-comma
1166 (c-lang-const c-stmt-delim-chars-with-comma
))
1169 ;;; Syntactic whitespace.
1171 (c-lang-defconst c-simple-ws
1172 "Regexp matching an ordinary whitespace character.
1173 Does not contain a \\| operator at the top level."
1174 ;; "\\s " is not enough since it doesn't match line breaks.
1175 t
"\\(\\s \\|[\n\r]\\)")
1177 (c-lang-defconst c-simple-ws-depth
1178 ;; Number of regexp grouping parens in `c-simple-ws'.
1179 t
(regexp-opt-depth (c-lang-const c-simple-ws
)))
1181 (c-lang-defconst c-line-comment-starter
1182 "String that starts line comments, or nil if such don't exist.
1183 Line comments are always terminated by newlines. At least one of
1184 `c-block-comment-starter' and this one is assumed to be set.
1186 Note that it's currently not enough to set this to support a new
1187 comment style. Other stuff like the syntax table must also be set up
1191 (c-lang-defvar c-line-comment-starter
(c-lang-const c-line-comment-starter
))
1193 (c-lang-defconst c-block-comment-starter
1194 "String that starts block comments, or nil if such don't exist.
1195 Block comments are ended by `c-block-comment-ender', which is assumed
1196 to be set if this is. At least one of `c-line-comment-starter' and
1197 this one is assumed to be set.
1199 Note that it's currently not enough to set this to support a new
1200 comment style. Other stuff like the syntax table must also be set up
1205 (c-lang-defconst c-block-comment-ender
1206 "String that ends block comments, or nil if such don't exist.
1208 Note that it's currently not enough to set this to support a new
1209 comment style. Other stuff like the syntax table must also be set up
1214 (c-lang-defconst c-comment-start-regexp
1215 ;; Regexp to match the start of any type of comment.
1216 t
(let ((re (c-make-keywords-re nil
1217 (list (c-lang-const c-line-comment-starter
)
1218 (c-lang-const c-block-comment-starter
)))))
1219 (if (memq 'gen-comment-delim c-emacs-features
)
1220 (concat re
"\\|\\s!")
1222 (c-lang-defvar c-comment-start-regexp
(c-lang-const c-comment-start-regexp
))
1224 ;;;; Added by ACM, 2003/9/18.
1225 (c-lang-defconst c-block-comment-start-regexp
1226 ;; Regexp which matches the start of a block comment (if such exists in the
1228 t
(if (c-lang-const c-block-comment-starter
)
1229 (regexp-quote (c-lang-const c-block-comment-starter
))
1231 (c-lang-defvar c-block-comment-start-regexp
1232 (c-lang-const c-block-comment-start-regexp
))
1234 (c-lang-defconst c-literal-start-regexp
1235 ;; Regexp to match the start of comments and string literals.
1236 t
(concat (c-lang-const c-comment-start-regexp
)
1238 (if (memq 'gen-string-delim c-emacs-features
)
1241 (c-lang-defvar c-literal-start-regexp
(c-lang-const c-literal-start-regexp
))
1243 (c-lang-defconst c-doc-comment-start-regexp
1244 "Regexp to match the start of documentation comments."
1246 ;; From font-lock.el: `doxygen' uses /*! while others use /**.
1247 (c c
++ objc
) "/\\*[*!]"
1250 (c-lang-defvar c-doc-comment-start-regexp
1251 (c-lang-const c-doc-comment-start-regexp
))
1253 (c-lang-defconst comment-start
1254 "String that starts comments inserted with M-; etc.
1255 `comment-start' is initialized from this."
1256 ;; Default: Prefer line comments to block comments, and pad with a space.
1257 t
(concat (or (c-lang-const c-line-comment-starter
)
1258 (c-lang-const c-block-comment-starter
))
1260 ;; In C we still default to the block comment style since line
1261 ;; comments aren't entirely portable.
1263 (c-lang-setvar comment-start
(c-lang-const comment-start
))
1265 (c-lang-defconst comment-end
1266 "String that ends comments inserted with M-; etc.
1267 `comment-end' is initialized from this."
1268 ;; Default: Use block comment style if comment-start uses block
1269 ;; comments, and pad with a space in that case.
1270 t
(if (string-match (concat "\\`\\("
1271 (c-lang-const c-block-comment-start-regexp
)
1273 (c-lang-const comment-start
))
1274 (concat " " (c-lang-const c-block-comment-ender
))
1276 (c-lang-setvar comment-end
(c-lang-const comment-end
))
1278 (c-lang-defconst comment-start-skip
1279 "Regexp to match the start of a comment plus everything up to its body.
1280 `comment-start-skip' is initialized from this."
1281 ;; Default: Allow the last char of the comment starter(s) to be
1282 ;; repeated, then allow any amount of horizontal whitespace.
1285 (mapcar (lambda (cs)
1287 (concat (regexp-quote cs
) "+")))
1288 (list (c-lang-const c-line-comment-starter
)
1289 (c-lang-const c-block-comment-starter
)))
1292 (c-lang-setvar comment-start-skip
(c-lang-const comment-start-skip
))
1294 (c-lang-defconst c-syntactic-ws-start
1295 ;; Regexp matching any sequence that can start syntactic whitespace.
1296 ;; The only uncertain case is '#' when there are cpp directives.
1298 (c-make-keywords-re nil
1299 (append (list (c-lang-const c-line-comment-starter
)
1300 (c-lang-const c-block-comment-starter
)
1301 (when (c-lang-const c-opt-cpp-prefix
)
1305 (when (memq 'gen-comment-delim c-emacs-features
)
1307 (c-lang-defvar c-syntactic-ws-start
(c-lang-const c-syntactic-ws-start
))
1309 (c-lang-defconst c-syntactic-ws-end
1310 ;; Regexp matching any single character that might end syntactic whitespace.
1312 (c-make-keywords-re nil
1313 (append (when (c-lang-const c-block-comment-ender
)
1316 (elt (c-lang-const c-block-comment-ender
)
1318 (c-lang-const c-block-comment-ender
)))))))
1320 (when (memq 'gen-comment-delim c-emacs-features
)
1322 (c-lang-defvar c-syntactic-ws-end
(c-lang-const c-syntactic-ws-end
))
1324 (c-lang-defconst c-unterminated-block-comment-regexp
1325 ;; Regexp matching an unterminated block comment that doesn't
1326 ;; contain line breaks, or nil in languages without block comments.
1327 ;; Does not contain a \| operator at the top level.
1328 t
(when (c-lang-const c-block-comment-starter
)
1330 (regexp-quote (c-lang-const c-block-comment-starter
))
1331 ;; It's messy to cook together a regexp that matches anything
1332 ;; but c-block-comment-ender.
1333 (let ((end (c-lang-const c-block-comment-ender
)))
1334 (cond ((= (length end
) 1)
1335 (concat "[^" end
"\n\r]*"))
1337 (concat "[^" (substring end
0 1) "\n\r]*"
1339 (regexp-quote (substring end
0 1)) "+"
1341 ;; The quoting rules inside char classes are silly. :P
1342 (cond ((= (elt end
0) (elt end
1))
1343 (concat (substring end
0 1) "\n\r"))
1344 ((= (elt end
1) ?\
])
1345 (concat (substring end
1 2) "\n\r"
1346 (substring end
0 1)))
1348 (concat (substring end
0 1) "\n\r"
1349 (substring end
1 2))))
1351 "[^" (substring end
0 1) "\n\r]*"
1354 (error "Can't handle a block comment ender of length %s"
1357 (c-lang-defconst c-block-comment-regexp
1358 ;; Regexp matching a block comment that doesn't contain line breaks,
1359 ;; or nil in languages without block comments. The reason we don't
1360 ;; allow line breaks is to avoid going very far and risk running out
1361 ;; of regexp stack; this regexp is intended to handle only short
1362 ;; comments that might be put in the middle of limited constructs
1363 ;; like declarations. Does not contain a \| operator at the top
1365 t
(when (c-lang-const c-unterminated-block-comment-regexp
)
1367 (c-lang-const c-unterminated-block-comment-regexp
)
1368 (let ((end (c-lang-const c-block-comment-ender
)))
1369 (cond ((= (length end
) 1)
1372 (concat (regexp-quote (substring end
0 1)) "+"
1373 (regexp-quote (substring end
1 2))))
1375 (error "Can't handle a block comment ender of length %s"
1378 (c-lang-defconst c-nonwhite-syntactic-ws
1379 ;; Regexp matching a piece of syntactic whitespace that isn't a
1380 ;; sequence of simple whitespace characters. As opposed to
1381 ;; `c-(forward|backward)-syntactic-ws', this doesn't regard cpp
1382 ;; directives as syntactic whitespace.
1383 t
(c-concat-separated
1384 (list (when (c-lang-const c-line-comment-starter
)
1385 (concat (regexp-quote (c-lang-const c-line-comment-starter
))
1387 (c-lang-const c-block-comment-regexp
)
1389 (when (memq 'gen-comment-delim c-emacs-features
)
1393 (c-lang-defconst c-syntactic-ws
1394 ;; Regexp matching syntactic whitespace, including possibly the
1395 ;; empty string. As opposed to `c-(forward|backward)-syntactic-ws',
1396 ;; this doesn't regard cpp directives as syntactic whitespace. Does
1397 ;; not contain a \| operator at the top level.
1398 t
(concat (c-lang-const c-simple-ws
) "*"
1400 (concat "\\(" (c-lang-const c-nonwhite-syntactic-ws
) "\\)"
1401 (c-lang-const c-simple-ws
) "*")
1404 (c-lang-defconst c-syntactic-ws-depth
1405 ;; Number of regexp grouping parens in `c-syntactic-ws'.
1406 t
(regexp-opt-depth (c-lang-const c-syntactic-ws
)))
1408 (c-lang-defconst c-nonempty-syntactic-ws
1409 ;; Regexp matching syntactic whitespace, which is at least one
1410 ;; character long. As opposed to `c-(forward|backward)-syntactic-ws',
1411 ;; this doesn't regard cpp directives as syntactic whitespace. Does
1412 ;; not contain a \| operator at the top level.
1414 (c-lang-const c-simple-ws
)
1416 (c-lang-const c-nonwhite-syntactic-ws
)
1419 (c-lang-defconst c-nonempty-syntactic-ws-depth
1420 ;; Number of regexp grouping parens in `c-nonempty-syntactic-ws'.
1421 t
(regexp-opt-depth (c-lang-const c-nonempty-syntactic-ws
)))
1423 (c-lang-defconst c-single-line-syntactic-ws
1424 ;; Regexp matching syntactic whitespace without any line breaks. As
1425 ;; opposed to `c-(forward|backward)-syntactic-ws', this doesn't
1426 ;; regard cpp directives as syntactic whitespace. Does not contain
1427 ;; a \| operator at the top level.
1428 t
(if (c-lang-const c-block-comment-regexp
)
1430 (c-lang-const c-block-comment-regexp
)
1434 (c-lang-defconst c-single-line-syntactic-ws-depth
1435 ;; Number of regexp grouping parens in `c-single-line-syntactic-ws'.
1436 t
(regexp-opt-depth (c-lang-const c-single-line-syntactic-ws
)))
1438 (c-lang-defconst c-syntactic-eol
1439 ;; Regexp that matches when there is no syntactically significant
1440 ;; text before eol. Macros are regarded as syntactically
1441 ;; significant text here.
1442 t
(concat (c-lang-const c-single-line-syntactic-ws
)
1443 ;; Match eol (possibly inside a block comment or preceded
1444 ;; by a line continuation backslash), or the beginning of a
1445 ;; line comment. Note: This has to be modified for awk
1446 ;; where line comments start with '#'.
1449 (list (when (c-lang-const c-line-comment-starter
)
1450 (regexp-quote (c-lang-const c-line-comment-starter
)))
1451 (when (c-lang-const c-unterminated-block-comment-regexp
)
1452 (concat (c-lang-const c-unterminated-block-comment-regexp
)
1458 (c-lang-defvar c-syntactic-eol
(c-lang-const c-syntactic-eol
))
1461 ;;; Syntactic analysis ("virtual semicolons") for line-oriented languages (AWK).
1462 (c-lang-defconst c-at-vsemi-p-fn
1463 "Contains a function \"Is there a virtual semicolon at POS or point?\".
1464 Such a function takes one optional parameter, a buffer position (defaults to
1465 point), and returns nil or t. This variable contains nil for languages which
1466 don't have EOL terminated statements. "
1468 awk
'c-awk-at-vsemi-p
)
1469 (c-lang-defvar c-at-vsemi-p-fn
(c-lang-const c-at-vsemi-p-fn
))
1471 (c-lang-defconst c-vsemi-status-unknown-p-fn
1472 "Contains a function \"are we unsure whether there is a virtual semicolon on this line?\".
1473 The (admittedly kludgey) purpose of such a function is to prevent an infinite
1474 recursion in c-beginning-of-statement-1 when point starts at a `while' token.
1475 The function MUST NOT UNDER ANY CIRCUMSTANCES call c-beginning-of-statement-1,
1476 even indirectly. This variable contains nil for languages which don't have
1477 EOL terminated statements."
1479 awk
'c-awk-vsemi-status-unknown-p
)
1480 (c-lang-defvar c-vsemi-status-unknown-p-fn
1481 (c-lang-const c-vsemi-status-unknown-p-fn
))
1486 ;; The Emacs variables beginning-of-defun-function and
1487 ;; end-of-defun-function will be set so that commands like
1488 ;; `mark-defun' and `narrow-to-defun' work right. The key sequences
1489 ;; C-M-a and C-M-e are, however, bound directly to the CC Mode
1490 ;; functions, allowing optimisation for large n.
1491 (c-lang-defconst beginning-of-defun-function
1492 "Function to which beginning-of-defun-function will be set."
1493 t
'c-beginning-of-defun
1494 awk
'c-awk-beginning-of-defun
)
1495 (c-lang-setvar beginning-of-defun-function
1496 (c-lang-const beginning-of-defun-function
))
1498 (c-lang-defconst end-of-defun-function
1499 "Function to which end-of-defun-function will be set."
1501 awk
'c-awk-end-of-defun
)
1502 (c-lang-setvar end-of-defun-function
(c-lang-const end-of-defun-function
))
1504 ;;; In-comment text handling.
1506 (c-lang-defconst c-paragraph-start
1507 "Regexp to append to `paragraph-start'."
1509 java
"\\(@[a-zA-Z]+\\>\\|$\\)" ; For Javadoc.
1510 pike
"\\(@[a-zA-Z_-]+\\>\\([^{]\\|$\\)\\|$\\)") ; For Pike refdoc.
1511 (c-lang-defvar c-paragraph-start
(c-lang-const c-paragraph-start
))
1513 (c-lang-defconst c-paragraph-separate
1514 "Regexp to append to `paragraph-separate'."
1516 pike
(c-lang-const c-paragraph-start
))
1517 (c-lang-defvar c-paragraph-separate
(c-lang-const c-paragraph-separate
))
1522 ;; Note: All and only all language constants containing keyword lists
1523 ;; should end with "-kwds"; they're automatically collected into the
1524 ;; `c-kwds-lang-consts' list below and used to build `c-keywords' etc.
1526 (c-lang-defconst c-primitive-type-kwds
1527 "Primitive type keywords. As opposed to the other keyword lists, the
1528 keywords listed here are fontified with the type face instead of the
1531 If any of these also are on `c-type-list-kwds', `c-ref-list-kwds',
1532 `c-colon-type-list-kwds', `c-paren-nontype-kwds', `c-paren-type-kwds',
1533 `c-<>-type-kwds', or `c-<>-arglist-kwds' then the associated clauses
1536 Do not try to modify this list for end user customizations; the
1537 `*-font-lock-extra-types' variable, where `*' is the mode prefix, is
1538 the appropriate place for that."
1539 t
'("char" "double" "float" "int" "long" "short" "signed"
1542 '("_Bool" "_Complex" "_Imaginary") ; Conditionally defined in C99.
1543 (c-lang-const c-primitive-type-kwds
))
1546 (c-lang-const c-primitive-type-kwds
))
1547 ;; Objective-C extends C, but probably not the new stuff in C99.
1549 '("id" "Class" "SEL" "IMP" "BOOL")
1550 (c-lang-const c-primitive-type-kwds
))
1551 java
'("boolean" "byte" "char" "double" "float" "int" "long" "short" "void")
1552 idl
'("Object" "ValueBase" "any" "boolean" "char" "double" "fixed" "float"
1553 "long" "octet" "sequence" "short" "string" "void" "wchar" "wstring"
1556 ;; The following can't really end a type, but we have to specify them
1557 ;; here due to the assumption in `c-primitive-type-prefix-kwds'. It
1558 ;; doesn't matter that much.
1559 "unsigned" "strong")
1560 pike
'(;; this_program isn't really a keyword, but it's practically
1561 ;; used as a builtin type.
1562 "array" "float" "function" "int" "mapping" "mixed" "multiset"
1563 "object" "program" "string" "this_program" "void"))
1565 (c-lang-defconst c-primitive-type-key
1566 ;; An adorned regexp that matches `c-primitive-type-kwds'.
1567 t
(c-make-keywords-re t
(c-lang-const c-primitive-type-kwds
)))
1568 (c-lang-defvar c-primitive-type-key
(c-lang-const c-primitive-type-key
))
1570 (c-lang-defconst c-primitive-type-prefix-kwds
1571 "Keywords that might act as prefixes for primitive types. Assumed to
1572 be a subset of `c-primitive-type-kwds'."
1574 (c c
++) '("long" "short" "signed" "unsigned")
1575 idl
'("long" "unsigned"
1579 (c-lang-defconst c-typedef-kwds
1580 "Prefix keyword\(s\) like \"typedef\" which make a type declaration out
1581 of a variable declaration."
1585 (c-lang-defconst c-typedef-key
1586 ;; Adorned regexp matching `c-typedef-kwds'.
1587 t
(c-make-keywords-re t
(c-lang-const c-typedef-kwds
)))
1588 (c-lang-defvar c-typedef-key
(c-lang-const c-typedef-key
))
1590 (c-lang-defconst c-type-prefix-kwds
1591 "Keywords where the following name - if any - is a type name, and
1592 where the keyword together with the symbol works as a type in
1595 Note that an alternative if the second part doesn't hold is
1596 `c-type-list-kwds'. Keywords on this list are typically also present
1597 on one of the `*-decl-kwds' lists."
1599 c
'("struct" "union" "enum")
1600 c
++ (append '("class" "typename")
1601 (c-lang-const c-type-prefix-kwds c
)))
1603 (c-lang-defconst c-type-prefix-key
1604 ;; Adorned regexp matching `c-type-prefix-kwds'.
1605 t
(c-make-keywords-re t
(c-lang-const c-type-prefix-kwds
)))
1606 (c-lang-defvar c-type-prefix-key
(c-lang-const c-type-prefix-key
))
1608 (c-lang-defconst c-type-modifier-kwds
1609 "Type modifier keywords. These can occur almost anywhere in types
1610 but they don't build a type of themselves. Unlike the keywords on
1611 `c-primitive-type-kwds', they are fontified with the keyword face and
1614 c
'("const" "restrict" "volatile")
1615 c
++ '("const" "volatile" "throw")
1616 objc
'("const" "volatile"))
1618 (c-lang-defconst c-opt-type-modifier-key
1619 ;; Adorned regexp matching `c-type-modifier-kwds', or nil in
1620 ;; languages without such keywords.
1621 t
(and (c-lang-const c-type-modifier-kwds
)
1622 (c-make-keywords-re t
(c-lang-const c-type-modifier-kwds
))))
1623 (c-lang-defvar c-opt-type-modifier-key
(c-lang-const c-opt-type-modifier-key
))
1625 (c-lang-defconst c-opt-type-component-key
1626 ;; An adorned regexp that matches `c-primitive-type-prefix-kwds' and
1627 ;; `c-type-modifier-kwds', or nil in languages without any of them.
1628 t
(and (or (c-lang-const c-primitive-type-prefix-kwds
)
1629 (c-lang-const c-type-modifier-kwds
))
1630 (c-make-keywords-re t
1631 (append (c-lang-const c-primitive-type-prefix-kwds
)
1632 (c-lang-const c-type-modifier-kwds
)))))
1633 (c-lang-defvar c-opt-type-component-key
1634 (c-lang-const c-opt-type-component-key
))
1636 (c-lang-defconst c-type-start-kwds
1637 ;; All keywords that can start a type (i.e. are either a type prefix
1638 ;; or a complete type).
1639 t
(delete-duplicates (append (c-lang-const c-primitive-type-kwds
)
1640 (c-lang-const c-type-prefix-kwds
)
1641 (c-lang-const c-type-modifier-kwds
))
1642 :test
'string-equal
))
1644 (c-lang-defconst c-class-decl-kwds
1645 "Keywords introducing declarations where the following block (if any)
1646 contains another declaration level that should be considered a class.
1648 If any of these also are on `c-type-list-kwds', `c-ref-list-kwds',
1649 `c-colon-type-list-kwds', `c-paren-nontype-kwds', `c-paren-type-kwds',
1650 `c-<>-type-kwds', or `c-<>-arglist-kwds' then the associated clauses
1653 Note that presence on this list does not automatically treat the
1654 following identifier as a type; the keyword must also be present on
1655 `c-type-prefix-kwds' or `c-type-list-kwds' to accomplish that."
1657 c
'("struct" "union")
1658 c
++ '("class" "struct" "union")
1659 objc
'("struct" "union"
1660 "@interface" "@implementation" "@protocol")
1661 java
'("class" "@interface" "interface")
1662 idl
'("component" "eventtype" "exception" "home" "interface" "struct"
1665 "storagehome" "storagetype"
1667 "catalog" "executor" "manages" "segment")
1670 (c-lang-defconst c-class-key
1671 ;; Regexp matching the start of a class.
1672 t
(c-make-keywords-re t
(c-lang-const c-class-decl-kwds
)))
1673 (c-lang-defvar c-class-key
(c-lang-const c-class-key
))
1675 (c-lang-defconst c-brace-list-decl-kwds
1676 "Keywords introducing declarations where the following block (if
1677 any) is a brace list.
1679 If any of these also are on `c-type-list-kwds', `c-ref-list-kwds',
1680 `c-colon-type-list-kwds', `c-paren-nontype-kwds', `c-paren-type-kwds',
1681 `c-<>-type-kwds', or `c-<>-arglist-kwds' then the associated clauses
1686 (c-lang-defconst c-brace-list-key
1687 ;; Regexp matching the start of declarations where the following
1688 ;; block is a brace list.
1689 t
(c-make-keywords-re t
(c-lang-const c-brace-list-decl-kwds
)))
1690 (c-lang-defvar c-brace-list-key
(c-lang-const c-brace-list-key
))
1692 (c-lang-defconst c-other-block-decl-kwds
1693 "Keywords where the following block (if any) contains another
1694 declaration level that should not be considered a class. For every
1695 keyword here, CC Mode will add a set of special syntactic symbols for
1696 those blocks. E.g. if the keyword is \"foo\" then there will be
1697 `foo-open', `foo-close', and `infoo' symbols.
1699 The intention is that this category should be used for block
1700 constructs that aren't related to object orientation concepts like
1701 classes (which thus also include e.g. interfaces, templates,
1702 contracts, structs, etc). The more pragmatic distinction is that
1703 while most want some indentation inside classes, it's fairly common
1704 that they don't want it in some of these constructs, so it should be
1705 simple to configure that differently from classes. See also
1706 `c-class-decl-kwds'.
1708 If any of these also are on `c-type-list-kwds', `c-ref-list-kwds',
1709 `c-colon-type-list-kwds', `c-paren-nontype-kwds', `c-paren-type-kwds',
1710 `c-<>-type-kwds', or `c-<>-arglist-kwds' then the associated clauses
1713 (c objc
) '("extern")
1714 c
++ '("namespace" "extern")
1719 (c-lang-defconst c-other-decl-block-key
1720 ;; Regexp matching the start of blocks besides classes that contain
1721 ;; another declaration level.
1722 t
(c-make-keywords-re t
(c-lang-const c-other-block-decl-kwds
)))
1723 (c-lang-defvar c-other-decl-block-key
(c-lang-const c-other-decl-block-key
))
1725 (c-lang-defvar c-other-decl-block-key-in-symbols-alist
1729 (if (string= elt
"extern")
1731 (intern (concat "in" elt
)))))
1732 (c-lang-const c-other-block-decl-kwds
))
1733 "Alist associating keywords in c-other-decl-block-decl-kwds with
1734 their matching \"in\" syntactic symbols.")
1736 (c-lang-defconst c-typedef-decl-kwds
1737 "Keywords introducing declarations where the identifier(s) being
1740 If any of these also are on `c-type-list-kwds', `c-ref-list-kwds',
1741 `c-colon-type-list-kwds', `c-paren-nontype-kwds', `c-paren-type-kwds',
1742 `c-<>-type-kwds', or `c-<>-arglist-kwds' then the associated clauses
1744 ;; Default to `c-class-decl-kwds' and `c-brace-list-decl-kwds'
1745 ;; (since e.g. "Foo" is a type that's being defined in "class Foo
1747 t
(append (c-lang-const c-class-decl-kwds
)
1748 (c-lang-const c-brace-list-decl-kwds
))
1749 ;; Languages that have a "typedef" construct.
1750 (c c
++ objc idl pike
) (append (c-lang-const c-typedef-decl-kwds
)
1752 ;; Unlike most other languages, exception names are not handled as
1753 ;; types in IDL since they only can occur in "raises" specs.
1754 idl
(delete "exception" (append (c-lang-const c-typedef-decl-kwds
) nil
)))
1756 (c-lang-defconst c-typedef-decl-key
1757 t
(c-make-keywords-re t
(c-lang-const c-typedef-decl-kwds
)))
1758 (c-lang-defvar c-typedef-decl-key
(c-lang-const c-typedef-decl-key
))
1760 (c-lang-defconst c-typeless-decl-kwds
1761 "Keywords introducing declarations where the \(first) identifier
1762 \(declarator) follows directly after the keyword, without any type.
1764 If any of these also are on `c-type-list-kwds', `c-ref-list-kwds',
1765 `c-colon-type-list-kwds', `c-paren-nontype-kwds', `c-paren-type-kwds',
1766 `c-<>-type-kwds', or `c-<>-arglist-kwds' then the associated clauses
1768 ;; Default to `c-class-decl-kwds' and `c-brace-list-decl-kwds'
1769 ;; (since e.g. "Foo" is the identifier being defined in "class Foo
1771 t
(append (c-lang-const c-class-decl-kwds
)
1772 (c-lang-const c-brace-list-decl-kwds
))
1773 ;; Note: "manages" for CORBA CIDL clashes with its presence on
1774 ;; `c-type-list-kwds' for IDL.
1775 idl
(append (c-lang-const c-typeless-decl-kwds
)
1776 '("factory" "finder" "native"
1781 pike
(append (c-lang-const c-class-decl-kwds
)
1784 (c-lang-defconst c-modifier-kwds
1785 "Keywords that can prefix normal declarations of identifiers
1786 \(and typically act as flags). Things like argument declarations
1787 inside function headers are also considered declarations in this
1790 If any of these also are on `c-type-list-kwds', `c-ref-list-kwds',
1791 `c-colon-type-list-kwds', `c-paren-nontype-kwds', `c-paren-type-kwds',
1792 `c-<>-type-kwds', or `c-<>-arglist-kwds' then the associated clauses
1795 (c c
++) '("auto" "extern" "inline" "register" "static")
1796 c
++ (append '("explicit" "friend" "mutable" "template" "using" "virtual")
1797 (c-lang-const c-modifier-kwds
))
1798 objc
'("auto" "bycopy" "byref" "extern" "in" "inout" "oneway" "out" "static")
1799 ;; FIXME: Some of those below ought to be on `c-other-decl-kwds' instead.
1800 idl
'("abstract" "attribute" "const" "consumes" "custom" "emits" "import"
1801 "in" "inout" "local" "multiple" "oneway" "out" "private" "provides"
1802 "public" "publishes" "readonly" "typeid" "typeprefix" "uses"
1806 "bindsTo" "delegatesTo" "implements" "proxy" "storedOn")
1807 ;; Note: "const" is not used in Java, but it's still a reserved keyword.
1808 java
'("abstract" "const" "final" "native" "private" "protected" "public"
1809 "static" "strictfp" "synchronized" "transient" "volatile" "@[A-Za-z0-9]+")
1810 pike
'("final" "inline" "local" "nomask" "optional" "private" "protected"
1811 "public" "static" "variant"))
1813 (c-lang-defconst c-other-decl-kwds
1814 "Keywords that can start or prefix any declaration level construct,
1815 besides those on `c-class-decl-kwds', `c-brace-list-decl-kwds',
1816 `c-other-block-decl-kwds', `c-typedef-decl-kwds',
1817 `c-typeless-decl-kwds' and `c-modifier-kwds'.
1819 If any of these also are on `c-type-list-kwds', `c-ref-list-kwds',
1820 `c-colon-type-list-kwds', `c-paren-nontype-kwds', `c-paren-type-kwds',
1821 `c-<>-type-kwds', or `c-<>-arglist-kwds' then the associated clauses
1824 objc
'("@class" "@end" "@defs")
1825 java
'("import" "package")
1826 pike
'("import" "inherit"))
1828 (c-lang-defconst c-decl-start-kwds
1829 "Keywords that always start declarations, wherever they occur.
1830 This can be used for declarations that aren't recognized by the normal
1831 combination of `c-decl-prefix-re' and `c-decl-start-re'."
1833 ;; Classes can be declared anywhere in a Pike expression.
1836 (c-lang-defconst c-decl-hangon-kwds
1837 "Keywords that can occur anywhere in a declaration level construct.
1838 This is used for self-contained things that can be tacked on anywhere
1839 on a declaration and that should be ignored to be able to recognize it
1840 correctly. Typical cases are compiler extensions like
1841 \"__attribute__\" or \"__declspec\":
1843 __declspec(noreturn) void foo();
1844 class __declspec(dllexport) classname {...};
1845 void foo() __attribute__((noreturn));
1847 Note that unrecognized plain symbols are skipped anyway if they occur
1848 before the type, so such things are not necessary to mention here.
1849 Mentioning them here is necessary only if they can occur in other
1850 places, or if they are followed by a construct that must be skipped
1851 over \(like the parens in the \"__attribute__\" and \"__declspec\"
1852 examples above). In the last case, they alse need to be present on
1853 one of `c-type-list-kwds', `c-ref-list-kwds',
1854 `c-colon-type-list-kwds', `c-paren-nontype-kwds', `c-paren-type-kwds',
1855 `c-<>-type-kwds', or `c-<>-arglist-kwds'."
1856 ;; NB: These are currently not recognized in all parts of a
1857 ;; declaration. Specifically, they aren't recognized in the middle
1858 ;; of multi-token types, inside declarators, and between the
1859 ;; identifier and the arglist paren of a function declaration.
1861 ;; FIXME: This ought to be user customizable since compiler stuff
1862 ;; like this usually is wrapped in project specific macros. (It'd
1863 ;; of course be even better if we could cope without knowing this.)
1865 (c c
++) '(;; GCC extension.
1870 (c-lang-defconst c-decl-hangon-key
1871 ;; Adorned regexp matching `c-decl-hangon-kwds'.
1872 t
(c-make-keywords-re t
(c-lang-const c-decl-hangon-kwds
)))
1873 (c-lang-defvar c-decl-hangon-key
(c-lang-const c-decl-hangon-key
))
1875 (c-lang-defconst c-prefix-spec-kwds
1876 ;; All keywords that can occur in the preamble of a declaration.
1877 ;; They typically occur before the type, but they are also matched
1878 ;; after presumptive types since we often can't be sure that
1879 ;; something is a type or just some sort of macro in front of the
1880 ;; declaration. They might be ambiguous with types or type
1882 t
(delete-duplicates (append (c-lang-const c-class-decl-kwds
)
1883 (c-lang-const c-brace-list-decl-kwds
)
1884 (c-lang-const c-other-block-decl-kwds
)
1885 (c-lang-const c-typedef-decl-kwds
)
1886 (c-lang-const c-typeless-decl-kwds
)
1887 (c-lang-const c-modifier-kwds
)
1888 (c-lang-const c-other-decl-kwds
)
1889 (c-lang-const c-decl-start-kwds
)
1890 (c-lang-const c-decl-hangon-kwds
))
1891 :test
'string-equal
))
1893 (c-lang-defconst c-prefix-spec-kwds-re
1894 ;; Adorned regexp of `c-prefix-spec-kwds'.
1895 t
(c-make-keywords-re t
(c-lang-const c-prefix-spec-kwds
))
1896 java
(replace-regexp-in-string
1898 (replace-regexp-in-string "\\\\\\+" "+" (c-make-keywords-re t
(c-lang-const c-prefix-spec-kwds
)))))
1900 (c-lang-defvar c-prefix-spec-kwds-re
(c-lang-const c-prefix-spec-kwds-re
))
1902 (c-lang-defconst c-specifier-key
1903 ;; Adorned regexp of the keywords in `c-prefix-spec-kwds' that aren't
1904 ;; ambiguous with types or type prefixes. These are the keywords (like
1905 ;; extern, namespace, but NOT template) that can modify a declaration.
1906 t
(c-make-keywords-re t
1907 (set-difference (c-lang-const c-prefix-spec-kwds
)
1908 (append (c-lang-const c-type-start-kwds
)
1909 (c-lang-const c-
<>-arglist-kwds
))
1910 :test
'string-equal
)))
1911 (c-lang-defvar c-specifier-key
(c-lang-const c-specifier-key
))
1913 (c-lang-defconst c-postfix-spec-kwds
1914 ;; Keywords that can occur after argument list of a function header
1915 ;; declaration, i.e. in the "K&R region".
1916 t
(append (c-lang-const c-postfix-decl-spec-kwds
)
1917 (c-lang-const c-decl-hangon-kwds
)))
1919 (c-lang-defconst c-not-decl-init-keywords
1920 ;; Adorned regexp matching all keywords that can't appear at the
1921 ;; start of a declaration.
1922 t
(c-make-keywords-re t
1923 (set-difference (c-lang-const c-keywords
)
1924 (append (c-lang-const c-type-start-kwds
)
1925 (c-lang-const c-prefix-spec-kwds
))
1926 :test
'string-equal
)))
1927 (c-lang-defvar c-not-decl-init-keywords
1928 (c-lang-const c-not-decl-init-keywords
))
1930 (c-lang-defconst c-protection-kwds
1931 "Access protection label keywords in classes."
1933 c
++ '("private" "protected" "public")
1934 objc
'("@private" "@protected" "@public"))
1936 (c-lang-defconst c-block-decls-with-vars
1937 "Keywords introducing declarations that can contain a block which
1938 might be followed by variable declarations, e.g. like \"foo\" in
1939 \"class Foo { ... } foo;\". So if there is a block in a declaration
1940 like that, it ends with the following ';' and not right away.
1942 The keywords on list are assumed to also be present on one of the
1943 `*-decl-kwds' lists."
1945 (c objc
) '("struct" "union" "enum" "typedef")
1946 c
++ '("class" "struct" "union" "enum" "typedef"))
1948 (c-lang-defconst c-opt-block-decls-with-vars-key
1949 ;; Regexp matching the `c-block-decls-with-vars' keywords, or nil in
1950 ;; languages without such constructs.
1951 t
(and (c-lang-const c-block-decls-with-vars
)
1952 (c-make-keywords-re t
(c-lang-const c-block-decls-with-vars
))))
1953 (c-lang-defvar c-opt-block-decls-with-vars-key
1954 (c-lang-const c-opt-block-decls-with-vars-key
))
1956 (c-lang-defconst c-postfix-decl-spec-kwds
1957 "Keywords introducing extra declaration specifiers in the region
1958 between the header and the body \(i.e. the \"K&R-region\") in
1961 java
'("extends" "implements" "throws")
1962 idl
'("context" "getraises" "manages" "primarykey" "raises" "setraises"
1965 "as" "const" "implements" "of" "ref"))
1967 (c-lang-defconst c-nonsymbol-sexp-kwds
1968 "Keywords that may be followed by a nonsymbol sexp before whatever
1969 construct it's part of continues."
1971 (c c
++ objc
) '("extern"))
1973 (c-lang-defconst c-type-list-kwds
1974 "Keywords that may be followed by a comma separated list of type
1975 identifiers, where each optionally can be prefixed by keywords. (Can
1976 also be used for the special case when the list can contain only one
1979 Assumed to be mutually exclusive with `c-ref-list-kwds'. There's no
1980 reason to put keywords on this list if they are on `c-type-prefix-kwds'.
1981 There's also no reason to add keywords that prefixes a normal
1982 declaration consisting of a type followed by a declarator (list), so
1983 the keywords on `c-modifier-kwds' should normally not be listed here
1986 Note: Use `c-typeless-decl-kwds' for keywords followed by a function
1987 or variable identifier (that's being defined)."
1991 java
'("import" "new" "extends" "super" "implements" "throws")
1992 idl
'("manages" "native" "primarykey" "supports"
1994 "as" "implements" "of" "scope")
1997 (c-lang-defconst c-ref-list-kwds
1998 "Keywords that may be followed by a comma separated list of
1999 reference (i.e. namespace/scope/module) identifiers, where each
2000 optionally can be prefixed by keywords. (Can also be used for the
2001 special case when the list can contain only one element.) Assumed to
2002 be mutually exclusive with `c-type-list-kwds'.
2004 Note: Use `c-typeless-decl-kwds' for keywords followed by a function
2005 or variable identifier (that's being defined)."
2009 idl
'("import" "module"
2014 (c-lang-defconst c-colon-type-list-kwds
2015 "Keywords that may be followed (not necessarily directly) by a colon
2016 and then a comma separated list of type identifiers, where each
2017 optionally can be prefixed by keywords. (Can also be used for the
2018 special case when the list can contain only one element.)"
2020 c
++ '("class" "struct")
2021 idl
'("component" "eventtype" "home" "interface" "valuetype"
2023 "storagehome" "storagetype"))
2025 (c-lang-defconst c-colon-type-list-re
2026 "Regexp matched after the keywords in `c-colon-type-list-kwds' to skip
2027 forward to the colon. The end of the match is assumed to be directly
2028 after the colon, so the regexp should end with \":\". Must be a
2029 regexp if `c-colon-type-list-kwds' isn't nil."
2030 t
(if (c-lang-const c-colon-type-list-kwds
)
2031 ;; Disallow various common punctuation chars that can't come
2032 ;; before the ":" that starts the inherit list after "class"
2033 ;; or "struct" in C++. (Also used as default for other
2035 "[^\]\[{}();,/#=:]*:"))
2036 (c-lang-defvar c-colon-type-list-re
(c-lang-const c-colon-type-list-re
))
2038 (c-lang-defconst c-paren-nontype-kwds
2039 "Keywords that may be followed by a parenthesis expression that doesn't
2040 contain type identifiers."
2042 (c c
++) '(;; GCC extension.
2047 (c-lang-defconst c-paren-type-kwds
2048 "Keywords that may be followed by a parenthesis expression containing
2049 type identifiers separated by arbitrary tokens."
2054 pike
'("array" "function" "int" "mapping" "multiset" "object" "program"))
2056 (c-lang-defconst c-paren-any-kwds
2057 t
(delete-duplicates (append (c-lang-const c-paren-nontype-kwds
)
2058 (c-lang-const c-paren-type-kwds
))
2059 :test
'string-equal
))
2061 (c-lang-defconst c-
<>-type-kwds
2062 "Keywords that may be followed by an angle bracket expression
2063 containing type identifiers separated by \",\". The difference from
2064 `c-<>-arglist-kwds' is that unknown names are taken to be types and
2065 not other identifiers. `c-recognize-<>-arglists' is assumed to be set
2073 (c-lang-defconst c-
<>-arglist-kwds
2074 "Keywords that can be followed by a C++ style template arglist; see
2075 `c-recognize-<>-arglists' for details. That language constant is
2076 assumed to be set if this isn't nil."
2079 idl
'("fixed" "string" "wstring"))
2081 (c-lang-defconst c-
<>-sexp-kwds
2082 ;; All keywords that can be followed by an angle bracket sexp.
2083 t
(delete-duplicates (append (c-lang-const c-
<>-type-kwds
)
2084 (c-lang-const c-
<>-arglist-kwds
))
2085 :test
'string-equal
))
2087 (c-lang-defconst c-opt-
<>-sexp-key
2088 ;; Adorned regexp matching keywords that can be followed by an angle
2089 ;; bracket sexp. Always set when `c-recognize-<>-arglists' is.
2090 t
(if (c-lang-const c-recognize-
<>-arglists
)
2091 (c-make-keywords-re t
(c-lang-const c-
<>-sexp-kwds
))))
2092 (c-lang-defvar c-opt-
<>-sexp-key
(c-lang-const c-opt-
<>-sexp-key
))
2094 (c-lang-defconst c-brace-id-list-kwds
2095 "Keywords that may be followed by a brace block containing a comma
2096 separated list of identifier definitions, i.e. like the list of
2097 identifiers that follows the type in a normal declaration."
2098 t
(c-lang-const c-brace-list-decl-kwds
))
2100 (c-lang-defconst c-block-stmt-1-kwds
2101 "Statement keywords followed directly by a substatement."
2103 c
++ '("do" "else" "try")
2104 objc
'("do" "else" "@finally" "@try")
2105 java
'("do" "else" "finally" "try")
2108 (c-lang-defconst c-block-stmt-1-key
2109 ;; Regexp matching the start of any statement followed directly by a
2110 ;; substatement (doesn't match a bare block, however).
2111 t
(c-make-keywords-re t
(c-lang-const c-block-stmt-1-kwds
)))
2112 (c-lang-defvar c-block-stmt-1-key
(c-lang-const c-block-stmt-1-key
))
2114 (c-lang-defconst c-block-stmt-2-kwds
2115 "Statement keywords followed by a paren sexp and then by a substatement."
2116 t
'("for" "if" "switch" "while")
2117 c
++ '("for" "if" "switch" "while" "catch")
2118 objc
'("for" "if" "switch" "while" "@catch" "@synchronized")
2119 java
'("for" "if" "switch" "while" "catch" "synchronized")
2121 pike
'("for" "if" "switch" "while" "foreach")
2122 awk
'("for" "if" "while"))
2124 (c-lang-defconst c-block-stmt-2-key
2125 ;; Regexp matching the start of any statement followed by a paren sexp
2126 ;; and then by a substatement.
2127 t
(c-make-keywords-re t
(c-lang-const c-block-stmt-2-kwds
)))
2128 (c-lang-defvar c-block-stmt-2-key
(c-lang-const c-block-stmt-2-key
))
2130 (c-lang-defconst c-block-stmt-kwds
2131 ;; Union of `c-block-stmt-1-kwds' and `c-block-stmt-2-kwds'.
2132 t
(delete-duplicates (append (c-lang-const c-block-stmt-1-kwds
)
2133 (c-lang-const c-block-stmt-2-kwds
))
2134 :test
'string-equal
))
2136 (c-lang-defconst c-opt-block-stmt-key
2137 ;; Regexp matching the start of any statement that has a
2138 ;; substatement (except a bare block). Nil in languages that
2139 ;; don't have such constructs.
2140 t
(if (or (c-lang-const c-block-stmt-1-kwds
)
2141 (c-lang-const c-block-stmt-2-kwds
))
2142 (c-make-keywords-re t
2143 (append (c-lang-const c-block-stmt-1-kwds
)
2144 (c-lang-const c-block-stmt-2-kwds
)))))
2145 (c-lang-defvar c-opt-block-stmt-key
(c-lang-const c-opt-block-stmt-key
))
2147 (c-lang-defconst c-simple-stmt-kwds
2148 "Statement keywords followed by an expression or nothing."
2149 t
'("break" "continue" "goto" "return")
2150 objc
'("break" "continue" "goto" "return" "@throw")
2151 ;; Note: `goto' is not valid in Java, but the keyword is still reserved.
2152 java
'("break" "continue" "goto" "return" "throw")
2154 pike
'("break" "continue" "return")
2155 awk
'(;; Not sure about "delete", "exit", "getline", etc. ; ACM 2002/5/30
2156 "break" "continue" "return" "delete" "exit" "getline" "next"
2157 "nextfile" "print" "printf"))
2159 (c-lang-defconst c-simple-stmt-key
2160 ;; Adorned regexp matching `c-simple-stmt-kwds'.
2161 t
(c-make-keywords-re t
(c-lang-const c-simple-stmt-kwds
)))
2162 (c-lang-defvar c-simple-stmt-key
(c-lang-const c-simple-stmt-key
))
2164 (c-lang-defconst c-paren-stmt-kwds
2165 "Statement keywords followed by a parenthesis expression that
2166 nevertheless contains a list separated with ';' and not ','."
2170 (c-lang-defconst c-paren-stmt-key
2171 ;; Adorned regexp matching `c-paren-stmt-kwds'.
2172 t
(c-make-keywords-re t
(c-lang-const c-paren-stmt-kwds
)))
2173 (c-lang-defvar c-paren-stmt-key
(c-lang-const c-paren-stmt-key
))
2175 (c-lang-defconst c-asm-stmt-kwds
2176 "Statement keywords followed by an assembler expression."
2178 (c c
++) '("asm" "__asm__")) ;; Not standard, but common.
2180 (c-lang-defconst c-opt-asm-stmt-key
2181 ;; Regexp matching the start of an assembler statement. Nil in
2182 ;; languages that don't support that.
2183 t
(if (c-lang-const c-asm-stmt-kwds
)
2184 (c-make-keywords-re t
(c-lang-const c-asm-stmt-kwds
))))
2185 (c-lang-defvar c-opt-asm-stmt-key
(c-lang-const c-opt-asm-stmt-key
))
2187 (c-lang-defconst c-case-kwds
2188 "The keyword\(s) which introduce a \"case\" like construct.
2189 This construct is \"<keyword> <expression> :\"."
2193 (c-lang-defconst c-case-kwds-regexp
2194 ;; Adorned regexp matching any "case"-like keyword.
2195 t
(c-make-keywords-re t
(c-lang-const c-case-kwds
)))
2196 (c-lang-defvar c-case-kwds-regexp
(c-lang-const c-case-kwds-regexp
))
2198 (c-lang-defconst c-label-kwds
2199 "Keywords introducing colon terminated labels in blocks."
2200 t
'("case" "default")
2203 (c-lang-defconst c-label-kwds-regexp
2204 ;; Adorned regexp matching any keyword that introduces a label.
2205 t
(c-make-keywords-re t
(c-lang-const c-label-kwds
)))
2206 (c-lang-defvar c-label-kwds-regexp
(c-lang-const c-label-kwds-regexp
))
2208 (c-lang-defconst c-before-label-kwds
2209 "Keywords that might be followed by a label identifier."
2211 (java pike
) (append '("break" "continue")
2212 (c-lang-const c-before-label-kwds
))
2216 (c-lang-defconst c-constant-kwds
2217 "Keywords for constants."
2219 (c c
++) '("NULL" ;; Not a keyword, but practically works as one.
2220 "false" "true") ; Defined in C99.
2221 objc
'("nil" "Nil" "YES" "NO" "NS_DURING" "NS_HANDLER" "NS_ENDHANDLER")
2222 idl
'("TRUE" "FALSE")
2223 java
'("true" "false" "null") ; technically "literals", not keywords
2224 pike
'("UNDEFINED")) ;; Not a keyword, but practically works as one.
2226 (c-lang-defconst c-primary-expr-kwds
2227 "Keywords besides constants and operators that start primary expressions."
2229 c
++ '("operator" "this")
2230 objc
'("super" "self")
2232 pike
'("this")) ;; Not really a keyword, but practically works as one.
2234 (c-lang-defconst c-expr-kwds
2235 ;; Keywords that can occur anywhere in expressions. Built from
2236 ;; `c-primary-expr-kwds' and all keyword operators in `c-operators'.
2237 t
(delete-duplicates
2238 (append (c-lang-const c-primary-expr-kwds
)
2239 (c-filter-ops (c-lang-const c-operator-list
)
2241 "\\`\\(\\w\\|\\s_\\)+\\'"))
2242 :test
'string-equal
))
2244 (c-lang-defconst c-lambda-kwds
2245 "Keywords that start lambda constructs, i.e. function definitions in
2250 (c-lang-defconst c-inexpr-block-kwds
2251 "Keywords that start constructs followed by statement blocks which can
2252 be used in expressions \(the gcc extension for this in C and C++ is
2253 handled separately by `c-recognize-paren-inexpr-blocks')."
2255 pike
'("catch" "gauge"))
2257 (c-lang-defconst c-inexpr-class-kwds
2258 "Keywords that can start classes inside expressions."
2263 (c-lang-defconst c-inexpr-brace-list-kwds
2264 "Keywords that can start brace list blocks inside expressions.
2265 Note that Java specific rules are currently applied to tell this from
2266 `c-inexpr-class-kwds'."
2270 (c-lang-defconst c-opt-inexpr-brace-list-key
2271 ;; Regexp matching the start of a brace list in an expression, or
2272 ;; nil in languages that don't have such things. This should not
2273 ;; match brace lists recognized through `c-special-brace-lists'.
2274 t
(and (c-lang-const c-inexpr-brace-list-kwds
)
2275 (c-make-keywords-re t
(c-lang-const c-inexpr-brace-list-kwds
))))
2276 (c-lang-defvar c-opt-inexpr-brace-list-key
2277 (c-lang-const c-opt-inexpr-brace-list-key
))
2279 (c-lang-defconst c-decl-block-key
2280 ;; Regexp matching keywords in any construct that contain another
2281 ;; declaration level, i.e. that isn't followed by a function block
2282 ;; or brace list. When the first submatch matches, it's an
2283 ;; unambiguous construct, otherwise it's an ambiguous match that
2284 ;; might also be the return type of a function declaration.
2285 t
(let* ((decl-kwds (append (c-lang-const c-class-decl-kwds
)
2286 (c-lang-const c-other-block-decl-kwds
)
2287 (c-lang-const c-inexpr-class-kwds
)))
2288 (unambiguous (set-difference decl-kwds
2289 (c-lang-const c-type-start-kwds
)
2290 :test
'string-equal
))
2291 (ambiguous (intersection decl-kwds
2292 (c-lang-const c-type-start-kwds
)
2293 :test
'string-equal
)))
2295 (concat (c-make-keywords-re t unambiguous
)
2297 (c-make-keywords-re t ambiguous
))
2298 (c-make-keywords-re t unambiguous
))))
2299 (c-lang-defvar c-decl-block-key
(c-lang-const c-decl-block-key
))
2301 (c-lang-defconst c-bitfield-kwds
2302 "Keywords that can introduce bitfields."
2304 (c c
++ objc
) '("char" "int" "long" "signed" "unsigned"))
2306 (c-lang-defconst c-opt-bitfield-key
2307 ;; Regexp matching the start of a bitfield (not uniquely), or nil in
2308 ;; languages without bitfield support.
2310 (c c
++) (c-make-keywords-re t
(c-lang-const c-bitfield-kwds
)))
2311 (c-lang-defvar c-opt-bitfield-key
(c-lang-const c-opt-bitfield-key
))
2313 (c-lang-defconst c-other-kwds
2314 "Keywords not accounted for by any other `*-kwds' language constant."
2317 ;; In CORBA CIDL: (These are declaration keywords that never
2318 ;; can start a declaration.)
2319 "entity" "process" "service" "session" "storage"))
2322 ;;; Constants built from keywords.
2324 ;; Note: No `*-kwds' language constants may be defined below this point.
2327 (defconst c-kwds-lang-consts
2328 ;; List of all the language constants that contain keyword lists.
2330 (mapatoms (lambda (sym)
2331 (when (and (boundp sym
)
2332 (string-match "-kwds\\'" (symbol-name sym
)))
2333 ;; Make the list of globally interned symbols
2334 ;; instead of ones interned in `c-lang-constants'.
2335 (setq list
(cons (intern (symbol-name sym
)) list
))))
2339 (c-lang-defconst c-keywords
2340 ;; All keywords as a list.
2341 t
(delete-duplicates
2342 (c-lang-defconst-eval-immediately
2343 `(append ,@(mapcar (lambda (kwds-lang-const)
2344 `(c-lang-const ,kwds-lang-const
))
2347 :test
'string-equal
))
2349 (c-lang-defconst c-keywords-regexp
2350 ;; All keywords as an adorned regexp.
2351 t
(c-make-keywords-re t
(c-lang-const c-keywords
)))
2352 (c-lang-defvar c-keywords-regexp
(c-lang-const c-keywords-regexp
))
2354 (c-lang-defconst c-keyword-member-alist
2355 ;; An alist with all the keywords in the cars. The cdr for each
2356 ;; keyword is a list of the symbols for the `*-kwds' lists that
2358 t
(let ((kwd-list-alist
2359 (c-lang-defconst-eval-immediately
2360 `(list ,@(mapcar (lambda (kwds-lang-const)
2361 `(cons ',kwds-lang-const
2362 (c-lang-const ,kwds-lang-const
)))
2363 c-kwds-lang-consts
))))
2364 lang-const kwd-list kwd
2366 (while kwd-list-alist
2367 (setq lang-const
(caar kwd-list-alist
)
2368 kwd-list
(cdar kwd-list-alist
)
2369 kwd-list-alist
(cdr kwd-list-alist
))
2371 (setq kwd
(car kwd-list
)
2372 kwd-list
(cdr kwd-list
))
2373 (unless (setq elem
(assoc kwd result-alist
))
2374 (setq result-alist
(cons (setq elem
(list kwd
)) result-alist
)))
2375 (unless (memq lang-const
(cdr elem
))
2376 (setcdr elem
(cons lang-const
(cdr elem
))))))
2379 (c-lang-defvar c-keywords-obarray
2380 ;; An obarray containing all keywords as symbols. The property list
2381 ;; of each symbol has a non-nil entry for the specific `*-kwds'
2382 ;; lists it's a member of.
2384 ;; E.g. to see whether the string str contains a keyword on
2385 ;; `c-class-decl-kwds', one can do like this:
2386 ;; (get (intern-soft str c-keyword-obarray) 'c-class-decl-kwds)
2387 ;; Which preferably is written using the associated functions in
2389 ;; (c-keyword-member (c-keyword-sym str) 'c-class-decl-kwds)
2391 ;; The obarray is not stored directly as a language constant since
2392 ;; the printed representation for obarrays used in .elc files isn't
2395 (let* ((alist (c-lang-const c-keyword-member-alist
))
2397 (obarray (make-vector (* (length alist
) 2) 0)))
2399 (setq kwd
(caar alist
)
2400 lang-const-list
(cdar alist
)
2402 (setplist (intern kwd obarray
)
2403 ;; Emacs has an odd bug that causes `mapcan' to fail
2404 ;; with unintelligible errors. (XEmacs works.)
2405 ;;(mapcan (lambda (lang-const)
2406 ;; (list lang-const t))
2408 (apply 'nconc
(mapcar (lambda (lang-const)
2409 (list lang-const t
))
2413 (c-lang-defconst c-regular-keywords-regexp
2414 ;; Adorned regexp matching all keywords that should be fontified
2415 ;; with the keywords face. I.e. that aren't types or constants.
2416 t
(c-make-keywords-re t
2417 (set-difference (c-lang-const c-keywords
)
2418 (append (c-lang-const c-primitive-type-kwds
)
2419 (c-lang-const c-constant-kwds
))
2420 :test
'string-equal
)))
2421 (c-lang-defvar c-regular-keywords-regexp
2422 (c-lang-const c-regular-keywords-regexp
))
2424 (c-lang-defconst c-primary-expr-regexp
2425 ;; Regexp matching the start of any primary expression, i.e. any
2426 ;; literal, symbol, prefix operator, and '('. It doesn't need to
2427 ;; exclude keywords; they are excluded afterwards unless the second
2428 ;; submatch matches. If the first but not the second submatch
2429 ;; matches then it is an ambiguous primary expression; it could also
2430 ;; be a match of e.g. an infix operator. (The case with ambiguous
2431 ;; keyword operators isn't handled.)
2433 t
(let* ((prefix-ops
2434 (c-filter-ops (c-lang-const c-operators
)
2437 ;; Filter out the special case prefix
2438 ;; operators that are close parens.
2439 (not (string-match "\\s)" op
)))))
2441 (nonkeyword-prefix-ops
2442 (c-filter-ops prefix-ops
2444 "\\`\\(\\s.\\|\\s(\\|\\s)\\)+\\'"))
2447 (c-filter-ops (c-lang-const c-operators
)
2452 right-assoc-sequence
)
2455 (unambiguous-prefix-ops (set-difference nonkeyword-prefix-ops
2457 :test
'string-equal
))
2458 (ambiguous-prefix-ops (intersection nonkeyword-prefix-ops
2460 :test
'string-equal
)))
2464 ;; Take out all symbol class operators from `prefix-ops' and make the
2465 ;; first submatch from them together with `c-primary-expr-kwds'.
2466 (c-make-keywords-re t
2467 (append (c-lang-const c-primary-expr-kwds
)
2468 (set-difference prefix-ops nonkeyword-prefix-ops
2469 :test
'string-equal
)))
2472 ;; Match all ambiguous operators.
2473 (c-make-keywords-re nil
2474 (intersection nonkeyword-prefix-ops in-or-postfix-ops
2475 :test
'string-equal
))
2479 ;; Now match all other symbols.
2480 (c-lang-const c-symbol-start
)
2483 ;; The chars that can start integer and floating point
2488 ;; The nonambiguous operators from `prefix-ops'.
2489 (c-make-keywords-re nil
2490 (set-difference nonkeyword-prefix-ops in-or-postfix-ops
2491 :test
'string-equal
))
2494 ;; Match string and character literals.
2496 (if (memq 'gen-string-delim c-emacs-features
)
2499 (c-lang-defvar c-primary-expr-regexp
(c-lang-const c-primary-expr-regexp
))
2502 ;;; Additional constants for parser-level constructs.
2504 (c-lang-defconst c-decl-prefix-re
2505 "Regexp matching something that might precede a declaration, cast or
2506 label, such as the last token of a preceding statement or declaration.
2507 This is used in the common situation where a declaration or cast
2508 doesn't start with any specific token that can be searched for.
2510 The regexp should not match bob; that is done implicitly. It can't
2511 require a match longer than one token. The end of the token is taken
2512 to be at the end of the first submatch, which is assumed to always
2513 match. It's undefined whether identifier syntax (see
2514 `c-identifier-syntax-table') is in effect or not. This regexp is
2515 assumed to be a superset of `c-label-prefix-re' if
2516 `c-recognize-colon-labels' is set.
2518 Besides this, `c-decl-start-kwds' is used to find declarations.
2520 Note: This variable together with `c-decl-start-re' and
2521 `c-decl-start-kwds' is only used to detect \"likely\"
2522 declaration/cast/label starts. I.e. they might produce more matches
2523 but should not miss anything (or else it's necessary to use text
2524 properties - see the next note). Wherever they match, the following
2525 construct is analyzed to see if it indeed is a declaration, cast or
2526 label. That analysis is not cheap, so it's important that not too
2527 many false matches are triggered.
2529 Note: If a declaration/cast/label start can't be detected with this
2530 variable, it's necessary to use the `c-type' text property with the
2531 value `c-decl-end' on the last char of the last token preceding the
2532 declaration. See the comment blurb at the start of cc-engine.el for
2535 ;; We match a sequence of characters to skip over things like \"};\"
2536 ;; more quickly. We match ")" in C for K&R region declarations, and
2537 ;; in all languages except Java for when a cpp macro definition
2538 ;; begins with a declaration.
2539 t
"\\([\{\}\(\);,]+\\)"
2540 java
"\\([\{\}\(;,<]+\\)"
2541 ;; Match "<" in C++ to get the first argument in a template arglist.
2542 ;; In that case there's an additional check in `c-find-decl-spots'
2543 ;; that it got open paren syntax.
2544 c
++ "\\([\{\}\(\);,<]+\\)"
2545 ;; Additionally match the protection directives in Objective-C.
2546 ;; Note that this doesn't cope with the longer directives, which we
2547 ;; would have to match from start to end since they don't end with
2548 ;; any easily recognized characters.
2549 objc
(concat "\\([\{\}\(\);,]+\\|"
2550 (c-make-keywords-re nil
(c-lang-const c-protection-kwds
))
2552 ;; Pike is like C but we also match "[" for multiple value
2553 ;; assignments and type casts.
2554 pike
"\\([\{\}\(\)\[;,]+\\)")
2555 (c-lang-defvar c-decl-prefix-re
(c-lang-const c-decl-prefix-re
)
2558 (c-lang-defconst c-decl-start-re
2559 "Regexp matching the start of any declaration, cast or label.
2560 It's used on the token after the one `c-decl-prefix-re' matched. This
2561 regexp should not try to match those constructs accurately as it's
2562 only used as a sieve to avoid spending more time checking other
2564 t
(c-lang-const c-identifier-start
))
2565 (c-lang-defvar c-decl-start-re
(c-lang-const c-decl-start-re
))
2567 (c-lang-defconst c-decl-prefix-or-start-re
2568 ;; Regexp matching something that might precede or start a
2569 ;; declaration, cast or label.
2571 ;; If the first submatch matches, it's taken to match the end of a
2572 ;; token that might precede such a construct, e.g. ';', '}' or '{'.
2573 ;; It's built from `c-decl-prefix-re'.
2575 ;; If the first submatch did not match, the match of the whole
2576 ;; regexp is taken to be at the first token in the declaration.
2577 ;; `c-decl-start-re' is not checked in this case.
2579 ;; Design note: The reason the same regexp is used to match both
2580 ;; tokens that precede declarations and start them is to avoid an
2581 ;; extra regexp search from the previous declaration spot in
2582 ;; `c-find-decl-spots'. Users of `c-find-decl-spots' also count on
2583 ;; that it finds all declaration/cast/label starts in approximately
2584 ;; linear order, so we can't do the searches in two separate passes.
2585 t
(if (c-lang-const c-decl-start-kwds
)
2586 (concat (c-lang-const c-decl-prefix-re
)
2588 (c-make-keywords-re t
(c-lang-const c-decl-start-kwds
)))
2589 (c-lang-const c-decl-prefix-re
)))
2590 (c-lang-defvar c-decl-prefix-or-start-re
2591 (c-lang-const c-decl-prefix-or-start-re
)
2594 (c-lang-defconst c-cast-parens
2595 ;; List containing the paren characters that can open a cast, or nil in
2596 ;; languages without casts.
2597 t
(c-filter-ops (c-lang-const c-operators
)
2600 (lambda (op) (elt op
0))))
2601 (c-lang-defvar c-cast-parens
(c-lang-const c-cast-parens
))
2603 (c-lang-defconst c-block-prefix-disallowed-chars
2604 "List of syntactically relevant characters that never can occur before
2605 the open brace in any construct that contains a brace block, e.g. in
2606 the \"class Foo: public Bar\" part of:
2608 class Foo: public Bar {int x();} a, *b;
2610 If parens can occur, the chars inside those aren't filtered with this
2613 '<' and '>' should be disallowed even if angle bracket arglists can
2614 occur. That since the search function needs to stop at them anyway to
2615 ensure they are given paren syntax.
2617 This is used to skip backward from the open brace to find the region
2618 in which to look for a construct like \"class\", \"enum\",
2619 \"namespace\" or whatever. That skipping should be as tight as
2620 possible for good performance."
2622 ;; Default to all chars that only occurs in nonsymbol tokens outside
2625 (c-lang-const c-nonsymbol-token-char-list
)
2626 (c-filter-ops (append (c-lang-const c-identifier-ops
)
2628 (c-lang-const c-after-id-concat-ops
))))
2633 (while (string-match "\\(\\s.\\|\\s(\\|\\s)\\)"
2635 (setq res
(cons (aref op
(match-beginning 1)) res
)
2639 ;; Allow cpp operatios (where applicable).
2640 t
(if (c-lang-const c-opt-cpp-prefix
)
2641 (set-difference (c-lang-const c-block-prefix-disallowed-chars
)
2643 (c-lang-const c-block-prefix-disallowed-chars
))
2645 ;; Allow ':' for inherit list starters.
2646 (c++ objc idl
) (set-difference (c-lang-const c-block-prefix-disallowed-chars
)
2649 ;; Allow ',' for multiple inherits.
2650 (c++ java
) (set-difference (c-lang-const c-block-prefix-disallowed-chars
)
2653 ;; Allow parentheses for anonymous inner classes in Java and class
2654 ;; initializer lists in Pike.
2655 (java pike
) (set-difference (c-lang-const c-block-prefix-disallowed-chars
)
2658 ;; Allow '"' for extern clauses (e.g. extern "C" {...}).
2659 (c c
++ objc
) (set-difference (c-lang-const c-block-prefix-disallowed-chars
)
2662 (c-lang-defconst c-block-prefix-charset
2663 ;; `c-block-prefix-disallowed-chars' as an inverted charset suitable
2664 ;; for `c-syntactic-skip-backward'.
2665 t
(c-make-bare-char-alt (c-lang-const c-block-prefix-disallowed-chars
) t
))
2666 (c-lang-defvar c-block-prefix-charset
(c-lang-const c-block-prefix-charset
))
2668 (c-lang-defconst c-type-decl-prefix-key
2669 "Regexp matching the declarator operators that might precede the
2670 identifier in a declaration, e.g. the \"*\" in \"char *argv\". This
2671 regexp should match \"(\" if parentheses are valid in declarators.
2672 The end of the first submatch is taken as the end of the operator.
2673 Identifier syntax is in effect when this is matched \(see
2674 `c-identifier-syntax-table')."
2675 t
(if (c-lang-const c-type-modifier-kwds
)
2676 (concat (regexp-opt (c-lang-const c-type-modifier-kwds
) t
) "\\>")
2677 ;; Default to a regexp that never matches.
2679 ;; Check that there's no "=" afterwards to avoid matching tokens
2681 (c objc
) (concat "\\("
2684 (c-lang-const c-type-decl-prefix-key
)
2690 (c-lang-const c-type-decl-prefix-key
)
2693 ;; If this matches there's special treatment in
2694 ;; `c-font-lock-declarators' and
2695 ;; `c-font-lock-declarations' that check for a
2696 ;; complete name followed by ":: *".
2697 (c-lang-const c-identifier-start
)
2701 pike
"\\(\\*\\)\\([^=]\\|$\\)")
2702 (c-lang-defvar c-type-decl-prefix-key
(c-lang-const c-type-decl-prefix-key
)
2705 (c-lang-defconst c-type-decl-suffix-key
2706 "Regexp matching the declarator operators that might follow after the
2707 identifier in a declaration, e.g. the \"[\" in \"char argv[]\". This
2708 regexp should match \")\" if parentheses are valid in declarators. If
2709 it matches an open paren of some kind, the type declaration check
2710 continues at the corresponding close paren, otherwise the end of the
2711 first submatch is taken as the end of the operator. Identifier syntax
2712 is in effect when this is matched (see `c-identifier-syntax-table')."
2713 ;; Default to a regexp that matches `c-type-modifier-kwds' and a
2714 ;; function argument list parenthesis.
2715 t
(if (c-lang-const c-type-modifier-kwds
)
2717 (regexp-opt (c-lang-const c-type-modifier-kwds
) t
) "\\>"
2720 (c c
++ objc
) (concat
2723 (if (c-lang-const c-type-modifier-kwds
)
2726 ;; "throw" in `c-type-modifier-kwds' is followed
2727 ;; by a parenthesis list, but no extra measures
2728 ;; are necessary to handle that.
2729 (regexp-opt (c-lang-const c-type-modifier-kwds
) t
)
2733 (java idl
) "\\([\[\(]\\)")
2734 (c-lang-defvar c-type-decl-suffix-key
(c-lang-const c-type-decl-suffix-key
)
2737 (c-lang-defconst c-after-suffixed-type-decl-key
2738 "This regexp is matched after a declarator expression where
2739 `c-type-decl-suffix-key' has matched. If it matches then the
2740 construct is taken as a declaration. It's typically used to match the
2741 beginning of a function body or whatever might occur after the
2742 function header in a function declaration or definition. It's
2743 undefined whether identifier syntax (see `c-identifier-syntax-table')
2744 is in effect or not.
2746 Note that it's used in cases like after \"foo (bar)\" so it should
2747 only match when it's certain that it's a declaration, e.g \"{\" but
2748 not \",\" or \";\"."
2750 ;; If K&R style declarations should be recognized then one could
2751 ;; consider to match the start of any symbol since we want to match
2752 ;; the start of the first declaration in the "K&R region". That
2753 ;; could however produce false matches on code like "FOO(bar) x"
2754 ;; where FOO is a cpp macro, so it's better to leave it out and rely
2755 ;; on the other heuristics in that case.
2756 t
(if (c-lang-const c-postfix-spec-kwds
)
2757 ;; Add on the keywords in `c-postfix-spec-kwds'.
2758 (concat (c-lang-const c-after-suffixed-type-decl-key
)
2760 (c-make-keywords-re t
(c-lang-const c-postfix-spec-kwds
)))
2761 (c-lang-const c-after-suffixed-type-decl-key
))
2762 ;; Also match the colon that starts a base class initializer list in
2763 ;; C++. That can be confused with a function call before the colon
2764 ;; in a ? : operator, but we count on that `c-decl-prefix-re' won't
2765 ;; match before such a thing (as a declaration-level construct;
2766 ;; matches inside arglist contexts are already excluded).
2768 (c-lang-defvar c-after-suffixed-type-decl-key
2769 (c-lang-const c-after-suffixed-type-decl-key
)
2772 (c-lang-defconst c-after-suffixed-type-maybe-decl-key
2773 ;; Regexp that in addition to `c-after-suffixed-type-decl-key'
2774 ;; matches ";" and ",".
2775 t
(concat "\\(" (c-lang-const c-after-suffixed-type-decl-key
) "\\)"
2777 (c-lang-defvar c-after-suffixed-type-maybe-decl-key
2778 (c-lang-const c-after-suffixed-type-maybe-decl-key
))
2780 (c-lang-defconst c-opt-type-concat-key
2781 "Regexp matching operators that concatenate types, e.g. the \"|\" in
2782 \"int|string\" in Pike. The end of the first submatch is taken as the
2783 end of the operator. nil in languages without such operators. It's
2784 undefined whether identifier syntax (see `c-identifier-syntax-table')
2785 is in effect or not."
2787 pike
"\\([|.&]\\)\\($\\|[^|.&]\\)")
2788 (c-lang-defvar c-opt-type-concat-key
(c-lang-const c-opt-type-concat-key
)
2791 (c-lang-defconst c-opt-type-suffix-key
2792 "Regexp matching operators that might follow after a type, or nil in
2793 languages that don't have such operators. The end of the first
2794 submatch is taken as the end of the operator. This should not match
2795 things like C++ template arglists if `c-recognize-<>-arglists' is set.
2796 It's undefined whether identifier syntax (see `c-identifier-syntax-table')
2797 is in effect or not."
2799 (c c
++ objc pike
) "\\(\\.\\.\\.\\)"
2800 java
(concat "\\(\\[" (c-lang-const c-simple-ws
) "*\\]\\|\\.\\.\\.\\)"))
2801 (c-lang-defvar c-opt-type-suffix-key
(c-lang-const c-opt-type-suffix-key
))
2803 (c-lang-defvar c-known-type-key
2804 ;; Regexp matching the known type identifiers. This is initialized
2805 ;; from the type keywords and `*-font-lock-extra-types'. The first
2806 ;; submatch is the one that matches the type. Note that this regexp
2807 ;; assumes that symbol constituents like '_' and '$' have word
2810 (when (boundp (c-mode-symbol "font-lock-extra-types"))
2811 (c-mode-var "font-lock-extra-types")))
2814 (mapcar (lambda (re)
2815 (when (string-match "[][.*+?^$\\]" re
)
2820 (mapcar (lambda (re)
2821 (unless (string-match "[][.*+?^$\\]" re
)
2826 (append (list (c-make-keywords-re nil
2827 (append (c-lang-const c-primitive-type-kwds
)
2833 (c-lang-defconst c-special-brace-lists
2834 "List of open- and close-chars that makes up a pike-style brace list,
2835 i.e. for a ([Â ]) list there should be a cons (?\\[ . ?\\]) in this
2838 pike
'((?
{ . ?
}) (?\
[ . ?\
]) (?
< . ?
>)))
2839 (c-lang-defvar c-special-brace-lists
(c-lang-const c-special-brace-lists
))
2841 (c-lang-defconst c-recognize-knr-p
2842 "Non-nil means K&R style argument declarations are valid."
2845 (c-lang-defvar c-recognize-knr-p
(c-lang-const c-recognize-knr-p
))
2847 (c-lang-defconst c-recognize-typeless-decls
2848 "Non-nil means function declarations without return type should be
2849 recognized. That can introduce an ambiguity with parenthesized macro
2850 calls before a brace block. This setting does not affect declarations
2851 that are preceded by a declaration starting keyword, so
2852 e.g. `c-typeless-decl-kwds' may still be used when it's set to nil."
2855 (c-lang-defvar c-recognize-typeless-decls
2856 (c-lang-const c-recognize-typeless-decls
))
2858 (c-lang-defconst c-recognize-
<>-arglists
2859 "Non-nil means C++ style template arglists should be handled. More
2860 specifically, this means a comma separated list of types or
2861 expressions surrounded by \"<\" and \">\". It's always preceded by an
2862 identifier or one of the keywords on `c-<>-type-kwds' or
2863 `c-<>-arglist-kwds'. If there's an identifier before then the whole
2864 expression is considered to be a type."
2865 t
(or (consp (c-lang-const c-
<>-type-kwds
))
2866 (consp (c-lang-const c-
<>-arglist-kwds
))))
2867 (c-lang-defvar c-recognize-
<>-arglists
(c-lang-const c-recognize-
<>-arglists
))
2869 (c-lang-defconst c-recognize-paren-inits
2870 "Non-nil means that parenthesis style initializers exist,
2871 i.e. constructs like
2875 in addition to the more classic
2880 (c-lang-defvar c-recognize-paren-inits
(c-lang-const c-recognize-paren-inits
))
2882 (c-lang-defconst c-recognize-paren-inexpr-blocks
2883 "Non-nil to recognize gcc style in-expression blocks,
2884 i.e. compound statements surrounded by parentheses inside expressions."
2887 (c-lang-defvar c-recognize-paren-inexpr-blocks
2888 (c-lang-const c-recognize-paren-inexpr-blocks
))
2890 (c-lang-defconst c-opt-
<>-arglist-start
2891 ;; Regexp matching the start of angle bracket arglists in languages
2892 ;; where `c-recognize-<>-arglists' is set. Does not exclude
2893 ;; keywords outside `c-<>-arglist-kwds'. The first submatch is
2894 ;; assumed to surround the preceding symbol. The whole match is
2895 ;; assumed to end directly after the opening "<".
2896 t
(if (c-lang-const c-recognize-
<>-arglists
)
2898 (c-lang-const c-symbol-key
)
2900 (c-lang-const c-syntactic-ws
)
2902 (c-lang-defvar c-opt-
<>-arglist-start
(c-lang-const c-opt-
<>-arglist-start
))
2904 (c-lang-defconst c-opt-
<>-arglist-start-in-paren
2905 ;; Regexp that in addition to `c-opt-<>-arglist-start' matches close
2906 ;; parens. The first submatch is assumed to surround
2907 ;; `c-opt-<>-arglist-start'.
2908 t
(if (c-lang-const c-opt-
<>-arglist-start
)
2910 (c-lang-const c-opt-
<>-arglist-start
)
2912 (c-lang-defvar c-opt-
<>-arglist-start-in-paren
2913 (c-lang-const c-opt-
<>-arglist-start-in-paren
))
2915 (c-lang-defconst c-opt-postfix-decl-spec-key
2916 ;; Regexp matching the beginning of a declaration specifier in the
2917 ;; region between the header and the body of a declaration.
2919 ;; TODO: This is currently not used uniformly; c++-mode and
2920 ;; java-mode each have their own ways of using it.
2923 (c-lang-const c-simple-ws
) "*"
2924 "\\(virtual" (c-lang-const c-simple-ws
) "+\\)?\\("
2925 (c-make-keywords-re nil
(c-lang-const c-protection-kwds
))
2926 "\\)" (c-lang-const c-simple-ws
) "+"
2927 "\\(" (c-lang-const c-symbol-key
) "\\)")
2928 java
(c-make-keywords-re t
(c-lang-const c-postfix-spec-kwds
)))
2929 (c-lang-defvar c-opt-postfix-decl-spec-key
2930 (c-lang-const c-opt-postfix-decl-spec-key
))
2932 (c-lang-defconst c-recognize-colon-labels
2933 "Non-nil if generic labels ending with \":\" should be recognized.
2934 That includes labels in code and access keys in classes. This does
2935 not apply to labels recognized by `c-label-kwds' and
2936 `c-opt-extra-label-key'."
2938 (c c
++ objc java pike
) t
)
2939 (c-lang-defvar c-recognize-colon-labels
2940 (c-lang-const c-recognize-colon-labels
))
2942 (c-lang-defconst c-label-prefix-re
2943 "Regexp like `c-decl-prefix-re' that matches any token that can precede
2944 a generic colon label. Not used if `c-recognize-colon-labels' is
2947 (c-lang-defvar c-label-prefix-re
2948 (c-lang-const c-label-prefix-re
))
2950 (c-lang-defconst c-nonlabel-token-key
2951 "Regexp matching things that can't occur in generic colon labels,
2952 neither in a statement nor in a declaration context. The regexp is
2953 tested at the beginning of every sexp in a suspected label,
2954 i.e. before \":\". Only used if `c-recognize-colon-labels' is set."
2956 ;; Don't allow string literals.
2958 ;; All keywords except `c-label-kwds' and `c-protection-kwds'.
2959 (c-make-keywords-re t
2960 (set-difference (c-lang-const c-keywords
)
2961 (append (c-lang-const c-label-kwds
)
2962 (c-lang-const c-protection-kwds
))
2963 :test
'string-equal
)))
2964 ;; Also check for open parens in C++, to catch member init lists in
2965 ;; constructors. We normally allow it so that macros with arguments
2967 c
++ (concat "\\s\(\\|" (c-lang-const c-nonlabel-token-key
)))
2968 (c-lang-defvar c-nonlabel-token-key
(c-lang-const c-nonlabel-token-key
))
2970 (c-lang-defconst c-opt-extra-label-key
2971 "Optional regexp matching labels.
2972 Normally, labels are detected according to `c-nonlabel-token-key',
2973 `c-decl-prefix-re' and `c-nonlabel-decl-prefix-re'. This regexp can
2974 be used if there are additional labels that aren't recognized that
2977 objc
(c-make-keywords-re t
(c-lang-const c-protection-kwds
)))
2978 (c-lang-defvar c-opt-extra-label-key
(c-lang-const c-opt-extra-label-key
))
2980 (c-lang-defconst c-opt-friend-key
2981 ;; Regexp describing friend declarations classes, or nil in
2982 ;; languages that don't have such things.
2984 ;; TODO: Ought to use `c-prefix-spec-kwds-re' or similar, and the
2985 ;; template skipping isn't done properly. This will disappear soon.
2987 c
++ (concat "friend" (c-lang-const c-simple-ws
) "+"
2990 (c-lang-const c-simple-ws
) "*"
2992 (c-lang-const c-simple-ws
) "*"
2994 (c-lang-const c-simple-ws
) "+")))
2995 (c-lang-defvar c-opt-friend-key
(c-lang-const c-opt-friend-key
))
2997 (c-lang-defconst c-opt-method-key
2998 ;; Special regexp to match the start of Objective-C methods. The
2999 ;; first submatch is assumed to end after the + or - key.
3002 ;; TODO: Ought to use a better method than anchoring on bol.
3005 (c-lang-const c-simple-ws
) "*"
3006 (concat "\\(" ; Return type.
3008 (c-lang-const c-simple-ws
) "*"
3010 "\\(" (c-lang-const c-symbol-key
) "\\)"))
3011 (c-lang-defvar c-opt-method-key
(c-lang-const c-opt-method-key
))
3013 (c-lang-defconst c-type-decl-end-used
3014 ;; Must be set in buffers where the `c-type' text property might be
3015 ;; used with the value `c-decl-end'.
3017 ;; `c-decl-end' is used to mark the ends of labels and access keys
3018 ;; to make interactive refontification work better.
3019 t
(or (c-lang-const c-recognize-colon-labels
)
3020 (and (c-lang-const c-label-kwds
) t
))
3021 ;; `c-decl-end' is used to mark the end of the @-style directives in
3024 (c-lang-defvar c-type-decl-end-used
(c-lang-const c-type-decl-end-used
))
3027 ;;; Wrap up the `c-lang-defvar' system.
3029 ;; Compile in the list of language variables that has been collected
3030 ;; with the `c-lang-defvar' and `c-lang-setvar' macros. Note that the
3031 ;; first element of each is nil.
3032 (defconst c-lang-variable-inits
(cc-eval-when-compile c-lang-variable-inits
))
3033 (defconst c-emacs-variable-inits
(cc-eval-when-compile c-emacs-variable-inits
))
3035 ;; Make the `c-lang-setvar' variables buffer local in the current buffer.
3036 ;; These are typically standard emacs variables such as `comment-start'.
3037 (defmacro c-make-emacs-variables-local
()
3039 ,@(mapcar (lambda (init)
3040 `(make-local-variable ',(car init
)))
3041 (cdr c-emacs-variable-inits
))))
3043 (defun c-make-init-lang-vars-fun (mode)
3044 "Create a function that initializes all the language dependent variables
3047 This function should be evaluated at compile time, so that the
3048 function it returns is byte compiled with all the evaluated results
3049 from the language constants. Use the `c-init-language-vars' macro to
3050 accomplish that conveniently."
3052 (if (and (not load-in-progress
)
3053 (boundp 'byte-compile-dest-file
)
3054 (stringp byte-compile-dest-file
))
3056 ;; No need to byte compile this lambda since the byte compiler is
3057 ;; smart enough to detect the `funcall' construct in the
3058 ;; `c-init-language-vars' macro below and compile it all straight
3059 ;; into the function that contains `c-init-language-vars'.
3062 ;; This let sets up the context for `c-mode-var' and similar
3063 ;; that could be in the result from `cl-macroexpand-all'.
3064 (let ((c-buffer-is-cc-mode ',mode
)
3065 current-var source-eval
)
3066 (c-make-emacs-variables-local)
3069 (if (eq c-version-sym
',c-version-sym
)
3070 (setq ,@(let ((c-buffer-is-cc-mode mode
)
3071 (c-lang-const-expansion 'immediate
))
3072 ;; `c-lang-const' will expand to the evaluated
3073 ;; constant immediately in `cl-macroexpand-all'
3077 `(current-var ',(car init
)
3078 ,(car init
) ,(cl-macroexpand-all
3080 ;; Note: The following `append' copies the
3081 ;; first argument. That list is small, so
3082 ;; this doesn't matter too much.
3083 (append (cdr c-emacs-variable-inits
)
3084 (cdr c-lang-variable-inits
)))))
3086 ;; This diagnostic message isn't useful for end
3087 ;; users, so it's disabled.
3088 ;;(unless (get ',mode 'c-has-warned-lang-consts)
3089 ;; (message ,(concat "%s compiled with CC Mode %s "
3090 ;; "but loaded with %s - evaluating "
3091 ;; "language constants from source")
3092 ;; ',mode ,c-version c-version)
3093 ;; (put ',mode 'c-has-warned-lang-consts t))
3096 (setq source-eval t
)
3097 (let ((init (append (cdr c-emacs-variable-inits
)
3098 (cdr c-lang-variable-inits
))))
3100 (setq current-var
(caar init
))
3101 (set (caar init
) (eval (cadar init
)))
3102 (setq init
(cdr init
)))))
3106 (message "Eval error in the `c-lang-defvar' or `c-lang-setvar' for `%s'%s: %S"
3110 (fallback source eval - %s compiled with CC Mode %s but loaded with %s)"
3111 ',mode
,c-version c-version
)
3114 (signal (car err
) (cdr err
)))))))
3116 ;; Being evaluated from source. Always use the dynamic method to
3117 ;; work well when `c-lang-defvar's in this file are reevaluated
3121 (let ((c-buffer-is-cc-mode ',mode
)
3122 (init (append (cdr c-emacs-variable-inits
)
3123 (cdr c-lang-variable-inits
)))
3125 (c-make-emacs-variables-local)
3129 (setq current-var
(caar init
))
3130 (set (caar init
) (eval (cadar init
)))
3131 (setq init
(cdr init
)))
3136 "Eval error in the `c-lang-defvar' or `c-lang-setver' for `%s' (source eval): %S"
3138 (signal (car err
) (cdr err
)))))))
3141 (defmacro c-init-language-vars
(mode)
3142 "Initialize all the language dependent variables for the given mode.
3143 This macro is expanded at compile time to a form tailored for the mode
3144 in question, so MODE must be a constant. Therefore MODE is not
3145 evaluated and should not be quoted."
3146 `(funcall ,(c-make-init-lang-vars-fun mode
)))
3149 (cc-provide 'cc-langs
)
3151 ;;; cc-langs.el ends here