[clang] [clang-format][NFC] Simplify AlignMacroMatches (PR #164122)
via cfe-commits
cfe-commits at lists.llvm.org
Sat Oct 18 23:42:36 PDT 2025
================
@@ -665,22 +664,21 @@ void WhitespaceManager::alignConsecutiveMacros() {
// If token is a ")", skip over the parameter list, to the
// token that precedes the "("
- if (Current->is(tok::r_paren) && Current->MatchingParen) {
- Current = Current->MatchingParen->Previous;
- SpacesRequiredBefore = 0;
- }
-
- if (!Current || Current->isNot(tok::identifier))
- return false;
-
- if (!Current->Previous || Current->Previous->isNot(tok::pp_define))
+ if (const auto *MatchingParen = Current->MatchingParen;
+ Current->is(tok::r_paren) && MatchingParen) {
+ // For a macro function, 0 spaces are required between the
+ // identifier and the lparen that opens the parameter list.
+ if (MatchingParen->SpacesRequiredBefore > 0)
+ return false;
+ Current = MatchingParen->Previous;
+ } else if (Current->Next->SpacesRequiredBefore != 1) {
+ // For a simple macro, 1 space is required between the
+ // identifier and the first token of the defined value.
return false;
+ }
- // For a macro function, 0 spaces are required between the
- // identifier and the lparen that opens the parameter list.
- // For a simple macro, 1 space is required between the
- // identifier and the first token of the defined value.
- return Current->Next->SpacesRequiredBefore == SpacesRequiredBefore;
+ return Current && Current->is(tok::identifier) && Current->Previous &&
+ Current->Previous->is(tok::pp_define);
----------------
owenca wrote:
```suggestion
return Current->endsSequence(tok::identifier, tok::pp_define);
```
https://github.com/llvm/llvm-project/pull/164122
More information about the cfe-commits
mailing list