Merge changes from emacs-23 branch.
[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-type-prefix-kwds
1569 "Keywords where the following name - if any - is a type name, and
1570 where the keyword together with the symbol works as a type in
1571 declarations.
1572
1573 Note that an alternative if the second part doesn't hold is
1574 `c-type-list-kwds'. Keywords on this list are typically also present
1575 on one of the `*-decl-kwds' lists."
1576 t nil
1577 c '("struct" "union" "enum")
1578 c++ (append '("class" "typename")
1579 (c-lang-const c-type-prefix-kwds c)))
1580
1581 (c-lang-defconst c-type-prefix-key
1582 ;; Adorned regexp matching `c-type-prefix-kwds'.
1583 t (c-make-keywords-re t (c-lang-const c-type-prefix-kwds)))
1584 (c-lang-defvar c-type-prefix-key (c-lang-const c-type-prefix-key))
1585
1586 (c-lang-defconst c-type-modifier-kwds
1587 "Type modifier keywords. These can occur almost anywhere in types
1588 but they don't build a type of themselves. Unlike the keywords on
1589 `c-primitive-type-kwds', they are fontified with the keyword face and
1590 not the type face."
1591 t nil
1592 c '("const" "restrict" "volatile")
1593 c++ '("const" "volatile" "throw")
1594 objc '("const" "volatile"))
1595
1596 (c-lang-defconst c-opt-type-modifier-key
1597 ;; Adorned regexp matching `c-type-modifier-kwds', or nil in
1598 ;; languages without such keywords.
1599 t (and (c-lang-const c-type-modifier-kwds)
1600 (c-make-keywords-re t (c-lang-const c-type-modifier-kwds))))
1601 (c-lang-defvar c-opt-type-modifier-key (c-lang-const c-opt-type-modifier-key))
1602
1603 (c-lang-defconst c-opt-type-component-key
1604 ;; An adorned regexp that matches `c-primitive-type-prefix-kwds' and
1605 ;; `c-type-modifier-kwds', or nil in languages without any of them.
1606 t (and (or (c-lang-const c-primitive-type-prefix-kwds)
1607 (c-lang-const c-type-modifier-kwds))
1608 (c-make-keywords-re t
1609 (append (c-lang-const c-primitive-type-prefix-kwds)
1610 (c-lang-const c-type-modifier-kwds)))))
1611 (c-lang-defvar c-opt-type-component-key
1612 (c-lang-const c-opt-type-component-key))
1613
1614 (c-lang-defconst c-type-start-kwds
1615 ;; All keywords that can start a type (i.e. are either a type prefix
1616 ;; or a complete type).
1617 t (delete-duplicates (append (c-lang-const c-primitive-type-kwds)
1618 (c-lang-const c-type-prefix-kwds)
1619 (c-lang-const c-type-modifier-kwds))
1620 :test 'string-equal))
1621
1622 (c-lang-defconst c-class-decl-kwds
1623 "Keywords introducing declarations where the following block (if any)
1624 contains another declaration level that should be considered a class.
1625
1626 If any of these also are on `c-type-list-kwds', `c-ref-list-kwds',
1627 `c-colon-type-list-kwds', `c-paren-nontype-kwds', `c-paren-type-kwds',
1628 `c-<>-type-kwds', or `c-<>-arglist-kwds' then the associated clauses
1629 will be handled.
1630
1631 Note that presence on this list does not automatically treat the
1632 following identifier as a type; the keyword must also be present on
1633 `c-type-prefix-kwds' or `c-type-list-kwds' to accomplish that."
1634 t nil
1635 c '("struct" "union")
1636 c++ '("class" "struct" "union")
1637 objc '("struct" "union"
1638 "@interface" "@implementation" "@protocol")
1639 java '("class" "@interface" "interface")
1640 idl '("component" "eventtype" "exception" "home" "interface" "struct"
1641 "union" "valuetype"
1642 ;; In CORBA PSDL:
1643 "storagehome" "storagetype"
1644 ;; In CORBA CIDL:
1645 "catalog" "executor" "manages" "segment")
1646 pike '("class"))
1647
1648 (c-lang-defconst c-class-key
1649 ;; Regexp matching the start of a class.
1650 t (c-make-keywords-re t (c-lang-const c-class-decl-kwds)))
1651 (c-lang-defvar c-class-key (c-lang-const c-class-key))
1652
1653 (c-lang-defconst c-brace-list-decl-kwds
1654 "Keywords introducing declarations where the following block (if
1655 any) is a brace list.
1656
1657 If any of these also are on `c-type-list-kwds', `c-ref-list-kwds',
1658 `c-colon-type-list-kwds', `c-paren-nontype-kwds', `c-paren-type-kwds',
1659 `c-<>-type-kwds', or `c-<>-arglist-kwds' then the associated clauses
1660 will be handled."
1661 t '("enum")
1662 (awk) nil)
1663
1664 (c-lang-defconst c-brace-list-key
1665 ;; Regexp matching the start of declarations where the following
1666 ;; block is a brace list.
1667 t (c-make-keywords-re t (c-lang-const c-brace-list-decl-kwds)))
1668 (c-lang-defvar c-brace-list-key (c-lang-const c-brace-list-key))
1669
1670 (c-lang-defconst c-other-block-decl-kwds
1671 "Keywords where the following block (if any) contains another
1672 declaration level that should not be considered a class. For every
1673 keyword here, CC Mode will add a set of special syntactic symbols for
1674 those blocks. E.g. if the keyword is \"foo\" then there will be
1675 `foo-open', `foo-close', and `infoo' symbols.
1676
1677 The intention is that this category should be used for block
1678 constructs that aren't related to object orientation concepts like
1679 classes (which thus also include e.g. interfaces, templates,
1680 contracts, structs, etc). The more pragmatic distinction is that
1681 while most want some indentation inside classes, it's fairly common
1682 that they don't want it in some of these constructs, so it should be
1683 simple to configure that differently from classes. See also
1684 `c-class-decl-kwds'.
1685
1686 If any of these also are on `c-type-list-kwds', `c-ref-list-kwds',
1687 `c-colon-type-list-kwds', `c-paren-nontype-kwds', `c-paren-type-kwds',
1688 `c-<>-type-kwds', or `c-<>-arglist-kwds' then the associated clauses
1689 will be handled."
1690 t nil
1691 (c objc) '("extern")
1692 c++ '("namespace" "extern")
1693 idl '("module"
1694 ;; In CORBA CIDL:
1695 "composition"))
1696
1697 (c-lang-defconst c-other-decl-block-key
1698 ;; Regexp matching the start of blocks besides classes that contain
1699 ;; another declaration level.
1700 t (c-make-keywords-re t (c-lang-const c-other-block-decl-kwds)))
1701 (c-lang-defvar c-other-decl-block-key (c-lang-const c-other-decl-block-key))
1702
1703 (c-lang-defvar c-other-decl-block-key-in-symbols-alist
1704 (mapcar
1705 (lambda (elt)
1706 (cons elt
1707 (if (string= elt "extern")
1708 'inextern-lang
1709 (intern (concat "in" elt)))))
1710 (c-lang-const c-other-block-decl-kwds))
1711 "Alist associating keywords in c-other-decl-block-decl-kwds with
1712 their matching \"in\" syntactic symbols.")
1713
1714 (c-lang-defconst c-typedef-decl-kwds
1715 "Keywords introducing declarations where the identifier(s) being
1716 declared are types.
1717
1718 If any of these also are on `c-type-list-kwds', `c-ref-list-kwds',
1719 `c-colon-type-list-kwds', `c-paren-nontype-kwds', `c-paren-type-kwds',
1720 `c-<>-type-kwds', or `c-<>-arglist-kwds' then the associated clauses
1721 will be handled."
1722 ;; Default to `c-class-decl-kwds' and `c-brace-list-decl-kwds'
1723 ;; (since e.g. "Foo" is a type that's being defined in "class Foo
1724 ;; {...}").
1725 t (append (c-lang-const c-class-decl-kwds)
1726 (c-lang-const c-brace-list-decl-kwds))
1727 ;; Languages that have a "typedef" construct.
1728 (c c++ objc idl pike) (append (c-lang-const c-typedef-decl-kwds)
1729 '("typedef"))
1730 ;; Unlike most other languages, exception names are not handled as
1731 ;; types in IDL since they only can occur in "raises" specs.
1732 idl (delete "exception" (append (c-lang-const c-typedef-decl-kwds) nil)))
1733
1734 (c-lang-defconst c-typeless-decl-kwds
1735 "Keywords introducing declarations where the \(first) identifier
1736 \(declarator) follows directly after the keyword, without any type.
1737
1738 If any of these also are on `c-type-list-kwds', `c-ref-list-kwds',
1739 `c-colon-type-list-kwds', `c-paren-nontype-kwds', `c-paren-type-kwds',
1740 `c-<>-type-kwds', or `c-<>-arglist-kwds' then the associated clauses
1741 will be handled."
1742 ;; Default to `c-class-decl-kwds' and `c-brace-list-decl-kwds'
1743 ;; (since e.g. "Foo" is the identifier being defined in "class Foo
1744 ;; {...}").
1745 t (append (c-lang-const c-class-decl-kwds)
1746 (c-lang-const c-brace-list-decl-kwds))
1747 ;; Note: "manages" for CORBA CIDL clashes with its presence on
1748 ;; `c-type-list-kwds' for IDL.
1749 idl (append (c-lang-const c-typeless-decl-kwds)
1750 '("factory" "finder" "native"
1751 ;; In CORBA PSDL:
1752 "key" "stores"
1753 ;; In CORBA CIDL:
1754 "facet"))
1755 pike (append (c-lang-const c-class-decl-kwds)
1756 '("constant")))
1757
1758 (c-lang-defconst c-modifier-kwds
1759 "Keywords that can prefix normal declarations of identifiers
1760 \(and typically act as flags). Things like argument declarations
1761 inside function headers are also considered declarations in this
1762 sense.
1763
1764 If any of these also are on `c-type-list-kwds', `c-ref-list-kwds',
1765 `c-colon-type-list-kwds', `c-paren-nontype-kwds', `c-paren-type-kwds',
1766 `c-<>-type-kwds', or `c-<>-arglist-kwds' then the associated clauses
1767 will be handled."
1768 t nil
1769 (c c++) '("auto" "extern" "inline" "register" "static")
1770 c++ (append '("explicit" "friend" "mutable" "template" "using" "virtual")
1771 (c-lang-const c-modifier-kwds))
1772 objc '("auto" "bycopy" "byref" "extern" "in" "inout" "oneway" "out" "static")
1773 ;; FIXME: Some of those below ought to be on `c-other-decl-kwds' instead.
1774 idl '("abstract" "attribute" "const" "consumes" "custom" "emits" "import"
1775 "in" "inout" "local" "multiple" "oneway" "out" "private" "provides"
1776 "public" "publishes" "readonly" "typeid" "typeprefix" "uses"
1777 ;; In CORBA PSDL:
1778 "primary" "state"
1779 ;; In CORBA CIDL:
1780 "bindsTo" "delegatesTo" "implements" "proxy" "storedOn")
1781 ;; Note: "const" is not used in Java, but it's still a reserved keyword.
1782 java '("abstract" "const" "final" "native" "private" "protected" "public"
1783 "static" "strictfp" "synchronized" "transient" "volatile" "@[A-Za-z0-9]+")
1784 pike '("final" "inline" "local" "nomask" "optional" "private" "protected"
1785 "public" "static" "variant"))
1786
1787 (c-lang-defconst c-other-decl-kwds
1788 "Keywords that can start or prefix any declaration level construct,
1789 besides those on `c-class-decl-kwds', `c-brace-list-decl-kwds',
1790 `c-other-block-decl-kwds', `c-typedef-decl-kwds',
1791 `c-typeless-decl-kwds' and `c-modifier-kwds'.
1792
1793 If any of these also are on `c-type-list-kwds', `c-ref-list-kwds',
1794 `c-colon-type-list-kwds', `c-paren-nontype-kwds', `c-paren-type-kwds',
1795 `c-<>-type-kwds', or `c-<>-arglist-kwds' then the associated clauses
1796 will be handled."
1797 t nil
1798 objc '("@class" "@end" "@defs")
1799 java '("import" "package")
1800 pike '("import" "inherit"))
1801
1802 (c-lang-defconst c-decl-start-kwds
1803 "Keywords that always start declarations, wherever they occur.
1804 This can be used for declarations that aren't recognized by the normal
1805 combination of `c-decl-prefix-re' and `c-decl-start-re'."
1806 t nil
1807 ;; Classes can be declared anywhere in a Pike expression.
1808 pike '("class"))
1809
1810 (c-lang-defconst c-decl-hangon-kwds
1811 "Keywords that can occur anywhere in a declaration level construct.
1812 This is used for self-contained things that can be tacked on anywhere
1813 on a declaration and that should be ignored to be able to recognize it
1814 correctly. Typical cases are compiler extensions like
1815 \"__attribute__\" or \"__declspec\":
1816
1817 __declspec(noreturn) void foo();
1818 class __declspec(dllexport) classname {...};
1819 void foo() __attribute__((noreturn));
1820
1821 Note that unrecognized plain symbols are skipped anyway if they occur
1822 before the type, so such things are not necessary to mention here.
1823 Mentioning them here is necessary only if they can occur in other
1824 places, or if they are followed by a construct that must be skipped
1825 over \(like the parens in the \"__attribute__\" and \"__declspec\"
1826 examples above). In the last case, they alse need to be present on
1827 one of `c-type-list-kwds', `c-ref-list-kwds',
1828 `c-colon-type-list-kwds', `c-paren-nontype-kwds', `c-paren-type-kwds',
1829 `c-<>-type-kwds', or `c-<>-arglist-kwds'."
1830 ;; NB: These are currently not recognized in all parts of a
1831 ;; declaration. Specifically, they aren't recognized in the middle
1832 ;; of multi-token types, inside declarators, and between the
1833 ;; identifier and the arglist paren of a function declaration.
1834 ;;
1835 ;; FIXME: This ought to be user customizable since compiler stuff
1836 ;; like this usually is wrapped in project specific macros. (It'd
1837 ;; of course be even better if we could cope without knowing this.)
1838 t nil
1839 (c c++) '(;; GCC extension.
1840 "__attribute__"
1841 ;; MSVC extension.
1842 "__declspec"))
1843
1844 (c-lang-defconst c-decl-hangon-key
1845 ;; Adorned regexp matching `c-decl-hangon-kwds'.
1846 t (c-make-keywords-re t (c-lang-const c-decl-hangon-kwds)))
1847 (c-lang-defvar c-decl-hangon-key (c-lang-const c-decl-hangon-key))
1848
1849 (c-lang-defconst c-prefix-spec-kwds
1850 ;; All keywords that can occur in the preamble of a declaration.
1851 ;; They typically occur before the type, but they are also matched
1852 ;; after presumptive types since we often can't be sure that
1853 ;; something is a type or just some sort of macro in front of the
1854 ;; declaration. They might be ambiguous with types or type
1855 ;; prefixes.
1856 t (delete-duplicates (append (c-lang-const c-class-decl-kwds)
1857 (c-lang-const c-brace-list-decl-kwds)
1858 (c-lang-const c-other-block-decl-kwds)
1859 (c-lang-const c-typedef-decl-kwds)
1860 (c-lang-const c-typeless-decl-kwds)
1861 (c-lang-const c-modifier-kwds)
1862 (c-lang-const c-other-decl-kwds)
1863 (c-lang-const c-decl-start-kwds)
1864 (c-lang-const c-decl-hangon-kwds))
1865 :test 'string-equal))
1866
1867 (c-lang-defconst c-prefix-spec-kwds-re
1868 ;; Adorned regexp of `c-prefix-spec-kwds'.
1869 t (c-make-keywords-re t (c-lang-const c-prefix-spec-kwds))
1870 java (replace-regexp-in-string
1871 "\\\\\\[" "["
1872 (replace-regexp-in-string "\\\\\\+" "+" (c-make-keywords-re t (c-lang-const c-prefix-spec-kwds)))))
1873
1874 (c-lang-defvar c-prefix-spec-kwds-re (c-lang-const c-prefix-spec-kwds-re))
1875
1876 (c-lang-defconst c-specifier-key
1877 ;; Adorned regexp of the keywords in `c-prefix-spec-kwds' that aren't
1878 ;; ambiguous with types or type prefixes. These are the keywords (like
1879 ;; extern, namespace, but NOT template) that can modify a declaration.
1880 t (c-make-keywords-re t
1881 (set-difference (c-lang-const c-prefix-spec-kwds)
1882 (append (c-lang-const c-type-start-kwds)
1883 (c-lang-const c-<>-arglist-kwds))
1884 :test 'string-equal)))
1885 (c-lang-defvar c-specifier-key (c-lang-const c-specifier-key))
1886
1887 (c-lang-defconst c-postfix-spec-kwds
1888 ;; Keywords that can occur after argument list of a function header
1889 ;; declaration, i.e. in the "K&R region".
1890 t (append (c-lang-const c-postfix-decl-spec-kwds)
1891 (c-lang-const c-decl-hangon-kwds)))
1892
1893 (c-lang-defconst c-not-decl-init-keywords
1894 ;; Adorned regexp matching all keywords that can't appear at the
1895 ;; start of a declaration.
1896 t (c-make-keywords-re t
1897 (set-difference (c-lang-const c-keywords)
1898 (append (c-lang-const c-type-start-kwds)
1899 (c-lang-const c-prefix-spec-kwds))
1900 :test 'string-equal)))
1901 (c-lang-defvar c-not-decl-init-keywords
1902 (c-lang-const c-not-decl-init-keywords))
1903
1904 (c-lang-defconst c-protection-kwds
1905 "Access protection label keywords in classes."
1906 t nil
1907 c++ '("private" "protected" "public")
1908 objc '("@private" "@protected" "@public"))
1909
1910 (c-lang-defconst c-block-decls-with-vars
1911 "Keywords introducing declarations that can contain a block which
1912 might be followed by variable declarations, e.g. like \"foo\" in
1913 \"class Foo { ... } foo;\". So if there is a block in a declaration
1914 like that, it ends with the following ';' and not right away.
1915
1916 The keywords on list are assumed to also be present on one of the
1917 `*-decl-kwds' lists."
1918 t nil
1919 (c objc) '("struct" "union" "enum" "typedef")
1920 c++ '("class" "struct" "union" "enum" "typedef"))
1921
1922 (c-lang-defconst c-opt-block-decls-with-vars-key
1923 ;; Regexp matching the `c-block-decls-with-vars' keywords, or nil in
1924 ;; languages without such constructs.
1925 t (and (c-lang-const c-block-decls-with-vars)
1926 (c-make-keywords-re t (c-lang-const c-block-decls-with-vars))))
1927 (c-lang-defvar c-opt-block-decls-with-vars-key
1928 (c-lang-const c-opt-block-decls-with-vars-key))
1929
1930 (c-lang-defconst c-postfix-decl-spec-kwds
1931 "Keywords introducing extra declaration specifiers in the region
1932 between the header and the body \(i.e. the \"K&R-region\") in
1933 declarations."
1934 t nil
1935 java '("extends" "implements" "throws")
1936 idl '("context" "getraises" "manages" "primarykey" "raises" "setraises"
1937 "supports"
1938 ;; In CORBA PSDL:
1939 "as" "const" "implements" "of" "ref"))
1940
1941 (c-lang-defconst c-nonsymbol-sexp-kwds
1942 "Keywords that may be followed by a nonsymbol sexp before whatever
1943 construct it's part of continues."
1944 t nil
1945 (c c++ objc) '("extern"))
1946
1947 (c-lang-defconst c-type-list-kwds
1948 "Keywords that may be followed by a comma separated list of type
1949 identifiers, where each optionally can be prefixed by keywords. (Can
1950 also be used for the special case when the list can contain only one
1951 element.)
1952
1953 Assumed to be mutually exclusive with `c-ref-list-kwds'. There's no
1954 reason to put keywords on this list if they are on `c-type-prefix-kwds'.
1955 There's also no reason to add keywords that prefixes a normal
1956 declaration consisting of a type followed by a declarator (list), so
1957 the keywords on `c-modifier-kwds' should normally not be listed here
1958 either.
1959
1960 Note: Use `c-typeless-decl-kwds' for keywords followed by a function
1961 or variable identifier (that's being defined)."
1962 t nil
1963 c++ '("operator")
1964 objc '("@class")
1965 java '("import" "new" "extends" "super" "implements" "throws")
1966 idl '("manages" "native" "primarykey" "supports"
1967 ;; In CORBA PSDL:
1968 "as" "implements" "of" "scope")
1969 pike '("inherit"))
1970
1971 (c-lang-defconst c-ref-list-kwds
1972 "Keywords that may be followed by a comma separated list of
1973 reference (i.e. namespace/scope/module) identifiers, where each
1974 optionally can be prefixed by keywords. (Can also be used for the
1975 special case when the list can contain only one element.) Assumed to
1976 be mutually exclusive with `c-type-list-kwds'.
1977
1978 Note: Use `c-typeless-decl-kwds' for keywords followed by a function
1979 or variable identifier (that's being defined)."
1980 t nil
1981 c++ '("namespace")
1982 java '("package")
1983 idl '("import" "module"
1984 ;; In CORBA CIDL:
1985 "composition")
1986 pike '("import"))
1987
1988 (c-lang-defconst c-colon-type-list-kwds
1989 "Keywords that may be followed (not necessarily directly) by a colon
1990 and then a comma separated list of type identifiers, where each
1991 optionally can be prefixed by keywords. (Can also be used for the
1992 special case when the list can contain only one element.)"
1993 t nil
1994 c++ '("class" "struct")
1995 idl '("component" "eventtype" "home" "interface" "valuetype"
1996 ;; In CORBA PSDL:
1997 "storagehome" "storagetype"))
1998
1999 (c-lang-defconst c-colon-type-list-re
2000 "Regexp matched after the keywords in `c-colon-type-list-kwds' to skip
2001 forward to the colon. The end of the match is assumed to be directly
2002 after the colon, so the regexp should end with \":\". Must be a
2003 regexp if `c-colon-type-list-kwds' isn't nil."
2004 t (if (c-lang-const c-colon-type-list-kwds)
2005 ;; Disallow various common punctuation chars that can't come
2006 ;; before the ":" that starts the inherit list after "class"
2007 ;; or "struct" in C++. (Also used as default for other
2008 ;; languages.)
2009 "[^\]\[{}();,/#=:]*:"))
2010 (c-lang-defvar c-colon-type-list-re (c-lang-const c-colon-type-list-re))
2011
2012 (c-lang-defconst c-paren-nontype-kwds
2013 "Keywords that may be followed by a parenthesis expression that doesn't
2014 contain type identifiers."
2015 t nil
2016 (c c++) '(;; GCC extension.
2017 "__attribute__"
2018 ;; MSVC extension.
2019 "__declspec"))
2020
2021 (c-lang-defconst c-paren-type-kwds
2022 "Keywords that may be followed by a parenthesis expression containing
2023 type identifiers separated by arbitrary tokens."
2024 t nil
2025 c++ '("throw")
2026 objc '("@defs")
2027 idl '("switch")
2028 pike '("array" "function" "int" "mapping" "multiset" "object" "program"))
2029
2030 (c-lang-defconst c-paren-any-kwds
2031 t (delete-duplicates (append (c-lang-const c-paren-nontype-kwds)
2032 (c-lang-const c-paren-type-kwds))
2033 :test 'string-equal))
2034
2035 (c-lang-defconst c-<>-type-kwds
2036 "Keywords that may be followed by an angle bracket expression
2037 containing type identifiers separated by \",\". The difference from
2038 `c-<>-arglist-kwds' is that unknown names are taken to be types and
2039 not other identifiers. `c-recognize-<>-arglists' is assumed to be set
2040 if this isn't nil."
2041 t nil
2042 objc '("id")
2043 idl '("sequence"
2044 ;; In CORBA PSDL:
2045 "ref"))
2046
2047 (c-lang-defconst c-<>-arglist-kwds
2048 "Keywords that can be followed by a C++ style template arglist; see
2049 `c-recognize-<>-arglists' for details. That language constant is
2050 assumed to be set if this isn't nil."
2051 t nil
2052 c++ '("template")
2053 idl '("fixed" "string" "wstring"))
2054
2055 (c-lang-defconst c-<>-sexp-kwds
2056 ;; All keywords that can be followed by an angle bracket sexp.
2057 t (delete-duplicates (append (c-lang-const c-<>-type-kwds)
2058 (c-lang-const c-<>-arglist-kwds))
2059 :test 'string-equal))
2060
2061 (c-lang-defconst c-opt-<>-sexp-key
2062 ;; Adorned regexp matching keywords that can be followed by an angle
2063 ;; bracket sexp. Always set when `c-recognize-<>-arglists' is.
2064 t (if (c-lang-const c-recognize-<>-arglists)
2065 (c-make-keywords-re t (c-lang-const c-<>-sexp-kwds))))
2066 (c-lang-defvar c-opt-<>-sexp-key (c-lang-const c-opt-<>-sexp-key))
2067
2068 (c-lang-defconst c-brace-id-list-kwds
2069 "Keywords that may be followed by a brace block containing a comma
2070 separated list of identifier definitions, i.e. like the list of
2071 identifiers that follows the type in a normal declaration."
2072 t (c-lang-const c-brace-list-decl-kwds))
2073
2074 (c-lang-defconst c-block-stmt-1-kwds
2075 "Statement keywords followed directly by a substatement."
2076 t '("do" "else")
2077 c++ '("do" "else" "try")
2078 objc '("do" "else" "@finally" "@try")
2079 java '("do" "else" "finally" "try")
2080 idl nil)
2081
2082 (c-lang-defconst c-block-stmt-1-key
2083 ;; Regexp matching the start of any statement followed directly by a
2084 ;; substatement (doesn't match a bare block, however).
2085 t (c-make-keywords-re t (c-lang-const c-block-stmt-1-kwds)))
2086 (c-lang-defvar c-block-stmt-1-key (c-lang-const c-block-stmt-1-key))
2087
2088 (c-lang-defconst c-block-stmt-2-kwds
2089 "Statement keywords followed by a paren sexp and then by a substatement."
2090 t '("for" "if" "switch" "while")
2091 c++ '("for" "if" "switch" "while" "catch")
2092 objc '("for" "if" "switch" "while" "@catch" "@synchronized")
2093 java '("for" "if" "switch" "while" "catch" "synchronized")
2094 idl nil
2095 pike '("for" "if" "switch" "while" "foreach")
2096 awk '("for" "if" "while"))
2097
2098 (c-lang-defconst c-block-stmt-2-key
2099 ;; Regexp matching the start of any statement followed by a paren sexp
2100 ;; and then by a substatement.
2101 t (c-make-keywords-re t (c-lang-const c-block-stmt-2-kwds)))
2102 (c-lang-defvar c-block-stmt-2-key (c-lang-const c-block-stmt-2-key))
2103
2104 (c-lang-defconst c-block-stmt-kwds
2105 ;; Union of `c-block-stmt-1-kwds' and `c-block-stmt-2-kwds'.
2106 t (delete-duplicates (append (c-lang-const c-block-stmt-1-kwds)
2107 (c-lang-const c-block-stmt-2-kwds))
2108 :test 'string-equal))
2109
2110 (c-lang-defconst c-opt-block-stmt-key
2111 ;; Regexp matching the start of any statement that has a
2112 ;; substatement (except a bare block). Nil in languages that
2113 ;; don't have such constructs.
2114 t (if (or (c-lang-const c-block-stmt-1-kwds)
2115 (c-lang-const c-block-stmt-2-kwds))
2116 (c-make-keywords-re t
2117 (append (c-lang-const c-block-stmt-1-kwds)
2118 (c-lang-const c-block-stmt-2-kwds)))))
2119 (c-lang-defvar c-opt-block-stmt-key (c-lang-const c-opt-block-stmt-key))
2120
2121 (c-lang-defconst c-simple-stmt-kwds
2122 "Statement keywords followed by an expression or nothing."
2123 t '("break" "continue" "goto" "return")
2124 objc '("break" "continue" "goto" "return" "@throw")
2125 ;; Note: `goto' is not valid in Java, but the keyword is still reserved.
2126 java '("break" "continue" "goto" "return" "throw")
2127 idl nil
2128 pike '("break" "continue" "return")
2129 awk '(;; Not sure about "delete", "exit", "getline", etc. ; ACM 2002/5/30
2130 "break" "continue" "return" "delete" "exit" "getline" "next"
2131 "nextfile" "print" "printf"))
2132
2133 (c-lang-defconst c-simple-stmt-key
2134 ;; Adorned regexp matching `c-simple-stmt-kwds'.
2135 t (c-make-keywords-re t (c-lang-const c-simple-stmt-kwds)))
2136 (c-lang-defvar c-simple-stmt-key (c-lang-const c-simple-stmt-key))
2137
2138 (c-lang-defconst c-paren-stmt-kwds
2139 "Statement keywords followed by a parenthesis expression that
2140 nevertheless contains a list separated with ';' and not ','."
2141 t '("for")
2142 idl nil)
2143
2144 (c-lang-defconst c-paren-stmt-key
2145 ;; Adorned regexp matching `c-paren-stmt-kwds'.
2146 t (c-make-keywords-re t (c-lang-const c-paren-stmt-kwds)))
2147 (c-lang-defvar c-paren-stmt-key (c-lang-const c-paren-stmt-key))
2148
2149 (c-lang-defconst c-asm-stmt-kwds
2150 "Statement keywords followed by an assembler expression."
2151 t nil
2152 (c c++) '("asm" "__asm__")) ;; Not standard, but common.
2153
2154 (c-lang-defconst c-opt-asm-stmt-key
2155 ;; Regexp matching the start of an assembler statement. Nil in
2156 ;; languages that don't support that.
2157 t (if (c-lang-const c-asm-stmt-kwds)
2158 (c-make-keywords-re t (c-lang-const c-asm-stmt-kwds))))
2159 (c-lang-defvar c-opt-asm-stmt-key (c-lang-const c-opt-asm-stmt-key))
2160
2161 (c-lang-defconst c-case-kwds
2162 "The keyword\(s) which introduce a \"case\" like construct.
2163 This construct is \"<keyword> <expression> :\"."
2164 t '("case")
2165 awk nil)
2166
2167 (c-lang-defconst c-case-kwds-regexp
2168 ;; Adorned regexp matching any "case"-like keyword.
2169 t (c-make-keywords-re t (c-lang-const c-case-kwds)))
2170 (c-lang-defvar c-case-kwds-regexp (c-lang-const c-case-kwds-regexp))
2171
2172 (c-lang-defconst c-label-kwds
2173 "Keywords introducing colon terminated labels in blocks."
2174 t '("case" "default")
2175 awk nil)
2176
2177 (c-lang-defconst c-label-kwds-regexp
2178 ;; Adorned regexp matching any keyword that introduces a label.
2179 t (c-make-keywords-re t (c-lang-const c-label-kwds)))
2180 (c-lang-defvar c-label-kwds-regexp (c-lang-const c-label-kwds-regexp))
2181
2182 (c-lang-defconst c-before-label-kwds
2183 "Keywords that might be followed by a label identifier."
2184 t '("goto")
2185 (java pike) (append '("break" "continue")
2186 (c-lang-const c-before-label-kwds))
2187 idl nil
2188 awk nil)
2189
2190 (c-lang-defconst c-constant-kwds
2191 "Keywords for constants."
2192 t nil
2193 (c c++) '("NULL" ;; Not a keyword, but practically works as one.
2194 "false" "true") ; Defined in C99.
2195 objc '("nil" "Nil" "YES" "NO" "NS_DURING" "NS_HANDLER" "NS_ENDHANDLER")
2196 idl '("TRUE" "FALSE")
2197 java '("true" "false" "null") ; technically "literals", not keywords
2198 pike '("UNDEFINED")) ;; Not a keyword, but practically works as one.
2199
2200 (c-lang-defconst c-primary-expr-kwds
2201 "Keywords besides constants and operators that start primary expressions."
2202 t nil
2203 c++ '("operator" "this")
2204 objc '("super" "self")
2205 java '("this")
2206 pike '("this")) ;; Not really a keyword, but practically works as one.
2207
2208 (c-lang-defconst c-expr-kwds
2209 ;; Keywords that can occur anywhere in expressions. Built from
2210 ;; `c-primary-expr-kwds' and all keyword operators in `c-operators'.
2211 t (delete-duplicates
2212 (append (c-lang-const c-primary-expr-kwds)
2213 (c-filter-ops (c-lang-const c-operator-list)
2214 t
2215 "\\`\\(\\w\\|\\s_\\)+\\'"))
2216 :test 'string-equal))
2217
2218 (c-lang-defconst c-lambda-kwds
2219 "Keywords that start lambda constructs, i.e. function definitions in
2220 expressions."
2221 t nil
2222 pike '("lambda"))
2223
2224 (c-lang-defconst c-inexpr-block-kwds
2225 "Keywords that start constructs followed by statement blocks which can
2226 be used in expressions \(the gcc extension for this in C and C++ is
2227 handled separately by `c-recognize-paren-inexpr-blocks')."
2228 t nil
2229 pike '("catch" "gauge"))
2230
2231 (c-lang-defconst c-inexpr-class-kwds
2232 "Keywords that can start classes inside expressions."
2233 t nil
2234 java '("new")
2235 pike '("class"))
2236
2237 (c-lang-defconst c-inexpr-brace-list-kwds
2238 "Keywords that can start brace list blocks inside expressions.
2239 Note that Java specific rules are currently applied to tell this from
2240 `c-inexpr-class-kwds'."
2241 t nil
2242 java '("new"))
2243
2244 (c-lang-defconst c-opt-inexpr-brace-list-key
2245 ;; Regexp matching the start of a brace list in an expression, or
2246 ;; nil in languages that don't have such things. This should not
2247 ;; match brace lists recognized through `c-special-brace-lists'.
2248 t (and (c-lang-const c-inexpr-brace-list-kwds)
2249 (c-make-keywords-re t (c-lang-const c-inexpr-brace-list-kwds))))
2250 (c-lang-defvar c-opt-inexpr-brace-list-key
2251 (c-lang-const c-opt-inexpr-brace-list-key))
2252
2253 (c-lang-defconst c-decl-block-key
2254 ;; Regexp matching keywords in any construct that contain another
2255 ;; declaration level, i.e. that isn't followed by a function block
2256 ;; or brace list. When the first submatch matches, it's an
2257 ;; unambiguous construct, otherwise it's an ambiguous match that
2258 ;; might also be the return type of a function declaration.
2259 t (let* ((decl-kwds (append (c-lang-const c-class-decl-kwds)
2260 (c-lang-const c-other-block-decl-kwds)
2261 (c-lang-const c-inexpr-class-kwds)))
2262 (unambiguous (set-difference decl-kwds
2263 (c-lang-const c-type-start-kwds)
2264 :test 'string-equal))
2265 (ambiguous (intersection decl-kwds
2266 (c-lang-const c-type-start-kwds)
2267 :test 'string-equal)))
2268 (if ambiguous
2269 (concat (c-make-keywords-re t unambiguous)
2270 "\\|"
2271 (c-make-keywords-re t ambiguous))
2272 (c-make-keywords-re t unambiguous))))
2273 (c-lang-defvar c-decl-block-key (c-lang-const c-decl-block-key))
2274
2275 (c-lang-defconst c-bitfield-kwds
2276 "Keywords that can introduce bitfields."
2277 t nil
2278 (c c++ objc) '("char" "int" "long" "signed" "unsigned"))
2279
2280 (c-lang-defconst c-opt-bitfield-key
2281 ;; Regexp matching the start of a bitfield (not uniquely), or nil in
2282 ;; languages without bitfield support.
2283 t nil
2284 (c c++) (c-make-keywords-re t (c-lang-const c-bitfield-kwds)))
2285 (c-lang-defvar c-opt-bitfield-key (c-lang-const c-opt-bitfield-key))
2286
2287 (c-lang-defconst c-other-kwds
2288 "Keywords not accounted for by any other `*-kwds' language constant."
2289 t nil
2290 idl '("truncatable"
2291 ;; In CORBA CIDL: (These are declaration keywords that never
2292 ;; can start a declaration.)
2293 "entity" "process" "service" "session" "storage"))
2294
2295 \f
2296 ;;; Constants built from keywords.
2297
2298 ;; Note: No `*-kwds' language constants may be defined below this point.
2299
2300 (eval-and-compile
2301 (defconst c-kwds-lang-consts
2302 ;; List of all the language constants that contain keyword lists.
2303 (let (list)
2304 (mapatoms (lambda (sym)
2305 (when (and (boundp sym)
2306 (string-match "-kwds\\'" (symbol-name sym)))
2307 ;; Make the list of globally interned symbols
2308 ;; instead of ones interned in `c-lang-constants'.
2309 (setq list (cons (intern (symbol-name sym)) list))))
2310 c-lang-constants)
2311 list)))
2312
2313 (c-lang-defconst c-keywords
2314 ;; All keywords as a list.
2315 t (delete-duplicates
2316 (c-lang-defconst-eval-immediately
2317 `(append ,@(mapcar (lambda (kwds-lang-const)
2318 `(c-lang-const ,kwds-lang-const))
2319 c-kwds-lang-consts)
2320 nil))
2321 :test 'string-equal))
2322
2323 (c-lang-defconst c-keywords-regexp
2324 ;; All keywords as an adorned regexp.
2325 t (c-make-keywords-re t (c-lang-const c-keywords)))
2326 (c-lang-defvar c-keywords-regexp (c-lang-const c-keywords-regexp))
2327
2328 (c-lang-defconst c-keyword-member-alist
2329 ;; An alist with all the keywords in the cars. The cdr for each
2330 ;; keyword is a list of the symbols for the `*-kwds' lists that
2331 ;; contains it.
2332 t (let ((kwd-list-alist
2333 (c-lang-defconst-eval-immediately
2334 `(list ,@(mapcar (lambda (kwds-lang-const)
2335 `(cons ',kwds-lang-const
2336 (c-lang-const ,kwds-lang-const)))
2337 c-kwds-lang-consts))))
2338 lang-const kwd-list kwd
2339 result-alist elem)
2340 (while kwd-list-alist
2341 (setq lang-const (caar kwd-list-alist)
2342 kwd-list (cdar kwd-list-alist)
2343 kwd-list-alist (cdr kwd-list-alist))
2344 (while kwd-list
2345 (setq kwd (car kwd-list)
2346 kwd-list (cdr kwd-list))
2347 (unless (setq elem (assoc kwd result-alist))
2348 (setq result-alist (cons (setq elem (list kwd)) result-alist)))
2349 (unless (memq lang-const (cdr elem))
2350 (setcdr elem (cons lang-const (cdr elem))))))
2351 result-alist))
2352
2353 (c-lang-defvar c-keywords-obarray
2354 ;; An obarray containing all keywords as symbols. The property list
2355 ;; of each symbol has a non-nil entry for the specific `*-kwds'
2356 ;; lists it's a member of.
2357 ;;
2358 ;; E.g. to see whether the string str contains a keyword on
2359 ;; `c-class-decl-kwds', one can do like this:
2360 ;; (get (intern-soft str c-keyword-obarray) 'c-class-decl-kwds)
2361 ;; Which preferably is written using the associated functions in
2362 ;; cc-engine:
2363 ;; (c-keyword-member (c-keyword-sym str) 'c-class-decl-kwds)
2364
2365 ;; The obarray is not stored directly as a language constant since
2366 ;; the printed representation for obarrays used in .elc files isn't
2367 ;; complete.
2368
2369 (let* ((alist (c-lang-const c-keyword-member-alist))
2370 kwd lang-const-list
2371 (obarray (make-vector (* (length alist) 2) 0)))
2372 (while alist
2373 (setq kwd (caar alist)
2374 lang-const-list (cdar alist)
2375 alist (cdr alist))
2376 (setplist (intern kwd obarray)
2377 ;; Emacs has an odd bug that causes `mapcan' to fail
2378 ;; with unintelligible errors. (XEmacs works.)
2379 ;;(mapcan (lambda (lang-const)
2380 ;; (list lang-const t))
2381 ;; lang-const-list)
2382 (apply 'nconc (mapcar (lambda (lang-const)
2383 (list lang-const t))
2384 lang-const-list))))
2385 obarray))
2386
2387 (c-lang-defconst c-regular-keywords-regexp
2388 ;; Adorned regexp matching all keywords that should be fontified
2389 ;; with the keywords face. I.e. that aren't types or constants.
2390 t (c-make-keywords-re t
2391 (set-difference (c-lang-const c-keywords)
2392 (append (c-lang-const c-primitive-type-kwds)
2393 (c-lang-const c-constant-kwds))
2394 :test 'string-equal)))
2395 (c-lang-defvar c-regular-keywords-regexp
2396 (c-lang-const c-regular-keywords-regexp))
2397
2398 (c-lang-defconst c-primary-expr-regexp
2399 ;; Regexp matching the start of any primary expression, i.e. any
2400 ;; literal, symbol, prefix operator, and '('. It doesn't need to
2401 ;; exclude keywords; they are excluded afterwards unless the second
2402 ;; submatch matches. If the first but not the second submatch
2403 ;; matches then it is an ambiguous primary expression; it could also
2404 ;; be a match of e.g. an infix operator. (The case with ambiguous
2405 ;; keyword operators isn't handled.)
2406
2407 t (let* ((prefix-ops
2408 (c-filter-ops (c-lang-const c-operators)
2409 '(prefix)
2410 (lambda (op)
2411 ;; Filter out the special case prefix
2412 ;; operators that are close parens.
2413 (not (string-match "\\s)" op)))))
2414
2415 (nonkeyword-prefix-ops
2416 (c-filter-ops prefix-ops
2417 t
2418 "\\`\\(\\s.\\|\\s(\\|\\s)\\)+\\'"))
2419
2420 (in-or-postfix-ops
2421 (c-filter-ops (c-lang-const c-operators)
2422 '(postfix
2423 postfix-if-paren
2424 left-assoc
2425 right-assoc
2426 right-assoc-sequence)
2427 t))
2428
2429 (unambiguous-prefix-ops (set-difference nonkeyword-prefix-ops
2430 in-or-postfix-ops
2431 :test 'string-equal))
2432 (ambiguous-prefix-ops (intersection nonkeyword-prefix-ops
2433 in-or-postfix-ops
2434 :test 'string-equal)))
2435
2436 (concat
2437 "\\("
2438 ;; Take out all symbol class operators from `prefix-ops' and make the
2439 ;; first submatch from them together with `c-primary-expr-kwds'.
2440 (c-make-keywords-re t
2441 (append (c-lang-const c-primary-expr-kwds)
2442 (set-difference prefix-ops nonkeyword-prefix-ops
2443 :test 'string-equal)))
2444
2445 "\\|"
2446 ;; Match all ambiguous operators.
2447 (c-make-keywords-re nil
2448 (intersection nonkeyword-prefix-ops in-or-postfix-ops
2449 :test 'string-equal))
2450 "\\)"
2451
2452 "\\|"
2453 ;; Now match all other symbols.
2454 (c-lang-const c-symbol-start)
2455
2456 "\\|"
2457 ;; The chars that can start integer and floating point
2458 ;; constants.
2459 "\\.?[0-9]"
2460
2461 "\\|"
2462 ;; The nonambiguous operators from `prefix-ops'.
2463 (c-make-keywords-re nil
2464 (set-difference nonkeyword-prefix-ops in-or-postfix-ops
2465 :test 'string-equal))
2466
2467 "\\|"
2468 ;; Match string and character literals.
2469 "\\s\""
2470 (if (memq 'gen-string-delim c-emacs-features)
2471 "\\|\\s|"
2472 ""))))
2473 (c-lang-defvar c-primary-expr-regexp (c-lang-const c-primary-expr-regexp))
2474
2475 \f
2476 ;;; Additional constants for parser-level constructs.
2477
2478 (c-lang-defconst c-decl-prefix-re
2479 "Regexp matching something that might precede a declaration, cast or
2480 label, such as the last token of a preceding statement or declaration.
2481 This is used in the common situation where a declaration or cast
2482 doesn't start with any specific token that can be searched for.
2483
2484 The regexp should not match bob; that is done implicitly. It can't
2485 require a match longer than one token. The end of the token is taken
2486 to be at the end of the first submatch, which is assumed to always
2487 match. It's undefined whether identifier syntax (see
2488 `c-identifier-syntax-table') is in effect or not. This regexp is
2489 assumed to be a superset of `c-label-prefix-re' if
2490 `c-recognize-colon-labels' is set.
2491
2492 Besides this, `c-decl-start-kwds' is used to find declarations.
2493
2494 Note: This variable together with `c-decl-start-re' and
2495 `c-decl-start-kwds' is only used to detect \"likely\"
2496 declaration/cast/label starts. I.e. they might produce more matches
2497 but should not miss anything (or else it's necessary to use text
2498 properties - see the next note). Wherever they match, the following
2499 construct is analyzed to see if it indeed is a declaration, cast or
2500 label. That analysis is not cheap, so it's important that not too
2501 many false matches are triggered.
2502
2503 Note: If a declaration/cast/label start can't be detected with this
2504 variable, it's necessary to use the `c-type' text property with the
2505 value `c-decl-end' on the last char of the last token preceding the
2506 declaration. See the comment blurb at the start of cc-engine.el for
2507 more info."
2508
2509 ;; We match a sequence of characters to skip over things like \"};\"
2510 ;; more quickly. We match ")" in C for K&R region declarations, and
2511 ;; in all languages except Java for when a cpp macro definition
2512 ;; begins with a declaration.
2513 t "\\([\{\}\(\);,]+\\)"
2514 java "\\([\{\}\(;,<]+\\)"
2515 ;; Match "<" in C++ to get the first argument in a template arglist.
2516 ;; In that case there's an additional check in `c-find-decl-spots'
2517 ;; that it got open paren syntax.
2518 c++ "\\([\{\}\(\);,<]+\\)"
2519 ;; Additionally match the protection directives in Objective-C.
2520 ;; Note that this doesn't cope with the longer directives, which we
2521 ;; would have to match from start to end since they don't end with
2522 ;; any easily recognized characters.
2523 objc (concat "\\([\{\}\(\);,]+\\|"
2524 (c-make-keywords-re nil (c-lang-const c-protection-kwds))
2525 "\\)")
2526 ;; Pike is like C but we also match "[" for multiple value
2527 ;; assignments and type casts.
2528 pike "\\([\{\}\(\)\[;,]+\\)")
2529 (c-lang-defvar c-decl-prefix-re (c-lang-const c-decl-prefix-re)
2530 'dont-doc)
2531
2532 (c-lang-defconst c-decl-start-re
2533 "Regexp matching the start of any declaration, cast or label.
2534 It's used on the token after the one `c-decl-prefix-re' matched. This
2535 regexp should not try to match those constructs accurately as it's
2536 only used as a sieve to avoid spending more time checking other
2537 constructs."
2538 t (c-lang-const c-identifier-start))
2539 (c-lang-defvar c-decl-start-re (c-lang-const c-decl-start-re))
2540
2541 (c-lang-defconst c-decl-prefix-or-start-re
2542 ;; Regexp matching something that might precede or start a
2543 ;; declaration, cast or label.
2544 ;;
2545 ;; If the first submatch matches, it's taken to match the end of a
2546 ;; token that might precede such a construct, e.g. ';', '}' or '{'.
2547 ;; It's built from `c-decl-prefix-re'.
2548 ;;
2549 ;; If the first submatch did not match, the match of the whole
2550 ;; regexp is taken to be at the first token in the declaration.
2551 ;; `c-decl-start-re' is not checked in this case.
2552 ;;
2553 ;; Design note: The reason the same regexp is used to match both
2554 ;; tokens that precede declarations and start them is to avoid an
2555 ;; extra regexp search from the previous declaration spot in
2556 ;; `c-find-decl-spots'. Users of `c-find-decl-spots' also count on
2557 ;; that it finds all declaration/cast/label starts in approximately
2558 ;; linear order, so we can't do the searches in two separate passes.
2559 t (if (c-lang-const c-decl-start-kwds)
2560 (concat (c-lang-const c-decl-prefix-re)
2561 "\\|"
2562 (c-make-keywords-re t (c-lang-const c-decl-start-kwds)))
2563 (c-lang-const c-decl-prefix-re)))
2564 (c-lang-defvar c-decl-prefix-or-start-re
2565 (c-lang-const c-decl-prefix-or-start-re)
2566 'dont-doc)
2567
2568 (c-lang-defconst c-cast-parens
2569 ;; List containing the paren characters that can open a cast, or nil in
2570 ;; languages without casts.
2571 t (c-filter-ops (c-lang-const c-operators)
2572 '(prefix)
2573 "\\`\\s\(\\'"
2574 (lambda (op) (elt op 0))))
2575 (c-lang-defvar c-cast-parens (c-lang-const c-cast-parens))
2576
2577 (c-lang-defconst c-block-prefix-disallowed-chars
2578 "List of syntactically relevant characters that never can occur before
2579 the open brace in any construct that contains a brace block, e.g. in
2580 the \"class Foo: public Bar\" part of:
2581
2582 class Foo: public Bar {int x();} a, *b;
2583
2584 If parens can occur, the chars inside those aren't filtered with this
2585 list.
2586
2587 '<' and '>' should be disallowed even if angle bracket arglists can
2588 occur. That since the search function needs to stop at them anyway to
2589 ensure they are given paren syntax.
2590
2591 This is used to skip backward from the open brace to find the region
2592 in which to look for a construct like \"class\", \"enum\",
2593 \"namespace\" or whatever. That skipping should be as tight as
2594 possible for good performance."
2595
2596 ;; Default to all chars that only occurs in nonsymbol tokens outside
2597 ;; identifiers.
2598 t (set-difference
2599 (c-lang-const c-nonsymbol-token-char-list)
2600 (c-filter-ops (append (c-lang-const c-identifier-ops)
2601 (list (cons nil
2602 (c-lang-const c-after-id-concat-ops))))
2603 t
2604 t
2605 (lambda (op)
2606 (let ((pos 0) res)
2607 (while (string-match "\\(\\s.\\|\\s(\\|\\s)\\)"
2608 op pos)
2609 (setq res (cons (aref op (match-beginning 1)) res)
2610 pos (match-end 0)))
2611 res))))
2612
2613 ;; Allow cpp operatios (where applicable).
2614 t (if (c-lang-const c-opt-cpp-prefix)
2615 (set-difference (c-lang-const c-block-prefix-disallowed-chars)
2616 '(?#))
2617 (c-lang-const c-block-prefix-disallowed-chars))
2618
2619 ;; Allow ':' for inherit list starters.
2620 (c++ objc idl) (set-difference (c-lang-const c-block-prefix-disallowed-chars)
2621 '(?:))
2622
2623 ;; Allow ',' for multiple inherits.
2624 (c++ java) (set-difference (c-lang-const c-block-prefix-disallowed-chars)
2625 '(?,))
2626
2627 ;; Allow parentheses for anonymous inner classes in Java and class
2628 ;; initializer lists in Pike.
2629 (java pike) (set-difference (c-lang-const c-block-prefix-disallowed-chars)
2630 '(?\( ?\)))
2631
2632 ;; Allow '"' for extern clauses (e.g. extern "C" {...}).
2633 (c c++ objc) (set-difference (c-lang-const c-block-prefix-disallowed-chars)
2634 '(?\" ?')))
2635
2636 (c-lang-defconst c-block-prefix-charset
2637 ;; `c-block-prefix-disallowed-chars' as an inverted charset suitable
2638 ;; for `c-syntactic-skip-backward'.
2639 t (c-make-bare-char-alt (c-lang-const c-block-prefix-disallowed-chars) t))
2640 (c-lang-defvar c-block-prefix-charset (c-lang-const c-block-prefix-charset))
2641
2642 (c-lang-defconst c-type-decl-prefix-key
2643 "Regexp matching the declarator operators that might precede the
2644 identifier in a declaration, e.g. the \"*\" in \"char *argv\". This
2645 regexp should match \"(\" if parentheses are valid in declarators.
2646 The end of the first submatch is taken as the end of the operator.
2647 Identifier syntax is in effect when this is matched \(see
2648 `c-identifier-syntax-table')."
2649 t (if (c-lang-const c-type-modifier-kwds)
2650 (concat (regexp-opt (c-lang-const c-type-modifier-kwds) t) "\\>")
2651 ;; Default to a regexp that never matches.
2652 "\\<\\>")
2653 ;; Check that there's no "=" afterwards to avoid matching tokens
2654 ;; like "*=".
2655 (c objc) (concat "\\("
2656 "[*\(]"
2657 "\\|"
2658 (c-lang-const c-type-decl-prefix-key)
2659 "\\)"
2660 "\\([^=]\\|$\\)")
2661 c++ (concat "\\("
2662 "[*\(&]"
2663 "\\|"
2664 (concat "\\(" ; 2
2665 ;; If this matches there's special treatment in
2666 ;; `c-font-lock-declarators' and
2667 ;; `c-font-lock-declarations' that check for a
2668 ;; complete name followed by ":: *".
2669 (c-lang-const c-identifier-start)
2670 "\\)")
2671 "\\|"
2672 (c-lang-const c-type-decl-prefix-key)
2673 "\\)"
2674 "\\([^=]\\|$\\)")
2675 pike "\\(\\*\\)\\([^=]\\|$\\)")
2676 (c-lang-defvar c-type-decl-prefix-key (c-lang-const c-type-decl-prefix-key)
2677 'dont-doc)
2678
2679 (c-lang-defconst c-type-decl-suffix-key
2680 "Regexp matching the declarator operators that might follow after the
2681 identifier in a declaration, e.g. the \"[\" in \"char argv[]\". This
2682 regexp should match \")\" if parentheses are valid in declarators. If
2683 it matches an open paren of some kind, the type declaration check
2684 continues at the corresponding close paren, otherwise the end of the
2685 first submatch is taken as the end of the operator. Identifier syntax
2686 is in effect when this is matched (see `c-identifier-syntax-table')."
2687 ;; Default to a regexp that matches `c-type-modifier-kwds' and a
2688 ;; function argument list parenthesis.
2689 t (if (c-lang-const c-type-modifier-kwds)
2690 (concat "\\(\(\\|"
2691 (regexp-opt (c-lang-const c-type-modifier-kwds) t) "\\>"
2692 "\\)")
2693 "\\(\(\\)")
2694 (c c++ objc) (concat
2695 "\\("
2696 "[\)\[\(]"
2697 (if (c-lang-const c-type-modifier-kwds)
2698 (concat
2699 "\\|"
2700 ;; "throw" in `c-type-modifier-kwds' is followed
2701 ;; by a parenthesis list, but no extra measures
2702 ;; are necessary to handle that.
2703 (regexp-opt (c-lang-const c-type-modifier-kwds) t)
2704 "\\>")
2705 "")
2706 "\\)")
2707 (java idl) "\\([\[\(]\\)")
2708 (c-lang-defvar c-type-decl-suffix-key (c-lang-const c-type-decl-suffix-key)
2709 'dont-doc)
2710
2711 (c-lang-defconst c-after-suffixed-type-decl-key
2712 "This regexp is matched after a declarator expression where
2713 `c-type-decl-suffix-key' has matched. If it matches then the
2714 construct is taken as a declaration. It's typically used to match the
2715 beginning of a function body or whatever might occur after the
2716 function header in a function declaration or definition. It's
2717 undefined whether identifier syntax (see `c-identifier-syntax-table')
2718 is in effect or not.
2719
2720 Note that it's used in cases like after \"foo (bar)\" so it should
2721 only match when it's certain that it's a declaration, e.g \"{\" but
2722 not \",\" or \";\"."
2723 t "{"
2724 ;; If K&R style declarations should be recognized then one could
2725 ;; consider to match the start of any symbol since we want to match
2726 ;; the start of the first declaration in the "K&R region". That
2727 ;; could however produce false matches on code like "FOO(bar) x"
2728 ;; where FOO is a cpp macro, so it's better to leave it out and rely
2729 ;; on the other heuristics in that case.
2730 t (if (c-lang-const c-postfix-spec-kwds)
2731 ;; Add on the keywords in `c-postfix-spec-kwds'.
2732 (concat (c-lang-const c-after-suffixed-type-decl-key)
2733 "\\|"
2734 (c-make-keywords-re t (c-lang-const c-postfix-spec-kwds)))
2735 (c-lang-const c-after-suffixed-type-decl-key))
2736 ;; Also match the colon that starts a base class initializer list in
2737 ;; C++. That can be confused with a function call before the colon
2738 ;; in a ? : operator, but we count on that `c-decl-prefix-re' won't
2739 ;; match before such a thing (as a declaration-level construct;
2740 ;; matches inside arglist contexts are already excluded).
2741 c++ "[{:]")
2742 (c-lang-defvar c-after-suffixed-type-decl-key
2743 (c-lang-const c-after-suffixed-type-decl-key)
2744 'dont-doc)
2745
2746 (c-lang-defconst c-after-suffixed-type-maybe-decl-key
2747 ;; Regexp that in addition to `c-after-suffixed-type-decl-key'
2748 ;; matches ";" and ",".
2749 t (concat "\\(" (c-lang-const c-after-suffixed-type-decl-key) "\\)"
2750 "\\|[;,]"))
2751 (c-lang-defvar c-after-suffixed-type-maybe-decl-key
2752 (c-lang-const c-after-suffixed-type-maybe-decl-key))
2753
2754 (c-lang-defconst c-opt-type-concat-key
2755 "Regexp matching operators that concatenate types, e.g. the \"|\" in
2756 \"int|string\" in Pike. The end of the first submatch is taken as the
2757 end of the operator. nil in languages without such operators. It's
2758 undefined whether identifier syntax (see `c-identifier-syntax-table')
2759 is in effect or not."
2760 t nil
2761 pike "\\([|.&]\\)\\($\\|[^|.&]\\)")
2762 (c-lang-defvar c-opt-type-concat-key (c-lang-const c-opt-type-concat-key)
2763 'dont-doc)
2764
2765 (c-lang-defconst c-opt-type-suffix-key
2766 "Regexp matching operators that might follow after a type, or nil in
2767 languages that don't have such operators. The end of the first
2768 submatch is taken as the end of the operator. This should not match
2769 things like C++ template arglists if `c-recognize-<>-arglists' is set.
2770 It's undefined whether identifier syntax (see `c-identifier-syntax-table')
2771 is in effect or not."
2772 t nil
2773 (c c++ objc pike) "\\(\\.\\.\\.\\)"
2774 java (concat "\\(\\[" (c-lang-const c-simple-ws) "*\\]\\|\\.\\.\\.\\)"))
2775 (c-lang-defvar c-opt-type-suffix-key (c-lang-const c-opt-type-suffix-key))
2776
2777 (c-lang-defvar c-known-type-key
2778 ;; Regexp matching the known type identifiers. This is initialized
2779 ;; from the type keywords and `*-font-lock-extra-types'. The first
2780 ;; submatch is the one that matches the type. Note that this regexp
2781 ;; assumes that symbol constituents like '_' and '$' have word
2782 ;; syntax.
2783 (let* ((extra-types
2784 (when (boundp (c-mode-symbol "font-lock-extra-types"))
2785 (c-mode-var "font-lock-extra-types")))
2786 (regexp-strings
2787 (apply 'nconc
2788 (mapcar (lambda (re)
2789 (when (string-match "[][.*+?^$\\]" re)
2790 (list re)))
2791 extra-types)))
2792 (plain-strings
2793 (apply 'nconc
2794 (mapcar (lambda (re)
2795 (unless (string-match "[][.*+?^$\\]" re)
2796 (list re)))
2797 extra-types))))
2798 (concat "\\<\\("
2799 (c-concat-separated
2800 (append (list (c-make-keywords-re nil
2801 (append (c-lang-const c-primitive-type-kwds)
2802 plain-strings)))
2803 regexp-strings)
2804 "\\|")
2805 "\\)\\>")))
2806
2807 (c-lang-defconst c-special-brace-lists
2808 "List of open- and close-chars that makes up a pike-style brace list,
2809 i.e. for a ([ ]) list there should be a cons (?\\[ . ?\\]) in this
2810 list."
2811 t nil
2812 pike '((?{ . ?}) (?\[ . ?\]) (?< . ?>)))
2813 (c-lang-defvar c-special-brace-lists (c-lang-const c-special-brace-lists))
2814
2815 (c-lang-defconst c-recognize-knr-p
2816 "Non-nil means K&R style argument declarations are valid."
2817 t nil
2818 c t)
2819 (c-lang-defvar c-recognize-knr-p (c-lang-const c-recognize-knr-p))
2820
2821 (c-lang-defconst c-recognize-typeless-decls
2822 "Non-nil means function declarations without return type should be
2823 recognized. That can introduce an ambiguity with parenthesized macro
2824 calls before a brace block. This setting does not affect declarations
2825 that are preceded by a declaration starting keyword, so
2826 e.g. `c-typeless-decl-kwds' may still be used when it's set to nil."
2827 t nil
2828 (c c++ objc) t)
2829 (c-lang-defvar c-recognize-typeless-decls
2830 (c-lang-const c-recognize-typeless-decls))
2831
2832 (c-lang-defconst c-recognize-<>-arglists
2833 "Non-nil means C++ style template arglists should be handled. More
2834 specifically, this means a comma separated list of types or
2835 expressions surrounded by \"<\" and \">\". It's always preceded by an
2836 identifier or one of the keywords on `c-<>-type-kwds' or
2837 `c-<>-arglist-kwds'. If there's an identifier before then the whole
2838 expression is considered to be a type."
2839 t (or (consp (c-lang-const c-<>-type-kwds))
2840 (consp (c-lang-const c-<>-arglist-kwds))))
2841 (c-lang-defvar c-recognize-<>-arglists (c-lang-const c-recognize-<>-arglists))
2842
2843 (c-lang-defconst c-recognize-paren-inits
2844 "Non-nil means that parenthesis style initializers exist,
2845 i.e. constructs like
2846
2847 Foo bar (gnu);
2848
2849 in addition to the more classic
2850
2851 Foo bar = gnu;"
2852 t nil
2853 c++ t)
2854 (c-lang-defvar c-recognize-paren-inits (c-lang-const c-recognize-paren-inits))
2855
2856 (c-lang-defconst c-recognize-paren-inexpr-blocks
2857 "Non-nil to recognize gcc style in-expression blocks,
2858 i.e. compound statements surrounded by parentheses inside expressions."
2859 t nil
2860 (c c++) t)
2861 (c-lang-defvar c-recognize-paren-inexpr-blocks
2862 (c-lang-const c-recognize-paren-inexpr-blocks))
2863
2864 (c-lang-defconst c-opt-<>-arglist-start
2865 ;; Regexp matching the start of angle bracket arglists in languages
2866 ;; where `c-recognize-<>-arglists' is set. Does not exclude
2867 ;; keywords outside `c-<>-arglist-kwds'. The first submatch is
2868 ;; assumed to surround the preceding symbol. The whole match is
2869 ;; assumed to end directly after the opening "<".
2870 t (if (c-lang-const c-recognize-<>-arglists)
2871 (concat "\\("
2872 (c-lang-const c-symbol-key)
2873 "\\)"
2874 (c-lang-const c-syntactic-ws)
2875 "<")))
2876 (c-lang-defvar c-opt-<>-arglist-start (c-lang-const c-opt-<>-arglist-start))
2877
2878 (c-lang-defconst c-opt-<>-arglist-start-in-paren
2879 ;; Regexp that in addition to `c-opt-<>-arglist-start' matches close
2880 ;; parens. The first submatch is assumed to surround
2881 ;; `c-opt-<>-arglist-start'.
2882 t (if (c-lang-const c-opt-<>-arglist-start)
2883 (concat "\\("
2884 (c-lang-const c-opt-<>-arglist-start)
2885 "\\)\\|\\s\)")))
2886 (c-lang-defvar c-opt-<>-arglist-start-in-paren
2887 (c-lang-const c-opt-<>-arglist-start-in-paren))
2888
2889 (c-lang-defconst c-opt-postfix-decl-spec-key
2890 ;; Regexp matching the beginning of a declaration specifier in the
2891 ;; region between the header and the body of a declaration.
2892 ;;
2893 ;; TODO: This is currently not used uniformly; c++-mode and
2894 ;; java-mode each have their own ways of using it.
2895 t nil
2896 c++ (concat ":?"
2897 (c-lang-const c-simple-ws) "*"
2898 "\\(virtual" (c-lang-const c-simple-ws) "+\\)?\\("
2899 (c-make-keywords-re nil (c-lang-const c-protection-kwds))
2900 "\\)" (c-lang-const c-simple-ws) "+"
2901 "\\(" (c-lang-const c-symbol-key) "\\)")
2902 java (c-make-keywords-re t (c-lang-const c-postfix-spec-kwds)))
2903 (c-lang-defvar c-opt-postfix-decl-spec-key
2904 (c-lang-const c-opt-postfix-decl-spec-key))
2905
2906 (c-lang-defconst c-recognize-colon-labels
2907 "Non-nil if generic labels ending with \":\" should be recognized.
2908 That includes labels in code and access keys in classes. This does
2909 not apply to labels recognized by `c-label-kwds' and
2910 `c-opt-extra-label-key'."
2911 t nil
2912 (c c++ objc java pike) t)
2913 (c-lang-defvar c-recognize-colon-labels
2914 (c-lang-const c-recognize-colon-labels))
2915
2916 (c-lang-defconst c-label-prefix-re
2917 "Regexp like `c-decl-prefix-re' that matches any token that can precede
2918 a generic colon label. Not used if `c-recognize-colon-labels' is
2919 nil."
2920 t "\\([{};]+\\)")
2921 (c-lang-defvar c-label-prefix-re
2922 (c-lang-const c-label-prefix-re))
2923
2924 (c-lang-defconst c-nonlabel-token-key
2925 "Regexp matching things that can't occur in generic colon labels,
2926 neither in a statement nor in a declaration context. The regexp is
2927 tested at the beginning of every sexp in a suspected label,
2928 i.e. before \":\". Only used if `c-recognize-colon-labels' is set."
2929 t (concat
2930 ;; Don't allow string literals.
2931 "\"\\|"
2932 ;; All keywords except `c-label-kwds' and `c-protection-kwds'.
2933 (c-make-keywords-re t
2934 (set-difference (c-lang-const c-keywords)
2935 (append (c-lang-const c-label-kwds)
2936 (c-lang-const c-protection-kwds))
2937 :test 'string-equal)))
2938 ;; Also check for open parens in C++, to catch member init lists in
2939 ;; constructors. We normally allow it so that macros with arguments
2940 ;; work in labels.
2941 c++ (concat "\\s\(\\|" (c-lang-const c-nonlabel-token-key)))
2942 (c-lang-defvar c-nonlabel-token-key (c-lang-const c-nonlabel-token-key))
2943
2944 (c-lang-defconst c-opt-extra-label-key
2945 "Optional regexp matching labels.
2946 Normally, labels are detected according to `c-nonlabel-token-key',
2947 `c-decl-prefix-re' and `c-nonlabel-decl-prefix-re'. This regexp can
2948 be used if there are additional labels that aren't recognized that
2949 way."
2950 t nil
2951 objc (c-make-keywords-re t (c-lang-const c-protection-kwds)))
2952 (c-lang-defvar c-opt-extra-label-key (c-lang-const c-opt-extra-label-key))
2953
2954 (c-lang-defconst c-opt-friend-key
2955 ;; Regexp describing friend declarations classes, or nil in
2956 ;; languages that don't have such things.
2957 ;;
2958 ;; TODO: Ought to use `c-prefix-spec-kwds-re' or similar, and the
2959 ;; template skipping isn't done properly. This will disappear soon.
2960 t nil
2961 c++ (concat "friend" (c-lang-const c-simple-ws) "+"
2962 "\\|"
2963 (concat "template"
2964 (c-lang-const c-simple-ws) "*"
2965 "<.+>"
2966 (c-lang-const c-simple-ws) "*"
2967 "friend"
2968 (c-lang-const c-simple-ws) "+")))
2969 (c-lang-defvar c-opt-friend-key (c-lang-const c-opt-friend-key))
2970
2971 (c-lang-defconst c-opt-method-key
2972 ;; Special regexp to match the start of Objective-C methods. The
2973 ;; first submatch is assumed to end after the + or - key.
2974 t nil
2975 objc (concat
2976 ;; TODO: Ought to use a better method than anchoring on bol.
2977 "^\\s *"
2978 "\\([+-]\\)"
2979 (c-lang-const c-simple-ws) "*"
2980 (concat "\\(" ; Return type.
2981 "([^\)]*)"
2982 (c-lang-const c-simple-ws) "*"
2983 "\\)?")
2984 "\\(" (c-lang-const c-symbol-key) "\\)"))
2985 (c-lang-defvar c-opt-method-key (c-lang-const c-opt-method-key))
2986
2987 (c-lang-defconst c-type-decl-end-used
2988 ;; Must be set in buffers where the `c-type' text property might be
2989 ;; used with the value `c-decl-end'.
2990 ;;
2991 ;; `c-decl-end' is used to mark the ends of labels and access keys
2992 ;; to make interactive refontification work better.
2993 t (or (c-lang-const c-recognize-colon-labels)
2994 (and (c-lang-const c-label-kwds) t))
2995 ;; `c-decl-end' is used to mark the end of the @-style directives in
2996 ;; Objective-C.
2997 objc t)
2998 (c-lang-defvar c-type-decl-end-used (c-lang-const c-type-decl-end-used))
2999
3000 \f
3001 ;;; Wrap up the `c-lang-defvar' system.
3002
3003 ;; Compile in the list of language variables that has been collected
3004 ;; with the `c-lang-defvar' and `c-lang-setvar' macros. Note that the
3005 ;; first element of each is nil.
3006 (defconst c-lang-variable-inits (cc-eval-when-compile c-lang-variable-inits))
3007 (defconst c-emacs-variable-inits (cc-eval-when-compile c-emacs-variable-inits))
3008
3009 ;; Make the `c-lang-setvar' variables buffer local in the current buffer.
3010 ;; These are typically standard emacs variables such as `comment-start'.
3011 (defmacro c-make-emacs-variables-local ()
3012 `(progn
3013 ,@(mapcar (lambda (init)
3014 `(make-local-variable ',(car init)))
3015 (cdr c-emacs-variable-inits))))
3016
3017 (defun c-make-init-lang-vars-fun (mode)
3018 "Create a function that initializes all the language dependent variables
3019 for the given mode.
3020
3021 This function should be evaluated at compile time, so that the
3022 function it returns is byte compiled with all the evaluated results
3023 from the language constants. Use the `c-init-language-vars' macro to
3024 accomplish that conveniently."
3025
3026 (if (and (not load-in-progress)
3027 (boundp 'byte-compile-dest-file)
3028 (stringp byte-compile-dest-file))
3029
3030 ;; No need to byte compile this lambda since the byte compiler is
3031 ;; smart enough to detect the `funcall' construct in the
3032 ;; `c-init-language-vars' macro below and compile it all straight
3033 ;; into the function that contains `c-init-language-vars'.
3034 `(lambda ()
3035
3036 ;; This let sets up the context for `c-mode-var' and similar
3037 ;; that could be in the result from `cl-macroexpand-all'.
3038 (let ((c-buffer-is-cc-mode ',mode)
3039 current-var source-eval)
3040 (c-make-emacs-variables-local)
3041 (condition-case err
3042
3043 (if (eq c-version-sym ',c-version-sym)
3044 (setq ,@(let ((c-buffer-is-cc-mode mode)
3045 (c-lang-const-expansion 'immediate))
3046 ;; `c-lang-const' will expand to the evaluated
3047 ;; constant immediately in `cl-macroexpand-all'
3048 ;; below.
3049 (mapcan
3050 (lambda (init)
3051 `(current-var ',(car init)
3052 ,(car init) ,(cl-macroexpand-all
3053 (elt init 1))))
3054 ;; Note: The following `append' copies the
3055 ;; first argument. That list is small, so
3056 ;; this doesn't matter too much.
3057 (append (cdr c-emacs-variable-inits)
3058 (cdr c-lang-variable-inits)))))
3059
3060 ;; This diagnostic message isn't useful for end
3061 ;; users, so it's disabled.
3062 ;;(unless (get ',mode 'c-has-warned-lang-consts)
3063 ;; (message ,(concat "%s compiled with CC Mode %s "
3064 ;; "but loaded with %s - evaluating "
3065 ;; "language constants from source")
3066 ;; ',mode ,c-version c-version)
3067 ;; (put ',mode 'c-has-warned-lang-consts t))
3068
3069 (require 'cc-langs)
3070 (setq source-eval t)
3071 (let ((init (append (cdr c-emacs-variable-inits)
3072 (cdr c-lang-variable-inits))))
3073 (while init
3074 (setq current-var (caar init))
3075 (set (caar init) (eval (cadar init)))
3076 (setq init (cdr init)))))
3077
3078 (error
3079 (if current-var
3080 (message "Eval error in the `c-lang-defvar' or `c-lang-setvar' for `%s'%s: %S"
3081 current-var
3082 (if source-eval
3083 (format "\
3084 (fallback source eval - %s compiled with CC Mode %s but loaded with %s)"
3085 ',mode ,c-version c-version)
3086 "")
3087 err)
3088 (signal (car err) (cdr err)))))))
3089
3090 ;; Being evaluated from source. Always use the dynamic method to
3091 ;; work well when `c-lang-defvar's in this file are reevaluated
3092 ;; interactively.
3093 `(lambda ()
3094 (require 'cc-langs)
3095 (let ((c-buffer-is-cc-mode ',mode)
3096 (init (append (cdr c-emacs-variable-inits)
3097 (cdr c-lang-variable-inits)))
3098 current-var)
3099 (c-make-emacs-variables-local)
3100 (condition-case err
3101
3102 (while init
3103 (setq current-var (caar init))
3104 (set (caar init) (eval (cadar init)))
3105 (setq init (cdr init)))
3106
3107 (error
3108 (if current-var
3109 (message
3110 "Eval error in the `c-lang-defvar' or `c-lang-setver' for `%s' (source eval): %S"
3111 current-var err)
3112 (signal (car err) (cdr err)))))))
3113 ))
3114
3115 (defmacro c-init-language-vars (mode)
3116 "Initialize all the language dependent variables for the given mode.
3117 This macro is expanded at compile time to a form tailored for the mode
3118 in question, so MODE must be a constant. Therefore MODE is not
3119 evaluated and should not be quoted."
3120 `(funcall ,(c-make-init-lang-vars-fun mode)))
3121
3122 \f
3123 (cc-provide 'cc-langs)
3124
3125 ;; arch-tag: 1ab57482-cfc2-4c5b-b628-3539c3098822
3126 ;;; cc-langs.el ends here