[clang] [clang-format] Fix the indent of the ternary operator when AlignOperands and BreakBeforeTernaryOperators is specified. (PR #100860)

2024-07-29 Thread Hirofumi Nakamura via cfe-commits

hnakamura5 wrote:

>  this is the default behavior of clang-format. And someone did intend it that 
> way.
> If the change is desired, the BreakBeforeTernaryOperators option should be 
> expanded to an enum or AlignOperands extended.

I agree. The current style has been default in this many years. Enough time to 
be got familiar with.

https://clang.llvm.org/docs/ClangFormatStyleOptions.html#alignoperands

The issue https://github.com/llvm/llvm-project/issues/98559 can also be 
regarded as the inaccuracy of the manual. That says 
> OAS_Align (in configuration: Align) Horizontally align operands of binary and 
> ternary expressions

Only changing this part may be better.

If the precise alignment is desired, adding a new `AlignOperands` option is the 
way.




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


[clang] [clang-format] Fix the indent of the ternary operator when AlignOperands and BreakBeforeTernaryOperators is specified. (PR #100860)

2024-07-27 Thread Hirofumi Nakamura via cfe-commits

https://github.com/hnakamura5 created 
https://github.com/llvm/llvm-project/pull/100860

Trying to fix https://github.com/llvm/llvm-project/issues/98559 .

This PR modifies the ad-hoc tweaks introduced by 
https://reviews.llvm.org/D50078 .
The change is limited to the case `AlignOperands ` and 
`BreakBeforeTernaryOperators`  are specified (default in LLVM style).

```
int foo = bar > baz
  ? 42
  : 99;
```

↓ This PR makes,

```
int foo = bar > baz
  ? 42
  : 99;
```

For the case `BreakBeforeTernaryOperators` is not specified, I'm not sure such 
style is desirable.
```
int foo = bar > baz ?
  42 :
  99;
```
So I did not touch the case at first. It may be a point of discussion.

>From 2d2695767cbd853bc2327b2f640fdeeeb41f43f6 Mon Sep 17 00:00:00 2001
From: hnakamura5 
Date: Mon, 22 Jul 2024 23:00:45 +0900
Subject: [PATCH] [clang-format] Fix the indent of the ternary operator when
 AlignOperands and  BreakBeforeTernaryOperators is specified.

---
 clang/lib/Format/ContinuationIndenter.cpp |  11 +-
 clang/unittests/Format/FormatTest.cpp | 138 +-
 .../unittests/Format/FormatTestRawStrings.cpp |  15 +-
 3 files changed, 84 insertions(+), 80 deletions(-)

diff --git a/clang/lib/Format/ContinuationIndenter.cpp 
b/clang/lib/Format/ContinuationIndenter.cpp
index b07360425ca6e..c01fe6940bf22 100644
--- a/clang/lib/Format/ContinuationIndenter.cpp
+++ b/clang/lib/Format/ContinuationIndenter.cpp
@@ -1347,8 +1347,14 @@ unsigned ContinuationIndenter::getNewLineColumn(const 
LineState ) {
   //* always un-indent by the operator when
   //BreakBeforeTernaryOperators=true
   unsigned Indent = CurrentState.Indent;
-  if (Style.AlignOperands != FormatStyle::OAS_DontAlign)
+  if (Style.AlignOperands != FormatStyle::OAS_DontAlign &&
+  !Style.BreakBeforeTernaryOperators) {
 Indent -= Style.ContinuationIndentWidth;
+  }
+  if (Style.BreakBeforeTernaryOperators &&
+  CurrentState.IsChainedConditional) {
+Indent -= 2;
+  }
   if (Style.BreakBeforeTernaryOperators && CurrentState.UnindentOperator)
 Indent -= 2;
   return Indent;
@@ -1773,7 +1779,8 @@ void 
ContinuationIndenter::moveStatePastFakeLParens(LineState ,
 !CurrentState.IsWrappedConditional) {
   NewParenState.IsChainedConditional = true;
   NewParenState.UnindentOperator = State.Stack.back().UnindentOperator;
-} else if (PrecedenceLevel == prec::Conditional ||
+} else if ((PrecedenceLevel == prec::Conditional &&
+!Style.BreakBeforeTernaryOperators) ||
(!SkipFirstExtraIndent && PrecedenceLevel > prec::Assignment &&
 !Current.isTrailingComment())) {
   NewParenState.Indent += Style.ContinuationIndentWidth;
diff --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index d01ce137b8fcb..bdd657db06712 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -7332,12 +7332,11 @@ TEST_F(FormatTest, 
ExpressionIndentationBreakingBeforeOperators) {
"};",
Style);
   verifyFormat("return abc\n"
-   " ? foo(\n"
-   " a,\n"
-   " b,\n"
-   " bar(\n"
-   "   abc))\n"
-   " : g(abc);",
+   "   ? foo(\n"
+   "   a,\n"
+   "   b,\n"
+   "   bar(abc))\n"
+   "   : g(abc);",
Style);
 }
 
@@ -9410,20 +9409,20 @@ TEST_F(FormatTest, BreaksConditionalExpressions) {
": aaa;");
   verifyFormat("a aa =\n"
"\n"
-   "? aa\n"
-   ": ;");
+   "? aa\n"
+   ": ;");
   verifyFormat(
   "aa == aa\n"
   "? aaa\n"
   ": aaa;");
   verifyFormat("f( == // force break\n"
-   "  a\n"
-   "  ? b\n"
-   "  : c);");
+   "  a\n"
+   "  ? b\n"
+   "  : c);");
   verifyFormat("return  == \n"
-   "   // comment\n"
-   "   ? \n"
-   "   : ;");
+   "   // comment\n"
+   "   ? \n"
+   "   : ;");
   verifyFormat("unsigned Indent =\n"
"format(TheLine.First,\n"
"   IndentForLevel[TheLine.Level] >= 0\n"
@@ -9432,21 +9431,20 @@ 

[clang] [clang-format] Fix a bug in annotating `*` in `#define`s (PR #99433)

2024-07-20 Thread Hirofumi Nakamura via cfe-commits

https://github.com/hnakamura5 approved this pull request.


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


[clang] [clang-format] Fix a bug in annotating `*` in `#define`s (PR #99433)

2024-07-18 Thread Hirofumi Nakamura via cfe-commits

hnakamura5 wrote:

This change certainly fixes the issue, but also seems specific for the reported 
code.
For example it does not work well for the case the line contains something else 
as,
```
#define FN(N) void fn(void *addr) { a + f(addr, 0, N * two); }
```

This results the annotations where `*` is PointerOrReference,
```
{(hash, "#" , Unknown), (identifier, "define" , Unknown), (identifier, "FN" , 
Unknown), (l_paren, "(" , Unknown),
(identifier, "N" , Unknown), (r_paren, ")" , Unknown), (void, "void" , 
Unknown), (identifier, "fn" , FunctionDeclarationName), 
(l_paren, "(" , FunctionDeclarationLParen), (void, "void" , Unknown), (star, 
"*" , PointerOrReference),
(identifier, "addr" , StartOfName), (r_paren, ")" , Unknown), (l_brace, "{" , 
FunctionLBrace), (identifier, "a" , Unknown),
(plus, "+" , BinaryOperator), (identifier, "f" , Unknown), (l_paren, "(" , 
Unknown), (identifier, "addr" , Unknown),
(comma, "," , Unknown), (numeric_constant, "0" , Unknown), (comma, "," , 
Unknown), (identifier, "N" , Unknown),
(star, "*" , PointerOrReference) , (identifier, "two" , StartOfName), 
(r_paren, ")" , Unknown), (semi, ";" , Unknown),
(r_brace, "}" , Unknown), (eof, "" , Unknown)}
```

How about judging whether the FunctionLBrace exists as the opener of the outer 
context?

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


[clang] [clang-format] BreakAfterAttributes did not take into account gnu attributes (PR #78102)

2024-07-08 Thread Hirofumi Nakamura via cfe-commits


@@ -26827,6 +26827,31 @@ TEST_F(FormatTest, BreakAdjacentStringLiterals) {
   Style.BreakAdjacentStringLiterals = false;
   verifyFormat(Code, Style);
 }
+
+TEST_F(FormatTest, BreakAfterGNUAttributes) {
+  FormatStyle Style = getLLVMStyle();
+  Style.BreakAfterAttributes = FormatStyle::ABS_Never;
+
+  verifyFormat("__attribute__((__warn_unused_result__)) const int i;", Style);
+
+  verifyFormat(
+  "__attribute__((other)) __attribute__((__warn_unused_result__)) int j;",
+  Style);
+
+  verifyFormat("__attribute__((__warn_unused_result__)) inline int f(int );",
+   Style);
+
+  Style.BreakAfterAttributes = FormatStyle::ABS_Always;
+  verifyFormat("__attribute__((__warn_unused_result__))\nconst int i;", Style);
+
+  verifyFormat(
+  "__attribute__((other)) __attribute__((__warn_unused_result__))\nint j;",

hnakamura5 wrote:

Same as above.

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


[clang] [clang-format] BreakAfterAttributes did not take into account gnu attributes (PR #78102)

2024-07-08 Thread Hirofumi Nakamura via cfe-commits


@@ -26827,6 +26827,31 @@ TEST_F(FormatTest, BreakAdjacentStringLiterals) {
   Style.BreakAdjacentStringLiterals = false;
   verifyFormat(Code, Style);
 }
+
+TEST_F(FormatTest, BreakAfterGNUAttributes) {
+  FormatStyle Style = getLLVMStyle();
+  Style.BreakAfterAttributes = FormatStyle::ABS_Never;
+
+  verifyFormat("__attribute__((__warn_unused_result__)) const int i;", Style);
+
+  verifyFormat(
+  "__attribute__((other)) __attribute__((__warn_unused_result__)) int j;",
+  Style);
+
+  verifyFormat("__attribute__((__warn_unused_result__)) inline int f(int );",
+   Style);
+
+  Style.BreakAfterAttributes = FormatStyle::ABS_Always;
+  verifyFormat("__attribute__((__warn_unused_result__))\nconst int i;", Style);

hnakamura5 wrote:

How about breaking the string and the line after '\n' ?

```suggestion
  verifyFormat("__attribute__((__warn_unused_result__))\n"
   "const int i;",
   Style);
```
↑ Test cases around look like that.

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


[clang] [clang-format] BreakAfterAttributes did not take into account gnu attributes (PR #78102)

2024-07-08 Thread Hirofumi Nakamura via cfe-commits

https://github.com/hnakamura5 commented:

There are small suggestions on the format of test.

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


[clang] [clang-format] BreakAfterAttributes did not take into account gnu attributes (PR #78102)

2024-07-08 Thread Hirofumi Nakamura via cfe-commits


@@ -26827,6 +26827,31 @@ TEST_F(FormatTest, BreakAdjacentStringLiterals) {
   Style.BreakAdjacentStringLiterals = false;
   verifyFormat(Code, Style);
 }
+
+TEST_F(FormatTest, BreakAfterGNUAttributes) {
+  FormatStyle Style = getLLVMStyle();
+  Style.BreakAfterAttributes = FormatStyle::ABS_Never;
+
+  verifyFormat("__attribute__((__warn_unused_result__)) const int i;", Style);
+
+  verifyFormat(
+  "__attribute__((other)) __attribute__((__warn_unused_result__)) int j;",
+  Style);
+
+  verifyFormat("__attribute__((__warn_unused_result__)) inline int f(int );",
+   Style);
+
+  Style.BreakAfterAttributes = FormatStyle::ABS_Always;
+  verifyFormat("__attribute__((__warn_unused_result__))\nconst int i;", Style);
+
+  verifyFormat(
+  "__attribute__((other)) __attribute__((__warn_unused_result__))\nint j;",
+  Style);
+
+  verifyFormat("__attribute__((__warn_unused_result__))\ninline int f(int 
);",

hnakamura5 wrote:

Also '\n' here.

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


[clang] [clang-format] BreakAfterAttributes did not take into account gnu attributes (PR #78102)

2024-07-08 Thread Hirofumi Nakamura via cfe-commits

https://github.com/hnakamura5 edited 
https://github.com/llvm/llvm-project/pull/78102
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format]: Annotate colons found in inline assembly (PR #92617)

2024-05-25 Thread Hirofumi Nakamura via cfe-commits

https://github.com/hnakamura5 approved this pull request.


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


[clang] [clang-format]: Annotate colons found in inline assembly (PR #92617)

2024-05-24 Thread Hirofumi Nakamura via cfe-commits


@@ -1426,12 +1428,9 @@ class AnnotatingParser {
 // the colon are passed as macro arguments.
 Tok->setType(TT_ObjCMethodExpr);
   } else if (Contexts.back().ContextKind == tok::l_paren &&
- !Line.InPragmaDirective) {
-if (Style.isTableGen() && Contexts.back().IsTableGenDAGArg) {
-  Tok->setType(TT_TableGenDAGArgListColon);
-  break;
-}
-Tok->setType(TT_InlineASMColon);
+ !Line.InPragmaDirective && Style.isTableGen() &&
+ Contexts.back().IsTableGenDAGArg) {
+Tok->setType(TT_TableGenDAGArgListColon);

hnakamura5 wrote:

No objection. This seems redundant. Thank you for removing.

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


[clang] [clang-format] Remove trailing newlines in TableGen formatting test. (PR #87983)

2024-04-09 Thread Hirofumi Nakamura via cfe-commits

hnakamura5 wrote:

Thank you!

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


[clang] [clang-format] Remove trailing newlines in TableGen formatting test. (PR #87983)

2024-04-09 Thread Hirofumi Nakamura via cfe-commits

https://github.com/hnakamura5 closed 
https://github.com/llvm/llvm-project/pull/87983
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format] Remove trailing newlines in TableGen formatting test. (PR #87983)

2024-04-08 Thread Hirofumi Nakamura via cfe-commits

https://github.com/hnakamura5 created 
https://github.com/llvm/llvm-project/pull/87983

Refactoring suggested here https://github.com/llvm/llvm-project/pull/87924 .

>From d55a0986ed175dbc18c073507691321a30952979 Mon Sep 17 00:00:00 2001
From: hnakamura5 
Date: Mon, 8 Apr 2024 21:20:04 +0900
Subject: [PATCH] [clang-format] Remove trailing newline in TableGen formatting
 test.

---
 clang/unittests/Format/FormatTestTableGen.cpp | 103 +-
 1 file changed, 51 insertions(+), 52 deletions(-)

diff --git a/clang/unittests/Format/FormatTestTableGen.cpp 
b/clang/unittests/Format/FormatTestTableGen.cpp
index d235c85c8eaa0f..79b6961b00b42a 100644
--- a/clang/unittests/Format/FormatTestTableGen.cpp
+++ b/clang/unittests/Format/FormatTestTableGen.cpp
@@ -72,7 +72,7 @@ TEST_F(FormatTestTableGen, LiteralsAndIdentifiers) {
"  let 0startID = $TokVarName;\n"
"  let 0xstartInteger = 0x42;\n"
"  let someIdentifier = $TokVarName;\n"
-   "}\n");
+   "}");
 }
 
 TEST_F(FormatTestTableGen, BangOperators) {
@@ -101,22 +101,22 @@ TEST_F(FormatTestTableGen, BangOperators) {
"  \"zerozero\",\n"
"  true:  // default\n"
"  \"positivepositive\");\n"
-   "}\n");
+   "}");
 }
 
 TEST_F(FormatTestTableGen, Include) {
-  verifyFormat("include \"test/IncludeFile.h\"\n");
+  verifyFormat("include \"test/IncludeFile.h\"");
 }
 
 TEST_F(FormatTestTableGen, Types) {
-  verifyFormat("def Types : list, bits<3>, list> {}\n");
+  verifyFormat("def Types : list, bits<3>, list> {}");
 }
 
 TEST_F(FormatTestTableGen, SimpleValue1_SingleLiterals) {
   verifyFormat("def SimpleValue {\n"
"  let Integer = 42;\n"
"  let String = \"some string\";\n"
-   "}\n");
+   "}");
 }
 
 TEST_F(FormatTestTableGen, SimpleValue1_MultilineString) {
@@ -129,7 +129,7 @@ TEST_F(FormatTestTableGen, SimpleValue1_MultilineString) {
   "delimited by \\[{ and }\\]. It  can break across lines and the line "
   "breaks are retained in the string. \n"
   
"(https://llvm.org/docs/TableGen/ProgRef.html#grammar-token-TokCode)}];\n"
-  "}\n";
+  "}";
   StringRef DefWithCodeMessedUp =
   "def SimpleValueCode {  let  \n"
   "Code=   \n"
@@ -139,7 +139,7 @@ TEST_F(FormatTestTableGen, SimpleValue1_MultilineString) {
   "breaks are retained in the string. \n"
   "(https://llvm.org/docs/TableGen/ProgRef.html#grammar-token-TokCode)}] 
\n"
   " ;  \n"
-  "   }\n";
+  "   }";
   verifyFormat(DefWithCode, DefWithCodeMessedUp);
 }
 
@@ -147,15 +147,15 @@ TEST_F(FormatTestTableGen, SimpleValue2) {
   verifyFormat("def SimpleValue2 {\n"
"  let True = true;\n"
"  let False = false;\n"
-   "}\n");
+   "}");
 }
 
 TEST_F(FormatTestTableGen, SimpleValue3) {
-  verifyFormat("class SimpleValue3 { int Question = ?; }\n");
+  verifyFormat("class SimpleValue3 { int Question = ?; }");
 }
 
 TEST_F(FormatTestTableGen, SimpleValue4) {
-  verifyFormat("def SimpleValue4 { let ValueList = {1, 2, 3}; }\n");
+  verifyFormat("def SimpleValue4 { let ValueList = {1, 2, 3}; }");
 }
 
 TEST_F(FormatTestTableGen, SimpleValue5) {
@@ -166,7 +166,7 @@ TEST_F(FormatTestTableGen, SimpleValue5) {
"  list>;\n"
"  let SquareBitsListWithType = [ {1, 2},\n"
" {3, 4} ]>>;\n"
-   "}\n");
+   "}");
 }
 
 TEST_F(FormatTestTableGen, SimpleValue6) {
@@ -184,15 +184,15 @@ TEST_F(FormatTestTableGen, SimpleValue6) {
"  );\n"
"  let DAGArgBang = (!cast(\"Some\") i32:$src1,\n"
"  i32:$src2);\n"
-   "}\n");
+   "}");
 }
 
 TEST_F(FormatTestTableGen, SimpleValue7) {
-  verifyFormat("def SimpleValue7 { let Identifier = SimpleValue; }\n");
+  verifyFormat("def SimpleValue7 { let Identifier = SimpleValue; }");
 }
 
 TEST_F(FormatTestTableGen, SimpleValue8) {
-  verifyFormat("def SimpleValue8 { let Class = SimpleValue3<3>; }\n");
+  verifyFormat("def SimpleValue8 { let Class = SimpleValue3<3>; }");
 }
 
 TEST_F(FormatTestTableGen, ValueSuffix) {
@@ -203,19 +203,18 @@ TEST_F(FormatTestTableGen, ValueSuffix) {
"  let Slice1 = value[1, ];\n"
"  let Slice2 = value[4...7, 17, 2...3, 4];\n"
"  let Field = value.field;\n"
-   "}\n");
+   "}");
 }
 
 TEST_F(FormatTestTableGen, PasteOperator) {
-  verifyFormat(
-  "def Paste#\"Operator\" { string Paste = \"Paste\"#operator; }\n");
+  verifyFormat("def Paste#\"Operator\" { string Paste = \"Paste\"#operator; 
}");
 
   verifyFormat("def [\"Traring\", \"Paste\"]# {\n"
"  string X = Traring#;\n"
"  

[clang] [clang-format] Added unittest of TableGen formatting w.r.t. block type calculation. (PR #87924)

2024-04-08 Thread Hirofumi Nakamura via cfe-commits

hnakamura5 wrote:

Thank you!

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


[clang] [clang-format] Added unittest of TableGen formatting w.r.t. block type calculation. (PR #87924)

2024-04-08 Thread Hirofumi Nakamura via cfe-commits

https://github.com/hnakamura5 closed 
https://github.com/llvm/llvm-project/pull/87924
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format] Added unittest of TableGen formatting w.r.t. block type calculation. (PR #87924)

2024-04-08 Thread Hirofumi Nakamura via cfe-commits


@@ -290,6 +290,16 @@ TEST_F(FormatTestTableGen, MultiClass) {
"}\n");
 }
 
+TEST_F(FormatTestTableGen, MultiClassesWithPasteOperator) {
+  // This is a sensitive example for the handling of the paste operators in
+  // brace type calculation.
+  verifyFormat("multiclass MultiClass1 {\n"
+   "  def : Def#x;\n"
+   "  def : Def#y;\n"
+   "}\n"
+   "multiclass MultiClass2 { def : Def#x; }\n");

hnakamura5 wrote:

I come to notice that they are not required. I will make a patch for whole this 
file later.

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


[clang] [clang-format] Added unittest of TableGen formatting w.r.t. block type calculation. (PR #87924)

2024-04-07 Thread Hirofumi Nakamura via cfe-commits

https://github.com/hnakamura5 created 
https://github.com/llvm/llvm-project/pull/87924

The test I mentioned here https://github.com/llvm/llvm-project/pull/87450 .
This is a regression test to detect the case block type is not calculated due 
to the paste `#` operator misunderstood as preprocessor. 

>From fd10ce8a2d6532052c240d385f263602b859ff7a Mon Sep 17 00:00:00 2001
From: hnakamura5 
Date: Sun, 7 Apr 2024 22:32:31 +0900
Subject: [PATCH] [clang-format] Added unittest of TableGen formatting w.r.t.
 block kind

---
 clang/unittests/Format/FormatTestTableGen.cpp | 10 ++
 1 file changed, 10 insertions(+)

diff --git a/clang/unittests/Format/FormatTestTableGen.cpp 
b/clang/unittests/Format/FormatTestTableGen.cpp
index 8ca6bf97e5a6b1..d235c85c8eaa0f 100644
--- a/clang/unittests/Format/FormatTestTableGen.cpp
+++ b/clang/unittests/Format/FormatTestTableGen.cpp
@@ -290,6 +290,16 @@ TEST_F(FormatTestTableGen, MultiClass) {
"}\n");
 }
 
+TEST_F(FormatTestTableGen, MultiClassesWithPasteOperator) {
+  // This is a sensitive example for the handling of the paste operators in
+  // brace type calculation.
+  verifyFormat("multiclass MultiClass1 {\n"
+   "  def : Def#x;\n"
+   "  def : Def#y;\n"
+   "}\n"
+   "multiclass MultiClass2 { def : Def#x; }\n");
+}
+
 TEST_F(FormatTestTableGen, Defm) {
   verifyFormat("defm : Multiclass<0>;\n");
 

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format] Support of TableGen formatting. (PR #76059)

2024-03-22 Thread Hirofumi Nakamura via cfe-commits

https://github.com/hnakamura5 closed 
https://github.com/llvm/llvm-project/pull/76059
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format] Support of TableGen formatting. (PR #76059)

2024-03-22 Thread Hirofumi Nakamura via cfe-commits

hnakamura5 wrote:

All the split parts of this PR is merged. Thank you!

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


[clang] [clang-format] Added AlignConsecutiveTableGenBreakingDAGArgColons option. (PR #86150)

2024-03-22 Thread Hirofumi Nakamura via cfe-commits

hnakamura5 wrote:

@HazardyKnusperkeks 
Thank you very much!
It took about 4 month with ten or more PRs for the parts of the first concept 
of TableGen formatting. 
You reviewed every time and gave me many valuable suggestions. I appreciate you 
again and again!

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


[clang] [clang-format] Added AlignConsecutiveTableGenBreakingDAGArgColons option. (PR #86150)

2024-03-22 Thread Hirofumi Nakamura via cfe-commits

https://github.com/hnakamura5 closed 
https://github.com/llvm/llvm-project/pull/86150
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format] Support of TableGen formatting. (PR #76059)

2024-03-21 Thread Hirofumi Nakamura via cfe-commits

hnakamura5 wrote:

Alignment option for DAGArg: https://github.com/llvm/llvm-project/pull/86150

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


[clang] [clang-format] Added AlignConsecutiveTableGenBreakingDAGArgColons option. (PR #86150)

2024-03-21 Thread Hirofumi Nakamura via cfe-commits

https://github.com/hnakamura5 created 
https://github.com/llvm/llvm-project/pull/86150

This is the option to specify the style of alignment of the colons inside 
TableGen's DAGArg.

>From 4a0d3cd3d20220b7f363922b49eae8cd0c740426 Mon Sep 17 00:00:00 2001
From: hnakamura5 
Date: Fri, 22 Mar 2024 01:36:47 +0900
Subject: [PATCH] [clang-format] Added
 AlignConsecutiveTableGenBreakingDAGArgColons option.

---
 clang/docs/ClangFormatStyleOptions.rst| 145 ++
 clang/include/clang/Format/Format.h   |  17 ++
 clang/lib/Format/Format.cpp   |   3 +
 clang/lib/Format/FormatToken.h|   1 +
 clang/lib/Format/TokenAnnotator.cpp   |  18 ++-
 clang/lib/Format/WhitespaceManager.cpp|   6 +
 clang/lib/Format/WhitespaceManager.h  |   3 +
 clang/unittests/Format/FormatTestTableGen.cpp |  32 
 clang/unittests/Format/TokenAnnotatorTest.cpp |  16 ++
 9 files changed, 236 insertions(+), 5 deletions(-)

diff --git a/clang/docs/ClangFormatStyleOptions.rst 
b/clang/docs/ClangFormatStyleOptions.rst
index be021dfc5c084c..2ee36f24d7ce4b 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -955,6 +955,151 @@ the configuration (without a prefix: ``Auto``).
   }
 
 
+.. _AlignConsecutiveTableGenBreakingDAGArgColons:
+
+**AlignConsecutiveTableGenBreakingDAGArgColons** (``AlignConsecutiveStyle``) 
:versionbadge:`clang-format 19` :ref:`¶ 
`
+  Style of aligning consecutive TableGen DAGArg operator colons.
+  If enabled, align the colon inside DAGArg which have line break inside.
+  This works only when TableGenBreakInsideDAGArg is BreakElements or
+  BreakAll and the DAGArg is not excepted by
+  TableGenBreakingDAGArgOperators's effect.
+
+  .. code-block:: c++
+
+let dagarg = (ins
+a  :$src1,
+aa :$src2,
+aaa:$src3
+)
+
+  Nested configuration flags:
+
+  Alignment options.
+
+  They can also be read as a whole for compatibility. The choices are:
+  - None
+  - Consecutive
+  - AcrossEmptyLines
+  - AcrossComments
+  - AcrossEmptyLinesAndComments
+
+  For example, to align across empty lines and not across comments, either
+  of these work.
+
+  .. code-block:: c++
+
+AlignConsecutiveTableGenBreakingDAGArgColons: AcrossEmptyLines
+
+AlignConsecutiveTableGenBreakingDAGArgColons:
+  Enabled: true
+  AcrossEmptyLines: true
+  AcrossComments: false
+
+  * ``bool Enabled`` Whether aligning is enabled.
+
+.. code-block:: c++
+
+  #define SHORT_NAME   42
+  #define LONGER_NAME  0x007f
+  #define EVEN_LONGER_NAME (2)
+  #define foo(x)   (x * x)
+  #define bar(y, z)(y + z)
+
+  int a= 1;
+  int somelongname = 2;
+  double c = 3;
+
+  int  : 1;
+  int b: 12;
+  int ccc  : 8;
+
+  int  = 12;
+  float   b = 23;
+  std::string ccc;
+
+  * ``bool AcrossEmptyLines`` Whether to align across empty lines.
+
+.. code-block:: c++
+
+  true:
+  int a= 1;
+  int somelongname = 2;
+  double c = 3;
+
+  int d= 3;
+
+  false:
+  int a= 1;
+  int somelongname = 2;
+  double c = 3;
+
+  int d = 3;
+
+  * ``bool AcrossComments`` Whether to align across comments.
+
+.. code-block:: c++
+
+  true:
+  int d= 3;
+  /* A comment. */
+  double e = 4;
+
+  false:
+  int d = 3;
+  /* A comment. */
+  double e = 4;
+
+  * ``bool AlignCompound`` Only for ``AlignConsecutiveAssignments``.  Whether 
compound assignments
+like ``+=`` are aligned along with ``=``.
+
+.. code-block:: c++
+
+  true:
+  a   &= 2;
+  bbb  = 2;
+
+  false:
+  a &= 2;
+  bbb = 2;
+
+  * ``bool AlignFunctionPointers`` Only for ``AlignConsecutiveDeclarations``. 
Whether function pointers are
+aligned.
+
+.. code-block:: c++
+
+  true:
+  unsigned i;
+  int 
+  int *p;
+  int  (*f)();
+
+  false:
+  unsigned i;
+  int 
+  int *p;
+  int (*f)();
+
+  * ``bool PadOperators`` Only for ``AlignConsecutiveAssignments``.  Whether 
short assignment
+operators are left-padded to the same length as long ones in order to
+put all assignment operators to the right of the left hand side.
+
+.. code-block:: c++
+
+  true:
+  a   >>= 2;
+  bbb   = 2;
+
+  a = 2;
+  bbb >>= 2;
+
+  false:
+  a >>= 2;
+  bbb = 2;
+
+  a = 2;
+  bbb >>= 2;
+
+
 .. _AlignConsecutiveTableGenCondOperatorColons:
 
 **AlignConsecutiveTableGenCondOperatorColons** (``AlignConsecutiveStyle``) 
:versionbadge:`clang-format 19` :ref:`¶ 
`
diff --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index 7ad2579bf7773b..0720c8283cd75c 100644
--- a/clang/include/clang/Format/Format.h
+++ 

[clang] [clang-format] Add Options to break inside the TableGen DAGArg. (PR #83149)

2024-03-19 Thread Hirofumi Nakamura via cfe-commits

hnakamura5 wrote:

@HazardyKnusperkeks 
Thank you for reviewing and merging the fix.

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


[clang] [clang-format] Add Options to break inside the TableGen DAGArg. (PR #83149)

2024-03-19 Thread Hirofumi Nakamura via cfe-commits

hnakamura5 wrote:

@wangpc-pp 
Thank you for telling, and sorry for overlooking the detailed check for CI.

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


[clang] [clang-format] Fixed the warning in building document for TableGenBreakingDAGArgOperators. (PR #85760)

2024-03-19 Thread Hirofumi Nakamura via cfe-commits

hnakamura5 wrote:

Thank you so much for quick response!

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


[clang] [clang-format] Fixed the warning in building document for TableGenBreakingDAGArgOperators. (PR #85760)

2024-03-19 Thread Hirofumi Nakamura via cfe-commits

https://github.com/hnakamura5 created 
https://github.com/llvm/llvm-project/pull/85760

Intend to fix the `Test documentation build `, degraded here 
https://github.com/llvm/llvm-project/pull/83149 .

>From 612bc89ef805a3324520f4b7ef1ebb13e334ec0b Mon Sep 17 00:00:00 2001
From: hnakamura5 
Date: Tue, 19 Mar 2024 18:46:37 +0900
Subject: [PATCH] [clang-format] Fixed the warning in building document for
 TableGenBreakingDAGArgOperators.

---
 clang/docs/ClangFormatStyleOptions.rst | 2 +-
 clang/include/clang/Format/Format.h| 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/clang/docs/ClangFormatStyleOptions.rst 
b/clang/docs/ClangFormatStyleOptions.rst
index 35b6d0a2b52b67..be021dfc5c084c 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -6204,7 +6204,7 @@ the configuration (without a prefix: ``Auto``).
 
   For example the configuration,
 
-  .. code-block:: c++
+  .. code-block:: yaml
 
 TableGenBreakInsideDAGArg: BreakAll
 TableGenBreakingDAGArgOperators: ['ins', 'outs']
diff --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index 54861a66889e22..7ad2579bf7773b 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -4735,7 +4735,7 @@ struct FormatStyle {
   /// the specified identifiers.
   ///
   /// For example the configuration,
-  /// \code
+  /// \code{.yaml}
   ///   TableGenBreakInsideDAGArg: BreakAll
   ///   TableGenBreakingDAGArgOperators: ['ins', 'outs']
   /// \endcode

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format] Add Options to break inside the TableGen DAGArg. (PR #83149)

2024-03-18 Thread Hirofumi Nakamura via cfe-commits

hnakamura5 wrote:

Thank you very much!
I really appreciate you for reviewing up to such a complicated option.

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


[clang] [clang-format] Add Options to break inside the TableGen DAGArg. (PR #83149)

2024-03-18 Thread Hirofumi Nakamura via cfe-commits

https://github.com/hnakamura5 closed 
https://github.com/llvm/llvm-project/pull/83149
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format] Add Options to break inside the TableGen DAGArg. (PR #83149)

2024-03-17 Thread Hirofumi Nakamura via cfe-commits


@@ -1842,6 +1846,19 @@ void 
ContinuationIndenter::moveStatePastScopeOpener(LineState ,
 Style.ContinuationIndentWidth +
 std::max(CurrentState.LastSpace, CurrentState.StartOfFunctionCall);
 
+if (Style.isTableGen()) {
+  if (Current.is(TT_TableGenDAGArgOpenerToBreak) &&
+  Style.TableGenBreakInsideDAGArg == FormatStyle::DAS_BreakElements) {

hnakamura5 wrote:

Changed as suggested.

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


[clang] [clang-format] Add Options to break inside the TableGen DAGArg. (PR #83149)

2024-03-17 Thread Hirofumi Nakamura via cfe-commits


@@ -332,6 +332,84 @@ TEST_F(FormatTestTableGen, Assert) {
   verifyFormat("assert !le(DefVar1, 0), \"Assert1\";\n");
 }
 
+TEST_F(FormatTestTableGen, DAGArgBreakElements) {
+  FormatStyle Style = getGoogleStyle(FormatStyle::LK_TableGen);
+  Style.ColumnLimit = 60;
+  // By default, the DAGArg does not have a break inside.
+  verifyFormat("def Def : Parent {\n"

hnakamura5 wrote:

Added the suggested check of default option.

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


[clang] [clang-format] Add Options to break inside the TableGen DAGArg. (PR #83149)

2024-03-17 Thread Hirofumi Nakamura via cfe-commits

https://github.com/hnakamura5 updated 
https://github.com/llvm/llvm-project/pull/83149

>From becb28f6daa1fed9cabe40375a7ed863207b6bd2 Mon Sep 17 00:00:00 2001
From: hnakamura5 
Date: Wed, 28 Feb 2024 01:10:12 +0900
Subject: [PATCH 1/4] [clang-format] Add Options to break inside the TableGen
 DAGArg.

---
 clang/docs/ClangFormatStyleOptions.rst| 42 
 clang/include/clang/Format/Format.h   | 46 +++--
 clang/lib/Format/ContinuationIndenter.cpp |  3 +-
 clang/lib/Format/Format.cpp   |  6 +++
 clang/lib/Format/FormatToken.h|  2 +
 clang/lib/Format/TokenAnnotator.cpp   | 49 ++-
 clang/unittests/Format/FormatTestTableGen.cpp | 42 
 clang/unittests/Format/TokenAnnotatorTest.cpp | 41 
 8 files changed, 226 insertions(+), 5 deletions(-)

diff --git a/clang/docs/ClangFormatStyleOptions.rst 
b/clang/docs/ClangFormatStyleOptions.rst
index df399a229d8d4f..9b055d16b24ac9 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -6158,6 +6158,48 @@ the configuration (without a prefix: ``Auto``).
 **TabWidth** (``Unsigned``) :versionbadge:`clang-format 3.7` :ref:`¶ 
`
   The number of columns used for tab stops.
 
+.. _TableGenBreakInsideDAGArgList:
+
+**TableGenBreakInsideDAGArgList** (``Boolean``) :versionbadge:`clang-format 
19` :ref:`¶ `
+  Insert the line break for each element of DAGArg list in TableGen.
+
+
+  .. code-block:: c++
+
+let DAGArgIns = (ins
+i32:$src1,
+i32:$src2
+);
+
+.. _TableGenBreakingDAGArgOperators:
+
+**TableGenBreakingDAGArgOperators** (``List of Strings``) 
:versionbadge:`clang-format 19` :ref:`¶ `
+  Works only when TableGenBreakInsideDAGArgList is true.
+  The string list needs to consist of identifiers in TableGen.
+  If any identifier is specified, this limits the line breaks by
+  TableGenBreakInsideDAGArgList option only on DAGArg values beginning with
+  the specified identifiers.
+
+  For example the configuration,
+
+  .. code-block:: c++
+
+TableGenBreakInsideDAGArgList: true
+TableGenBreakingDAGArgOperators: ['ins', 'outs']
+
+  makes the line break only occurs inside DAGArgs beginning with the
+  specified identifiers 'ins' and 'outs'.
+
+
+  .. code-block:: c++
+
+let DAGArgIns = (ins
+i32:$src1,
+i32:$src2
+);
+let DAGArgOtherID = (other i32:$other1, i32:$other2);
+let DAGArgBang = (!cast("Some") i32:$src1, i32:$src2)
+
 .. _TypeNames:
 
 **TypeNames** (``List of Strings``) :versionbadge:`clang-format 17` :ref:`¶ 
`
diff --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index 613f1fd168465d..9729634183110c 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -4728,6 +4728,43 @@ struct FormatStyle {
   /// \version 8
   std::vector StatementMacros;
 
+  /// Works only when TableGenBreakInsideDAGArgList is true.
+  /// The string list needs to consist of identifiers in TableGen.
+  /// If any identifier is specified, this limits the line breaks by
+  /// TableGenBreakInsideDAGArgList option only on DAGArg values beginning with
+  /// the specified identifiers.
+  ///
+  /// For example the configuration,
+  /// \code
+  ///   TableGenBreakInsideDAGArgList: true
+  ///   TableGenBreakingDAGArgOperators: ['ins', 'outs']
+  /// \endcode
+  ///
+  /// makes the line break only occurs inside DAGArgs beginning with the
+  /// specified identifiers 'ins' and 'outs'.
+  ///
+  /// \code
+  ///   let DAGArgIns = (ins
+  ///   i32:$src1,
+  ///   i32:$src2
+  ///   );
+  ///   let DAGArgOtherID = (other i32:$other1, i32:$other2);
+  ///   let DAGArgBang = (!cast("Some") i32:$src1, i32:$src2)
+  /// \endcode
+  /// \version 19
+  std::vector TableGenBreakingDAGArgOperators;
+
+  /// Insert the line break for each element of DAGArg list in TableGen.
+  ///
+  /// \code
+  ///   let DAGArgIns = (ins
+  ///   i32:$src1,
+  ///   i32:$src2
+  ///   );
+  /// \endcode
+  /// \version 19
+  bool TableGenBreakInsideDAGArgList;
+
   /// The number of columns used for tab stops.
   /// \version 3.7
   unsigned TabWidth;
@@ -4980,9 +5017,12 @@ struct FormatStyle {
SpacesInSquareBrackets == R.SpacesInSquareBrackets &&
Standard == R.Standard &&
StatementAttributeLikeMacros == R.StatementAttributeLikeMacros &&
-   StatementMacros == R.StatementMacros && TabWidth == R.TabWidth &&
-   TypeNames == R.TypeNames && TypenameMacros == R.TypenameMacros &&
-   UseTab == R.UseTab &&
+   StatementMacros == R.StatementMacros &&
+   TableGenBreakingDAGArgOperators ==
+   R.TableGenBreakingDAGArgOperators &&
+   TableGenBreakInsideDAGArgList == R.TableGenBreakInsideDAGArgList &&
+   TabWidth == R.TabWidth && TypeNames == R.TypeNames &&
+   TypenameMacros == R.TypenameMacros && 

[clang] [clang-format] Add Options to break inside the TableGen DAGArg. (PR #83149)

2024-03-17 Thread Hirofumi Nakamura via cfe-commits


@@ -2332,6 +2332,77 @@ TEST_F(TokenAnnotatorTest, UnderstandTableGenTokens) {
   EXPECT_TOKEN(Tokens[4], tok::less, TT_TemplateOpener);
   EXPECT_TOKEN(Tokens[6], tok::greater, TT_TemplateCloser);
   EXPECT_TOKEN(Tokens[7], tok::l_brace, TT_FunctionLBrace);
+
+  // DAGArg breaking options. They use different token types depending on what
+  // is specified.
+  Style.TableGenBreakInsideDAGArg = FormatStyle::DAS_BreakElements;
+
+  // When TableGenBreakInsideDAGArg is DAS_BreakElements and
+  // TableGenBreakingDAGArgOperators is not specified, it makes all the DAGArg
+  // elements to have line break.
+  Tokens = AnnotateValue("(ins type1:$src1, type2:$src2)");
+  ASSERT_EQ(Tokens.size(), 10u) << Tokens;
+  EXPECT_TOKEN(Tokens[0], tok::l_paren, TT_TableGenDAGArgOpenerToBreak);
+  EXPECT_TOKEN(Tokens[1], tok::identifier,
+   TT_TableGenDAGArgOperatorID); // ins
+  EXPECT_TOKEN(Tokens[5], tok::comma, TT_TableGenDAGArgListCommaToBreak);
+  EXPECT_TOKEN(Tokens[9], tok::r_paren, TT_TableGenDAGArgCloser);
+
+  Tokens = AnnotateValue("(other type1:$src1, type2:$src2)");
+  ASSERT_EQ(Tokens.size(), 10u) << Tokens;
+  EXPECT_TOKEN(Tokens[0], tok::l_paren, TT_TableGenDAGArgOpenerToBreak);
+  EXPECT_TOKEN(Tokens[1], tok::identifier,
+   TT_TableGenDAGArgOperatorID); // other
+  EXPECT_TOKEN(Tokens[5], tok::comma, TT_TableGenDAGArgListCommaToBreak);
+  EXPECT_TOKEN(Tokens[9], tok::r_paren, TT_TableGenDAGArgCloser);
+
+  // For non-identifier operators, breaks after the operator.
+  Tokens = AnnotateValue("(!cast(\"Name\") type1:$src1, type2:$src2)");
+  ASSERT_EQ(Tokens.size(), 16u) << Tokens;
+  EXPECT_TOKEN(Tokens[0], tok::l_paren, TT_TableGenDAGArgOpenerToBreak);
+  EXPECT_TOKEN(Tokens[7], tok::r_paren, TT_TableGenDAGArgOperatorToBreak);
+  EXPECT_TOKEN(Tokens[11], tok::comma, TT_TableGenDAGArgListCommaToBreak);
+  EXPECT_TOKEN(Tokens[15], tok::r_paren, TT_TableGenDAGArgCloser);
+
+  Style.TableGenBreakInsideDAGArg = FormatStyle::DAS_BreakAll;
+
+  // When TableGenBreakInsideDAGArg is DAS_BreakAll and
+  // TableGenBreakingDAGArgOperators is not specified, it makes all the DAGArg
+  // to have line break inside it.
+  Tokens = AnnotateValue("(ins type1:$src1, type2:$src2)");
+  ASSERT_EQ(Tokens.size(), 10u) << Tokens;
+  EXPECT_TOKEN(Tokens[0], tok::l_paren, TT_TableGenDAGArgOpenerToBreak);
+  EXPECT_TOKEN(Tokens[1], tok::identifier,
+   TT_TableGenDAGArgOperatorToBreak); // ins
+  EXPECT_TOKEN(Tokens[5], tok::comma, TT_TableGenDAGArgListCommaToBreak);
+  EXPECT_TOKEN(Tokens[9], tok::r_paren, TT_TableGenDAGArgCloser);
+
+  Tokens = AnnotateValue("(other type1:$src1, type2:$src2)");
+  ASSERT_EQ(Tokens.size(), 10u) << Tokens;
+  EXPECT_TOKEN(Tokens[0], tok::l_paren, TT_TableGenDAGArgOpenerToBreak);
+  EXPECT_TOKEN(Tokens[1], tok::identifier,
+   TT_TableGenDAGArgOperatorToBreak); // other
+  EXPECT_TOKEN(Tokens[5], tok::comma, TT_TableGenDAGArgListCommaToBreak);
+  EXPECT_TOKEN(Tokens[9], tok::r_paren, TT_TableGenDAGArgCloser);
+
+  // If TableGenBreakingDAGArgOperators is specified, it is limited to the
+  // specified operators.
+  Style.TableGenBreakingDAGArgOperators = {"ins", "outs"};
+  Tokens = AnnotateValue("(ins type1:$src1, type2:$src2)");
+  ASSERT_EQ(Tokens.size(), 10u) << Tokens;
+  EXPECT_TOKEN(Tokens[0], tok::l_paren, TT_TableGenDAGArgOpenerToBreak);
+  EXPECT_TOKEN(Tokens[1], tok::identifier,
+   TT_TableGenDAGArgOperatorToBreak); // ins
+  EXPECT_TOKEN(Tokens[5], tok::comma, TT_TableGenDAGArgListCommaToBreak);
+  EXPECT_TOKEN(Tokens[9], tok::r_paren, TT_TableGenDAGArgCloser);
+
+  Tokens = AnnotateValue("(other type1:$src1, type2:$src2)");
+  ASSERT_EQ(Tokens.size(), 10u) << Tokens;
+  EXPECT_TOKEN(Tokens[0], tok::l_paren, TT_TableGenDAGArgOpener);
+  EXPECT_TOKEN(Tokens[1], tok::identifier,
+   TT_Unknown); // other

hnakamura5 wrote:

Fixed as suggested.

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


[clang] [clang-format] Add Options to break inside the TableGen DAGArg. (PR #83149)

2024-03-10 Thread Hirofumi Nakamura via cfe-commits

https://github.com/hnakamura5 updated 
https://github.com/llvm/llvm-project/pull/83149

>From becb28f6daa1fed9cabe40375a7ed863207b6bd2 Mon Sep 17 00:00:00 2001
From: hnakamura5 
Date: Wed, 28 Feb 2024 01:10:12 +0900
Subject: [PATCH 1/3] [clang-format] Add Options to break inside the TableGen
 DAGArg.

---
 clang/docs/ClangFormatStyleOptions.rst| 42 
 clang/include/clang/Format/Format.h   | 46 +++--
 clang/lib/Format/ContinuationIndenter.cpp |  3 +-
 clang/lib/Format/Format.cpp   |  6 +++
 clang/lib/Format/FormatToken.h|  2 +
 clang/lib/Format/TokenAnnotator.cpp   | 49 ++-
 clang/unittests/Format/FormatTestTableGen.cpp | 42 
 clang/unittests/Format/TokenAnnotatorTest.cpp | 41 
 8 files changed, 226 insertions(+), 5 deletions(-)

diff --git a/clang/docs/ClangFormatStyleOptions.rst 
b/clang/docs/ClangFormatStyleOptions.rst
index df399a229d8d4f..9b055d16b24ac9 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -6158,6 +6158,48 @@ the configuration (without a prefix: ``Auto``).
 **TabWidth** (``Unsigned``) :versionbadge:`clang-format 3.7` :ref:`¶ 
`
   The number of columns used for tab stops.
 
+.. _TableGenBreakInsideDAGArgList:
+
+**TableGenBreakInsideDAGArgList** (``Boolean``) :versionbadge:`clang-format 
19` :ref:`¶ `
+  Insert the line break for each element of DAGArg list in TableGen.
+
+
+  .. code-block:: c++
+
+let DAGArgIns = (ins
+i32:$src1,
+i32:$src2
+);
+
+.. _TableGenBreakingDAGArgOperators:
+
+**TableGenBreakingDAGArgOperators** (``List of Strings``) 
:versionbadge:`clang-format 19` :ref:`¶ `
+  Works only when TableGenBreakInsideDAGArgList is true.
+  The string list needs to consist of identifiers in TableGen.
+  If any identifier is specified, this limits the line breaks by
+  TableGenBreakInsideDAGArgList option only on DAGArg values beginning with
+  the specified identifiers.
+
+  For example the configuration,
+
+  .. code-block:: c++
+
+TableGenBreakInsideDAGArgList: true
+TableGenBreakingDAGArgOperators: ['ins', 'outs']
+
+  makes the line break only occurs inside DAGArgs beginning with the
+  specified identifiers 'ins' and 'outs'.
+
+
+  .. code-block:: c++
+
+let DAGArgIns = (ins
+i32:$src1,
+i32:$src2
+);
+let DAGArgOtherID = (other i32:$other1, i32:$other2);
+let DAGArgBang = (!cast("Some") i32:$src1, i32:$src2)
+
 .. _TypeNames:
 
 **TypeNames** (``List of Strings``) :versionbadge:`clang-format 17` :ref:`¶ 
`
diff --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index 613f1fd168465d..9729634183110c 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -4728,6 +4728,43 @@ struct FormatStyle {
   /// \version 8
   std::vector StatementMacros;
 
+  /// Works only when TableGenBreakInsideDAGArgList is true.
+  /// The string list needs to consist of identifiers in TableGen.
+  /// If any identifier is specified, this limits the line breaks by
+  /// TableGenBreakInsideDAGArgList option only on DAGArg values beginning with
+  /// the specified identifiers.
+  ///
+  /// For example the configuration,
+  /// \code
+  ///   TableGenBreakInsideDAGArgList: true
+  ///   TableGenBreakingDAGArgOperators: ['ins', 'outs']
+  /// \endcode
+  ///
+  /// makes the line break only occurs inside DAGArgs beginning with the
+  /// specified identifiers 'ins' and 'outs'.
+  ///
+  /// \code
+  ///   let DAGArgIns = (ins
+  ///   i32:$src1,
+  ///   i32:$src2
+  ///   );
+  ///   let DAGArgOtherID = (other i32:$other1, i32:$other2);
+  ///   let DAGArgBang = (!cast("Some") i32:$src1, i32:$src2)
+  /// \endcode
+  /// \version 19
+  std::vector TableGenBreakingDAGArgOperators;
+
+  /// Insert the line break for each element of DAGArg list in TableGen.
+  ///
+  /// \code
+  ///   let DAGArgIns = (ins
+  ///   i32:$src1,
+  ///   i32:$src2
+  ///   );
+  /// \endcode
+  /// \version 19
+  bool TableGenBreakInsideDAGArgList;
+
   /// The number of columns used for tab stops.
   /// \version 3.7
   unsigned TabWidth;
@@ -4980,9 +5017,12 @@ struct FormatStyle {
SpacesInSquareBrackets == R.SpacesInSquareBrackets &&
Standard == R.Standard &&
StatementAttributeLikeMacros == R.StatementAttributeLikeMacros &&
-   StatementMacros == R.StatementMacros && TabWidth == R.TabWidth &&
-   TypeNames == R.TypeNames && TypenameMacros == R.TypenameMacros &&
-   UseTab == R.UseTab &&
+   StatementMacros == R.StatementMacros &&
+   TableGenBreakingDAGArgOperators ==
+   R.TableGenBreakingDAGArgOperators &&
+   TableGenBreakInsideDAGArgList == R.TableGenBreakInsideDAGArgList &&
+   TabWidth == R.TabWidth && TypeNames == R.TypeNames &&
+   TypenameMacros == R.TypenameMacros && 

[clang] [clang-format] Add Options to break inside the TableGen DAGArg. (PR #83149)

2024-03-10 Thread Hirofumi Nakamura via cfe-commits

https://github.com/hnakamura5 edited 
https://github.com/llvm/llvm-project/pull/83149
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format] Add Options to break inside the TableGen DAGArg. (PR #83149)

2024-03-10 Thread Hirofumi Nakamura via cfe-commits

https://github.com/hnakamura5 updated 
https://github.com/llvm/llvm-project/pull/83149

>From becb28f6daa1fed9cabe40375a7ed863207b6bd2 Mon Sep 17 00:00:00 2001
From: hnakamura5 
Date: Wed, 28 Feb 2024 01:10:12 +0900
Subject: [PATCH 1/2] [clang-format] Add Options to break inside the TableGen
 DAGArg.

---
 clang/docs/ClangFormatStyleOptions.rst| 42 
 clang/include/clang/Format/Format.h   | 46 +++--
 clang/lib/Format/ContinuationIndenter.cpp |  3 +-
 clang/lib/Format/Format.cpp   |  6 +++
 clang/lib/Format/FormatToken.h|  2 +
 clang/lib/Format/TokenAnnotator.cpp   | 49 ++-
 clang/unittests/Format/FormatTestTableGen.cpp | 42 
 clang/unittests/Format/TokenAnnotatorTest.cpp | 41 
 8 files changed, 226 insertions(+), 5 deletions(-)

diff --git a/clang/docs/ClangFormatStyleOptions.rst 
b/clang/docs/ClangFormatStyleOptions.rst
index df399a229d8d4f..9b055d16b24ac9 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -6158,6 +6158,48 @@ the configuration (without a prefix: ``Auto``).
 **TabWidth** (``Unsigned``) :versionbadge:`clang-format 3.7` :ref:`¶ 
`
   The number of columns used for tab stops.
 
+.. _TableGenBreakInsideDAGArgList:
+
+**TableGenBreakInsideDAGArgList** (``Boolean``) :versionbadge:`clang-format 
19` :ref:`¶ `
+  Insert the line break for each element of DAGArg list in TableGen.
+
+
+  .. code-block:: c++
+
+let DAGArgIns = (ins
+i32:$src1,
+i32:$src2
+);
+
+.. _TableGenBreakingDAGArgOperators:
+
+**TableGenBreakingDAGArgOperators** (``List of Strings``) 
:versionbadge:`clang-format 19` :ref:`¶ `
+  Works only when TableGenBreakInsideDAGArgList is true.
+  The string list needs to consist of identifiers in TableGen.
+  If any identifier is specified, this limits the line breaks by
+  TableGenBreakInsideDAGArgList option only on DAGArg values beginning with
+  the specified identifiers.
+
+  For example the configuration,
+
+  .. code-block:: c++
+
+TableGenBreakInsideDAGArgList: true
+TableGenBreakingDAGArgOperators: ['ins', 'outs']
+
+  makes the line break only occurs inside DAGArgs beginning with the
+  specified identifiers 'ins' and 'outs'.
+
+
+  .. code-block:: c++
+
+let DAGArgIns = (ins
+i32:$src1,
+i32:$src2
+);
+let DAGArgOtherID = (other i32:$other1, i32:$other2);
+let DAGArgBang = (!cast("Some") i32:$src1, i32:$src2)
+
 .. _TypeNames:
 
 **TypeNames** (``List of Strings``) :versionbadge:`clang-format 17` :ref:`¶ 
`
diff --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index 613f1fd168465d..9729634183110c 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -4728,6 +4728,43 @@ struct FormatStyle {
   /// \version 8
   std::vector StatementMacros;
 
+  /// Works only when TableGenBreakInsideDAGArgList is true.
+  /// The string list needs to consist of identifiers in TableGen.
+  /// If any identifier is specified, this limits the line breaks by
+  /// TableGenBreakInsideDAGArgList option only on DAGArg values beginning with
+  /// the specified identifiers.
+  ///
+  /// For example the configuration,
+  /// \code
+  ///   TableGenBreakInsideDAGArgList: true
+  ///   TableGenBreakingDAGArgOperators: ['ins', 'outs']
+  /// \endcode
+  ///
+  /// makes the line break only occurs inside DAGArgs beginning with the
+  /// specified identifiers 'ins' and 'outs'.
+  ///
+  /// \code
+  ///   let DAGArgIns = (ins
+  ///   i32:$src1,
+  ///   i32:$src2
+  ///   );
+  ///   let DAGArgOtherID = (other i32:$other1, i32:$other2);
+  ///   let DAGArgBang = (!cast("Some") i32:$src1, i32:$src2)
+  /// \endcode
+  /// \version 19
+  std::vector TableGenBreakingDAGArgOperators;
+
+  /// Insert the line break for each element of DAGArg list in TableGen.
+  ///
+  /// \code
+  ///   let DAGArgIns = (ins
+  ///   i32:$src1,
+  ///   i32:$src2
+  ///   );
+  /// \endcode
+  /// \version 19
+  bool TableGenBreakInsideDAGArgList;
+
   /// The number of columns used for tab stops.
   /// \version 3.7
   unsigned TabWidth;
@@ -4980,9 +5017,12 @@ struct FormatStyle {
SpacesInSquareBrackets == R.SpacesInSquareBrackets &&
Standard == R.Standard &&
StatementAttributeLikeMacros == R.StatementAttributeLikeMacros &&
-   StatementMacros == R.StatementMacros && TabWidth == R.TabWidth &&
-   TypeNames == R.TypeNames && TypenameMacros == R.TypenameMacros &&
-   UseTab == R.UseTab &&
+   StatementMacros == R.StatementMacros &&
+   TableGenBreakingDAGArgOperators ==
+   R.TableGenBreakingDAGArgOperators &&
+   TableGenBreakInsideDAGArgList == R.TableGenBreakInsideDAGArgList &&
+   TabWidth == R.TabWidth && TypeNames == R.TypeNames &&
+   TypenameMacros == R.TypenameMacros && 

[clang] [clang-format] Add Options to break inside the TableGen DAGArg. (PR #83149)

2024-02-27 Thread Hirofumi Nakamura via cfe-commits

hnakamura5 wrote:

These options have a dependency that TableGenBreakInsideDAGArgList is effective 
only when TableGenBreakingDAGArgOperators is specified as true.
I'm not sure this is a smart way.

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


[clang] [clang-format] Support of TableGen formatting. (PR #76059)

2024-02-27 Thread Hirofumi Nakamura via cfe-commits

hnakamura5 wrote:

Break options for DAGArg: https://github.com/llvm/llvm-project/pull/83149.

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


[clang] [clang-format] Support of TableGen formatting. (PR #76059)

2024-02-27 Thread Hirofumi Nakamura via cfe-commits

hnakamura5 wrote:

Alignment option for definitions: 
https://github.com/llvm/llvm-project/pull/83008.

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


[clang] [clang-format] Add Options to break inside the TableGen DAGArg. (PR #83149)

2024-02-27 Thread Hirofumi Nakamura via cfe-commits

https://github.com/hnakamura5 created 
https://github.com/llvm/llvm-project/pull/83149

This adds two options to control the line break inside TableGen DAGArg.
- TableGenBreakInsideDAGArgList 
- TableGenBreakingDAGArgOperators


>From becb28f6daa1fed9cabe40375a7ed863207b6bd2 Mon Sep 17 00:00:00 2001
From: hnakamura5 
Date: Wed, 28 Feb 2024 01:10:12 +0900
Subject: [PATCH] [clang-format] Add Options to break inside the TableGen
 DAGArg.

---
 clang/docs/ClangFormatStyleOptions.rst| 42 
 clang/include/clang/Format/Format.h   | 46 +++--
 clang/lib/Format/ContinuationIndenter.cpp |  3 +-
 clang/lib/Format/Format.cpp   |  6 +++
 clang/lib/Format/FormatToken.h|  2 +
 clang/lib/Format/TokenAnnotator.cpp   | 49 ++-
 clang/unittests/Format/FormatTestTableGen.cpp | 42 
 clang/unittests/Format/TokenAnnotatorTest.cpp | 41 
 8 files changed, 226 insertions(+), 5 deletions(-)

diff --git a/clang/docs/ClangFormatStyleOptions.rst 
b/clang/docs/ClangFormatStyleOptions.rst
index df399a229d8d4f..9b055d16b24ac9 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -6158,6 +6158,48 @@ the configuration (without a prefix: ``Auto``).
 **TabWidth** (``Unsigned``) :versionbadge:`clang-format 3.7` :ref:`¶ 
`
   The number of columns used for tab stops.
 
+.. _TableGenBreakInsideDAGArgList:
+
+**TableGenBreakInsideDAGArgList** (``Boolean``) :versionbadge:`clang-format 
19` :ref:`¶ `
+  Insert the line break for each element of DAGArg list in TableGen.
+
+
+  .. code-block:: c++
+
+let DAGArgIns = (ins
+i32:$src1,
+i32:$src2
+);
+
+.. _TableGenBreakingDAGArgOperators:
+
+**TableGenBreakingDAGArgOperators** (``List of Strings``) 
:versionbadge:`clang-format 19` :ref:`¶ `
+  Works only when TableGenBreakInsideDAGArgList is true.
+  The string list needs to consist of identifiers in TableGen.
+  If any identifier is specified, this limits the line breaks by
+  TableGenBreakInsideDAGArgList option only on DAGArg values beginning with
+  the specified identifiers.
+
+  For example the configuration,
+
+  .. code-block:: c++
+
+TableGenBreakInsideDAGArgList: true
+TableGenBreakingDAGArgOperators: ['ins', 'outs']
+
+  makes the line break only occurs inside DAGArgs beginning with the
+  specified identifiers 'ins' and 'outs'.
+
+
+  .. code-block:: c++
+
+let DAGArgIns = (ins
+i32:$src1,
+i32:$src2
+);
+let DAGArgOtherID = (other i32:$other1, i32:$other2);
+let DAGArgBang = (!cast("Some") i32:$src1, i32:$src2)
+
 .. _TypeNames:
 
 **TypeNames** (``List of Strings``) :versionbadge:`clang-format 17` :ref:`¶ 
`
diff --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index 613f1fd168465d..9729634183110c 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -4728,6 +4728,43 @@ struct FormatStyle {
   /// \version 8
   std::vector StatementMacros;
 
+  /// Works only when TableGenBreakInsideDAGArgList is true.
+  /// The string list needs to consist of identifiers in TableGen.
+  /// If any identifier is specified, this limits the line breaks by
+  /// TableGenBreakInsideDAGArgList option only on DAGArg values beginning with
+  /// the specified identifiers.
+  ///
+  /// For example the configuration,
+  /// \code
+  ///   TableGenBreakInsideDAGArgList: true
+  ///   TableGenBreakingDAGArgOperators: ['ins', 'outs']
+  /// \endcode
+  ///
+  /// makes the line break only occurs inside DAGArgs beginning with the
+  /// specified identifiers 'ins' and 'outs'.
+  ///
+  /// \code
+  ///   let DAGArgIns = (ins
+  ///   i32:$src1,
+  ///   i32:$src2
+  ///   );
+  ///   let DAGArgOtherID = (other i32:$other1, i32:$other2);
+  ///   let DAGArgBang = (!cast("Some") i32:$src1, i32:$src2)
+  /// \endcode
+  /// \version 19
+  std::vector TableGenBreakingDAGArgOperators;
+
+  /// Insert the line break for each element of DAGArg list in TableGen.
+  ///
+  /// \code
+  ///   let DAGArgIns = (ins
+  ///   i32:$src1,
+  ///   i32:$src2
+  ///   );
+  /// \endcode
+  /// \version 19
+  bool TableGenBreakInsideDAGArgList;
+
   /// The number of columns used for tab stops.
   /// \version 3.7
   unsigned TabWidth;
@@ -4980,9 +5017,12 @@ struct FormatStyle {
SpacesInSquareBrackets == R.SpacesInSquareBrackets &&
Standard == R.Standard &&
StatementAttributeLikeMacros == R.StatementAttributeLikeMacros &&
-   StatementMacros == R.StatementMacros && TabWidth == R.TabWidth &&
-   TypeNames == R.TypeNames && TypenameMacros == R.TypenameMacros &&
-   UseTab == R.UseTab &&
+   StatementMacros == R.StatementMacros &&
+   TableGenBreakingDAGArgOperators ==
+   R.TableGenBreakingDAGArgOperators &&
+   TableGenBreakInsideDAGArgList == 

[clang] [clang-format] Add AlignConsecutiveTableGenDefinitions option. (PR #83008)

2024-02-27 Thread Hirofumi Nakamura via cfe-commits

hnakamura5 wrote:

Thank you!

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


[clang] [clang-format] Add AlignConsecutiveTableGenDefinitions option. (PR #83008)

2024-02-27 Thread Hirofumi Nakamura via cfe-commits

https://github.com/hnakamura5 closed 
https://github.com/llvm/llvm-project/pull/83008
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format] Add AlignConsecutiveTableGenDefinitions option. (PR #83008)

2024-02-26 Thread Hirofumi Nakamura via cfe-commits

https://github.com/hnakamura5 created 
https://github.com/llvm/llvm-project/pull/83008

To align TableGen consecutive definitions.

>From 4d22f709eff00b38cce6e9f4087bea14d04424fd Mon Sep 17 00:00:00 2001
From: hnakamura5 
Date: Mon, 26 Feb 2024 23:17:55 +0900
Subject: [PATCH 1/2] [clang-format] Add AlignConsecutiveTableGenDefinitions
 option to align TableGen consecutive definitions.

---
 clang/docs/ClangFormatStyleOptions.rst| 140 ++
 clang/include/clang/Format/Format.h   |  12 ++
 clang/lib/Format/Format.cpp   |   3 +
 clang/lib/Format/WhitespaceManager.cpp|   9 +-
 clang/lib/Format/WhitespaceManager.h  |   3 +
 clang/unittests/Format/FormatTestTableGen.cpp |  14 ++
 6 files changed, 180 insertions(+), 1 deletion(-)

diff --git a/clang/docs/ClangFormatStyleOptions.rst 
b/clang/docs/ClangFormatStyleOptions.rst
index d509bb80767979..7be66df3aec61d 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -1095,6 +1095,146 @@ the configuration (without a prefix: ``Auto``).
   bbb >>= 2;
 
 
+.. _AlignConsecutiveTableGenDefinitionsColons:
+
+**AlignConsecutiveTableGenDefinitionsColons** (``AlignConsecutiveStyle``) 
:versionbadge:`clang-format 19` :ref:`¶ 
`
+  Style of aligning consecutive TableGen definition colons.
+  This aligns the inheritance colons of consecutive definitions.
+
+  .. code-block:: c++
+
+def Def   : Parent {}
+def DefDef: Parent {}
+def DefDefDef : Parent {}
+
+  Nested configuration flags:
+
+  Alignment options.
+
+  They can also be read as a whole for compatibility. The choices are:
+  - None
+  - Consecutive
+  - AcrossEmptyLines
+  - AcrossComments
+  - AcrossEmptyLinesAndComments
+
+  For example, to align across empty lines and not across comments, either
+  of these work.
+
+  .. code-block:: c++
+
+AlignConsecutiveMacros: AcrossEmptyLines
+
+AlignConsecutiveMacros:
+  Enabled: true
+  AcrossEmptyLines: true
+  AcrossComments: false
+
+  * ``bool Enabled`` Whether aligning is enabled.
+
+.. code-block:: c++
+
+  #define SHORT_NAME   42
+  #define LONGER_NAME  0x007f
+  #define EVEN_LONGER_NAME (2)
+  #define foo(x)   (x * x)
+  #define bar(y, z)(y + z)
+
+  int a= 1;
+  int somelongname = 2;
+  double c = 3;
+
+  int  : 1;
+  int b: 12;
+  int ccc  : 8;
+
+  int  = 12;
+  float   b = 23;
+  std::string ccc;
+
+  * ``bool AcrossEmptyLines`` Whether to align across empty lines.
+
+.. code-block:: c++
+
+  true:
+  int a= 1;
+  int somelongname = 2;
+  double c = 3;
+
+  int d= 3;
+
+  false:
+  int a= 1;
+  int somelongname = 2;
+  double c = 3;
+
+  int d = 3;
+
+  * ``bool AcrossComments`` Whether to align across comments.
+
+.. code-block:: c++
+
+  true:
+  int d= 3;
+  /* A comment. */
+  double e = 4;
+
+  false:
+  int d = 3;
+  /* A comment. */
+  double e = 4;
+
+  * ``bool AlignCompound`` Only for ``AlignConsecutiveAssignments``.  Whether 
compound assignments
+like ``+=`` are aligned along with ``=``.
+
+.. code-block:: c++
+
+  true:
+  a   &= 2;
+  bbb  = 2;
+
+  false:
+  a &= 2;
+  bbb = 2;
+
+  * ``bool AlignFunctionPointers`` Only for ``AlignConsecutiveDeclarations``. 
Whether function pointers are
+aligned.
+
+.. code-block:: c++
+
+  true:
+  unsigned i;
+  int 
+  int *p;
+  int  (*f)();
+
+  false:
+  unsigned i;
+  int 
+  int *p;
+  int (*f)();
+
+  * ``bool PadOperators`` Only for ``AlignConsecutiveAssignments``.  Whether 
short assignment
+operators are left-padded to the same length as long ones in order to
+put all assignment operators to the right of the left hand side.
+
+.. code-block:: c++
+
+  true:
+  a   >>= 2;
+  bbb   = 2;
+
+  a = 2;
+  bbb >>= 2;
+
+  false:
+  a >>= 2;
+  bbb = 2;
+
+  a = 2;
+  bbb >>= 2;
+
+
 .. _AlignEscapedNewlines:
 
 **AlignEscapedNewlines** (``EscapedNewlineAlignmentStyle``) 
:versionbadge:`clang-format 5` :ref:`¶ `
diff --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index 449ce9e53be147..1b66d6b9fc6ced 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -424,6 +424,16 @@ struct FormatStyle {
   /// \version 19
   AlignConsecutiveStyle AlignConsecutiveTableGenCondOperatorColons;
 
+  /// Style of aligning consecutive TableGen definition colons.
+  /// This aligns the inheritance colons of consecutive definitions.
+  /// \code
+  ///   def Def   : Parent {}
+  ///   def DefDef: Parent {}
+  ///   def DefDefDef : Parent {}
+  /// \endcode
+  /// \version 19
+  

[clang] [clang-format] Add AlignConsecutiveTableGenCondOperatorColons option. (PR #82878)

2024-02-26 Thread Hirofumi Nakamura via cfe-commits

hnakamura5 wrote:

Thank you!

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


[clang] [clang-format] Add AlignConsecutiveTableGenCondOperatorColons option. (PR #82878)

2024-02-26 Thread Hirofumi Nakamura via cfe-commits

https://github.com/hnakamura5 closed 
https://github.com/llvm/llvm-project/pull/82878
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format] Add AlignConsecutiveTableGenCondOperatorColons option. (PR #82878)

2024-02-25 Thread Hirofumi Nakamura via cfe-commits


@@ -849,7 +851,12 @@ void WhitespaceManager::alignConsecutiveAssignments() {
 }
 
 void WhitespaceManager::alignConsecutiveBitFields() {
-  if (!Style.AlignConsecutiveBitFields.Enabled)
+  alignConsecutiveColons(Style.AlignConsecutiveBitFields, TT_BitFieldColon);
+}
+
+void WhitespaceManager::alignConsecutiveColons(
+const FormatStyle::AlignConsecutiveStyle , TokenType Type) {

hnakamura5 wrote:

Both are OK, but other such functions seems using const reference to pass style.

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


[clang] [clang-format] Support of TableGen formatting. (PR #76059)

2024-02-24 Thread Hirofumi Nakamura via cfe-commits

hnakamura5 wrote:

Alignment option for cond operator: 
https://github.com/llvm/llvm-project/pull/82878.

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


[clang] [clang-format] Add AlignConsecutiveTableGenCondOperatorColons option. (PR #82878)

2024-02-24 Thread Hirofumi Nakamura via cfe-commits

https://github.com/hnakamura5 created 
https://github.com/llvm/llvm-project/pull/82878

To align colons inside TableGen !cond operators.

>From d0ceab536cc9aa06ce5de1324eee1e3a05dac804 Mon Sep 17 00:00:00 2001
From: hnakamura5 
Date: Sat, 24 Feb 2024 22:21:04 +0900
Subject: [PATCH] [clang-format] Add AlignConsecutiveTableGenCondOperatorColons
  option to align colons in tablegen cond operators.

---
 clang/docs/ClangFormatStyleOptions.rst| 140 ++
 clang/include/clang/Format/Format.h   |  12 ++
 clang/lib/Format/Format.cpp   |   3 +
 clang/lib/Format/WhitespaceManager.cpp|  18 ++-
 clang/lib/Format/WhitespaceManager.h  |   8 +
 clang/unittests/Format/FormatTestTableGen.cpp |  21 +++
 6 files changed, 199 insertions(+), 3 deletions(-)

diff --git a/clang/docs/ClangFormatStyleOptions.rst 
b/clang/docs/ClangFormatStyleOptions.rst
index fdf7bfaeaa4ec7..2cb55503038f66 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -955,6 +955,146 @@ the configuration (without a prefix: ``Auto``).
   }
 
 
+.. _AlignConsecutiveTableGenCondOperatorColons:
+
+**AlignConsecutiveTableGenCondOperatorColons** (``AlignConsecutiveStyle``) 
:versionbadge:`clang-format 19` :ref:`¶ 
`
+  Style of aligning consecutive TableGen cond operator colons.
+  Align the colons of cases inside !cond operators.
+
+  .. code-block:: c++
+
+!cond(!eq(size, 1) : 1,
+  !eq(size, 16): 1,
+  true : 0)
+
+  Nested configuration flags:
+
+  Alignment options.
+
+  They can also be read as a whole for compatibility. The choices are:
+  - None
+  - Consecutive
+  - AcrossEmptyLines
+  - AcrossComments
+  - AcrossEmptyLinesAndComments
+
+  For example, to align across empty lines and not across comments, either
+  of these work.
+
+  .. code-block:: c++
+
+AlignConsecutiveMacros: AcrossEmptyLines
+
+AlignConsecutiveMacros:
+  Enabled: true
+  AcrossEmptyLines: true
+  AcrossComments: false
+
+  * ``bool Enabled`` Whether aligning is enabled.
+
+.. code-block:: c++
+
+  #define SHORT_NAME   42
+  #define LONGER_NAME  0x007f
+  #define EVEN_LONGER_NAME (2)
+  #define foo(x)   (x * x)
+  #define bar(y, z)(y + z)
+
+  int a= 1;
+  int somelongname = 2;
+  double c = 3;
+
+  int  : 1;
+  int b: 12;
+  int ccc  : 8;
+
+  int  = 12;
+  float   b = 23;
+  std::string ccc;
+
+  * ``bool AcrossEmptyLines`` Whether to align across empty lines.
+
+.. code-block:: c++
+
+  true:
+  int a= 1;
+  int somelongname = 2;
+  double c = 3;
+
+  int d= 3;
+
+  false:
+  int a= 1;
+  int somelongname = 2;
+  double c = 3;
+
+  int d = 3;
+
+  * ``bool AcrossComments`` Whether to align across comments.
+
+.. code-block:: c++
+
+  true:
+  int d= 3;
+  /* A comment. */
+  double e = 4;
+
+  false:
+  int d = 3;
+  /* A comment. */
+  double e = 4;
+
+  * ``bool AlignCompound`` Only for ``AlignConsecutiveAssignments``.  Whether 
compound assignments
+like ``+=`` are aligned along with ``=``.
+
+.. code-block:: c++
+
+  true:
+  a   &= 2;
+  bbb  = 2;
+
+  false:
+  a &= 2;
+  bbb = 2;
+
+  * ``bool AlignFunctionPointers`` Only for ``AlignConsecutiveDeclarations``. 
Whether function pointers are
+aligned.
+
+.. code-block:: c++
+
+  true:
+  unsigned i;
+  int 
+  int *p;
+  int  (*f)();
+
+  false:
+  unsigned i;
+  int 
+  int *p;
+  int (*f)();
+
+  * ``bool PadOperators`` Only for ``AlignConsecutiveAssignments``.  Whether 
short assignment
+operators are left-padded to the same length as long ones in order to
+put all assignment operators to the right of the left hand side.
+
+.. code-block:: c++
+
+  true:
+  a   >>= 2;
+  bbb   = 2;
+
+  a = 2;
+  bbb >>= 2;
+
+  false:
+  a >>= 2;
+  bbb = 2;
+
+  a = 2;
+  bbb >>= 2;
+
+
 .. _AlignEscapedNewlines:
 
 **AlignEscapedNewlines** (``EscapedNewlineAlignmentStyle``) 
:versionbadge:`clang-format 5` :ref:`¶ `
diff --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index e9b2160a7b9243..11853d23f2b42b 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -414,6 +414,16 @@ struct FormatStyle {
   /// \version 17
   ShortCaseStatementsAlignmentStyle AlignConsecutiveShortCaseStatements;
 
+  /// Style of aligning consecutive TableGen cond operator colons.
+  /// Align the colons of cases inside !cond operators.
+  /// \code
+  ///   !cond(!eq(size, 1) : 1,
+  /// !eq(size, 16): 1,
+  /// true : 0)
+  /// \endcode
+  /// \version 19
+  AlignConsecutiveStyle 

[clang] [clang-format] Support of TableGen basic format restrictions. (PR #81611)

2024-02-16 Thread Hirofumi Nakamura via cfe-commits

hnakamura5 wrote:

Thank you very much!

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


[clang] [clang-format] Support of TableGen basic format restrictions. (PR #81611)

2024-02-16 Thread Hirofumi Nakamura via cfe-commits

https://github.com/hnakamura5 closed 
https://github.com/llvm/llvm-project/pull/81611
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format] Support of TableGen basic format restrictions. (PR #81611)

2024-02-15 Thread Hirofumi Nakamura via cfe-commits

https://github.com/hnakamura5 updated 
https://github.com/llvm/llvm-project/pull/81611

>From 7ee4b35f0aed434053b6fd6329ef39de97bc22db Mon Sep 17 00:00:00 2001
From: hnakamura5 
Date: Tue, 13 Feb 2024 23:50:15 +0900
Subject: [PATCH 1/6] [clang-format] Support of TableGen basic format
 restrictions.

- Allow/force to break the line or not.
- Allow to insert space or not.
---
 clang/lib/Format/ContinuationIndenter.cpp |  14 +-
 clang/lib/Format/TokenAnnotator.cpp   |  56 
 clang/unittests/Format/FormatTestTableGen.cpp | 263 ++
 3 files changed, 331 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Format/ContinuationIndenter.cpp 
b/clang/lib/Format/ContinuationIndenter.cpp
index 0b2ef97af44d83..1879af94f6da49 100644
--- a/clang/lib/Format/ContinuationIndenter.cpp
+++ b/clang/lib/Format/ContinuationIndenter.cpp
@@ -821,6 +821,7 @@ void ContinuationIndenter::addTokenOnCurrentLine(LineState 
, bool DryRun,
   if (Style.AlignAfterOpenBracket != FormatStyle::BAS_DontAlign &&
   !CurrentState.IsCSharpGenericTypeConstraint && Previous.opensScope() &&
   Previous.isNot(TT_ObjCMethodExpr) && Previous.isNot(TT_RequiresClause) &&
+  Previous.isNot(TT_TableGenDAGArgOpener) &&
   !(Current.MacroParent && Previous.MacroParent) &&
   (Current.isNot(TT_LineComment) ||
Previous.isOneOf(BK_BracedInit, TT_VerilogMultiLineListLParen))) {
@@ -1250,7 +1251,7 @@ unsigned ContinuationIndenter::getNewLineColumn(const 
LineState ) {
 return CurrentState.Indent;
   }
   if ((Current.isOneOf(tok::r_brace, tok::r_square) ||
-   (Current.is(tok::greater) && Style.isProto())) &&
+   (Current.is(tok::greater) && (Style.isProto() || Style.isTableGen( 
&&
   State.Stack.size() > 1) {
 if (Current.closesBlockOrBlockTypeList(Style))
   return State.Stack[State.Stack.size() - 2].NestedBlockIndent;
@@ -1278,6 +1279,12 @@ unsigned ContinuationIndenter::getNewLineColumn(const 
LineState ) {
Current.Next->isOneOf(tok::semi, tok::kw_const, tok::l_brace))) {
 return State.Stack[State.Stack.size() - 2].LastSpace;
   }
+  // When DAGArg closer exists top of line, it should be aligned in the similar
+  // way as function call above.
+  if (Style.isTableGen() && Current.is(TT_TableGenDAGArgCloser) &&
+  State.Stack.size() > 1) {
+return State.Stack[State.Stack.size() - 2].LastSpace;
+  }
   if (Style.AlignAfterOpenBracket == FormatStyle::BAS_BlockIndent &&
   (Current.is(tok::r_paren) ||
(Current.is(tok::r_brace) && Current.MatchingParen &&
@@ -1696,7 +1703,9 @@ void 
ContinuationIndenter::moveStatePastFakeLParens(LineState ,
 (!Previous || Previous->isNot(tok::kw_return) ||
  (Style.Language != FormatStyle::LK_Java && PrecedenceLevel > 0)) &&
 (Style.AlignAfterOpenBracket != FormatStyle::BAS_DontAlign ||
- PrecedenceLevel != prec::Comma || Current.NestingLevel == 0)) {
+ PrecedenceLevel != prec::Comma || Current.NestingLevel == 0) &&
+(!Style.isTableGen() ||
+ (Previous && Previous->is(TT_TableGenDAGArgListComma {
   NewParenState.Indent = std::max(
   std::max(State.Column, NewParenState.Indent), 
CurrentState.LastSpace);
 }
@@ -1942,6 +1951,7 @@ void 
ContinuationIndenter::moveStatePastScopeCloser(LineState ) {
   (Current.isOneOf(tok::r_paren, tok::r_square, TT_TemplateString) ||
(Current.is(tok::r_brace) && State.NextToken != State.Line->First) ||
State.NextToken->is(TT_TemplateCloser) ||
+   State.NextToken->is(TT_TableGenListCloser) ||
(Current.is(tok::greater) && Current.is(TT_DictLiteral {
 State.Stack.pop_back();
   }
diff --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index d353388a862b56..636d098881c97e 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -5072,7 +5072,38 @@ bool TokenAnnotator::spaceRequiredBefore(const 
AnnotatedLine ,
  Left.endsSequence(tok::greatergreater, tok::l_brace))) {
   return false;
 }
+  } else if (Style.isTableGen()) {
+// Avoid to connect [ and {. [{ is start token of multiline string.
+if (Left.is(tok::l_square) && Right.is(tok::l_brace))
+  return true;
+if (Left.is(tok::r_brace) && Right.is(tok::r_square))
+  return true;
+// Do not insert around colon in DAGArg and cond operator.
+if (Right.is(TT_TableGenDAGArgListColon) ||
+Left.is(TT_TableGenDAGArgListColon)) {
+  return false;
+}
+if (Right.is(TT_TableGenCondOperatorColon))
+  return false;
+// Do not insert bang operators and consequent openers.
+if (Right.isOneOf(tok::l_paren, tok::greater) &&
+Left.isOneOf(TT_TableGenBangOperator, TT_TableGenCondOperator)) {
+  return false;
+}
+// Trailing paste requires space before '{' or ':', the case in name 
values.
+// Not before ';', the case in normal values.
+if 

[clang] [clang-format] Support of TableGen basic format restrictions. (PR #81611)

2024-02-14 Thread Hirofumi Nakamura via cfe-commits

https://github.com/hnakamura5 updated 
https://github.com/llvm/llvm-project/pull/81611

>From 7ee4b35f0aed434053b6fd6329ef39de97bc22db Mon Sep 17 00:00:00 2001
From: hnakamura5 
Date: Tue, 13 Feb 2024 23:50:15 +0900
Subject: [PATCH 1/5] [clang-format] Support of TableGen basic format
 restrictions.

- Allow/force to break the line or not.
- Allow to insert space or not.
---
 clang/lib/Format/ContinuationIndenter.cpp |  14 +-
 clang/lib/Format/TokenAnnotator.cpp   |  56 
 clang/unittests/Format/FormatTestTableGen.cpp | 263 ++
 3 files changed, 331 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Format/ContinuationIndenter.cpp 
b/clang/lib/Format/ContinuationIndenter.cpp
index 0b2ef97af44d83..1879af94f6da49 100644
--- a/clang/lib/Format/ContinuationIndenter.cpp
+++ b/clang/lib/Format/ContinuationIndenter.cpp
@@ -821,6 +821,7 @@ void ContinuationIndenter::addTokenOnCurrentLine(LineState 
, bool DryRun,
   if (Style.AlignAfterOpenBracket != FormatStyle::BAS_DontAlign &&
   !CurrentState.IsCSharpGenericTypeConstraint && Previous.opensScope() &&
   Previous.isNot(TT_ObjCMethodExpr) && Previous.isNot(TT_RequiresClause) &&
+  Previous.isNot(TT_TableGenDAGArgOpener) &&
   !(Current.MacroParent && Previous.MacroParent) &&
   (Current.isNot(TT_LineComment) ||
Previous.isOneOf(BK_BracedInit, TT_VerilogMultiLineListLParen))) {
@@ -1250,7 +1251,7 @@ unsigned ContinuationIndenter::getNewLineColumn(const 
LineState ) {
 return CurrentState.Indent;
   }
   if ((Current.isOneOf(tok::r_brace, tok::r_square) ||
-   (Current.is(tok::greater) && Style.isProto())) &&
+   (Current.is(tok::greater) && (Style.isProto() || Style.isTableGen( 
&&
   State.Stack.size() > 1) {
 if (Current.closesBlockOrBlockTypeList(Style))
   return State.Stack[State.Stack.size() - 2].NestedBlockIndent;
@@ -1278,6 +1279,12 @@ unsigned ContinuationIndenter::getNewLineColumn(const 
LineState ) {
Current.Next->isOneOf(tok::semi, tok::kw_const, tok::l_brace))) {
 return State.Stack[State.Stack.size() - 2].LastSpace;
   }
+  // When DAGArg closer exists top of line, it should be aligned in the similar
+  // way as function call above.
+  if (Style.isTableGen() && Current.is(TT_TableGenDAGArgCloser) &&
+  State.Stack.size() > 1) {
+return State.Stack[State.Stack.size() - 2].LastSpace;
+  }
   if (Style.AlignAfterOpenBracket == FormatStyle::BAS_BlockIndent &&
   (Current.is(tok::r_paren) ||
(Current.is(tok::r_brace) && Current.MatchingParen &&
@@ -1696,7 +1703,9 @@ void 
ContinuationIndenter::moveStatePastFakeLParens(LineState ,
 (!Previous || Previous->isNot(tok::kw_return) ||
  (Style.Language != FormatStyle::LK_Java && PrecedenceLevel > 0)) &&
 (Style.AlignAfterOpenBracket != FormatStyle::BAS_DontAlign ||
- PrecedenceLevel != prec::Comma || Current.NestingLevel == 0)) {
+ PrecedenceLevel != prec::Comma || Current.NestingLevel == 0) &&
+(!Style.isTableGen() ||
+ (Previous && Previous->is(TT_TableGenDAGArgListComma {
   NewParenState.Indent = std::max(
   std::max(State.Column, NewParenState.Indent), 
CurrentState.LastSpace);
 }
@@ -1942,6 +1951,7 @@ void 
ContinuationIndenter::moveStatePastScopeCloser(LineState ) {
   (Current.isOneOf(tok::r_paren, tok::r_square, TT_TemplateString) ||
(Current.is(tok::r_brace) && State.NextToken != State.Line->First) ||
State.NextToken->is(TT_TemplateCloser) ||
+   State.NextToken->is(TT_TableGenListCloser) ||
(Current.is(tok::greater) && Current.is(TT_DictLiteral {
 State.Stack.pop_back();
   }
diff --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index d353388a862b56..636d098881c97e 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -5072,7 +5072,38 @@ bool TokenAnnotator::spaceRequiredBefore(const 
AnnotatedLine ,
  Left.endsSequence(tok::greatergreater, tok::l_brace))) {
   return false;
 }
+  } else if (Style.isTableGen()) {
+// Avoid to connect [ and {. [{ is start token of multiline string.
+if (Left.is(tok::l_square) && Right.is(tok::l_brace))
+  return true;
+if (Left.is(tok::r_brace) && Right.is(tok::r_square))
+  return true;
+// Do not insert around colon in DAGArg and cond operator.
+if (Right.is(TT_TableGenDAGArgListColon) ||
+Left.is(TT_TableGenDAGArgListColon)) {
+  return false;
+}
+if (Right.is(TT_TableGenCondOperatorColon))
+  return false;
+// Do not insert bang operators and consequent openers.
+if (Right.isOneOf(tok::l_paren, tok::greater) &&
+Left.isOneOf(TT_TableGenBangOperator, TT_TableGenCondOperator)) {
+  return false;
+}
+// Trailing paste requires space before '{' or ':', the case in name 
values.
+// Not before ';', the case in normal values.
+if 

[clang] [clang-format] Support of TableGen basic format restrictions. (PR #81611)

2024-02-14 Thread Hirofumi Nakamura via cfe-commits

https://github.com/hnakamura5 updated 
https://github.com/llvm/llvm-project/pull/81611

>From 7ee4b35f0aed434053b6fd6329ef39de97bc22db Mon Sep 17 00:00:00 2001
From: hnakamura5 
Date: Tue, 13 Feb 2024 23:50:15 +0900
Subject: [PATCH 1/4] [clang-format] Support of TableGen basic format
 restrictions.

- Allow/force to break the line or not.
- Allow to insert space or not.
---
 clang/lib/Format/ContinuationIndenter.cpp |  14 +-
 clang/lib/Format/TokenAnnotator.cpp   |  56 
 clang/unittests/Format/FormatTestTableGen.cpp | 263 ++
 3 files changed, 331 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Format/ContinuationIndenter.cpp 
b/clang/lib/Format/ContinuationIndenter.cpp
index 0b2ef97af44d83..1879af94f6da49 100644
--- a/clang/lib/Format/ContinuationIndenter.cpp
+++ b/clang/lib/Format/ContinuationIndenter.cpp
@@ -821,6 +821,7 @@ void ContinuationIndenter::addTokenOnCurrentLine(LineState 
, bool DryRun,
   if (Style.AlignAfterOpenBracket != FormatStyle::BAS_DontAlign &&
   !CurrentState.IsCSharpGenericTypeConstraint && Previous.opensScope() &&
   Previous.isNot(TT_ObjCMethodExpr) && Previous.isNot(TT_RequiresClause) &&
+  Previous.isNot(TT_TableGenDAGArgOpener) &&
   !(Current.MacroParent && Previous.MacroParent) &&
   (Current.isNot(TT_LineComment) ||
Previous.isOneOf(BK_BracedInit, TT_VerilogMultiLineListLParen))) {
@@ -1250,7 +1251,7 @@ unsigned ContinuationIndenter::getNewLineColumn(const 
LineState ) {
 return CurrentState.Indent;
   }
   if ((Current.isOneOf(tok::r_brace, tok::r_square) ||
-   (Current.is(tok::greater) && Style.isProto())) &&
+   (Current.is(tok::greater) && (Style.isProto() || Style.isTableGen( 
&&
   State.Stack.size() > 1) {
 if (Current.closesBlockOrBlockTypeList(Style))
   return State.Stack[State.Stack.size() - 2].NestedBlockIndent;
@@ -1278,6 +1279,12 @@ unsigned ContinuationIndenter::getNewLineColumn(const 
LineState ) {
Current.Next->isOneOf(tok::semi, tok::kw_const, tok::l_brace))) {
 return State.Stack[State.Stack.size() - 2].LastSpace;
   }
+  // When DAGArg closer exists top of line, it should be aligned in the similar
+  // way as function call above.
+  if (Style.isTableGen() && Current.is(TT_TableGenDAGArgCloser) &&
+  State.Stack.size() > 1) {
+return State.Stack[State.Stack.size() - 2].LastSpace;
+  }
   if (Style.AlignAfterOpenBracket == FormatStyle::BAS_BlockIndent &&
   (Current.is(tok::r_paren) ||
(Current.is(tok::r_brace) && Current.MatchingParen &&
@@ -1696,7 +1703,9 @@ void 
ContinuationIndenter::moveStatePastFakeLParens(LineState ,
 (!Previous || Previous->isNot(tok::kw_return) ||
  (Style.Language != FormatStyle::LK_Java && PrecedenceLevel > 0)) &&
 (Style.AlignAfterOpenBracket != FormatStyle::BAS_DontAlign ||
- PrecedenceLevel != prec::Comma || Current.NestingLevel == 0)) {
+ PrecedenceLevel != prec::Comma || Current.NestingLevel == 0) &&
+(!Style.isTableGen() ||
+ (Previous && Previous->is(TT_TableGenDAGArgListComma {
   NewParenState.Indent = std::max(
   std::max(State.Column, NewParenState.Indent), 
CurrentState.LastSpace);
 }
@@ -1942,6 +1951,7 @@ void 
ContinuationIndenter::moveStatePastScopeCloser(LineState ) {
   (Current.isOneOf(tok::r_paren, tok::r_square, TT_TemplateString) ||
(Current.is(tok::r_brace) && State.NextToken != State.Line->First) ||
State.NextToken->is(TT_TemplateCloser) ||
+   State.NextToken->is(TT_TableGenListCloser) ||
(Current.is(tok::greater) && Current.is(TT_DictLiteral {
 State.Stack.pop_back();
   }
diff --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index d353388a862b56..636d098881c97e 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -5072,7 +5072,38 @@ bool TokenAnnotator::spaceRequiredBefore(const 
AnnotatedLine ,
  Left.endsSequence(tok::greatergreater, tok::l_brace))) {
   return false;
 }
+  } else if (Style.isTableGen()) {
+// Avoid to connect [ and {. [{ is start token of multiline string.
+if (Left.is(tok::l_square) && Right.is(tok::l_brace))
+  return true;
+if (Left.is(tok::r_brace) && Right.is(tok::r_square))
+  return true;
+// Do not insert around colon in DAGArg and cond operator.
+if (Right.is(TT_TableGenDAGArgListColon) ||
+Left.is(TT_TableGenDAGArgListColon)) {
+  return false;
+}
+if (Right.is(TT_TableGenCondOperatorColon))
+  return false;
+// Do not insert bang operators and consequent openers.
+if (Right.isOneOf(tok::l_paren, tok::greater) &&
+Left.isOneOf(TT_TableGenBangOperator, TT_TableGenCondOperator)) {
+  return false;
+}
+// Trailing paste requires space before '{' or ':', the case in name 
values.
+// Not before ';', the case in normal values.
+if 

[clang] [clang-format] Support of TableGen basic format restrictions. (PR #81611)

2024-02-14 Thread Hirofumi Nakamura via cfe-commits

https://github.com/hnakamura5 updated 
https://github.com/llvm/llvm-project/pull/81611

>From 7ee4b35f0aed434053b6fd6329ef39de97bc22db Mon Sep 17 00:00:00 2001
From: hnakamura5 
Date: Tue, 13 Feb 2024 23:50:15 +0900
Subject: [PATCH 1/4] [clang-format] Support of TableGen basic format
 restrictions.

- Allow/force to break the line or not.
- Allow to insert space or not.
---
 clang/lib/Format/ContinuationIndenter.cpp |  14 +-
 clang/lib/Format/TokenAnnotator.cpp   |  56 
 clang/unittests/Format/FormatTestTableGen.cpp | 263 ++
 3 files changed, 331 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Format/ContinuationIndenter.cpp 
b/clang/lib/Format/ContinuationIndenter.cpp
index 0b2ef97af44d83..1879af94f6da49 100644
--- a/clang/lib/Format/ContinuationIndenter.cpp
+++ b/clang/lib/Format/ContinuationIndenter.cpp
@@ -821,6 +821,7 @@ void ContinuationIndenter::addTokenOnCurrentLine(LineState 
, bool DryRun,
   if (Style.AlignAfterOpenBracket != FormatStyle::BAS_DontAlign &&
   !CurrentState.IsCSharpGenericTypeConstraint && Previous.opensScope() &&
   Previous.isNot(TT_ObjCMethodExpr) && Previous.isNot(TT_RequiresClause) &&
+  Previous.isNot(TT_TableGenDAGArgOpener) &&
   !(Current.MacroParent && Previous.MacroParent) &&
   (Current.isNot(TT_LineComment) ||
Previous.isOneOf(BK_BracedInit, TT_VerilogMultiLineListLParen))) {
@@ -1250,7 +1251,7 @@ unsigned ContinuationIndenter::getNewLineColumn(const 
LineState ) {
 return CurrentState.Indent;
   }
   if ((Current.isOneOf(tok::r_brace, tok::r_square) ||
-   (Current.is(tok::greater) && Style.isProto())) &&
+   (Current.is(tok::greater) && (Style.isProto() || Style.isTableGen( 
&&
   State.Stack.size() > 1) {
 if (Current.closesBlockOrBlockTypeList(Style))
   return State.Stack[State.Stack.size() - 2].NestedBlockIndent;
@@ -1278,6 +1279,12 @@ unsigned ContinuationIndenter::getNewLineColumn(const 
LineState ) {
Current.Next->isOneOf(tok::semi, tok::kw_const, tok::l_brace))) {
 return State.Stack[State.Stack.size() - 2].LastSpace;
   }
+  // When DAGArg closer exists top of line, it should be aligned in the similar
+  // way as function call above.
+  if (Style.isTableGen() && Current.is(TT_TableGenDAGArgCloser) &&
+  State.Stack.size() > 1) {
+return State.Stack[State.Stack.size() - 2].LastSpace;
+  }
   if (Style.AlignAfterOpenBracket == FormatStyle::BAS_BlockIndent &&
   (Current.is(tok::r_paren) ||
(Current.is(tok::r_brace) && Current.MatchingParen &&
@@ -1696,7 +1703,9 @@ void 
ContinuationIndenter::moveStatePastFakeLParens(LineState ,
 (!Previous || Previous->isNot(tok::kw_return) ||
  (Style.Language != FormatStyle::LK_Java && PrecedenceLevel > 0)) &&
 (Style.AlignAfterOpenBracket != FormatStyle::BAS_DontAlign ||
- PrecedenceLevel != prec::Comma || Current.NestingLevel == 0)) {
+ PrecedenceLevel != prec::Comma || Current.NestingLevel == 0) &&
+(!Style.isTableGen() ||
+ (Previous && Previous->is(TT_TableGenDAGArgListComma {
   NewParenState.Indent = std::max(
   std::max(State.Column, NewParenState.Indent), 
CurrentState.LastSpace);
 }
@@ -1942,6 +1951,7 @@ void 
ContinuationIndenter::moveStatePastScopeCloser(LineState ) {
   (Current.isOneOf(tok::r_paren, tok::r_square, TT_TemplateString) ||
(Current.is(tok::r_brace) && State.NextToken != State.Line->First) ||
State.NextToken->is(TT_TemplateCloser) ||
+   State.NextToken->is(TT_TableGenListCloser) ||
(Current.is(tok::greater) && Current.is(TT_DictLiteral {
 State.Stack.pop_back();
   }
diff --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index d353388a862b56..636d098881c97e 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -5072,7 +5072,38 @@ bool TokenAnnotator::spaceRequiredBefore(const 
AnnotatedLine ,
  Left.endsSequence(tok::greatergreater, tok::l_brace))) {
   return false;
 }
+  } else if (Style.isTableGen()) {
+// Avoid to connect [ and {. [{ is start token of multiline string.
+if (Left.is(tok::l_square) && Right.is(tok::l_brace))
+  return true;
+if (Left.is(tok::r_brace) && Right.is(tok::r_square))
+  return true;
+// Do not insert around colon in DAGArg and cond operator.
+if (Right.is(TT_TableGenDAGArgListColon) ||
+Left.is(TT_TableGenDAGArgListColon)) {
+  return false;
+}
+if (Right.is(TT_TableGenCondOperatorColon))
+  return false;
+// Do not insert bang operators and consequent openers.
+if (Right.isOneOf(tok::l_paren, tok::greater) &&
+Left.isOneOf(TT_TableGenBangOperator, TT_TableGenCondOperator)) {
+  return false;
+}
+// Trailing paste requires space before '{' or ':', the case in name 
values.
+// Not before ';', the case in normal values.
+if 

[clang] [clang-format] Support of TableGen basic format restrictions. (PR #81611)

2024-02-13 Thread Hirofumi Nakamura via cfe-commits

https://github.com/hnakamura5 edited 
https://github.com/llvm/llvm-project/pull/81611
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format] Support of TableGen basic format restrictions. (PR #81611)

2024-02-13 Thread Hirofumi Nakamura via cfe-commits

https://github.com/hnakamura5 updated 
https://github.com/llvm/llvm-project/pull/81611

>From 7ee4b35f0aed434053b6fd6329ef39de97bc22db Mon Sep 17 00:00:00 2001
From: hnakamura5 
Date: Tue, 13 Feb 2024 23:50:15 +0900
Subject: [PATCH 1/3] [clang-format] Support of TableGen basic format
 restrictions.

- Allow/force to break the line or not.
- Allow to insert space or not.
---
 clang/lib/Format/ContinuationIndenter.cpp |  14 +-
 clang/lib/Format/TokenAnnotator.cpp   |  56 
 clang/unittests/Format/FormatTestTableGen.cpp | 263 ++
 3 files changed, 331 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Format/ContinuationIndenter.cpp 
b/clang/lib/Format/ContinuationIndenter.cpp
index 0b2ef97af44d83..1879af94f6da49 100644
--- a/clang/lib/Format/ContinuationIndenter.cpp
+++ b/clang/lib/Format/ContinuationIndenter.cpp
@@ -821,6 +821,7 @@ void ContinuationIndenter::addTokenOnCurrentLine(LineState 
, bool DryRun,
   if (Style.AlignAfterOpenBracket != FormatStyle::BAS_DontAlign &&
   !CurrentState.IsCSharpGenericTypeConstraint && Previous.opensScope() &&
   Previous.isNot(TT_ObjCMethodExpr) && Previous.isNot(TT_RequiresClause) &&
+  Previous.isNot(TT_TableGenDAGArgOpener) &&
   !(Current.MacroParent && Previous.MacroParent) &&
   (Current.isNot(TT_LineComment) ||
Previous.isOneOf(BK_BracedInit, TT_VerilogMultiLineListLParen))) {
@@ -1250,7 +1251,7 @@ unsigned ContinuationIndenter::getNewLineColumn(const 
LineState ) {
 return CurrentState.Indent;
   }
   if ((Current.isOneOf(tok::r_brace, tok::r_square) ||
-   (Current.is(tok::greater) && Style.isProto())) &&
+   (Current.is(tok::greater) && (Style.isProto() || Style.isTableGen( 
&&
   State.Stack.size() > 1) {
 if (Current.closesBlockOrBlockTypeList(Style))
   return State.Stack[State.Stack.size() - 2].NestedBlockIndent;
@@ -1278,6 +1279,12 @@ unsigned ContinuationIndenter::getNewLineColumn(const 
LineState ) {
Current.Next->isOneOf(tok::semi, tok::kw_const, tok::l_brace))) {
 return State.Stack[State.Stack.size() - 2].LastSpace;
   }
+  // When DAGArg closer exists top of line, it should be aligned in the similar
+  // way as function call above.
+  if (Style.isTableGen() && Current.is(TT_TableGenDAGArgCloser) &&
+  State.Stack.size() > 1) {
+return State.Stack[State.Stack.size() - 2].LastSpace;
+  }
   if (Style.AlignAfterOpenBracket == FormatStyle::BAS_BlockIndent &&
   (Current.is(tok::r_paren) ||
(Current.is(tok::r_brace) && Current.MatchingParen &&
@@ -1696,7 +1703,9 @@ void 
ContinuationIndenter::moveStatePastFakeLParens(LineState ,
 (!Previous || Previous->isNot(tok::kw_return) ||
  (Style.Language != FormatStyle::LK_Java && PrecedenceLevel > 0)) &&
 (Style.AlignAfterOpenBracket != FormatStyle::BAS_DontAlign ||
- PrecedenceLevel != prec::Comma || Current.NestingLevel == 0)) {
+ PrecedenceLevel != prec::Comma || Current.NestingLevel == 0) &&
+(!Style.isTableGen() ||
+ (Previous && Previous->is(TT_TableGenDAGArgListComma {
   NewParenState.Indent = std::max(
   std::max(State.Column, NewParenState.Indent), 
CurrentState.LastSpace);
 }
@@ -1942,6 +1951,7 @@ void 
ContinuationIndenter::moveStatePastScopeCloser(LineState ) {
   (Current.isOneOf(tok::r_paren, tok::r_square, TT_TemplateString) ||
(Current.is(tok::r_brace) && State.NextToken != State.Line->First) ||
State.NextToken->is(TT_TemplateCloser) ||
+   State.NextToken->is(TT_TableGenListCloser) ||
(Current.is(tok::greater) && Current.is(TT_DictLiteral {
 State.Stack.pop_back();
   }
diff --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index d353388a862b56..636d098881c97e 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -5072,7 +5072,38 @@ bool TokenAnnotator::spaceRequiredBefore(const 
AnnotatedLine ,
  Left.endsSequence(tok::greatergreater, tok::l_brace))) {
   return false;
 }
+  } else if (Style.isTableGen()) {
+// Avoid to connect [ and {. [{ is start token of multiline string.
+if (Left.is(tok::l_square) && Right.is(tok::l_brace))
+  return true;
+if (Left.is(tok::r_brace) && Right.is(tok::r_square))
+  return true;
+// Do not insert around colon in DAGArg and cond operator.
+if (Right.is(TT_TableGenDAGArgListColon) ||
+Left.is(TT_TableGenDAGArgListColon)) {
+  return false;
+}
+if (Right.is(TT_TableGenCondOperatorColon))
+  return false;
+// Do not insert bang operators and consequent openers.
+if (Right.isOneOf(tok::l_paren, tok::greater) &&
+Left.isOneOf(TT_TableGenBangOperator, TT_TableGenCondOperator)) {
+  return false;
+}
+// Trailing paste requires space before '{' or ':', the case in name 
values.
+// Not before ';', the case in normal values.
+if 

[clang] [clang-format] Support of TableGen basic format restrictions. (PR #81611)

2024-02-13 Thread Hirofumi Nakamura via cfe-commits

https://github.com/hnakamura5 edited 
https://github.com/llvm/llvm-project/pull/81611
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format] Support of TableGen basic format restrictions. (PR #81611)

2024-02-13 Thread Hirofumi Nakamura via cfe-commits


@@ -5072,7 +5072,38 @@ bool TokenAnnotator::spaceRequiredBefore(const 
AnnotatedLine ,
  Left.endsSequence(tok::greatergreater, tok::l_brace))) {
   return false;
 }
+  } else if (Style.isTableGen()) {
+// Avoid to connect [ and {. [{ is start token of multiline string.
+if (Left.is(tok::l_square) && Right.is(tok::l_brace))
+  return true;
+if (Left.is(tok::r_brace) && Right.is(tok::r_square))
+  return true;
+// Do not insert around colon in DAGArg and cond operator.
+if (Right.is(TT_TableGenDAGArgListColon) ||
+Left.is(TT_TableGenDAGArgListColon)) {
+  return false;
+}
+if (Right.is(TT_TableGenCondOperatorColon))
+  return false;
+// Do not insert bang operators and consequent openers.
+if (Right.isOneOf(tok::l_paren, tok::less) &&
+Left.isOneOf(TT_TableGenBangOperator, TT_TableGenCondOperator)) {
+  return false;
+}
+// Trailing paste requires space before '{' or ':', the case in name 
values.
+// Not before ';', the case in normal values.
+if (Left.is(TT_TableGenTrailingPasteOperator) &&
+Right.isOneOf(tok::l_brace, tok::colon)) {
+  return true;
+}
+// Otherwise paste operator does not prefer space around.
+if (Left.is(tok::hash) || Right.is(tok::hash))
+  return false;
+// Sure not to connect after defining keywords.
+if (Keywords.isTableGenDefinition(Left))
+  return true;

hnakamura5 wrote:

Returning true forces to insert space between Left and Right tokens.

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


[clang] [clang-format] Support of TableGen basic format restrictions. (PR #81611)

2024-02-13 Thread Hirofumi Nakamura via cfe-commits


@@ -5822,6 +5860,24 @@ bool TokenAnnotator::canBreakBefore(const AnnotatedLine 
,
   return false;
 if (Left.is(TT_TemplateString) && Left.opensScope())
   return true;
+  } else if (Style.isTableGen()) {
+// Avoid to break after "def", "class", "let" and so on.
+if (Keywords.isTableGenDefinition(Left))
+  return false;
+// Avoid to break after '(' in the cases that is in bang operators.
+if (Right.is(tok::l_paren)) {
+  return !Left.isOneOf(TT_TableGenBangOperator, TT_TableGenCondOperator,
+   TT_TemplateCloser);
+}
+// Avoid to split the value and its suffix part.
+if (Left.is(TT_TableGenValueSuffix))
+  return false;
+// Avoid to break between the value and its suffix part.
+if (Left.is(TT_TableGenValueSuffix))
+  return false;
+// Avoid to break around paste operator.
+if (Left.is(tok::hash) || Right.is(tok::hash))
+  return false;

hnakamura5 wrote:

Returning false does not allow to insert line break before Right token.

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


[clang] [clang-format] Support of TableGen basic format restrictions. (PR #81611)

2024-02-13 Thread Hirofumi Nakamura via cfe-commits


@@ -55,5 +55,268 @@ TEST_F(FormatTestTableGen, NoSpacesInSquareBracketLists) {
   verifyFormat("def flag : Flag<[\"-\", \"--\"], \"foo\">;");
 }
 
+TEST_F(FormatTestTableGen, LiteralsAndIdentifiers) {
+  verifyFormat("def LiteralAndIdentifiers {\n"
+   "  let someInteger = -42;\n"
+   "  let 0startID = $TokVarName;\n"
+   "  let 0xstartInteger = 0x42;\n"
+   "  let someIdentifier = $TokVarName;\n"
+   "}\n");
+}
+
+TEST_F(FormatTestTableGen, BangOperators) {
+  verifyFormat("def BangOperators {\n"
+   "  let IfOpe = !if(\n"
+   "  !not(!and(!gt(!add(1, 2), !sub(3, 4)), !isa($x))),\n"
+   "  !foldl(0, !listconcat(!range(5, 6), !range(7, 8)),\n"
+   " total, rec, !add(total, rec.Number)),\n"
+   "  !tail(!range(9, 10)));\n"
+   "  let ForeachOpe = !foreach(\n"
+   "  arg, arglist,\n"
+   "  !if(!isa(arg.Type),\n"
+   "  !add(!cast(arg).Number, x), arg));\n"
+   "  let CondOpe1 = !cond(!eq(size, 1): 1,\n"
+   "   !eq(size, 2): 1,\n"
+   "   !eq(size, 4): 1,\n"
+   "   !eq(size, 8): 1,\n"
+   "   !eq(size, 16): 1,\n"
+   "   true: 0);\n"
+   "  let CondOpe2 = !cond(!lt(x, 0): \"negativenegative\",\n"
+   "   !eq(x, 0): \"zerozero\",\n"
+   "   true: \"positivepositive\");\n"
+   "  let CondOpe2WithComment = !cond(!lt(x, 0):  // negative\n"
+   "  \"negativenegative\",\n"
+   "  !eq(x, 0):  // zero\n"
+   "  \"zerozero\",\n"
+   "  true:  // default\n"
+   "  \"positivepositive\");\n"
+   "}\n");
+}
+
+TEST_F(FormatTestTableGen, Include) {
+  verifyFormat("include \"test/IncludeFile.h\"\n");
+}
+
+TEST_F(FormatTestTableGen, Types) {
+  verifyFormat("def Types : list, bits<3>, list> {}\n");
+}
+
+TEST_F(FormatTestTableGen, SimpleValue1_SingleLiterals) {
+  verifyFormat("def SimpleValue {\n"
+   "  let Integer = 42;\n"
+   "  let String = \"some string\";\n"
+   "}\n");
+}
+
+TEST_F(FormatTestTableGen, SimpleValue1_MultilineString) {
+  // verifyFormat does not understand multiline TableGen code-literals
+  std::string DefWithCode =
+  "def SimpleValueCode {\n"
+  "  let Code =\n"
+  "  [{ A TokCode is  nothing more than a multi-line string literal "
+  "delimited by \\[{ and }\\]. It  can break across lines and the line "
+  "breaks are retained in the string. "
+  
"(https://llvm.org/docs/TableGen/ProgRef.html#grammar-token-TokCode)}];\n"
+  "}\n";
+  std::string DefWithCodeMessingUp =
+  "def SimpleValueCode {\n"
+  "  let   Code=   "
+  "[{ A TokCode is  nothing more than a multi-line string literal "
+  "delimited by \\[{ and }\\]. It  can break across lines and the line "
+  "breaks are retained in the string. "
+  
"(https://llvm.org/docs/TableGen/ProgRef.html#grammar-token-TokCode)}];\n"
+  "   }\n";
+  EXPECT_EQ(DefWithCode, format(DefWithCodeMessingUp));
+}
+
+TEST_F(FormatTestTableGen, SimpleValue2) {
+  verifyFormat("def SimpleValue2 {\n"
+   "  let True = true;\n"
+   "  let False = false;\n"
+   "}\n");
+}
+
+TEST_F(FormatTestTableGen, SimpleValue3) {
+  verifyFormat("class SimpleValue3 { int Question = ?; }\n");
+}
+
+TEST_F(FormatTestTableGen, SimpleValue4) {
+  verifyFormat("def SimpleValue4 { let ValueList = {1, 2, 3}; }\n");
+}
+
+TEST_F(FormatTestTableGen, SimpleValue5) {
+  verifyFormat("def SimpleValue5 {\n"
+   "  let SquareList = [1, 4, 9];\n"
+   "  let SquareListWithType = [\"a\", \"b\", \"c\"];\n"
+   "  let SquareListListWithType = [[1, 2], [3, 4, 5], [7]]<\n"
+   "  list>;\n"
+   "  let SquareBitsListWithType = [ {1, 2},\n"
+   " {3, 4} ]>>;\n"
+   "}\n");

hnakamura5 wrote:

SquareListListWithType and SquareBitsListWithType seems a little bit strange 
for they are similar but the format is difference.
One reason is  '[' and '{' cannot be connected because '[{' is the beginning of 
multiline string.

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


[clang] [clang-format] Support of TableGen basic format restrictions. (PR #81611)

2024-02-13 Thread Hirofumi Nakamura via cfe-commits

https://github.com/hnakamura5 edited 
https://github.com/llvm/llvm-project/pull/81611
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format] Support of TableGen basic format restrictions. (PR #81611)

2024-02-13 Thread Hirofumi Nakamura via cfe-commits

https://github.com/hnakamura5 updated 
https://github.com/llvm/llvm-project/pull/81611

>From 7ee4b35f0aed434053b6fd6329ef39de97bc22db Mon Sep 17 00:00:00 2001
From: hnakamura5 
Date: Tue, 13 Feb 2024 23:50:15 +0900
Subject: [PATCH 1/2] [clang-format] Support of TableGen basic format
 restrictions.

- Allow/force to break the line or not.
- Allow to insert space or not.
---
 clang/lib/Format/ContinuationIndenter.cpp |  14 +-
 clang/lib/Format/TokenAnnotator.cpp   |  56 
 clang/unittests/Format/FormatTestTableGen.cpp | 263 ++
 3 files changed, 331 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Format/ContinuationIndenter.cpp 
b/clang/lib/Format/ContinuationIndenter.cpp
index 0b2ef97af44d83..1879af94f6da49 100644
--- a/clang/lib/Format/ContinuationIndenter.cpp
+++ b/clang/lib/Format/ContinuationIndenter.cpp
@@ -821,6 +821,7 @@ void ContinuationIndenter::addTokenOnCurrentLine(LineState 
, bool DryRun,
   if (Style.AlignAfterOpenBracket != FormatStyle::BAS_DontAlign &&
   !CurrentState.IsCSharpGenericTypeConstraint && Previous.opensScope() &&
   Previous.isNot(TT_ObjCMethodExpr) && Previous.isNot(TT_RequiresClause) &&
+  Previous.isNot(TT_TableGenDAGArgOpener) &&
   !(Current.MacroParent && Previous.MacroParent) &&
   (Current.isNot(TT_LineComment) ||
Previous.isOneOf(BK_BracedInit, TT_VerilogMultiLineListLParen))) {
@@ -1250,7 +1251,7 @@ unsigned ContinuationIndenter::getNewLineColumn(const 
LineState ) {
 return CurrentState.Indent;
   }
   if ((Current.isOneOf(tok::r_brace, tok::r_square) ||
-   (Current.is(tok::greater) && Style.isProto())) &&
+   (Current.is(tok::greater) && (Style.isProto() || Style.isTableGen( 
&&
   State.Stack.size() > 1) {
 if (Current.closesBlockOrBlockTypeList(Style))
   return State.Stack[State.Stack.size() - 2].NestedBlockIndent;
@@ -1278,6 +1279,12 @@ unsigned ContinuationIndenter::getNewLineColumn(const 
LineState ) {
Current.Next->isOneOf(tok::semi, tok::kw_const, tok::l_brace))) {
 return State.Stack[State.Stack.size() - 2].LastSpace;
   }
+  // When DAGArg closer exists top of line, it should be aligned in the similar
+  // way as function call above.
+  if (Style.isTableGen() && Current.is(TT_TableGenDAGArgCloser) &&
+  State.Stack.size() > 1) {
+return State.Stack[State.Stack.size() - 2].LastSpace;
+  }
   if (Style.AlignAfterOpenBracket == FormatStyle::BAS_BlockIndent &&
   (Current.is(tok::r_paren) ||
(Current.is(tok::r_brace) && Current.MatchingParen &&
@@ -1696,7 +1703,9 @@ void 
ContinuationIndenter::moveStatePastFakeLParens(LineState ,
 (!Previous || Previous->isNot(tok::kw_return) ||
  (Style.Language != FormatStyle::LK_Java && PrecedenceLevel > 0)) &&
 (Style.AlignAfterOpenBracket != FormatStyle::BAS_DontAlign ||
- PrecedenceLevel != prec::Comma || Current.NestingLevel == 0)) {
+ PrecedenceLevel != prec::Comma || Current.NestingLevel == 0) &&
+(!Style.isTableGen() ||
+ (Previous && Previous->is(TT_TableGenDAGArgListComma {
   NewParenState.Indent = std::max(
   std::max(State.Column, NewParenState.Indent), 
CurrentState.LastSpace);
 }
@@ -1942,6 +1951,7 @@ void 
ContinuationIndenter::moveStatePastScopeCloser(LineState ) {
   (Current.isOneOf(tok::r_paren, tok::r_square, TT_TemplateString) ||
(Current.is(tok::r_brace) && State.NextToken != State.Line->First) ||
State.NextToken->is(TT_TemplateCloser) ||
+   State.NextToken->is(TT_TableGenListCloser) ||
(Current.is(tok::greater) && Current.is(TT_DictLiteral {
 State.Stack.pop_back();
   }
diff --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index d353388a862b56..636d098881c97e 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -5072,7 +5072,38 @@ bool TokenAnnotator::spaceRequiredBefore(const 
AnnotatedLine ,
  Left.endsSequence(tok::greatergreater, tok::l_brace))) {
   return false;
 }
+  } else if (Style.isTableGen()) {
+// Avoid to connect [ and {. [{ is start token of multiline string.
+if (Left.is(tok::l_square) && Right.is(tok::l_brace))
+  return true;
+if (Left.is(tok::r_brace) && Right.is(tok::r_square))
+  return true;
+// Do not insert around colon in DAGArg and cond operator.
+if (Right.is(TT_TableGenDAGArgListColon) ||
+Left.is(TT_TableGenDAGArgListColon)) {
+  return false;
+}
+if (Right.is(TT_TableGenCondOperatorColon))
+  return false;
+// Do not insert bang operators and consequent openers.
+if (Right.isOneOf(tok::l_paren, tok::greater) &&
+Left.isOneOf(TT_TableGenBangOperator, TT_TableGenCondOperator)) {
+  return false;
+}
+// Trailing paste requires space before '{' or ':', the case in name 
values.
+// Not before ';', the case in normal values.
+if 

[clang] [clang-format] Support of TableGen basic format restrictions. (PR #81611)

2024-02-13 Thread Hirofumi Nakamura via cfe-commits

https://github.com/hnakamura5 created 
https://github.com/llvm/llvm-project/pull/81611

- Allow/force to break the line or not.
- Allow to insert space or not.

This is separated part from https://github.com/llvm/llvm-project/pull/76059.
Now we come to format in basic style !

>From 7ee4b35f0aed434053b6fd6329ef39de97bc22db Mon Sep 17 00:00:00 2001
From: hnakamura5 
Date: Tue, 13 Feb 2024 23:50:15 +0900
Subject: [PATCH] [clang-format] Support of TableGen basic format restrictions.

- Allow/force to break the line or not.
- Allow to insert space or not.
---
 clang/lib/Format/ContinuationIndenter.cpp |  14 +-
 clang/lib/Format/TokenAnnotator.cpp   |  56 
 clang/unittests/Format/FormatTestTableGen.cpp | 263 ++
 3 files changed, 331 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Format/ContinuationIndenter.cpp 
b/clang/lib/Format/ContinuationIndenter.cpp
index 0b2ef97af44d83..1879af94f6da49 100644
--- a/clang/lib/Format/ContinuationIndenter.cpp
+++ b/clang/lib/Format/ContinuationIndenter.cpp
@@ -821,6 +821,7 @@ void ContinuationIndenter::addTokenOnCurrentLine(LineState 
, bool DryRun,
   if (Style.AlignAfterOpenBracket != FormatStyle::BAS_DontAlign &&
   !CurrentState.IsCSharpGenericTypeConstraint && Previous.opensScope() &&
   Previous.isNot(TT_ObjCMethodExpr) && Previous.isNot(TT_RequiresClause) &&
+  Previous.isNot(TT_TableGenDAGArgOpener) &&
   !(Current.MacroParent && Previous.MacroParent) &&
   (Current.isNot(TT_LineComment) ||
Previous.isOneOf(BK_BracedInit, TT_VerilogMultiLineListLParen))) {
@@ -1250,7 +1251,7 @@ unsigned ContinuationIndenter::getNewLineColumn(const 
LineState ) {
 return CurrentState.Indent;
   }
   if ((Current.isOneOf(tok::r_brace, tok::r_square) ||
-   (Current.is(tok::greater) && Style.isProto())) &&
+   (Current.is(tok::greater) && (Style.isProto() || Style.isTableGen( 
&&
   State.Stack.size() > 1) {
 if (Current.closesBlockOrBlockTypeList(Style))
   return State.Stack[State.Stack.size() - 2].NestedBlockIndent;
@@ -1278,6 +1279,12 @@ unsigned ContinuationIndenter::getNewLineColumn(const 
LineState ) {
Current.Next->isOneOf(tok::semi, tok::kw_const, tok::l_brace))) {
 return State.Stack[State.Stack.size() - 2].LastSpace;
   }
+  // When DAGArg closer exists top of line, it should be aligned in the similar
+  // way as function call above.
+  if (Style.isTableGen() && Current.is(TT_TableGenDAGArgCloser) &&
+  State.Stack.size() > 1) {
+return State.Stack[State.Stack.size() - 2].LastSpace;
+  }
   if (Style.AlignAfterOpenBracket == FormatStyle::BAS_BlockIndent &&
   (Current.is(tok::r_paren) ||
(Current.is(tok::r_brace) && Current.MatchingParen &&
@@ -1696,7 +1703,9 @@ void 
ContinuationIndenter::moveStatePastFakeLParens(LineState ,
 (!Previous || Previous->isNot(tok::kw_return) ||
  (Style.Language != FormatStyle::LK_Java && PrecedenceLevel > 0)) &&
 (Style.AlignAfterOpenBracket != FormatStyle::BAS_DontAlign ||
- PrecedenceLevel != prec::Comma || Current.NestingLevel == 0)) {
+ PrecedenceLevel != prec::Comma || Current.NestingLevel == 0) &&
+(!Style.isTableGen() ||
+ (Previous && Previous->is(TT_TableGenDAGArgListComma {
   NewParenState.Indent = std::max(
   std::max(State.Column, NewParenState.Indent), 
CurrentState.LastSpace);
 }
@@ -1942,6 +1951,7 @@ void 
ContinuationIndenter::moveStatePastScopeCloser(LineState ) {
   (Current.isOneOf(tok::r_paren, tok::r_square, TT_TemplateString) ||
(Current.is(tok::r_brace) && State.NextToken != State.Line->First) ||
State.NextToken->is(TT_TemplateCloser) ||
+   State.NextToken->is(TT_TableGenListCloser) ||
(Current.is(tok::greater) && Current.is(TT_DictLiteral {
 State.Stack.pop_back();
   }
diff --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index d353388a862b56..636d098881c97e 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -5072,7 +5072,38 @@ bool TokenAnnotator::spaceRequiredBefore(const 
AnnotatedLine ,
  Left.endsSequence(tok::greatergreater, tok::l_brace))) {
   return false;
 }
+  } else if (Style.isTableGen()) {
+// Avoid to connect [ and {. [{ is start token of multiline string.
+if (Left.is(tok::l_square) && Right.is(tok::l_brace))
+  return true;
+if (Left.is(tok::r_brace) && Right.is(tok::r_square))
+  return true;
+// Do not insert around colon in DAGArg and cond operator.
+if (Right.is(TT_TableGenDAGArgListColon) ||
+Left.is(TT_TableGenDAGArgListColon)) {
+  return false;
+}
+if (Right.is(TT_TableGenCondOperatorColon))
+  return false;
+// Do not insert bang operators and consequent openers.
+if (Right.isOneOf(tok::l_paren, tok::greater) &&
+Left.isOneOf(TT_TableGenBangOperator, TT_TableGenCondOperator)) {
+  return 

[clang] [clang-format] Support of TableGen value annotations. (PR #80299)

2024-02-12 Thread Hirofumi Nakamura via cfe-commits

hnakamura5 wrote:

Thank you very much!
Currently I think this will be the largest part. I try to make so. Thank you 
again for this, and of course for the other parts.

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


[clang] [clang-format] Support of TableGen value annotations. (PR #80299)

2024-02-12 Thread Hirofumi Nakamura via cfe-commits

https://github.com/hnakamura5 closed 
https://github.com/llvm/llvm-project/pull/80299
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format] Support of TableGen value annotations. (PR #80299)

2024-02-10 Thread Hirofumi Nakamura via cfe-commits


@@ -833,13 +885,207 @@ class AnnotatingParser {
 Left->setType(TT_ArrayInitializerLSquare);
   }
   FormatToken *Tok = CurrentToken;
+  if (Style.isTableGen()) {
+if (CurrentToken->isOneOf(tok::comma, tok::minus, tok::ellipsis)) {
+  // '-' and '...' appears as a separator in slice.
+  next();
+} else {
+  // In TableGen there must be a list of Values in square brackets.
+  // It must be ValueList or SliceElements.
+  if (!parseTableGenValue())
+return false;
+}
+updateParameterCount(Left, Tok);
+continue;
+  }
   if (!consumeToken())
 return false;
   updateParameterCount(Left, Tok);
 }
 return false;
   }
 
+  void nextTableGenNonComment() {
+next();
+while (CurrentToken && CurrentToken->is(tok::comment))
+  next();
+  }
+
+  bool parseTableGenValue(bool ParseNameMode = false) {

hnakamura5 wrote:

I added some more comments, here and on tryToParseTableGenTokVar.
Actually the behavior of return value is same as other parse functions here 
such as parseAngle, parseBrace.
That is, returning false results in the total failure of parseLine itself. They 
do not backtrack on fail.

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


[clang] [clang-format] Support of TableGen value annotations. (PR #80299)

2024-02-10 Thread Hirofumi Nakamura via cfe-commits

https://github.com/hnakamura5 updated 
https://github.com/llvm/llvm-project/pull/80299

>From 36f83a124ea8ad27cfefa1d12ae5aa781f8e6e3e Mon Sep 17 00:00:00 2001
From: hnakamura5 
Date: Thu, 1 Feb 2024 23:07:42 +0900
Subject: [PATCH 1/3] [clang-format] Support of TableGen value annotations.

---
 clang/lib/Format/FormatToken.h|  10 +
 clang/lib/Format/FormatTokenLexer.cpp |   2 +-
 clang/lib/Format/TokenAnnotator.cpp   | 303 +-
 clang/lib/Format/UnwrappedLineParser.cpp  |  13 +-
 clang/unittests/Format/TokenAnnotatorTest.cpp |  45 +++
 5 files changed, 364 insertions(+), 9 deletions(-)

diff --git a/clang/lib/Format/FormatToken.h b/clang/lib/Format/FormatToken.h
index bace91b5f99b4d..0c1dce7a294082 100644
--- a/clang/lib/Format/FormatToken.h
+++ b/clang/lib/Format/FormatToken.h
@@ -150,7 +150,17 @@ namespace format {
   TYPE(StructuredBindingLSquare)   
\
   TYPE(TableGenBangOperator)   
\
   TYPE(TableGenCondOperator)   
\
+  TYPE(TableGenCondOperatorColon)  
\
+  TYPE(TableGenCondOperatorComma)  
\
+  TYPE(TableGenDAGArgCloser)   
\
+  TYPE(TableGenDAGArgListColon)
\
+  TYPE(TableGenDAGArgListComma)
\
+  TYPE(TableGenDAGArgOpener)   
\
+  TYPE(TableGenListCloser) 
\
+  TYPE(TableGenListOpener) 
\
   TYPE(TableGenMultiLineString)
\
+  TYPE(TableGenTrailingPasteOperator)  
\
+  TYPE(TableGenValueSuffix)
\
   TYPE(TemplateCloser) 
\
   TYPE(TemplateOpener) 
\
   TYPE(TemplateString) 
\
diff --git a/clang/lib/Format/FormatTokenLexer.cpp 
b/clang/lib/Format/FormatTokenLexer.cpp
index d7de09ef0e12ab..27b2b1b619b1d3 100644
--- a/clang/lib/Format/FormatTokenLexer.cpp
+++ b/clang/lib/Format/FormatTokenLexer.cpp
@@ -816,7 +816,7 @@ void FormatTokenLexer::handleTableGenMultilineString() {
   auto CloseOffset = Lex->getBuffer().find("}]", OpenOffset);
   if (CloseOffset == StringRef::npos)
 return;
-  auto Text = Lex->getBuffer().substr(OpenOffset, CloseOffset + 2);
+  auto Text = Lex->getBuffer().substr(OpenOffset, CloseOffset - OpenOffset + 
2);
   MultiLineString->TokenText = Text;
   resetLexer(SourceMgr.getFileOffset(
   Lex->getSourceLocation(Lex->getBufferLocation() - 2 + Text.size(;
diff --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index df1c5bc19de1e8..afcf5f638ce4c8 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -256,6 +256,18 @@ class AnnotatingParser {
   }
 }
   }
+  if (Style.isTableGen()) {
+if (CurrentToken->isOneOf(tok::comma, tok::equal)) {
+  // They appears as a separator. Unless it is not in class definition.
+  next();
+  continue;
+}
+// In angle, there must be Value like tokens. Types are also able to be
+// parsed in the same way with Values.
+if (!parseTableGenValue())
+  return false;
+continue;
+  }
   if (!consumeToken())
 return false;
 }
@@ -388,6 +400,28 @@ class AnnotatingParser {
   Contexts.back().IsExpression = !IsForOrCatch;
 }
 
+if (Style.isTableGen()) {
+  if (FormatToken *Prev = OpeningParen.Previous) {
+if (Prev->is(TT_TableGenCondOperator)) {
+  Contexts.back().IsTableGenCondOpe = true;
+  Contexts.back().IsExpression = true;
+} else if (Contexts.size() > 1 &&
+   Contexts[Contexts.size() - 2].IsTableGenBangOpe) {
+  // Hack to handle bang operators. The parent context's flag
+  // was set by parseTableGenSimpleValue().
+  // We have to specify the context outside because the prev of "(" may
+  // be ">", not the bang operator in this case.
+  Contexts.back().IsTableGenBangOpe = true;
+  Contexts.back().IsExpression = true;
+} else {
+  // Otherwise, this paren seems DAGArg.
+  if (!parseTableGenDAGArg())
+return false;
+  return parseTableGenDAGArgAndList();
+}
+  }
+}
+
 // Infer the role of the l_paren based on the previous token if we haven't
 // detected one yet.
 if (PrevNonComment && 

[clang] [clang-format] Support of TableGen value annotations. (PR #80299)

2024-02-06 Thread Hirofumi Nakamura via cfe-commits


@@ -833,13 +885,207 @@ class AnnotatingParser {
 Left->setType(TT_ArrayInitializerLSquare);
   }
   FormatToken *Tok = CurrentToken;
+  if (Style.isTableGen()) {
+if (CurrentToken->isOneOf(tok::comma, tok::minus, tok::ellipsis)) {
+  // '-' and '...' appears as a separator in slice.
+  next();
+} else {
+  // In TableGen there must be a list of Values in square brackets.
+  // It must be ValueList or SliceElements.
+  if (!parseTableGenValue())
+return false;
+}
+updateParameterCount(Left, Tok);
+continue;
+  }
   if (!consumeToken())
 return false;
   updateParameterCount(Left, Tok);
 }
 return false;
   }
 
+  void nextTableGenNonComment() {
+next();
+while (CurrentToken && CurrentToken->is(tok::comment))
+  next();
+  }
+
+  bool parseTableGenValue(bool ParseNameMode = false) {
+if (!CurrentToken)
+  return false;
+while (CurrentToken->is(tok::comment))
+  next();
+if (!parseTableGenSimpleValue())
+  return false;
+if (!CurrentToken)
+  return true;
+// Value "#" [Value]
+if (CurrentToken->is(tok::hash)) {
+  if (CurrentToken->Next &&
+  CurrentToken->Next->isOneOf(tok::colon, tok::semi, tok::l_brace)) {
+// Trailing paste operator.
+// These are only the allowed cases in TGParser::ParseValue().
+CurrentToken->setType(TT_TableGenTrailingPasteOperator);
+next();
+return true;
+  }
+  FormatToken *HashTok = CurrentToken;
+  nextTableGenNonComment();
+  HashTok->setType(TT_Unknown);
+  if (!parseTableGenValue(ParseNameMode))
+return false;
+}
+// In name mode, '{' is regarded as the end of the value.
+// See TGParser::ParseValue in TGParser.cpp
+if (ParseNameMode && CurrentToken->is(tok::l_brace))
+  return true;
+if (CurrentToken->isOneOf(tok::l_brace, tok::l_square, tok::period)) {
+  // Delegate ValueSuffix to normal consumeToken
+  CurrentToken->setType(TT_TableGenValueSuffix);
+  FormatToken *Suffix = CurrentToken;
+  nextTableGenNonComment();
+  if (Suffix->is(tok::l_square)) {
+return parseSquare();
+  } else if (Suffix->is(tok::l_brace)) {
+Scopes.push_back(getScopeType(*Suffix));
+return parseBrace();
+  }
+  return true;

hnakamura5 wrote:

Removed this.

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


[clang] [clang-format] Support of TableGen value annotations. (PR #80299)

2024-02-06 Thread Hirofumi Nakamura via cfe-commits


@@ -1423,11 +1692,30 @@ class AnnotatingParser {
 if (!Tok->getPreviousNonComment())
   Line.IsContinuation = true;
   }
+  if (Style.isTableGen()) {
+if (Tok->is(Keywords.kw_assert)) {
+  if (!parseTableGenValue())
+return false;
+} else if (Tok->isOneOf(Keywords.kw_def, Keywords.kw_defm) &&
+   (!Tok->Next ||
+!Tok->Next->isOneOf(tok::colon, tok::l_brace))) {
+  // The case NameValue appears.
+  if (!parseTableGenValue(true))
+return false;
+}
+  }
   break;
 case tok::arrow:
   if (Tok->Previous && Tok->Previous->is(tok::kw_noexcept))
 Tok->setType(TT_TrailingReturnArrow);
   break;
+case tok::equal:
+  // In TableGen, there must be a value after "=";
+  if (Style.isTableGen()) {
+if (!parseTableGenValue())

hnakamura5 wrote:

Fixed as suggested.

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


[clang] [clang-format] Support of TableGen value annotations. (PR #80299)

2024-02-06 Thread Hirofumi Nakamura via cfe-commits


@@ -833,13 +885,207 @@ class AnnotatingParser {
 Left->setType(TT_ArrayInitializerLSquare);
   }
   FormatToken *Tok = CurrentToken;
+  if (Style.isTableGen()) {
+if (CurrentToken->isOneOf(tok::comma, tok::minus, tok::ellipsis)) {
+  // '-' and '...' appears as a separator in slice.
+  next();
+} else {
+  // In TableGen there must be a list of Values in square brackets.
+  // It must be ValueList or SliceElements.
+  if (!parseTableGenValue())
+return false;
+}
+updateParameterCount(Left, Tok);
+continue;
+  }
   if (!consumeToken())
 return false;
   updateParameterCount(Left, Tok);
 }
 return false;
   }
 
+  void nextTableGenNonComment() {
+next();
+while (CurrentToken && CurrentToken->is(tok::comment))
+  next();
+  }
+
+  bool parseTableGenValue(bool ParseNameMode = false) {
+if (!CurrentToken)
+  return false;
+while (CurrentToken->is(tok::comment))
+  next();
+if (!parseTableGenSimpleValue())
+  return false;
+if (!CurrentToken)
+  return true;
+// Value "#" [Value]
+if (CurrentToken->is(tok::hash)) {
+  if (CurrentToken->Next &&
+  CurrentToken->Next->isOneOf(tok::colon, tok::semi, tok::l_brace)) {
+// Trailing paste operator.
+// These are only the allowed cases in TGParser::ParseValue().
+CurrentToken->setType(TT_TableGenTrailingPasteOperator);
+next();
+return true;
+  }
+  FormatToken *HashTok = CurrentToken;
+  nextTableGenNonComment();
+  HashTok->setType(TT_Unknown);
+  if (!parseTableGenValue(ParseNameMode))
+return false;
+}
+// In name mode, '{' is regarded as the end of the value.
+// See TGParser::ParseValue in TGParser.cpp
+if (ParseNameMode && CurrentToken->is(tok::l_brace))
+  return true;
+if (CurrentToken->isOneOf(tok::l_brace, tok::l_square, tok::period)) {
+  // Delegate ValueSuffix to normal consumeToken
+  CurrentToken->setType(TT_TableGenValueSuffix);
+  FormatToken *Suffix = CurrentToken;
+  nextTableGenNonComment();
+  if (Suffix->is(tok::l_square)) {
+return parseSquare();
+  } else if (Suffix->is(tok::l_brace)) {

hnakamura5 wrote:

Removed 'else'.

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


[clang] [clang-format] Support of TableGen value annotations. (PR #80299)

2024-02-06 Thread Hirofumi Nakamura via cfe-commits


@@ -833,13 +885,207 @@ class AnnotatingParser {
 Left->setType(TT_ArrayInitializerLSquare);
   }
   FormatToken *Tok = CurrentToken;
+  if (Style.isTableGen()) {
+if (CurrentToken->isOneOf(tok::comma, tok::minus, tok::ellipsis)) {
+  // '-' and '...' appears as a separator in slice.
+  next();
+} else {
+  // In TableGen there must be a list of Values in square brackets.
+  // It must be ValueList or SliceElements.
+  if (!parseTableGenValue())
+return false;
+}
+updateParameterCount(Left, Tok);
+continue;
+  }
   if (!consumeToken())
 return false;
   updateParameterCount(Left, Tok);
 }
 return false;
   }
 
+  void nextTableGenNonComment() {
+next();
+while (CurrentToken && CurrentToken->is(tok::comment))
+  next();
+  }
+
+  bool parseTableGenValue(bool ParseNameMode = false) {

hnakamura5 wrote:

I added the description about the syntax of TableGen's Value.

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


[clang] [clang-format] Support of TableGen value annotations. (PR #80299)

2024-02-06 Thread Hirofumi Nakamura via cfe-commits


@@ -833,13 +885,207 @@ class AnnotatingParser {
 Left->setType(TT_ArrayInitializerLSquare);
   }
   FormatToken *Tok = CurrentToken;
+  if (Style.isTableGen()) {
+if (CurrentToken->isOneOf(tok::comma, tok::minus, tok::ellipsis)) {
+  // '-' and '...' appears as a separator in slice.
+  next();
+} else {
+  // In TableGen there must be a list of Values in square brackets.
+  // It must be ValueList or SliceElements.
+  if (!parseTableGenValue())
+return false;
+}
+updateParameterCount(Left, Tok);
+continue;
+  }
   if (!consumeToken())
 return false;
   updateParameterCount(Left, Tok);
 }
 return false;
   }
 
+  void nextTableGenNonComment() {

hnakamura5 wrote:

Changed the name to  skipToNextNonComment .

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


[clang] [clang-format] Support of TableGen value annotations. (PR #80299)

2024-02-06 Thread Hirofumi Nakamura via cfe-commits


@@ -256,6 +256,18 @@ class AnnotatingParser {
   }
 }
   }
+  if (Style.isTableGen()) {
+if (CurrentToken->isOneOf(tok::comma, tok::equal)) {
+  // They appears as a separator. Unless it is not in class definition.

hnakamura5 wrote:

Changed this sentence.

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


[clang] [clang-format] Support of TableGen value annotations. (PR #80299)

2024-02-06 Thread Hirofumi Nakamura via cfe-commits

https://github.com/hnakamura5 updated 
https://github.com/llvm/llvm-project/pull/80299

>From 36f83a124ea8ad27cfefa1d12ae5aa781f8e6e3e Mon Sep 17 00:00:00 2001
From: hnakamura5 
Date: Thu, 1 Feb 2024 23:07:42 +0900
Subject: [PATCH 1/2] [clang-format] Support of TableGen value annotations.

---
 clang/lib/Format/FormatToken.h|  10 +
 clang/lib/Format/FormatTokenLexer.cpp |   2 +-
 clang/lib/Format/TokenAnnotator.cpp   | 303 +-
 clang/lib/Format/UnwrappedLineParser.cpp  |  13 +-
 clang/unittests/Format/TokenAnnotatorTest.cpp |  45 +++
 5 files changed, 364 insertions(+), 9 deletions(-)

diff --git a/clang/lib/Format/FormatToken.h b/clang/lib/Format/FormatToken.h
index bace91b5f99b4..0c1dce7a29408 100644
--- a/clang/lib/Format/FormatToken.h
+++ b/clang/lib/Format/FormatToken.h
@@ -150,7 +150,17 @@ namespace format {
   TYPE(StructuredBindingLSquare)   
\
   TYPE(TableGenBangOperator)   
\
   TYPE(TableGenCondOperator)   
\
+  TYPE(TableGenCondOperatorColon)  
\
+  TYPE(TableGenCondOperatorComma)  
\
+  TYPE(TableGenDAGArgCloser)   
\
+  TYPE(TableGenDAGArgListColon)
\
+  TYPE(TableGenDAGArgListComma)
\
+  TYPE(TableGenDAGArgOpener)   
\
+  TYPE(TableGenListCloser) 
\
+  TYPE(TableGenListOpener) 
\
   TYPE(TableGenMultiLineString)
\
+  TYPE(TableGenTrailingPasteOperator)  
\
+  TYPE(TableGenValueSuffix)
\
   TYPE(TemplateCloser) 
\
   TYPE(TemplateOpener) 
\
   TYPE(TemplateString) 
\
diff --git a/clang/lib/Format/FormatTokenLexer.cpp 
b/clang/lib/Format/FormatTokenLexer.cpp
index d7de09ef0e12a..27b2b1b619b1d 100644
--- a/clang/lib/Format/FormatTokenLexer.cpp
+++ b/clang/lib/Format/FormatTokenLexer.cpp
@@ -816,7 +816,7 @@ void FormatTokenLexer::handleTableGenMultilineString() {
   auto CloseOffset = Lex->getBuffer().find("}]", OpenOffset);
   if (CloseOffset == StringRef::npos)
 return;
-  auto Text = Lex->getBuffer().substr(OpenOffset, CloseOffset + 2);
+  auto Text = Lex->getBuffer().substr(OpenOffset, CloseOffset - OpenOffset + 
2);
   MultiLineString->TokenText = Text;
   resetLexer(SourceMgr.getFileOffset(
   Lex->getSourceLocation(Lex->getBufferLocation() - 2 + Text.size(;
diff --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index df1c5bc19de1e..afcf5f638ce4c 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -256,6 +256,18 @@ class AnnotatingParser {
   }
 }
   }
+  if (Style.isTableGen()) {
+if (CurrentToken->isOneOf(tok::comma, tok::equal)) {
+  // They appears as a separator. Unless it is not in class definition.
+  next();
+  continue;
+}
+// In angle, there must be Value like tokens. Types are also able to be
+// parsed in the same way with Values.
+if (!parseTableGenValue())
+  return false;
+continue;
+  }
   if (!consumeToken())
 return false;
 }
@@ -388,6 +400,28 @@ class AnnotatingParser {
   Contexts.back().IsExpression = !IsForOrCatch;
 }
 
+if (Style.isTableGen()) {
+  if (FormatToken *Prev = OpeningParen.Previous) {
+if (Prev->is(TT_TableGenCondOperator)) {
+  Contexts.back().IsTableGenCondOpe = true;
+  Contexts.back().IsExpression = true;
+} else if (Contexts.size() > 1 &&
+   Contexts[Contexts.size() - 2].IsTableGenBangOpe) {
+  // Hack to handle bang operators. The parent context's flag
+  // was set by parseTableGenSimpleValue().
+  // We have to specify the context outside because the prev of "(" may
+  // be ">", not the bang operator in this case.
+  Contexts.back().IsTableGenBangOpe = true;
+  Contexts.back().IsExpression = true;
+} else {
+  // Otherwise, this paren seems DAGArg.
+  if (!parseTableGenDAGArg())
+return false;
+  return parseTableGenDAGArgAndList();
+}
+  }
+}
+
 // Infer the role of the l_paren based on the previous token if we haven't
 // detected one yet.
 if (PrevNonComment && 

[clang] [clang-format] Support of TableGen value annotations. (PR #80299)

2024-02-01 Thread Hirofumi Nakamura via cfe-commits

https://github.com/hnakamura5 edited 
https://github.com/llvm/llvm-project/pull/80299
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format] Support of TableGen value annotations. (PR #80299)

2024-02-01 Thread Hirofumi Nakamura via cfe-commits


@@ -915,10 +1163,12 @@ class AnnotatingParser {
 Previous->setType(TT_SelectorName);
   }
 }
-if (CurrentToken->is(tok::colon) && OpeningBrace.is(TT_Unknown))
+if (CurrentToken->is(tok::colon) && OpeningBrace.is(TT_Unknown) &&
+!Style.isTableGen()) {
   OpeningBrace.setType(TT_DictLiteral);
-else if (Style.isJavaScript())
+} else if (Style.isJavaScript()) {
   OpeningBrace.overwriteFixedType(TT_DictLiteral);
+}

hnakamura5 wrote:

Line 1126 to here is inside parseBrace(), where is determining whether the 
l_brace is opening of dictionary literal.
TableGen does not have DictLitereals.

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


[clang] [clang-format] Support of TableGen value annotations. (PR #80299)

2024-02-01 Thread Hirofumi Nakamura via cfe-commits


@@ -1423,11 +1692,30 @@ class AnnotatingParser {
 if (!Tok->getPreviousNonComment())
   Line.IsContinuation = true;
   }
+  if (Style.isTableGen()) {
+if (Tok->is(Keywords.kw_assert)) {
+  if (!parseTableGenValue())
+return false;
+} else if (Tok->isOneOf(Keywords.kw_def, Keywords.kw_defm) &&
+   (!Tok->Next ||
+!Tok->Next->isOneOf(tok::colon, tok::l_brace))) {
+  // The case NameValue appears.
+  if (!parseTableGenValue(true))
+return false;
+}
+  }
   break;
 case tok::arrow:
   if (Tok->Previous && Tok->Previous->is(tok::kw_noexcept))
 Tok->setType(TT_TrailingReturnArrow);
   break;
+case tok::equal:
+  // In TableGen, there must be a value after "=";
+  if (Style.isTableGen()) {
+if (!parseTableGenValue())
+  return false;
+  }
+  break;

hnakamura5 wrote:

In consumeToken().

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


[clang] [clang-format] Support of TableGen value annotations. (PR #80299)

2024-02-01 Thread Hirofumi Nakamura via cfe-commits


@@ -1423,11 +1692,30 @@ class AnnotatingParser {
 if (!Tok->getPreviousNonComment())
   Line.IsContinuation = true;
   }
+  if (Style.isTableGen()) {
+if (Tok->is(Keywords.kw_assert)) {
+  if (!parseTableGenValue())
+return false;
+} else if (Tok->isOneOf(Keywords.kw_def, Keywords.kw_defm) &&
+   (!Tok->Next ||
+!Tok->Next->isOneOf(tok::colon, tok::l_brace))) {
+  // The case NameValue appears.
+  if (!parseTableGenValue(true))
+return false;
+}
+  }

hnakamura5 wrote:

In consumeToken().

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


[clang] [clang-format] Support of TableGen value annotations. (PR #80299)

2024-02-01 Thread Hirofumi Nakamura via cfe-commits


@@ -833,13 +885,207 @@ class AnnotatingParser {
 Left->setType(TT_ArrayInitializerLSquare);
   }
   FormatToken *Tok = CurrentToken;
+  if (Style.isTableGen()) {
+if (CurrentToken->isOneOf(tok::comma, tok::minus, tok::ellipsis)) {
+  // '-' and '...' appears as a separator in slice.
+  next();
+} else {
+  // In TableGen there must be a list of Values in square brackets.
+  // It must be ValueList or SliceElements.
+  if (!parseTableGenValue())
+return false;
+}
+updateParameterCount(Left, Tok);
+continue;
+  }

hnakamura5 wrote:

In parseSquare(). 

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


[clang] [clang-format] Support of TableGen value annotations. (PR #80299)

2024-02-01 Thread Hirofumi Nakamura via cfe-commits

https://github.com/hnakamura5 edited 
https://github.com/llvm/llvm-project/pull/80299
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format] Support of TableGen value annotations. (PR #80299)

2024-02-01 Thread Hirofumi Nakamura via cfe-commits


@@ -549,6 +583,22 @@ class AnnotatingParser {
   if (CurrentToken->is(tok::comma))
 Contexts.back().CanBeExpression = true;
 
+  if (Style.isTableGen()) {
+if (CurrentToken->is(tok::comma)) {
+  if (Contexts.back().IsTableGenCondOpe)
+CurrentToken->setType(TT_TableGenCondOperatorComma);
+  next();
+} else if (CurrentToken->is(tok::colon)) {
+  if (Contexts.back().IsTableGenCondOpe)
+CurrentToken->setType(TT_TableGenCondOperatorColon);
+  next();
+}
+// In TableGen there must be Values in parens.
+if (!parseTableGenValue())
+  return false;
+continue;
+  }
+

hnakamura5 wrote:

In parseParens().

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


[clang] [clang-format] Support of TableGen value annotations. (PR #80299)

2024-02-01 Thread Hirofumi Nakamura via cfe-commits


@@ -388,6 +400,28 @@ class AnnotatingParser {
   Contexts.back().IsExpression = !IsForOrCatch;
 }
 
+if (Style.isTableGen()) {
+  if (FormatToken *Prev = OpeningParen.Previous) {
+if (Prev->is(TT_TableGenCondOperator)) {
+  Contexts.back().IsTableGenCondOpe = true;
+  Contexts.back().IsExpression = true;
+} else if (Contexts.size() > 1 &&
+   Contexts[Contexts.size() - 2].IsTableGenBangOpe) {
+  // Hack to handle bang operators. The parent context's flag
+  // was set by parseTableGenSimpleValue().
+  // We have to specify the context outside because the prev of "(" may
+  // be ">", not the bang operator in this case.
+  Contexts.back().IsTableGenBangOpe = true;
+  Contexts.back().IsExpression = true;
+} else {
+  // Otherwise, this paren seems DAGArg.
+  if (!parseTableGenDAGArg())
+return false;
+  return parseTableGenDAGArgAndList();
+}
+  }
+}
+

hnakamura5 wrote:

In parseParens().

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


[clang] [clang-format] Support of TableGen value annotations. (PR #80299)

2024-02-01 Thread Hirofumi Nakamura via cfe-commits


@@ -256,6 +256,18 @@ class AnnotatingParser {
   }
 }
   }
+  if (Style.isTableGen()) {
+if (CurrentToken->isOneOf(tok::comma, tok::equal)) {
+  // They appears as a separator. Unless it is not in class definition.
+  next();
+  continue;
+}
+// In angle, there must be Value like tokens. Types are also able to be
+// parsed in the same way with Values.
+if (!parseTableGenValue())
+  return false;
+continue;
+  }

hnakamura5 wrote:

This is inside parseAgnle().

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


[clang] [clang-format] Support of TableGen value annotations. (PR #80299)

2024-02-01 Thread Hirofumi Nakamura via cfe-commits


@@ -816,7 +816,7 @@ void FormatTokenLexer::handleTableGenMultilineString() {
   auto CloseOffset = Lex->getBuffer().find("}]", OpenOffset);
   if (CloseOffset == StringRef::npos)
 return;
-  auto Text = Lex->getBuffer().substr(OpenOffset, CloseOffset + 2);
+  auto Text = Lex->getBuffer().substr(OpenOffset, CloseOffset - OpenOffset + 
2);

hnakamura5 wrote:

This is actually a bug fix of https://github.com/llvm/llvm-project/pull/78032. 
I need this to run tests. If requested, I will split this change into single 
pull request.

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


[clang] [clang-format] Support of TableGen value annotations. (PR #80299)

2024-02-01 Thread Hirofumi Nakamura via cfe-commits

https://github.com/hnakamura5 created 
https://github.com/llvm/llvm-project/pull/80299

This implements the annotation of the values in TableGen.
The main changes are,

- parseTableGenValue(), the simplified parser method for the syntax of values.
- modified consumeToken() to parseTableGenValue in 'if', 'assert' and after '='.
- modified parseParens() to call parseTableGenValue inside.
- modified parseSquare() to to call parseTableGenValue inside, with skipping 
separator tokens.
- modified parseAngle() to call parseTableGenValue inside, with skipping 
separator tokens.

This PR is separated from https://github.com/llvm/llvm-project/pull/76059 .
Though this is fairly a large patch, I failed to split into some self completed 
patch. I will add some comments to clarify where the diff exists.

>From 36f83a124ea8ad27cfefa1d12ae5aa781f8e6e3e Mon Sep 17 00:00:00 2001
From: hnakamura5 
Date: Thu, 1 Feb 2024 23:07:42 +0900
Subject: [PATCH] [clang-format] Support of TableGen value annotations.

---
 clang/lib/Format/FormatToken.h|  10 +
 clang/lib/Format/FormatTokenLexer.cpp |   2 +-
 clang/lib/Format/TokenAnnotator.cpp   | 303 +-
 clang/lib/Format/UnwrappedLineParser.cpp  |  13 +-
 clang/unittests/Format/TokenAnnotatorTest.cpp |  45 +++
 5 files changed, 364 insertions(+), 9 deletions(-)

diff --git a/clang/lib/Format/FormatToken.h b/clang/lib/Format/FormatToken.h
index bace91b5f99b4..0c1dce7a29408 100644
--- a/clang/lib/Format/FormatToken.h
+++ b/clang/lib/Format/FormatToken.h
@@ -150,7 +150,17 @@ namespace format {
   TYPE(StructuredBindingLSquare)   
\
   TYPE(TableGenBangOperator)   
\
   TYPE(TableGenCondOperator)   
\
+  TYPE(TableGenCondOperatorColon)  
\
+  TYPE(TableGenCondOperatorComma)  
\
+  TYPE(TableGenDAGArgCloser)   
\
+  TYPE(TableGenDAGArgListColon)
\
+  TYPE(TableGenDAGArgListComma)
\
+  TYPE(TableGenDAGArgOpener)   
\
+  TYPE(TableGenListCloser) 
\
+  TYPE(TableGenListOpener) 
\
   TYPE(TableGenMultiLineString)
\
+  TYPE(TableGenTrailingPasteOperator)  
\
+  TYPE(TableGenValueSuffix)
\
   TYPE(TemplateCloser) 
\
   TYPE(TemplateOpener) 
\
   TYPE(TemplateString) 
\
diff --git a/clang/lib/Format/FormatTokenLexer.cpp 
b/clang/lib/Format/FormatTokenLexer.cpp
index d7de09ef0e12a..27b2b1b619b1d 100644
--- a/clang/lib/Format/FormatTokenLexer.cpp
+++ b/clang/lib/Format/FormatTokenLexer.cpp
@@ -816,7 +816,7 @@ void FormatTokenLexer::handleTableGenMultilineString() {
   auto CloseOffset = Lex->getBuffer().find("}]", OpenOffset);
   if (CloseOffset == StringRef::npos)
 return;
-  auto Text = Lex->getBuffer().substr(OpenOffset, CloseOffset + 2);
+  auto Text = Lex->getBuffer().substr(OpenOffset, CloseOffset - OpenOffset + 
2);
   MultiLineString->TokenText = Text;
   resetLexer(SourceMgr.getFileOffset(
   Lex->getSourceLocation(Lex->getBufferLocation() - 2 + Text.size(;
diff --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index df1c5bc19de1e..afcf5f638ce4c 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -256,6 +256,18 @@ class AnnotatingParser {
   }
 }
   }
+  if (Style.isTableGen()) {
+if (CurrentToken->isOneOf(tok::comma, tok::equal)) {
+  // They appears as a separator. Unless it is not in class definition.
+  next();
+  continue;
+}
+// In angle, there must be Value like tokens. Types are also able to be
+// parsed in the same way with Values.
+if (!parseTableGenValue())
+  return false;
+continue;
+  }
   if (!consumeToken())
 return false;
 }
@@ -388,6 +400,28 @@ class AnnotatingParser {
   Contexts.back().IsExpression = !IsForOrCatch;
 }
 
+if (Style.isTableGen()) {
+  if (FormatToken *Prev = OpeningParen.Previous) {
+if (Prev->is(TT_TableGenCondOperator)) {
+  Contexts.back().IsTableGenCondOpe = true;
+  Contexts.back().IsExpression = true;
+} else if (Contexts.size() > 1 &&
+   Contexts[Contexts.size() - 2].IsTableGenBangOpe) {
+  // Hack to 

[clang] [clang-format] Support of TableGen tokens with unary operator like form, bang operators and numeric literals. (PR #78996)

2024-01-30 Thread Hirofumi Nakamura via cfe-commits

hnakamura5 wrote:

@HazardyKnusperkeks 
Thank you for checking and accepting!

@mydeveloperday 
You will be able to see the points in the consequent PRs.

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


[clang] [clang-format] Support of TableGen tokens with unary operator like form, bang operators and numeric literals. (PR #78996)

2024-01-30 Thread Hirofumi Nakamura via cfe-commits

https://github.com/hnakamura5 closed 
https://github.com/llvm/llvm-project/pull/78996
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format] Support of TableGen tokens with unary operator like form, bang operators and numeric literals. (PR #78996)

2024-01-29 Thread Hirofumi Nakamura via cfe-commits


@@ -276,13 +276,44 @@ void FormatTokenLexer::tryMergePreviousTokens() {
   return;
 }
   }
-  // TableGen's Multi line string starts with [{
-  if (Style.isTableGen() && tryMergeTokens({tok::l_square, tok::l_brace},
-   TT_TableGenMultiLineString)) {
-// Set again with finalizing. This must never be annotated as other types.
-Tokens.back()->setFinalizedType(TT_TableGenMultiLineString);
-Tokens.back()->Tok.setKind(tok::string_literal);
-return;
+  if (Style.isTableGen()) {
+// TableGen's Multi line string starts with [{
+if (tryMergeTokens({tok::l_square, tok::l_brace},
+   TT_TableGenMultiLineString)) {
+  // Set again with finalizing. This must never be annotated as other 
types.
+  Tokens.back()->setFinalizedType(TT_TableGenMultiLineString);
+  Tokens.back()->Tok.setKind(tok::string_literal);
+  return;
+}
+// TableGen's bang operator is the form !.
+// !cond is a special case with specific syntax.
+if (tryMergeTokens({tok::exclaim, tok::identifier},
+   TT_TableGenBangOperator)) {
+  Tokens.back()->Tok.setKind(tok::identifier);
+  Tokens.back()->Tok.setIdentifierInfo(nullptr);
+  if (Tokens.back()->TokenText == "!cond")
+Tokens.back()->setFinalizedType(TT_TableGenCondOperator);
+  else
+Tokens.back()->setFinalizedType(TT_TableGenBangOperator);
+  return;
+}
+if (tryMergeTokens({tok::exclaim, tok::kw_if}, TT_TableGenBangOperator)) {
+  // Here, "! if" becomes "!if".  That is, ! captures if even when the 
space
+  // exists. That is only one possibility in TableGen's syntax.
+  Tokens.back()->Tok.setKind(tok::identifier);
+  Tokens.back()->Tok.setIdentifierInfo(nullptr);
+  Tokens.back()->setFinalizedType(TT_TableGenBangOperator);
+  return;
+}
+// +, - with numbers are literals. Not unary operators.
+if (tryMergeTokens({tok::plus, tok::numeric_constant}, TT_Unknown)) {
+  Tokens.back()->Tok.setKind(tok::numeric_constant);
+  return;

hnakamura5 wrote:

@mydeveloperday 
Thank you for reviewing this pull request.
Now it comes to 1 week since this PR is started. I want to continue before I 
forget.
Could you mind accepting or adding some suggestion?
Or if you do not intend neither, can I request another reviewer? 

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


[clang] [clang-format] Support of TableGen tokens with unary operator like form, bang operators and numeric literals. (PR #78996)

2024-01-23 Thread Hirofumi Nakamura via cfe-commits


@@ -276,13 +276,44 @@ void FormatTokenLexer::tryMergePreviousTokens() {
   return;
 }
   }
-  // TableGen's Multi line string starts with [{
-  if (Style.isTableGen() && tryMergeTokens({tok::l_square, tok::l_brace},
-   TT_TableGenMultiLineString)) {
-// Set again with finalizing. This must never be annotated as other types.
-Tokens.back()->setFinalizedType(TT_TableGenMultiLineString);
-Tokens.back()->Tok.setKind(tok::string_literal);
-return;
+  if (Style.isTableGen()) {
+// TableGen's Multi line string starts with [{
+if (tryMergeTokens({tok::l_square, tok::l_brace},
+   TT_TableGenMultiLineString)) {
+  // Set again with finalizing. This must never be annotated as other 
types.
+  Tokens.back()->setFinalizedType(TT_TableGenMultiLineString);
+  Tokens.back()->Tok.setKind(tok::string_literal);
+  return;
+}
+// TableGen's bang operator is the form !.
+// !cond is a special case with specific syntax.
+if (tryMergeTokens({tok::exclaim, tok::identifier},
+   TT_TableGenBangOperator)) {
+  Tokens.back()->Tok.setKind(tok::identifier);
+  Tokens.back()->Tok.setIdentifierInfo(nullptr);
+  if (Tokens.back()->TokenText == "!cond")
+Tokens.back()->setFinalizedType(TT_TableGenCondOperator);
+  else
+Tokens.back()->setFinalizedType(TT_TableGenBangOperator);
+  return;
+}
+if (tryMergeTokens({tok::exclaim, tok::kw_if}, TT_TableGenBangOperator)) {
+  // Here, "! if" becomes "!if".  That is, ! captures if even when the 
space
+  // exists. That is only one possibility in TableGen's syntax.
+  Tokens.back()->Tok.setKind(tok::identifier);
+  Tokens.back()->Tok.setIdentifierInfo(nullptr);
+  Tokens.back()->setFinalizedType(TT_TableGenBangOperator);
+  return;
+}
+// +, - with numbers are literals. Not unary operators.
+if (tryMergeTokens({tok::plus, tok::numeric_constant}, TT_Unknown)) {
+  Tokens.back()->Tok.setKind(tok::numeric_constant);
+  return;

hnakamura5 wrote:

https://llvm.org/docs/TableGen/ProgRef.html#values-and-expressions

As far as I read from the manual, TableGen does not have `+` as infix binary 
operator.
And as noted in the warning above, `-` is lexed as the integer's prefix rather 
than infix operator for range and slice.

> could we build a better set of FormatTableGen unit tests to ensure we don't 
> cause any regressions?could we build a better set of FormatTableGen unit 
> tests to ensure we don't cause any regressions?

I agree, and actually there is a comprehensive set of unit test for TableGen's 
syntax here. (Even this may be missing real examples of TableGen usage in 
target definition, mlir and so on.)
https://github.com/llvm/llvm-project/pull/76059/files#diff-2ce45a84684fe19d813e79bab2f732809f3544d38f344e3d2cfe23aa9216a1c8

Current pull request is separated from this PR. I'm wondering when to add the 
test. Because now it only recognizes tokens, and cannot format many part of 
that yet.


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


[clang] [clang-format] Support of TableGen formatting. (PR #76059)

2024-01-22 Thread Hirofumi Nakamura via cfe-commits

hnakamura5 wrote:

bang operators and numeric literals part 
https://github.com/llvm/llvm-project/pull/78996 .

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


[clang] [clang-format] Support of TableGen formatting. (PR #76059)

2024-01-22 Thread Hirofumi Nakamura via cfe-commits

hnakamura5 wrote:

Numeric like identifiers part https://github.com/llvm/llvm-project/pull/78571


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


[clang] [clang-format] Support of TableGen tokens with unary operator like form, bang operators and numeric literals. (PR #78996)

2024-01-22 Thread Hirofumi Nakamura via cfe-commits

https://github.com/hnakamura5 edited 
https://github.com/llvm/llvm-project/pull/78996
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format] Support of TableGen tokens with unary operator like form, bang operators and numeric literal. (PR #78996)

2024-01-22 Thread Hirofumi Nakamura via cfe-commits

https://github.com/hnakamura5 created 
https://github.com/llvm/llvm-project/pull/78996

Adds the support for tokens that have forms like unary operators.
- bang operators:  `!name`
- cond operator: `!cond`
- numeric literals: `+1`, `-1`
cond operator are one of bang operators but is distinguished because it has 
very specific syntax.

>From af522a6ac1a2620408ec2933261ad9d17066ddff Mon Sep 17 00:00:00 2001
From: hnakamura5 
Date: Tue, 23 Jan 2024 00:50:17 +0900
Subject: [PATCH] [clang-format] Support of TableGen tokens with unary operator
 like form, bang operators and numeric literal.

---
 clang/lib/Format/FormatToken.h|  2 +
 clang/lib/Format/FormatTokenLexer.cpp | 45 ---
 clang/unittests/Format/TokenAnnotatorTest.cpp | 24 --
 3 files changed, 60 insertions(+), 11 deletions(-)

diff --git a/clang/lib/Format/FormatToken.h b/clang/lib/Format/FormatToken.h
index dede89f2600150..bace91b5f99b4d 100644
--- a/clang/lib/Format/FormatToken.h
+++ b/clang/lib/Format/FormatToken.h
@@ -148,6 +148,8 @@ namespace format {
   TYPE(StructLBrace)   
\
   TYPE(StructRBrace)   
\
   TYPE(StructuredBindingLSquare)   
\
+  TYPE(TableGenBangOperator)   
\
+  TYPE(TableGenCondOperator)   
\
   TYPE(TableGenMultiLineString)
\
   TYPE(TemplateCloser) 
\
   TYPE(TemplateOpener) 
\
diff --git a/clang/lib/Format/FormatTokenLexer.cpp 
b/clang/lib/Format/FormatTokenLexer.cpp
index 52a55ea23b5f2f..d7de09ef0e12ab 100644
--- a/clang/lib/Format/FormatTokenLexer.cpp
+++ b/clang/lib/Format/FormatTokenLexer.cpp
@@ -276,13 +276,44 @@ void FormatTokenLexer::tryMergePreviousTokens() {
   return;
 }
   }
-  // TableGen's Multi line string starts with [{
-  if (Style.isTableGen() && tryMergeTokens({tok::l_square, tok::l_brace},
-   TT_TableGenMultiLineString)) {
-// Set again with finalizing. This must never be annotated as other types.
-Tokens.back()->setFinalizedType(TT_TableGenMultiLineString);
-Tokens.back()->Tok.setKind(tok::string_literal);
-return;
+  if (Style.isTableGen()) {
+// TableGen's Multi line string starts with [{
+if (tryMergeTokens({tok::l_square, tok::l_brace},
+   TT_TableGenMultiLineString)) {
+  // Set again with finalizing. This must never be annotated as other 
types.
+  Tokens.back()->setFinalizedType(TT_TableGenMultiLineString);
+  Tokens.back()->Tok.setKind(tok::string_literal);
+  return;
+}
+// TableGen's bang operator is the form !.
+// !cond is a special case with specific syntax.
+if (tryMergeTokens({tok::exclaim, tok::identifier},
+   TT_TableGenBangOperator)) {
+  Tokens.back()->Tok.setKind(tok::identifier);
+  Tokens.back()->Tok.setIdentifierInfo(nullptr);
+  if (Tokens.back()->TokenText == "!cond")
+Tokens.back()->setFinalizedType(TT_TableGenCondOperator);
+  else
+Tokens.back()->setFinalizedType(TT_TableGenBangOperator);
+  return;
+}
+if (tryMergeTokens({tok::exclaim, tok::kw_if}, TT_TableGenBangOperator)) {
+  // Here, "! if" becomes "!if".  That is, ! captures if even when the 
space
+  // exists. That is only one possibility in TableGen's syntax.
+  Tokens.back()->Tok.setKind(tok::identifier);
+  Tokens.back()->Tok.setIdentifierInfo(nullptr);
+  Tokens.back()->setFinalizedType(TT_TableGenBangOperator);
+  return;
+}
+// +, - with numbers are literals. Not unary operators.
+if (tryMergeTokens({tok::plus, tok::numeric_constant}, TT_Unknown)) {
+  Tokens.back()->Tok.setKind(tok::numeric_constant);
+  return;
+}
+if (tryMergeTokens({tok::minus, tok::numeric_constant}, TT_Unknown)) {
+  Tokens.back()->Tok.setKind(tok::numeric_constant);
+  return;
+}
   }
 }
 
diff --git a/clang/unittests/Format/TokenAnnotatorTest.cpp 
b/clang/unittests/Format/TokenAnnotatorTest.cpp
index 3dbf504c35ed55..cb93930e0fc3bc 100644
--- a/clang/unittests/Format/TokenAnnotatorTest.cpp
+++ b/clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -2210,16 +2210,24 @@ TEST_F(TokenAnnotatorTest, UnderstandTableGenTokens) {
   EXPECT_TRUE(Tokens[0]->IsMultiline);
   EXPECT_EQ(Tokens[0]->LastLineColumnWidth, sizeof("   the string. }]") - 1);
 
+  // Numeric literals.
+  Tokens = Annotate("1234");
+  EXPECT_TOKEN(Tokens[0], tok::numeric_constant, TT_Unknown);
+  Tokens = Annotate("-1");
+  EXPECT_TOKEN(Tokens[0], tok::numeric_constant, TT_Unknown);
+  Tokens = Annotate("+1234");
+  EXPECT_TOKEN(Tokens[0], tok::numeric_constant, TT_Unknown);
+  

[clang] [clang-format] Support of TableGen statements in unwrapped line parser (PR #78846)

2024-01-22 Thread Hirofumi Nakamura via cfe-commits

hnakamura5 wrote:

Thank you very much!

> how small the diff is

Maybe it is by TableGen's simple syntax, and that here we are parsing only the 
structure of the statements. (e.g. ignoring the `` part of `if` now).

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


[clang] [clang-format] Support of TableGen statements in unwrapped line parser (PR #78846)

2024-01-22 Thread Hirofumi Nakamura via cfe-commits

https://github.com/hnakamura5 closed 
https://github.com/llvm/llvm-project/pull/78846
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format] Support of TableGen statements in unwrapped line parser (PR #78846)

2024-01-21 Thread Hirofumi Nakamura via cfe-commits

https://github.com/hnakamura5 updated 
https://github.com/llvm/llvm-project/pull/78846

>From fbf7e0f624fb7a4ef05970ee1241cf68f3f5f783 Mon Sep 17 00:00:00 2001
From: hnakamura5 
Date: Sat, 20 Jan 2024 22:37:25 +0900
Subject: [PATCH 1/2] [clang-format] Support of TableGen statements in
 unwrapped line parser

---
 clang/lib/Format/UnwrappedLineParser.cpp  | 27 ++-
 clang/unittests/Format/TokenAnnotatorTest.cpp | 12 +
 2 files changed, 38 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Format/UnwrappedLineParser.cpp 
b/clang/lib/Format/UnwrappedLineParser.cpp
index c08ce86449b6ea6..a81c8e2971e2af9 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -1661,7 +1661,8 @@ void UnwrappedLineParser::parseStructuralElement(
 // In Verilog labels can be any expression, so we don't do them here.
 // JS doesn't have macros, and within classes colons indicate fields, not
 // labels.
-if (!Style.isJavaScript() && !Style.isVerilog() &&
+// TableGen doesn't have labels.
+if (!Style.isJavaScript() && !Style.isVerilog() && !Style.isTableGen() &&
 Tokens->peekNextToken()->is(tok::colon) && !Line->MustBeDeclaration) {
   nextToken();
   Line->Tokens.begin()->Tok->MustBreakBefore = true;
@@ -1790,6 +1791,12 @@ void UnwrappedLineParser::parseStructuralElement(
 addUnwrappedLine();
 return;
   }
+  if (Style.isTableGen()) {
+// Do nothing special. In this case the l_brace becomes FunctionLBrace.
+// This is same as def and so on.
+nextToken();
+break;
+  }
   [[fallthrough]];
 case tok::kw_struct:
 case tok::kw_union:
@@ -2028,6 +2035,16 @@ void UnwrappedLineParser::parseStructuralElement(
 // initialisers are indented the same way.
 if (Style.isCSharp())
   FormatTok->setBlockKind(BK_BracedInit);
+// TableGen's defset statement has syntax of the form,
+// `defset   = { ... }`
+if (Style.isTableGen() &&
+Line->Tokens.begin()->Tok->is(Keywords.kw_defset)) {
+  FormatTok->setFinalizedType(TT_FunctionLBrace);
+  parseBlock(/*MustBeDeclaration=*/false, /*AddLevels=*/1u,
+ /*MunchSemi=*/false);
+  addUnwrappedLine();
+  break;
+}
 nextToken();
 parseBracedList();
   } else if (Style.Language == FormatStyle::LK_Proto &&
@@ -2743,6 +2760,14 @@ FormatToken 
*UnwrappedLineParser::parseIfThenElse(IfStmtKind *IfKind,
 }
   }
 
+  // TableGen's if statement has the form of `if  then { ... }`.
+  if (Style.isTableGen()) {
+while (!eof() && !(FormatTok->is(Keywords.kw_then))) {
+  // Simply skip until then. This range only contains a value.
+  nextToken();
+}
+  }
+
   // Handle `if !consteval`.
   if (FormatTok->is(tok::exclaim))
 nextToken();
diff --git a/clang/unittests/Format/TokenAnnotatorTest.cpp 
b/clang/unittests/Format/TokenAnnotatorTest.cpp
index 64b2abac5cce531..6c065817892b543 100644
--- a/clang/unittests/Format/TokenAnnotatorTest.cpp
+++ b/clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -2232,6 +2232,18 @@ TEST_F(TokenAnnotatorTest, UnderstandTableGenTokens) {
   EXPECT_TOKEN(Tokens[0], tok::identifier, TT_Unknown);
   Tokens = Annotate("01234Vector");
   EXPECT_TOKEN(Tokens[0], tok::identifier, TT_Unknown);
+
+  // Structured statements.
+  Tokens = Annotate("class Foo {}");
+  EXPECT_TOKEN(Tokens[2], tok::l_brace, TT_FunctionLBrace);
+  Tokens = Annotate("def Def: Foo {}");
+  EXPECT_TOKEN(Tokens[2], tok::colon, TT_InheritanceColon);
+  EXPECT_TOKEN(Tokens[4], tok::l_brace, TT_FunctionLBrace);
+  Tokens = Annotate("if cond then {} else {}");
+  EXPECT_TOKEN(Tokens[3], tok::l_brace, TT_ControlStatementLBrace);
+  EXPECT_TOKEN(Tokens[6], tok::l_brace, TT_ElseLBrace);
+  Tokens = Annotate("defset Foo Def2 = {}");
+  EXPECT_TOKEN(Tokens[4], tok::l_brace, TT_FunctionLBrace);
 }
 
 TEST_F(TokenAnnotatorTest, UnderstandConstructors) {

>From 0d8025d75da3c943212b32291d017f3e485c37f8 Mon Sep 17 00:00:00 2001
From: Hirofumi Nakamura 
Date: Sun, 21 Jan 2024 21:25:13 +0900
Subject: [PATCH 2/2] Fixed as suggested.
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Co-authored-by: Björn Schäpers 
---
 clang/lib/Format/UnwrappedLineParser.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/lib/Format/UnwrappedLineParser.cpp 
b/clang/lib/Format/UnwrappedLineParser.cpp
index a81c8e2971e2af9..dd38ccd70bfeaa2 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -2762,7 +2762,7 @@ FormatToken 
*UnwrappedLineParser::parseIfThenElse(IfStmtKind *IfKind,
 
   // TableGen's if statement has the form of `if  then { ... }`.
   if (Style.isTableGen()) {
-while (!eof() && !(FormatTok->is(Keywords.kw_then))) {
+while (!eof() && FormatTok->isNot(Keywords.kw_then)) {
   // 

[clang] [clang-format] Support of TableGen formatting. (PR #76059)

2024-01-20 Thread Hirofumi Nakamura via cfe-commits

hnakamura5 wrote:

unwrapped line parser for statements part 
https://github.com/llvm/llvm-project/pull/78846 .

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


[clang] [clang-format] Support of TableGen formatting. (PR #76059)

2024-01-20 Thread Hirofumi Nakamura via cfe-commits

hnakamura5 wrote:

Numeric like identifiers part https://github.com/llvm/llvm-project/pull/78571

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


[clang] [clang-format] Support of TableGen statements in unwrapped line parser (PR #78846)

2024-01-20 Thread Hirofumi Nakamura via cfe-commits

https://github.com/hnakamura5 edited 
https://github.com/llvm/llvm-project/pull/78846
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


  1   2   >