]> code.delx.au - gnu-emacs/blobdiff - lisp/progmodes/cc-langs.el
Merge from emacs-23; up to 2010-06-11T21:26:13Z!lekktu@gmail.com.
[gnu-emacs] / lisp / progmodes / cc-langs.el
index 4f706fc0fa76b0c9753b5c2801652247330567d9..86a963bcf558b2f26496a4fb56364cc6fbdddcef 100644 (file)
@@ -1,18 +1,17 @@
 ;;; cc-langs.el --- language specific settings for CC Mode
 
-;; Copyright (C) 1985, 1987, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
-;;   1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008
-;;   Free Software Foundation, Inc.
+;; Copyright (C) 1985, 1987, 1992-2011  Free Software Foundation, Inc.
 
 ;; Authors:    2002- Alan Mackenzie
 ;;             1998- Martin Stjernholm
 ;;             1992-1999 Barry A. Warsaw
-;;             1987 Dave Detlefs and Stewart Clamen
+;;             1987 Dave Detlefs
+;;             1987 Stewart Clamen
 ;;             1985 Richard M. Stallman
 ;; Maintainer: bug-cc-mode@gnu.org
 ;; Created:    22-Apr-1997 (split from cc-mode.el)
-;; Version:    See cc-mode.el
-;; Keywords:   c languages oop
+;; Keywords:   c languages
+;; Package:    cc-mode
 
 ;; This file is part of GNU Emacs.
 
 
 ;;; Code:
 
+;; For Emacs < 22.2.
+(eval-and-compile
+  (unless (fboundp 'declare-function) (defmacro declare-function (&rest r))))
+
 (eval-when-compile
   (let ((load-path
         (if (and (boundp 'byte-compile-dest-file)
@@ -203,6 +206,12 @@ the evaluated constant value at compile time."
 (def-edebug-spec c-lang-defvar
   (&define name def-form &optional stringp)) ;)
 
+;; Suppress "might not be defined at runtime" warning.
+;; This file is only used when compiling other cc files.
+(declare-function delete-duplicates "cl-seq" (cl-seq &rest cl-keys))
+(declare-function mapcan "cl-extra" (cl-func cl-seq &rest cl-rest))
+(declare-function cl-macroexpand-all "cl-extra" (form &optional env))
+
 (eval-and-compile
   ;; Some helper functions used when building the language constants.
 
@@ -295,9 +304,9 @@ the evaluated constant value at compile time."
        :style toggle :selected c-auto-newline]
        ["Hungry delete"         c-toggle-hungry-state
        :style toggle :selected c-hungry-delete-key]
-       ["Subword mode"          c-subword-mode
-       :style toggle :selected (and (boundp 'c-subword-mode)
-                                     c-subword-mode)])))
+       ["Subword mode"          subword-mode
+       :style toggle :selected (and (boundp 'subword-mode)
+                                     subword-mode)])))
 
 \f
 ;;; Syntax tables.
@@ -348,7 +357,7 @@ The syntax tables aren't stored directly since they're quite large."
        (let ((table (make-syntax-table)))
         (c-populate-syntax-table table)
         ;; Mode specific syntaxes.
-        ,(cond ((c-major-mode-is 'objc-mode)
+        ,(cond ((or (c-major-mode-is 'objc-mode) (c-major-mode-is 'java-mode))
                 ;; Let '@' be part of symbols in ObjC to cope with
                 ;; its compiler directives as single keyword tokens.
                 ;; This is then necessary since it's assumed that
@@ -371,7 +380,7 @@ The syntax tables aren't stored directly since they're quite large."
   ;; '<' and '>' characters.  Therefore this syntax table might go
   ;; away when CC Mode handles templates correctly everywhere.
   t   nil
-  c++ `(lambda ()
+  (java c++) `(lambda ()
         (let ((table (funcall ,(c-lang-const c-make-mode-syntax-table))))
           (modify-syntax-entry ?< "(>" table)
           (modify-syntax-entry ?> ")<" table)
@@ -380,6 +389,27 @@ The syntax tables aren't stored directly since they're quite large."
   (and (c-lang-const c++-make-template-syntax-table)
        (funcall (c-lang-const c++-make-template-syntax-table))))
 
+(c-lang-defconst c-no-parens-syntax-table
+  ;; A variant of the standard syntax table which is used to find matching
+  ;; "<"s and ">"s which have been marked as parens using syntax table
+  ;; properties.  The other paren characters (e.g. "{", ")" "]") are given a
+  ;; non-paren syntax here. so that the list commands will work on "< ... >"
+  ;; even when there's unbalanced other parens inside them.
+  ;;
+  ;; This variable is nil for languages which don't have template stuff.
+  t  `(lambda ()
+       (if (c-lang-const c-recognize-<>-arglists)
+           (let ((table (funcall ,(c-lang-const c-make-mode-syntax-table))))
+             (modify-syntax-entry ?\( "." table)
+             (modify-syntax-entry ?\) "." table)
+             (modify-syntax-entry ?\[ "." table)
+             (modify-syntax-entry ?\] "." table)
+             (modify-syntax-entry ?\{ "." table)
+             (modify-syntax-entry ?\} "." table)
+             table))))
+(c-lang-defvar c-no-parens-syntax-table
+              (funcall (c-lang-const c-no-parens-syntax-table)))
+
 (c-lang-defconst c-identifier-syntax-modifications
   "A list that describes the modifications that should be done to the
 mode syntax table to get a syntax table that matches all identifiers
@@ -393,7 +423,7 @@ the new syntax, as accepted by `modify-syntax-entry'."
   ;; it as an indentifier character since it's often used in various
   ;; machine generated identifiers.
   t    '((?_ . "w") (?$ . "w"))
-  objc (append '((?@ . "w"))
+  (objc java) (append '((?@ . "w"))
               (c-lang-const c-identifier-syntax-modifications))
   awk  '((?_ . "w")))
 (c-lang-defvar c-identifier-syntax-modifications
@@ -412,26 +442,36 @@ the new syntax, as accepted by `modify-syntax-entry'."
 classifies symbol constituents like '_' and '$' as word constituents,
 so that all identifiers are recognized as words.")
 
-(c-lang-defconst c-get-state-before-change-function
-  "If non-nil, a function called from c-before-change-hook.
-Typically it will record enough state to allow
+(c-lang-defconst c-get-state-before-change-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 nil
+  c++ '(c-extend-region-for-CPP c-before-change-check-<>-operators)
+  (c objc) 'c-extend-region-for-CPP
+  ;; java 'c-before-change-check-<>-operators
+  awk 'c-awk-record-region-clear-NL)
+(c-lang-defvar c-get-state-before-change-functions
+              (let ((fs (c-lang-const c-get-state-before-change-functions)))
+                 (if (listp fs)
+                     fs
+                   (list fs)))
+  "If non-nil, a list of functions called from c-before-change-hook.
+Typically these will record enough state to allow
 `c-before-font-lock-function' to extend the region to fontify,
 and may do such things as removing text-properties which must be
 recalculated.
 
-It takes 2 parameters, the BEG and END supplied to every
+These functions will be run in the order given.  Each of them
+takes 2 parameters, the BEG and END supplied to every
 before-change function; on entry, the buffer will have been
 widened and match-data will have been saved; point is undefined
 on both entry and exit; the return value is ignored.
 
-When the mode is initialized, this function is called with
-parameters \(point-min) and \(point-max)."
-  t nil
-  (c c++ objc) 'c-extend-region-for-CPP
-  awk 'c-awk-record-region-clear-NL)
-(c-lang-defvar c-get-state-before-change-function
-              (c-lang-const c-get-state-before-change-function))
-  
+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
@@ -450,7 +490,7 @@ The function is called even when font locking is disabled.
 When the mode is initialized, this function is called with
 parameters \(point-min), \(point-max) and <buffer size>."
   t nil
-  (c c++ objc) 'c-neutralize-syntax-in-CPP
+  (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))
@@ -460,9 +500,10 @@ parameters \(point-min), \(point-max) and <buffer size>."
 
 (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 \\|
+keyword.  It's unspecified how far it matches. Does not contain a \\|
 operator at the top level."
   t    (concat "[" c-alpha "_]")
+  java (concat "[" c-alpha "_@]")
   objc (concat "[" c-alpha "@]")
   pike (concat "[" c-alpha "_`]"))
 (c-lang-defvar c-symbol-start (c-lang-const c-symbol-start))
@@ -817,7 +858,7 @@ since CC Mode treats every identifier as an expression."
 
       ;; Primary.
       ,@(c-lang-const c-identifier-ops)
-      ,@(cond ((c-major-mode-is 'c++-mode)
+      ,@(cond ((or (c-major-mode-is 'c++-mode) (c-major-mode-is 'java-mode))
               `((postfix-if-paren "<" ">"))) ; Templates.
              ((c-major-mode-is 'pike-mode)
               `((prefix "global" "predef")))
@@ -985,7 +1026,7 @@ This regexp is assumed to not match any non-operator identifier."
 ;; Note: the following alias is an old name which was a mis-spelling.  It has
 ;; been corrected above and throughout cc-engine.el.  It will be removed at
 ;; some release very shortly in the future.  ACM, 2006-04-14.
-(defalias 'c-opt-op-identitier-prefix 'c-opt-op-identifier-prefix)
+(defvaralias 'c-opt-op-identitier-prefix 'c-opt-op-identifier-prefix)
 (make-obsolete-variable 'c-opt-op-identitier-prefix 'c-opt-op-identifier-prefix
                        "CC Mode 5.31.4, 2006-04-14")
 
@@ -1076,6 +1117,7 @@ operators."
                    t
                    "\\`<."
                    (lambda (op) (substring op 1)))))
+
 (c-lang-defvar c-<-op-cont-regexp (c-lang-const c-<-op-cont-regexp))
 
 (c-lang-defconst c->-op-cont-regexp
@@ -1085,7 +1127,13 @@ operators."
       (c-filter-ops (c-lang-const c-all-op-syntax-tokens)
                    t
                    "\\`>."
-                   (lambda (op) (substring op 1)))))
+                   (lambda (op) (substring op 1))))
+  java (c-make-keywords-re nil
+        (c-filter-ops (c-lang-const c-all-op-syntax-tokens)
+                      t
+                      "\\`>[^>]\\|\\`>>[^>]"
+                      (lambda (op) (substring op 1)))))
+
 (c-lang-defvar c->-op-cont-regexp (c-lang-const c->-op-cont-regexp))
 
 (c-lang-defconst c-stmt-delim-chars
@@ -1515,6 +1563,17 @@ be a subset of `c-primitive-type-kwds'."
            ;; In CORBA PSDL:
            "strong"))
 
+(c-lang-defconst c-typedef-kwds
+  "Prefix keyword\(s\) like \"typedef\" which make a type declaration out
+of a variable declaration."
+  t        '("typedef")
+  (awk idl java) nil)
+
+(c-lang-defconst c-typedef-key
+  ;; Adorned regexp matching `c-typedef-kwds'.
+  t (c-make-keywords-re t (c-lang-const c-typedef-kwds)))
+(c-lang-defvar c-typedef-key (c-lang-const c-typedef-key))
+
 (c-lang-defconst c-type-prefix-kwds
   "Keywords where the following name - if any - is a type name, and
 where the keyword together with the symbol works as a type in
@@ -1586,7 +1645,7 @@ following identifier as a type; the keyword must also be present on
   c++  '("class" "struct" "union")
   objc '("struct" "union"
         "@interface" "@implementation" "@protocol")
-  java '("class" "interface")
+  java '("class" "@interface" "interface")
   idl  '("component" "eventtype" "exception" "home" "interface" "struct"
         "union" "valuetype"
         ;; In CORBA PSDL:
@@ -1609,7 +1668,7 @@ If any of these also are on `c-type-list-kwds', `c-ref-list-kwds',
 `c-<>-type-kwds', or `c-<>-arglist-kwds' then the associated clauses
 will be handled."
   t    '("enum")
-  (java awk) nil)
+  (awk) nil)
 
 (c-lang-defconst c-brace-list-key
   ;; Regexp matching the start of declarations where the following
@@ -1681,6 +1740,10 @@ will be handled."
   ;; types in IDL since they only can occur in "raises" specs.
   idl  (delete "exception" (append (c-lang-const c-typedef-decl-kwds) nil)))
 
+(c-lang-defconst c-typedef-decl-key
+  t  (c-make-keywords-re t (c-lang-const c-typedef-decl-kwds)))
+(c-lang-defvar c-typedef-decl-key (c-lang-const c-typedef-decl-key))
+
 (c-lang-defconst c-typeless-decl-kwds
   "Keywords introducing declarations where the \(first) identifier
 \(declarator) follows directly after the keyword, without any type.
@@ -1730,7 +1793,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")
+        "static" "strictfp" "synchronized" "transient" "volatile" "@[A-Za-z0-9]+")
   pike '("final" "inline" "local" "nomask" "optional" "private" "protected"
         "public" "static" "variant"))
 
@@ -1816,7 +1879,11 @@ 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)))
+  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)))))
+
 (c-lang-defvar c-prefix-spec-kwds-re (c-lang-const c-prefix-spec-kwds-re))
 
 (c-lang-defconst c-specifier-key
@@ -1908,7 +1975,7 @@ or variable identifier (that's being defined)."
   t    nil
   c++  '("operator")
   objc '("@class")
-  java '("import" "new" "extends" "implements" "throws")
+  java '("import" "new" "extends" "super" "implements" "throws")
   idl  '("manages" "native" "primarykey" "supports"
         ;; In CORBA PSDL:
         "as" "implements" "of" "scope")
@@ -2104,6 +2171,17 @@ nevertheless contains a list separated with ';' and not ','."
        (c-make-keywords-re t (c-lang-const c-asm-stmt-kwds))))
 (c-lang-defvar c-opt-asm-stmt-key (c-lang-const c-opt-asm-stmt-key))
 
+(c-lang-defconst c-case-kwds
+  "The keyword\(s) which introduce a \"case\" like construct.
+This construct is \"<keyword> <expression> :\"."
+  t '("case")
+  awk nil)
+
+(c-lang-defconst c-case-kwds-regexp
+  ;; Adorned regexp matching any "case"-like keyword.
+  t (c-make-keywords-re t (c-lang-const c-case-kwds)))
+(c-lang-defvar c-case-kwds-regexp (c-lang-const c-case-kwds-regexp))
+
 (c-lang-defconst c-label-kwds
   "Keywords introducing colon terminated labels in blocks."
   t '("case" "default")
@@ -2127,7 +2205,7 @@ nevertheless contains a list separated with ';' and not ','."
   t       nil
   (c c++) '("NULL" ;; Not a keyword, but practically works as one.
            "false" "true")             ; Defined in C99.
-  objc    '("nil" "Nil")
+  objc    '("nil" "Nil" "YES" "NO" "NS_DURING" "NS_HANDLER" "NS_ENDHANDLER")
   idl     '("TRUE" "FALSE")
   java    '("true" "false" "null") ; technically "literals", not keywords
   pike    '("UNDEFINED")) ;; Not a keyword, but practically works as one.
@@ -2446,7 +2524,7 @@ more info."
   ;; in all languages except Java for when a cpp macro definition
   ;; begins with a declaration.
   t "\\([\{\}\(\);,]+\\)"
-  java "\\([\{\}\(;,]+\\)"
+  java "\\([\{\}\(;,<]+\\)"
   ;; Match "<" in C++ to get the first argument in a template arglist.
   ;; In that case there's an additional check in `c-find-decl-spots'
   ;; that it got open paren syntax.
@@ -2596,15 +2674,15 @@ Identifier syntax is in effect when this is matched \(see
   c++  (concat "\\("
               "[*\(&]"
               "\\|"
-              (concat "\\("    ; 2
+              (c-lang-const c-type-decl-prefix-key)
+              "\\|"
+              (concat "\\("   ; 3
                       ;; If this matches there's special treatment in
                       ;; `c-font-lock-declarators' and
                       ;; `c-font-lock-declarations' that check for a
                       ;; complete name followed by ":: *".
                       (c-lang-const c-identifier-start)
                       "\\)")
-              "\\|"
-              (c-lang-const c-type-decl-prefix-key)
               "\\)"
               "\\([^=]\\|$\\)")
   pike "\\(\\*\\)\\([^=]\\|$\\)")
@@ -2706,7 +2784,7 @@ It's undefined whether identifier syntax (see `c-identifier-syntax-table')
 is in effect or not."
   t nil
   (c c++ objc pike) "\\(\\.\\.\\.\\)"
-  java (concat "\\(\\[" (c-lang-const c-simple-ws) "*\\]\\)"))
+  java (concat "\\(\\[" (c-lang-const c-simple-ws) "*\\]\\|\\.\\.\\.\\)"))
 (c-lang-defvar c-opt-type-suffix-key (c-lang-const c-opt-type-suffix-key))
 
 (c-lang-defvar c-known-type-key
@@ -2863,7 +2941,7 @@ 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)
@@ -3057,5 +3135,4 @@ evaluated and should not be quoted."
 \f
 (cc-provide 'cc-langs)
 
-;; arch-tag: 1ab57482-cfc2-4c5b-b628-3539c3098822
 ;;; cc-langs.el ends here