]> code.delx.au - gnu-emacs/blobdiff - lisp/progmodes/cc-fonts.el
; Merge from origin/emacs-25
[gnu-emacs] / lisp / progmodes / cc-fonts.el
index 03e67a99515e16c14e7815d675b7a229ee41c038..6c348514915444b7616e10f5bcd59724ee40ef06 100644 (file)
@@ -914,7 +914,7 @@ casts and declarations are fontified.  Used on level 2 and higher."
   ;;
   ;; Fontify types and references in names containing angle bracket
   ;; arglists from the point to LIMIT.  Note that
-  ;; `c-font-lock-declarations' already has handled many of them.
+  ;; `c-font-lock-declarations' has already handled many of them.
   ;;
   ;; This function might do hidden buffer changes.
 
@@ -976,11 +976,12 @@ casts and declarations are fontified.  Used on level 2 and higher."
                    (when (and c-opt-identifier-concat-key
                               (not (get-text-property id-start 'face)))
                      (c-forward-syntactic-ws)
-                     (if (looking-at c-opt-identifier-concat-key)
-                         (c-put-font-lock-face id-start id-end
-                                               c-reference-face-name)
-                       (c-put-font-lock-face id-start id-end
-                                             'font-lock-type-face)))))
+                     (cond ((looking-at c-opt-identifier-concat-key)
+                            (c-put-font-lock-face id-start id-end
+                                               c-reference-face-name))
+                           ((eq (char-after) ?\())
+                           (t (c-put-font-lock-face id-start id-end
+                                             'font-lock-type-face))))))
 
                (goto-char pos)))
          (goto-char pos)))))
@@ -1006,8 +1007,9 @@ casts and declarations are fontified.  Used on level 2 and higher."
   ;;(message "c-font-lock-declarators from %s to %s" (point) limit)
   (c-fontify-types-and-refs
       ((pos (point)) next-pos id-start id-end
+       decl-res
        paren-depth
-       id-face got-init
+       id-face got-type got-init
        c-last-identifier-range
        (separator-prop (if types 'c-decl-type-start 'c-decl-id-start))
        brackets-after-id)
@@ -1015,93 +1017,36 @@ casts and declarations are fontified.  Used on level 2 and higher."
     ;; The following `while' fontifies a single declarator id each time round.
     ;; It loops only when LIST is non-nil.
     (while
-       ;; Inside the following "condition form", we move forward over the
-       ;; declarator's identifier up as far as any opening bracket (for array
-       ;; size) or paren (for parameters of function-type) or brace (for
-       ;; array/struct initialization) or "=" or terminating delimiter
-       ;; (e.g. "," or ";" or "}").
-       (and
-           pos
-           (< (point) limit)
-
-           ;; The following form moves forward over the declarator's
-           ;; identifier (and what precedes it), returning t.  If there
-           ;; wasn't one, it returns nil, terminating the `while'.
-           (let (got-identifier)
-             (setq paren-depth 0)
-             ;; Skip over type decl prefix operators, one for each iteration
-             ;; of the while.  These are, e.g. "*" in "int *foo" or "(" and
-             ;; "*" in "int (*foo) (void)" (Note similar code in
-             ;; `c-forward-decl-or-cast-1'.)
-             (while (and (looking-at c-type-decl-prefix-key)
-                         (if (and (c-major-mode-is 'c++-mode)
-                                  (match-beginning 3))
-                             ;; If the third submatch matches in C++ then
-                             ;; we're looking at an identifier that's a
-                             ;; prefix only if it specifies a member pointer.
-                             (progn
-                               (setq id-start (point))
-                               (c-forward-name)
-                               (if (looking-at "\\(::\\)")
-                                   ;; We only check for a trailing "::" and
-                                   ;; let the "*" that should follow be
-                                   ;; matched in the next round.
-                                   t
-                                 ;; It turned out to be the real identifier,
-                                 ;; so flag that and stop.
-                                 (setq got-identifier t)
-                                 nil))
-                           t))
-               (if (eq (char-after) ?\()
-                   (progn
-                     (setq paren-depth (1+ paren-depth))
-                     (forward-char))
-                 (goto-char (match-end 1)))
-               (c-forward-syntactic-ws))
-
-             ;; If we haven't passed the identifier already, do it now.
-             (unless got-identifier
-               (setq id-start (point))
-               (c-forward-name))
-             (setq id-end (point))
-
-             (/= id-end pos))
-
-           ;; Skip out of the parens surrounding the identifier.  If closing
-           ;; parens are missing, this form returns nil.
-           (or (= paren-depth 0)
-               (c-safe (goto-char (scan-lists (point) 1 paren-depth))))
-
-           (<= (point) limit)
-
-           ;; Skip over any trailing bit, such as "__attribute__".
-           (progn
-             (when (looking-at c-decl-hangon-key)
-               (c-forward-keyword-clause 1))
-             (<= (point) limit))
-
-           ;; Search syntactically to the end of the declarator (";",
-           ;; ",", a closing paren, eob etc) or to the beginning of an
-           ;; initializer or function prototype ("=" or "\\s(").
-           ;; Note that square brackets are now not also treated as
-           ;; initializers, since this broke when there were also
-           ;; initializing brace lists.
-           (let (found)
-             (while
-                 (and (setq found (c-syntactic-re-search-forward
-                            "[;,]\\|\\s)\\|\\'\\|\\(=\\|\\s(\\)" limit t t))
-                      (eq (char-before) ?\[)
-                      (c-go-up-list-forward))
-                    (setq brackets-after-id t))
-             found))
-
-      (setq next-pos (match-beginning 0)
-           id-face (if (and (eq (char-after next-pos) ?\()
-                            (not brackets-after-id))
+       (and pos (setq decl-res (c-forward-declarator limit)))
+      (setq next-pos (point)
+           id-start (car decl-res)
+           id-face (if (and (eq (char-after) ?\()
+                            (not (car (cddr decl-res))) ; brackets-after-id
+                            (or (not (c-major-mode-is 'c++-mode))
+                                (save-excursion
+                                  (let (c-last-identifier-range)
+                                    (forward-char)
+                                    (c-forward-syntactic-ws)
+                                    (catch 'is-function
+                                      (while
+                                          (progn
+                                            (if (eq (char-after) ?\))
+                                                (throw 'is-function t))
+                                            (setq got-type (c-forward-type))
+                                            (cond
+                                             ((null got-type)
+                                              (throw 'is-function nil))
+                                             ((not (eq got-type 'maybe))
+                                              (throw 'is-function t)))
+                                            (c-forward-declarator limit t)
+                                            (eq (char-after) ?,))
+                                        (forward-char)
+                                        (c-forward-syntactic-ws))
+                                      t)))))
                        'font-lock-function-name-face
                      'font-lock-variable-name-face)
-           got-init (and (match-beginning 1)
-                         (char-after (match-beginning 1))))
+           got-init (and (cadr (cddr decl-res)) ; got-init
+                         (char-after)))
 
       (if types
          ;; Register and fontify the identifier as a type.
@@ -1260,8 +1205,20 @@ casts and declarations are fontified.  Used on level 2 and higher."
                           'font-lock-keyword-face)
                       (looking-at c-not-decl-init-keywords))
                  (and c-macro-with-semi-re
-                      (looking-at c-macro-with-semi-re))) ; 2008-11-04
-             ;; Don't do anything more if we're looking at a keyword that
+                      (looking-at c-macro-with-semi-re)) ; 2008-11-04
+                 (save-excursion ; A construct after a ; in a `for' statement
+                                 ; can't be a declaration.
+                   (and (c-go-up-list-backward)
+                        (eq (char-after) ?\()
+                        (progn (c-backward-syntactic-ws)
+                               (c-simple-skip-symbol-backward))
+                        (looking-at c-paren-stmt-key)
+                        (progn (goto-char match-pos)
+                               (while (and (eq (char-before) ?\))
+                                           (c-go-list-backward))
+                                 (c-backward-syntactic-ws))
+                               (eq (char-before) ?\;)))))
+             ;; Don't do anything more if we're looking at something that
              ;; can't start a declaration.
              t
 
@@ -1754,10 +1711,18 @@ on level 2 only and so aren't combined with `c-complex-decl-matchers'."
                        (unless (c-skip-comments-and-strings limit)
                          (c-forward-syntactic-ws)
                          ;; Handle prefix declaration specifiers.
-                         (when (or (looking-at c-prefix-spec-kwds-re)
-                                   (and (c-major-mode-is 'java-mode)
-                                        (looking-at "@[A-Za-z0-9]+")))
-                           (c-forward-keyword-clause 1))
+                         (while
+                             (or
+                              (when (or (looking-at c-prefix-spec-kwds-re)
+                                        (and (c-major-mode-is 'java-mode)
+                                             (looking-at "@[A-Za-z0-9]+")))
+                                (c-forward-keyword-clause 1)
+                                t)
+                              (when (and c-opt-cpp-prefix
+                                         (looking-at
+                                          c-noise-macro-with-parens-name-re))
+                                (c-forward-noise-clause)
+                                t)))
                          ,(if (c-major-mode-is 'c++-mode)
                               `(when (and (c-forward-type)
                                           (eq (char-after) ?=))
@@ -1883,7 +1848,7 @@ higher."
                "\\)\\>"
                ;; Disallow various common punctuation chars that can't come
                ;; before the '{' of the enum list, to avoid searching too far.
-               "[^][{}();/#=]*"
+               "[^][{};/#=]*"
                "{")
               '((c-font-lock-declarators limit t nil)
                 (save-match-data