-
Notifications
You must be signed in to change notification settings - Fork 14.9k
[clang-format] Fix TableGen nested DAGArg format #155837
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
@llvm/pr-subscribers-clang-format Author: Hirofumi Nakamura (hnakamura5) ChangesFixes #154634. Full diff: https://github.com/llvm/llvm-project/pull/155837.diff 2 Files Affected:
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; }");
}
|
" let DAGArgBang =\n" | ||
" (!cast<SomeType>(\"Some\") i32:$src1, i32:$src2);\n" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why does the line wrapping change (for better?) here now?
" let NestedDAGArg = ((DAGArg1 (v111 v112, v113), v12) v2,\n" | ||
" (DAGArg3 (v31 v32)));\n" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But here the line breaking is not after the =
.
Fixes #154634.
Allow inserting space before DAGArg's opener paren when nested.