6 changes: 2 additions & 4 deletions clang/lib/Format/UnwrappedLineFormatter.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,8 @@ class UnwrappedLineFormatter {
/// Format the current block and return the penalty.
unsigned format(const SmallVectorImpl<AnnotatedLine *> &Lines,
bool DryRun = false, int AdditionalIndent = 0,
bool FixBadIndentation = false,
unsigned FirstStartColumn = 0,
unsigned NextStartColumn = 0,
unsigned LastStartColumn = 0);
bool FixBadIndentation = false, unsigned FirstStartColumn = 0,
unsigned NextStartColumn = 0, unsigned LastStartColumn = 0);

private:
/// Add a new line and the required indent before the first Token
Expand Down
9 changes: 4 additions & 5 deletions clang/lib/Format/UnwrappedLineParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ void UnwrappedLineParser::calculateBraceTypes(bool ExpectClassBody) {
break;
case tok::identifier:
if (!Tok->is(TT_StatementMacro))
break;
break;
LLVM_FALLTHROUGH;
case tok::at:
case tok::semi:
Expand Down Expand Up @@ -1166,8 +1166,8 @@ void UnwrappedLineParser::parseStructuralElement() {
case tok::objc_synchronized:
nextToken();
if (FormatTok->Tok.is(tok::l_paren))
// Skip synchronization object
parseParens();
// Skip synchronization object
parseParens();
if (FormatTok->Tok.is(tok::l_brace)) {
if (Style.BraceWrapping.AfterControlStatement)
addUnwrappedLine();
Expand Down Expand Up @@ -2350,8 +2350,7 @@ void UnwrappedLineParser::parseJavaScriptEs6ImportExport() {
}
}

void UnwrappedLineParser::parseStatementMacro()
{
void UnwrappedLineParser::parseStatementMacro() {
nextToken();
if (FormatTok->is(tok::l_paren))
parseParens();
Expand Down
3 changes: 1 addition & 2 deletions clang/lib/Format/UnwrappedLineParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,7 @@ class UnwrappedLineParser {
public:
UnwrappedLineParser(const FormatStyle &Style,
const AdditionalKeywords &Keywords,
unsigned FirstStartColumn,
ArrayRef<FormatToken *> Tokens,
unsigned FirstStartColumn, ArrayRef<FormatToken *> Tokens,
UnwrappedLineConsumer &Callback);

void parse();
Expand Down
55 changes: 28 additions & 27 deletions clang/lib/Format/WhitespaceManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -432,19 +432,20 @@ void WhitespaceManager::alignConsecutiveAssignments() {
if (!Style.AlignConsecutiveAssignments)
return;

AlignTokens(Style,
[&](const Change &C) {
// Do not align on equal signs that are first on a line.
if (C.NewlinesBefore > 0)
return false;

// Do not align on equal signs that are last on a line.
if (&C != &Changes.back() && (&C + 1)->NewlinesBefore > 0)
return false;

return C.Tok->is(tok::equal);
},
Changes, /*StartAt=*/0);
AlignTokens(
Style,
[&](const Change &C) {
// Do not align on equal signs that are first on a line.
if (C.NewlinesBefore > 0)
return false;

// Do not align on equal signs that are last on a line.
if (&C != &Changes.back() && (&C + 1)->NewlinesBefore > 0)
return false;

return C.Tok->is(tok::equal);
},
Changes, /*StartAt=*/0);
}

void WhitespaceManager::alignConsecutiveDeclarations() {
Expand All @@ -457,15 +458,16 @@ void WhitespaceManager::alignConsecutiveDeclarations() {
// const char* const* v1;
// float const* v2;
// SomeVeryLongType const& v3;
AlignTokens(Style,
[](Change const &C) {
// tok::kw_operator is necessary for aligning operator overload
// definitions.
return C.Tok->is(TT_StartOfName) ||
C.Tok->is(TT_FunctionDeclarationName) ||
C.Tok->is(tok::kw_operator);
},
Changes, /*StartAt=*/0);
AlignTokens(
Style,
[](Change const &C) {
// tok::kw_operator is necessary for aligning operator overload
// definitions.
return C.Tok->is(TT_StartOfName) ||
C.Tok->is(TT_FunctionDeclarationName) ||
C.Tok->is(tok::kw_operator);
},
Changes, /*StartAt=*/0);
}

void WhitespaceManager::alignTrailingComments() {
Expand Down Expand Up @@ -541,11 +543,10 @@ void WhitespaceManager::alignTrailingComments() {
MinColumn = std::max(MinColumn, ChangeMinColumn);
MaxColumn = std::min(MaxColumn, ChangeMaxColumn);
}
BreakBeforeNext =
(i == 0) || (Changes[i].NewlinesBefore > 1) ||
// Never start a sequence with a comment at the beginning of
// the line.
(Changes[i].NewlinesBefore == 1 && StartOfSequence == i);
BreakBeforeNext = (i == 0) || (Changes[i].NewlinesBefore > 1) ||
// Never start a sequence with a comment at the beginning
// of the line.
(Changes[i].NewlinesBefore == 1 && StartOfSequence == i);
Newlines = 0;
}
alignTrailingComments(StartOfSequence, Changes.size(), MinColumn);
Expand Down