[clang] [clang-format] Refactor case and goto label parsing (PR #196815)
via cfe-commits
cfe-commits at lists.llvm.org
Sat May 16 00:22:22 PDT 2026
================
@@ -1714,9 +1714,32 @@ void UnwrappedLineParser::parseStructuralElement(
if (!Line->InMacroBody || CurrentLines->size() > 1)
Line->Tokens.begin()->Tok->MustBreakBefore = true;
FormatTok->setFinalizedType(TT_GotoLabelColon);
- parseLabel(Style.IndentGotoLabels);
+ const auto OldLineLevel = Line->Level;
+ switch (Style.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;
+ }
+ nextToken();
+ if (FormatTok->is(tok::semi))
+ nextToken();
+ addUnwrappedLine();
+ Line->Level = OldLineLevel;
if (HasLabel)
*HasLabel = true;
+
+ if (FormatTok->isNot(tok::l_brace)) {
+ // "Rerun" this function, this is e.g. for unbraced control statements.
+ parseStructuralElement();
+ addUnwrappedLine();
+ }
----------------
owenca wrote:
Ditto.
https://github.com/llvm/llvm-project/pull/196815
More information about the cfe-commits
mailing list