From 4f3e3811d17a82873361dac206b8ca80c1acc886 Mon Sep 17 00:00:00 2001 From: Richard Smith Date: Sat, 20 May 2017 01:36:41 +0000 Subject: [PATCH] Rename RAII objects for performing eager instantiation to have names that describe what they're for, not how they do it, and factor out a bit more common code into them. llvm-svn: 303479 --- clang/include/clang/Sema/Sema.h | 23 +++++--- clang/lib/Sema/SemaTemplateInstantiateDecl.cpp | 73 +++++++------------------- 2 files changed, 34 insertions(+), 62 deletions(-) diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h index 36ae650..fcd3ee7 100644 --- a/clang/include/clang/Sema/Sema.h +++ b/clang/include/clang/Sema/Sema.h @@ -7383,9 +7383,9 @@ public: /// but have not yet been performed. std::deque PendingInstantiations; - class SavePendingInstantiationsAndVTableUsesRAII { + class GlobalEagerInstantiationScope { public: - SavePendingInstantiationsAndVTableUsesRAII(Sema &S, bool Enabled) + GlobalEagerInstantiationScope(Sema &S, bool Enabled) : S(S), Enabled(Enabled) { if (!Enabled) return; @@ -7393,7 +7393,14 @@ public: SavedVTableUses.swap(S.VTableUses); } - ~SavePendingInstantiationsAndVTableUsesRAII() { + void perform() { + if (Enabled) { + S.DefineUsedVTables(); + S.PerformPendingInstantiations(); + } + } + + ~GlobalEagerInstantiationScope() { if (!Enabled) return; // Restore the set of pending vtables. @@ -7423,14 +7430,16 @@ public: /// types, static variables, enumerators, etc. std::deque PendingLocalImplicitInstantiations; - class SavePendingLocalImplicitInstantiationsRAII { + class LocalEagerInstantiationScope { public: - SavePendingLocalImplicitInstantiationsRAII(Sema &S): S(S) { + LocalEagerInstantiationScope(Sema &S) : S(S) { SavedPendingLocalImplicitInstantiations.swap( S.PendingLocalImplicitInstantiations); } - ~SavePendingLocalImplicitInstantiationsRAII() { + void perform() { S.PerformPendingInstantiations(/*LocalOnly=*/true); } + + ~LocalEagerInstantiationScope() { assert(S.PendingLocalImplicitInstantiations.empty() && "there shouldn't be any pending local implicit instantiations"); SavedPendingLocalImplicitInstantiations.swap( @@ -7440,7 +7449,7 @@ public: private: Sema &S; std::deque - SavedPendingLocalImplicitInstantiations; + SavedPendingLocalImplicitInstantiations; }; /// A helper class for building up ExtParameterInfos. diff --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp index 03df6fd..e7523ce 100644 --- a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp +++ b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp @@ -1540,8 +1540,7 @@ Decl *TemplateDeclInstantiator::VisitCXXRecordDecl(CXXRecordDecl *D) { // DR1484 clarifies that the members of a local class are instantiated as part // of the instantiation of their enclosing entity. if (D->isCompleteDefinition() && D->isLocalClass()) { - Sema::SavePendingLocalImplicitInstantiationsRAII - SavedPendingLocalImplicitInstantiations(SemaRef); + Sema::LocalEagerInstantiationScope LocalInstantiations(SemaRef); SemaRef.InstantiateClass(D->getLocation(), Record, D, TemplateArgs, TSK_ImplicitInstantiation, @@ -1555,7 +1554,7 @@ Decl *TemplateDeclInstantiator::VisitCXXRecordDecl(CXXRecordDecl *D) { // This class may have local implicit instantiations that need to be // performed within this scope. - SemaRef.PerformPendingInstantiations(/*LocalOnly=*/true); + LocalInstantiations.perform(); } SemaRef.DiagnoseUnusedNestedTypedefs(Record); @@ -3812,10 +3811,9 @@ void Sema::InstantiateFunctionDefinition(SourceLocation PointOfInstantiation, // while we're still within our own instantiation context. // This has to happen before LateTemplateParser below is called, so that // it marks vtables used in late parsed templates as used. - SavePendingLocalImplicitInstantiationsRAII - SavedPendingLocalImplicitInstantiations(*this); - SavePendingInstantiationsAndVTableUsesRAII - SavePendingInstantiationsAndVTableUses(*this, /*Enabled=*/Recursive); + GlobalEagerInstantiationScope GlobalInstantiations(*this, + /*Enabled=*/Recursive); + LocalEagerInstantiationScope LocalInstantiations(*this); // Call the LateTemplateParser callback if there is a need to late parse // a templated function definition. @@ -3942,20 +3940,9 @@ void Sema::InstantiateFunctionDefinition(SourceLocation PointOfInstantiation, // This class may have local implicit instantiations that need to be // instantiation within this scope. - PerformPendingInstantiations(/*LocalOnly=*/true); + LocalInstantiations.perform(); Scope.Exit(); - - if (Recursive) { - // Define any pending vtables. - DefineUsedVTables(); - - // Instantiate any pending implicit instantiations found during the - // instantiation of this template. - PerformPendingInstantiations(); - - // PendingInstantiations and VTableUses are restored through - // SavePendingInstantiationsAndVTableUses's destructor. - } + GlobalInstantiations.perform(); } VarTemplateSpecializationDecl *Sema::BuildVarTemplateInstantiation( @@ -4287,10 +4274,10 @@ void Sema::InstantiateVariableDefinition(SourceLocation PointOfInstantiation, // If we're performing recursive template instantiation, create our own // queue of pending implicit instantiations that we will instantiate // later, while we're still within our own instantiation context. - SavePendingInstantiationsAndVTableUsesRAII - SavePendingInstantiationsAndVTableUses(*this, /*Enabled=*/Recursive); - + GlobalEagerInstantiationScope GlobalInstantiations(*this, + /*Enabled=*/Recursive); LocalInstantiationScope Local(*this); + LocalEagerInstantiationScope LocalInstantiations(*this); // Enter the scope of this instantiation. We don't use // PushDeclContext because we don't have a scope. @@ -4303,21 +4290,9 @@ void Sema::InstantiateVariableDefinition(SourceLocation PointOfInstantiation, // This variable may have local implicit instantiations that need to be // instantiated within this scope. - PerformPendingInstantiations(/*LocalOnly=*/true); - + LocalInstantiations.perform(); Local.Exit(); - - if (Recursive) { - // Define any newly required vtables. - DefineUsedVTables(); - - // Instantiate any pending implicit instantiations found during the - // instantiation of this template. - PerformPendingInstantiations(); - - // PendingInstantiations and VTableUses are restored through - // SavePendingInstantiationsAndVTableUses's destructor. - } + GlobalInstantiations.perform(); } // Find actual definition @@ -4408,16 +4383,16 @@ void Sema::InstantiateVariableDefinition(SourceLocation PointOfInstantiation, // If we're performing recursive template instantiation, create our own // queue of pending implicit instantiations that we will instantiate later, // while we're still within our own instantiation context. - SavePendingLocalImplicitInstantiationsRAII - SavedPendingLocalImplicitInstantiations(*this); - SavePendingInstantiationsAndVTableUsesRAII - SavePendingInstantiationsAndVTableUses(*this, /*Enabled=*/Recursive); + GlobalEagerInstantiationScope GlobalInstantiations(*this, + /*Enabled=*/Recursive); // Enter the scope of this instantiation. We don't use // PushDeclContext because we don't have a scope. ContextRAII PreviousContext(*this, Var->getDeclContext()); LocalInstantiationScope Local(*this); + LocalEagerInstantiationScope LocalInstantiations(*this); + VarDecl *OldVar = Var; if (Def->isStaticDataMember() && !Def->isOutOfLine()) { // We're instantiating an inline static data member whose definition was @@ -4470,21 +4445,9 @@ void Sema::InstantiateVariableDefinition(SourceLocation PointOfInstantiation, // This variable may have local implicit instantiations that need to be // instantiated within this scope. - PerformPendingInstantiations(/*LocalOnly=*/true); - + LocalInstantiations.perform(); Local.Exit(); - - if (Recursive) { - // Define any newly required vtables. - DefineUsedVTables(); - - // Instantiate any pending implicit instantiations found during the - // instantiation of this template. - PerformPendingInstantiations(); - - // PendingInstantiations and VTableUses are restored through - // SavePendingInstantiationsAndVTableUses's destructor. - } + GlobalInstantiations.perform(); } void -- 2.7.4