Add Type::hasPointerRepresentation predicate.

- For types whose native representation is a pointer.

 - Use to replace ExprConstant.cpp:HasPointerEvalType,
   CodeGenFunction::isObjCPointerType.

llvm-svn: 65569
This commit is contained in:
Daniel Dunbar 2009-02-26 20:52:22 +00:00
parent 8b09ad17f9
commit 76ba41ce4f
5 changed files with 17 additions and 23 deletions

View File

@ -390,6 +390,12 @@ public:
bool isDependentType() const { return Dependent; } bool isDependentType() const { return Dependent; }
bool isOverloadType() const; // C++ overloaded function bool isOverloadType() const; // C++ overloaded function
/// hasPointerRepresentation - Whether this type is represented
/// natively as a pointer; this includes pointers, references, block
/// pointers, and Objective-C interface, qualified id, and qualified
/// interface types.
bool hasPointerRepresentation() const;
// Type Checking Functions: Check to see if this type is structurally the // Type Checking Functions: Check to see if this type is structurally the
// specified type, ignoring typedefs and qualifiers, and return a pointer to // specified type, ignoring typedefs and qualifiers, and return a pointer to
// the best type we can. // the best type we can.
@ -1936,6 +1942,12 @@ inline bool Type::isOverloadType() const {
return isSpecificBuiltinType(BuiltinType::Overload); return isSpecificBuiltinType(BuiltinType::Overload);
} }
inline bool Type::hasPointerRepresentation() const {
return (isPointerType() || isReferenceType() || isBlockPointerType() ||
isObjCInterfaceType() || isObjCQualifiedIdType() ||
isObjCQualifiedInterfaceType());
}
/// Insertion operator for diagnostics. This allows sending QualType's into a /// Insertion operator for diagnostics. This allows sending QualType's into a
/// diagnostic with <<. /// diagnostic with <<.
inline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB, inline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB,

View File

@ -279,14 +279,8 @@ public:
}; };
} // end anonymous namespace } // end anonymous namespace
static bool HasPointerEvalType(const Expr* E) {
return E->getType()->isPointerType()
|| E->getType()->isBlockPointerType()
|| E->getType()->isObjCQualifiedIdType();
}
static bool EvaluatePointer(const Expr* E, APValue& Result, EvalInfo &Info) { static bool EvaluatePointer(const Expr* E, APValue& Result, EvalInfo &Info) {
if (!HasPointerEvalType(E)) if (!E->getType()->hasPointerRepresentation())
return false; return false;
Result = PointerExprEvaluator(Info).Visit(const_cast<Expr*>(E)); Result = PointerExprEvaluator(Info).Visit(const_cast<Expr*>(E));
return Result.isLValue(); return Result.isLValue();
@ -1570,7 +1564,7 @@ bool Expr::Evaluate(EvalResult &Result, ASTContext &Ctx) const {
} else if (getType()->isIntegerType()) { } else if (getType()->isIntegerType()) {
if (!IntExprEvaluator(Info, Result.Val).Visit(const_cast<Expr*>(this))) if (!IntExprEvaluator(Info, Result.Val).Visit(const_cast<Expr*>(this)))
return false; return false;
} else if (HasPointerEvalType(this)) { } else if (getType()->hasPointerRepresentation()) {
if (!EvaluatePointer(this, Result.Val, Info)) if (!EvaluatePointer(this, Result.Val, Info))
return false; return false;
} else if (getType()->isRealFloatingType()) { } else if (getType()->isRealFloatingType()) {

View File

@ -525,9 +525,7 @@ void X86_64ABIInfo::classify(QualType Ty,
} else if (const EnumType *ET = Ty->getAsEnumType()) { } else if (const EnumType *ET = Ty->getAsEnumType()) {
// Classify the underlying integer type. // Classify the underlying integer type.
classify(ET->getDecl()->getIntegerType(), Context, OffsetBase, Lo, Hi); classify(ET->getDecl()->getIntegerType(), Context, OffsetBase, Lo, Hi);
} else if (Ty->isPointerType() || Ty->isReferenceType() || } else if (Ty->hasPointerRepresentation()) {
Ty->isBlockPointerType() || Ty->isObjCQualifiedIdType() ||
Ty->isObjCQualifiedInterfaceType()) {
Current = Integer; Current = Integer;
} else if (const VectorType *VT = Ty->getAsVectorType()) { } else if (const VectorType *VT = Ty->getAsVectorType()) {
uint64_t Size = Context.getTypeSize(VT); uint64_t Size = Context.getTypeSize(VT);

View File

@ -73,17 +73,11 @@ const llvm::Type *CodeGenFunction::ConvertType(QualType T) {
return CGM.getTypes().ConvertType(T); return CGM.getTypes().ConvertType(T);
} }
bool CodeGenFunction::isObjCPointerType(QualType T) {
// All Objective-C types are pointers.
return T->isObjCInterfaceType() ||
T->isObjCQualifiedInterfaceType() || T->isObjCQualifiedIdType();
}
bool CodeGenFunction::hasAggregateLLVMType(QualType T) { bool CodeGenFunction::hasAggregateLLVMType(QualType T) {
// FIXME: Use positive checks instead of negative ones to be more // FIXME: Use positive checks instead of negative ones to be more
// robust in the face of extension. // robust in the face of extension.
return !isObjCPointerType(T) &&!T->isRealType() && !T->isPointerType() && return !T->hasPointerRepresentation() &&!T->isRealType() &&
!T->isReferenceType() && !T->isVoidType() && !T->isVectorType() && !T->isFunctionType() && !T->isVoidType() && !T->isVectorType() && !T->isFunctionType() &&
!T->isBlockPointerType(); !T->isBlockPointerType();
} }

View File

@ -366,10 +366,6 @@ public:
/// TypeOfSelfObject - Return type of object that this self represents. /// TypeOfSelfObject - Return type of object that this self represents.
QualType TypeOfSelfObject(); QualType TypeOfSelfObject();
/// isObjCPointerType - Return true if the specificed AST type will map onto
/// some Objective-C pointer type.
static bool isObjCPointerType(QualType T);
/// hasAggregateLLVMType - Return true if the specified AST type will map into /// hasAggregateLLVMType - Return true if the specified AST type will map into
/// an aggregate LLVM type or is void. /// an aggregate LLVM type or is void.
static bool hasAggregateLLVMType(QualType T); static bool hasAggregateLLVMType(QualType T);