diff options
Diffstat (limited to 'clang/lib')
-rw-r--r-- | clang/lib/Format/UnwrappedLineParser.cpp | 24 |
1 files changed, 18 insertions, 6 deletions
diff --git a/clang/lib/Format/UnwrappedLineParser.cpp b/clang/lib/Format/UnwrappedLineParser.cpp index 9f355c930ea..7e55e04c7f7 100644 --- a/clang/lib/Format/UnwrappedLineParser.cpp +++ b/clang/lib/Format/UnwrappedLineParser.cpp @@ -434,6 +434,19 @@ static bool IsGoogScope(const UnwrappedLine &Line) { return I->Tok->is(tok::l_paren); } +static bool ShouldBreakBeforeBrace(const FormatStyle &Style, + const FormatToken &InitialToken) { + switch (Style.BreakBeforeBraces) { + case FormatStyle::BS_Linux: + return InitialToken.isOneOf(tok::kw_namespace, tok::kw_class); + case FormatStyle::BS_Allman: + case FormatStyle::BS_GNU: + return true; + default: + return false; + } +} + void UnwrappedLineParser::parseChildBlock() { FormatTok->BlockKind = BK_Block; nextToken(); @@ -1167,13 +1180,13 @@ void UnwrappedLineParser::parseTryCatch() { void UnwrappedLineParser::parseNamespace() { assert(FormatTok->Tok.is(tok::kw_namespace) && "'namespace' expected"); + + const FormatToken &InitialToken = *FormatTok; nextToken(); if (FormatTok->Tok.is(tok::identifier)) nextToken(); if (FormatTok->Tok.is(tok::l_brace)) { - if (Style.BreakBeforeBraces == FormatStyle::BS_Linux || - Style.BreakBeforeBraces == FormatStyle::BS_Allman || - Style.BreakBeforeBraces == FormatStyle::BS_GNU) + if (ShouldBreakBeforeBrace(Style, InitialToken)) addUnwrappedLine(); bool AddLevel = Style.NamespaceIndentation == FormatStyle::NI_All || @@ -1327,6 +1340,7 @@ void UnwrappedLineParser::parseEnum() { } void UnwrappedLineParser::parseRecord() { + const FormatToken &InitialToken = *FormatTok; nextToken(); if (FormatTok->isOneOf(tok::identifier, tok::coloncolon, tok::kw___attribute, tok::kw___declspec, tok::kw_alignas)) { @@ -1361,9 +1375,7 @@ void UnwrappedLineParser::parseRecord() { } } if (FormatTok->Tok.is(tok::l_brace)) { - if (Style.BreakBeforeBraces == FormatStyle::BS_Linux || - Style.BreakBeforeBraces == FormatStyle::BS_Allman || - Style.BreakBeforeBraces == FormatStyle::BS_GNU) + if (ShouldBreakBeforeBrace(Style, InitialToken)) addUnwrappedLine(); parseBlock(/*MustBeDeclaration=*/true, /*AddLevel=*/true, |