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