Changeset View
Changeset View
Standalone View
Standalone View
clang/lib/CodeGen/CGObjCMac.cpp
- This file is larger than 256 KB, so syntax highlighting is disabled by default.
Show First 20 Lines • Show All 4,026 Lines • ▼ Show 20 Lines | llvm::Function *CGObjCCommonMac::GenerateMethod(const ObjCMethodDecl *OMD, | ||||
MethodDefinitions.insert(std::make_pair(OMD, Method)); | MethodDefinitions.insert(std::make_pair(OMD, Method)); | ||||
return Method; | return Method; | ||||
} | } | ||||
llvm::Function * | llvm::Function * | ||||
CGObjCCommonMac::GenerateDirectMethod(const ObjCMethodDecl *OMD, | CGObjCCommonMac::GenerateDirectMethod(const ObjCMethodDecl *OMD, | ||||
const ObjCContainerDecl *CD) { | const ObjCContainerDecl *CD) { | ||||
auto I = DirectMethodDefinitions.find(OMD->getCanonicalDecl()); | auto *COMD = OMD->getCanonicalDecl(); | ||||
if (I != DirectMethodDefinitions.end()) | auto I = DirectMethodDefinitions.find(COMD); | ||||
llvm::Function *OldFn = nullptr, *Fn = nullptr; | |||||
if (I != DirectMethodDefinitions.end()) { | |||||
// Objective-C allows for the declaration and implementation types | |||||
// to differ slightly. | |||||
// | |||||
// If we're being asked for the Function associated for a method | |||||
// implementation, a previous value might have been cached | |||||
// based on the type of the canonical declaration. | |||||
// | |||||
// If these do not match, then we'll replace this function with | |||||
// a new one that has the proper type below. | |||||
if (!OMD->getBody() || COMD->getReturnType() == OMD->getReturnType()) | |||||
return I->second; | return I->second; | ||||
OldFn = I->second; | |||||
dexonsmith: I think the LLVM style is to leave out these braces. | |||||
SmallString<256> Name; | } | ||||
GetNameForMethod(OMD, CD, Name, /*ignoreCategoryNamespace*/true); | |||||
CodeGenTypes &Types = CGM.getTypes(); | CodeGenTypes &Types = CGM.getTypes(); | ||||
llvm::FunctionType *MethodTy = | llvm::FunctionType *MethodTy = | ||||
Types.GetFunctionType(Types.arrangeObjCMethodDeclaration(OMD)); | Types.GetFunctionType(Types.arrangeObjCMethodDeclaration(OMD)); | ||||
llvm::Function *Method = | |||||
llvm::Function::Create(MethodTy, llvm::GlobalValue::ExternalLinkage, | if (OldFn) { | ||||
Fn = llvm::Function::Create(MethodTy, llvm::GlobalValue::ExternalLinkage, | |||||
"", &CGM.getModule()); | |||||
Fn->takeName(OldFn); | |||||
OldFn->replaceAllUsesWith( | |||||
llvm::ConstantExpr::getBitCast(Fn, OldFn->getType())); | |||||
OldFn->eraseFromParent(); | |||||
// Replace the cached function in the map. | |||||
I->second = Fn; | |||||
} else { | |||||
SmallString<256> Name; | |||||
GetNameForMethod(OMD, CD, Name, /*ignoreCategoryNamespace*/ true); | |||||
Fn = llvm::Function::Create(MethodTy, llvm::GlobalValue::ExternalLinkage, | |||||
Name.str(), &CGM.getModule()); | Name.str(), &CGM.getModule()); | ||||
DirectMethodDefinitions.insert(std::make_pair(OMD->getCanonicalDecl(), Method)); | DirectMethodDefinitions.insert(std::make_pair(COMD, Fn)); | ||||
} | |||||
return Method; | return Fn; | ||||
} | } | ||||
void CGObjCCommonMac::GenerateDirectMethodPrologue( | void CGObjCCommonMac::GenerateDirectMethodPrologue( | ||||
CodeGenFunction &CGF, llvm::Function *Fn, const ObjCMethodDecl *OMD, | CodeGenFunction &CGF, llvm::Function *Fn, const ObjCMethodDecl *OMD, | ||||
const ObjCContainerDecl *CD) { | const ObjCContainerDecl *CD) { | ||||
auto &Builder = CGF.Builder; | auto &Builder = CGF.Builder; | ||||
bool ReceiverCanBeNull = true; | bool ReceiverCanBeNull = true; | ||||
auto selfAddr = CGF.GetAddrOfLocalVar(OMD->getSelfDecl()); | auto selfAddr = CGF.GetAddrOfLocalVar(OMD->getSelfDecl()); | ||||
▲ Show 20 Lines • Show All 3,855 Lines • Show Last 20 Lines |
I think the LLVM style is to leave out these braces.