[clang] b30c365 - [clang-format][NFC] Refactor UnwrappedLineParser::parseLabel (#207674)
via cfe-commits
cfe-commits at lists.llvm.org
Mon Jul 6 01:42:38 PDT 2026
Author: owenca
Date: 2026-07-06T01:42:33-07:00
New Revision: b30c365833b2d9d06c9de28551302acf524a2b04
URL: https://github.com/llvm/llvm-project/commit/b30c365833b2d9d06c9de28551302acf524a2b04
DIFF: https://github.com/llvm/llvm-project/commit/b30c365833b2d9d06c9de28551302acf524a2b04.diff
LOG: [clang-format][NFC] Refactor UnwrappedLineParser::parseLabel (#207674)
See
https://github.com/llvm/llvm-project/pull/196815#issuecomment-4470006692
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 0a211f5325e6f..c9913e0627a21 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -1773,7 +1773,7 @@ void UnwrappedLineParser::parseStructuralElement(
if (!Line->InMacroBody || CurrentLines->size() > 1)
Line->Tokens.begin()->Tok->MustBreakBefore = true;
FormatTok->setFinalizedType(TT_GotoLabelColon);
- parseLabel(Style.IndentGotoLabels);
+ parseLabel(/*IsGotoLabel=*/true);
if (HasLabel)
*HasLabel = true;
return;
@@ -3431,28 +3431,24 @@ void UnwrappedLineParser::parseDoWhile() {
parseStructuralElement();
}
-void UnwrappedLineParser::parseLabel(
- FormatStyle::IndentGotoLabelStyle IndentGotoLabels) {
- const bool IsGotoLabel = FormatTok->is(TT_GotoLabelColon);
+void UnwrappedLineParser::parseLabel(bool IsGotoLabel) {
nextToken();
- unsigned OldLineLevel = Line->Level;
- switch (IndentGotoLabels) {
- case FormatStyle::IGLS_NoIndent:
- Line->Level = 0;
- break;
- case FormatStyle::IGLS_OuterIndent:
- if (Line->Level > 1 || (!Line->InPPDirective && Line->Level > 0))
- --Line->Level;
- break;
- case FormatStyle::IGLS_HalfIndent:
- case FormatStyle::IGLS_InnerIndent:
- break;
+ const auto IndentGotoLabel = Style.IndentGotoLabels;
+ const auto OldLineLevel = Line->Level;
+ auto &Level = Line->Level;
+
+ if (IsGotoLabel && IndentGotoLabel == FormatStyle::IGLS_NoIndent)
+ Level = 0;
+
+ if (!IsGotoLabel || IndentGotoLabel == FormatStyle::IGLS_OuterIndent) {
+ if (OldLineLevel > 1 || (!Line->InPPDirective && OldLineLevel > 0))
+ --Level;
}
if (!IsGotoLabel && !Style.IndentCaseBlocks &&
CommentsBeforeNextToken.empty() && FormatTok->is(tok::l_brace)) {
- CompoundStatementIndenter Indenter(this, Line->Level,
+ CompoundStatementIndenter Indenter(this, Level,
Style.BraceWrapping.AfterCaseLabel,
Style.BraceWrapping.IndentBraces);
parseBlock();
@@ -3462,7 +3458,7 @@ void UnwrappedLineParser::parseLabel(
addUnwrappedLine();
if (!Style.IndentCaseBlocks &&
Style.BreakBeforeBraces == FormatStyle::BS_Whitesmiths) {
- ++Line->Level;
+ ++Level;
}
}
parseStructuralElement();
@@ -3473,7 +3469,9 @@ void UnwrappedLineParser::parseLabel(
nextToken();
addUnwrappedLine();
}
- Line->Level = OldLineLevel;
+
+ Level = OldLineLevel;
+
if (FormatTok->isNot(tok::l_brace)) {
parseStructuralElement();
addUnwrappedLine();
diff --git a/clang/lib/Format/UnwrappedLineParser.h b/clang/lib/Format/UnwrappedLineParser.h
index 22803a837cc63..8fa4e9f7540d5 100644
--- a/clang/lib/Format/UnwrappedLineParser.h
+++ b/clang/lib/Format/UnwrappedLineParser.h
@@ -162,8 +162,7 @@ class UnwrappedLineParser {
void parseLoopBody(bool KeepBraces, bool WrapRightBrace);
void parseForOrWhileLoop(bool HasParens = true);
void parseDoWhile();
- void parseLabel(FormatStyle::IndentGotoLabelStyle IndentGotoLabels =
- FormatStyle::IGLS_OuterIndent);
+ void parseLabel(bool IsGotoLabel = false);
void parseCaseLabel();
void parseSwitch(bool IsExpr);
void parseNamespace();
More information about the cfe-commits
mailing list