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