// BEGIN mycpp output #include "gc_heap.h" using gc_heap::Alloc; using gc_heap::kZeroMask; using gc_heap::StackRoots; #include "my_runtime.h" #include "mylib2.h" using gc_heap::NewStr; using gc_heap::NewList; using gc_heap::NewDict; GLOBAL_STR(str0, "mystr"); GLOBAL_STR(str1, "foo"); GLOBAL_STR(str2, "bar"); GLOBAL_STR(str3, "foo"); GLOBAL_STR(str4, "foo"); GLOBAL_STR(str5, "mystr"); GLOBAL_STR(str6, "[%s]"); GLOBAL_STR(str7, "mystr"); GLOBAL_STR(str8, "[%s, %s]"); GLOBAL_STR(str9, "abc"); GLOBAL_STR(str10, "%s: 5%%-100%%"); GLOBAL_STR(str11, "abc"); GLOBAL_STR(str12, "%s"); GLOBAL_STR(str13, "anchor"); GLOBAL_STR(str14, "foo? %d"); GLOBAL_STR(str15, "f"); GLOBAL_STR(str16, "str? %d"); GLOBAL_STR(str17, "s"); GLOBAL_STR(str18, "int 5d %5d"); GLOBAL_STR(str19, "'single'"); GLOBAL_STR(str20, "\"double\""); GLOBAL_STR(str21, "a\tb\nc\td\n"); GLOBAL_STR(str22, "x"); GLOBAL_STR(str23, "%s\tb\n%s\td\n"); namespace strings { // forward declare class Foo; } // forward declare namespace strings namespace strings { // declare class Foo : public gc_heap::Obj { public: Foo(); Str* s; DISALLOW_COPY_AND_ASSIGN(Foo) }; void run_tests(); void run_benchmarks(); inline Str* fmt0(Str* a0) { gBuf.reset(); gBuf.write_const("[", 1); gBuf.format_s(a0); gBuf.write_const("]", 1); return gBuf.getvalue(); } inline Str* fmt1(Str* a0, Str* a1) { gBuf.reset(); gBuf.write_const("[", 1); gBuf.format_s(a0); gBuf.write_const(", ", 2); gBuf.format_s(a1); gBuf.write_const("]", 1); return gBuf.getvalue(); } inline Str* fmt2(Str* a0) { gBuf.reset(); gBuf.format_s(a0); gBuf.write_const(": 5", 3); gBuf.write_const("%", 1); gBuf.write_const("-100", 4); gBuf.write_const("%", 1); return gBuf.getvalue(); } inline Str* fmt3(Str* a0) { gBuf.reset(); gBuf.write_const("", 19); gBuf.format_s(a0); gBuf.write_const("", 4); return gBuf.getvalue(); } inline Str* fmt4(bool a0) { gBuf.reset(); gBuf.write_const("foo? ", 5); gBuf.format_d(a0); return gBuf.getvalue(); } inline Str* fmt5(bool a0) { gBuf.reset(); gBuf.write_const("str? ", 5); gBuf.format_d(a0); return gBuf.getvalue(); } inline Str* fmt6(int a0) { gBuf.reset(); gBuf.write_const("int 5d ", 7); gBuf.format_d(a0); return gBuf.getvalue(); } inline Str* fmt7(Str* a0, Str* a1) { gBuf.reset(); gBuf.format_s(a0); gBuf.write_const("\tb\n", 3); gBuf.format_s(a1); gBuf.write_const("\td\n", 3); return gBuf.getvalue(); } } // declare namespace strings namespace strings { // define Foo::Foo() : gc_heap::Obj(Tag::FixedSize, kZeroMask, sizeof(Foo)) { this->s = str0; } void run_tests() { strings::Foo* obj = nullptr; Str* s = nullptr; Str* x = nullptr; StackRoots _roots({&obj, &s, &x}); print(str_concat(str1, str2)); print(str_repeat(str3, 3)); obj = Alloc(); print(str_concat(str4, obj->s)); s = str5; print(fmt0(s)); s = str7; print(fmt1(s, str9)); print(fmt2(str11)); print(fmt3(str13)); print(fmt4(str_contains(s, str15))); print(fmt5(str_contains(s, str17))); print(fmt6(35)); print(str19); print(str20); print(str21); x = str22; print(fmt7(x, x)); } void run_benchmarks() { ; // pass } } // define namespace strings