aboutsummaryrefslogtreecommitdiff
path: root/contrib/llvm-project/clang/lib/Format/Format.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/llvm-project/clang/lib/Format/Format.cpp')
-rw-r--r--contrib/llvm-project/clang/lib/Format/Format.cpp39
1 files changed, 22 insertions, 17 deletions
diff --git a/contrib/llvm-project/clang/lib/Format/Format.cpp b/contrib/llvm-project/clang/lib/Format/Format.cpp
index d13907faca43..2659fa2af1a7 100644
--- a/contrib/llvm-project/clang/lib/Format/Format.cpp
+++ b/contrib/llvm-project/clang/lib/Format/Format.cpp
@@ -1895,26 +1895,31 @@ private:
void removeBraces(SmallVectorImpl<AnnotatedLine *> &Lines,
tooling::Replacements &Result) {
const auto &SourceMgr = Env.getSourceManager();
+ bool EndsWithComment = false;
for (AnnotatedLine *Line : Lines) {
removeBraces(Line->Children, Result);
- if (!Line->Affected)
- continue;
- for (FormatToken *Token = Line->First; Token && !Token->Finalized;
- Token = Token->Next) {
- if (!Token->Optional)
- continue;
- assert(Token->isOneOf(tok::l_brace, tok::r_brace));
- assert(Token->Next || Token == Line->Last);
- const auto Start =
- Token == Line->Last ||
- (Token->Next->isOneOf(tok::kw_else, tok::comment) &&
- Token->Next->NewlinesBefore > 0)
- ? Token->WhitespaceRange.getBegin()
- : Token->Tok.getLocation();
- const auto Range =
- CharSourceRange::getCharRange(Start, Token->Tok.getEndLoc());
- cantFail(Result.add(tooling::Replacement(SourceMgr, Range, "")));
+ if (Line->Affected) {
+ for (FormatToken *Token = Line->First; Token && !Token->Finalized;
+ Token = Token->Next) {
+ if (!Token->Optional)
+ continue;
+ assert(Token->isOneOf(tok::l_brace, tok::r_brace));
+ assert(Token->Previous || Token == Line->First);
+ const FormatToken *Next = Token->Next;
+ assert(Next || Token == Line->Last);
+ const auto Start =
+ (!Token->Previous && EndsWithComment) ||
+ (Next && !(Next->isOneOf(tok::kw_else, tok::comment) &&
+ Next->NewlinesBefore > 0))
+ ? Token->Tok.getLocation()
+ : Token->WhitespaceRange.getBegin();
+ const auto Range =
+ CharSourceRange::getCharRange(Start, Token->Tok.getEndLoc());
+ cantFail(Result.add(tooling::Replacement(SourceMgr, Range, "")));
+ }
}
+ assert(Line->Last);
+ EndsWithComment = Line->Last->is(tok::comment);
}
}
};