} while (!eof());
}
-void UnwrappedLineParser::calculateBraceTypes() {
+void UnwrappedLineParser::calculateBraceTypes(bool ExpectClassBody) {
// We'll parse forward through the tokens until we hit
// a closing brace or eof - note that getNextToken() will
// parse macros, so this will magically work inside macro
//
// We exclude + and - as they can be ObjC visibility modifiers.
ProbablyBracedList =
- NextTok->isOneOf(tok::comma, tok::semi, tok::period, tok::colon,
+ NextTok->isOneOf(tok::comma, tok::period, tok::colon,
tok::r_paren, tok::r_square, tok::l_brace,
tok::l_paren, tok::ellipsis) ||
+ (NextTok->is(tok::semi) && !ExpectClassBody) ||
(NextTok->isBinaryOperator() && !NextIsObjCMethod);
}
if (ProbablyBracedList) {
parseChildBlock();
}
-bool UnwrappedLineParser::tryToParseBracedList() {
+bool UnwrappedLineParser::tryToParseBracedList(bool ExpectClassBody) {
if (FormatTok->BlockKind == BK_Unknown)
- calculateBraceTypes();
+ calculateBraceTypes(ExpectClassBody);
assert(FormatTok->BlockKind != BK_Unknown);
if (FormatTok->BlockKind == BK_Block)
return false;
tryToParseLambda();
break;
case tok::l_brace:
- if (!tryToParseBracedList()) {
+ if (!tryToParseBracedList())
parseChildBlock();
- }
break;
case tok::at:
nextToken();
parseSquare();
break;
case tok::l_brace: {
- if (!tryToParseBracedList()) {
+ if (!tryToParseBracedList())
parseChildBlock();
- }
break;
}
case tok::at:
// and thus rule out the record production in case there is no template
// (this would still leave us with an ambiguity between template function
// and class declarations).
- if (FormatTok->Tok.is(tok::colon) || FormatTok->Tok.is(tok::less)) {
- while (!eof() && FormatTok->Tok.isNot(tok::l_brace)) {
+ if (FormatTok->isOneOf(tok::colon, tok::less)) {
+ while (!eof()) {
+ if (FormatTok->is(tok::l_brace) &&
+ !tryToParseBracedList(/*ExpectClassBody=*/true))
+ break;
if (FormatTok->Tok.is(tok::semi))
return;
nextToken();
void parsePPEndIf();
void parsePPUnknown();
void parseStructuralElement();
- bool tryToParseBracedList();
+ bool tryToParseBracedList(bool ExpectClassBody = false);
bool parseBracedList(bool ContinueOnSemicolons = false);
void parseParens();
void parseSquare();
void readToken();
void flushComments(bool NewlineBeforeNext);
void pushToken(FormatToken *Tok);
- void calculateBraceTypes();
+ void calculateBraceTypes(bool ExpectClassBody);
// Marks a conditional compilation edge (for example, an '#if', '#ifdef',
// '#else' or merge conflict marker). If 'Unreachable' is true, assumes