diff options
author | Erich Keane <erich.keane@intel.com> | 2022-03-01 18:22:44 +0300 |
---|---|---|
committer | Erich Keane <erich.keane@intel.com> | 2022-03-01 19:31:51 +0300 |
commit | c601377b23767ede02fe5bbe880c05d420b53250 (patch) | |
tree | 0c0948c47fd9ca4256baa9aa36704ff755707f1b /clang | |
parent | 32ac21d04909da0d50d3b24100d5d9ab30b29a95 (diff) |
[NFC]Promote addInstantiatedParametersToScope to a private Sema function
This is used a few places in SemaTeplateInstantiateDecl, but is going
to be useful in SemaConcept.cpp as well. This patch switches it to be
a private function in Sema.
Differential Revision: https://reviews.llvm.org/D120729
Diffstat (limited to 'clang')
-rw-r--r-- | clang/include/clang/Sema/Sema.h | 8 | ||||
-rw-r--r-- | clang/lib/Sema/SemaTemplateInstantiateDecl.cpp | 37 |
2 files changed, 25 insertions, 20 deletions
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h index 0840f3a6cdb7..d905db93ccff 100644 --- a/clang/include/clang/Sema/Sema.h +++ b/clang/include/clang/Sema/Sema.h @@ -6935,6 +6935,14 @@ private: llvm::ContextualFoldingSet<ConstraintSatisfaction, const ASTContext &> SatisfactionCache; + /// Introduce the instantiated function parameters into the local + /// instantiation scope, and set the parameter names to those used + /// in the template. + bool addInstantiatedParametersToScope( + FunctionDecl *Function, const FunctionDecl *PatternDecl, + LocalInstantiationScope &Scope, + const MultiLevelTemplateArgumentList &TemplateArgs); + public: const NormalizedConstraint * getNormalizedAssociatedConstraints( diff --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp index 237886c906a5..49fe11d3fa6d 100644 --- a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp +++ b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp @@ -4377,10 +4377,10 @@ TemplateDeclInstantiator::SubstFunctionType(FunctionDecl *D, /// Introduce the instantiated function parameters into the local /// instantiation scope, and set the parameter names to those used /// in the template. -static bool addInstantiatedParametersToScope(Sema &S, FunctionDecl *Function, - const FunctionDecl *PatternDecl, - LocalInstantiationScope &Scope, - const MultiLevelTemplateArgumentList &TemplateArgs) { +bool Sema::addInstantiatedParametersToScope( + FunctionDecl *Function, const FunctionDecl *PatternDecl, + LocalInstantiationScope &Scope, + const MultiLevelTemplateArgumentList &TemplateArgs) { unsigned FParamIdx = 0; for (unsigned I = 0, N = PatternDecl->getNumParams(); I != N; ++I) { const ParmVarDecl *PatternParam = PatternDecl->getParamDecl(I); @@ -4396,9 +4396,9 @@ static bool addInstantiatedParametersToScope(Sema &S, FunctionDecl *Function, // it's instantiation-dependent. // FIXME: Updating the type to work around this is at best fragile. if (!PatternDecl->getType()->isDependentType()) { - QualType T = S.SubstType(PatternParam->getType(), TemplateArgs, - FunctionParam->getLocation(), - FunctionParam->getDeclName()); + QualType T = SubstType(PatternParam->getType(), TemplateArgs, + FunctionParam->getLocation(), + FunctionParam->getDeclName()); if (T.isNull()) return true; FunctionParam->setType(T); @@ -4411,8 +4411,8 @@ static bool addInstantiatedParametersToScope(Sema &S, FunctionDecl *Function, // Expand the parameter pack. Scope.MakeInstantiatedLocalArgPack(PatternParam); - Optional<unsigned> NumArgumentsInExpansion - = S.getNumArgumentsInExpansion(PatternParam->getType(), TemplateArgs); + Optional<unsigned> NumArgumentsInExpansion = + getNumArgumentsInExpansion(PatternParam->getType(), TemplateArgs); if (NumArgumentsInExpansion) { QualType PatternType = PatternParam->getType()->castAs<PackExpansionType>()->getPattern(); @@ -4420,10 +4420,10 @@ static bool addInstantiatedParametersToScope(Sema &S, FunctionDecl *Function, ParmVarDecl *FunctionParam = Function->getParamDecl(FParamIdx); FunctionParam->setDeclName(PatternParam->getDeclName()); if (!PatternDecl->getType()->isDependentType()) { - Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(S, Arg); - QualType T = S.SubstType(PatternType, TemplateArgs, - FunctionParam->getLocation(), - FunctionParam->getDeclName()); + Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(*this, Arg); + QualType T = + SubstType(PatternType, TemplateArgs, FunctionParam->getLocation(), + FunctionParam->getDeclName()); if (T.isNull()) return true; FunctionParam->setType(T); @@ -4487,8 +4487,7 @@ bool Sema::InstantiateDefaultArgument(SourceLocation CallLoc, FunctionDecl *FD, FunctionDecl *Pattern = FD->getTemplateInstantiationPattern( /*ForDefinition*/ false); - if (addInstantiatedParametersToScope(*this, FD, Pattern, Local, - TemplateArgs)) + if (addInstantiatedParametersToScope(FD, Pattern, Local, TemplateArgs)) return true; runWithSufficientStackSpace(CallLoc, [&] { @@ -4561,8 +4560,7 @@ void Sema::InstantiateExceptionSpec(SourceLocation PointOfInstantiation, // we don't store enough information to map back to the friend declaration in // the template. FunctionDecl *Template = Proto->getExceptionSpecTemplate(); - if (addInstantiatedParametersToScope(*this, Decl, Template, Scope, - TemplateArgs)) { + if (addInstantiatedParametersToScope(Decl, Template, Scope, TemplateArgs)) { UpdateExceptionSpec(Decl, EST_None); return; } @@ -4603,8 +4601,7 @@ bool Sema::CheckInstantiatedFunctionTemplateConstraints( MultiLevelTemplateArgumentList MLTAL( *Decl->getTemplateSpecializationArgs()); if (addInstantiatedParametersToScope( - *this, Decl, Decl->getPrimaryTemplate()->getTemplatedDecl(), - Scope, MLTAL)) + Decl, Decl->getPrimaryTemplate()->getTemplatedDecl(), Scope, MLTAL)) return true; } Qualifiers ThisQuals; @@ -5050,7 +5047,7 @@ void Sema::InstantiateFunctionDefinition(SourceLocation PointOfInstantiation, // PushDeclContext because we don't have a scope. Sema::ContextRAII savedContext(*this, Function); - if (addInstantiatedParametersToScope(*this, Function, PatternDecl, Scope, + if (addInstantiatedParametersToScope(Function, PatternDecl, Scope, TemplateArgs)) return; |