File tree Expand file tree Collapse file tree 2 files changed +16
-1
lines changed Expand file tree Collapse file tree 2 files changed +16
-1
lines changed Original file line number Diff line number Diff line change @@ -66,6 +66,19 @@ TEST_CASE("struct pointer", "[Type]"){
66
66
REQUIRE (answ == Translate (code));
67
67
}
68
68
69
+ TEST_CASE (" struct helper methods" ) {
70
+ std::string code = " struct listing { int a; int b; };" ;
71
+ Translate (code);
72
+ std::string answ = " \t implicit class struct_listing_ops(val p: native.Ptr[struct_listing]) extends AnyVal {\n "
73
+ " \t\t def a: native.CInt = !p._1\n "
74
+ " \t\t def a_=(value: native.CInt):Unit = !p._1 = value\n "
75
+ " \t\t def b: native.CInt = !p._2\n "
76
+ " \t\t def b_=(value: native.CInt):Unit = !p._2 = value\n "
77
+ " \t }\n\n "
78
+ " \t def struct_listing()(implicit z: native.Zone): native.Ptr[struct_listing] = native.alloc[struct_listing]\n\n " ;
79
+ REQUIRE (answ == helpers);
80
+ }
81
+
69
82
TEST_CASE (" func no args" , " [Func]" ){
70
83
std::string code = " int foo();" ;
71
84
std::string answ = " \t def foo(): native.CInt = native.extern\n " ;
Original file line number Diff line number Diff line change @@ -112,7 +112,7 @@ bool TreeVisitor::VisitRecordDecl(clang::RecordDecl *record){
112
112
helpers += helpersFunc;
113
113
helpers += " \t }\n\n " ;
114
114
115
- return true ;
115
+ return true ;
116
116
117
117
} else if (record->isStruct () && record->isThisDeclarationADefinition () && !record->isAnonymousStructOrUnion () && name != " " ){
118
118
@@ -165,6 +165,8 @@ bool TreeVisitor::VisitRecordDecl(clang::RecordDecl *record){
165
165
helpers += " \t implicit class " + newName + " _ops(val p: native.Ptr[struct_" + name + " ]) extends AnyVal {\n " ;
166
166
helpers += helpersFunc;
167
167
helpers += " \t }\n\n " ;
168
+
169
+ helpers += " \t def " + newName + " ()(implicit z: native.Zone): native.Ptr[" + newName + " ] = native.alloc[" + newName + " ]\n\n " ;
168
170
}
169
171
170
172
return true ;
You can’t perform that action at this time.
0 commit comments