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