emacs-diffs
[Top][All Lists]
Advanced

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

master ed85132740b: CC Mode: Handle C++20's if consteval


From: Alan Mackenzie
Subject: master ed85132740b: CC Mode: Handle C++20's if consteval
Date: Tue, 26 Mar 2024 17:04:42 -0400 (EDT)

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

    CC Mode: Handle C++20's if consteval
    
    * lisp/progmodes/cc-engine.el (c-after-conditional): Handle the
    new keyword in place of a paren sexp after `if'.
    
    * lisp/progmodes/cc-langs.el (c-negation-op-re)
    (c-paren-clause-kwds, c-paren-clause-key)
    (c-block-stmt-with-kwds, c-block-stmt-with-key): New
    lang-consts/vars.
    
    * if-11.cc, if-11.res: New test files.
---
 lisp/progmodes/cc-engine.el | 22 +++++++++++++++-------
 lisp/progmodes/cc-langs.el  | 30 ++++++++++++++++++++++++++++++
 2 files changed, 45 insertions(+), 7 deletions(-)

diff --git a/lisp/progmodes/cc-engine.el b/lisp/progmodes/cc-engine.el
index ea4ee3d7b7c..8c505e9556a 100644
--- a/lisp/progmodes/cc-engine.el
+++ b/lisp/progmodes/cc-engine.el
@@ -12346,13 +12346,21 @@ comment at the start of cc-engine.el for more info."
             (zerop (c-backward-token-2 1 t lim))
           t)
         (or (looking-at c-block-stmt-1-key)
-            (and (eq (char-after) ?\()
-                 (zerop (c-backward-token-2 1 t lim))
-                 (if (looking-at c-block-stmt-hangon-key)
-                     (zerop (c-backward-token-2 1 t lim))
-                   t)
-                 (or (looking-at c-block-stmt-2-key)
-                     (looking-at c-block-stmt-1-2-key))))
+            (or
+             (and
+              (eq (char-after) ?\()
+              (zerop (c-backward-token-2 1 t lim))
+              (if (looking-at c-block-stmt-hangon-key)
+                  (zerop (c-backward-token-2 1 t lim))
+                t)
+              (or (looking-at c-block-stmt-2-key)
+                  (looking-at c-block-stmt-1-2-key)))
+             (and (looking-at c-paren-clause-key)
+                  (zerop (c-backward-token-2 1 t lim))
+                  (if (looking-at c-negation-op-re)
+                      (zerop (c-backward-token-2 1 t lim))
+                    t)
+                  (looking-at c-block-stmt-with-key))))
         (point))))
 
 (defun c-after-special-operator-id (&optional lim)
diff --git a/lisp/progmodes/cc-langs.el b/lisp/progmodes/cc-langs.el
index ae2389c75c2..06b919f26fd 100644
--- a/lisp/progmodes/cc-langs.el
+++ b/lisp/progmodes/cc-langs.el
@@ -1599,6 +1599,12 @@ operators."
 (c-lang-defvar c-assignment-op-regexp
   (c-lang-const c-assignment-op-regexp))
 
+(c-lang-defconst c-negation-op-re
+  ;; Regexp matching the negation operator.
+  t "!\\([^=]\\|$\\)")
+
+(c-lang-defvar c-negation-op-re (c-lang-const c-negation-op-re))
+
 (c-lang-defconst c-arithmetic-operators
   "List of all arithmetic operators, including \"+=\", etc."
   ;; Note: in the following, there are too many operators for AWK and IDL.
@@ -3163,6 +3169,30 @@ Keywords here should also be in `c-block-stmt-1-kwds'."
                  (c-lang-const c-block-stmt-2-kwds)))))
 (c-lang-defvar c-opt-block-stmt-key (c-lang-const c-opt-block-stmt-key))
 
+(c-lang-defconst c-paren-clause-kwds
+  "Keywords which can stand in the place of paren sexps in conditionals.
+This applies only to conditionals in `c-block-stmt-with-kwds'."
+  t nil
+  c++ '("consteval"))
+
+(c-lang-defconst c-paren-clause-key
+  ;; Regexp matching a keyword in `c-paren-clause-kwds'.
+  t (c-make-keywords-re t
+      (c-lang-const c-paren-clause-kwds)))
+(c-lang-defvar c-paren-clause-key (c-lang-const c-paren-clause-key))
+
+(c-lang-defconst c-block-stmt-with-kwds
+  "Statement keywords which can be followed by a keyword instead of a parens.
+Such a keyword is a member of `c-paren-clause-kwds."
+  t nil
+  c++ '("if"))
+
+(c-lang-defconst c-block-stmt-with-key
+  ;; Regexp matching a keyword in `c-block-stmt-with-kwds'.
+  t (c-make-keywords-re t
+      (c-lang-const c-block-stmt-with-kwds)))
+(c-lang-defvar c-block-stmt-with-key (c-lang-const c-block-stmt-with-key))
+
 (c-lang-defconst c-simple-stmt-kwds
   "Statement keywords followed by an expression or nothing."
   t    '("break" "continue" "goto" "return")



reply via email to

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