return lBuiltin->getKind() == rBuiltin->getKind();
}
+// FIXME: Devise a way to do this without using strcmp.
+bool Type::isObjcIdType() const {
+ if (const RecordType *RT = getAsStructureType())
+ return !strcmp(RT->getDecl()->getName(), "objc_object");
+ return false;
+}
+
+bool Type::objcTypesAreCompatible(QualType lhs, QualType rhs) {
+ if (lhs->isObjcInterfaceType() && rhs->isObjcIdType())
+ return true;
+ else if (lhs->isObjcIdType() && rhs->isObjcInterfaceType())
+ return true;
+ return false;
+}
+
bool Type::interfaceTypesAreCompatible(QualType lhs, QualType rhs) {
return true; // FIXME: IMPLEMENT.
}
return true;
// If the canonical type classes don't match, they can't be compatible
- if (lcanon->getTypeClass() != rcanon->getTypeClass())
+ if (lcanon->getTypeClass() != rcanon->getTypeClass()) {
+ // For Objective-C, it is possible for two types to be compatible
+ // when their classes don't match (when dealing with "id"). If either type
+ // is an interface, we defer to objcTypesAreCompatible().
+ if (lcanon->isObjcInterfaceType() || rcanon->isObjcInterfaceType())
+ return objcTypesAreCompatible(lcanon, rcanon);
return false;
-
+ }
switch (lcanon->getTypeClass()) {
case Type::Pointer:
return pointerTypesAreCompatible(lcanon, rcanon);
bool isVectorType() const; // GCC vector type.
bool isOCUVectorType() const; // OCU vector type.
bool isObjcInterfaceType() const; // includes conforming protocol type
+ bool isObjcIdType() const;
// Type Checking Functions: Check to see if this type is structurally the
// specified type, ignoring typedefs, and return a pointer to the best type
static bool arrayTypesAreCompatible(QualType, QualType); // C99 6.7.5.2p6
static bool builtinTypesAreCompatible(QualType, QualType);
static bool interfaceTypesAreCompatible(QualType, QualType);
+ static bool objcTypesAreCompatible(QualType, QualType);
private:
QualType getCanonicalTypeInternal() const { return CanonicalType; }
friend class QualType;