-
Notifications
You must be signed in to change notification settings - Fork 37
Fix bugs related to printing types #661
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 |
|---|---|---|
|
|
@@ -2078,6 +2078,15 @@ TEST(FunctionReflectionTest, GetFunctionArgDefault) { | |
| template<class A> | ||
| void get_size(long k, A, char ch = 'a', double l = 0.0) {} | ||
|
|
||
| template<typename T> | ||
| struct Other {}; | ||
|
|
||
| template <typename T, typename S = Other<T>> | ||
| struct MyStruct { | ||
| T t; | ||
| S s; | ||
| void fn(T t, S s = S()) {} | ||
| }; | ||
| )"; | ||
|
|
||
| GetAllTopLevelDecls(code, Decls); | ||
|
|
@@ -2102,6 +2111,20 @@ TEST(FunctionReflectionTest, GetFunctionArgDefault) { | |
| EXPECT_EQ(Cpp::GetFunctionArgDefault(Decls[4], 1), ""); | ||
| EXPECT_EQ(Cpp::GetFunctionArgDefault(Decls[4], 2), "\'a\'"); | ||
| EXPECT_EQ(Cpp::GetFunctionArgDefault(Decls[4], 3), "0."); | ||
|
|
||
| ASTContext& C = Interp->getCI()->getASTContext(); | ||
| Cpp::TemplateArgInfo template_args[1] = {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: do not declare C-style arrays, use std::array<> instead [cppcoreguidelines-avoid-c-arrays] Cpp::TemplateArgInfo template_args[1] = {C.IntTy.getAsOpaquePtr()};
^ |
||
| Cpp::TCppScope_t my_struct = | ||
| Cpp::InstantiateTemplate(Decls[6], template_args, 1); | ||
|
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: do not implicitly decay an array into a pointer; consider using gsl::array_view or an explicit cast instead [cppcoreguidelines-pro-bounds-array-to-pointer-decay] Cpp::InstantiateTemplate(Decls[6], template_args, 1);
^ |
||
| EXPECT_TRUE(my_struct); | ||
|
|
||
| std::vector<Cpp::TCppFunction_t> fns = | ||
| Cpp::GetFunctionsUsingName(my_struct, "fn"); | ||
| EXPECT_EQ(fns.size(), 1); | ||
|
|
||
| Cpp::TCppScope_t fn = fns[0]; | ||
| EXPECT_EQ(Cpp::GetFunctionArgDefault(fn, 0), ""); | ||
| EXPECT_EQ(Cpp::GetFunctionArgDefault(fn, 1), "S()"); | ||
| } | ||
|
|
||
| TEST(FunctionReflectionTest, Construct) { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -334,6 +334,9 @@ TEST(ScopeReflectionTest, GetCompleteName) { | |
| A<int> a; | ||
|
|
||
| enum { enum1 }; | ||
|
|
||
| template<typename T1, typename T2> | ||
| void fn(T1 t1, T2 t2) {} | ||
| )"; | ||
| GetAllTopLevelDecls(code, Decls); | ||
|
|
||
|
|
@@ -350,7 +353,15 @@ TEST(ScopeReflectionTest, GetCompleteName) { | |
| Cpp::GetVariableType( | ||
| Decls[9]))), "A<int>"); | ||
| EXPECT_EQ(Cpp::GetCompleteName(Decls[10]), "(unnamed)"); | ||
| EXPECT_EQ(Cpp::GetCompleteName(Decls[11]), "fn"); | ||
| EXPECT_EQ(Cpp::GetCompleteName(nullptr), "<unnamed>"); | ||
|
|
||
| ASTContext& C = Interp->getCI()->getASTContext(); | ||
| Cpp::TemplateArgInfo template_args[2] = {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: do not declare C-style arrays, use std::array<> instead [cppcoreguidelines-avoid-c-arrays] Cpp::TemplateArgInfo template_args[2] = {C.IntTy.getAsOpaquePtr(),
^ |
||
| C.DoubleTy.getAsOpaquePtr()}; | ||
| Cpp::TCppScope_t fn = Cpp::InstantiateTemplate(Decls[11], template_args, 2); | ||
|
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: do not implicitly decay an array into a pointer; consider using gsl::array_view or an explicit cast instead [cppcoreguidelines-pro-bounds-array-to-pointer-decay] Cpp::TCppScope_t fn = Cpp::InstantiateTemplate(Decls[11], template_args, 2);
^ |
||
| EXPECT_TRUE(fn); | ||
| EXPECT_EQ(Cpp::GetCompleteName(fn), "fn<int, double>"); | ||
| } | ||
|
|
||
| TEST(ScopeReflectionTest, GetQualifiedName) { | ||
|
|
||
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.
I wonder if it would be a good idea to improve the to-string printing consistency by modifying the default printing policy at
CreateIntepretertime?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.
If the intention is to; not keep modifying the
PrintingPolicy, it may not be possible. We need different amounts of information at different times, using different APIs. Where we will have to modify thePrintingPolicy.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.
Can we open an issue to track this idea?
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.
Opened an issue at #662