-
Notifications
You must be signed in to change notification settings - Fork 56
Consolidate the template instantiation logic. #128
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -750,8 +750,52 @@ TEST(ScopeReflectionTest, InstantiateNNTPClassTemplate) { | |||||
| ASTContext &C = Interp->getCI()->getASTContext(); | ||||||
| Cpp::TCppType_t IntTy = C.IntTy.getAsOpaquePtr(); | ||||||
| std::vector<Cpp::TemplateArgInfo> args1 = {{IntTy, "5"}}; | ||||||
| EXPECT_TRUE(Cpp::InstantiateClassTemplate(Decls[0], args1.data(), | ||||||
| /*type_size*/ args1.size())); | ||||||
| EXPECT_TRUE(Cpp::InstantiateTemplate(Decls[0], args1.data(), | ||||||
| /*type_size*/ args1.size())); | ||||||
| } | ||||||
|
|
||||||
| TEST(ScopeReflectionTest, InstantiateVarTemplate) { | ||||||
| std::vector<Decl*> Decls; | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: variable 'Decls' is not initialized [cppcoreguidelines-init-variables]
Suggested change
|
||||||
| std::string code = R"( | ||||||
| template<class T> constexpr T pi = T(3.1415926535897932385L); | ||||||
| )"; | ||||||
|
|
||||||
| GetAllTopLevelDecls(code, Decls); | ||||||
| ASTContext& C = Interp->getCI()->getASTContext(); | ||||||
|
|
||||||
| std::vector<Cpp::TemplateArgInfo> args1 = {C.IntTy.getAsOpaquePtr()}; | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: variable 'args1' is not initialized [cppcoreguidelines-init-variables]
Suggested change
|
||||||
| auto Instance1 = Cpp::InstantiateTemplate(Decls[0], args1.data(), | ||||||
| /*type_size*/ args1.size()); | ||||||
| EXPECT_TRUE(isa<VarDecl>((Decl*)Instance1)); | ||||||
| auto* VD = cast<VarTemplateSpecializationDecl>((Decl*)Instance1); | ||||||
| VarTemplateDecl* VDTD1 = VD->getSpecializedTemplate(); | ||||||
| EXPECT_TRUE(VDTD1->isThisDeclarationADefinition()); | ||||||
| #if CLANG_VERSION_MAJOR > 13 | ||||||
| TemplateArgument TA1 = (*VD->getTemplateArgsInfo())[0].getArgument(); | ||||||
| #else | ||||||
| TemplateArgument TA1 = VD->getTemplateArgsInfo()[0].getArgument(); | ||||||
| #endif // CLANG_VERSION_MAJOR | ||||||
| EXPECT_TRUE(TA1.getAsType()->isIntegerType()); | ||||||
| } | ||||||
|
|
||||||
| TEST(ScopeReflectionTest, InstantiateFunctionTemplate) { | ||||||
| std::vector<Decl*> Decls; | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: variable 'Decls' is not initialized [cppcoreguidelines-init-variables]
Suggested change
|
||||||
| std::string code = R"( | ||||||
| template<typename T> T TrivialFnTemplate() { return T(); } | ||||||
| )"; | ||||||
|
|
||||||
| GetAllTopLevelDecls(code, Decls); | ||||||
| ASTContext& C = Interp->getCI()->getASTContext(); | ||||||
|
|
||||||
| std::vector<Cpp::TemplateArgInfo> args1 = {C.IntTy.getAsOpaquePtr()}; | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: variable 'args1' is not initialized [cppcoreguidelines-init-variables]
Suggested change
|
||||||
| auto Instance1 = Cpp::InstantiateTemplate(Decls[0], args1.data(), | ||||||
| /*type_size*/ args1.size()); | ||||||
| EXPECT_TRUE(isa<FunctionDecl>((Decl*)Instance1)); | ||||||
| FunctionDecl* FD = cast<FunctionDecl>((Decl*)Instance1); | ||||||
| FunctionDecl* FnTD1 = FD->getTemplateInstantiationPattern(); | ||||||
| EXPECT_TRUE(FnTD1->isThisDeclarationADefinition()); | ||||||
| TemplateArgument TA1 = FD->getTemplateSpecializationArgs()->get(0); | ||||||
| EXPECT_TRUE(TA1.getAsType()->isIntegerType()); | ||||||
| } | ||||||
|
|
||||||
| TEST(ScopeReflectionTest, InstantiateTemplateFunctionFromString) { | ||||||
|
|
@@ -807,29 +851,26 @@ TEST(ScopeReflectionTest, InstantiateClassTemplate) { | |||||
| ASTContext &C = Interp->getCI()->getASTContext(); | ||||||
|
|
||||||
| std::vector<Cpp::TemplateArgInfo> args1 = {C.IntTy.getAsOpaquePtr()}; | ||||||
| auto Instance1 = Cpp::InstantiateClassTemplate(Decls[0], | ||||||
| args1.data(), | ||||||
| /*type_size*/args1.size()); | ||||||
| auto Instance1 = Cpp::InstantiateTemplate(Decls[0], args1.data(), | ||||||
| /*type_size*/ args1.size()); | ||||||
| EXPECT_TRUE(isa<ClassTemplateSpecializationDecl>((Decl*)Instance1)); | ||||||
| auto *CTSD1 = static_cast<ClassTemplateSpecializationDecl*>(Instance1); | ||||||
| EXPECT_TRUE(CTSD1->hasDefinition()); | ||||||
| TemplateArgument TA1 = CTSD1->getTemplateArgs().get(0); | ||||||
| EXPECT_TRUE(TA1.getAsType()->isIntegerType()); | ||||||
| EXPECT_TRUE(CTSD1->hasDefinition()); | ||||||
|
|
||||||
| auto Instance2 = Cpp::InstantiateClassTemplate(Decls[1], | ||||||
| nullptr, | ||||||
| /*type_size*/0); | ||||||
| auto Instance2 = Cpp::InstantiateTemplate(Decls[1], nullptr, | ||||||
| /*type_size*/ 0); | ||||||
| EXPECT_TRUE(isa<ClassTemplateSpecializationDecl>((Decl*)Instance2)); | ||||||
| auto *CTSD2 = static_cast<ClassTemplateSpecializationDecl*>(Instance2); | ||||||
| EXPECT_TRUE(CTSD2->hasDefinition()); | ||||||
| TemplateArgument TA2 = CTSD2->getTemplateArgs().get(0); | ||||||
| EXPECT_TRUE(TA2.getAsType()->isIntegerType()); | ||||||
|
|
||||||
| std::vector<Cpp::TemplateArgInfo> args3 = {C.IntTy.getAsOpaquePtr()}; | ||||||
| auto Instance3 = Cpp::InstantiateClassTemplate(Decls[2], | ||||||
| args3.data(), | ||||||
| /*type_size*/args3.size()); | ||||||
| auto Instance3 = Cpp::InstantiateTemplate(Decls[2], args3.data(), | ||||||
| /*type_size*/ args3.size()); | ||||||
| EXPECT_TRUE(isa<ClassTemplateSpecializationDecl>((Decl*)Instance3)); | ||||||
| auto *CTSD3 = static_cast<ClassTemplateSpecializationDecl*>(Instance3); | ||||||
| EXPECT_TRUE(CTSD3->hasDefinition()); | ||||||
|
|
@@ -844,9 +885,8 @@ TEST(ScopeReflectionTest, InstantiateClassTemplate) { | |||||
|
|
||||||
| std::vector<Cpp::TemplateArgInfo> args4 = {C.IntTy.getAsOpaquePtr(), | ||||||
| {C.IntTy.getAsOpaquePtr(), "3"}}; | ||||||
| auto Instance4 = Cpp::InstantiateClassTemplate(Decls[3], | ||||||
| args4.data(), | ||||||
| /*type_size*/args4.size()); | ||||||
| auto Instance4 = Cpp::InstantiateTemplate(Decls[3], args4.data(), | ||||||
| /*type_size*/ args4.size()); | ||||||
|
|
||||||
| EXPECT_TRUE(isa<ClassTemplateSpecializationDecl>((Decl*)Instance4)); | ||||||
| auto *CTSD4 = static_cast<ClassTemplateSpecializationDecl*>(Instance4); | ||||||
|
|
@@ -901,4 +941,4 @@ TEST(ScopeReflectionTest, IncludeVector) { | |||||
| #include <iostream> | ||||||
| )"; | ||||||
| Interp->process(code); | ||||||
| } | ||||||
| } | ||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
warning: variable 'R' is not initialized [cppcoreguidelines-init-variables]