Changeset View
Changeset View
Standalone View
Standalone View
clang/lib/Format/WhitespaceManager.cpp
Show First 20 Lines • Show All 979 Lines • ▼ Show 20 Lines | for (unsigned i = 0, e = Changes.size(); i != e; ++i) { | ||||
// If we don't create a replacement for this change, we have to consider | // If we don't create a replacement for this change, we have to consider | ||||
// it to be immovable. | // it to be immovable. | ||||
if (!Changes[i].CreateReplacement) | if (!Changes[i].CreateReplacement) | ||||
ChangeMaxColumn = ChangeMinColumn; | ChangeMaxColumn = ChangeMinColumn; | ||||
if (i + 1 != e && Changes[i + 1].ContinuesPPDirective) | if (i + 1 != e && Changes[i + 1].ContinuesPPDirective) | ||||
ChangeMaxColumn -= 2; | 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. | // We don't want to align namespace end comments. | ||||
bool FollowsRBraceInColumn0 = i > 0 && Changes[i].NewlinesBefore == 0 && | bool DontAlignThisComment = | ||||
Changes[i - 1].Tok->is(tok::r_brace) && | i > 0 && Changes[i - 1].Tok->is(TT_NamespaceRBrace); | ||||
owenpan: Don't we still need to check `Changes[i].NewlinesBefore == 0`? How would this format the code… | |||||
HazardyKnusperkeksAuthorUnsubmitted Will check. HazardyKnusperkeks: Will check. | |||||
Changes[i - 1].StartOfTokenColumn == 0; | |||||
bool WasAlignedWithStartOfNextLine = false; | bool WasAlignedWithStartOfNextLine = false; | ||||
if (Changes[i].NewlinesBefore >= 1) { // A comment on its own line. | if (Changes[i].NewlinesBefore >= 1) { // A comment on its own line. | ||||
unsigned CommentColumn = SourceMgr.getSpellingColumnNumber( | unsigned CommentColumn = SourceMgr.getSpellingColumnNumber( | ||||
Changes[i].OriginalWhitespaceRange.getEnd()); | Changes[i].OriginalWhitespaceRange.getEnd()); | ||||
for (unsigned j = i + 1; j != e; ++j) { | for (unsigned j = i + 1; j != e; ++j) { | ||||
if (Changes[j].Tok->is(tok::comment)) | if (Changes[j].Tok->is(tok::comment)) | ||||
continue; | continue; | ||||
unsigned NextColumn = SourceMgr.getSpellingColumnNumber( | unsigned NextColumn = SourceMgr.getSpellingColumnNumber( | ||||
Changes[j].OriginalWhitespaceRange.getEnd()); | Changes[j].OriginalWhitespaceRange.getEnd()); | ||||
// The start of the next token was previously aligned with the | // The start of the next token was previously aligned with the | ||||
// start of this comment. | // start of this comment. | ||||
WasAlignedWithStartOfNextLine = | WasAlignedWithStartOfNextLine = | ||||
CommentColumn == NextColumn || | CommentColumn == NextColumn || | ||||
CommentColumn == NextColumn + Style.IndentWidth; | CommentColumn == NextColumn + Style.IndentWidth; | ||||
break; | break; | ||||
} | } | ||||
} | } | ||||
if (Style.AlignTrailingComments.Kind == FormatStyle::TCAS_Never || | if (Style.AlignTrailingComments.Kind == FormatStyle::TCAS_Never || | ||||
FollowsRBraceInColumn0) { | DontAlignThisComment) { | ||||
alignTrailingComments(StartOfSequence, i, MinColumn); | alignTrailingComments(StartOfSequence, i, MinColumn); | ||||
MinColumn = ChangeMinColumn; | MinColumn = ChangeMinColumn; | ||||
MaxColumn = ChangeMinColumn; | MaxColumn = ChangeMinColumn; | ||||
StartOfSequence = i; | StartOfSequence = i; | ||||
} else if (BreakBeforeNext || Newlines > NewLineThreshold || | } else if (BreakBeforeNext || Newlines > NewLineThreshold || | ||||
(ChangeMinColumn > MaxColumn || ChangeMaxColumn < MinColumn) || | (ChangeMinColumn > MaxColumn || ChangeMaxColumn < MinColumn) || | ||||
// Break the comment sequence if the previous line did not end | // Break the comment sequence if the previous line did not end | ||||
// in a trailing comment. | // in a trailing comment. | ||||
▲ Show 20 Lines • Show All 534 Lines • Show Last 20 Lines |
Don't we still need to check Changes[i].NewlinesBefore == 0? How would this format the code below with FixNamespaceComments: false?