X-Git-Url: https://code.delx.au/gnu-emacs/blobdiff_plain/0f74f7850de124626d556442d22d143d85457816..49a2697c1ed851de2e93ee3ba12ab74f286f9634:/lisp/progmodes/cc-langs.el diff --git a/lisp/progmodes/cc-langs.el b/lisp/progmodes/cc-langs.el index d7ef278174..493f3db096 100644 --- a/lisp/progmodes/cc-langs.el +++ b/lisp/progmodes/cc-langs.el @@ -1,6 +1,6 @@ ;;; cc-langs.el --- language specific settings for CC Mode -;; Copyright (C) 1985, 1987, 1992-2011 Free Software Foundation, Inc. +;; Copyright (C) 1985, 1987, 1992-2012 Free Software Foundation, Inc. ;; Authors: 2002- Alan Mackenzie ;; 1998- Martin Stjernholm @@ -221,7 +221,7 @@ the evaluated constant value at compile time." ;; ;; OPS either has the structure of `c-operators', is a single ;; group in `c-operators', or is a plain list of operators. - ;; + ;; ;; OPGROUP-FILTER specifies how to select the operator groups. It ;; can be t to choose all groups, a list of group type symbols ;; (such as 'prefix) to accept, or a function which will be called @@ -433,7 +433,7 @@ element is a cons where the car is the character to modify and the cdr the new syntax, as accepted by `modify-syntax-entry'." ;; The $ character is not allowed in most languages (one exception ;; is Java which allows it for legacy reasons) but we still classify - ;; it as an indentifier character since it's often used in various + ;; it as an identifier character since it's often used in various ;; machine generated identifiers. t '((?_ . "w") (?$ . "w")) (objc java) (append '((?@ . "w")) @@ -459,8 +459,10 @@ so that all identifiers are recognized as words.") ;; For documentation see the following c-lang-defvar of the same name. ;; The value here may be a list of functions or a single function. t nil - c++ '(c-extend-region-for-CPP c-before-change-check-<>-operators) - (c objc) 'c-extend-region-for-CPP + c++ '(c-extend-region-for-CPP + c-before-change-check-<>-operators + c-invalidate-macro-cache) + (c objc) '(c-extend-region-for-CPP c-invalidate-macro-cache) ;; java 'c-before-change-check-<>-operators awk 'c-awk-record-region-clear-NL) (c-lang-defvar c-get-state-before-change-functions @@ -485,32 +487,91 @@ The functions are called even when font locking isn't enabled. When the mode is initialized, the functions are called with parameters \(point-min) and \(point-max).") -(c-lang-defconst c-before-font-lock-function - "If non-nil, a function called just before font locking. -Typically it will extend the region about to be fontified \(see +(c-lang-defconst c-before-font-lock-functions + ;; For documentation see the following c-lang-defvar of the same name. + ;; The value here may be a list of functions or a single function. + t 'c-change-set-fl-decl-start + (c c++ objc) '(c-neutralize-syntax-in-and-mark-CPP + c-change-set-fl-decl-start) + awk 'c-awk-extend-and-syntax-tablify-region) +(c-lang-defvar c-before-font-lock-functions + (let ((fs (c-lang-const c-before-font-lock-functions))) + (if (listp fs) + fs + (list fs))) + "If non-nil, a list of functions called just before font locking. +Typically they will extend the region about to be fontified \(see below) and will set `syntax-table' text properties on the region. -It takes 3 parameters, the BEG, END, and OLD-LEN supplied to -every after-change function; point is undefined on both entry and -exit; on entry, the buffer will have been widened and match-data -will have been saved; the return value is ignored. +These functions will be run in the order given. Each of them +takes 3 parameters, the BEG, END, and OLD-LEN supplied to every +after-change function; point is undefined on both entry and exit; +on entry, the buffer will have been widened and match-data will +have been saved; the return value is ignored. -The function may extend the region to be fontified by setting the +The functions may extend the region to be fontified by setting the buffer local variables c-new-BEG and c-new-END. -The function is called even when font locking is disabled. +The functions are called even when font locking is disabled. + +When the mode is initialized, these functions are called with +parameters \(point-min), \(point-max) and .") + +(c-lang-defconst c-before-context-fontification-functions + awk nil + t 'c-context-set-fl-decl-start) + ;; For documentation see the following c-lang-defvar of the same name. + ;; The value here may be a list of functions or a single function. +(c-lang-defvar c-before-context-fontification-functions + (let ((fs (c-lang-const c-before-context-fontification-functions))) + (if (listp fs) + fs + (list fs))) + "If non-nil, a list of functions called just before context (or +other non-change) fontification is done. Typically they will +extend the region. + +These functions will be run in the order given. Each of them +takes 2 parameters, the BEG and END of the region to be +fontified. Point is undefined on both entry and exit. On entry, +the buffer will have been widened and match-data will have been +saved; the return value is a cons of the adjusted +region, (NEW-BEG . NEW-END).") -When the mode is initialized, this function is called with -parameters \(point-min), \(point-max) and ." + +;;; Syntactic analysis ("virtual semicolons") for line-oriented languages (AWK). +(c-lang-defconst c-at-vsemi-p-fn + "Contains a function \"Is there a virtual semicolon at POS or point?\". +Such a function takes one optional parameter, a buffer position (defaults to +point), and returns nil or t. This variable contains nil for languages which +don't have EOL terminated statements. " t nil - (c c++ objc) 'c-neutralize-syntax-in-and-mark-CPP - awk 'c-awk-extend-and-syntax-tablify-region) -(c-lang-defvar c-before-font-lock-function - (c-lang-const c-before-font-lock-function)) + (c c++ objc) 'c-at-macro-vsemi-p + awk 'c-awk-at-vsemi-p) +(c-lang-defvar c-at-vsemi-p-fn (c-lang-const c-at-vsemi-p-fn)) + +(c-lang-defconst c-vsemi-status-unknown-p-fn + "Contains a function \"are we unsure whether there is a virtual semicolon on this line?\". +The (admittedly kludgy) purpose of such a function is to prevent an infinite +recursion in c-beginning-of-statement-1 when point starts at a `while' token. +The function MUST NOT UNDER ANY CIRCUMSTANCES call c-beginning-of-statement-1, +even indirectly. This variable contains nil for languages which don't have +EOL terminated statements." + t nil + (c c++ objc) 'c-macro-vsemi-status-unknown-p + awk 'c-awk-vsemi-status-unknown-p) +(c-lang-defvar c-vsemi-status-unknown-p-fn + (c-lang-const c-vsemi-status-unknown-p-fn)) ;;; Lexer-level syntax (identifiers, tokens etc). +(c-lang-defconst c-has-bitfields + "Whether the language has bitfield declarations." + t nil + (c c++ objc) t) +(c-lang-defvar c-has-bitfields (c-lang-const c-has-bitfields)) + (c-lang-defconst c-symbol-start "Regexp that matches the start of a symbol, i.e. any identifier or keyword. It's unspecified how far it matches. Does not contain a \\| @@ -528,6 +589,7 @@ This is of the form that fits inside [ ] in a regexp." ;; operator chars too, but they are handled with other means instead. t (concat c-alnum "_$") objc (concat c-alnum "_$@")) +(c-lang-defvar c-symbol-chars (c-lang-const c-symbol-chars)) (c-lang-defconst c-symbol-key "Regexp matching identifiers and keywords (with submatch 0). Assumed @@ -730,11 +792,17 @@ literal are multiline." (c-lang-defvar c-multiline-string-start-char (c-lang-const c-multiline-string-start-char)) +(c-lang-defconst c-opt-cpp-symbol + "The symbol which starts preprocessor constructs when in the margin." + t "#" + (java awk) nil) +(c-lang-defvar c-opt-cpp-symbol (c-lang-const c-opt-cpp-symbol)) + (c-lang-defconst c-opt-cpp-prefix "Regexp matching the prefix of a cpp directive in the languages that normally use that macro preprocessor. Tested at bol or at boi. Assumed to not contain any submatches or \\| operators." - ;; TODO (ACM, 2005-04-01). Amend the following to recognise escaped NLs; + ;; TODO (ACM, 2005-04-01). Amend the following to recognize escaped NLs; ;; amend all uses of c-opt-cpp-prefix which count regexp-depth. t "\\s *#\\s *" (java awk) nil) @@ -778,6 +846,8 @@ file name in angle brackets or quotes." definition, or nil if the language doesn't have any." t (if (c-lang-const c-opt-cpp-prefix) "define")) +(c-lang-defvar c-opt-cpp-macro-define + (c-lang-const c-opt-cpp-macro-define)) (c-lang-defconst c-opt-cpp-macro-define-start ;; Regexp matching everything up to the macro body of a cpp define, or the @@ -808,6 +878,16 @@ expression." t (if (c-lang-const c-opt-cpp-prefix) '("if" "elif"))) +(c-lang-defconst c-cpp-expr-intro-re + "Regexp which matches the start of a CPP directive which contains an +expression, or nil if there aren't any in the language." + t (if (c-lang-const c-cpp-expr-directives) + (concat + (c-lang-const c-opt-cpp-prefix) + (c-make-keywords-re t (c-lang-const c-cpp-expr-directives))))) +(c-lang-defvar c-cpp-expr-intro-re + (c-lang-const c-cpp-expr-intro-re)) + (c-lang-defconst c-cpp-expr-functions "List of functions in cpp expressions." t (if (c-lang-const c-opt-cpp-prefix) @@ -1154,14 +1234,12 @@ operators." ;; optimize `c-crosses-statement-barrier-p' somewhat, it's assumed to ;; begin with "^" to negate the set. If ? : operators should be ;; detected then the string must end with "?:". - t "^;{}?:" - awk "^;{}#\n\r?:") ; The newline chars gets special treatment. + t "^;{}?:") (c-lang-defvar c-stmt-delim-chars (c-lang-const c-stmt-delim-chars)) (c-lang-defconst c-stmt-delim-chars-with-comma ;; Variant of `c-stmt-delim-chars' that additionally contains ','. - t "^;,{}?:" - awk "^;,{}\n\r?:") ; The newline chars gets special treatment. + t "^;,{}?:") (c-lang-defvar c-stmt-delim-chars-with-comma (c-lang-const c-stmt-delim-chars-with-comma)) @@ -1221,7 +1299,6 @@ properly." re))) (c-lang-defvar c-comment-start-regexp (c-lang-const c-comment-start-regexp)) -;;;; Added by ACM, 2003/9/18. (c-lang-defconst c-block-comment-start-regexp ;; Regexp which matches the start of a block comment (if such exists in the ;; language) @@ -1231,6 +1308,15 @@ properly." (c-lang-defvar c-block-comment-start-regexp (c-lang-const c-block-comment-start-regexp)) +(c-lang-defconst c-line-comment-start-regexp + ;; Regexp which matches the start of a line comment (if such exists in the + ;; language; it does in all 7 CC Mode languages). + t (if (c-lang-const c-line-comment-starter) + (regexp-quote (c-lang-const c-line-comment-starter)) + "\\<\\>")) +(c-lang-defvar c-line-comment-start-regexp + (c-lang-const c-line-comment-start-regexp)) + (c-lang-defconst c-literal-start-regexp ;; Regexp to match the start of comments and string literals. t (concat (c-lang-const c-comment-start-regexp) @@ -1457,29 +1543,6 @@ properly." "\\)")) (c-lang-defvar c-syntactic-eol (c-lang-const c-syntactic-eol)) - -;;; Syntactic analysis ("virtual semicolons") for line-oriented languages (AWK). -(c-lang-defconst c-at-vsemi-p-fn - "Contains a function \"Is there a virtual semicolon at POS or point?\". -Such a function takes one optional parameter, a buffer position (defaults to -point), and returns nil or t. This variable contains nil for languages which -don't have EOL terminated statements. " - t nil - awk 'c-awk-at-vsemi-p) -(c-lang-defvar c-at-vsemi-p-fn (c-lang-const c-at-vsemi-p-fn)) - -(c-lang-defconst c-vsemi-status-unknown-p-fn - "Contains a function \"are we unsure whether there is a virtual semicolon on this line?\". -The (admittedly kludgey) purpose of such a function is to prevent an infinite -recursion in c-beginning-of-statement-1 when point starts at a `while' token. -The function MUST NOT UNDER ANY CIRCUMSTANCES call c-beginning-of-statement-1, -even indirectly. This variable contains nil for languages which don't have -EOL terminated statements." - t nil - awk 'c-awk-vsemi-status-unknown-p) -(c-lang-defvar c-vsemi-status-unknown-p-fn - (c-lang-const c-vsemi-status-unknown-p-fn)) - ;;; Defun functions @@ -1487,7 +1550,7 @@ EOL terminated statements." ;; end-of-defun-function will be set so that commands like ;; `mark-defun' and `narrow-to-defun' work right. The key sequences ;; C-M-a and C-M-e are, however, bound directly to the CC Mode -;; functions, allowing optimisation for large n. +;; functions, allowing optimization for large n. (c-lang-defconst beginning-of-defun-function "Function to which beginning-of-defun-function will be set." t 'c-beginning-of-defun @@ -1806,7 +1869,7 @@ will be handled." "bindsTo" "delegatesTo" "implements" "proxy" "storedOn") ;; Note: "const" is not used in Java, but it's still a reserved keyword. java '("abstract" "const" "final" "native" "private" "protected" "public" - "static" "strictfp" "synchronized" "transient" "volatile" "@[A-Za-z0-9]+") + "static" "strictfp" "synchronized" "transient" "volatile") pike '("final" "inline" "local" "nomask" "optional" "private" "protected" "public" "static" "variant")) @@ -1892,10 +1955,7 @@ one of `c-type-list-kwds', `c-ref-list-kwds', (c-lang-defconst c-prefix-spec-kwds-re ;; Adorned regexp of `c-prefix-spec-kwds'. - t (c-make-keywords-re t (c-lang-const c-prefix-spec-kwds)) - java (replace-regexp-in-string - "\\\\\\[" "[" - (replace-regexp-in-string "\\\\\\+" "+" (c-make-keywords-re t (c-lang-const c-prefix-spec-kwds))))) + t (c-make-keywords-re t (c-lang-const c-prefix-spec-kwds))) (c-lang-defvar c-prefix-spec-kwds-re (c-lang-const c-prefix-spec-kwds-re)) @@ -1927,6 +1987,21 @@ one of `c-type-list-kwds', `c-ref-list-kwds', (c-lang-defvar c-not-decl-init-keywords (c-lang-const c-not-decl-init-keywords)) +(c-lang-defconst c-not-primitive-type-keywords + "List of all keywords apart from primitive types (like \"int\")." + t (set-difference (c-lang-const c-keywords) + (c-lang-const c-primitive-type-kwds) + :test 'string-equal) + ;; The "more" for C++ is the QT keyword (as in "more slots:"). + ;; This variable is intended for use in c-beginning-of-statement-1. + c++ (append (c-lang-const c-not-primitive-type-keywords) '("more"))) + +(c-lang-defconst c-not-primitive-type-keywords-regexp + t (c-make-keywords-re t + (c-lang-const c-not-primitive-type-keywords))) +(c-lang-defvar c-not-primitive-type-keywords-regexp + (c-lang-const c-not-primitive-type-keywords-regexp)) + (c-lang-defconst c-protection-kwds "Access protection label keywords in classes." t nil @@ -2197,8 +2272,7 @@ This construct is \" :\"." (c-lang-defconst c-label-kwds "Keywords introducing colon terminated labels in blocks." - t '("case" "default") - awk nil) + t '("case" "default")) (c-lang-defconst c-label-kwds-regexp ;; Adorned regexp matching any keyword that introduces a label. @@ -2485,7 +2559,7 @@ Note that Java specific rules are currently applied to tell this from "\\.?[0-9]" "\\|" - ;; The nonambiguous operators from `prefix-ops'. + ;; The unambiguous operators from `prefix-ops'. (c-make-keywords-re nil (set-difference nonkeyword-prefix-ops in-or-postfix-ops :test 'string-equal)) @@ -2636,7 +2710,7 @@ possible for good performance." pos (match-end 0))) res)))) - ;; Allow cpp operatios (where applicable). + ;; Allow cpp operations (where applicable). t (if (c-lang-const c-opt-cpp-prefix) (set-difference (c-lang-const c-block-prefix-disallowed-chars) '(?#)) @@ -2866,6 +2940,12 @@ expression is considered to be a type." (consp (c-lang-const c-<>-arglist-kwds)))) (c-lang-defvar c-recognize-<>-arglists (c-lang-const c-recognize-<>-arglists)) +(c-lang-defconst c-enums-contain-decls + "Non-nil means that an enum structure can contain declarations." + t nil + java t) +(c-lang-defvar c-enums-contain-decls (c-lang-const c-enums-contain-decls)) + (c-lang-defconst c-recognize-paren-inits "Non-nil means that parenthesis style initializers exist, i.e. constructs like @@ -2953,20 +3033,29 @@ neither in a statement nor in a declaration context. The regexp is tested at the beginning of every sexp in a suspected label, i.e. before \":\". Only used if `c-recognize-colon-labels' is set." t (concat - ;; Don't allow string literals. - "\"\\|" ;; All keywords except `c-label-kwds' and `c-protection-kwds'. (c-make-keywords-re t (set-difference (c-lang-const c-keywords) (append (c-lang-const c-label-kwds) (c-lang-const c-protection-kwds)) :test 'string-equal))) + ;; Don't allow string literals, except in AWK. Character constants are OK. + (c objc java pike idl) (concat "\"\\|" + (c-lang-const c-nonlabel-token-key)) ;; Also check for open parens in C++, to catch member init lists in ;; constructors. We normally allow it so that macros with arguments ;; work in labels. - c++ (concat "\\s\(\\|" (c-lang-const c-nonlabel-token-key))) + c++ (concat "\\s\(\\|\"\\|" (c-lang-const c-nonlabel-token-key))) (c-lang-defvar c-nonlabel-token-key (c-lang-const c-nonlabel-token-key)) +(c-lang-defconst c-nonlabel-token-2-key + "Regexp matching things that can't occur two symbols before a colon in +a label construct. This catches C++'s inheritance construct \"class foo +: bar\". Only used if `c-recognize-colon-labels' is set." + t "\\<\\>" ; matches nothing + c++ (c-make-keywords-re t '("class"))) +(c-lang-defvar c-nonlabel-token-2-key (c-lang-const c-nonlabel-token-2-key)) + (c-lang-defconst c-opt-extra-label-key "Optional regexp matching labels. Normally, labels are detected according to `c-nonlabel-token-key',