diff options
author | Douglas Gregor <dgregor@apple.com> | 2009-08-28 17:37:35 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2009-08-28 17:37:35 +0000 |
commit | d1102433214bd33b5bef5b493944292a1e82c2fb (patch) | |
tree | 770c465ed722312656def6331406a04125adc33d /lib/Sema/SemaTemplateInstantiate.cpp | |
parent | faccd72e2448b552f17992eaba6cfe12ec497e58 (diff) |
Collect multiple levels of template arguments into a new type,
MultiLevelTemplateArgumentList. This is a baby step toward
instantiating member templates; no intended functionality change yet.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@80380 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaTemplateInstantiate.cpp')
-rw-r--r-- | lib/Sema/SemaTemplateInstantiate.cpp | 51 |
1 files changed, 30 insertions, 21 deletions
diff --git a/lib/Sema/SemaTemplateInstantiate.cpp b/lib/Sema/SemaTemplateInstantiate.cpp index 4642251d95..b330ae960b 100644 --- a/lib/Sema/SemaTemplateInstantiate.cpp +++ b/lib/Sema/SemaTemplateInstantiate.cpp @@ -28,30 +28,39 @@ using namespace clang; /// \brief Retrieve the template argument list that should be used to /// instantiate the given declaration. -const TemplateArgumentList & +MultiLevelTemplateArgumentList Sema::getTemplateInstantiationArgs(NamedDecl *D) { - // Template arguments for a class template specialization. - if (ClassTemplateSpecializationDecl *Spec - = dyn_cast<ClassTemplateSpecializationDecl>(D)) - return Spec->getTemplateInstantiationArgs(); - - // Template arguments for a function template specialization. - if (FunctionDecl *Function = dyn_cast<FunctionDecl>(D)) - if (const TemplateArgumentList *TemplateArgs - = Function->getTemplateSpecializationArgs()) - return *TemplateArgs; + // Accumulate the set of template argument lists in this structure. + MultiLevelTemplateArgumentList Result; + + DeclContext *Ctx = dyn_cast<DeclContext>(D); + if (!Ctx) + Ctx = D->getDeclContext(); + + for (; !Ctx->isFileContext(); Ctx = Ctx->getParent()) { + // Add template arguments from a class template instantiation. + if (ClassTemplateSpecializationDecl *Spec + = dyn_cast<ClassTemplateSpecializationDecl>(Ctx)) { + // We're done when we hit an explicit specialization. + if (Spec->getSpecializationKind() == TSK_ExplicitSpecialization) + break; + + Result.addOuterTemplateArguments(&Spec->getTemplateInstantiationArgs()); + continue; + } + + // Add template arguments from a function template specialization. + if (FunctionDecl *Function = dyn_cast<FunctionDecl>(Ctx)) { + // FIXME: Check whether this is an explicit specialization. + if (const TemplateArgumentList *TemplateArgs + = Function->getTemplateSpecializationArgs()) + Result.addOuterTemplateArguments(TemplateArgs); - // Template arguments for a member of a class template specialization. - DeclContext *EnclosingTemplateCtx = D->getDeclContext(); - while (!isa<ClassTemplateSpecializationDecl>(EnclosingTemplateCtx)) { - assert(!EnclosingTemplateCtx->isFileContext() && - "Tried to get the instantiation arguments of a non-template"); - EnclosingTemplateCtx = EnclosingTemplateCtx->getParent(); + continue; + } } - - ClassTemplateSpecializationDecl *EnclosingTemplate - = cast<ClassTemplateSpecializationDecl>(EnclosingTemplateCtx); - return EnclosingTemplate->getTemplateInstantiationArgs(); + + return Result; } Sema::InstantiatingTemplate:: |