aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Format
diff options
context:
space:
mode:
Diffstat (limited to 'clang/lib/Format')
-rw-r--r--clang/lib/Format/FormatToken.h2
-rw-r--r--clang/lib/Format/UnwrappedLineParser.cpp5
-rw-r--r--clang/lib/Format/WhitespaceManager.cpp11
3 files changed, 12 insertions, 6 deletions
diff --git a/clang/lib/Format/FormatToken.h b/clang/lib/Format/FormatToken.h
index 4e45478..6ce9249 100644
--- a/clang/lib/Format/FormatToken.h
+++ b/clang/lib/Format/FormatToken.h
@@ -102,7 +102,9 @@ namespace format {
TYPE(MacroBlockBegin) \
TYPE(MacroBlockEnd) \
TYPE(ModulePartitionColon) \
+ TYPE(NamespaceLBrace) \
TYPE(NamespaceMacro) \
+ TYPE(NamespaceRBrace) \
TYPE(NonNullAssertion) \
TYPE(NullCoalescingEqual) \
TYPE(NullCoalescingOperator) \
diff --git a/clang/lib/Format/UnwrappedLineParser.cpp b/clang/lib/Format/UnwrappedLineParser.cpp
index 5c6e7e2..22fa651 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -806,6 +806,9 @@ FormatToken *UnwrappedLineParser::parseBlock(
return IfLBrace;
}
+ if (FormatTok->is(tok::r_brace) && Tok->is(TT_NamespaceLBrace))
+ FormatTok->setFinalizedType(TT_NamespaceRBrace);
+
const bool IsFunctionRBrace =
FormatTok->is(tok::r_brace) && Tok->is(TT_FunctionLBrace);
@@ -2959,6 +2962,8 @@ void UnwrappedLineParser::parseNamespace() {
}
}
if (FormatTok->is(tok::l_brace)) {
+ FormatTok->setFinalizedType(TT_NamespaceLBrace);
+
if (ShouldBreakBeforeBrace(Style, InitialToken))
addUnwrappedLine();
diff --git a/clang/lib/Format/WhitespaceManager.cpp b/clang/lib/Format/WhitespaceManager.cpp
index 668ca38..61e59d0 100644
--- a/clang/lib/Format/WhitespaceManager.cpp
+++ b/clang/lib/Format/WhitespaceManager.cpp
@@ -1081,11 +1081,10 @@ void WhitespaceManager::alignTrailingComments() {
if (i + 1 != e && Changes[i + 1].ContinuesPPDirective)
ChangeMaxColumn -= 2;
- // If this comment follows an } in column 0, it probably documents the
- // closing of a namespace and we don't want to align it.
- bool FollowsRBraceInColumn0 = i > 0 && Changes[i].NewlinesBefore == 0 &&
- Changes[i - 1].Tok->is(tok::r_brace) &&
- Changes[i - 1].StartOfTokenColumn == 0;
+
+ // We don't want to align namespace end comments.
+ bool DontAlignThisComment = i > 0 && Changes[i].NewlinesBefore == 0 &&
+ Changes[i - 1].Tok->is(TT_NamespaceRBrace);
bool WasAlignedWithStartOfNextLine = false;
if (Changes[i].NewlinesBefore >= 1) { // A comment on its own line.
unsigned CommentColumn = SourceMgr.getSpellingColumnNumber(
@@ -1105,7 +1104,7 @@ void WhitespaceManager::alignTrailingComments() {
}
}
if (Style.AlignTrailingComments.Kind == FormatStyle::TCAS_Never ||
- FollowsRBraceInColumn0) {
+ DontAlignThisComment) {
alignTrailingComments(StartOfSequence, i, MinColumn);
MinColumn = ChangeMinColumn;
MaxColumn = ChangeMinColumn;