/// StartObjCMethod - Begin emission of an ObjCMethod. This generates
/// the LLVM function and sets the other context used by
/// CodeGenFunction.
-void CodeGenFunction::StartObjCMethod(const ObjCMethodDecl *OMD) {
+void CodeGenFunction::StartObjCMethod(const ObjCMethodDecl *OMD,
+ const ObjCContainerDecl *CD) {
FunctionArgList Args;
- llvm::Function *Fn = CGM.getObjCRuntime().GenerateMethod(OMD);
+ llvm::Function *Fn = CGM.getObjCRuntime().GenerateMethod(OMD, CD);
CGM.SetMethodAttributes(OMD, Fn);
/// Generate an Objective-C method. An Objective-C method is a C function with
/// its pointer, name, and types registered in the class struture.
void CodeGenFunction::GenerateObjCMethod(const ObjCMethodDecl *OMD) {
- StartObjCMethod(OMD);
+ StartObjCMethod(OMD, OMD->getClassInterface());
EmitStmt(OMD->getBody());
FinishFunction(cast<CompoundStmt>(OMD->getBody())->getRBracLoc());
}
const ObjCPropertyDecl *PD = PID->getPropertyDecl();
ObjCMethodDecl *OMD = PD->getGetterMethodDecl();
assert(OMD && "Invalid call to generate getter (empty method)");
- assert (!dyn_cast<ObjCProtocolDecl>(OMD->getDeclContext()) &&
- "GenerateObjCMethod - cannot synthesize protocol getter");
// FIXME: This is rather murky, we create this here since they will
// not have been created by Sema for us.
OMD->createImplicitParams(getContext(), IMP->getClassInterface());
- StartObjCMethod(OMD);
+ StartObjCMethod(OMD, IMP->getClassInterface());
// Determine if we should use an objc_getProperty call for
// this. Non-atomic properties are directly evaluated.
const ObjCPropertyDecl *PD = PID->getPropertyDecl();
ObjCMethodDecl *OMD = PD->getSetterMethodDecl();
assert(OMD && "Invalid call to generate setter (empty method)");
- assert (!dyn_cast<ObjCProtocolDecl>(OMD->getDeclContext()) &&
- "GenerateObjCSetter - cannot synthesize protocol setter");
// FIXME: This is rather murky, we create this here since they will
// not have been created by Sema for us.
OMD->createImplicitParams(getContext(), IMP->getClassInterface());
- StartObjCMethod(OMD);
+ StartObjCMethod(OMD, IMP->getClassInterface());
bool IsCopy = PD->getSetterKind() == ObjCPropertyDecl::Copy;
bool IsAtomic =
const ObjCInterfaceDecl *OID);
virtual llvm::Value *GetSelector(CGBuilderTy &Builder, Selector Sel);
- virtual llvm::Function *GenerateMethod(const ObjCMethodDecl *OMD);
+ virtual llvm::Function *GenerateMethod(const ObjCMethodDecl *OMD,
+ const ObjCContainerDecl *CD);
virtual void GenerateCategory(const ObjCCategoryImplDecl *CMD);
virtual void GenerateClass(const ObjCImplementationDecl *ClassDecl);
virtual llvm::Value *GenerateProtocolRef(CGBuilderTy &Builder,
return LoadFunction;
}
-llvm::Function *CGObjCGNU::GenerateMethod(const ObjCMethodDecl *OMD) {
+llvm::Function *CGObjCGNU::GenerateMethod(const ObjCMethodDecl *OMD,
+ const ObjCContainerDecl *CD) {
const ObjCCategoryImplDecl *OCD =
dyn_cast<ObjCCategoryImplDecl>(OMD->getDeclContext());
std::string CategoryName = OCD ? OCD->getNameAsString() : "";
/// GetNameForMethod - Return a name for the given method.
/// \param[out] NameOut - The return value.
void GetNameForMethod(const ObjCMethodDecl *OMD,
+ const ObjCContainerDecl *CD,
std::string &NameOut);
public:
virtual llvm::Value *GetSelector(CGBuilderTy &Builder, Selector Sel);
- virtual llvm::Function *GenerateMethod(const ObjCMethodDecl *OMD);
+ virtual llvm::Function *GenerateMethod(const ObjCMethodDecl *OMD,
+ const ObjCContainerDecl *CD=0);
virtual void GenerateCategory(const ObjCCategoryImplDecl *CMD);
ObjCTypes.MethodListPtrTy);
}
-llvm::Function *CGObjCMac::GenerateMethod(const ObjCMethodDecl *OMD) {
+llvm::Function *CGObjCMac::GenerateMethod(const ObjCMethodDecl *OMD,
+ const ObjCContainerDecl *CD) {
std::string Name;
- GetNameForMethod(OMD, Name);
+ GetNameForMethod(OMD, CD, Name);
const llvm::FunctionType *MethodTy =
CGM.getTypes().GetFunctionType(CGFunctionInfo(OMD, CGM.getContext()));
}
void CGObjCMac::GetNameForMethod(const ObjCMethodDecl *D,
+ const ObjCContainerDecl *CD,
std::string &NameOut) {
// FIXME: Find the mangling GCC uses.
NameOut = (D->isInstanceMethod() ? "-" : "+");
NameOut += '[';
- NameOut += D->getClassInterface()->getNameAsString();
+ assert (CD && "Missing container decl in GetNameForMethod");
+ NameOut += CD->getNameAsString();
NameOut += ' ';
NameOut += D->getSelector().getAsString();
NameOut += ']';
class ObjCAtTryStmt;
class ObjCAtThrowStmt;
class ObjCAtSynchronizedStmt;
+ class ObjCContainerDecl;
class ObjCCategoryImplDecl;
class ObjCImplementationDecl;
class ObjCInterfaceDecl;
// really this should also be generating the loads of the
// parameters, as the runtime should have full control over how
// parameters are passed.
- virtual llvm::Function *GenerateMethod(const ObjCMethodDecl *OMD) = 0;
+ virtual llvm::Function *GenerateMethod(const ObjCMethodDecl *OMD,
+ const ObjCContainerDecl *CD) = 0;
/// Return the runtime function for getting properties.
virtual llvm::Function *GetPropertyGetFunction() = 0;
class FunctionDecl;
class FunctionTypeProto;
class LabelStmt;
+ class ObjCContainerDecl;
class ObjCInterfaceDecl;
class ObjCIvarDecl;
class ObjCMethodDecl;
void GenerateObjCMethod(const ObjCMethodDecl *OMD);
- void StartObjCMethod(const ObjCMethodDecl *MD);
+ void StartObjCMethod(const ObjCMethodDecl *MD,
+ const ObjCContainerDecl *CD);
/// GenerateObjCGetter - Synthesize an Objective-C property getter
/// function.