From 1d752d7d68359fd8f7701585d4658aa70e129261 Mon Sep 17 00:00:00 2001 From: Douglas Gregor Date: Wed, 2 Mar 2011 18:46:51 +0000 Subject: [PATCH] Kill off the TreeTransform::TransformTemplateName overload that has poor source-location information. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@126852 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Sema/Sema.h | 3 +- lib/Sema/SemaTemplate.cpp | 14 ++- lib/Sema/SemaTemplateInstantiate.cpp | 65 ++------------ lib/Sema/TreeTransform.h | 128 ++------------------------- 4 files changed, 22 insertions(+), 188 deletions(-) diff --git a/include/clang/Sema/Sema.h b/include/clang/Sema/Sema.h index fcc29442a5..9e3d19e309 100644 --- a/include/clang/Sema/Sema.h +++ b/include/clang/Sema/Sema.h @@ -4338,7 +4338,8 @@ public: SubstDeclarationNameInfo(const DeclarationNameInfo &NameInfo, const MultiLevelTemplateArgumentList &TemplateArgs); TemplateName - SubstTemplateName(TemplateName Name, SourceLocation Loc, + SubstTemplateName(NestedNameSpecifierLoc QualifierLoc, TemplateName Name, + SourceLocation Loc, const MultiLevelTemplateArgumentList &TemplateArgs); bool Subst(const TemplateArgumentLoc *Args, unsigned NumArgs, TemplateArgumentListInfo &Result, diff --git a/lib/Sema/SemaTemplate.cpp b/lib/Sema/SemaTemplate.cpp index 90b0d7e29b..49f9a1de1e 100644 --- a/lib/Sema/SemaTemplate.cpp +++ b/lib/Sema/SemaTemplate.cpp @@ -2105,7 +2105,6 @@ bool Sema::CheckTemplateTypeArgument(TemplateTypeParmDecl *Param, /// /// \param Converted the list of template arguments provided for template /// parameters that precede \p Param in the template parameter list. -/// /// \returns the substituted template argument, or NULL if an error occurred. static TypeSourceInfo * SubstDefaultTemplateArgument(Sema &SemaRef, @@ -2202,8 +2201,8 @@ SubstDefaultTemplateArgument(Sema &SemaRef, /// \param Converted the list of template arguments provided for template /// parameters that precede \p Param in the template parameter list. /// -/// \param QualifierLoc The nested-name-specifier, with source-location -/// information, which will also be instantiated and updated. +/// \param QualifierLoc Will be set to the nested-name-specifier (with +/// source-location information) that precedes the template name. /// /// \returns the substituted template argument, or NULL if an error occurred. static TemplateName @@ -2226,6 +2225,7 @@ SubstDefaultTemplateArgument(Sema &SemaRef, SourceRange(TemplateLoc, RAngleLoc)); // Substitute into the nested-name-specifier first, + QualifierLoc = Param->getDefaultArgument().getTemplateQualifierLoc(); if (QualifierLoc) { QualifierLoc = SemaRef.SubstNestedNameSpecifierLoc(QualifierLoc, AllTemplateArgs); @@ -2233,7 +2233,7 @@ SubstDefaultTemplateArgument(Sema &SemaRef, return TemplateName(); } - return SemaRef.SubstTemplateName( + return SemaRef.SubstTemplateName(QualifierLoc, Param->getDefaultArgument().getArgument().getAsTemplate(), Param->getDefaultArgument().getTemplateNameLoc(), AllTemplateArgs); @@ -2286,8 +2286,7 @@ Sema::SubstDefaultTemplateArgumentIfAvailable(TemplateDecl *Template, return TemplateArgumentLoc(); - NestedNameSpecifierLoc QualifierLoc - = TempTempParm->getDefaultArgument().getTemplateQualifierLoc(); + NestedNameSpecifierLoc QualifierLoc; TemplateName TName = SubstDefaultTemplateArgument(*this, Template, TemplateLoc, RAngleLoc, @@ -2679,8 +2678,7 @@ bool Sema::CheckTemplateArgumentList(TemplateDecl *Template, break; } - NestedNameSpecifierLoc QualifierLoc - = TempParm->getDefaultArgument().getTemplateQualifierLoc(); + NestedNameSpecifierLoc QualifierLoc; TemplateName Name = SubstDefaultTemplateArgument(*this, Template, TemplateLoc, RAngleLoc, diff --git a/lib/Sema/SemaTemplateInstantiate.cpp b/lib/Sema/SemaTemplateInstantiate.cpp index 287dc173e1..24acb7a6e0 100644 --- a/lib/Sema/SemaTemplateInstantiate.cpp +++ b/lib/Sema/SemaTemplateInstantiate.cpp @@ -733,10 +733,6 @@ namespace { NestedNameSpecifierLoc QualifierLoc, QualType T); - TemplateName TransformTemplateName(TemplateName Name, - QualType ObjectType = QualType(), - NamedDecl *FirstQualifierInScope = 0); - TemplateName TransformTemplateName(CXXScopeSpec &SS, TemplateName Name, SourceLocation NameLoc, @@ -929,60 +925,6 @@ TemplateInstantiator::RebuildElaboratedType(SourceLocation KeywordLoc, T); } -TemplateName TemplateInstantiator::TransformTemplateName(TemplateName Name, - QualType ObjectType, - NamedDecl *FirstQualifierInScope) { - if (TemplateTemplateParmDecl *TTP - = dyn_cast_or_null(Name.getAsTemplateDecl())) { - if (TTP->getDepth() < TemplateArgs.getNumLevels()) { - // If the corresponding template argument is NULL or non-existent, it's - // because we are performing instantiation from explicitly-specified - // template arguments in a function template, but there were some - // arguments left unspecified. - if (!TemplateArgs.hasTemplateArgument(TTP->getDepth(), - TTP->getPosition())) - return Name; - - TemplateArgument Arg = TemplateArgs(TTP->getDepth(), TTP->getPosition()); - - if (TTP->isParameterPack()) { - assert(Arg.getKind() == TemplateArgument::Pack && - "Missing argument pack"); - - if (getSema().ArgumentPackSubstitutionIndex == -1) { - // We have the template argument pack to substitute, but we're not - // actually expanding the enclosing pack expansion yet. So, just - // keep the entire argument pack. - return getSema().Context.getSubstTemplateTemplateParmPack(TTP, Arg); - } - - assert(getSema().ArgumentPackSubstitutionIndex < (int)Arg.pack_size()); - Arg = Arg.pack_begin()[getSema().ArgumentPackSubstitutionIndex]; - } - - TemplateName Template = Arg.getAsTemplate(); - assert(!Template.isNull() && Template.getAsTemplateDecl() && - "Wrong kind of template template argument"); - return Template; - } - } - - if (SubstTemplateTemplateParmPackStorage *SubstPack - = Name.getAsSubstTemplateTemplateParmPack()) { - if (getSema().ArgumentPackSubstitutionIndex == -1) - return Name; - - const TemplateArgument &ArgPack = SubstPack->getArgumentPack(); - assert(getSema().ArgumentPackSubstitutionIndex < (int)ArgPack.pack_size() && - "Pack substitution index out-of-range"); - return ArgPack.pack_begin()[getSema().ArgumentPackSubstitutionIndex] - .getAsTemplate(); - } - - return inherited::TransformTemplateName(Name, ObjectType, - FirstQualifierInScope); -} - TemplateName TemplateInstantiator::TransformTemplateName(CXXScopeSpec &SS, TemplateName Name, SourceLocation NameLoc, @@ -2231,11 +2173,14 @@ Sema::SubstDeclarationNameInfo(const DeclarationNameInfo &NameInfo, } TemplateName -Sema::SubstTemplateName(TemplateName Name, SourceLocation Loc, +Sema::SubstTemplateName(NestedNameSpecifierLoc QualifierLoc, + TemplateName Name, SourceLocation Loc, const MultiLevelTemplateArgumentList &TemplateArgs) { TemplateInstantiator Instantiator(*this, TemplateArgs, Loc, DeclarationName()); - return Instantiator.TransformTemplateName(Name); + CXXScopeSpec SS; + SS.Adopt(QualifierLoc); + return Instantiator.TransformTemplateName(SS, Name, Loc); } bool Sema::Subst(const TemplateArgumentLoc *Args, unsigned NumArgs, diff --git a/lib/Sema/TreeTransform.h b/lib/Sema/TreeTransform.h index 31a4bec233..6b25d33bbc 100644 --- a/lib/Sema/TreeTransform.h +++ b/lib/Sema/TreeTransform.h @@ -405,15 +405,6 @@ public: DeclarationNameInfo TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo); - /// \brief Transform the given template name. - /// - /// By default, transforms the template name by transforming the declarations - /// and nested-name-specifiers that occur within the template name. - /// Subclasses may override this function to provide alternate behavior. - TemplateName TransformTemplateName(TemplateName Name, - QualType ObjectType = QualType(), - NamedDecl *FirstQualifierInScope = 0); - /// \brief Transform the given template name. /// /// \param SS The nested-name-specifier that qualifies the template @@ -2714,113 +2705,6 @@ TreeTransform return DeclarationNameInfo(); } -template -TemplateName -TreeTransform::TransformTemplateName(TemplateName Name, - QualType ObjectType, - NamedDecl *FirstQualifierInScope) { - // FIXME: This routine needs to go away. - SourceLocation Loc = getDerived().getBaseLocation(); - - if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) { - NestedNameSpecifier *NNS - = getDerived().TransformNestedNameSpecifier(QTN->getQualifier(), - /*FIXME*/ SourceRange(Loc), - ObjectType, - FirstQualifierInScope); - if (!NNS) - return TemplateName(); - - if (TemplateDecl *Template = QTN->getTemplateDecl()) { - TemplateDecl *TransTemplate - = cast_or_null(getDerived().TransformDecl(Loc, Template)); - if (!TransTemplate) - return TemplateName(); - - if (!getDerived().AlwaysRebuild() && - NNS == QTN->getQualifier() && - TransTemplate == Template) - return Name; - - CXXScopeSpec SS; - SS.MakeTrivial(SemaRef.Context, NNS, Loc); - return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(), - TransTemplate); - } - - // These should be getting filtered out before they make it into the AST. - llvm_unreachable("overloaded template name survived to here"); - } - - if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) { - NestedNameSpecifier *NNS = DTN->getQualifier(); - if (NNS) { - NNS = getDerived().TransformNestedNameSpecifier(NNS, - /*FIXME:*/SourceRange(Loc), - ObjectType, - FirstQualifierInScope); - if (!NNS) return TemplateName(); - - // These apply to the scope specifier, not the template. - ObjectType = QualType(); - FirstQualifierInScope = 0; - } - - if (!getDerived().AlwaysRebuild() && - NNS == DTN->getQualifier() && - ObjectType.isNull()) - return Name; - - // FIXME: Bad source-location information all around. - CXXScopeSpec SS; - SS.MakeTrivial(SemaRef.Context, NNS, getDerived().getBaseLocation()); - if (DTN->isIdentifier()) { - return getDerived().RebuildTemplateName(SS, - *DTN->getIdentifier(), - getDerived().getBaseLocation(), - ObjectType, - FirstQualifierInScope); - } - - return getDerived().RebuildTemplateName(SS, DTN->getOperator(), - getDerived().getBaseLocation(), - ObjectType); - } - - if (TemplateDecl *Template = Name.getAsTemplateDecl()) { - TemplateDecl *TransTemplate - = cast_or_null(getDerived().TransformDecl(Loc, Template)); - if (!TransTemplate) - return TemplateName(); - - if (!getDerived().AlwaysRebuild() && - TransTemplate == Template) - return Name; - - return TemplateName(TransTemplate); - } - - if (SubstTemplateTemplateParmPackStorage *SubstPack - = Name.getAsSubstTemplateTemplateParmPack()) { - TemplateTemplateParmDecl *TransParam - = cast_or_null( - getDerived().TransformDecl(Loc, SubstPack->getParameterPack())); - if (!TransParam) - return TemplateName(); - - if (!getDerived().AlwaysRebuild() && - TransParam == SubstPack->getParameterPack()) - return Name; - - return getDerived().RebuildTemplateName(TransParam, - SubstPack->getArgumentPack()); - } - - // These should be getting filtered out before they reach the AST. - llvm_unreachable("overloaded function decl survived to here"); - return TemplateName(); -} - template TemplateName TreeTransform::TransformTemplateName(CXXScopeSpec &SS, @@ -3007,9 +2891,11 @@ bool TreeTransform::TransformTemplateArgument( return true; } - TemporaryBase Rebase(*this, Input.getLocation(), DeclarationName()); + CXXScopeSpec SS; + SS.Adopt(QualifierLoc); TemplateName Template - = getDerived().TransformTemplateName(Arg.getAsTemplate()); + = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(), + Input.getTemplateNameLoc()); if (Template.isNull()) return true; @@ -4399,8 +4285,12 @@ QualType TreeTransform::TransformTemplateSpecializationType( TemplateSpecializationTypeLoc TL) { const TemplateSpecializationType *T = TL.getTypePtr(); + // The nested-name-specifier never matters in a TemplateSpecializationType, + // because we can't have a dependent nested-name-specifier anyway. + CXXScopeSpec SS; TemplateName Template - = getDerived().TransformTemplateName(T->getTemplateName()); + = getDerived().TransformTemplateName(SS, T->getTemplateName(), + TL.getTemplateNameLoc()); if (Template.isNull()) return QualType(); -- 2.40.0