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