|
@@ -460,7 +460,7 @@ void UnwrappedLineParser::parseBlock(bool MustBeDeclaration, bool AddLevel,
|
|
|
FormatTok->BlockKind = BK_Block;
|
|
|
|
|
|
unsigned InitialLevel = Line->Level;
|
|
|
- nextToken();
|
|
|
+ nextToken(/*LevelDifference=*/AddLevel ? 1 : 0);
|
|
|
|
|
|
if (MacroBlock && FormatTok->is(tok::l_paren))
|
|
|
parseParens();
|
|
@@ -486,9 +486,8 @@ void UnwrappedLineParser::parseBlock(bool MustBeDeclaration, bool AddLevel,
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- flushComments(isOnNewLine(*FormatTok));
|
|
|
- Line->Level = InitialLevel;
|
|
|
- nextToken(); // Munch the closing brace.
|
|
|
+ // Munch the closing brace.
|
|
|
+ nextToken(/*LevelDifference=*/AddLevel ? -1 : 0);
|
|
|
|
|
|
if (MacroBlock && FormatTok->is(tok::l_paren))
|
|
|
parseParens();
|
|
@@ -496,6 +495,7 @@ void UnwrappedLineParser::parseBlock(bool MustBeDeclaration, bool AddLevel,
|
|
|
if (MunchSemi && FormatTok->Tok.is(tok::semi))
|
|
|
nextToken();
|
|
|
Line->MatchingOpeningBlockLineIndex = OpeningLineIndex;
|
|
|
+ Line->Level = InitialLevel;
|
|
|
if (OpeningLineIndex != UnwrappedLine::kInvalidIndex) {
|
|
|
// Update the opening line to add the forward reference as well
|
|
|
(*CurrentLines)[OpeningLineIndex].MatchingOpeningBlockLineIndex =
|
|
@@ -2288,13 +2288,13 @@ void UnwrappedLineParser::flushComments(bool NewlineBeforeNext) {
|
|
|
CommentsBeforeNextToken.clear();
|
|
|
}
|
|
|
|
|
|
-void UnwrappedLineParser::nextToken() {
|
|
|
+void UnwrappedLineParser::nextToken(int LevelDifference) {
|
|
|
if (eof())
|
|
|
return;
|
|
|
flushComments(isOnNewLine(*FormatTok));
|
|
|
pushToken(FormatTok);
|
|
|
if (Style.Language != FormatStyle::LK_JavaScript)
|
|
|
- readToken();
|
|
|
+ readToken(LevelDifference);
|
|
|
else
|
|
|
readTokenWithJavaScriptASI();
|
|
|
}
|
|
@@ -2363,7 +2363,7 @@ void UnwrappedLineParser::distributeComments(
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-void UnwrappedLineParser::readToken() {
|
|
|
+void UnwrappedLineParser::readToken(int LevelDifference) {
|
|
|
SmallVector<FormatToken *, 1> Comments;
|
|
|
do {
|
|
|
FormatTok = Tokens->getNextToken();
|
|
@@ -2376,6 +2376,10 @@ void UnwrappedLineParser::readToken() {
|
|
|
// directives only after that unwrapped line was finished later.
|
|
|
bool SwitchToPreprocessorLines = !Line->Tokens.empty();
|
|
|
ScopedLineState BlockState(*this, SwitchToPreprocessorLines);
|
|
|
+ assert((LevelDifference >= 0 ||
|
|
|
+ static_cast<unsigned>(-LevelDifference) <= Line->Level) &&
|
|
|
+ "LevelDifference makes Line->Level negative");
|
|
|
+ Line->Level += LevelDifference;
|
|
|
// Comments stored before the preprocessor directive need to be output
|
|
|
// before the preprocessor directive, at the same level as the
|
|
|
// preprocessor directive, as we consider them to apply to the directive.
|