cgen: cleanup the generated code for dump(x)

pull/12719/head
Delyan Angelov 2021-12-04 11:56:39 +02:00
parent 2d43fdb42a
commit 89c08c6292
No known key found for this signature in database
GPG Key ID: 66886C0F12D595ED
1 changed files with 9 additions and 10 deletions

View File

@ -45,17 +45,16 @@ fn (mut g Gen) dump_expr_definitions() {
continue continue
} }
mut surrounder := util.new_surrounder(3) mut surrounder := util.new_surrounder(3)
surrounder.add('string sline = int_str(line);', 'string_free(&sline);') surrounder.add('\tstring sline = int_str(line);', '\tstring_free(&sline);')
surrounder.add('string value = ${to_string_fn_name}(${deref}dump_arg);', 'string_free(&value);') surrounder.add('\tstring value = ${to_string_fn_name}(${deref}dump_arg);', '\tstring_free(&value);')
surrounder.add(' surrounder.add('
string res; strings__Builder sb = strings__new_builder(256);
strings__Builder sb = strings__new_builder(256); ', '
', string res;
' res = strings__Builder_str(&sb);
res = strings__Builder_str(&sb); eprint(res);
eprint(res); string_free(&res);
string_free(&res); strings__Builder_free(&sb);
strings__Builder_free(&sb);
') ')
surrounder.builder_write_befores(mut dump_fns) surrounder.builder_write_befores(mut dump_fns)
dump_fns.writeln("\tstrings__Builder_write_rune(&sb, '[');") dump_fns.writeln("\tstrings__Builder_write_rune(&sb, '[');")