summaryrefslogtreecommitdiff
path: root/contrib/llvm/tools/clang/lib/Format/WhitespaceManager.cpp
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2019-01-20 14:02:54 +0000
committerDimitry Andric <dim@FreeBSD.org>2019-01-20 14:02:54 +0000
commitd5ea6fa648f8835a44adfb322b788e615d77cb71 (patch)
tree570aa90958a58b9d6a71fa8594ee0ad8d2a18f2c /contrib/llvm/tools/clang/lib/Format/WhitespaceManager.cpp
parentd9484dd61cc151c4f34c31e07f693fefa66316b5 (diff)
parent676fbe8105eeb6ff4bb2ed261cb212fcfdbe7b63 (diff)
Notes
Diffstat (limited to 'contrib/llvm/tools/clang/lib/Format/WhitespaceManager.cpp')
-rw-r--r--contrib/llvm/tools/clang/lib/Format/WhitespaceManager.cpp10
1 files changed, 8 insertions, 2 deletions
diff --git a/contrib/llvm/tools/clang/lib/Format/WhitespaceManager.cpp b/contrib/llvm/tools/clang/lib/Format/WhitespaceManager.cpp
index 7070ce03c864..032b1333322d 100644
--- a/contrib/llvm/tools/clang/lib/Format/WhitespaceManager.cpp
+++ b/contrib/llvm/tools/clang/lib/Format/WhitespaceManager.cpp
@@ -90,7 +90,7 @@ const tooling::Replacements &WhitespaceManager::generateReplacements() {
if (Changes.empty())
return Replaces;
- llvm::sort(Changes.begin(), Changes.end(), Change::IsBeforeInFile(SourceMgr));
+ llvm::sort(Changes, Change::IsBeforeInFile(SourceMgr));
calculateLineBreakInformation();
alignConsecutiveDeclarations();
alignConsecutiveAssignments();
@@ -255,8 +255,14 @@ AlignTokenSequence(unsigned Start, unsigned End, unsigned Column, F &&Matches,
Changes[ScopeStack.back()].indentAndNestingLevel())
ScopeStack.pop_back();
+ // Compare current token to previous non-comment token to ensure whether
+ // it is in a deeper scope or not.
+ unsigned PreviousNonComment = i - 1;
+ while (PreviousNonComment > Start &&
+ Changes[PreviousNonComment].Tok->is(tok::comment))
+ PreviousNonComment--;
if (i != Start && Changes[i].indentAndNestingLevel() >
- Changes[i - 1].indentAndNestingLevel())
+ Changes[PreviousNonComment].indentAndNestingLevel())
ScopeStack.push_back(i);
bool InsideNestedScope = ScopeStack.size() != 0;