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