aboutsummaryrefslogtreecommitdiff
path: root/lib/AST/Type.cpp
diff options
context:
space:
mode:
authorJohn McCall <rjmccall@apple.com>2010-05-15 11:32:37 +0000
committerJohn McCall <rjmccall@apple.com>2010-05-15 11:32:37 +0000
commitc12c5bba6ceb6acd4e51e7a0fc03257da9cfd44e (patch)
treef6b386f56c0925da061036cb04ba79a0bff05d91 /lib/AST/Type.cpp
parentd86c477fb5d3fc34864afecbbb5443da9355e8fb (diff)
Substantially alter the design of the Objective C type AST by introducing
ObjCObjectType, which is basically just a pair of one of {primitive-id, primitive-Class, user-defined @class} with a list of protocols. An ObjCObjectPointerType is therefore just a pointer which always points to one of these types (possibly sugared). ObjCInterfaceType is now just a kind of ObjCObjectType which happens to not carry any protocols. Alter a rather large number of use sites to use ObjCObjectType instead of ObjCInterfaceType. Store an ObjCInterfaceType as a pointer on the decl rather than hashing them in a FoldingSet. Remove some number of methods that are no longer used, at least after this patch. By simplifying ObjCObjectPointerType, we are now able to easily remove and apply pointers to Objective-C types, which is crucial for a certain kind of ObjC++ metaprogramming common in WebKit. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@103870 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/AST/Type.cpp')
-rw-r--r--lib/AST/Type.cpp82
1 files changed, 36 insertions, 46 deletions
diff --git a/lib/AST/Type.cpp b/lib/AST/Type.cpp
index a5c3a209c8..5b484054b5 100644
--- a/lib/AST/Type.cpp
+++ b/lib/AST/Type.cpp
@@ -345,29 +345,36 @@ const RecordType *Type::getAsUnionType() const {
return 0;
}
-ObjCInterfaceType::ObjCInterfaceType(QualType Canonical,
- ObjCInterfaceDecl *D,
- ObjCProtocolDecl **Protos, unsigned NumP) :
- Type(ObjCInterface, Canonical, /*Dependent=*/false),
- Decl(D), NumProtocols(NumP)
-{
+void ObjCInterfaceType::Destroy(ASTContext& C) {
+ this->~ObjCInterfaceType();
+ C.Deallocate(this);
+}
+
+ObjCObjectType::ObjCObjectType(QualType Canonical, QualType Base,
+ ObjCProtocolDecl * const *Protocols,
+ unsigned NumProtocols)
+ : Type(ObjCObject, Canonical, false),
+ NumProtocols(NumProtocols),
+ BaseType(Base) {
+ assert(this->NumProtocols == NumProtocols &&
+ "bitfield overflow in protocol count");
if (NumProtocols)
- memcpy(reinterpret_cast<ObjCProtocolDecl**>(this + 1), Protos,
- NumProtocols * sizeof(*Protos));
+ memcpy(getProtocolStorage(), Protocols,
+ NumProtocols * sizeof(ObjCProtocolDecl*));
}
-void ObjCInterfaceType::Destroy(ASTContext& C) {
- this->~ObjCInterfaceType();
+void ObjCObjectTypeImpl::Destroy(ASTContext& C) {
+ this->~ObjCObjectTypeImpl();
C.Deallocate(this);
}
-const ObjCInterfaceType *Type::getAsObjCQualifiedInterfaceType() const {
- // There is no sugar for ObjCInterfaceType's, just return the canonical
+const ObjCObjectType *Type::getAsObjCQualifiedInterfaceType() const {
+ // There is no sugar for ObjCObjectType's, just return the canonical
// type pointer if it is the right class. There is no typedef information to
// return and these cannot be Address-space qualified.
- if (const ObjCInterfaceType *OIT = getAs<ObjCInterfaceType>())
- if (OIT->getNumProtocols())
- return OIT;
+ if (const ObjCObjectType *T = getAs<ObjCObjectType>())
+ if (T->getNumProtocols() && T->getInterface())
+ return T;
return 0;
}
@@ -375,17 +382,6 @@ bool Type::isObjCQualifiedInterfaceType() const {
return getAsObjCQualifiedInterfaceType() != 0;
}
-ObjCObjectPointerType::ObjCObjectPointerType(QualType Canonical, QualType T,
- ObjCProtocolDecl **Protos,
- unsigned NumP) :
- Type(ObjCObjectPointer, Canonical, /*Dependent=*/false),
- PointeeType(T), NumProtocols(NumP)
-{
- if (NumProtocols)
- memcpy(reinterpret_cast<ObjCProtocolDecl **>(this + 1), Protos,
- NumProtocols * sizeof(*Protos));
-}
-
void ObjCObjectPointerType::Destroy(ASTContext& C) {
this->~ObjCObjectPointerType();
C.Deallocate(this);
@@ -638,6 +634,8 @@ bool Type::isIncompleteType() const {
case IncompleteArray:
// An array of unknown size is an incomplete type (C99 6.2.5p22).
return true;
+ case ObjCObject:
+ return cast<ObjCObjectType>(this)->getBaseType()->isIncompleteType();
case ObjCInterface:
// ObjC interfaces are incomplete if they are @class, not @interface.
return cast<ObjCInterfaceType>(this)->getDecl()->isForwardDecl();
@@ -768,7 +766,8 @@ bool Type::isSpecifierType() const {
case Elaborated:
case DependentName:
case ObjCInterface:
- case ObjCObjectPointer:
+ case ObjCObject:
+ case ObjCObjectPointer: // FIXME: object pointers aren't really specifiers
return true;
default:
return false;
@@ -953,17 +952,8 @@ void FunctionProtoType::Profile(llvm::FoldingSetNodeID &ID) {
getExtInfo());
}
-void ObjCObjectPointerType::Profile(llvm::FoldingSetNodeID &ID,
- QualType OIT,
- ObjCProtocolDecl * const *protocols,
- unsigned NumProtocols) {
- ID.AddPointer(OIT.getAsOpaquePtr());
- for (unsigned i = 0; i != NumProtocols; i++)
- ID.AddPointer(protocols[i]);
-}
-
void ObjCObjectPointerType::Profile(llvm::FoldingSetNodeID &ID) {
- Profile(ID, getPointeeType(), qual_begin(), getNumProtocols());
+ Profile(ID, getPointeeType());
}
/// LookThroughTypedefs - Return the ultimate type this typedef corresponds to
@@ -1163,17 +1153,17 @@ QualType QualifierCollector::apply(const Type *T) const {
return Context->getQualifiedType(T, *this);
}
-void ObjCInterfaceType::Profile(llvm::FoldingSetNodeID &ID,
- const ObjCInterfaceDecl *Decl,
- ObjCProtocolDecl * const *protocols,
- unsigned NumProtocols) {
- ID.AddPointer(Decl);
+void ObjCObjectTypeImpl::Profile(llvm::FoldingSetNodeID &ID,
+ QualType BaseType,
+ ObjCProtocolDecl * const *Protocols,
+ unsigned NumProtocols) {
+ ID.AddPointer(BaseType.getAsOpaquePtr());
for (unsigned i = 0; i != NumProtocols; i++)
- ID.AddPointer(protocols[i]);
+ ID.AddPointer(Protocols[i]);
}
-void ObjCInterfaceType::Profile(llvm::FoldingSetNodeID &ID) {
- Profile(ID, getDecl(), qual_begin(), getNumProtocols());
+void ObjCObjectTypeImpl::Profile(llvm::FoldingSetNodeID &ID) {
+ Profile(ID, getBaseType(), qual_begin(), getNumProtocols());
}
Linkage Type::getLinkage() const {
@@ -1244,7 +1234,7 @@ Linkage FunctionProtoType::getLinkage() const {
return L;
}
-Linkage ObjCInterfaceType::getLinkage() const {
+Linkage ObjCObjectType::getLinkage() const {
return ExternalLinkage;
}