]> code.delx.au - gnu-emacs/blobdiff - lisp/progmodes/cc-fonts.el
(cperl-find-bad-style): Use with-no-warnings.
[gnu-emacs] / lisp / progmodes / cc-fonts.el
index bab838a22d104a45be6ef84a644060cc03162ea1..c5bbfaf86dd05909e5505bce3aa425f077bf8ad7 100644 (file)
@@ -514,26 +514,21 @@ stuff.  Used on level 1 and higher."
 (defun c-font-lock-invalid-string ()
   ;; Assuming the point is after the opening character of a string,
   ;; fontify that char with `c-invalid-face-name' if the string
-  ;; decidedly isn't terminated properly.  Assumes the string already
-  ;; is syntactically fontified.
-  (let ((end (1+ (c-point 'eol))))
-    (and (eq (get-text-property (point) 'face) 'font-lock-string-face)
-        (= (next-single-property-change (point) 'face nil end) end)
-        ;; We're at eol inside a string.  The first check above is
-        ;; necessary in XEmacs since it doesn't fontify the string
-        ;; delimiters themselves.  Thus an empty string won't have
-        ;; the string face anywhere.
-        (if (c-major-mode-is '(c-mode c++-mode objc-mode pike-mode))
-            ;; There's no \ before the newline.
-            (not (eq (char-before (1- end)) ?\\))
-          ;; Quoted newlines aren't supported.
-          t)
-        (if (c-major-mode-is 'pike-mode)
-            ;; There's no # before the string, so newlines
-            ;; aren't allowed.
-            (not (eq (char-before (1- (point))) ?#))
-          t)
-        (c-put-font-lock-face (1- (point)) (point) c-invalid-face-name))))
+  ;; decidedly isn't terminated properly.
+  (let ((start (1- (point))))
+    (save-excursion
+      (and (nth 3 (parse-partial-sexp start (c-point 'eol)))
+          (if (c-major-mode-is '(c-mode c++-mode objc-mode pike-mode))
+              ;; There's no \ before the newline.
+              (not (eq (char-before (point)) ?\\))
+            ;; Quoted newlines aren't supported.
+            t)
+          (if (c-major-mode-is 'pike-mode)
+              ;; There's no # before the string, so newlines
+              ;; aren't allowed.
+              (not (eq (char-before start) ?#))
+            t)
+          (c-put-font-lock-face start (1+ start) c-invalid-face-name)))))
 
 (c-lang-defconst c-basic-matchers-before
   "Font lock matchers for basic keywords, labels, references and various
@@ -579,33 +574,65 @@ casts and declarations are fontified.  Used on level 2 and higher."
       ;; Fontify leading identifiers in fully qualified names like
       ;; "foo::bar" in languages that supports such things.
       ,@(when (c-lang-const c-opt-identifier-concat-key)
-         `((,(byte-compile
-              ;; Must use a function here since we match longer
-              ;; than we want to move before doing a new search.
-              ;; This is not necessary for XEmacs >= 20 since it
-              ;; restarts the search from the end of the first
-              ;; highlighted submatch (something that causes
-              ;; problems in other places).
-              `(lambda (limit)
-                 (while (re-search-forward
-                         ,(concat "\\(\\<" ; 1
-                                  "\\(" (c-lang-const c-symbol-key) "\\)" ; 2
-                                  "[ \t\n\r\f\v]*"
-                                  (c-lang-const c-opt-identifier-concat-key)
-                                  "[ \t\n\r\f\v]*"
-                                  "\\)"
-                                  "\\("
-                                  (c-lang-const c-opt-after-id-concat-key)
-                                  "\\)")
-                         limit t)
-                   (unless (progn
-                             (goto-char (match-beginning 0))
-                             (c-skip-comments-and-strings limit))
-                     (or (get-text-property (match-beginning 2) 'face)
-                         (c-put-font-lock-face (match-beginning 2)
-                                               (match-end 2)
-                                               c-reference-face-name))
-                     (goto-char (match-end 1)))))))))
+         (if (c-major-mode-is 'java-mode)
+             ;; Java needs special treatment since "." is used both to
+             ;; qualify names and in normal indexing.  Here we look for
+             ;; capital characters at the beginning of an identifier to
+             ;; recognize the class.  "*" is also recognized to cover
+             ;; wildcard import declarations.  All preceding dot separated
+             ;; identifiers are taken as package names and therefore
+             ;; fontified as references.
+             `(,(c-make-font-lock-search-function
+                 ;; Search for class identifiers preceded by ".".  The
+                 ;; anchored matcher takes it from there.
+                 (concat (c-lang-const c-opt-identifier-concat-key)
+                         "[ \t\n\r\f\v]*"
+                         (concat "\\("
+                                 "[" c-upper "][" (c-lang-const c-symbol-chars) "]*"
+                                 "\\|"
+                                 "\\*"
+                                 "\\)"))
+                 `((let (id-end)
+                     (goto-char (1+ (match-beginning 0)))
+                     (while (and (eq (char-before) ?.)
+                                 (progn
+                                   (backward-char)
+                                   (c-backward-syntactic-ws)
+                                   (setq id-end (point))
+                                   (< (skip-chars-backward
+                                       ,(c-lang-const c-symbol-chars)) 0))
+                                 (not (get-text-property (point) 'face)))
+                       (c-put-font-lock-face (point) id-end c-reference-face-name)
+                       (c-backward-syntactic-ws)))
+                   nil
+                   (goto-char (match-end 0)))))
+
+           `((,(byte-compile
+                ;; Must use a function here since we match longer than we
+                ;; want to move before doing a new search.  This is not
+                ;; necessary for XEmacs >= 20 since it restarts the search
+                ;; from the end of the first highlighted submatch (something
+                ;; that causes problems in other places).
+                `(lambda (limit)
+                   (while (re-search-forward
+                           ,(concat "\\(\\<" ; 1
+                                    "\\(" (c-lang-const c-symbol-key) "\\)" ; 2
+                                    "[ \t\n\r\f\v]*"
+                                    (c-lang-const c-opt-identifier-concat-key)
+                                    "[ \t\n\r\f\v]*"
+                                    "\\)"
+                                    "\\("
+                                    (c-lang-const c-opt-after-id-concat-key)
+                                    "\\)")
+                           limit t)
+                     (unless (progn
+                               (goto-char (match-beginning 0))
+                               (c-skip-comments-and-strings limit))
+                       (or (get-text-property (match-beginning 2) 'face)
+                           (c-put-font-lock-face (match-beginning 2)
+                                                 (match-end 2)
+                                                 c-reference-face-name))
+                       (goto-char (match-end 1))))))))))
 
       ;; Fontify the special declarations in Objective-C.
       ,@(when (c-major-mode-is 'objc-mode)
@@ -792,17 +819,19 @@ casts and declarations are fontified.  Used on level 2 and higher."
            (<= (point) limit)
 
            ;; Search syntactically to the end of the declarator (";",
-           ;; ",", ")", ">" (for <> arglists), eob etc) or to the
-           ;; beginning of an initializer or function prototype ("="
-           ;; or "\\s\(").
+           ;; ",", a closen paren, eob etc) or to the beginning of an
+           ;; initializer or function prototype ("=" or "\\s\(").
+           ;; Note that the open paren will match array specs in
+           ;; square brackets, and we treat them as initializers too.
            (c-syntactic-re-search-forward
-            "[\];,\{\}\[\)>]\\|\\'\\|\\(=\\|\\(\\s\(\\)\\)" limit t t))
+            "[;,]\\|\\s)\\|\\'\\|\\(=\\|\\s(\\)" limit t t))
 
       (setq next-pos (match-beginning 0)
-           id-face (if (match-beginning 2)
+           id-face (if (eq (char-after next-pos) ?\()
                        'font-lock-function-name-face
                      'font-lock-variable-name-face)
-           got-init (match-beginning 1))
+           got-init (and (match-beginning 1)
+                         (char-after (match-beginning 1))))
 
       (if types
          ;; Register and fontify the identifer as a type.
@@ -833,9 +862,17 @@ casts and declarations are fontified.  Used on level 2 and higher."
                 (goto-char limit)))
 
              (got-init
-              ;; Skip an initializer expression.
-              (if (c-syntactic-re-search-forward "[;,]" limit 'move t)
-                  (backward-char)))
+              ;; Skip an initializer expression.  If we're at a '='
+              ;; then accept a brace list directly after it to cope
+              ;; with array initializers.  Otherwise stop at braces
+              ;; to avoid going past full function and class blocks.
+              (and (if (and (eq got-init ?=)
+                            (= (c-forward-token-2) 0)
+                            (looking-at "{"))
+                       (c-safe (c-forward-sexp) t)
+                     t)
+                   (c-syntactic-re-search-forward "[;,{]" limit 'move t)
+                   (backward-char)))
 
              (t (c-forward-syntactic-ws limit)))
 
@@ -899,7 +936,7 @@ casts and declarations are fontified.  Used on level 2 and higher."
 
   (save-restriction
     (let (start-pos
-         c-disallow-comma-in-<>-arglists
+         c-restricted-<>-arglists
          ;; Nonzero if the `c-decl-prefix-re' match is in an arglist context,
          ;; as opposed to a statement-level context.  The major difference is
          ;; that "," works as declaration delimiter in an arglist context,
@@ -1055,11 +1092,11 @@ casts and declarations are fontified.  Used on level 2 and higher."
                 ;; If we're in a normal arglist context we don't want to
                 ;; recognize commas in nested angle bracket arglists since
                 ;; those commas could be part of our own arglist.
-                c-disallow-comma-in-<>-arglists
+                c-restricted-<>-arglists
                 (and c-recognize-<>-arglists
                      (eq arglist-type 'other)))
 
-          (when (and c-disallow-comma-in-<>-arglists
+          (when (and c-restricted-<>-arglists
                      (/= arglist-match ?,))
             ;; We're standing at the start of a normal arglist so remove any
             ;; angle bracket arglists containing commas that's been
@@ -1497,15 +1534,21 @@ casts and declarations are fontified.  Used on level 2 and higher."
                           ;; identifier as a type and then backed up again in
                           ;; this case.
                           identifier-type
-                          (or (eq identifier-type 'found)
+                          (or (memq identifier-type '(found known))
                               (and (eq (char-after identifier-start) ?~)
                                    ;; `at-type' probably won't be 'found for
                                    ;; destructors since the "~" is then part
                                    ;; of the type name being checked against
                                    ;; the list of known types, so do a check
                                    ;; without that operator.
-                                   (c-check-type (1+ identifier-start)
-                                                 identifier-end))))
+                                   (or (save-excursion
+                                         (goto-char (1+ identifier-start))
+                                         (c-forward-syntactic-ws)
+                                         (c-with-syntax-table
+                                             c-identifier-syntax-table
+                                           (looking-at c-known-type-key)))
+                                       (c-check-type (1+ identifier-start)
+                                                     identifier-end)))))
                  (throw 'at-decl-or-cast t))
 
                (if got-identifier
@@ -2877,4 +2920,5 @@ std\\(err\\|in\\|out\\)\\|user\\)\\)\\>\
 \f
 (cc-provide 'cc-fonts)
 
+;;; arch-tag: 2f65f405-735f-4da5-8d4b-b957844c5203
 ;;; cc-fonts.el ends here