diff options
-rw-r--r-- | Driver/RewriteObjC.cpp | 36 | ||||
-rw-r--r-- | include/clang/AST/DeclObjC.h | 66 | ||||
-rw-r--r-- | lib/AST/DeclObjC.cpp | 44 | ||||
-rw-r--r-- | lib/CodeGen/CodeGenModule.cpp | 9 | ||||
-rw-r--r-- | lib/Sema/SemaDeclObjC.cpp | 29 | ||||
-rw-r--r-- | lib/Sema/SemaExprObjC.cpp | 13 |
6 files changed, 80 insertions, 117 deletions
diff --git a/Driver/RewriteObjC.cpp b/Driver/RewriteObjC.cpp index 347874e58a..a95abbecd6 100644 --- a/Driver/RewriteObjC.cpp +++ b/Driver/RewriteObjC.cpp @@ -217,8 +217,8 @@ namespace { const char *ClassName, std::string &Result); - void RewriteObjCProtocolsMetaData(ObjCProtocolDecl *const*Protocols, - int NumProtocols, + void RewriteObjCProtocolsMetaData(const ObjCList<ObjCProtocolDecl> + &Protocols, const char *prefix, const char *ClassName, std::string &Result); @@ -2524,14 +2524,14 @@ void RewriteObjC::RewriteObjCMethodsMetaData(instmeth_iterator MethodBegin, } /// RewriteObjCProtocolsMetaData - Rewrite protocols meta-data. -void RewriteObjC::RewriteObjCProtocolsMetaData(ObjCProtocolDecl*const*Protocols, - int NumProtocols, - const char *prefix, - const char *ClassName, - std::string &Result) { +void RewriteObjC:: +RewriteObjCProtocolsMetaData(const ObjCList<ObjCProtocolDecl> &Protocols, + const char *prefix, + const char *ClassName, + std::string &Result) { static bool objc_protocol_methods = false; - if (NumProtocols > 0) { - for (int i = 0; i < NumProtocols; i++) { + if (!Protocols.empty()) { + for (unsigned i = 0; i != Protocols.size(); i++) { ObjCProtocolDecl *PDecl = Protocols[i]; // Output struct protocol_methods holder of method selector and type. if (!objc_protocol_methods && !PDecl->isForwardDecl()) { @@ -2680,24 +2680,23 @@ void RewriteObjC::RewriteObjCProtocolsMetaData(ObjCProtocolDecl*const*Protocols, Result += "\tstruct _objc_protocol_list *next;\n"; Result += "\tint protocol_count;\n"; Result += "\tstruct _objc_protocol *class_protocols["; - Result += utostr(NumProtocols); + Result += utostr(Protocols.size()); Result += "];\n} _OBJC_"; Result += prefix; Result += "_PROTOCOLS_"; Result += ClassName; Result += " __attribute__ ((used, section (\"__OBJC, __cat_cls_meth\")))= " "{\n\t0, "; - Result += utostr(NumProtocols); + Result += utostr(Protocols.size()); Result += "\n"; Result += "\t,{&_OBJC_PROTOCOL_"; Result += Protocols[0]->getName(); Result += " \n"; - for (int i = 1; i < NumProtocols; i++) { - ObjCProtocolDecl *PDecl = Protocols[i]; + for (unsigned i = 1; i != Protocols.size(); i++) { Result += "\t ,&_OBJC_PROTOCOL_"; - Result += PDecl->getName(); + Result += Protocols[i]->getName(); Result += "\n"; } Result += "\t }\n};\n"; @@ -2733,9 +2732,7 @@ void RewriteObjC::RewriteObjCCategoryImplDecl(ObjCCategoryImplDecl *IDecl, // Protocols referenced in class declaration? // Null CDecl is case of a category implementation with no category interface if (CDecl) - RewriteObjCProtocolsMetaData(CDecl->getReferencedProtocols(), - CDecl->getNumReferencedProtocols(), - "CATEGORY", + RewriteObjCProtocolsMetaData(CDecl->getReferencedProtocols(), "CATEGORY", FullCategoryName.c_str(), Result); /* struct _objc_category { @@ -2789,7 +2786,7 @@ void RewriteObjC::RewriteObjCCategoryImplDecl(ObjCCategoryImplDecl *IDecl, else Result += "\t, 0\n"; - if (CDecl && CDecl->getNumReferencedProtocols() > 0) { + if (CDecl && !CDecl->getReferencedProtocols().empty()) { Result += "\t, (struct _objc_protocol_list *)&_OBJC_CATEGORY_PROTOCOLS_"; Result += FullCategoryName; Result += "\n"; @@ -2915,8 +2912,7 @@ void RewriteObjC::RewriteObjCClassMetaData(ObjCImplementationDecl *IDecl, false, "", IDecl->getName(), Result); // Protocols referenced in class declaration? - RewriteObjCProtocolsMetaData(CDecl->getReferencedProtocols().begin(), - CDecl->getReferencedProtocols().size(), + RewriteObjCProtocolsMetaData(CDecl->getReferencedProtocols(), "CLASS", CDecl->getName(), Result); diff --git a/include/clang/AST/DeclObjC.h b/include/clang/AST/DeclObjC.h index d35ae178d1..27760f2d76 100644 --- a/include/clang/AST/DeclObjC.h +++ b/include/clang/AST/DeclObjC.h @@ -63,7 +63,7 @@ public: unsigned size() const { return NumElts; } bool empty() const { return NumElts == 0; } - T* get(unsigned idx) const { + T* operator[](unsigned idx) const { assert(idx < NumElts && "Invalid access"); return List[idx]; } @@ -356,11 +356,10 @@ public: return ClassMethods+NumClassMethods; } - /// addReferencedProtocols - Set the list of protocols that this interface /// implements. - void addReferencedProtocols(ObjCProtocolDecl * const *OID, unsigned NumRPs) { - ReferencedProtocols.set(OID, NumRPs); + void addReferencedProtocols(ObjCProtocolDecl *const*List, unsigned NumRPs) { + ReferencedProtocols.set(List, NumRPs); } void addInstanceVariablesToClass(ObjCIvarDecl **ivars, unsigned numIvars, @@ -526,9 +525,8 @@ private: /// id <NSDraggingInfo> anyObjectThatImplementsNSDraggingInfo; /// class ObjCProtocolDecl : public NamedDecl { - /// referenced protocols - ObjCProtocolDecl **ReferencedProtocols; // Null if none - unsigned NumReferencedProtocols; // 0 if none + /// Referenced protocols + ObjCList<ObjCProtocolDecl> ReferencedProtocols; /// protocol instance methods ObjCMethodDecl **InstanceMethods; // Null if not defined @@ -547,14 +545,12 @@ class ObjCProtocolDecl : public NamedDecl { SourceLocation EndLoc; // marks the '>' or identifier. SourceLocation AtEndLoc; // marks the end of the entire interface. - ObjCProtocolDecl(SourceLocation L, unsigned numRefProtos, IdentifierInfo *Id) + ObjCProtocolDecl(SourceLocation L, IdentifierInfo *Id) : NamedDecl(ObjCProtocol, L, Id), - ReferencedProtocols(0), NumReferencedProtocols(0), InstanceMethods(0), NumInstanceMethods(0), ClassMethods(0), NumClassMethods(0), PropertyDecl(0), NumPropertyDecl(0), isForwardProtoDecl(true) { - AllocReferencedProtocols(numRefProtos); } virtual ~ObjCProtocolDecl(); @@ -565,33 +561,23 @@ public: virtual void Destroy(ASTContext& C); static ObjCProtocolDecl *Create(ASTContext &C, SourceLocation L, - unsigned numRefProtos, IdentifierInfo *Id); + IdentifierInfo *Id); - void AllocReferencedProtocols(unsigned numRefProtos) { - if (numRefProtos) { - ReferencedProtocols = new ObjCProtocolDecl*[numRefProtos]; - memset(ReferencedProtocols, '\0', - numRefProtos*sizeof(ObjCProtocolDecl*)); - NumReferencedProtocols = numRefProtos; - } - } void addMethods(ObjCMethodDecl **insMethods, unsigned numInsMembers, ObjCMethodDecl **clsMethods, unsigned numClsMembers, SourceLocation AtEndLoc); - void setReferencedProtocols(unsigned idx, ObjCProtocolDecl *OID) { - assert((idx < NumReferencedProtocols) && "index out of range"); - ReferencedProtocols[idx] = OID; - } - - ObjCProtocolDecl** getReferencedProtocols() const { - return ReferencedProtocols; + const ObjCList<ObjCProtocolDecl> &getReferencedProtocols() const { + return ReferencedProtocols; } - unsigned getNumReferencedProtocols() const { return NumReferencedProtocols; } typedef ObjCProtocolDecl * const * protocol_iterator; - protocol_iterator protocol_begin() const { return ReferencedProtocols; } - protocol_iterator protocol_end() const { - return ReferencedProtocols+NumReferencedProtocols; + protocol_iterator protocol_begin() const {return ReferencedProtocols.begin();} + protocol_iterator protocol_end() const { return ReferencedProtocols.end(); } + + /// addReferencedProtocols - Set the list of protocols that this interface + /// implements. + void addReferencedProtocols(ObjCProtocolDecl *const*List, unsigned NumRPs) { + ReferencedProtocols.set(List, NumRPs); } unsigned getNumInstanceMethods() const { return NumInstanceMethods; } @@ -783,8 +769,7 @@ class ObjCCategoryDecl : public NamedDecl { ObjCInterfaceDecl *ClassInterface; /// referenced protocols in this category. - ObjCProtocolDecl **ReferencedProtocols; // Null if none - unsigned NumReferencedProtocols; // 0 if none + ObjCList<ObjCProtocolDecl> ReferencedProtocols; /// category instance methods ObjCMethodDecl **InstanceMethods; // Null if not defined @@ -806,7 +791,7 @@ class ObjCCategoryDecl : public NamedDecl { ObjCCategoryDecl(SourceLocation L, IdentifierInfo *Id) : NamedDecl(ObjCCategory, L, Id), - ClassInterface(0), ReferencedProtocols(0), NumReferencedProtocols(0), + ClassInterface(0), InstanceMethods(0), NumInstanceMethods(0), ClassMethods(0), NumClassMethods(0), NextClassCategory(0), PropertyDecl(0), NumPropertyDecl(0) { @@ -822,12 +807,19 @@ public: /// addReferencedProtocols - Set the list of protocols that this interface /// implements. - void addReferencedProtocols(ObjCProtocolDecl **List, unsigned NumRPs); + void addReferencedProtocols(ObjCProtocolDecl *const*List, unsigned NumRPs) { + ReferencedProtocols.set(List, NumRPs); + } - ObjCProtocolDecl **getReferencedProtocols() const { - return ReferencedProtocols; + const ObjCList<ObjCProtocolDecl> &getReferencedProtocols() const { + return ReferencedProtocols; } - unsigned getNumReferencedProtocols() const { return NumReferencedProtocols; } + + typedef ObjCProtocolDecl * const * protocol_iterator; + protocol_iterator protocol_begin() const {return ReferencedProtocols.begin();} + protocol_iterator protocol_end() const { return ReferencedProtocols.end(); } + + unsigned getNumInstanceMethods() const { return NumInstanceMethods; } unsigned getNumClassMethods() const { return NumClassMethods; } diff --git a/lib/AST/DeclObjC.cpp b/lib/AST/DeclObjC.cpp index 7b28b10f91..4b798474f6 100644 --- a/lib/AST/DeclObjC.cpp +++ b/lib/AST/DeclObjC.cpp @@ -94,14 +94,12 @@ ObjCIvarDecl *ObjCIvarDecl::Create(ASTContext &C, SourceLocation L, ObjCProtocolDecl *ObjCProtocolDecl::Create(ASTContext &C, SourceLocation L, - unsigned numRefProtos, IdentifierInfo *Id) { void *Mem = C.getAllocator().Allocate<ObjCProtocolDecl>(); - return new (Mem) ObjCProtocolDecl(L, numRefProtos, Id); + return new (Mem) ObjCProtocolDecl(L, Id); } ObjCProtocolDecl::~ObjCProtocolDecl() { - delete [] ReferencedProtocols; delete [] InstanceMethods; delete [] ClassMethods; delete [] PropertyDecl; @@ -440,15 +438,6 @@ void ObjCProtocolDecl::addMethods(ObjCMethodDecl **insMethods, AtEndLoc = endLoc; } -void ObjCCategoryDecl::addReferencedProtocols(ObjCProtocolDecl **List, - unsigned NumRPs) { - assert(NumReferencedProtocols == 0 && "Protocol list already set"); - if (NumRPs == 0) return; - - ReferencedProtocols = new ObjCProtocolDecl*[NumRPs]; - memcpy(ReferencedProtocols, List, NumRPs*sizeof(ObjCProtocolDecl*)); - NumReferencedProtocols = NumRPs; -} /// addMethods - Insert instance and methods declarations into @@ -557,14 +546,11 @@ ObjCMethodDecl *ObjCInterfaceDecl::lookupClassMethod(Selector Sel) { return MethodDecl; // Didn't find one yet - look through protocols. - const ObjCList<ObjCProtocolDecl> &Protocols = - ClassDecl->getReferencedProtocols(); - - for (ObjCList<ObjCProtocolDecl>::iterator I = Protocols.begin(), - E = Protocols.end(); I != E; ++I) { + for (ObjCInterfaceDecl::protocol_iterator I = ClassDecl->protocol_begin(), + E = ClassDecl->protocol_end(); I != E; ++I) if ((MethodDecl = (*I)->getClassMethod(Sel))) return MethodDecl; - } + // Didn't find one yet - now look through categories. ObjCCategoryDecl *CatDecl = ClassDecl->getCategoryList(); while (CatDecl) { @@ -627,14 +613,9 @@ ObjCMethodDecl *ObjCProtocolDecl::lookupInstanceMethod(Selector Sel) { if ((MethodDecl = getInstanceMethod(Sel))) return MethodDecl; - if (getNumReferencedProtocols() > 0) { - ObjCProtocolDecl **RefPDecl = getReferencedProtocols(); - - for (unsigned i = 0; i < getNumReferencedProtocols(); i++) { - if ((MethodDecl = RefPDecl[i]->getInstanceMethod(Sel))) - return MethodDecl; - } - } + for (protocol_iterator I = protocol_begin(), E = protocol_end(); I != E; ++I) + if ((MethodDecl = (*I)->getInstanceMethod(Sel))) + return MethodDecl; return NULL; } @@ -646,14 +627,9 @@ ObjCMethodDecl *ObjCProtocolDecl::lookupClassMethod(Selector Sel) { if ((MethodDecl = getClassMethod(Sel))) return MethodDecl; - if (getNumReferencedProtocols() > 0) { - ObjCProtocolDecl **RefPDecl = getReferencedProtocols(); - - for(unsigned i = 0; i < getNumReferencedProtocols(); i++) { - if ((MethodDecl = RefPDecl[i]->getClassMethod(Sel))) - return MethodDecl; - } - } + for (protocol_iterator I = protocol_begin(), E = protocol_end(); I != E; ++I) + if ((MethodDecl = (*I)->getClassMethod(Sel))) + return MethodDecl; return NULL; } diff --git a/lib/CodeGen/CodeGenModule.cpp b/lib/CodeGen/CodeGenModule.cpp index b9c15427c3..f2112ebd72 100644 --- a/lib/CodeGen/CodeGenModule.cpp +++ b/lib/CodeGen/CodeGenModule.cpp @@ -362,14 +362,15 @@ void CodeGenModule::EmitObjCMethod(const ObjCMethodDecl *OMD) { } void CodeGenModule::EmitObjCProtocolImplementation(const ObjCProtocolDecl *PD){ llvm::SmallVector<std::string, 16> Protocols; - for (unsigned i = 0, e = PD->getNumReferencedProtocols() ; i < e ; i++) - Protocols.push_back(PD->getReferencedProtocols()[i]->getName()); + for (ObjCProtocolDecl::protocol_iterator PI = PD->protocol_begin(), + E = PD->protocol_end(); PI != E; ++PI) + Protocols.push_back((*PI)->getName()); llvm::SmallVector<llvm::Constant*, 16> InstanceMethodNames; llvm::SmallVector<llvm::Constant*, 16> InstanceMethodTypes; for (ObjCProtocolDecl::instmeth_iterator iter = PD->instmeth_begin(), - endIter = PD->instmeth_end() ; iter != endIter ; iter++) { + E = PD->instmeth_end(); iter != E; iter++) { std::string TypeStr; - Context.getObjCEncodingForMethodDecl((*iter),TypeStr); + Context.getObjCEncodingForMethodDecl(*iter, TypeStr); InstanceMethodNames.push_back( GetAddrOfConstantString((*iter)->getSelector().getName())); InstanceMethodTypes.push_back(GetAddrOfConstantString(TypeStr)); diff --git a/lib/Sema/SemaDeclObjC.cpp b/lib/Sema/SemaDeclObjC.cpp index c3c2426bdc..9de9efab4c 100644 --- a/lib/Sema/SemaDeclObjC.cpp +++ b/lib/Sema/SemaDeclObjC.cpp @@ -209,18 +209,17 @@ Sema::DeclTy *Sema::ActOnStartProtocolInterface( } PDecl->setForwardDecl(false); - PDecl->AllocReferencedProtocols(NumProtoRefs); } else { - PDecl = ObjCProtocolDecl::Create(Context, AtProtoInterfaceLoc, NumProtoRefs, - ProtocolName); + PDecl = ObjCProtocolDecl::Create(Context, AtProtoInterfaceLoc,ProtocolName); PDecl->setForwardDecl(false); ObjCProtocols[ProtocolName] = PDecl; } if (NumProtoRefs) { /// Check then save referenced protocols. + llvm::SmallVector<ObjCProtocolDecl*, 8> Protocols; for (unsigned int i = 0; i != NumProtoRefs; i++) { - ObjCProtocolDecl* RefPDecl = ObjCProtocols[ProtoRefNames[i]]; + ObjCProtocolDecl *RefPDecl = ObjCProtocols[ProtoRefNames[i]]; if (!RefPDecl) Diag(ProtocolLoc, diag::err_undef_protocolref, ProtoRefNames[i]->getName(), ProtocolName->getName()); @@ -228,9 +227,11 @@ Sema::DeclTy *Sema::ActOnStartProtocolInterface( if (RefPDecl->isForwardDecl()) Diag(ProtocolLoc, diag::warn_undef_protocolref, ProtoRefNames[i]->getName(), ProtocolName->getName()); - PDecl->setReferencedProtocols(i, RefPDecl); + Protocols.push_back(RefPDecl); } } + if (!Protocols.empty()) + PDecl->addReferencedProtocols(&Protocols[0], Protocols.size()); PDecl->setLocEnd(EndProtoLoc); } return PDecl; @@ -389,7 +390,7 @@ Sema::ActOnForwardProtocolDeclaration(SourceLocation AtProtocolLoc, ObjCProtocolDecl *&PDecl = ObjCProtocols[Ident]; if (PDecl == 0) { // Not already seen? // FIXME: Pass in the location of the identifier! - PDecl = ObjCProtocolDecl::Create(Context, AtProtocolLoc, 0, Ident); + PDecl = ObjCProtocolDecl::Create(Context, AtProtocolLoc, Ident); } Protocols.push_back(PDecl); @@ -627,10 +628,10 @@ void Sema::CheckProtocolMethodDefs(SourceLocation ImpLoc, method->getImplementationControl() != ObjCMethodDecl::Optional) WarnUndefinedMethod(ImpLoc, method, IncompleteImpl); } - // Check on this protocols's referenced protocols, recursively - ObjCProtocolDecl** RefPDecl = PDecl->getReferencedProtocols(); - for (unsigned i = 0; i < PDecl->getNumReferencedProtocols(); i++) - CheckProtocolMethodDefs(ImpLoc, RefPDecl[i], IncompleteImpl, InsMap, ClsMap); + // Check on this protocols's referenced protocols, recursively. + for (ObjCProtocolDecl::protocol_iterator PI = PDecl->protocol_begin(), + E = PDecl->protocol_end(); PI != E; ++PI) + CheckProtocolMethodDefs(ImpLoc, *PI, IncompleteImpl, InsMap, ClsMap); } void Sema::ImplMethodsVsClassMethods(ObjCImplementationDecl* IMPDecl, @@ -702,12 +703,10 @@ void Sema::ImplCategoryMethodsVsIntfMethods(ObjCCategoryImplDecl *CatImplDecl, // Check the protocol list for unimplemented methods in the @implementation // class. - ObjCProtocolDecl** protocols = CatClassDecl->getReferencedProtocols(); - for (unsigned i = 0; i < CatClassDecl->getNumReferencedProtocols(); i++) { - ObjCProtocolDecl* PDecl = protocols[i]; - CheckProtocolMethodDefs(CatImplDecl->getLocation(), PDecl, IncompleteImpl, + for (ObjCCategoryDecl::protocol_iterator PI = CatClassDecl->protocol_begin(), + E = CatClassDecl->protocol_end(); PI != E; ++PI) + CheckProtocolMethodDefs(CatImplDecl->getLocation(), *PI, IncompleteImpl, InsMap, ClsMap); - } } /// ActOnForwardClassDeclaration - diff --git a/lib/Sema/SemaExprObjC.cpp b/lib/Sema/SemaExprObjC.cpp index 6d19b87446..333268e8e5 100644 --- a/lib/Sema/SemaExprObjC.cpp +++ b/lib/Sema/SemaExprObjC.cpp @@ -359,9 +359,9 @@ static bool ProtocolCompatibleWithProtocol(ObjCProtocolDecl *lProto, ObjCProtocolDecl *rProto) { if (lProto == rProto) return true; - ObjCProtocolDecl** RefPDecl = rProto->getReferencedProtocols(); - for (unsigned i = 0; i < rProto->getNumReferencedProtocols(); i++) - if (ProtocolCompatibleWithProtocol(lProto, RefPDecl[i])) + for (ObjCProtocolDecl::protocol_iterator PI = rProto->protocol_begin(), + E = rProto->protocol_end(); PI != E; ++PI) + if (ProtocolCompatibleWithProtocol(lProto, *PI)) return true; return false; } @@ -396,11 +396,10 @@ static bool ClassImplementsProtocol(ObjCProtocolDecl *lProto, if (lookupCategory) for (ObjCCategoryDecl *CDecl = IDecl->getCategoryList(); CDecl; CDecl = CDecl->getNextClassCategory()) { - ObjCProtocolDecl **protoList = CDecl->getReferencedProtocols(); - for (unsigned i = 0; i < CDecl->getNumReferencedProtocols(); i++) { - if (ProtocolCompatibleWithProtocol(lProto, protoList[i])) + for (ObjCCategoryDecl::protocol_iterator PI = CDecl->protocol_begin(), + E = CDecl->protocol_end(); PI != E; ++PI) + if (ProtocolCompatibleWithProtocol(lProto, *PI)) return true; - } } // 3rd, look up the super class(s) |