diff options
Diffstat (limited to 'clang/lib/AST')
-rw-r--r-- | clang/lib/AST/ASTContext.cpp | 52 | ||||
-rw-r--r-- | clang/lib/AST/Type.cpp | 80 |
2 files changed, 82 insertions, 50 deletions
diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp index 660b30a5e25..4af1599b94a 100644 --- a/clang/lib/AST/ASTContext.cpp +++ b/clang/lib/AST/ASTContext.cpp @@ -369,7 +369,7 @@ ASTContext::getTypeInfo(const Type *T) { // FIXME: Pointers into different addr spaces could have different sizes and // alignment requirements: getPointerInfo should take an AddrSpace. return getTypeInfo(QualType(cast<ExtQualType>(T)->getBaseType(), 0)); - case Type::ObjCQualifiedId: + case Type::ObjCObjectPointer: case Type::ObjCQualifiedInterface: Width = Target.getPointerWidth(0); Align = Target.getPointerAlign(0); @@ -1578,6 +1578,31 @@ static void SortAndUniqueProtocols(ObjCProtocolDecl **&Protocols, NumProtocols = ProtocolsEnd-Protocols; } +/// getObjCObjectPointerType - Return a ObjCObjectPointerType type for +/// the given interface decl and the conforming protocol list. +QualType ASTContext::getObjCObjectPointerType(ObjCInterfaceDecl *Decl, + ObjCProtocolDecl **Protocols, + unsigned NumProtocols) { + // Sort the protocol list alphabetically to canonicalize it. + if (NumProtocols) + SortAndUniqueProtocols(Protocols, NumProtocols); + + llvm::FoldingSetNodeID ID; + ObjCObjectPointerType::Profile(ID, Decl, Protocols, NumProtocols); + + void *InsertPos = 0; + if (ObjCObjectPointerType *QT = + ObjCObjectPointerTypes.FindNodeOrInsertPos(ID, InsertPos)) + return QualType(QT, 0); + + // No Match; + ObjCObjectPointerType *QType = + new (*this,8) ObjCObjectPointerType(Decl, Protocols, NumProtocols); + + Types.push_back(QType); + ObjCObjectPointerTypes.InsertNode(QType, InsertPos); + return QualType(QType, 0); +} /// getObjCQualifiedInterfaceType - Return a ObjCQualifiedInterfaceType type for /// the given interface decl and the conforming protocol list. @@ -1607,23 +1632,7 @@ QualType ASTContext::getObjCQualifiedInterfaceType(ObjCInterfaceDecl *Decl, /// and the conforming protocol list. QualType ASTContext::getObjCQualifiedIdType(ObjCProtocolDecl **Protocols, unsigned NumProtocols) { - // Sort the protocol list alphabetically to canonicalize it. - SortAndUniqueProtocols(Protocols, NumProtocols); - - llvm::FoldingSetNodeID ID; - ObjCQualifiedIdType::Profile(ID, Protocols, NumProtocols); - - void *InsertPos = 0; - if (ObjCQualifiedIdType *QT = - ObjCQualifiedIdTypes.FindNodeOrInsertPos(ID, InsertPos)) - return QualType(QT, 0); - - // No Match; - ObjCQualifiedIdType *QType = - new (*this,8) ObjCQualifiedIdType(Protocols, NumProtocols); - Types.push_back(QType); - ObjCQualifiedIdTypes.InsertNode(QType, InsertPos); - return QualType(QType, 0); + return getObjCObjectPointerType(0, Protocols, NumProtocols); } /// getTypeOfExprType - Unlike many "get<Type>" functions, we can't unique @@ -2413,9 +2422,9 @@ void ASTContext::getObjCEncodingForTypeImpl(QualType T, std::string& S, if (FD || EncodingProperty) { // Note that we do extended encoding of protocol qualifer list // Only when doing ivar or property encoding. - const ObjCQualifiedIdType *QIDT = T->getAsObjCQualifiedIdType(); + const ObjCObjectPointerType *QIDT = T->getAsObjCQualifiedIdType(); S += '"'; - for (ObjCQualifiedIdType::qual_iterator I = QIDT->qual_begin(), + for (ObjCObjectPointerType::qual_iterator I = QIDT->qual_begin(), E = QIDT->qual_end(); I != E; ++I) { S += '<'; S += (*I)->getNameAsString(); @@ -3298,7 +3307,8 @@ QualType ASTContext::mergeTypes(QualType LHS, QualType RHS) { return QualType(); } - case Type::ObjCQualifiedId: + case Type::ObjCObjectPointer: + // FIXME: finish // Distinct qualified id's are not compatible. return QualType(); case Type::FixedWidthInt: diff --git a/clang/lib/AST/Type.cpp b/clang/lib/AST/Type.cpp index 55a09522238..1db666fdaeb 100644 --- a/clang/lib/AST/Type.cpp +++ b/clang/lib/AST/Type.cpp @@ -562,6 +562,12 @@ const ObjCInterfaceType *Type::getAsObjCInterfaceType() const { return dyn_cast<ObjCInterfaceType>(CanonicalType.getUnqualifiedType()); } +const ObjCObjectPointerType *Type::getAsObjCObjectPointerType() const { + // There is no sugar for ObjCObjectPointerType's, just return the + // canonical type pointer if it is the right class. + return dyn_cast<ObjCObjectPointerType>(CanonicalType.getUnqualifiedType()); +} + const ObjCQualifiedInterfaceType * Type::getAsObjCQualifiedInterfaceType() const { // There is no sugar for ObjCQualifiedInterfaceType's, just return the @@ -569,10 +575,14 @@ Type::getAsObjCQualifiedInterfaceType() const { return dyn_cast<ObjCQualifiedInterfaceType>(CanonicalType.getUnqualifiedType()); } -const ObjCQualifiedIdType *Type::getAsObjCQualifiedIdType() const { +const ObjCObjectPointerType *Type::getAsObjCQualifiedIdType() const { // There is no sugar for ObjCQualifiedIdType's, just return the canonical // type pointer if it is the right class. - return dyn_cast<ObjCQualifiedIdType>(CanonicalType.getUnqualifiedType()); + if (const ObjCObjectPointerType *OPT = getAsObjCObjectPointerType()) { + if (OPT->isObjCQualifiedIdType()) + return OPT; + } + return 0; } const TemplateTypeParmType *Type::getAsTemplateTypeParmType() const { @@ -777,7 +787,7 @@ bool Type::isScalarType() const { isa<BlockPointerType>(CanonicalType) || isa<MemberPointerType>(CanonicalType) || isa<ComplexType>(CanonicalType) || - isa<ObjCQualifiedIdType>(CanonicalType); + isa<ObjCObjectPointerType>(CanonicalType); } /// \brief Determines whether the type is a C++ aggregate type or C @@ -864,7 +874,7 @@ bool Type::isPODType() const { case MemberPointer: case Vector: case ExtVector: - case ObjCQualifiedId: + case ObjCObjectPointer: return true; case Enum: @@ -919,7 +929,7 @@ bool Type::isSpecifierType() const { case Typename: case ObjCInterface: case ObjCQualifiedInterface: - case ObjCQualifiedId: + case ObjCObjectPointer: return true; default: return false; @@ -980,28 +990,30 @@ void FunctionProtoType::Profile(llvm::FoldingSetNodeID &ID) { getNumExceptions(), exception_begin()); } -void ObjCQualifiedInterfaceType::Profile(llvm::FoldingSetNodeID &ID, - const ObjCInterfaceDecl *Decl, - ObjCProtocolDecl **protocols, - unsigned NumProtocols) { +void ObjCObjectPointerType::Profile(llvm::FoldingSetNodeID &ID, + const ObjCInterfaceDecl *Decl, + ObjCProtocolDecl **protocols, + unsigned NumProtocols) { ID.AddPointer(Decl); for (unsigned i = 0; i != NumProtocols; i++) ID.AddPointer(protocols[i]); } -void ObjCQualifiedInterfaceType::Profile(llvm::FoldingSetNodeID &ID) { +void ObjCObjectPointerType::Profile(llvm::FoldingSetNodeID &ID) { Profile(ID, getDecl(), &Protocols[0], getNumProtocols()); } -void ObjCQualifiedIdType::Profile(llvm::FoldingSetNodeID &ID, - ObjCProtocolDecl **protocols, - unsigned NumProtocols) { +void ObjCQualifiedInterfaceType::Profile(llvm::FoldingSetNodeID &ID, + const ObjCInterfaceDecl *Decl, + ObjCProtocolDecl **protocols, + unsigned NumProtocols) { + ID.AddPointer(Decl); for (unsigned i = 0; i != NumProtocols; i++) ID.AddPointer(protocols[i]); } -void ObjCQualifiedIdType::Profile(llvm::FoldingSetNodeID &ID) { - Profile(ID, &Protocols[0], getNumProtocols()); +void ObjCQualifiedInterfaceType::Profile(llvm::FoldingSetNodeID &ID) { + Profile(ID, getDecl(), &Protocols[0], getNumProtocols()); } /// LookThroughTypedefs - Return the ultimate type this typedef corresponds to @@ -1593,6 +1605,30 @@ void ObjCInterfaceType::getAsStringInternal(std::string &InnerString, const Prin InnerString = getDecl()->getIdentifier()->getName() + InnerString; } +void ObjCObjectPointerType::getAsStringInternal(std::string &InnerString, + const PrintingPolicy &Policy) const { + if (!InnerString.empty()) // Prefix the basic type, e.g. 'typedefname X'. + InnerString = ' ' + InnerString; + + std::string ObjCQIString; + + if (getDecl()) + ObjCQIString = getDecl()->getNameAsString(); + else + ObjCQIString = "id"; + + if (!qual_empty()) { + ObjCQIString += '<'; + for (qual_iterator I = qual_begin(), E = qual_end(); I != E; ++I) { + ObjCQIString += (*I)->getNameAsString(); + if (I+1 != E) + ObjCQIString += ','; + } + ObjCQIString += '>'; + } + InnerString = ObjCQIString + InnerString; +} + void ObjCQualifiedInterfaceType::getAsStringInternal(std::string &InnerString, const PrintingPolicy &Policy) const { @@ -1612,20 +1648,6 @@ ObjCQualifiedInterfaceType::getAsStringInternal(std::string &InnerString, InnerString = ObjCQIString + InnerString; } -void ObjCQualifiedIdType::getAsStringInternal(std::string &InnerString, const PrintingPolicy &Policy) const { - if (!InnerString.empty()) // Prefix the basic type, e.g. 'typedefname X'. - InnerString = ' ' + InnerString; - std::string ObjCQIString = "id"; - ObjCQIString += '<'; - for (qual_iterator I = qual_begin(), E = qual_end(); I != E; ++I) { - ObjCQIString += (*I)->getNameAsString(); - if (I+1 != E) - ObjCQIString += ','; - } - ObjCQIString += '>'; - InnerString = ObjCQIString + InnerString; -} - void TagType::getAsStringInternal(std::string &InnerString, const PrintingPolicy &Policy) const { if (Policy.SuppressTag) return; |