diff options
Diffstat (limited to 'lib')
-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 |
4 files changed, 35 insertions, 60 deletions
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) |