// Very simple code to understand how tlcc works // and test the new reference system #include #include #include using namespace std; #define _TLMP_foo struct _F_foo{ #define _F_foo_func1(x) void x func1(vector &t) virtual _F_foo_func1( )=0; #define _F_foo_func2(x) void x func2(vector &t) virtual _F_foo_func2( )=0; }; void foo (_F_foo &c, vector &t) { c.func1(t); c.func2(t); } #ifndef _TLMP_foo #error TLMP module foo unknown #endif #ifndef _F_foo_func1 #error Unknown logical function func1 for module/class foo #endif #ifndef _TLMP_foo #error TLMP module foo unknown #endif #ifndef _F_foo_func1 #error Unknown logical function func1 for module/class foo #endif #ifndef _F_foo_func2 #error Unknown logical function func2 for module/class foo #endif #ifndef _F_foo_func2 #error Unknown logical function func2 for module/class foo #endif #line 22 "refer2.tlcc" static void f (int &refval, int val, const char *title,vector &tb) { using glocaltype0 = decltype(refval); using glocaltype1 = decltype(val); using glocaltype2 = decltype(title); using glocaltype3 = decltype(tb); #line 30 "refer2.tlcc" struct __gl_tests_refer2_tlcc_GLOCAL1_1{ __gl_tests_refer2_tlcc_GLOCAL1_1(glocaltype0 &refval,glocaltype1 &val,glocaltype2 &title,glocaltype3 &tb) : refval(refval) ,val(val) ,title(title) ,tb(tb) {} glocaltype0 &refval; glocaltype1 &val; glocaltype2 &title; #line 28 "refer2.tlcc" int a; glocaltype3 &tb; }; { // Inserted to support nested glocals __gl_tests_refer2_tlcc_GLOCAL1_1 B_glocal(refval,val,title,tb); #line 28 "refer2.tlcc" B_glocal.a=1; #line 30 "refer2.tlcc" class __sc_tests_refer2_tlcc1: public _F_foo{ public: __gl_tests_refer2_tlcc_GLOCAL1_1 &glocal; __sc_tests_refer2_tlcc1 (__gl_tests_refer2_tlcc_GLOCAL1_1 &g) : glocal(g) { } _F_foo_func1( ) { #line 31 "refer2.tlcc" printf ("This is func1 glocal.a=%d\n",glocal.a); glocal.tb.push_back("func1"); using glocaltype4 = decltype(t); #line 35 "refer2.tlcc" struct __gl_tests_refer2_tlcc_GLOCAL1_2{ __gl_tests_refer2_tlcc_GLOCAL1_1 &glocal; _F_foo &foo; __gl_tests_refer2_tlcc_GLOCAL1_2(__gl_tests_refer2_tlcc_GLOCAL1_1 &gl,_F_foo *_c,glocaltype4 &t) : glocal(gl),foo(*_c) ,t(t) {} glocaltype4 &t; }; { // Inserted to support nested glocals __gl_tests_refer2_tlcc_GLOCAL1_2 B_glocal(this->glocal,this,t); #line 35 "refer2.tlcc" class __sc_tests_refer2_tlcc2: public _F_foo{ public: __gl_tests_refer2_tlcc_GLOCAL1_2 &glocal; __sc_tests_refer2_tlcc2 (__gl_tests_refer2_tlcc_GLOCAL1_2 &g) : glocal(g) { } _F_foo_func1( ) { #line 36 "refer2.tlcc" glocal.t.push_back("sub-func1"); } // #line 38 "refer2.tlcc" _F_foo_func2( ) { #line 39 "refer2.tlcc" glocal.t.push_back("sub-func2"); glocal.glocal.refval++; } // #line 42 "refer2.tlcc" }; __sc_tests_refer2_tlcc2 _scopeobj2(B_glocal); #line 35 "refer2.tlcc" ::foo(_scopeobj2,t); #line 43 "refer2.tlcc" } // #line 44 "refer2.tlcc" } // For nested glocals 2 -> 1 _F_foo_func2( ) { #line 45 "refer2.tlcc" printf ("This is func2, val=%d title=%s\n",glocal.val,glocal.title); glocal.tb.push_back("func2"); glocal.refval++; } // #line 49 "refer2.tlcc" }; __sc_tests_refer2_tlcc1 _scopeobj1(B_glocal); #line 30 "refer2.tlcc" ::foo(_scopeobj1,tb); #line 50 "refer2.tlcc" } } // For nested glocals 1 -> 0 #line 52 "refer2.tlcc" int main () { vector tb; int val=10; f (val,1,"this is the title",tb); printf ("val=%d\n",val); for (auto const &s:tb) printf ("tb[]=%s\n",s.c_str()); return 0; }