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