*** empty log message ***
[emacs.git] / lisp / progmodes / cc-langs.el
blobc9fb45d1d8ac201c3d09ec1dca36d6860d32c42d
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)
20 ;; any later version.
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.
32 ;;; Commentary:
34 ;;; Code:
36 (eval-when-compile
37 (let ((load-path
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)
41 load-path)))
42 (require 'cc-bytecomp)))
44 (cc-require 'cc-defs)
45 (cc-require 'cc-vars)
48 ;; Some support functions that are used when the language specific
49 ;; constants are built. Since the constants are built during compile
50 ;; time, these need to be defined then too.
52 (eval-and-compile
53 ;; `require' in XEmacs doesn't have the third NOERROR argument.
54 (condition-case nil (require 'regexp-opt) (file-error nil))
56 (if (fboundp 'regexp-opt)
57 (fset 'c-regexp-opt (symbol-function 'regexp-opt))
58 ;; Emacs 19.34 doesn't have the regexp-opt package.
59 (defun c-regexp-opt (strings &optional paren)
60 (if paren
61 (concat "\\(" (mapconcat 'regexp-quote strings "\\|") "\\)")
62 (mapconcat 'regexp-quote strings "\\|"))))
64 (if (fboundp 'regexp-opt-depth)
65 (fset 'c-regexp-opt-depth (symbol-function 'regexp-opt-depth))
66 ;; Emacs 19.34 doesn't have the regexp-opt package.
67 (defun c-regexp-opt-depth (regexp)
68 ;; This is the definition of `regexp-opt-depth' in Emacs 20.
69 (save-match-data
70 ;; Hack to signal an error if REGEXP does not have balanced
71 ;; parentheses.
72 (string-match regexp "")
73 ;; Count the number of open parentheses in REGEXP.
74 (let ((count 0) start)
75 (while (string-match "\\\\(" regexp start)
76 (setq count (1+ count) start (match-end 0)))
77 count))))
79 (defun c-delete-duplicates (list)
80 (let ((tail list))
81 (while tail
82 (setcdr tail (delete (car tail) (cdr tail)))
83 (setq tail (cdr tail)))
84 list))
86 (defun c-make-keywords-re (adorn &rest lists)
87 "Make a regexp that matches all the strings in all the lists.
88 Duplicates in the lists are removed. The regexp may contain zero or
89 more submatch expressions. If ADORN is non-nil there will be at least
90 one submatch which matches the whole keyword, and the regexp will also
91 not match a prefix of any identifier. Adorned regexps cannot be
92 appended."
93 (let ((list (copy-sequence (apply 'append lists))))
94 (setq list (c-delete-duplicates list))
95 (if list
96 (let ((re (c-regexp-opt list)))
97 ;; Add our own grouping parenthesis around re instead of
98 ;; passing adorn to regexp-opt, since it in XEmacs makes the
99 ;; top level grouping "shy".
100 (if adorn
101 (concat "\\(" re "\\)\\>\\([^_]\\|$\\)")
102 re))
103 "\\<\\>" ; Matches nothing.
105 (put 'c-make-keywords-re 'lisp-indent-function 1)
109 ;; Building of constants that are parameterized on a per-language
110 ;; basis.
112 (eval-and-compile
113 (defvar c-macroexpand-mode nil
114 ;; Dynamically bound to the mode symbol during `c-lang-defconst'
115 ;; so that `c-lang-var' can do the right expansion.
118 (defmacro c-lang-defconst (var &rest args)
119 ;; Sets the mode specific values of the constant VAR. The rest of
120 ;; the arguments are one or more repetitions of MODE VAL. MODE is
121 ;; the mode name without the "-mode" suffix, or a list of such
122 ;; mode names, or `all' as a shortcut for a list of all modes.
123 ;; VAL is evaluated (during compilation) for each mode with
124 ;; `c-macroexpand-mode' temporarily bound, so `c-lang-var' without
125 ;; an explicit mode may be used within it. The assignments in
126 ;; ARGS are processed in sequence, similar to `setq'.
127 (let* ((res (list 'progn))
128 (res-tail res))
129 (while args
130 (let ((mode (car args)))
131 (cond ((eq mode 'all)
132 (setq mode '(c c++ objc java idl pike)))
133 ((symbolp mode)
134 (setq mode (list mode))))
135 (while mode
136 (let* ((c-macroexpand-mode
137 (intern (concat (symbol-name (car mode)) "-mode")))
138 (val (eval (car (cdr args)))))
139 ;; Need to install the value also during compilation,
140 ;; since val might refer to earlier mode specific
141 ;; values.
142 (put var c-macroexpand-mode val)
143 (setcdr res-tail (list `(put ',var ',c-macroexpand-mode ',val)))
144 (setq res-tail (cdr res-tail)))
145 (setq mode (cdr mode))))
146 (setq args (cdr (cdr args))))
147 res))
148 (put 'c-lang-defconst 'lisp-indent-function 1)
150 (defmacro c-lang-var (var &optional mode)
151 ;; Get the mode specific value of the variable VAR in mode MODE.
152 ;; MODE is the mode name without the "-mode" suffix. It may also
153 ;; be nil to use the current value of `c-macroexpand-mode' (which
154 ;; is useful inside `c-lang-defconst') or `c-buffer-is-cc-mode'
155 ;; (which is useful inside `c-lang-defvar').
156 `(get ',var ,(if (eq mode 'nil)
157 (if c-macroexpand-mode
158 ;; In the macro expansion of c-lang-defconst.
159 `(quote ,c-macroexpand-mode)
160 `c-buffer-is-cc-mode)
161 `(quote ,(intern (concat (symbol-name mode) "-mode"))))))
163 ;; These are used to collect the init forms from the subsequent
164 ;; `c-lang-defvar'. They become a big setq in the
165 ;; `c-init-lang-defvars' lambda below.
166 (defconst c-lang-defvar-init-form (list 'setq))
167 (defvar c-lang-defvar-init-form-tail nil)
168 (setq c-lang-defvar-init-form-tail c-lang-defvar-init-form)
170 (defmacro c-lang-defvar (var val)
171 ;; Declares the buffer local variable VAR to get the value VAL at
172 ;; mode initialization, at which point VAL is evaluated.
173 ;; `c-lang-var' is typically used in VAL to get the right value
174 ;; according to `c-buffer-is-cc-mode'.
175 (setcdr c-lang-defvar-init-form-tail (list var val))
176 (setq c-lang-defvar-init-form-tail
177 (cdr (cdr c-lang-defvar-init-form-tail)))
178 `(progn
179 (defvar ,var nil)
180 (make-variable-buffer-local ',var)))
181 (put 'c-lang-defvar 'lisp-indent-function 1)
184 ;; Regexp describing a `symbol' in all languages, not excluding
185 ;; keywords.
186 (c-lang-defconst c-symbol-key
187 (c c++ objc java idl)
188 (if (string-match "[[:alpha:]]" "a")
189 "[[:alpha:]_][[:alnum:]_]*" ; Emacs 21.
190 ;; We cannot use just `word' syntax class since `_' cannot be
191 ;; in word class. Putting underscore in word class breaks
192 ;; forward word movement behavior that users are familiar
193 ;; with. Besides, it runs counter to Emacs convention.
194 "[a-zA-Z_]\\(\\w\\|_\\)*")
195 pike (concat "\\(" (c-lang-var c-symbol-key c) "\\|"
196 (c-make-keywords-re nil
197 '("`+" "`-" "`&" "`|" "`^" "`<<" "`>>" "`*" "`/" "`%" "`~"
198 "`==" "`<" "`>" "`!" "`[]" "`[]=" "`->" "`->=" "`()" "``+"
199 "``-" "``&" "``|" "``^" "``<<" "``>>" "``*" "``/" "``%"
200 "`+="))
201 "\\)"))
202 (c-lang-defvar c-symbol-key (c-lang-var c-symbol-key))
204 ;; Number of regexp grouping parens in c-symbol-key.
205 (c-lang-defvar c-symbol-key-depth (c-regexp-opt-depth c-symbol-key))
207 (defvar c-stmt-delim-chars "^;{}?:")
208 ;; The characters that should be considered to bound statements. To
209 ;; optimize c-crosses-statement-barrier-p somewhat, it's assumed to
210 ;; begin with "^" to negate the set. If ? : operators should be
211 ;; detected then the string must end with "?:".
213 (defvar c-stmt-delim-chars-with-comma "^;,{}?:")
214 ;; Variant of c-stmt-delim-chars that additionally contains ','.
216 ;; HELPME: Many of the following keyword lists are more or less bogus
217 ;; for some languages (notably ObjC and IDL). The effects of the
218 ;; erroneous values in the language handling are mostly negligible
219 ;; since the constants that actually matter in the syntax detection
220 ;; code are mostly correct in the situations they are used, but I'd
221 ;; still appreciate help to get them correct for other uses.
223 ;; Primitive type keywords.
224 (c-lang-defconst c-primitive-type-kwds
225 (c c++ objc idl) '("char" "double" "float" "int" "long" "short"
226 "signed" "unsigned" "void")
227 java '("boolean" "byte" "char" "double" "float" "int" "long" "short" "void")
228 pike '("constant" "float" "int" "mapping" "multiset" "object" "program"
229 "string" "void"))
231 ;; Declaration specifier keywords.
232 (c-lang-defconst c-specifier-kwds
233 c '("auto" "const" "extern" "register" "static" "volatile")
234 (c++ objc idl) (append '("friend" "inline" "virtual")
235 (c-lang-var c-specifier-kwds c))
236 ;; Note: `const' is not used in Java, but it's still a reserved keyword.
237 java '("abstract" "const" "final" "native" "private" "protected"
238 "public" "static" "synchronized" "transient" "volatile")
239 pike '("final" "inline" "local" "nomask" "optional" "private"
240 "protected" "static" "variant"))
242 ;; Class/struct declaration keywords.
243 (c-lang-defconst c-class-kwds
244 c '("struct" "union")
245 c++ '("class" "struct" "union")
246 objc '("interface" "implementation")
247 java '("class" "interface")
248 idl '("interface" "valuetype" "class" "struct" "union")
249 pike '("class"))
251 ;; Regexp matching the start of a class.
252 (c-lang-defconst c-class-key
253 all (c-make-keywords-re t (c-lang-var c-class-kwds)))
254 (c-lang-defconst c-class-key ; ObjC needs some tuning of the regexp.
255 objc (concat "@" (c-lang-var c-class-key)))
256 (c-lang-defvar c-class-key (c-lang-var c-class-key))
258 ;; Keywords introducing blocks besides classes that contain another
259 ;; declaration level.
260 (c-lang-defconst c-other-decl-block-kwds
261 c '("extern")
262 c++ '("namespace" "extern")
263 idl '("module"))
265 ;; Regexp matching the start of blocks besides classes that contain
266 ;; another declaration level.
267 (c-lang-defconst c-other-decl-block-key
268 all (c-make-keywords-re t (c-lang-var c-other-decl-block-kwds)))
269 (c-lang-defvar c-other-decl-block-key (c-lang-var c-other-decl-block-key))
271 ;; Keywords introducing declarations that can contain a block which
272 ;; might be followed by variable declarations, e.g. like "foo" in
273 ;; "class Foo { ... } foo;". So if there is a block in a declaration
274 ;; like that, it ends with the following ';' and not right away.
275 (c-lang-defconst c-block-decls-with-vars
276 c '("struct" "union" "enum" "typedef")
277 c++ '("class" "struct" "union" "enum" "typedef"))
279 ;; Regexp matching the `c-block-decls-with-vars' keywords, or nil in
280 ;; languages without such constructs.
281 (c-lang-defconst c-opt-block-decls-with-vars-key
282 all (and (c-lang-var c-block-decls-with-vars)
283 (c-make-keywords-re t (c-lang-var c-block-decls-with-vars))))
284 (c-lang-defvar c-opt-block-decls-with-vars-key
285 (c-lang-var c-opt-block-decls-with-vars-key))
287 ;; Keywords introducing declarations that has not been accounted for
288 ;; by any of the above.
289 (c-lang-defconst c-other-decl-kwds
290 ;; FIXME: Shouldn't "template" be moved to c-specifier-kwds for C++?
291 c++ '("template")
292 java '("import" "package")
293 pike '("import" "inherit"))
295 ;; Keywords introducing extra declaration specifiers in the region
296 ;; between the header and the body (i.e. the "K&R-region") in
297 ;; declarations.
298 (c-lang-defconst c-decl-spec-kwds java '("extends" "implements" "throws"))
300 ;; Protection label keywords in classes.
301 (c-lang-defconst c-protection-kwds
302 (c++ objc) '("private" "protected" "public"))
304 ;; Statement keywords followed directly by a substatement.
305 (c-lang-defconst c-block-stmt-1-kwds
306 (c pike) '("do" "else")
307 (c++ objc) '("do" "else" "asm" "try")
308 java '("do" "else" "finally" "try"))
310 ;; Regexp matching the start of any statement followed directly by a
311 ;; substatement (doesn't match a bare block, however).
312 (c-lang-defconst c-block-stmt-1-key
313 all (c-make-keywords-re t (c-lang-var c-block-stmt-1-kwds)))
314 (c-lang-defvar c-block-stmt-1-key (c-lang-var c-block-stmt-1-key))
316 ;; Statement keywords followed by a paren sexp and then by a substatement.
317 (c-lang-defconst c-block-stmt-2-kwds
318 c '("for" "if" "switch" "while")
319 (c++ objc) '("for" "if" "switch" "while" "catch")
320 java '("for" "if" "switch" "while" "catch" "synchronized")
321 pike '("for" "if" "switch" "while" "foreach"))
323 ;; Regexp matching the start of any statement followed by a paren sexp
324 ;; and then by a substatement.
325 (c-lang-defconst c-block-stmt-2-key
326 all (c-make-keywords-re t (c-lang-var c-block-stmt-2-kwds)))
327 (c-lang-defvar c-block-stmt-2-key (c-lang-var c-block-stmt-2-key))
329 ;; Regexp matching the start of any statement that has a substatement
330 ;; (except a bare block). Nil in languages that doesn't have such
331 ;; constructs.
332 (c-lang-defconst c-opt-block-stmt-key
333 all (if (or (c-lang-var c-block-stmt-1-kwds)
334 (c-lang-var c-block-stmt-2-kwds))
335 (c-make-keywords-re t
336 (c-lang-var c-block-stmt-1-kwds)
337 (c-lang-var c-block-stmt-2-kwds))))
338 (c-lang-defvar c-opt-block-stmt-key (c-lang-var c-opt-block-stmt-key))
340 ;; Statement keywords followed by an expression or nothing.
341 (c-lang-defconst c-simple-stmt-kwds
342 (c c++ objc) '("break" "continue" "goto" "return")
343 ;; Note: `goto' is not valid in Java, but the keyword is still reserved.
344 java '("break" "continue" "goto" "return" "throw")
345 pike '("break" "continue" "return"))
347 ;; Statement keywords followed by an assembler expression.
348 (c-lang-defconst c-asm-stmt-kwds
349 (c c++) '("asm" "__asm__"))
351 ;; Regexp matching the start of an assembler statement. Nil in
352 ;; languages that doesn't support that.
353 (c-lang-defconst c-opt-asm-stmt-key
354 all (if (c-lang-var c-asm-stmt-kwds)
355 (c-make-keywords-re t (c-lang-var c-asm-stmt-kwds))))
356 (c-lang-defvar c-opt-asm-stmt-key (c-lang-var c-opt-asm-stmt-key))
358 ;; Keywords introducing labels in blocks.
359 (c-lang-defconst c-label-kwds (c c++ objc java pike) '("case" "default"))
361 ;; Regexp matching any keyword that introduces a label.
362 (c-lang-defconst c-label-kwds-regexp
363 all (c-make-keywords-re t (c-lang-var c-label-kwds)))
364 (c-lang-defvar c-label-kwds-regexp (c-lang-var c-label-kwds-regexp))
366 ;; Keywords that can occur anywhere in expressions.
367 (c-lang-defconst c-expr-kwds
368 (c objc) '("sizeof")
369 c++ '("sizeof" "delete" "new" "operator" "this" "throw")
370 java '("instanceof" "new" "super" "this")
371 pike '("sizeof" "catch" "class" "gauge" "lambda" "predef"))
373 ;; Keywords that start lambda constructs, i.e. function definitions in
374 ;; expressions.
375 (c-lang-defconst c-lambda-kwds pike '("lambda"))
377 ;; Regexp matching the start of lambda constructs, or nil in languages
378 ;; that doesn't have such things.
379 (c-lang-defconst c-opt-lambda-key
380 pike (c-make-keywords-re t (c-lang-var c-lambda-kwds)))
381 (c-lang-defvar c-opt-lambda-key (c-lang-var c-opt-lambda-key))
383 ;; Keywords that start constructs followed by statement blocks which
384 ;; can be used in expressions (the gcc extension for this in C and C++
385 ;; is handled separately).
386 (c-lang-defconst c-inexpr-block-kwds pike '("catch" "gauge"))
388 ;; Regexp matching the start of in-expression statements, or nil in
389 ;; languages that doesn't have such things.
390 (c-lang-defconst c-opt-inexpr-block-key
391 pike (c-make-keywords-re t (c-lang-var c-inexpr-block-kwds)))
392 (c-lang-defvar c-opt-inexpr-block-key (c-lang-var c-opt-inexpr-block-key))
394 ;; Keywords that start classes in expressions.
395 (c-lang-defconst c-inexpr-class-kwds
396 java '("new")
397 pike '("class"))
399 ;; Regexp matching the start of a class in an expression, or nil in
400 ;; languages that doesn't have such things.
401 (c-lang-defconst c-opt-inexpr-class-key
402 (java pike) (c-make-keywords-re t (c-lang-var c-inexpr-class-kwds)))
403 (c-lang-defvar c-opt-inexpr-class-key (c-lang-var c-opt-inexpr-class-key))
405 ;; Regexp matching the start of any class, both at top level and in
406 ;; expressions.
407 (c-lang-defconst c-any-class-key
408 all (c-make-keywords-re t
409 (c-lang-var c-class-kwds)
410 (c-lang-var c-inexpr-class-kwds)))
411 (c-lang-defconst c-any-class-key ; ObjC needs some tuning of the regexp.
412 objc (concat "@" (c-lang-var c-any-class-key)))
413 (c-lang-defvar c-any-class-key (c-lang-var c-any-class-key))
415 ;; Regexp matching the start of any declaration-level block that
416 ;; contain another declaration level, i.e. that isn't a function
417 ;; block.
418 (c-lang-defconst c-decl-block-key
419 all (c-make-keywords-re t
420 (c-lang-var c-class-kwds)
421 (c-lang-var c-other-decl-block-kwds)
422 (c-lang-var c-inexpr-class-kwds)))
423 (c-lang-defconst c-decl-block-key ; ObjC needs some tuning of the regexp.
424 objc (concat "@" (c-lang-var c-decl-block-key)))
425 (c-lang-defvar c-decl-block-key (c-lang-var c-decl-block-key))
427 ;; Keywords that can introduce bitfields.
428 (c-lang-defconst c-bitfield-kwds
429 (c c++) '("char" "int" "long" "signed" "unsigned"))
431 ;; Regexp matching the start of a bitfield (not uniquely), or nil in
432 ;; languages without bitfield support.
433 (c-lang-defconst c-opt-bitfield-key
434 (c c++) (c-make-keywords-re t (c-lang-var c-bitfield-kwds)))
435 (c-lang-defvar c-opt-bitfield-key (c-lang-var c-opt-bitfield-key))
437 ;; All keywords as a list.
438 (c-lang-defconst c-keywords
439 all (c-delete-duplicates
440 (append (c-lang-var c-primitive-type-kwds)
441 (c-lang-var c-specifier-kwds)
442 (c-lang-var c-class-kwds)
443 (c-lang-var c-other-decl-block-kwds)
444 (c-lang-var c-block-decls-with-vars)
445 (c-lang-var c-other-decl-kwds)
446 (c-lang-var c-decl-spec-kwds)
447 (c-lang-var c-protection-kwds)
448 (c-lang-var c-block-stmt-1-kwds)
449 (c-lang-var c-block-stmt-2-kwds)
450 (c-lang-var c-simple-stmt-kwds)
451 (c-lang-var c-asm-stmt-kwds)
452 (c-lang-var c-label-kwds)
453 (c-lang-var c-expr-kwds)
454 (c-lang-var c-lambda-kwds)
455 (c-lang-var c-inexpr-block-kwds)
456 (c-lang-var c-inexpr-class-kwds)
457 (c-lang-var c-bitfield-kwds)
458 nil)))
459 (c-lang-defvar c-keywords (c-lang-var c-keywords))
461 ;; All keywords as an adorned regexp.
462 (c-lang-defconst c-keywords-regexp
463 all (c-make-keywords-re t (c-lang-var c-keywords)))
464 (c-lang-defvar c-keywords-regexp (c-lang-var c-keywords-regexp))
466 ;; Regexp matching an access protection label in a class, or nil in
467 ;; languages that doesn't have such things.
468 (c-lang-defconst c-opt-access-key
469 c++ (concat "\\("
470 (c-make-keywords-re nil (c-lang-var c-protection-kwds))
471 "\\)[ \t\n\r]*:"))
472 (c-lang-defconst c-opt-access-key
473 objc (concat "@" (c-make-keywords-re t (c-lang-var c-protection-kwds))))
474 (c-lang-defvar c-opt-access-key (c-lang-var c-opt-access-key))
476 ;; Regexp matching a normal label, i.e. not a label that's recognized
477 ;; with a keyword, like switch labels. It's only used at the
478 ;; beginning of a statement.
479 (c-lang-defconst c-label-key
480 all (concat (c-lang-var c-symbol-key) "[ \t\n\r]*:\\([^:]\\|$\\)"))
481 (c-lang-defvar c-label-key (c-lang-var c-label-key))
483 ;; Regexp matching the beginning of a declaration specifier in the
484 ;; region between the header and the body of a declaration.
486 ;; FIXME: This is currently not used in a uniformly; c++-mode and
487 ;; java-mode each have their own ways of using it.
488 (c-lang-defconst c-opt-decl-spec-key
489 c++ (concat ":?[ \t\n\r]*\\(virtual[ \t\n\r]+\\)?\\("
490 (c-make-keywords-re nil (c-lang-var c-protection-kwds))
491 "\\)[ \t\n\r]+"
492 (c-lang-var c-symbol-key))
493 java (c-make-keywords-re t (c-lang-var c-decl-spec-kwds)))
494 (c-lang-defvar c-opt-decl-spec-key (c-lang-var c-opt-decl-spec-key))
496 ;; Regexp describing friend declarations classes, or nil in languages
497 ;; that doesn't have such things.
498 (c-lang-defconst c-opt-friend-key
499 ;; FIXME: Ought to use c-specifier-kwds or similar, and the template
500 ;; skipping isn't done properly.
501 c++ "friend[ \t]+\\|template[ \t]*<.+>[ \t]*friend[ \t]+")
502 (c-lang-defvar c-opt-friend-key (c-lang-var c-opt-friend-key))
504 ;; Special regexp to match the start of methods.
505 (c-lang-defconst c-opt-method-key
506 objc (concat
507 "^\\s *[+-]\\s *"
508 "\\(([^)]*)\\)?" ; return type
509 ;; \\s- in objc syntax table does not include \n
510 ;; since it is considered the end of //-comments.
511 "[ \t\n]*" (c-lang-var c-symbol-key)))
512 (c-lang-defvar c-opt-method-key (c-lang-var c-opt-method-key))
514 ;; Name of functions in cpp expressions that take an identifier as the
515 ;; argument.
516 (c-lang-defconst c-cpp-defined-fns
517 (c c++) '("defined")
518 pike '("defined" "efun" "constant"))
520 ;; List of open- and close-chars that makes up a pike-style brace
521 ;; list, i.e. for a `([ ])' list there should be a cons (?\[ . ?\]) in
522 ;; this list.
523 (c-lang-defconst c-special-brace-lists pike '((?{ . ?})
524 (?\[ . ?\])
525 (?< . ?>)))
526 (c-lang-defvar c-special-brace-lists (c-lang-var c-special-brace-lists))
528 ;; Non-nil means K&R style argument declarations are valid.
529 (c-lang-defconst c-recognize-knr-p c t)
530 (c-lang-defvar c-recognize-knr-p (c-lang-var c-recognize-knr-p))
532 ;; Regexp to match the start of any type of comment.
534 ;; FIXME: Ought to use c-comment-prefix-regexp with some modifications
535 ;; instead of this.
536 (c-lang-defconst c-comment-start-regexp
537 (c c++ objc idl pike) "/[/*]"
538 ;; We need to match all 3 Java style comments
539 ;; 1) Traditional C block; 2) javadoc /** ...; 3) C++ style
540 java "/\\(/\\|[*][*]?\\)")
541 (c-lang-defvar c-comment-start-regexp (c-lang-var c-comment-start-regexp))
543 ;; Strings that starts and ends comments inserted with M-; etc.
544 ;; comment-start and comment-end are initialized from these.
545 (c-lang-defconst comment-start
546 c "/* "
547 (c++ objc java idl pike) "// ")
548 (c-lang-defvar comment-start (c-lang-var comment-start))
549 (c-lang-defconst comment-end
550 c "*/"
551 (c++ objc java idl pike) "")
552 (c-lang-defvar comment-end (c-lang-var comment-end))
554 ;; Regexp that matches when there is no syntactically significant text
555 ;; before eol. Macros are regarded as syntactically significant text
556 ;; here.
557 (c-lang-defvar c-syntactic-eol
558 (concat (concat
559 ;; Match horizontal whitespace and block comments that
560 ;; doesn't contain newlines.
561 "\\(\\s \\|"
562 (concat "/\\*"
563 "\\([^*\n\r]\\|\\*[^/\n\r]\\)*"
564 "\\*/")
565 "\\)*")
566 (concat
567 ;; Match eol (possibly inside a block comment), or the
568 ;; beginning of a line comment. Note: This has to be
569 ;; modified for awk where line comments start with '#'.
570 "\\("
571 (concat "\\("
572 "/\\*\\([^*\n\r]\\|\\*[^/\n\r]\\)*"
573 "\\)?"
574 "$")
575 "\\|//\\)")))
577 ;; Regexp to append to paragraph-start.
578 (c-lang-defconst paragraph-start
579 (c c++ objc idl) "$"
580 java "\\(@[a-zA-Z]+\\>\\|$\\)" ; For Javadoc.
581 pike "\\(@[a-zA-Z]+\\>\\([^{]\\|$\\)\\|$\\)") ; For Pike refdoc.
583 ;; Regexp to append to paragraph-separate.
584 (c-lang-defconst paragraph-separate
585 (c c++ objc java idl) "$"
586 pike (c-lang-var paragraph-start))
588 ;; Prefix added to `c-current-comment-prefix' to set
589 ;; `c-opt-in-comment-lc', or nil if it should be nil.
590 (c-lang-defconst c-in-comment-lc-prefix pike "@[\n\r]\\s *")
592 ;; Regexp to match in-comment line continuations, or nil in languages
593 ;; where that isn't applicable. It's assumed that it only might match
594 ;; from and including the last character on a line. Built from
595 ;; *-in-comment-lc-prefix and the current value of
596 ;; c-current-comment-prefix.
597 (c-lang-defvar c-opt-in-comment-lc
598 (if (c-lang-var c-in-comment-lc-prefix)
599 (concat (c-lang-var c-in-comment-lc-prefix)
600 c-current-comment-prefix)))
602 (defconst c-init-lang-defvars
603 ;; Make a lambda of the collected `c-lang-defvar' initializations.
604 (cc-eval-when-compile
605 (if (cc-bytecomp-is-compiling)
606 (byte-compile-lambda `(lambda () ,c-lang-defvar-init-form))
607 `(lambda () ,c-lang-defvar-init-form))))
609 (defun c-init-language-vars ()
610 ;; Initialize all `c-lang-defvar' variables according to
611 ;; `c-buffer-is-cc-mode'.
612 (if (not (memq c-buffer-is-cc-mode
613 '(c-mode c++-mode objc-mode java-mode idl-mode pike-mode)))
614 (error "Cannot initialize language variables for unknown mode %s"
615 c-buffer-is-cc-mode))
616 (funcall c-init-lang-defvars))
618 ;; Regexp trying to describe the beginning of a Java top-level
619 ;; definition. This is not used by CC Mode, nor is it maintained
620 ;; since it's practically impossible to write a regexp that reliably
621 ;; matches such a construct. Other tools are necessary.
622 (defconst c-Java-defun-prompt-regexp
623 "^[ \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-*")
626 ;; Syntax tables.
628 (defun c-populate-syntax-table (table)
629 ;; Populate the syntax 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 (modify-syntax-entry ?> "." table)
638 (modify-syntax-entry ?& "." table)
639 (modify-syntax-entry ?| "." table)
640 (modify-syntax-entry ?\' "\"" table)
641 ;; Set up block and line oriented comments. The new C standard
642 ;; mandates both comment styles even in C, so since all languages
643 ;; now require dual comments, we make this the default.
644 (cond
645 ;; XEmacs 19 & 20
646 ((memq '8-bit c-emacs-features)
647 (modify-syntax-entry ?/ ". 1456" table)
648 (modify-syntax-entry ?* ". 23" table))
649 ;; Emacs 19 & 20
650 ((memq '1-bit c-emacs-features)
651 (modify-syntax-entry ?/ ". 124b" table)
652 (modify-syntax-entry ?* ". 23" table))
653 ;; incompatible
654 (t (error "CC Mode is incompatible with this version of Emacs"))
656 (modify-syntax-entry ?\n "> b" table)
657 ;; Give CR the same syntax as newline, for selective-display
658 (modify-syntax-entry ?\^m "> b" table))
660 ;;;###autoload
661 (defvar c-mode-syntax-table nil
662 "Syntax table used in c-mode buffers.")
663 (if c-mode-syntax-table
665 (setq c-mode-syntax-table (make-syntax-table))
666 (c-populate-syntax-table c-mode-syntax-table))
668 ;;;###autoload
669 (defvar c++-mode-syntax-table nil
670 "Syntax table used in c++-mode buffers.")
671 (if c++-mode-syntax-table
673 (setq c++-mode-syntax-table (make-syntax-table))
674 (c-populate-syntax-table c++-mode-syntax-table))
676 (defvar c++-template-syntax-table nil
677 "A variant of `c++-mode-syntax-table' that defines `<' and `>' as
678 parenthesis characters. Used temporarily when template argument lists
679 are parsed.")
680 (if c++-template-syntax-table
682 (setq c++-template-syntax-table
683 (copy-syntax-table c++-mode-syntax-table))
684 (modify-syntax-entry ?< "(>" c++-template-syntax-table)
685 (modify-syntax-entry ?> ")<" c++-template-syntax-table))
687 ;;;###autoload
688 (defvar objc-mode-syntax-table nil
689 "Syntax table used in objc-mode buffers.")
690 (if objc-mode-syntax-table
692 (setq objc-mode-syntax-table (make-syntax-table))
693 (c-populate-syntax-table objc-mode-syntax-table)
694 ;; add extra Objective-C only syntax
695 (modify-syntax-entry ?@ "_" objc-mode-syntax-table))
697 ;;;###autoload
698 (defvar java-mode-syntax-table nil
699 "Syntax table used in java-mode buffers.")
700 (if java-mode-syntax-table
702 (setq java-mode-syntax-table (make-syntax-table))
703 (c-populate-syntax-table java-mode-syntax-table))
705 ;;;###autoload
706 (defvar idl-mode-syntax-table nil
707 "Syntax table used in idl-mode buffers.")
708 (if idl-mode-syntax-table
710 (setq idl-mode-syntax-table (make-syntax-table))
711 (c-populate-syntax-table idl-mode-syntax-table))
713 ;;;###autoload
714 (defvar pike-mode-syntax-table nil
715 "Syntax table used in pike-mode buffers.")
716 (if pike-mode-syntax-table
718 (setq pike-mode-syntax-table (make-syntax-table))
719 (c-populate-syntax-table pike-mode-syntax-table)
720 (modify-syntax-entry ?@ "." pike-mode-syntax-table))
723 ;; internal state variables
725 ;; Internal state of hungry delete key feature
726 (defvar c-hungry-delete-key nil)
727 (make-variable-buffer-local 'c-hungry-delete-key)
729 ;; Internal state of auto newline feature.
730 (defvar c-auto-newline nil)
731 (make-variable-buffer-local 'c-auto-newline)
733 ;; Internal auto-newline/hungry-delete designation string for mode line.
734 (defvar c-auto-hungry-string nil)
735 (make-variable-buffer-local 'c-auto-hungry-string)
738 (cc-provide 'cc-langs)
740 ;;; cc-langs.el ends here