From 7ded7f4983dc4a20561db7a8d02c6b2435030961 Mon Sep 17 00:00:00 2001 From: Daniel Dunbar Date: Fri, 15 Aug 2008 22:20:32 +0000 Subject: Change CGObjCRuntime methods to take appropriate clang Decls. - This is in prep for implementation class support for the NeXT runtime, for which the existing methods don't provide enough information (and additionally make too many assumptions about how things should be emitted). git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@54824 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/CodeGenModule.cpp | 123 ++---------------------------------------- 1 file changed, 5 insertions(+), 118 deletions(-) (limited to 'lib/CodeGen/CodeGenModule.cpp') diff --git a/lib/CodeGen/CodeGenModule.cpp b/lib/CodeGen/CodeGenModule.cpp index 500bf5b5d5..3340cdff56 100644 --- a/lib/CodeGen/CodeGenModule.cpp +++ b/lib/CodeGen/CodeGenModule.cpp @@ -252,125 +252,12 @@ void CodeGenModule::EmitObjCProtocolImplementation(const ObjCProtocolDecl *PD){ } void CodeGenModule::EmitObjCCategoryImpl(const ObjCCategoryImplDecl *OCD) { + Runtime->GenerateCategory(OCD); +} - // Collect information about instance methods - llvm::SmallVector InstanceMethodSels; - llvm::SmallVector InstanceMethodTypes; - for (ObjCCategoryDecl::instmeth_iterator iter = OCD->instmeth_begin(), - endIter = OCD->instmeth_end() ; iter != endIter ; iter++) { - InstanceMethodSels.push_back((*iter)->getSelector()); - std::string TypeStr; - Context.getObjCEncodingForMethodDecl(*iter,TypeStr); - InstanceMethodTypes.push_back(GetAddrOfConstantCString(TypeStr)); - } - - // Collect information about class methods - llvm::SmallVector ClassMethodSels; - llvm::SmallVector ClassMethodTypes; - for (ObjCCategoryDecl::classmeth_iterator iter = OCD->classmeth_begin(), - endIter = OCD->classmeth_end() ; iter != endIter ; iter++) { - ClassMethodSels.push_back((*iter)->getSelector()); - std::string TypeStr; - Context.getObjCEncodingForMethodDecl(*iter,TypeStr); - ClassMethodTypes.push_back(GetAddrOfConstantCString(TypeStr)); - } - - // Collect the names of referenced protocols - llvm::SmallVector Protocols; - const ObjCInterfaceDecl *ClassDecl = OCD->getClassInterface(); - const ObjCList &Protos =ClassDecl->getReferencedProtocols(); - for (ObjCList::iterator I = Protos.begin(), - E = Protos.end(); I != E; ++I) - Protocols.push_back((*I)->getName()); - - // Generate the category - Runtime->GenerateCategory(OCD->getClassInterface()->getName(), - OCD->getName(), InstanceMethodSels, InstanceMethodTypes, - ClassMethodSels, ClassMethodTypes, Protocols); -} - -void CodeGenModule::EmitObjCClassImplementation( - const ObjCImplementationDecl *OID) { - // Get the superclass name. - const ObjCInterfaceDecl * SCDecl = OID->getClassInterface()->getSuperClass(); - const char * SCName = NULL; - if (SCDecl) { - SCName = SCDecl->getName(); - } - - // Get the class name - ObjCInterfaceDecl * ClassDecl = (ObjCInterfaceDecl*)OID->getClassInterface(); - const char * ClassName = ClassDecl->getName(); - - // Get the size of instances. For runtimes that support late-bound instances - // this should probably be something different (size just of instance - // varaibles in this class, not superclasses?). - int instanceSize = 0; - const llvm::Type *ObjTy = 0; - if (!Runtime->LateBoundIVars()) { - ObjTy = getTypes().ConvertType(Context.getObjCInterfaceType(ClassDecl)); - instanceSize = TheTargetData.getABITypeSize(ObjTy); - } else { - // This is required by newer ObjC runtimes. - assert(0 && "Late-bound instance variables not yet supported"); - } - - // Collect information about instance variables. - llvm::SmallVector IvarNames; - llvm::SmallVector IvarTypes; - llvm::SmallVector IvarOffsets; - const llvm::StructLayout *Layout = - TheTargetData.getStructLayout(cast(ObjTy)); - ObjTy = llvm::PointerType::getUnqual(ObjTy); - for (ObjCInterfaceDecl::ivar_iterator iter = ClassDecl->ivar_begin(), - endIter = ClassDecl->ivar_end() ; iter != endIter ; iter++) { - // Store the name - IvarNames.push_back(GetAddrOfConstantCString((*iter)->getName())); - // Get the type encoding for this ivar - std::string TypeStr; - llvm::SmallVector EncodingRecordTypes; - Context.getObjCEncodingForType((*iter)->getType(), TypeStr, - EncodingRecordTypes); - IvarTypes.push_back(GetAddrOfConstantCString(TypeStr)); - // Get the offset - int offset = - (int)Layout->getElementOffset(getTypes().getLLVMFieldNo(*iter)); - IvarOffsets.push_back( - llvm::ConstantInt::get(llvm::Type::Int32Ty, offset)); - } - - // Collect information about instance methods - llvm::SmallVector InstanceMethodSels; - llvm::SmallVector InstanceMethodTypes; - for (ObjCImplementationDecl::instmeth_iterator iter = OID->instmeth_begin(), - endIter = OID->instmeth_end() ; iter != endIter ; iter++) { - InstanceMethodSels.push_back((*iter)->getSelector()); - std::string TypeStr; - Context.getObjCEncodingForMethodDecl((*iter),TypeStr); - InstanceMethodTypes.push_back(GetAddrOfConstantCString(TypeStr)); - } - - // Collect information about class methods - llvm::SmallVector ClassMethodSels; - llvm::SmallVector ClassMethodTypes; - for (ObjCImplementationDecl::classmeth_iterator iter = OID->classmeth_begin(), - endIter = OID->classmeth_end() ; iter != endIter ; iter++) { - ClassMethodSels.push_back((*iter)->getSelector()); - std::string TypeStr; - Context.getObjCEncodingForMethodDecl((*iter),TypeStr); - ClassMethodTypes.push_back(GetAddrOfConstantCString(TypeStr)); - } - // Collect the names of referenced protocols - llvm::SmallVector Protocols; - const ObjCList &Protos =ClassDecl->getReferencedProtocols(); - for (ObjCList::iterator I = Protos.begin(), - E = Protos.end(); I != E; ++I) - Protocols.push_back((*I)->getName()); - - // Generate the category - Runtime->GenerateClass(ClassName, SCName, instanceSize, IvarNames, IvarTypes, - IvarOffsets, InstanceMethodSels, InstanceMethodTypes, - ClassMethodSels, ClassMethodTypes, Protocols); +void +CodeGenModule::EmitObjCClassImplementation(const ObjCImplementationDecl *OID) { + Runtime->GenerateClass(OID); } void CodeGenModule::EmitStatics() { -- cgit v1.2.3-18-g5258