[qfcc] Print block label expressions first

Just running through the list of expressions in a block expression
results in label expressions within the block getting printed by
expressions that reference them and thus don't receive the correct next
pointer and wind up pointing to themselves. Printing the labels first
ensures they have the correct next pointer. However, I suspect there are
other ways things will get tangled.
This commit is contained in:
Bill Currie 2024-02-08 11:24:39 +09:00
parent 09d0e6b27c
commit 701b0f3992

View file

@ -256,6 +256,13 @@ print_block (dstring_t *dstr, const expr_t *e, int level, int id,
dasprintf (dstr, "%*se_%p:result -> e_%p;\n", indent, "", e,
e->block.result);
}
// print any label expressions first to ensure they get the correct
// next pointer instead of pointing to themselves.
for (int i = 0; i < num_exprs; i++) {
if (exprs[i]->type == ex_label) {
_print_expr (dstr, exprs[i], level + 1, id, exprs[i + 1]);
}
}
for (int i = 0; i < num_exprs; i++) {
_print_expr (dstr, exprs[i], level + 1, id, exprs[i + 1]);
dasprintf (dstr, "%*se_%p:b%d -> e_%p;\n", indent, "", e,
@ -771,7 +778,7 @@ dump_dot_expr (const void *_e, const char *filename)
dasprintf (dstr, "digraph expr_%p {\n", e);
dasprintf (dstr, " graph [label=\"%s\"];\n", quote_string (filename));
dasprintf (dstr, " layout=dot; rankdir=TB; compound=true;\n");
_print_expr (dstr, e, 0, ++id, 0);
_print_expr (dstr, e, 0, ++id, nullptr);
dasprintf (dstr, "}\n");
if (filename) {