This revision was automatically updated to reflect the committed changes. Closed by commit rG2cdabc032292: [clang-format] Handle "if consteval { ... }" for RemoveBracesLLVM (authored by owenpan).
Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D125593/new/ https://reviews.llvm.org/D125593 Files: clang/lib/Format/UnwrappedLineParser.cpp clang/unittests/Format/FormatTest.cpp Index: clang/unittests/Format/FormatTest.cpp =================================================================== --- clang/unittests/Format/FormatTest.cpp +++ clang/unittests/Format/FormatTest.cpp @@ -25379,6 +25379,25 @@ "}", Style); + verifyFormat("if consteval {\n" + " f();\n" + "} else {\n" + " g();\n" + "}", + Style); + + verifyFormat("if not consteval {\n" + " f();\n" + "} else if (a) {\n" + " g();\n" + "}", + Style); + + verifyFormat("if !consteval {\n" + " g();\n" + "}", + Style); + Style.ColumnLimit = 65; verifyFormat("if (condition) {\n" Index: clang/lib/Format/UnwrappedLineParser.cpp =================================================================== --- clang/lib/Format/UnwrappedLineParser.cpp +++ clang/lib/Format/UnwrappedLineParser.cpp @@ -2473,7 +2473,12 @@ nextToken(); if (FormatTok->is(tok::exclaim)) nextToken(); + + bool KeepIfBraces = false; + bool KeepElseBraces = false; if (FormatTok->is(tok::kw_consteval)) { + KeepIfBraces = true; + KeepElseBraces = true; nextToken(); } else { if (FormatTok->isOneOf(tok::kw_constexpr, tok::identifier)) @@ -2501,10 +2506,10 @@ parseUnbracedBody(); } - bool KeepIfBraces = false; if (Style.RemoveBracesLLVM) { assert(!NestedTooDeep.empty()); - KeepIfBraces = (IfLeftBrace && !IfLeftBrace->MatchingParen) || + KeepIfBraces = KeepIfBraces || + (IfLeftBrace && !IfLeftBrace->MatchingParen) || NestedTooDeep.back() || IfBlockKind == IfStmtKind::IfOnly || IfBlockKind == IfStmtKind::IfElseIf; } @@ -2558,8 +2563,9 @@ return nullptr; assert(!NestedTooDeep.empty()); - const bool KeepElseBraces = - (ElseLeftBrace && !ElseLeftBrace->MatchingParen) || NestedTooDeep.back(); + KeepElseBraces = KeepElseBraces || + (ElseLeftBrace && !ElseLeftBrace->MatchingParen) || + NestedTooDeep.back(); NestedTooDeep.pop_back();
Index: clang/unittests/Format/FormatTest.cpp =================================================================== --- clang/unittests/Format/FormatTest.cpp +++ clang/unittests/Format/FormatTest.cpp @@ -25379,6 +25379,25 @@ "}", Style); + verifyFormat("if consteval {\n" + " f();\n" + "} else {\n" + " g();\n" + "}", + Style); + + verifyFormat("if not consteval {\n" + " f();\n" + "} else if (a) {\n" + " g();\n" + "}", + Style); + + verifyFormat("if !consteval {\n" + " g();\n" + "}", + Style); + Style.ColumnLimit = 65; verifyFormat("if (condition) {\n" Index: clang/lib/Format/UnwrappedLineParser.cpp =================================================================== --- clang/lib/Format/UnwrappedLineParser.cpp +++ clang/lib/Format/UnwrappedLineParser.cpp @@ -2473,7 +2473,12 @@ nextToken(); if (FormatTok->is(tok::exclaim)) nextToken(); + + bool KeepIfBraces = false; + bool KeepElseBraces = false; if (FormatTok->is(tok::kw_consteval)) { + KeepIfBraces = true; + KeepElseBraces = true; nextToken(); } else { if (FormatTok->isOneOf(tok::kw_constexpr, tok::identifier)) @@ -2501,10 +2506,10 @@ parseUnbracedBody(); } - bool KeepIfBraces = false; if (Style.RemoveBracesLLVM) { assert(!NestedTooDeep.empty()); - KeepIfBraces = (IfLeftBrace && !IfLeftBrace->MatchingParen) || + KeepIfBraces = KeepIfBraces || + (IfLeftBrace && !IfLeftBrace->MatchingParen) || NestedTooDeep.back() || IfBlockKind == IfStmtKind::IfOnly || IfBlockKind == IfStmtKind::IfElseIf; } @@ -2558,8 +2563,9 @@ return nullptr; assert(!NestedTooDeep.empty()); - const bool KeepElseBraces = - (ElseLeftBrace && !ElseLeftBrace->MatchingParen) || NestedTooDeep.back(); + KeepElseBraces = KeepElseBraces || + (ElseLeftBrace && !ElseLeftBrace->MatchingParen) || + NestedTooDeep.back(); NestedTooDeep.pop_back();
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits