aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Format
diff options
context:
space:
mode:
authorOwen Pan <owenpiano@gmail.com>2023-11-10 01:13:17 -0800
committerOwen Pan <owenpiano@gmail.com>2023-11-10 01:23:05 -0800
commitcc75e520162ef651977d3f6d11b0d0b92dd2be07 (patch)
treebfebbe8e5d8a731077dda7740ab137a74a23023c /clang/lib/Format
parentd62f040418bd167d1ddd2b79c640a90c0c2ea353 (diff)
downloadllvm-cc75e520162ef651977d3f6d11b0d0b92dd2be07.zip
llvm-cc75e520162ef651977d3f6d11b0d0b92dd2be07.tar.gz
llvm-cc75e520162ef651977d3f6d11b0d0b92dd2be07.tar.bz2
[clang-format][NFC] Refactor isPointerOrReference
Diffstat (limited to 'clang/lib/Format')
-rw-r--r--clang/lib/Format/FormatToken.h4
-rw-r--r--clang/lib/Format/QualifierAlignmentFixer.cpp2
-rw-r--r--clang/lib/Format/TokenAnnotator.cpp31
-rw-r--r--clang/lib/Format/WhitespaceManager.cpp3
4 files changed, 20 insertions, 20 deletions
diff --git a/clang/lib/Format/FormatToken.h b/clang/lib/Format/FormatToken.h
index 87f6a76..14a3c21 100644
--- a/clang/lib/Format/FormatToken.h
+++ b/clang/lib/Format/FormatToken.h
@@ -692,6 +692,10 @@ public:
TT_LeadingJavaAnnotation);
}
+ bool isPointerOrReference() const {
+ return isOneOf(tok::star, tok::amp, tok::ampamp);
+ }
+
bool isUnaryOperator() const {
switch (Tok.getKind()) {
case tok::plus:
diff --git a/clang/lib/Format/QualifierAlignmentFixer.cpp b/clang/lib/Format/QualifierAlignmentFixer.cpp
index 7758653..7167e50 100644
--- a/clang/lib/Format/QualifierAlignmentFixer.cpp
+++ b/clang/lib/Format/QualifierAlignmentFixer.cpp
@@ -380,7 +380,7 @@ const FormatToken *LeftRightQualifierAlignmentFixer::analyzeLeft(
// For left qualifiers preceeded by nothing, a template declaration, or *,&,&&
// we only perform sorting.
- if (!TypeToken || TypeToken->isOneOf(tok::star, tok::amp, tok::ampamp) ||
+ if (!TypeToken || TypeToken->isPointerOrReference() ||
TypeToken->ClosesRequiresClause || TypeToken->ClosesTemplateDeclaration) {
// Don't sort past a non-configured qualifier token.
diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp
index 729e7e3..d648e44 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -405,7 +405,7 @@ private:
// void (^ObjCBlock)(void);
bool MightBeFunctionType = !Contexts[Contexts.size() - 2].IsExpression;
bool ProbablyFunctionType =
- CurrentToken->isOneOf(tok::star, tok::amp, tok::ampamp, tok::caret);
+ CurrentToken->isPointerOrReference() || CurrentToken->is(tok::caret);
bool HasMultipleLines = false;
bool HasMultipleParametersOnALine = false;
bool MightBeObjCForRangeLoop =
@@ -422,8 +422,7 @@ private:
FormatToken *PrevPrev = Prev->getPreviousNonComment();
FormatToken *Next = CurrentToken->Next;
if (PrevPrev && PrevPrev->is(tok::identifier) &&
- PrevPrev->isNot(TT_TypeName) &&
- Prev->isOneOf(tok::star, tok::amp, tok::ampamp) &&
+ PrevPrev->isNot(TT_TypeName) && Prev->isPointerOrReference() &&
CurrentToken->is(tok::identifier) && Next->isNot(tok::equal)) {
Prev->setType(TT_BinaryOperator);
LookForDecls = false;
@@ -460,10 +459,8 @@ private:
// auto my_lambda = MACRO((Type *type, int i) { .. body .. });
for (FormatToken *Tok = &OpeningParen; Tok != CurrentToken;
Tok = Tok->Next) {
- if (Tok->is(TT_BinaryOperator) &&
- Tok->isOneOf(tok::star, tok::amp, tok::ampamp)) {
+ if (Tok->is(TT_BinaryOperator) && Tok->isPointerOrReference())
Tok->setType(TT_PointerOrReference);
- }
}
}
@@ -1861,8 +1858,8 @@ private:
if (Previous->opensScope())
break;
if (Previous->isOneOf(TT_BinaryOperator, TT_UnaryOperator) &&
- Previous->isOneOf(tok::star, tok::amp, tok::ampamp) &&
- Previous->Previous && Previous->Previous->isNot(tok::equal)) {
+ Previous->isPointerOrReference() && Previous->Previous &&
+ Previous->Previous->isNot(tok::equal)) {
Previous->setType(TT_PointerOrReference);
}
}
@@ -2023,7 +2020,7 @@ private:
} else if (isDeductionGuide(Current)) {
// Deduction guides trailing arrow " A(...) -> A<T>;".
Current.setType(TT_TrailingReturnArrow);
- } else if (Current.isOneOf(tok::star, tok::amp, tok::ampamp)) {
+ } else if (Current.isPointerOrReference()) {
Current.setType(determineStarAmpUsage(
Current,
Contexts.back().CanBeExpression && Contexts.back().IsExpression,
@@ -3281,7 +3278,7 @@ static bool isFunctionDeclarationName(bool IsCpp, const FormatToken &Current,
continue;
}
if ((Next->isSimpleTypeSpecifier() || Next->is(tok::identifier)) &&
- Next->Next && Next->Next->isOneOf(tok::star, tok::amp, tok::ampamp)) {
+ Next->Next && Next->Next->isPointerOrReference()) {
// For operator void*(), operator char*(), operator Foo*().
Next = Next->Next;
continue;
@@ -3310,7 +3307,7 @@ static bool isFunctionDeclarationName(bool IsCpp, const FormatToken &Current,
assert(Previous->MatchingParen->is(TT_TypeDeclarationParen));
return true;
}
- if (!Previous->isOneOf(tok::star, tok::amp, tok::ampamp, TT_TemplateCloser))
+ if (!Previous->isPointerOrReference() && Previous->isNot(TT_TemplateCloser))
return false;
Next = skipOperatorName(Next);
} else {
@@ -3481,8 +3478,8 @@ void TokenAnnotator::calculateFormattingInformation(AnnotatedLine &Line) const {
continue;
auto *Next = Tok->Next;
const bool NextIsBinaryOperator =
- Next && Next->isOneOf(tok::star, tok::amp, tok::ampamp) &&
- Next->Next && Next->Next->is(tok::identifier);
+ Next && Next->isPointerOrReference() && Next->Next &&
+ Next->Next->is(tok::identifier);
if (!NextIsBinaryOperator)
continue;
Next->setType(TT_BinaryOperator);
@@ -4105,15 +4102,15 @@ bool TokenAnnotator::spaceRequiredBetween(const AnnotatedLine &Line,
}
// Ensure right pointer alignment with ellipsis e.g. int *...P
if (Left.is(tok::ellipsis) && Left.Previous &&
- Left.Previous->isOneOf(tok::star, tok::amp, tok::ampamp)) {
+ Left.Previous->isPointerOrReference()) {
return Style.PointerAlignment != FormatStyle::PAS_Right;
}
if (Right.is(tok::star) && Left.is(tok::l_paren))
return false;
- if (Left.is(tok::star) && Right.isOneOf(tok::star, tok::amp, tok::ampamp))
+ if (Left.is(tok::star) && Right.isPointerOrReference())
return false;
- if (Right.isOneOf(tok::star, tok::amp, tok::ampamp)) {
+ if (Right.isPointerOrReference()) {
const FormatToken *Previous = &Left;
while (Previous && Previous->isNot(tok::kw_operator)) {
if (Previous->is(tok::identifier) || Previous->isSimpleTypeSpecifier()) {
@@ -5258,7 +5255,7 @@ bool TokenAnnotator::mustBreakBefore(const AnnotatedLine &Line,
}
if (Style.BraceWrapping.BeforeLambdaBody && Right.is(TT_LambdaLBrace) &&
- Left.isOneOf(tok::star, tok::amp, tok::ampamp, TT_TemplateCloser)) {
+ (Left.isPointerOrReference() || Left.is(TT_TemplateCloser))) {
return true;
}
diff --git a/clang/lib/Format/WhitespaceManager.cpp b/clang/lib/Format/WhitespaceManager.cpp
index ff8b1e6..764a068 100644
--- a/clang/lib/Format/WhitespaceManager.cpp
+++ b/clang/lib/Format/WhitespaceManager.cpp
@@ -470,8 +470,7 @@ AlignTokenSequence(const FormatStyle &Style, unsigned Start, unsigned End,
Previous >= 0 &&
Changes[Previous].Tok->getType() == TT_PointerOrReference;
--Previous) {
- assert(
- Changes[Previous].Tok->isOneOf(tok::star, tok::amp, tok::ampamp));
+ assert(Changes[Previous].Tok->isPointerOrReference());
if (Changes[Previous].Tok->isNot(tok::star)) {
if (ReferenceNotRightAligned)
continue;