emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master 9bda21ad0dd: CC Mode: Handle noise clauses, template arglists in


From: Alan Mackenzie
Subject: master 9bda21ad0dd: CC Mode: Handle noise clauses, template arglists in any order
Date: Thu, 23 Nov 2023 11:34:41 -0500 (EST)

branch: master
commit 9bda21ad0dddc5d84b6fca269626adeaa608b7a1
Author: Alan Mackenzie <acm@muc.de>
Commit: Alan Mackenzie <acm@muc.de>

    CC Mode: Handle noise clauses, template arglists in any order
    
    This fixes the first part of bug#66911.
    
    * lisp/progmodes/cc-engine.el (c-looking-at-decl-block): Skip
    back over template arglists and noise clauses in any order, no
    longer assuming the noise clauses are before the template
    arglist in the buffer.  When scanning forward, take noise
    clauses into account.  Refactor a collection of nested `if'
    forms as a cond form.
---
 lisp/progmodes/cc-engine.el | 117 ++++++++++++++++++++++++--------------------
 1 file changed, 63 insertions(+), 54 deletions(-)

diff --git a/lisp/progmodes/cc-engine.el b/lisp/progmodes/cc-engine.el
index f5e0d21108f..1fc02d1ad07 100644
--- a/lisp/progmodes/cc-engine.el
+++ b/lisp/progmodes/cc-engine.el
@@ -12617,31 +12617,27 @@ comment at the start of cc-engine.el for more info."
   (let ((open-brace (point)) kwd-start first-specifier-pos)
     (c-syntactic-skip-backward c-block-prefix-charset limit t)
 
-    (when (and c-recognize-<>-arglists
-              (eq (char-before) ?>))
-      ;; Could be at the end of a template arglist.
-      (let ((c-parse-and-markup-<>-arglists t))
-       (while (and
-               (c-backward-<>-arglist nil limit)
-               (progn
-                 (c-syntactic-skip-backward c-block-prefix-charset limit t)
-                 (eq (char-before) ?>))))))
-
-    ;; Skip back over noise clauses.
-    (while (and
-           c-opt-cpp-prefix
-           (eq (char-before) ?\))
-           (let ((after-paren (point)))
-             (if (and (c-go-list-backward)
-                      (progn (c-backward-syntactic-ws)
-                             (c-simple-skip-symbol-backward))
-                      (or (looking-at c-paren-nontype-key)
-                          (looking-at c-noise-macro-with-parens-name-re)))
-                 (progn
-                   (c-syntactic-skip-backward c-block-prefix-charset limit t)
-                   t)
-               (goto-char after-paren)
-               nil))))
+    (while
+       (or 
+        ;; Could be after a template arglist....
+        (and c-recognize-<>-arglists
+             (eq (char-before) ?>)
+             (let ((c-parse-and-markup-<>-arglists t))
+               (c-backward-<>-arglist nil limit)))
+        ;; .... or after a noise clause with parens.
+        (and c-opt-cpp-prefix
+             (let ((after-paren (point)))
+               (if (eq (char-before) ?\))
+                   (and
+                    (c-go-list-backward)
+                    (eq (char-after) ?\()
+                    (progn (c-backward-syntactic-ws)
+                           (c-simple-skip-symbol-backward))
+                    (or (looking-at c-paren-nontype-key) ; e.g. __attribute__
+                        (looking-at c-noise-macro-with-parens-name-re)))
+                 (goto-char after-paren)
+                 nil))))
+      (c-syntactic-skip-backward c-block-prefix-charset limit t))
 
     ;; Note: Can't get bogus hits inside template arglists below since they
     ;; have gotten paren syntax above.
@@ -12651,10 +12647,18 @@ comment at the start of cc-engine.el for more info."
           ;; The `c-decl-block-key' search continues from there since
           ;; we know it can't match earlier.
           (if goto-start
-              (when (c-syntactic-re-search-forward c-symbol-start
-                                                   open-brace t t)
-                (goto-char (setq first-specifier-pos (match-beginning 0)))
-                t)
+              (progn
+                (while
+                    (and
+                     (c-syntactic-re-search-forward c-symbol-start
+                                                    open-brace t t)
+                     (goto-char (match-beginning 0))
+                     (if (or (looking-at c-noise-macro-name-re)
+                             (looking-at c-noise-macro-with-parens-name-re))
+                         (c-forward-noise-clause)
+                       (setq first-specifier-pos (match-beginning 0))
+                       nil)))
+                first-specifier-pos)
             t)
 
           (cond
@@ -12723,34 +12727,39 @@ comment at the start of cc-engine.el for more info."
            (goto-char first-specifier-pos)
 
            (while (< (point) kwd-start)
-             (if (looking-at c-symbol-key)
-                 ;; Accept any plain symbol token on the ground that
-                 ;; it's a specifier masked through a macro (just
-                 ;; like `c-forward-decl-or-cast-1' skip forward over
-                 ;; such tokens).
-                 ;;
-                 ;; Could be more restrictive wrt invalid keywords,
-                 ;; but that'd only occur in invalid code so there's
-                 ;; no use spending effort on it.
-                 (let ((end (match-end 0))
-                       (kwd-sym (c-keyword-sym (match-string 0))))
-                   (unless
-                       (and kwd-sym
-                            ;; Moving over a protection kwd and the following
-                            ;; ":" (in C++ Mode) to the next token could take
-                            ;; us all the way up to `kwd-start', leaving us
-                            ;; no chance to update `first-specifier-pos'.
-                            (not (c-keyword-member kwd-sym 'c-protection-kwds))
-                            (c-forward-keyword-clause 0))
-                     (goto-char end)
-                     (c-forward-syntactic-ws)))
-
+             (cond
+              ((or (looking-at c-noise-macro-name-re)
+                   (looking-at c-noise-macro-with-parens-name-re))
+               (c-forward-noise-clause))
+              ((looking-at c-symbol-key)
+               ;; Accept any plain symbol token on the ground that
+               ;; it's a specifier masked through a macro (just
+               ;; like `c-forward-decl-or-cast-1' skips forward over
+               ;; such tokens).
+               ;;
+               ;; Could be more restrictive wrt invalid keywords,
+               ;; but that'd only occur in invalid code so there's
+               ;; no use spending effort on it.
+               (let ((end (match-end 0))
+                     (kwd-sym (c-keyword-sym (match-string 0))))
+                 (unless
+                     (and kwd-sym
+                          ;; Moving over a protection kwd and the following
+                          ;; ":" (in C++ Mode) to the next token could take
+                          ;; us all the way up to `kwd-start', leaving us
+                          ;; no chance to update `first-specifier-pos'.
+                          (not (c-keyword-member kwd-sym 'c-protection-kwds))
+                          (c-forward-keyword-clause 0))
+                   (goto-char end)
+                   (c-forward-syntactic-ws))))
+
+              ((c-syntactic-re-search-forward c-symbol-start
+                                              kwd-start 'move t)
                ;; Can't parse a declaration preamble and is still
                ;; before `kwd-start'.  That means `first-specifier-pos'
                ;; was in some earlier construct.  Search again.
-               (if (c-syntactic-re-search-forward c-symbol-start
-                                                  kwd-start 'move t)
-                   (goto-char (setq first-specifier-pos (match-beginning 0)))
+               (goto-char (setq first-specifier-pos (match-beginning 0))))
+              (t
                  ;; Got no preamble before the block declaration keyword.
                  (setq first-specifier-pos kwd-start))))
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]