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