-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[clang-format][NFC] Simplify AlignMacroMatches #164122
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Just return early based on the SpacedRequiredBefore.
|
@llvm/pr-subscribers-clang-format Author: Björn Schäpers (HazardyKnusperkeks) ChangesJust return early based on the SpacedRequiredBefore. Full diff: https://github.com/llvm/llvm-project/pull/164122.diff 1 Files Affected:
diff --git a/clang/lib/Format/WhitespaceManager.cpp b/clang/lib/Format/WhitespaceManager.cpp
index 7348a3af8cf95..03a1e9a6bd80b 100644
--- a/clang/lib/Format/WhitespaceManager.cpp
+++ b/clang/lib/Format/WhitespaceManager.cpp
@@ -656,7 +656,6 @@ void WhitespaceManager::alignConsecutiveMacros() {
auto AlignMacrosMatches = [](const Change &C) {
const FormatToken *Current = C.Tok;
- unsigned SpacesRequiredBefore = 1;
if (Current->SpacesRequiredBefore == 0 || !Current->Previous)
return false;
@@ -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);
};
unsigned MinColumn = 0;
|
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/190/builds/29344 Here is the relevant piece of the build log for the reference |
Just return early based on the SpacedRequiredBefore.
Just return early based on the SpacedRequiredBefore.
Just return early based on the SpacedRequiredBefore.