simplify the way ObjCCategoryDecl's get their referenced protocols list
specified. Previously, the ctor would allocate memory for the list and then
it would get filled in later. Move the allocation+filling in to be more
consistent with other stuff, e.g. the addMethods method.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@48427 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Sema/SemaDeclObjC.cpp b/lib/Sema/SemaDeclObjC.cpp
index 7bdfd9e..e07d3c5 100644
--- a/lib/Sema/SemaDeclObjC.cpp
+++ b/lib/Sema/SemaDeclObjC.cpp
@@ -281,8 +281,7 @@
ObjCInterfaceDecl *IDecl = getObjCInterfaceDecl(ClassName);
ObjCCategoryDecl *CDecl =
- ObjCCategoryDecl::Create(Context, AtInterfaceLoc, NumProtoRefs,
- CategoryName);
+ ObjCCategoryDecl::Create(Context, AtInterfaceLoc, CategoryName);
CDecl->setClassInterface(IDecl);
/// Check that class of this category is already completely declared.
@@ -304,7 +303,8 @@
}
if (NumProtoRefs) {
- /// Check then save referenced protocols
+ llvm::SmallVector<ObjCProtocolDecl*, 32> RefProtocols;
+ /// Check and then save the referenced protocols.
for (unsigned int i = 0; i != NumProtoRefs; i++) {
ObjCProtocolDecl* RefPDecl = ObjCProtocols[ProtoRefNames[i]];
if (!RefPDecl || RefPDecl->isForwardDecl()) {
@@ -312,10 +312,13 @@
ProtoRefNames[i]->getName(),
CategoryName->getName());
}
- CDecl->setCatReferencedProtocols(i, RefPDecl);
+ if (RefPDecl)
+ RefProtocols.push_back(RefPDecl);
}
- CDecl->setLocEnd(EndProtoLoc);
+ if (!RefProtocols.empty())
+ CDecl->setReferencedProtocolList(&RefProtocols[0], RefProtocols.size());
}
+ CDecl->setLocEnd(EndProtoLoc);
return CDecl;
}