From bc3045b3d8e8140d94a7bfd0cff1dbf8a7b491a1 Mon Sep 17 00:00:00 2001 From: NeilBrown Date: Sun, 19 Dec 2021 11:52:25 +1100 Subject: [PATCH] oceani-tests: Add testing for --bracket printing. Make sure that printing with --bracket is still parseable, and double-printing doesn't change from single. Signed-off-by: NeilBrown --- csrc/oceani-tests.mdc | 6 ++++++ csrc/oceani.mdc | 16 ++++++++++------ 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/csrc/oceani-tests.mdc b/csrc/oceani-tests.mdc index fafb788..6759c54 100644 --- a/csrc/oceani-tests.mdc +++ b/csrc/oceani-tests.mdc @@ -66,6 +66,12 @@ arguments separated from the name by commas. For each test, there is a section ./oceani --noexec --print .tmp.code1a >> .tmp.code2a || exit 1;\ if ! cmp -s .tmp.code1 .tmp.code2a; then \ echo " Failed"; diff -u .tmp.code1 .tmp.code2a; exit 1; fi ; \ + echo -n "brackets.. "; \ + echo '``````' > .tmp.code2b ; echo '``````' > .tmp.code2c ;\ + ./oceani --noexec --print --brackets .tmp.code1 >> .tmp.code2b || exit 1; \ + ./oceani -npb .tmp.code2b >> .tmp.code2c || exit 1 ; \ + if ! cmp -s .tmp.code2b .tmp.code2c; then \ + echo " Failed"; diff -u .tmp.code2b .tmp.code2c; exit 1; fi; \ echo -n "exec-after-print.. "; \ ./oceani .tmp.code1 $${1+"$$@"} > .tmp.have ; \ if ! cmp -s .tmp.want .tmp.have; then \ diff --git a/csrc/oceani.mdc b/csrc/oceani.mdc index 543ca75..910d095 100644 --- a/csrc/oceani.mdc +++ b/csrc/oceani.mdc @@ -3552,6 +3552,7 @@ further detailed when Expression Lists are introduced. static void function_print(struct type *type, struct value *val, FILE *f) { + fprintf(f, "\n"); print_exec(val->function, 1, 0); } @@ -3585,7 +3586,6 @@ further detailed when Expression Lists are introduced. } else type_print(type->function.return_type, f); } - fprintf(f, "\n"); } static void function_free_type(struct type *t) @@ -4313,9 +4313,10 @@ parentheses around an expression converts it into a Term, if (bracket) printf(")"); break; case Bracket: - printf("("); + /* Avoid double brackets... */ + if (!bracket) printf("("); print_exec(b->right, indent, bracket); - printf(")"); + if (!bracket) printf(")"); break; ###### propagate binode cases @@ -5802,10 +5803,13 @@ is a bit more interesting at this level. struct value *val = var_value(&context, v); printf("func %.*s", v->name->name.len, v->name->name.txt); v->type->print_type_decl(v->type, stdout); - if (brackets) - print_exec(val->function, 0, brackets); - else + if (brackets) { + printf(" {\n"); + print_exec(val->function, 1, brackets); + printf("}\n"); + } else { print_value(v->type, val, stdout); + } printf("/* frame size %d */\n", v->type->function.local_size); target -= 1; } -- 2.43.0