1 ;;; cc-langs.el --- language specific settings for CC Mode
3 ;; Copyright (C) 1985,1987,1992-2001 Free Software Foundation, Inc.
5 ;; Authors: 2000- Martin Stjernholm
6 ;; 1998-1999 Barry A. Warsaw and Martin Stjernholm
7 ;; 1992-1997 Barry A. Warsaw
8 ;; 1987 Dave Detlefs and Stewart Clamen
9 ;; 1985 Richard M. Stallman
10 ;; Maintainer: bug-cc-mode@gnu.org
11 ;; Created: 22-Apr-1997 (split from cc-mode.el)
12 ;; Version: See cc-mode.el
13 ;; Keywords: c languages oop
15 ;; This file is part of GNU Emacs.
17 ;; GNU Emacs is free software; you can redistribute it and/or modify
18 ;; it under the terms of the GNU General Public License as published by
19 ;; the Free Software Foundation; either version 2, or (at your option)
22 ;; GNU Emacs is distributed in the hope that it will be useful,
23 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
24 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 ;; GNU General Public License for more details.
27 ;; You should have received a copy of the GNU General Public License
28 ;; along with GNU Emacs; see the file COPYING. If not, write to
29 ;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
30 ;; Boston, MA 02111-1307, USA.
38 (if (and (boundp 'byte-compile-dest-file
)
39 (stringp byte-compile-dest-file
))
40 (cons (file-name-directory byte-compile-dest-file
) load-path
)
42 (require 'cc-bytecomp
)))
50 ;; Some support functions that are used when the language specific
51 ;; constants are built. Since the constants are built during compile
52 ;; time, these need to be defined then too.
55 ;; `require' in XEmacs doesn't have the third NOERROR argument.
56 (condition-case nil
(require 'regexp-opt
) (file-error nil
))
58 (if (fboundp 'regexp-opt
)
59 (fset 'c-regexp-opt
(symbol-function 'regexp-opt
))
60 ;; Emacs 19.34 doesn't have the regexp-opt package.
61 (defun c-regexp-opt (strings &optional paren
)
63 (concat "\\(" (mapconcat 'regexp-quote strings
"\\|") "\\)")
64 (mapconcat 'regexp-quote strings
"\\|"))))
66 (if (fboundp 'regexp-opt-depth
)
67 (fset 'c-regexp-opt-depth
(symbol-function 'regexp-opt-depth
))
68 ;; Emacs 19.34 doesn't have the regexp-opt package.
69 (defun c-regexp-opt-depth (regexp)
70 ;; This is the definition of `regexp-opt-depth' in Emacs 20.
72 ;; Hack to signal an error if REGEXP does not have balanced
74 (string-match regexp
"")
75 ;; Count the number of open parentheses in REGEXP.
76 (let ((count 0) start
)
77 (while (string-match "\\\\(" regexp start
)
78 (setq count
(1+ count
) start
(match-end 0)))
81 (defun c-make-keywords-re (adorn &rest lists
)
82 "Make a regexp that matches all the strings in all the lists.
83 Duplicates in the lists are removed. The regexp may contain zero or
84 more submatch expressions. If ADORN is non-nil there will be at least
85 one submatch which matches the whole keyword, and the regexp will also
86 not match a prefix of any identifier. Adorned regexps cannot be
88 (setq lists
(delete-duplicates (apply 'append
(nconc lists
'(nil)))
91 (let ((re (c-regexp-opt lists
)))
92 ;; Add our own grouping parenthesis around re instead of
93 ;; passing adorn to regexp-opt, since it in XEmacs makes the
94 ;; top level grouping "shy".
96 (concat "\\(" re
"\\)\\>\\([^_]\\|$\\)")
98 "\\<\\>" ; Matches nothing.
100 (put 'c-make-keywords-re
'lisp-indent-function
1)
104 ;; Building of constants that are parameterized on a per-language
108 (defvar c-macroexpand-mode nil
109 ;; Dynamically bound to the mode symbol during `c-lang-defconst'
110 ;; so that `c-lang-var' can do the right expansion.
113 (defmacro c-lang-defconst
(var &rest args
)
114 ;; Sets the mode specific values of the constant VAR. The rest of
115 ;; the arguments are one or more repetitions of MODE VAL. MODE is
116 ;; the mode name without the "-mode" suffix, or a list of such
117 ;; mode names, or `all' as a shortcut for a list of all modes.
118 ;; VAL is evaluated (during compilation) for each mode with
119 ;; `c-macroexpand-mode' temporarily bound, so `c-lang-var' without
120 ;; an explicit mode may be used within it. The assignments in
121 ;; ARGS are processed in sequence, similar to `setq'.
122 (let* ((res (list 'progn
))
125 (let ((mode (car args
)))
126 (cond ((eq mode
'all
)
127 (setq mode
'(c c
++ objc java idl pike
)))
129 (setq mode
(list mode
))))
131 (let* ((c-macroexpand-mode
132 (intern (concat (symbol-name (car mode
)) "-mode")))
133 (val (eval (car (cdr args
)))))
134 ;; Need to install the value also during compilation,
135 ;; since val might refer to earlier mode specific
137 (put var c-macroexpand-mode val
)
138 (setcdr res-tail
(list `(put ',var
',c-macroexpand-mode
',val
)))
139 (setq res-tail
(cdr res-tail
)))
140 (setq mode
(cdr mode
))))
141 (setq args
(cdr (cdr args
))))
143 (put 'c-lang-defconst
'lisp-indent-function
1)
145 (defmacro c-lang-var
(var &optional mode
)
146 ;; Get the mode specific value of the variable VAR in mode MODE.
147 ;; MODE is the mode name without the "-mode" suffix. It may also
148 ;; be nil to use the current value of `c-macroexpand-mode' (which
149 ;; is useful inside `c-lang-defconst') or `c-buffer-is-cc-mode'
150 ;; (which is useful inside `c-lang-defvar').
151 `(get ',var
,(if (eq mode
'nil
)
152 (if c-macroexpand-mode
153 ;; In the macro expansion of c-lang-defconst.
154 `(quote ,c-macroexpand-mode
)
155 `c-buffer-is-cc-mode
)
156 `(quote ,(intern (concat (symbol-name mode
) "-mode"))))))
158 ;; These are used to collect the init forms from the subsequent
159 ;; `c-lang-defvar'. They become a big setq in the
160 ;; `c-init-lang-defvars' lambda below.
161 (defconst c-lang-defvar-init-form
(list 'setq
))
162 (defconst c-lang-defvar-init-form-tail c-lang-defvar-init-form
)
164 (defmacro c-lang-defvar
(var val
)
165 ;; Declares the buffer local variable VAR to get the value VAL at
166 ;; mode initialization, at which point VAL is evaluated.
167 ;; `c-lang-var' is typically used in VAL to get the right value
168 ;; according to `c-buffer-is-cc-mode'.
169 (setcdr c-lang-defvar-init-form-tail
(list var val
))
170 (setq c-lang-defvar-init-form-tail
171 (cdr (cdr c-lang-defvar-init-form-tail
)))
174 (make-variable-buffer-local ',var
)))
175 (put 'c-lang-defvar
'lisp-indent-function
1)
178 ;; Regexp describing a `symbol' in all languages, not excluding
179 ;; keywords. We cannot use just `word' syntax class since `_' cannot
180 ;; be in word class. Putting underscore in word class breaks forward
181 ;; word movement behavior that users are familiar with. Besides, it
182 ;; runs counter to Emacs convention.
184 ;; This definition isn't correct for the first character in the
185 ;; languages that accept the full range of Unicode word constituents
186 ;; in identifiers (e.g. Java and Pike). For that we'd need to make a
187 ;; regexp that matches all characters in the word constituent class
188 ;; except 0-9, and the regexp engine currently can't do that.
189 (c-lang-defconst c-symbol-key
190 (c c
++ objc java idl
) "[_a-zA-Z]\\(\\w\\|\\s_\\)*"
191 pike
(concat "\\(" (c-lang-var c-symbol-key c
) "\\|"
192 (c-make-keywords-re nil
193 '("`+" "`-" "`&" "`|" "`^" "`<<" "`>>" "`*" "`/" "`%" "`~"
194 "`==" "`<" "`>" "`!" "`[]" "`[]=" "`->" "`->=" "`()" "``+"
195 "``-" "``&" "``|" "``^" "``<<" "``>>" "``*" "``/" "``%"
198 (c-lang-defvar c-symbol-key
(c-lang-var c-symbol-key
))
200 ;; Number of regexp grouping parens in c-symbol-key.
201 (c-lang-defvar c-symbol-key-depth
(c-regexp-opt-depth c-symbol-key
))
203 (defvar c-stmt-delim-chars
"^;{}?:")
204 ;; The characters that should be considered to bound statements. To
205 ;; optimize c-crosses-statement-barrier-p somewhat, it's assumed to
206 ;; begin with "^" to negate the set. If ? : operators should be
207 ;; detected then the string must end with "?:".
209 (defvar c-stmt-delim-chars-with-comma
"^;,{}?:")
210 ;; Variant of c-stmt-delim-chars that additionally contains ','.
212 ;; HELPME: Many of the following keyword lists are more or less bogus
213 ;; for some languages (notably ObjC and IDL). The effects of the
214 ;; erroneous values in the language handling are mostly negligible
215 ;; since the constants that actually matter in the syntax detection
216 ;; code are mostly correct in the situations they are used, but I'd
217 ;; still appreciate help to get them correct for other uses.
219 ;; Primitive type keywords.
220 (c-lang-defconst c-primitive-type-kwds
221 (c c
++ objc idl
) '("char" "double" "float" "int" "long" "short"
222 "signed" "unsigned" "void")
223 java
'("boolean" "byte" "char" "double" "float" "int" "long" "short" "void")
224 pike
'("constant" "float" "int" "mapping" "multiset" "object" "program"
227 ;; Declaration specifier keywords.
228 (c-lang-defconst c-specifier-kwds
229 c
'("auto" "const" "extern" "register" "static" "volatile")
230 (c++ objc idl
) (append '("friend" "inline" "virtual")
231 (c-lang-var c-specifier-kwds c
))
232 ;; Note: `const' is not used in Java, but it's still a reserved keyword.
233 java
'("abstract" "const" "final" "native" "private" "protected"
234 "public" "static" "synchronized" "transient" "volatile")
235 pike
'("final" "inline" "local" "nomask" "optional" "private"
236 "protected" "static" "variant"))
238 ;; Class/struct declaration keywords.
239 (c-lang-defconst c-class-kwds
240 c
'("struct" "union")
241 c
++ '("class" "struct" "union")
242 objc
'("interface" "implementation")
243 java
'("class" "interface")
244 idl
'("interface" "valuetype" "class" "struct" "union")
247 ;; Regexp matching the start of a class.
248 (c-lang-defconst c-class-key
249 all
(c-make-keywords-re t
(c-lang-var c-class-kwds
)))
250 (c-lang-defconst c-class-key
; ObjC needs some tuning of the regexp.
251 objc
(concat "@" (c-lang-var c-class-key
)))
252 (c-lang-defvar c-class-key
(c-lang-var c-class-key
))
254 ;; Keywords introducing blocks besides classes that contain another
255 ;; declaration level.
256 (c-lang-defconst c-other-decl-block-kwds
258 c
++ '("namespace" "extern")
261 ;; Regexp matching the start of blocks besides classes that contain
262 ;; another declaration level.
263 (c-lang-defconst c-other-decl-block-key
264 all
(c-make-keywords-re t
(c-lang-var c-other-decl-block-kwds
)))
265 (c-lang-defvar c-other-decl-block-key
(c-lang-var c-other-decl-block-key
))
267 ;; Keywords introducing declarations that can contain a block which
268 ;; might be followed by variable declarations, e.g. like "foo" in
269 ;; "class Foo { ... } foo;". So if there is a block in a declaration
270 ;; like that, it ends with the following ';' and not right away.
271 (c-lang-defconst c-block-decls-with-vars
272 c
'("struct" "union" "enum" "typedef")
273 c
++ '("class" "struct" "union" "enum" "typedef"))
275 ;; Regexp matching the `c-block-decls-with-vars' keywords, or nil in
276 ;; languages without such constructs.
277 (c-lang-defconst c-opt-block-decls-with-vars-key
278 all
(and (c-lang-var c-block-decls-with-vars
)
279 (c-make-keywords-re t
(c-lang-var c-block-decls-with-vars
))))
280 (c-lang-defvar c-opt-block-decls-with-vars-key
281 (c-lang-var c-opt-block-decls-with-vars-key
))
283 ;; Keywords introducing declarations that has not been accounted for
284 ;; by any of the above.
285 (c-lang-defconst c-other-decl-kwds
286 ;; FIXME: Shouldn't "template" be moved to c-specifier-kwds for C++?
288 java
'("import" "package")
289 pike
'("import" "inherit"))
291 ;; Keywords introducing extra declaration specifiers in the region
292 ;; between the header and the body (i.e. the "K&R-region") in
294 (c-lang-defconst c-decl-spec-kwds java
'("extends" "implements" "throws"))
296 ;; Protection label keywords in classes.
297 (c-lang-defconst c-protection-kwds
298 (c++ objc
) '("private" "protected" "public"))
300 ;; Statement keywords followed directly by a substatement.
301 (c-lang-defconst c-block-stmt-1-kwds
302 (c pike
) '("do" "else")
303 (c++ objc
) '("do" "else" "asm" "try")
304 java
'("do" "else" "finally" "try"))
306 ;; Regexp matching the start of any statement followed directly by a
307 ;; substatement (doesn't match a bare block, however).
308 (c-lang-defconst c-block-stmt-1-key
309 all
(c-make-keywords-re t
(c-lang-var c-block-stmt-1-kwds
)))
310 (c-lang-defvar c-block-stmt-1-key
(c-lang-var c-block-stmt-1-key
))
312 ;; Statement keywords followed by a paren sexp and then by a substatement.
313 (c-lang-defconst c-block-stmt-2-kwds
314 c
'("for" "if" "switch" "while")
315 (c++ objc
) '("for" "if" "switch" "while" "catch")
316 java
'("for" "if" "switch" "while" "catch" "synchronized")
317 pike
'("for" "if" "switch" "while" "foreach"))
319 ;; Regexp matching the start of any statement followed by a paren sexp
320 ;; and then by a substatement.
321 (c-lang-defconst c-block-stmt-2-key
322 all
(c-make-keywords-re t
(c-lang-var c-block-stmt-2-kwds
)))
323 (c-lang-defvar c-block-stmt-2-key
(c-lang-var c-block-stmt-2-key
))
325 ;; Regexp matching the start of any statement that has a substatement
326 ;; (except a bare block). Nil in languages that doesn't have such
328 (c-lang-defconst c-opt-block-stmt-key
329 all
(if (or (c-lang-var c-block-stmt-1-kwds
)
330 (c-lang-var c-block-stmt-2-kwds
))
331 (c-make-keywords-re t
332 (c-lang-var c-block-stmt-1-kwds
)
333 (c-lang-var c-block-stmt-2-kwds
))))
334 (c-lang-defvar c-opt-block-stmt-key
(c-lang-var c-opt-block-stmt-key
))
336 ;; Statement keywords followed by an expression or nothing.
337 (c-lang-defconst c-simple-stmt-kwds
338 (c c
++ objc
) '("break" "continue" "goto" "return")
339 ;; Note: `goto' is not valid in Java, but the keyword is still reserved.
340 java
'("break" "continue" "goto" "return" "throw")
341 pike
'("break" "continue" "return"))
343 ;; Statement keywords followed by an assembler expression.
344 (c-lang-defconst c-asm-stmt-kwds
345 (c c
++) '("asm" "__asm__"))
347 ;; Regexp matching the start of an assembler statement. Nil in
348 ;; languages that doesn't support that.
349 (c-lang-defconst c-opt-asm-stmt-key
350 all
(if (c-lang-var c-asm-stmt-kwds
)
351 (c-make-keywords-re t
(c-lang-var c-asm-stmt-kwds
))))
352 (c-lang-defvar c-opt-asm-stmt-key
(c-lang-var c-opt-asm-stmt-key
))
354 ;; Keywords introducing labels in blocks.
355 (c-lang-defconst c-label-kwds
(c c
++ objc java pike
) '("case" "default"))
357 ;; Regexp matching any keyword that introduces a label.
358 (c-lang-defconst c-label-kwds-regexp
359 all
(c-make-keywords-re t
(c-lang-var c-label-kwds
)))
360 (c-lang-defvar c-label-kwds-regexp
(c-lang-var c-label-kwds-regexp
))
362 ;; Keywords that can occur anywhere in expressions.
363 (c-lang-defconst c-expr-kwds
365 c
++ '("sizeof" "delete" "new" "operator" "this" "throw")
366 java
'("instanceof" "new" "super" "this")
367 pike
'("sizeof" "catch" "class" "gauge" "lambda" "predef"))
369 ;; Keywords that start lambda constructs, i.e. function definitions in
371 (c-lang-defconst c-lambda-kwds pike
'("lambda"))
373 ;; Regexp matching the start of lambda constructs, or nil in languages
374 ;; that doesn't have such things.
375 (c-lang-defconst c-opt-lambda-key
376 pike
(c-make-keywords-re t
(c-lang-var c-lambda-kwds
)))
377 (c-lang-defvar c-opt-lambda-key
(c-lang-var c-opt-lambda-key
))
379 ;; Keywords that start constructs followed by statement blocks which
380 ;; can be used in expressions (the gcc extension for this in C and C++
381 ;; is handled separately).
382 (c-lang-defconst c-inexpr-block-kwds pike
'("catch" "gauge"))
384 ;; Regexp matching the start of in-expression statements, or nil in
385 ;; languages that doesn't have such things.
386 (c-lang-defconst c-opt-inexpr-block-key
387 pike
(c-make-keywords-re t
(c-lang-var c-inexpr-block-kwds
)))
388 (c-lang-defvar c-opt-inexpr-block-key
(c-lang-var c-opt-inexpr-block-key
))
390 ;; Keywords that start classes in expressions.
391 (c-lang-defconst c-inexpr-class-kwds
395 ;; Regexp matching the start of a class in an expression, or nil in
396 ;; languages that doesn't have such things.
397 (c-lang-defconst c-opt-inexpr-class-key
398 (java pike
) (c-make-keywords-re t
(c-lang-var c-inexpr-class-kwds
)))
399 (c-lang-defvar c-opt-inexpr-class-key
(c-lang-var c-opt-inexpr-class-key
))
401 ;; Regexp matching the start of any class, both at top level and in
403 (c-lang-defconst c-any-class-key
404 all
(c-make-keywords-re t
405 (c-lang-var c-class-kwds
)
406 (c-lang-var c-inexpr-class-kwds
)))
407 (c-lang-defconst c-any-class-key
; ObjC needs some tuning of the regexp.
408 objc
(concat "@" (c-lang-var c-any-class-key
)))
409 (c-lang-defvar c-any-class-key
(c-lang-var c-any-class-key
))
411 ;; Regexp matching the start of any declaration-level block that
412 ;; contain another declaration level, i.e. that isn't a function
414 (c-lang-defconst c-decl-block-key
415 all
(c-make-keywords-re t
416 (c-lang-var c-class-kwds
)
417 (c-lang-var c-other-decl-block-kwds
)
418 (c-lang-var c-inexpr-class-kwds
)))
419 (c-lang-defconst c-decl-block-key
; ObjC needs some tuning of the regexp.
420 objc
(concat "@" (c-lang-var c-decl-block-key
)))
421 (c-lang-defvar c-decl-block-key
(c-lang-var c-decl-block-key
))
423 ;; Keywords that can introduce bitfields.
424 (c-lang-defconst c-bitfield-kwds
425 (c c
++) '("char" "int" "long" "signed" "unsigned"))
427 ;; Regexp matching the start of a bitfield (not uniquely), or nil in
428 ;; languages without bitfield support.
429 (c-lang-defconst c-opt-bitfield-key
430 (c c
++) (c-make-keywords-re t
(c-lang-var c-bitfield-kwds
)))
431 (c-lang-defvar c-opt-bitfield-key
(c-lang-var c-opt-bitfield-key
))
433 ;; All keywords as a list.
434 (c-lang-defconst c-keywords
435 all
(delete-duplicates (append (c-lang-var c-primitive-type-kwds
)
436 (c-lang-var c-specifier-kwds
)
437 (c-lang-var c-class-kwds
)
438 (c-lang-var c-other-decl-block-kwds
)
439 (c-lang-var c-block-decls-with-vars
)
440 (c-lang-var c-other-decl-kwds
)
441 (c-lang-var c-decl-spec-kwds
)
442 (c-lang-var c-protection-kwds
)
443 (c-lang-var c-block-stmt-1-kwds
)
444 (c-lang-var c-block-stmt-2-kwds
)
445 (c-lang-var c-simple-stmt-kwds
)
446 (c-lang-var c-asm-stmt-kwds
)
447 (c-lang-var c-label-kwds
)
448 (c-lang-var c-expr-kwds
)
449 (c-lang-var c-lambda-kwds
)
450 (c-lang-var c-inexpr-block-kwds
)
451 (c-lang-var c-inexpr-class-kwds
)
452 (c-lang-var c-bitfield-kwds
)
454 :test
'string-equal
))
455 (c-lang-defvar c-keywords
(c-lang-var c-keywords
))
457 ;; All keywords as an adorned regexp.
458 (c-lang-defconst c-keywords-regexp
459 all
(c-make-keywords-re t
(c-lang-var c-keywords
)))
460 (c-lang-defvar c-keywords-regexp
(c-lang-var c-keywords-regexp
))
462 ;; Regexp matching an access protection label in a class, or nil in
463 ;; languages that doesn't have such things.
464 (c-lang-defconst c-opt-access-key
466 (c-make-keywords-re nil
(c-lang-var c-protection-kwds
))
468 (c-lang-defconst c-opt-access-key
469 objc
(concat "@" (c-make-keywords-re t
(c-lang-var c-protection-kwds
))))
470 (c-lang-defvar c-opt-access-key
(c-lang-var c-opt-access-key
))
472 ;; Regexp matching a normal label, i.e. not a label that's recognized
473 ;; with a keyword, like switch labels. It's only used at the
474 ;; beginning of a statement.
475 (c-lang-defconst c-label-key
476 all
(concat (c-lang-var c-symbol-key
) "[ \t\n\r]*:\\([^:]\\|$\\)"))
477 (c-lang-defvar c-label-key
(c-lang-var c-label-key
))
479 ;; Regexp matching the beginning of a declaration specifier in the
480 ;; region between the header and the body of a declaration.
482 ;; FIXME: This is currently not used in a uniformly; c++-mode and
483 ;; java-mode each have their own ways of using it.
484 (c-lang-defconst c-opt-decl-spec-key
485 c
++ (concat ":?[ \t\n\r]*\\(virtual[ \t\n\r]+\\)?\\("
486 (c-make-keywords-re nil
(c-lang-var c-protection-kwds
))
488 (c-lang-var c-symbol-key
))
489 java
(c-make-keywords-re t
(c-lang-var c-decl-spec-kwds
)))
490 (c-lang-defvar c-opt-decl-spec-key
(c-lang-var c-opt-decl-spec-key
))
492 ;; Regexp describing friend declarations classes, or nil in languages
493 ;; that doesn't have such things.
494 (c-lang-defconst c-opt-friend-key
495 ;; FIXME: Ought to use c-specifier-kwds or similar, and the template
496 ;; skipping isn't done properly.
497 c
++ "friend[ \t]+\\|template[ \t]*<.+>[ \t]*friend[ \t]+")
498 (c-lang-defvar c-opt-friend-key
(c-lang-var c-opt-friend-key
))
500 ;; Special regexp to match the start of methods.
501 (c-lang-defconst c-opt-method-key
504 "\\(([^)]*)\\)?" ; return type
505 ;; \\s- in objc syntax table does not include \n
506 ;; since it is considered the end of //-comments.
507 "[ \t\n]*" (c-lang-var c-symbol-key
)))
508 (c-lang-defvar c-opt-method-key
(c-lang-var c-opt-method-key
))
510 ;; Name of functions in cpp expressions that take an identifier as the
512 (c-lang-defconst c-cpp-defined-fns
514 pike
'("defined" "efun" "constant"))
516 ;; List of open- and close-chars that makes up a pike-style brace
517 ;; list, i.e. for a `([ ])' list there should be a cons (?\[ . ?\]) in
519 (c-lang-defconst c-special-brace-lists pike
'((?
{ . ?
})
522 (c-lang-defvar c-special-brace-lists
(c-lang-var c-special-brace-lists
))
524 ;; Non-nil means K&R style argument declarations are valid.
525 (c-lang-defconst c-recognize-knr-p c t
)
526 (c-lang-defvar c-recognize-knr-p
(c-lang-var c-recognize-knr-p
))
528 ;; Regexp to match the start of any type of comment.
530 ;; FIXME: Ought to use c-comment-prefix-regexp with some modifications
532 (c-lang-defconst c-comment-start-regexp
533 (c c
++ objc idl pike
) "/[/*]"
534 ;; We need to match all 3 Java style comments
535 ;; 1) Traditional C block; 2) javadoc /** ...; 3) C++ style
536 java
"/\\(/\\|[*][*]?\\)")
537 (c-lang-defvar c-comment-start-regexp
(c-lang-var c-comment-start-regexp
))
539 ;; Strings that starts and ends comments inserted with M-; etc.
540 ;; comment-start and comment-end are initialized from these.
541 (c-lang-defconst comment-start
543 (c++ objc java idl pike
) "// ")
544 (c-lang-defvar comment-start
(c-lang-var comment-start
))
545 (c-lang-defconst comment-end
547 (c++ objc java idl pike
) "")
548 (c-lang-defvar comment-end
(c-lang-var comment-end
))
550 ;; Regexp that matches when there is no syntactically significant text
551 ;; before eol. Macros are regarded as syntactically significant text
553 (c-lang-defvar c-syntactic-eol
555 ;; Match horizontal whitespace and block comments that
556 ;; doesn't contain newlines.
559 "\\([^*\n\r]\\|\\*[^/\n\r]\\)*"
563 ;; Match eol (possibly inside a block comment), or the
564 ;; beginning of a line comment. Note: This has to be
565 ;; modified for awk where line comments start with '#'.
568 "/\\*\\([^*\n\r]\\|\\*[^/\n\r]\\)*"
573 ;; Regexp to append to paragraph-start.
574 (c-lang-defconst paragraph-start
576 java
"\\(@[a-zA-Z]+\\>\\|$\\)" ; For Javadoc.
577 pike
"\\(@[a-zA-Z]+\\>\\([^{]\\|$\\)\\|$\\)") ; For Pike refdoc.
579 ;; Regexp to append to paragraph-separate.
580 (c-lang-defconst paragraph-separate
581 (c c
++ objc java idl
) "$"
582 pike
(c-lang-var paragraph-start
))
584 ;; Prefix added to `c-current-comment-prefix' to set
585 ;; `c-opt-in-comment-lc', or nil if it should be nil.
586 (c-lang-defconst c-in-comment-lc-prefix pike
"@[\n\r]\\s *")
588 ;; Regexp to match in-comment line continuations, or nil in languages
589 ;; where that isn't applicable. It's assumed that it only might match
590 ;; from and including the last character on a line. Built from
591 ;; *-in-comment-lc-prefix and the current value of
592 ;; c-current-comment-prefix.
593 (c-lang-defvar c-opt-in-comment-lc
594 (if (c-lang-var c-in-comment-lc-prefix
)
595 (concat (c-lang-var c-in-comment-lc-prefix
)
596 c-current-comment-prefix
)))
598 (defconst c-init-lang-defvars
599 ;; Make a lambda of the collected `c-lang-defvar' initializations.
600 (cc-eval-when-compile
601 (if (cc-bytecomp-is-compiling)
602 (byte-compile-lambda `(lambda () ,c-lang-defvar-init-form
))
603 `(lambda () ,c-lang-defvar-init-form
))))
605 (defun c-init-language-vars ()
606 ;; Initialize all `c-lang-defvar' variables according to
607 ;; `c-buffer-is-cc-mode'.
608 (if (not (memq c-buffer-is-cc-mode
609 '(c-mode c
++-mode objc-mode java-mode idl-mode pike-mode
)))
610 (error "Cannot initialize language variables for unknown mode %s"
611 c-buffer-is-cc-mode
))
612 (funcall c-init-lang-defvars
))
614 ;; Regexp trying to describe the beginning of a Java top-level
615 ;; definition. This is not used by CC Mode, nor is it maintained
616 ;; since it's practically impossible to write a regexp that reliably
617 ;; matches such a construct. Other tools are necessary.
618 (defconst c-Java-defun-prompt-regexp
619 "^[ \t]*\\(\\(\\(public\\|protected\\|private\\|const\\|abstract\\|synchronized\\|final\\|static\\|threadsafe\\|transient\\|native\\|volatile\\)\\s-+\\)*\\(\\(\\([[a-zA-Z][][_$.a-zA-Z0-9]*[][_$.a-zA-Z0-9]+\\|[[a-zA-Z]\\)\\s-*\\)\\s-+\\)\\)?\\(\\([[a-zA-Z][][_$.a-zA-Z0-9]*\\s-+\\)\\s-*\\)?\\([_a-zA-Z][^][ \t:;.,{}()\x7f=]*\\|\\([_$a-zA-Z][_$.a-zA-Z0-9]*\\)\\)\\s-*\\(([^);{}]*)\\)?\\([] \t]*\\)\\(\\s-*\\<throws\\>\\s-*\\(\\([_$a-zA-Z][_$.a-zA-Z0-9]*\\)[, \t\n\r\f]*\\)+\\)?\\s-*")
624 (defun c-populate-syntax-table (table)
625 ;; Populate the syntax TABLE
626 (modify-syntax-entry ?_
"_" table
)
627 (modify-syntax-entry ?
\\ "\\" table
)
628 (modify-syntax-entry ?
+ "." table
)
629 (modify-syntax-entry ?-
"." table
)
630 (modify-syntax-entry ?
= "." table
)
631 (modify-syntax-entry ?%
"." table
)
632 (modify-syntax-entry ?
< "." table
)
633 (modify-syntax-entry ?
> "." table
)
634 (modify-syntax-entry ?
& "." table
)
635 (modify-syntax-entry ?|
"." table
)
636 (modify-syntax-entry ?
\' "\"" table
)
637 ;; Set up block and line oriented comments. The new C standard
638 ;; mandates both comment styles even in C, so since all languages
639 ;; now require dual comments, we make this the default.
642 ((memq '8-bit c-emacs-features
)
643 (modify-syntax-entry ?
/ ". 1456" table
)
644 (modify-syntax-entry ?
* ". 23" table
))
646 ((memq '1-bit c-emacs-features
)
647 (modify-syntax-entry ?
/ ". 124b" table
)
648 (modify-syntax-entry ?
* ". 23" table
))
650 (t (error "CC Mode is incompatible with this version of Emacs"))
652 (modify-syntax-entry ?
\n "> b" table
)
653 ;; Give CR the same syntax as newline, for selective-display
654 (modify-syntax-entry ?\^m
"> b" table
))
657 (defvar c-mode-syntax-table nil
658 "Syntax table used in c-mode buffers.")
659 (if c-mode-syntax-table
661 (setq c-mode-syntax-table
(make-syntax-table))
662 (c-populate-syntax-table c-mode-syntax-table
))
665 (defvar c
++-mode-syntax-table nil
666 "Syntax table used in c++-mode buffers.")
667 (if c
++-mode-syntax-table
669 (setq c
++-mode-syntax-table
(make-syntax-table))
670 (c-populate-syntax-table c
++-mode-syntax-table
))
672 (defvar c
++-template-syntax-table nil
673 "A variant of `c++-mode-syntax-table' that defines `<' and `>' as
674 parenthesis characters. Used temporarily when template argument lists
676 (if c
++-template-syntax-table
678 (setq c
++-template-syntax-table
679 (copy-syntax-table c
++-mode-syntax-table
))
680 (modify-syntax-entry ?
< "(>" c
++-template-syntax-table
)
681 (modify-syntax-entry ?
> ")<" c
++-template-syntax-table
))
684 (defvar objc-mode-syntax-table nil
685 "Syntax table used in objc-mode buffers.")
686 (if objc-mode-syntax-table
688 (setq objc-mode-syntax-table
(make-syntax-table))
689 (c-populate-syntax-table objc-mode-syntax-table
)
690 ;; add extra Objective-C only syntax
691 (modify-syntax-entry ?
@ "_" objc-mode-syntax-table
))
694 (defvar java-mode-syntax-table nil
695 "Syntax table used in java-mode buffers.")
696 (if java-mode-syntax-table
698 (setq java-mode-syntax-table
(make-syntax-table))
699 (c-populate-syntax-table java-mode-syntax-table
))
702 (defvar idl-mode-syntax-table nil
703 "Syntax table used in idl-mode buffers.")
704 (if idl-mode-syntax-table
706 (setq idl-mode-syntax-table
(make-syntax-table))
707 (c-populate-syntax-table idl-mode-syntax-table
))
710 (defvar pike-mode-syntax-table nil
711 "Syntax table used in pike-mode buffers.")
712 (if pike-mode-syntax-table
714 (setq pike-mode-syntax-table
(make-syntax-table))
715 (c-populate-syntax-table pike-mode-syntax-table
)
716 (modify-syntax-entry ?
@ "." pike-mode-syntax-table
))
719 ;; internal state variables
721 ;; Internal state of hungry delete key feature
722 (defvar c-hungry-delete-key nil
)
723 (make-variable-buffer-local 'c-hungry-delete-key
)
725 ;; Internal state of auto newline feature.
726 (defvar c-auto-newline nil
)
727 (make-variable-buffer-local 'c-auto-newline
)
729 ;; Internal auto-newline/hungry-delete designation string for mode line.
730 (defvar c-auto-hungry-string nil
)
731 (make-variable-buffer-local 'c-auto-hungry-string
)
734 (cc-provide 'cc-langs
)
736 ;;; cc-langs.el ends here