clean up some logic in objc type handling. Specifically, make it so that

there are QualType::getAsObjc* type methods, and make isa<ObjCInterfaceType>
return true for ObjCQualifiedInterfaceType's.

llvm-svn: 49300
This commit is contained in:
Chris Lattner 2008-04-07 00:27:04 +00:00
parent 87e484f08b
commit ba5862e74c
4 changed files with 79 additions and 27 deletions

View File

@ -353,23 +353,22 @@ public:
return T->getAsStructureType() == SelStructType;
}
//===--------------------------------------------------------------------===//
// Serialization
//===--------------------------------------------------------------------===//
void Emit(llvm::Serializer& S) const;
static ASTContext* Create(llvm::Deserializer& D);
private:
ASTContext(const ASTContext&); // DO NOT IMPLEMENT
void operator=(const ASTContext&); // DO NOT IMPLEMENT
void InitBuiltinTypes();
void InitBuiltinType(QualType &R, BuiltinType::Kind K);
/// helper function for Objective-C specific type checking.
bool interfaceTypesAreCompatible(QualType, QualType);
//===--------------------------------------------------------------------===//
// Serialization
//===--------------------------------------------------------------------===//
public:
void Emit(llvm::Serializer& S) const;
static ASTContext* Create(llvm::Deserializer& D);
};
} // end namespace clang

View File

@ -52,6 +52,8 @@ namespace clang {
class FunctionType;
class OCUVectorType;
class BuiltinType;
class ObjCInterfaceType;
class ObjCQualifiedIdType;
class ObjCQualifiedInterfaceType;
class StmtIteratorBase;
@ -153,9 +155,11 @@ public:
void dump(const char *s = 0) const;
//private:
/// getCanonicalType - Return the canonical version of this type, with the
/// appropriate type qualifiers on it.
inline QualType getCanonicalType() const;
public:
/// getAddressSpace - Return the address space of this type.
inline unsigned getAddressSpace() const;
@ -313,11 +317,12 @@ public:
bool isRecordType() const;
bool isStructureType() const;
bool isUnionType() const;
bool isComplexIntegerType() const; // GCC complex int type.
bool isVectorType() const; // GCC vector type.
bool isOCUVectorType() const; // OCU vector type.
bool isObjCInterfaceType() const; // includes conforming protocol type
bool isObjCQualifiedIdType() const; // id includes conforming protocol type
bool isComplexIntegerType() const; // GCC _Complex integer type.
bool isVectorType() const; // GCC vector type.
bool isOCUVectorType() const; // OCU vector type.
bool isObjCInterfaceType() const; // NSString or NSString<foo>
bool isObjCQualifiedInterfaceType() const; // NSString<foo>
bool isObjCQualifiedIdType() const; // id<foo>
// Type Checking Functions: Check to see if this type is structurally the
// specified type, ignoring typedefs and qualifiers, and return a pointer to
@ -338,6 +343,10 @@ public:
const ComplexType *getAsComplexType() const;
const ComplexType *getAsComplexIntegerType() const; // GCC complex int type.
const OCUVectorType *getAsOCUVectorType() const; // OCU vector type.
const ObjCInterfaceType *getAsObjCInterfaceType() const;
const ObjCQualifiedInterfaceType *getAsObjCQualifiedInterfaceType() const;
const ObjCQualifiedIdType *getAsObjCQualifiedIdType() const;
/// getDesugaredType - Return the specified type with any "sugar" removed from
/// type type. This takes off typedefs, typeof's etc. If the outer level of
@ -1060,7 +1069,8 @@ public:
virtual void getAsStringInternal(std::string &InnerString) const;
static bool classof(const Type *T) {
return T->getTypeClass() == ObjCInterface;
return T->getTypeClass() == ObjCInterface ||
T->getTypeClass() == ObjCQualifiedInterface;
}
static bool classof(const ObjCInterfaceType *) { return true; }
};
@ -1204,8 +1214,10 @@ inline bool Type::isOCUVectorType() const {
return isa<OCUVectorType>(CanonicalType.getUnqualifiedType());
}
inline bool Type::isObjCInterfaceType() const {
return isa<ObjCInterfaceType>(CanonicalType)
|| isa<ObjCQualifiedInterfaceType>(CanonicalType);
return isa<ObjCInterfaceType>(CanonicalType);
}
inline bool Type::isObjCQualifiedInterfaceType() const {
return isa<ObjCQualifiedInterfaceType>(CanonicalType);
}
inline bool Type::isObjCQualifiedIdType() const {
return isa<ObjCQualifiedIdType>(CanonicalType);

View File

@ -1427,17 +1427,18 @@ bool ASTContext::objcTypesAreCompatible(QualType lhs, QualType rhs) {
return true;
else if (isObjCIdType(lhs) && rhs->isObjCInterfaceType())
return true;
if (ObjCInterfaceType *lhsIT =
dyn_cast<ObjCInterfaceType>(lhs.getCanonicalType().getTypePtr())) {
ObjCQualifiedInterfaceType *rhsQI =
dyn_cast<ObjCQualifiedInterfaceType>(rhs.getCanonicalType().getTypePtr());
return rhsQI && (lhsIT->getDecl() == rhsQI->getDecl());
if (const ObjCInterfaceType *lhsIT = lhs->getAsObjCInterfaceType()) {
const ObjCQualifiedInterfaceType *rhsQI =
rhs->getAsObjCQualifiedInterfaceType();
if (!isa<ObjCQualifiedInterfaceType>(lhsIT))
return rhsQI && (lhsIT->getDecl() == rhsQI->getDecl());
}
else if (ObjCInterfaceType *rhsIT =
dyn_cast<ObjCInterfaceType>(rhs.getCanonicalType().getTypePtr())) {
ObjCQualifiedInterfaceType *lhsQI =
dyn_cast<ObjCQualifiedInterfaceType>(lhs.getCanonicalType().getTypePtr());
return lhsQI && (rhsIT->getDecl() == lhsQI->getDecl());
if (const ObjCInterfaceType *rhsIT = rhs->getAsObjCInterfaceType()) {
const ObjCQualifiedInterfaceType *lhsQI =
lhs->getAsObjCQualifiedInterfaceType();
if (!isa<ObjCQualifiedInterfaceType>(rhsIT))
return lhsQI && (rhsIT->getDecl() == lhsQI->getDecl());
}
return false;
}

View File

@ -428,6 +428,46 @@ const OCUVectorType *Type::getAsOCUVectorType() const {
return getDesugaredType()->getAsOCUVectorType();
}
const ObjCInterfaceType *Type::getAsObjCInterfaceType() const {
// Are we directly an ObjCInterface type?
if (const ObjCInterfaceType *VTy = dyn_cast<ObjCInterfaceType>(this))
return VTy;
// If the canonical form of this type isn't the right kind, reject it.
if (!isa<ObjCInterfaceType>(CanonicalType)) {
// Look through type qualifiers
if (isa<ObjCInterfaceType>(CanonicalType.getUnqualifiedType()))
return CanonicalType.getUnqualifiedType()->getAsObjCInterfaceType();
return 0;
}
// If this is a typedef for an objc interface type, strip the typedef off
// without losing all typedef information.
return getDesugaredType()->getAsObjCInterfaceType();
}
const ObjCQualifiedInterfaceType *
Type::getAsObjCQualifiedInterfaceType() const {
// Are we directly an ObjCQualifiedInterfaceType?
if (const ObjCQualifiedInterfaceType *VTy =
dyn_cast<ObjCQualifiedInterfaceType>(this))
return VTy;
// If the canonical form of this type isn't the right kind, reject it.
if (!isa<ObjCQualifiedInterfaceType>(CanonicalType)) {
// Look through type qualifiers
if (isa<ObjCQualifiedInterfaceType>(CanonicalType.getUnqualifiedType()))
return CanonicalType.getUnqualifiedType()->
getAsObjCQualifiedInterfaceType();
return 0;
}
// If this is a typedef for an objc qual interface type, strip the typedef off
// without losing all typedef information.
return getDesugaredType()->getAsObjCQualifiedInterfaceType();
}
bool Type::isIntegerType() const {
if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType))
return BT->getKind() >= BuiltinType::Bool &&