move two more lists of protocols over to use ObjCList<ObjCProtocolDecl>,
simplifying code along the way and fixing a problem and memory leak or two.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@53876 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Sema/SemaDeclObjC.cpp b/lib/Sema/SemaDeclObjC.cpp
index c3c2426..9de9efa 100644
--- a/lib/Sema/SemaDeclObjC.cpp
+++ b/lib/Sema/SemaDeclObjC.cpp
@@ -209,18 +209,17 @@
}
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 @@
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 @@
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 @@
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 @@
// 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 -