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