[clang] Annotate enum r brace (PR #68535)

2023-10-09 Thread Björn Schäpers via cfe-commits

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


[clang] Annotate enum r brace (PR #68535)

2023-10-08 Thread Owen Pan via cfe-commits
=?utf-8?q?Bj=C3=B6rn_Sch=C3=A4pers?= 
Message-ID:
In-Reply-To: 


owenca wrote:

See https://github.com/llvm/llvm-project/issues/56636.

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


[clang] Annotate enum r brace (PR #68535)

2023-10-08 Thread Owen Pan via cfe-commits
=?utf-8?q?Bj=C3=B6rn_Sch=C3=A4pers?= 
Message-ID:
In-Reply-To: 


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


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


[clang] Annotate enum r brace (PR #68535)

2023-10-08 Thread via cfe-commits
=?utf-8?q?Björn_Schäpers?= 
Message-ID:
In-Reply-To: 


llvmbot wrote:




@llvm/pr-subscribers-clang-format


Changes

This review is only for the second commit.

Is there a way to build pull request upon each other?

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


3 Files Affected:

- (modified) clang/lib/Format/FormatToken.h (+5) 
- (modified) clang/lib/Format/UnwrappedLineParser.cpp (+16-6) 
- (modified) clang/unittests/Format/TokenAnnotatorTest.cpp (+13) 


``diff
diff --git a/clang/lib/Format/FormatToken.h b/clang/lib/Format/FormatToken.h
index 5877b0a6124742a..527f1d744a58089 100644
--- a/clang/lib/Format/FormatToken.h
+++ b/clang/lib/Format/FormatToken.h
@@ -42,6 +42,7 @@ namespace format {
   TYPE(CaseLabelColon) 
\
   TYPE(CastRParen) 
\
   TYPE(ClassLBrace)
\
+  TYPE(ClassRBrace)
\
   /* ternary ?: expression */  
\
   TYPE(ConditionalExpr)
\
   /* the condition in an if statement */   
\
@@ -67,6 +68,7 @@ namespace format {
   TYPE(DictLiteral)
\
   TYPE(ElseLBrace) 
\
   TYPE(EnumLBrace) 
\
+  TYPE(EnumRBrace) 
\
   TYPE(FatArrow)   
\
   TYPE(ForEachMacro)   
\
   TYPE(FunctionAnnotationRParen)   
\
@@ -125,6 +127,7 @@ namespace format {
   TYPE(PureVirtualSpecifier)   
\
   TYPE(RangeBasedForLoopColon) 
\
   TYPE(RecordLBrace)   
\
+  TYPE(RecordRBrace)   
\
   TYPE(RegexLiteral)   
\
   TYPE(RequiresClause) 
\
   TYPE(RequiresClauseInARequiresExpression)
\
@@ -141,6 +144,7 @@ namespace format {
* braces need to be added to split it. Not used for other languages. */ 
\
   TYPE(StringInConcatenation)  
\
   TYPE(StructLBrace)   
\
+  TYPE(StructRBrace)   
\
   TYPE(StructuredBindingLSquare)   
\
   TYPE(TemplateCloser) 
\
   TYPE(TemplateOpener) 
\
@@ -153,6 +157,7 @@ namespace format {
   TYPE(TypenameMacro)  
\
   TYPE(UnaryOperator)  
\
   TYPE(UnionLBrace)
\
+  TYPE(UnionRBrace)
\
   TYPE(UntouchableMacroFunc)   
\
   /* Like in 'assign x = 0, y = 1;' . */   
\
   TYPE(VerilogAssignComma) 
\
diff --git a/clang/lib/Format/UnwrappedLineParser.cpp 
b/clang/lib/Format/UnwrappedLineParser.cpp
index dda5fd077e590e5..3275d7b6a71aaa0 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -3713,6 +3713,10 @@ bool UnwrappedLineParser::parseEnum() {
   nextToken();
 addUnwrappedLine();
   }
+  if (auto Prev = FormatTok->getPreviousNonComment();
+  Prev && Prev->is(tok::r_brace)) {
+Prev->setFinalizedType(TT_EnumRBrace);
+  }
   return true;
 
   // There is no addUnwrappedLine() here so that we fall through to parsing a
@@ -3920,21 +3924,23 @@ void UnwrappedLineParser::parseRecord(bool ParseAsExpr) 
{
 } while (!eof());
   }
 
-  auto GetBraceType = [](const FormatToken ) {
+  auto GetBraceTypes =
+  [](const FormatToken ) -> std::pair {
 switch (RecordTok.Tok.getKind()) {
 case tok::kw_class:
-  return TT_ClassLBrace;
+  return {TT_ClassLBrace, TT_ClassRBrace};
 case tok::kw_struct:
-  return TT_StructLBrace;
+  return {TT_StructLBrace, TT_StructRBrace};
 case tok::kw_union:
-  return TT_UnionLBrace;
+  return {TT_UnionLBrace, TT_UnionRBrace};
 default:
   // 

[clang] Annotate enum r brace (PR #68535)

2023-10-08 Thread Björn Schäpers via cfe-commits

https://github.com/HazardyKnusperkeks created 
https://github.com/llvm/llvm-project/pull/68535

This review is only for the second commit.

Is there a way to build pull request upon each other?

From f8b65d778b81e2dccc6773303d4b17843078864c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Bj=C3=B6rn=20Sch=C3=A4pers?= 
Date: Sun, 8 Oct 2023 22:12:28 +0200
Subject: [PATCH 1/2] [clang-format][NFC] Annotate more r_braces

In preparation of #67906.
---
 clang/lib/Format/FormatToken.h|  4 
 clang/lib/Format/UnwrappedLineParser.cpp  | 18 --
 clang/unittests/Format/TokenAnnotatorTest.cpp | 12 
 3 files changed, 28 insertions(+), 6 deletions(-)

diff --git a/clang/lib/Format/FormatToken.h b/clang/lib/Format/FormatToken.h
index 5877b0a6124742a..092ad4126451bd7 100644
--- a/clang/lib/Format/FormatToken.h
+++ b/clang/lib/Format/FormatToken.h
@@ -42,6 +42,7 @@ namespace format {
   TYPE(CaseLabelColon) 
\
   TYPE(CastRParen) 
\
   TYPE(ClassLBrace)
\
+  TYPE(ClassRBrace)
\
   /* ternary ?: expression */  
\
   TYPE(ConditionalExpr)
\
   /* the condition in an if statement */   
\
@@ -125,6 +126,7 @@ namespace format {
   TYPE(PureVirtualSpecifier)   
\
   TYPE(RangeBasedForLoopColon) 
\
   TYPE(RecordLBrace)   
\
+  TYPE(RecordRBrace)   
\
   TYPE(RegexLiteral)   
\
   TYPE(RequiresClause) 
\
   TYPE(RequiresClauseInARequiresExpression)
\
@@ -141,6 +143,7 @@ namespace format {
* braces need to be added to split it. Not used for other languages. */ 
\
   TYPE(StringInConcatenation)  
\
   TYPE(StructLBrace)   
\
+  TYPE(StructRBrace)   
\
   TYPE(StructuredBindingLSquare)   
\
   TYPE(TemplateCloser) 
\
   TYPE(TemplateOpener) 
\
@@ -153,6 +156,7 @@ namespace format {
   TYPE(TypenameMacro)  
\
   TYPE(UnaryOperator)  
\
   TYPE(UnionLBrace)
\
+  TYPE(UnionRBrace)
\
   TYPE(UntouchableMacroFunc)   
\
   /* Like in 'assign x = 0, y = 1;' . */   
\
   TYPE(VerilogAssignComma) 
\
diff --git a/clang/lib/Format/UnwrappedLineParser.cpp 
b/clang/lib/Format/UnwrappedLineParser.cpp
index dda5fd077e590e5..399318e26b970ac 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -3920,21 +3920,23 @@ void UnwrappedLineParser::parseRecord(bool ParseAsExpr) 
{
 } while (!eof());
   }
 
-  auto GetBraceType = [](const FormatToken ) {
+  auto GetBraceTypes =
+  [](const FormatToken ) -> std::pair {
 switch (RecordTok.Tok.getKind()) {
 case tok::kw_class:
-  return TT_ClassLBrace;
+  return {TT_ClassLBrace, TT_ClassRBrace};
 case tok::kw_struct:
-  return TT_StructLBrace;
+  return {TT_StructLBrace, TT_StructRBrace};
 case tok::kw_union:
-  return TT_UnionLBrace;
+  return {TT_UnionLBrace, TT_UnionRBrace};
 default:
   // Useful for e.g. interface.
-  return TT_RecordLBrace;
+  return {TT_RecordLBrace, TT_RecordRBrace};
 }
   };
   if (FormatTok->is(tok::l_brace)) {
-FormatTok->setFinalizedType(GetBraceType(InitialToken));
+auto [OpenBraceType, ClosingBraceType] = GetBraceTypes(InitialToken);
+FormatTok->setFinalizedType(OpenBraceType);
 if (ParseAsExpr) {
   parseChildBlock();
 } else {
@@ -3944,6 +3946,10 @@ void UnwrappedLineParser::parseRecord(bool ParseAsExpr) {
   unsigned AddLevels = Style.IndentAccessModifiers ? 2u : 1u;
   parseBlock(/*MustBeDeclaration=*/true, AddLevels, /*MunchSemi=*/false);
 }
+if (auto Prev = FormatTok->getPreviousNonComment();
+Prev && Prev->is(tok::r_brace)) {
+