llvmbot wrote:

<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang-format

Author: Hirofumi Nakamura (hnakamura5)

<details>
<summary>Changes</summary>

Fixes https://github.com/llvm/llvm-project/issues/154634. 
Allow inserting space before DAGArg's opener paren when nested.

---
Full diff: https://github.com/llvm/llvm-project/pull/155837.diff


2 Files Affected:

- (modified) clang/lib/Format/TokenAnnotator.cpp (+12-1) 
- (modified) clang/unittests/Format/FormatTestTableGen.cpp (+9-2) 


``````````diff
diff --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index a220de54f46bf..997fcfc2159dc 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -1045,6 +1045,14 @@ class AnnotatingParser {
       }
     }
     // Parse the [DagArgList] part
+    return parseTableGenDAGArgList(Opener, BreakInside);
+  }
+
+  // DagArgList   ::=  "," DagArg [DagArgList]
+  // This parses SimpleValue 6's [DagArgList] part.
+  bool parseTableGenDAGArgList(FormatToken *Opener, bool BreakInside) {
+    ScopedContextCreator ContextCreator(*this, tok::l_paren, 1);
+    Contexts.back().IsTableGenDAGArgList = true;
     bool FirstDAGArgListElm = true;
     while (CurrentToken) {
       if (!FirstDAGArgListElm && CurrentToken->is(tok::comma)) {
@@ -1101,6 +1109,9 @@ class AnnotatingParser {
     // SimpleValue6 ::=  "(" DagArg [DagArgList] ")"
     if (Tok->is(tok::l_paren)) {
       Tok->setType(TT_TableGenDAGArgOpener);
+      // Nested DAGArg requires space before '(' as separator.
+      if (Contexts.back().IsTableGenDAGArgList)
+        Tok->SpacesRequiredBefore = 1;
       return parseTableGenDAGArgAndList(Tok);
     }
     // SimpleValue 9: Bang operator
@@ -2138,7 +2149,7 @@ class AnnotatingParser {
     // Whether the braces may mean concatenation instead of structure or array
     // literal.
     bool VerilogMayBeConcatenation = false;
-    bool IsTableGenDAGArg = false;
+    bool IsTableGenDAGArgList = false;
     bool IsTableGenBangOpe = false;
     bool IsTableGenCondOpe = false;
     enum {
diff --git a/clang/unittests/Format/FormatTestTableGen.cpp 
b/clang/unittests/Format/FormatTestTableGen.cpp
index 1c3d187de393c..33acd2435d289 100644
--- a/clang/unittests/Format/FormatTestTableGen.cpp
+++ b/clang/unittests/Format/FormatTestTableGen.cpp
@@ -185,11 +185,18 @@ TEST_F(FormatTestTableGen, SimpleValue6) {
                "      i32:$dst6,                                // dst6\n"
                "      i32:$dst7                                 // dst7\n"
                "  );\n"
-               "  let DAGArgBang = (!cast<SomeType>(\"Some\") i32:$src1,\n"
-               "      i32:$src2);\n"
+               "  let DAGArgBang =\n"
+               "      (!cast<SomeType>(\"Some\") i32:$src1, i32:$src2);\n"
+               "  let NestedDAGArg = ((DAGArg1 (v111 v112, v113), v12) v2,\n"
+               "      (DAGArg3 (v31 v32)));\n"
                "}");
 }
 
+TEST_F(FormatTestTableGen, SimpleValue6_NestedInPat) {
+  verifyFormat("def : Pat<(vec.vt (avg (vec.vt V128:$l), (vec.vt V128:$r))),\n"
+               "          (inst $l, $r)>;");
+}
+
 TEST_F(FormatTestTableGen, SimpleValue7) {
   verifyFormat("def SimpleValue7 { let Identifier = SimpleValue; }");
 }

``````````

</details>


https://github.com/llvm/llvm-project/pull/155837
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to