Skip to content

Commit bec23db

Browse files
HazardyKnusperkeksaokblast
authored andcommitted
[clang-format][NFC] Simplify AlignMacroMatches (llvm#164122)
Just return early based on the SpacedRequiredBefore.
1 parent 149e2f2 commit bec23db

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

clang/lib/Format/WhitespaceManager.cpp

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -663,7 +663,7 @@ void WhitespaceManager::alignConsecutiveMacros() {
663663

664664
auto AlignMacrosMatches = [](const Change &C) {
665665
const FormatToken *Current = C.Tok;
666-
unsigned SpacesRequiredBefore = 1;
666+
assert(Current);
667667

668668
if (Current->SpacesRequiredBefore == 0 || !Current->Previous)
669669
return false;
@@ -672,22 +672,22 @@ void WhitespaceManager::alignConsecutiveMacros() {
672672

673673
// If token is a ")", skip over the parameter list, to the
674674
// token that precedes the "("
675-
if (Current->is(tok::r_paren) && Current->MatchingParen) {
676-
Current = Current->MatchingParen->Previous;
677-
SpacesRequiredBefore = 0;
678-
}
679-
680-
if (!Current || Current->isNot(tok::identifier))
681-
return false;
682-
683-
if (!Current->Previous || Current->Previous->isNot(tok::pp_define))
675+
if (Current->is(tok::r_paren)) {
676+
const auto *MatchingParen = Current->MatchingParen;
677+
// For a macro function, 0 spaces are required between the
678+
// identifier and the lparen that opens the parameter list.
679+
if (!MatchingParen || MatchingParen->SpacesRequiredBefore > 0 ||
680+
!MatchingParen->Previous) {
681+
return false;
682+
}
683+
Current = MatchingParen->Previous;
684+
} else if (Current->Next->SpacesRequiredBefore != 1) {
685+
// For a simple macro, 1 space is required between the
686+
// identifier and the first token of the defined value.
684687
return false;
688+
}
685689

686-
// For a macro function, 0 spaces are required between the
687-
// identifier and the lparen that opens the parameter list.
688-
// For a simple macro, 1 space is required between the
689-
// identifier and the first token of the defined value.
690-
return Current->Next->SpacesRequiredBefore == SpacesRequiredBefore;
690+
return Current->endsSequence(tok::identifier, tok::pp_define);
691691
};
692692

693693
AlignTokens<decltype(AlignMacrosMatches) &, /*SimpleCheck=*/true>(

0 commit comments

Comments
 (0)