forked from OSchip/llvm-project
Automatically munch semicolons after blocks.
While it is mostly a user error to have the extra semicolon, formatting it graciously will correctly format in the cases where we do not fully understand the code (macros). llvm-svn: 192543
This commit is contained in:
parent
0b48c738e6
commit
b212f3baa1
|
@ -360,7 +360,8 @@ void UnwrappedLineParser::calculateBraceTypes() {
|
|||
FormatTok = Tokens->setPosition(StoredPosition);
|
||||
}
|
||||
|
||||
void UnwrappedLineParser::parseBlock(bool MustBeDeclaration, bool AddLevel) {
|
||||
void UnwrappedLineParser::parseBlock(bool MustBeDeclaration, bool AddLevel,
|
||||
bool MunchSemi) {
|
||||
assert(FormatTok->Tok.is(tok::l_brace) && "'{' expected");
|
||||
unsigned InitialLevel = Line->Level;
|
||||
nextToken();
|
||||
|
@ -380,6 +381,8 @@ void UnwrappedLineParser::parseBlock(bool MustBeDeclaration, bool AddLevel) {
|
|||
}
|
||||
|
||||
nextToken(); // Munch the closing brace.
|
||||
if (MunchSemi && FormatTok->Tok.is(tok::semi))
|
||||
nextToken();
|
||||
Line->Level = InitialLevel;
|
||||
}
|
||||
|
||||
|
@ -1160,7 +1163,8 @@ void UnwrappedLineParser::parseRecord() {
|
|||
Style.BreakBeforeBraces == FormatStyle::BS_Allman)
|
||||
addUnwrappedLine();
|
||||
|
||||
parseBlock(/*MustBeDeclaration=*/true);
|
||||
parseBlock(/*MustBeDeclaration=*/true, /*Addlevel=*/true,
|
||||
/*MunchSemi=*/false);
|
||||
}
|
||||
// We fall through to parsing a structural element afterwards, so
|
||||
// class A {} n, m;
|
||||
|
|
|
@ -69,7 +69,8 @@ private:
|
|||
void reset();
|
||||
void parseFile();
|
||||
void parseLevel(bool HasOpeningBrace);
|
||||
void parseBlock(bool MustBeDeclaration, bool AddLevel = true);
|
||||
void parseBlock(bool MustBeDeclaration, bool AddLevel = true,
|
||||
bool MunchSemi = true);
|
||||
void parseChildBlock();
|
||||
void parsePPDirective();
|
||||
void parsePPDefine();
|
||||
|
|
|
@ -6854,5 +6854,12 @@ TEST_F(FormatTest, SupportsCRLF) {
|
|||
getGoogleStyle()));
|
||||
}
|
||||
|
||||
TEST_F(FormatTest, MunchSemicolonAfterBlocks) {
|
||||
verifyFormat("MY_CLASS(C) {\n"
|
||||
" int i;\n"
|
||||
" int j;\n"
|
||||
"};");
|
||||
}
|
||||
|
||||
} // end namespace tooling
|
||||
} // end namespace clang
|
||||
|
|
Loading…
Reference in New Issue