diff options
author | Douglas Gregor <dgregor@apple.com> | 2009-05-14 23:26:13 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2009-05-14 23:26:13 +0000 |
commit | 54dabfca850ca9e60e9ffb60003529f868d4d127 (patch) | |
tree | 8e9ea9e3574c06f8bc4d4a67caaf42a967da3154 /lib/Sema/SemaTemplateInstantiateDecl.cpp | |
parent | 77b7f1d4fb782c9152f91b76f9f8b1d1af21bd35 (diff) |
Introduce basic support for instantiating the definitions of member
functions of class templates. Only compound statements and expression
statements are currently implemented.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@71814 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaTemplateInstantiateDecl.cpp')
-rw-r--r-- | lib/Sema/SemaTemplateInstantiateDecl.cpp | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/lib/Sema/SemaTemplateInstantiateDecl.cpp b/lib/Sema/SemaTemplateInstantiateDecl.cpp index 02df5931a5..eb006dc3f3 100644 --- a/lib/Sema/SemaTemplateInstantiateDecl.cpp +++ b/lib/Sema/SemaTemplateInstantiateDecl.cpp @@ -572,6 +572,9 @@ TemplateDeclInstantiator::InitMethodInstantiation(CXXMethodDecl *New, void Sema::InstantiateFunctionDefinition(FunctionDecl *Function) { // FIXME: make this work for function template specializations, too. + if (Function->isInvalidDecl()) + return; + // Find the function body that we'll be substituting. const FunctionDecl *PatternDecl = Function->getInstantiatedFromMemberFunction(); @@ -582,7 +585,23 @@ void Sema::InstantiateFunctionDefinition(FunctionDecl *Function) { if (!Pattern) return; - // FIXME: instantiate the pattern + // Introduce a new scope where local variable instantiations will be + // recorded. + LocalInstantiationScope Scope(*this); + + // Introduce the instantiated function parameters into the local + // instantiation scope. + for (unsigned I = 0, N = PatternDecl->getNumParams(); I != N; ++I) + Scope.InstantiatedLocal(PatternDecl->getParamDecl(I), + Function->getParamDecl(I)); + + // Instantiate the function body. + OwningStmtResult Body + = InstantiateStmt(Pattern, getTemplateInstantiationArgs(Function)); + if (Body.isInvalid()) + Function->setInvalidDecl(true); + else + Function->setBody(Body.takeAs<Stmt>()); } /// \brief Instantiate the definition of the given variable from its |