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