[clang] 42ad305 - Modify the qualified/unqualified getter for TypeOfType; NFC
Aaron Ballman via cfe-commits
cfe-commits at lists.llvm.org
Tue Oct 4 09:14:58 PDT 2022
Author: Aaron Ballman
Date: 2022-10-04T12:14:38-04:00
New Revision: 42ad305bdbb87d567d4d365ec5ede8be4d2a4210
URL: https://github.com/llvm/llvm-project/commit/42ad305bdbb87d567d4d365ec5ede8be4d2a4210
DIFF: https://github.com/llvm/llvm-project/commit/42ad305bdbb87d567d4d365ec5ede8be4d2a4210.diff
LOG: Modify the qualified/unqualified getter for TypeOfType; NFC
Post-commit feedback observed that returning the TypeOfKind from the
type instead of a Boolean cleans up code using that interface.
Added:
Modified:
clang/include/clang/AST/Type.h
clang/include/clang/AST/TypeProperties.td
clang/lib/AST/ASTContext.cpp
clang/lib/AST/ASTImporter.cpp
clang/lib/AST/Type.cpp
clang/lib/AST/TypePrinter.cpp
clang/lib/Sema/TreeTransform.h
Removed:
################################################################################
diff --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h
index b7ef891f97d81..fbf65e588fb51 100644
--- a/clang/include/clang/AST/Type.h
+++ b/clang/include/clang/AST/Type.h
@@ -4608,8 +4608,11 @@ class TypeOfExprType : public Type {
public:
Expr *getUnderlyingExpr() const { return TOExpr; }
- /// Returns true if this is a typeof_unqual type.
- bool isUnqual() const { return TypeOfBits.IsUnqual; }
+ /// Returns the kind of 'typeof' type this is.
+ TypeOfKind getKind() const {
+ return TypeOfBits.IsUnqual ? TypeOfKind::Unqualified
+ : TypeOfKind::Qualified;
+ }
/// Remove a single level of sugar.
QualType desugar() const;
@@ -4635,7 +4638,8 @@ class DependentTypeOfExprType
: TypeOfExprType(E, Kind), Context(Context) {}
void Profile(llvm::FoldingSetNodeID &ID) {
- Profile(ID, Context, getUnderlyingExpr(), isUnqual());
+ Profile(ID, Context, getUnderlyingExpr(),
+ getKind() == TypeOfKind::Unqualified);
}
static void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context,
@@ -4664,14 +4668,17 @@ class TypeOfType : public Type {
/// Remove a single level of sugar.
QualType desugar() const {
QualType QT = getUnmodifiedType();
- return isUnqual() ? QT.getAtomicUnqualifiedType() : QT;
+ return TypeOfBits.IsUnqual ? QT.getAtomicUnqualifiedType() : QT;
}
/// Returns whether this type directly provides sugar.
bool isSugared() const { return true; }
- /// Returns true if this is a typeof_unqual type.
- bool isUnqual() const { return TypeOfBits.IsUnqual; }
+ /// Returns the kind of 'typeof' type this is.
+ TypeOfKind getKind() const {
+ return TypeOfBits.IsUnqual ? TypeOfKind::Unqualified
+ : TypeOfKind::Qualified;
+ }
static bool classof(const Type *T) { return T->getTypeClass() == TypeOf; }
};
diff --git a/clang/include/clang/AST/TypeProperties.td b/clang/include/clang/AST/TypeProperties.td
index 9634d2b961b18..ef7ed6eda3143 100644
--- a/clang/include/clang/AST/TypeProperties.td
+++ b/clang/include/clang/AST/TypeProperties.td
@@ -394,8 +394,7 @@ let Class = TypeOfExprType in {
}
def : Property<"kind", TypeOfKind> {
- let Read = [{ node->isUnqual() ? TypeOfKind::Unqualified
- : TypeOfKind::Qualified }];
+ let Read = [{ node->getKind() }];
}
def : Creator<[{
@@ -409,8 +408,7 @@ let Class = TypeOfType in {
}
def : Property<"kind", TypeOfKind> {
- let Read = [{ node->isUnqual() ? TypeOfKind::Unqualified
- : TypeOfKind::Qualified }];
+ let Read = [{ node->getKind() }];
}
def : Creator<[{
diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index fa7d5269e3f9e..d609fe8cbed09 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -12963,16 +12963,17 @@ static QualType getCommonSugarTypeNode(ASTContext &Ctx, const Type *X,
return QualType();
return Ctx.getTypedefType(CD, Ctx.getQualifiedType(Underlying));
}
- case Type::TypeOf:
+ case Type::TypeOf: {
// The common sugar between two typeof expressions, where one is
// potentially a typeof_unqual and the other is not, we unify to the
// qualified type as that retains the most information along with the type.
// We only return a typeof_unqual type when both types are unqual types.
- return Ctx.getTypeOfType(Ctx.getQualifiedType(Underlying),
- cast<TypeOfType>(X)->isUnqual() &&
- cast<TypeOfType>(Y)->isUnqual()
- ? TypeOfKind::Unqualified
- : TypeOfKind::Qualified);
+ TypeOfKind Kind = TypeOfKind::Qualified;
+ if (cast<TypeOfType>(X)->getKind() == cast<TypeOfType>(Y)->getKind() &&
+ cast<TypeOfType>(X)->getKind() == TypeOfKind::Unqualified)
+ Kind = TypeOfKind::Unqualified;
+ return Ctx.getTypeOfType(Ctx.getQualifiedType(Underlying), Kind);
+ }
case Type::TypeOfExpr:
return QualType();
diff --git a/clang/lib/AST/ASTImporter.cpp b/clang/lib/AST/ASTImporter.cpp
index 63b258c284c71..988fa6349a03e 100644
--- a/clang/lib/AST/ASTImporter.cpp
+++ b/clang/lib/AST/ASTImporter.cpp
@@ -1374,9 +1374,7 @@ ExpectedType ASTNodeImporter::VisitTypeOfExprType(const TypeOfExprType *T) {
ExpectedExpr ToExprOrErr = import(T->getUnderlyingExpr());
if (!ToExprOrErr)
return ToExprOrErr.takeError();
- return Importer.getToContext().getTypeOfExprType(
- *ToExprOrErr,
- T->isUnqual() ? TypeOfKind::Unqualified : TypeOfKind::Qualified);
+ return Importer.getToContext().getTypeOfExprType(*ToExprOrErr, T->getKind());
}
ExpectedType ASTNodeImporter::VisitTypeOfType(const TypeOfType *T) {
@@ -1384,7 +1382,7 @@ ExpectedType ASTNodeImporter::VisitTypeOfType(const TypeOfType *T) {
if (!ToUnderlyingTypeOrErr)
return ToUnderlyingTypeOrErr.takeError();
return Importer.getToContext().getTypeOfType(*ToUnderlyingTypeOrErr,
- T->isUnqual() ? TypeOfKind::Unqualified : TypeOfKind::Qualified);
+ T->getKind());
}
ExpectedType ASTNodeImporter::VisitUsingType(const UsingType *T) {
diff --git a/clang/lib/AST/Type.cpp b/clang/lib/AST/Type.cpp
index ccad2f37e6b87..bd5fe3dda304d 100644
--- a/clang/lib/AST/Type.cpp
+++ b/clang/lib/AST/Type.cpp
@@ -3499,7 +3499,7 @@ bool TypeOfExprType::isSugared() const {
QualType TypeOfExprType::desugar() const {
if (isSugared()) {
QualType QT = getUnderlyingExpr()->getType();
- return isUnqual() ? QT.getAtomicUnqualifiedType() : QT;
+ return TypeOfBits.IsUnqual ? QT.getAtomicUnqualifiedType() : QT;
}
return QualType(this, 0);
}
diff --git a/clang/lib/AST/TypePrinter.cpp b/clang/lib/AST/TypePrinter.cpp
index c033b354f389a..8b0159bf0255a 100644
--- a/clang/lib/AST/TypePrinter.cpp
+++ b/clang/lib/AST/TypePrinter.cpp
@@ -1110,7 +1110,8 @@ void TypePrinter::printTypedefAfter(const TypedefType *T, raw_ostream &OS) {}
void TypePrinter::printTypeOfExprBefore(const TypeOfExprType *T,
raw_ostream &OS) {
- OS << (T->isUnqual() ? "typeof_unqual " : "typeof ");
+ OS << (T->getKind() == TypeOfKind::Unqualified ? "typeof_unqual "
+ : "typeof ");
if (T->getUnderlyingExpr())
T->getUnderlyingExpr()->printPretty(OS, nullptr, Policy);
spaceBeforePlaceHolder(OS);
@@ -1120,7 +1121,8 @@ void TypePrinter::printTypeOfExprAfter(const TypeOfExprType *T,
raw_ostream &OS) {}
void TypePrinter::printTypeOfBefore(const TypeOfType *T, raw_ostream &OS) {
- OS << (T->isUnqual() ? "typeof_unqual(" : "typeof(");
+ OS << (T->getKind() == TypeOfKind::Unqualified ? "typeof_unqual("
+ : "typeof(");
print(T->getUnmodifiedType(), OS, StringRef());
OS << ')';
spaceBeforePlaceHolder(OS);
diff --git a/clang/lib/Sema/TreeTransform.h b/clang/lib/Sema/TreeTransform.h
index 0ae3c77859668..eb7be2c6118fa 100644
--- a/clang/lib/Sema/TreeTransform.h
+++ b/clang/lib/Sema/TreeTransform.h
@@ -6200,12 +6200,10 @@ QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
return QualType();
QualType Result = TL.getType();
- bool IsUnqual = Result->getAs<TypeOfExprType>()->isUnqual();
- if (getDerived().AlwaysRebuild() ||
- E.get() != TL.getUnderlyingExpr()) {
- Result = getDerived().RebuildTypeOfExprType(
- E.get(), TL.getTypeofLoc(),
- IsUnqual ? TypeOfKind::Unqualified : TypeOfKind::Qualified);
+ TypeOfKind Kind = Result->getAs<TypeOfExprType>()->getKind();
+ if (getDerived().AlwaysRebuild() || E.get() != TL.getUnderlyingExpr()) {
+ Result =
+ getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc(), Kind);
if (Result.isNull())
return QualType();
}
@@ -6227,11 +6225,9 @@ QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
return QualType();
QualType Result = TL.getType();
- bool IsUnqual = Result->getAs<TypeOfType>()->isUnqual();
+ TypeOfKind Kind = Result->getAs<TypeOfType>()->getKind();
if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
- Result = getDerived().RebuildTypeOfType(New_Under_TI->getType(),
- IsUnqual ? TypeOfKind::Unqualified
- : TypeOfKind::Qualified);
+ Result = getDerived().RebuildTypeOfType(New_Under_TI->getType(), Kind);
if (Result.isNull())
return QualType();
}
More information about the cfe-commits
mailing list