[clang] a533b76 - [clang-format][NFC] Simplify parseBracedList() (#72010)
via cfe-commits
cfe-commits at lists.llvm.org
Sun Nov 12 15:55:09 PST 2023
Author: Owen Pan
Date: 2023-11-12T15:55:06-08:00
New Revision: a533b76468ac1df54e2e541b05ba4c060a77c603
URL: https://github.com/llvm/llvm-project/commit/a533b76468ac1df54e2e541b05ba4c060a77c603
DIFF: https://github.com/llvm/llvm-project/commit/a533b76468ac1df54e2e541b05ba4c060a77c603.diff
LOG: [clang-format][NFC] Simplify parseBracedList() (#72010)
Added:
Modified:
clang/lib/Format/UnwrappedLineParser.cpp
clang/lib/Format/UnwrappedLineParser.h
Removed:
################################################################################
diff --git a/clang/lib/Format/UnwrappedLineParser.cpp b/clang/lib/Format/UnwrappedLineParser.cpp
index 018bc6c165485e2..c870ff01605e725 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -2017,8 +2017,7 @@ void UnwrappedLineParser::parseStructuralElement(
} else if (Style.Language == FormatStyle::LK_Proto &&
FormatTok->is(tok::less)) {
nextToken();
- parseBracedList(/*ContinueOnSemicolons=*/false, /*IsEnum=*/false,
- /*ClosingBraceKind=*/tok::greater);
+ parseBracedList(/*IsAngleBracket=*/true);
}
break;
case tok::l_square:
@@ -2379,9 +2378,7 @@ bool UnwrappedLineParser::tryToParseChildBlock() {
return true;
}
-bool UnwrappedLineParser::parseBracedList(bool ContinueOnSemicolons,
- bool IsEnum,
- tok::TokenKind ClosingBraceKind) {
+bool UnwrappedLineParser::parseBracedList(bool IsAngleBracket, bool IsEnum) {
bool HasError = false;
// FIXME: Once we have an expression parser in the UnwrappedLineParser,
@@ -2403,7 +2400,7 @@ bool UnwrappedLineParser::parseBracedList(bool ContinueOnSemicolons,
parseChildBlock();
}
}
- if (FormatTok->Tok.getKind() == ClosingBraceKind) {
+ if (FormatTok->is(IsAngleBracket ? tok::greater : tok::r_brace)) {
if (IsEnum && !Style.AllowShortEnumsOnASingleLine)
addUnwrappedLine();
nextToken();
@@ -2434,14 +2431,9 @@ bool UnwrappedLineParser::parseBracedList(bool ContinueOnSemicolons,
parseBracedList();
break;
case tok::less:
- if (Style.Language == FormatStyle::LK_Proto ||
- ClosingBraceKind == tok::greater) {
- nextToken();
- parseBracedList(/*ContinueOnSemicolons=*/false, /*IsEnum=*/false,
- /*ClosingBraceKind=*/tok::greater);
- } else {
- nextToken();
- }
+ nextToken();
+ if (IsAngleBracket)
+ parseBracedList(/*IsAngleBracket=*/true);
break;
case tok::semi:
// JavaScript (or more precisely TypeScript) can have semicolons in braced
@@ -2453,8 +2445,8 @@ bool UnwrappedLineParser::parseBracedList(bool ContinueOnSemicolons,
break;
}
HasError = true;
- if (!ContinueOnSemicolons)
- return !HasError;
+ if (!IsEnum)
+ return false;
nextToken();
break;
case tok::comma:
@@ -3618,8 +3610,7 @@ void UnwrappedLineParser::parseConstraintExpression() {
return;
nextToken();
- parseBracedList(/*ContinueOnSemicolons=*/false, /*IsEnum=*/false,
- /*ClosingBraceKind=*/tok::greater);
+ parseBracedList(/*IsAngleBracket=*/true);
break;
default:
@@ -3650,8 +3641,7 @@ void UnwrappedLineParser::parseConstraintExpression() {
nextToken();
if (FormatTok->is(tok::less)) {
nextToken();
- parseBracedList(/*ContinueOnSemicolons=*/false, /*IsEnum=*/false,
- /*ClosingBraceKind=*/tok::greater);
+ parseBracedList(/*IsAngleBracket=*/true);
}
TopLevelParensAllowed = false;
break;
@@ -3732,8 +3722,7 @@ bool UnwrappedLineParser::parseEnum() {
addUnwrappedLine();
Line->Level += 1;
}
- bool HasError = !parseBracedList(/*ContinueOnSemicolons=*/true,
- /*IsEnum=*/true);
+ bool HasError = !parseBracedList(/*IsAngleBracket=*/false, /*IsEnum=*/true);
if (!Style.AllowShortEnumsOnASingleLine)
Line->Level -= 1;
if (HasError) {
diff --git a/clang/lib/Format/UnwrappedLineParser.h b/clang/lib/Format/UnwrappedLineParser.h
index 39294d14e57e574..739298690bbd765 100644
--- a/clang/lib/Format/UnwrappedLineParser.h
+++ b/clang/lib/Format/UnwrappedLineParser.h
@@ -150,8 +150,7 @@ class UnwrappedLineParser {
bool *HasDoWhile = nullptr,
bool *HasLabel = nullptr);
bool tryToParseBracedList();
- bool parseBracedList(bool ContinueOnSemicolons = false, bool IsEnum = false,
- tok::TokenKind ClosingBraceKind = tok::r_brace);
+ bool parseBracedList(bool IsAngleBracket = false, bool IsEnum = false);
bool parseParens(TokenType AmpAmpTokenType = TT_Unknown);
void parseSquare(bool LambdaIntroducer = false);
void keepAncestorBraces();
More information about the cfe-commits
mailing list