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