diff options
author | John McCall <rjmccall@apple.com> | 2010-03-11 09:03:00 +0000 |
---|---|---|
committer | John McCall <rjmccall@apple.com> | 2010-03-11 09:03:00 +0000 |
commit | 21ef0fa27b0783ec0bc6aa5b524feb2ec840f952 (patch) | |
tree | 68e3c812ea882f8f9094c6de1cd77c50b8f2e13e /lib/Sema/SemaTemplateInstantiate.cpp | |
parent | 92b7f70c924cbf4514e9e434cea7def51ab49860 (diff) |
Maintain type source information for functions through template
instantiation. Based on a patch by Enea Zaffanella! I found a way to
reduce some of the redundancy between TreeTransform's "standard"
FunctionProtoType transformation and TemplateInstantiator's override,
and I killed off the old SubstFunctionType by adding type source info
for the last cases where we were creating FunctionDecls without TSI
(at least that get passed through template instantiation).
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@98252 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaTemplateInstantiate.cpp')
-rw-r--r-- | lib/Sema/SemaTemplateInstantiate.cpp | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/lib/Sema/SemaTemplateInstantiate.cpp b/lib/Sema/SemaTemplateInstantiate.cpp index 8f73337e43..19c257d5b7 100644 --- a/lib/Sema/SemaTemplateInstantiate.cpp +++ b/lib/Sema/SemaTemplateInstantiate.cpp @@ -567,6 +567,15 @@ namespace { Sema::OwningExprResult TransformTemplateParmRefExpr(DeclRefExpr *E, NonTypeTemplateParmDecl *D); + /// \brief Transforms a function proto type by performing + /// substitution in the function parameters, possibly adjusting + /// their types and marking default arguments as uninstantiated. + bool TransformFunctionTypeParams(FunctionProtoTypeLoc TL, + llvm::SmallVectorImpl<QualType> &PTypes, + llvm::SmallVectorImpl<ParmVarDecl*> &PVars); + + ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm); + /// \brief Transforms a template type parameter type by performing /// substitution of the corresponding template type argument. QualType TransformTemplateTypeParmType(TypeLocBuilder &TLB, @@ -859,6 +868,59 @@ Sema::OwningExprResult TemplateInstantiator::TransformCXXDefaultArgExpr( } +bool +TemplateInstantiator::TransformFunctionTypeParams(FunctionProtoTypeLoc TL, + llvm::SmallVectorImpl<QualType> &PTypes, + llvm::SmallVectorImpl<ParmVarDecl*> &PVars) { + // Create a local instantiation scope for the parameters. + Sema::LocalInstantiationScope + Scope(SemaRef, SemaRef.CurrentInstantiationScope != 0); + + if (TreeTransform<TemplateInstantiator>:: + TransformFunctionTypeParams(TL, PTypes, PVars)) + return true; + + // Check instantiated parameters. + if (SemaRef.CheckInstantiatedParams(PVars)) + return true; + + return false; +} + +ParmVarDecl * +TemplateInstantiator::TransformFunctionTypeParam(ParmVarDecl *OldParm) { + TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo(); + TypeSourceInfo *NewDI = getDerived().TransformType(OldDI); + if (!NewDI) + return 0; + + // TODO: do we have to clone this decl if the types match and + // there's no default argument? + + ParmVarDecl *NewParm + = ParmVarDecl::Create(SemaRef.Context, + OldParm->getDeclContext(), + OldParm->getLocation(), + OldParm->getIdentifier(), + NewDI->getType(), + NewDI, + OldParm->getStorageClass(), + /* DefArg */ NULL); + + // Maybe adjust new parameter type. + NewParm->setType(SemaRef.adjustParameterType(NewParm->getType())); + + // Mark the (new) default argument as uninstantiated (if any). + if (OldParm->hasUninstantiatedDefaultArg()) { + Expr *Arg = OldParm->getUninstantiatedDefaultArg(); + NewParm->setUninstantiatedDefaultArg(Arg); + } else if (Expr *Arg = OldParm->getDefaultArg()) + NewParm->setUninstantiatedDefaultArg(Arg); + + SemaRef.CurrentInstantiationScope->InstantiatedLocal(OldParm, NewParm); + return NewParm; +} + QualType TemplateInstantiator::TransformTemplateTypeParmType(TypeLocBuilder &TLB, TemplateTypeParmTypeLoc TL, |