-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[clang-format] Split TT_AttributeParen #67396
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
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Replaced TT_AttributeParen with TT_AttributeLParen and TT_AttributeRParen.
32c0717
to
3ae6475
Compare
@llvm/pr-subscribers-clang-format ChangesReplaced TT_AttributeParen with TT_AttributeLParen and TT_AttributeRParen. Full diff: https://github.com/llvm/llvm-project/pull/67396.diff 4 Files Affected:
diff --git a/clang/lib/Format/ContinuationIndenter.cpp b/clang/lib/Format/ContinuationIndenter.cpp
index 68103c45b0b9463..bd7a2020589b88f 100644
--- a/clang/lib/Format/ContinuationIndenter.cpp
+++ b/clang/lib/Format/ContinuationIndenter.cpp
@@ -1336,7 +1336,7 @@ unsigned ContinuationIndenter::getNewLineColumn(const LineState &State) {
(PreviousNonComment->ClosesTemplateDeclaration ||
PreviousNonComment->ClosesRequiresClause ||
PreviousNonComment->isOneOf(
- TT_AttributeParen, TT_AttributeSquare, TT_FunctionAnnotationRParen,
+ TT_AttributeRParen, TT_AttributeSquare, TT_FunctionAnnotationRParen,
TT_JavaAnnotation, TT_LeadingJavaAnnotation))) ||
(!Style.IndentWrappedFunctionNames &&
NextNonComment->isOneOf(tok::kw_operator, TT_FunctionDeclarationName))) {
diff --git a/clang/lib/Format/FormatToken.h b/clang/lib/Format/FormatToken.h
index 0605ac9da7219f2..986849abd8f9206 100644
--- a/clang/lib/Format/FormatToken.h
+++ b/clang/lib/Format/FormatToken.h
@@ -30,8 +30,9 @@ namespace format {
TYPE(ArrayInitializerLSquare) \
TYPE(ArraySubscriptLSquare) \
TYPE(AttributeColon) \
+ TYPE(AttributeLParen) \
TYPE(AttributeMacro) \
- TYPE(AttributeParen) \
+ TYPE(AttributeRParen) \
TYPE(AttributeSquare) \
TYPE(BinaryOperator) \
TYPE(BitFieldColon) \
diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp
index 5becb86c0f37081..6f9332b47f2c3d0 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -377,7 +377,7 @@ class AnnotatingParser {
// detected one yet.
if (PrevNonComment && OpeningParen.is(TT_Unknown)) {
if (PrevNonComment->is(tok::kw___attribute)) {
- OpeningParen.setType(TT_AttributeParen);
+ OpeningParen.setType(TT_AttributeLParen);
} else if (PrevNonComment->isOneOf(TT_TypenameMacro, tok::kw_decltype,
tok::kw_typeof,
#define TRANSFORM_TYPE_TRAIT_DEF(_, Trait) tok::kw___##Trait,
@@ -475,8 +475,8 @@ class AnnotatingParser {
}
}
- if (OpeningParen.is(TT_AttributeParen))
- CurrentToken->setType(TT_AttributeParen);
+ if (OpeningParen.is(TT_AttributeLParen))
+ CurrentToken->setType(TT_AttributeRParen);
if (OpeningParen.is(TT_TypeDeclarationParen))
CurrentToken->setType(TT_TypeDeclarationParen);
if (OpeningParen.Previous &&
@@ -2382,11 +2382,15 @@ class AnnotatingParser {
// Strip trailing qualifiers such as const or volatile when checking
// whether the parens could be a cast to a pointer/reference type.
while (T) {
- if (T->is(TT_AttributeParen)) {
+ if (T->is(TT_AttributeRParen)) {
// Handle `x = (foo *__attribute__((foo)))&v;`:
- if (T->MatchingParen && T->MatchingParen->Previous &&
- T->MatchingParen->Previous->is(tok::kw___attribute)) {
- T = T->MatchingParen->Previous->Previous;
+ assert(T->is(tok::r_paren));
+ assert(T->MatchingParen);
+ assert(T->MatchingParen->is(tok::l_paren));
+ assert(T->MatchingParen->is(TT_AttributeLParen));
+ if (const auto *Tok = T->MatchingParen->Previous;
+ Tok && Tok->is(tok::kw___attribute)) {
+ T = Tok->Previous;
continue;
}
} else if (T->is(TT_AttributeSquare)) {
@@ -3989,7 +3993,7 @@ bool TokenAnnotator::spaceRequiredBetween(const AnnotatedLine &Line,
// after pointer qualifiers.
if ((Style.SpaceAroundPointerQualifiers == FormatStyle::SAPQ_After ||
Style.SpaceAroundPointerQualifiers == FormatStyle::SAPQ_Both) &&
- (Left.is(TT_AttributeParen) ||
+ (Left.is(TT_AttributeRParen) ||
Left.canBePointerOrReferenceQualifier())) {
return true;
}
@@ -4182,7 +4186,7 @@ bool TokenAnnotator::spaceRequiredBetween(const AnnotatedLine &Line,
return Style.SpaceBeforeParensOptions.AfterRequiresInExpression ||
spaceRequiredBeforeParens(Right);
}
- if ((Left.is(tok::r_paren) && Left.is(TT_AttributeParen)) ||
+ if (Left.is(TT_AttributeRParen) ||
(Left.is(tok::r_square) && Left.is(TT_AttributeSquare))) {
return true;
}
@@ -4361,7 +4365,7 @@ bool TokenAnnotator::spaceRequiredBefore(const AnnotatedLine &Line,
return false;
}
// Space in __attribute__((attr)) ::type.
- if (Left.is(TT_AttributeParen) && Right.is(tok::coloncolon))
+ if (Left.is(TT_AttributeRParen) && Right.is(tok::coloncolon))
return true;
if (Left.is(tok::kw_operator))
@@ -5190,7 +5194,7 @@ bool TokenAnnotator::mustBreakBefore(const AnnotatedLine &Line,
}
// Ensure wrapping after __attribute__((XX)) and @interface etc.
- if (Left.is(TT_AttributeParen) && Right.is(TT_ObjCDecl))
+ if (Left.is(TT_AttributeRParen) && Right.is(TT_ObjCDecl))
return true;
if (Left.is(TT_LambdaLBrace)) {
@@ -5552,8 +5556,8 @@ bool TokenAnnotator::canBreakBefore(const AnnotatedLine &Line,
!Style.Cpp11BracedListStyle) {
return false;
}
- if (Left.is(tok::l_paren) &&
- Left.isOneOf(TT_AttributeParen, TT_TypeDeclarationParen)) {
+ if (Left.is(TT_AttributeLParen) ||
+ (Left.is(tok::l_paren) && Left.is(TT_TypeDeclarationParen))) {
return false;
}
if (Left.is(tok::l_paren) && Left.Previous &&
diff --git a/clang/unittests/Format/TokenAnnotatorTest.cpp b/clang/unittests/Format/TokenAnnotatorTest.cpp
index 22698f6faf3cb1e..ab53d2691aa9516 100644
--- a/clang/unittests/Format/TokenAnnotatorTest.cpp
+++ b/clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -2065,6 +2065,15 @@ TEST_F(TokenAnnotatorTest, UnderstandsJavaScript) {
EXPECT_TOKEN(Tokens[11], tok::r_brace, TT_Unknown);
}
+TEST_F(TokenAnnotatorTest, UnderstandsAttributes) {
+ auto Tokens = annotate("bool foo __attribute__((unused));");
+ ASSERT_EQ(Tokens.size(), 10u) << Tokens;
+ EXPECT_TOKEN(Tokens[3], tok::l_paren, TT_AttributeLParen);
+ EXPECT_TOKEN(Tokens[4], tok::l_paren, TT_Unknown);
+ EXPECT_TOKEN(Tokens[6], tok::r_paren, TT_Unknown);
+ EXPECT_TOKEN(Tokens[7], tok::r_paren, TT_AttributeRParen);
+}
+
} // namespace
} // namespace format
} // namespace clang
|
HazardyKnusperkeks
approved these changes
Sep 26, 2023
legrosbuffle
pushed a commit
to legrosbuffle/llvm-project
that referenced
this pull request
Sep 29, 2023
Replaced TT_AttributeParen with TT_AttributeLParen and TT_AttributeRParen.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Replaced TT_AttributeParen with TT_AttributeLParen and TT_AttributeRParen.