]> code.delx.au - gnu-emacs/blobdiff - lisp/progmodes/cc-fonts.el
Merge from origin/emacs-25
[gnu-emacs] / lisp / progmodes / cc-fonts.el
index f74e5cbf6783fe64e45b563e163d0c76c825605e..a7097b98c9d29328508cdab7b8136bebacaae3e3 100644 (file)
@@ -1006,8 +1006,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 +1016,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.
@@ -1157,15 +1101,6 @@ casts and declarations are fontified.  Used on level 2 and higher."
          (setq pos (point))))))     ; acts to make the `while' form continue.
   nil)
 
-(defconst c-font-lock-maybe-decl-faces
-  ;; List of faces that might be put at the start of a type when
-  ;; `c-font-lock-declarations' runs.  This needs to be evaluated to
-  ;; ensure that face name aliases in Emacs are resolved.
-  (list nil
-       font-lock-type-face
-       c-reference-face-name
-       font-lock-keyword-face))
-
 (defun c-font-lock-declarations (limit)
   ;; Fontify all the declarations, casts and labels from the point to LIMIT.
   ;; Assumes that strings and comments have been fontified already.
@@ -1256,7 +1191,7 @@ casts and declarations are fontified.  Used on level 2 and higher."
       (c-find-decl-spots
        limit
        c-decl-start-re
-       c-font-lock-maybe-decl-faces
+       (eval c-maybe-decl-faces)
 
        (lambda (match-pos inside-macro)
         ;; Note to maintainers: don't use `limit' inside this lambda form;
@@ -1763,10 +1698,16 @@ 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 (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) ?=))
@@ -1892,7 +1833,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