aboutsummaryrefslogtreecommitdiff
path: root/lib/Sema/SemaTemplateInstantiate.cpp
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2009-08-20 07:17:43 +0000
committerDouglas Gregor <dgregor@apple.com>2009-08-20 07:17:43 +0000
commit43959a93c6aba8b03b09116fe077f4ce8e80005e (patch)
tree4b456c1cc2755e9741e84b310e13b76de03f2a18 /lib/Sema/SemaTemplateInstantiate.cpp
parent357f7ce199fdeb20634595dbfba5484d1f908ed2 (diff)
Refactor the instantiation of statements into a generic tree
transformation. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@79519 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaTemplateInstantiate.cpp')
-rw-r--r--lib/Sema/SemaTemplateInstantiate.cpp77
1 files changed, 48 insertions, 29 deletions
diff --git a/lib/Sema/SemaTemplateInstantiate.cpp b/lib/Sema/SemaTemplateInstantiate.cpp
index 45214bfd6c..0f66c45b26 100644
--- a/lib/Sema/SemaTemplateInstantiate.cpp
+++ b/lib/Sema/SemaTemplateInstantiate.cpp
@@ -294,12 +294,14 @@ namespace {
DeclarationName Entity;
public:
+ typedef TreeTransform<TemplateInstantiator> inherited;
+
TemplateInstantiator(Sema &SemaRef,
const TemplateArgumentList &TemplateArgs,
SourceLocation Loc,
DeclarationName Entity)
- : TreeTransform<TemplateInstantiator>(SemaRef), TemplateArgs(TemplateArgs),
- Loc(Loc), Entity(Entity) { }
+ : inherited(SemaRef), TemplateArgs(TemplateArgs), Loc(Loc),
+ Entity(Entity) { }
/// \brief Determine whether the given type \p T has already been
/// transformed.
@@ -319,21 +321,20 @@ namespace {
/// \brief Transform the given declaration by instantiating a reference to
/// this declaration.
Decl *TransformDecl(Decl *D);
-
- Sema::OwningStmtResult TransformStmt(Stmt *S) {
- return SemaRef.InstantiateStmt(S, TemplateArgs);
- }
- Sema::OwningStmtResult TransformCompoundStmt(CompoundStmt *S,
- bool IsStmtExpr) {
- return SemaRef.InstantiateCompoundStmt(S, TemplateArgs, IsStmtExpr);
- }
+ /// \brief Transform the definition of the given declaration by
+ /// instantiating it.
+ Decl *TransformDefinition(Decl *D);
+
+ /// \brief Rebuild the exception declaration and register the declaration
+ /// as an instantiated local.
+ VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl, QualType T,
+ DeclaratorInfo *Declarator,
+ IdentifierInfo *Name,
+ SourceLocation Loc, SourceRange TypeRange);
Sema::OwningExprResult TransformDeclRefExpr(DeclRefExpr *E);
- Sema::OwningExprResult
- TransformCXXConditionDeclExpr(CXXConditionDeclExpr *E);
-
/// \brief Transforms a template type parameter type by performing
/// substitution of the corresponding template type argument.
QualType TransformTemplateTypeParmType(const TemplateTypeParmType *T);
@@ -357,6 +358,29 @@ Decl *TemplateInstantiator::TransformDecl(Decl *D) {
return SemaRef.InstantiateCurrentDeclRef(cast_or_null<NamedDecl>(D));
}
+Decl *TemplateInstantiator::TransformDefinition(Decl *D) {
+ Decl *Inst = getSema().InstantiateDecl(D, getSema().CurContext, TemplateArgs);
+ if (!Inst)
+ return 0;
+
+ getSema().CurrentInstantiationScope->InstantiatedLocal(D, Inst);
+ return Inst;
+}
+
+VarDecl *
+TemplateInstantiator::RebuildExceptionDecl(VarDecl *ExceptionDecl,
+ QualType T,
+ DeclaratorInfo *Declarator,
+ IdentifierInfo *Name,
+ SourceLocation Loc,
+ SourceRange TypeRange) {
+ VarDecl *Var = inherited::RebuildExceptionDecl(ExceptionDecl, T, Declarator,
+ Name, Loc, TypeRange);
+ if (Var && !Var->isInvalidDecl())
+ getSema().CurrentInstantiationScope->InstantiatedLocal(ExceptionDecl, Var);
+ return Var;
+}
+
Sema::OwningExprResult
TemplateInstantiator::TransformDeclRefExpr(DeclRefExpr *E) {
// FIXME: Clean this up a bit
@@ -428,22 +452,6 @@ TemplateInstantiator::TransformDeclRefExpr(DeclRefExpr *E) {
/*FIXME:*/false);
}
-Sema::OwningExprResult
-TemplateInstantiator::TransformCXXConditionDeclExpr(CXXConditionDeclExpr *E) {
- VarDecl *Var
- = cast_or_null<VarDecl>(SemaRef.InstantiateDecl(E->getVarDecl(),
- SemaRef.CurContext,
- TemplateArgs));
- if (!Var)
- return SemaRef.ExprError();
-
- SemaRef.CurrentInstantiationScope->InstantiatedLocal(E->getVarDecl(), Var);
- return SemaRef.Owned(new (SemaRef.Context) CXXConditionDeclExpr(
- E->getStartLoc(),
- SourceLocation(),
- Var));
-}
-
QualType
TemplateInstantiator::TransformTemplateTypeParmType(
const TemplateTypeParmType *T) {
@@ -840,6 +848,17 @@ void Sema::InstantiateClassTemplateSpecializationMembers(
ClassTemplateSpec->getTemplateArgs());
}
+Sema::OwningStmtResult
+Sema::InstantiateStmt(Stmt *S, const TemplateArgumentList &TemplateArgs) {
+ if (!S)
+ return Owned(S);
+
+ TemplateInstantiator Instantiator(*this, TemplateArgs,
+ SourceLocation(),
+ DeclarationName());
+ return Instantiator.TransformStmt(S);
+}
+
Sema::OwningExprResult
Sema::InstantiateExpr(Expr *E, const TemplateArgumentList &TemplateArgs) {
if (!E)