curdeius created this revision. curdeius added a reviewer: MyDeveloperDay. curdeius requested review of this revision. Herald added a project: clang. Herald added a subscriber: cfe-commits.
Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D115968 Files: clang/lib/Format/UnwrappedLineParser.cpp Index: clang/lib/Format/UnwrappedLineParser.cpp =================================================================== --- clang/lib/Format/UnwrappedLineParser.cpp +++ clang/lib/Format/UnwrappedLineParser.cpp @@ -2159,18 +2159,22 @@ } void UnwrappedLineParser::parseIfThenElse() { + auto HandleAttributes = [this]() { + // Handle AttributeMacro, e.g. `if (x) UNLIKELY`. + if (FormatTok->is(TT_AttributeMacro)) + nextToken(); + // Handle [[likely]] / [[unlikely]] attributes. + if (FormatTok->is(tok::l_square) && tryToParseSimpleAttribute()) + parseSquare(); + }; + assert(FormatTok->Tok.is(tok::kw_if) && "'if' expected"); nextToken(); if (FormatTok->Tok.isOneOf(tok::kw_constexpr, tok::identifier)) nextToken(); if (FormatTok->Tok.is(tok::l_paren)) parseParens(); - // handle AttributeMacro if (x) UNLIKELY - if (FormatTok->is(TT_AttributeMacro)) - nextToken(); - // handle [[likely]] / [[unlikely]] - if (FormatTok->is(tok::l_square) && tryToParseSimpleAttribute()) - parseSquare(); + HandleAttributes(); bool NeedsUnwrappedLine = false; if (FormatTok->Tok.is(tok::l_brace)) { CompoundStatementIndenter Indenter(this, Style, Line->Level); @@ -2187,12 +2191,7 @@ } if (FormatTok->Tok.is(tok::kw_else)) { nextToken(); - // handle AttributeMacro else UNLIKELY - if (FormatTok->is(TT_AttributeMacro)) - nextToken(); - // handle [[likely]] / [[unlikely]] - if (FormatTok->Tok.is(tok::l_square) && tryToParseSimpleAttribute()) - parseSquare(); + HandleAttributes(); if (FormatTok->Tok.is(tok::l_brace)) { CompoundStatementIndenter Indenter(this, Style, Line->Level); parseBlock();
Index: clang/lib/Format/UnwrappedLineParser.cpp =================================================================== --- clang/lib/Format/UnwrappedLineParser.cpp +++ clang/lib/Format/UnwrappedLineParser.cpp @@ -2159,18 +2159,22 @@ } void UnwrappedLineParser::parseIfThenElse() { + auto HandleAttributes = [this]() { + // Handle AttributeMacro, e.g. `if (x) UNLIKELY`. + if (FormatTok->is(TT_AttributeMacro)) + nextToken(); + // Handle [[likely]] / [[unlikely]] attributes. + if (FormatTok->is(tok::l_square) && tryToParseSimpleAttribute()) + parseSquare(); + }; + assert(FormatTok->Tok.is(tok::kw_if) && "'if' expected"); nextToken(); if (FormatTok->Tok.isOneOf(tok::kw_constexpr, tok::identifier)) nextToken(); if (FormatTok->Tok.is(tok::l_paren)) parseParens(); - // handle AttributeMacro if (x) UNLIKELY - if (FormatTok->is(TT_AttributeMacro)) - nextToken(); - // handle [[likely]] / [[unlikely]] - if (FormatTok->is(tok::l_square) && tryToParseSimpleAttribute()) - parseSquare(); + HandleAttributes(); bool NeedsUnwrappedLine = false; if (FormatTok->Tok.is(tok::l_brace)) { CompoundStatementIndenter Indenter(this, Style, Line->Level); @@ -2187,12 +2191,7 @@ } if (FormatTok->Tok.is(tok::kw_else)) { nextToken(); - // handle AttributeMacro else UNLIKELY - if (FormatTok->is(TT_AttributeMacro)) - nextToken(); - // handle [[likely]] / [[unlikely]] - if (FormatTok->Tok.is(tok::l_square) && tryToParseSimpleAttribute()) - parseSquare(); + HandleAttributes(); if (FormatTok->Tok.is(tok::l_brace)) { CompoundStatementIndenter Indenter(this, Style, Line->Level); parseBlock();
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits