diff options
author | Anders Carlsson <andersca@mac.com> | 2009-04-04 20:47:02 +0000 |
---|---|---|
committer | Anders Carlsson <andersca@mac.com> | 2009-04-04 20:47:02 +0000 |
commit | 468fa6366be872e9cbb687e1963a6bd4b9ce89ed (patch) | |
tree | ea70d22964a2293cfc00e6acbcc98749f9fc91dd /clang/lib/CodeGen/CodeGenFunction.cpp | |
parent | 1dfc5f51c809801796c0fa85fa9bcbe551a53b40 (diff) | |
download | bcm5719-llvm-468fa6366be872e9cbb687e1963a6bd4b9ce89ed.tar.gz bcm5719-llvm-468fa6366be872e9cbb687e1963a6bd4b9ce89ed.zip |
Add some basic support for generating C++ member functions.
llvm-svn: 68425
Diffstat (limited to 'clang/lib/CodeGen/CodeGenFunction.cpp')
-rw-r--r-- | clang/lib/CodeGen/CodeGenFunction.cpp | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/clang/lib/CodeGen/CodeGenFunction.cpp b/clang/lib/CodeGen/CodeGenFunction.cpp index dc00a76ff91..5b63e6594d3 100644 --- a/clang/lib/CodeGen/CodeGenFunction.cpp +++ b/clang/lib/CodeGen/CodeGenFunction.cpp @@ -18,6 +18,7 @@ #include "clang/AST/APValue.h" #include "clang/AST/ASTContext.h" #include "clang/AST/Decl.h" +#include "clang/AST/DeclCXX.h" #include "llvm/Support/CFG.h" #include "llvm/Target/TargetData.h" using namespace clang; @@ -26,7 +27,8 @@ using namespace CodeGen; CodeGenFunction::CodeGenFunction(CodeGenModule &cgm) : BlockFunction(cgm, *this, Builder), CGM(cgm), Target(CGM.getContext().Target), - DebugInfo(0), SwitchInsn(0), CaseRangeBlock(0), InvokeDest(0) { + DebugInfo(0), SwitchInsn(0), CaseRangeBlock(0), InvokeDest(0), + CXXThisDecl(0) { LLVMIntTy = ConvertType(getContext().IntTy); LLVMPointerWidth = Target.getPointerWidth(0); } @@ -201,6 +203,19 @@ void CodeGenFunction::GenerateCode(const FunctionDecl *FD, DebugInfo = CGM.getDebugInfo(); FunctionArgList Args; + + if (const CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(FD)) { + if (MD->isInstance()) { + // Create the implicit 'this' decl. + // FIXME: I'm not entirely sure I like using a fake decl just for code + // generation. Maybe we can come up with a better way? + CXXThisDecl = ImplicitParamDecl::Create(getContext(), 0, SourceLocation(), + &getContext().Idents.get("this"), + MD->getThisType(getContext())); + Args.push_back(std::make_pair(CXXThisDecl, CXXThisDecl->getType())); + } + } + if (FD->getNumParams()) { const FunctionProtoType* FProto = FD->getType()->getAsFunctionProtoType(); assert(FProto && "Function def must have prototype!"); @@ -221,6 +236,10 @@ void CodeGenFunction::GenerateCode(const FunctionDecl *FD, } else { FinishFunction(); } + + // Destroy the 'this' declaration. + if (CXXThisDecl) + CXXThisDecl->Destroy(getContext()); } /// ContainsLabel - Return true if the statement contains a label in it. If |