[qfcc] Remove union hack for block expressions

I don't remember why I thought it was a good idea at the time, but I
decided that having the union was a bit iffy and making the list
"official" would be a good idea. In the end, it removed a nice chunk of
code (redundant list manipulations).
This commit is contained in:
Bill Currie 2024-10-03 13:48:54 +09:00
parent dcd2505bb9
commit 8b9333e108
5 changed files with 15 additions and 34 deletions

View file

@ -112,15 +112,11 @@ typedef struct ex_list_s {
ex_listitem_t **tail; ex_listitem_t **tail;
} ex_list_t; } ex_list_t;
typedef union { typedef struct {
ex_list_t list; ex_list_t list;
struct {
ex_listitem_t *head;
ex_listitem_t **tail;
const expr_t *result; ///< the result of this block if non-void const expr_t *result; ///< the result of this block if non-void
int is_call; ///< this block exprssion forms a function call int is_call; ///< this block exprssion forms a function call
void *return_addr; ///< who allocated this void *return_addr; ///< who allocated this
};
} ex_block_t; } ex_block_t;
typedef struct { typedef struct {

View file

@ -549,17 +549,11 @@ new_block_expr (const expr_t *old)
expr_t *b = new_expr (); expr_t *b = new_expr ();
b->type = ex_block; b->type = ex_block;
b->block.head = 0;
b->block.tail = &b->block.head;
if (old) { if (old) {
if (old->type != ex_block) { if (old->type != ex_block) {
internal_error (old, "not a block expression"); internal_error (old, "not a block expression");
} }
if ((b->block.head = old->block.head)) { b->block = old->block;
b->block.tail = old->block.tail;
}
b->block.result = old->block.result;
b->block.is_call = old->block.is_call;
} }
b->block.return_addr = __builtin_return_address (0); b->block.return_addr = __builtin_return_address (0);
return b; return b;
@ -593,10 +587,9 @@ build_block_expr (expr_t *list, bool set_result)
} }
expr_t *b = new_block_expr (0); expr_t *b = new_block_expr (0);
b->block.head = list->list.head; b->block.list = list->list;
b->block.tail = list->list.tail; if (set_result && b->block.list.tail != &b->block.list.head) {
if (set_result && b->block.tail != &b->block.head) { auto last = (ex_listitem_t *) b->block.list.tail;
auto last = (ex_listitem_t *) b->block.tail;
b->block.result = last->expr; b->block.result = last->expr;
} }
return b; return b;
@ -1606,9 +1599,7 @@ append_expr (expr_t *block, const expr_t *e)
if (!e || e->type == ex_error) if (!e || e->type == ex_error)
return block; return block;
auto li = new_listitem (e); list_append (&block->block.list, e);
*block->block.tail = li;
block->block.tail = &li->next;
return block; return block;
} }
@ -1622,13 +1613,7 @@ prepend_expr (expr_t *block, const expr_t *e)
if (!e || e->type == ex_error) if (!e || e->type == ex_error)
return block; return block;
auto li = new_listitem (e); list_prepend (&block->block.list, e);
li->next = block->block.head;
block->block.head = li;
if (block->block.tail == &block->block.head) {
block->block.tail = &li->next;
}
return block; return block;
} }
@ -1887,7 +1872,7 @@ has_function_call (const expr_t *e)
if (e->block.is_call) if (e->block.is_call)
return 1; return 1;
case ex_list: case ex_list:
for (auto li = e->block.head; li; li = li->next) for (auto li = e->block.list.head; li; li = li->next)
if (has_function_call (li->expr)) if (has_function_call (li->expr))
return 1; return 1;
return 0; return 0;

View file

@ -308,8 +308,8 @@ convert_bool (const expr_t *e, int block)
auto b = new_block_expr (0); auto b = new_block_expr (0);
append_expr (b, branch_expr (QC_NE, e, 0)); append_expr (b, branch_expr (QC_NE, e, 0));
append_expr (b, goto_expr (0)); append_expr (b, goto_expr (0));
e = new_bool_expr (make_list (b->block.head->expr), e = new_bool_expr (make_list (b->block.list.head->expr),
make_list (b->block.head->next->expr), b); make_list (b->block.list.head->next->expr), b);
} }
} }
if (block && e->boolean.e->type != ex_block) { if (block && e->boolean.e->type != ex_block) {

View file

@ -2160,7 +2160,7 @@ identifier_list
classdecl classdecl
: CLASS identifier_list ';' : CLASS identifier_list ';'
{ {
for (auto li = $2->block.head; li; li = li->next) { for (auto li = $2->block.list.head; li; li = li->next) {
auto e = li->expr; auto e = li->expr;
get_class (e->symbol, 1); get_class (e->symbol, 1);
if (!e->symbol->table) if (!e->symbol->table)

View file

@ -2274,7 +2274,7 @@ build_bool_block (expr_t *block, expr_t *e)
break; break;
case ex_block: case ex_block:
if (!e->block.result) { if (!e->block.result) {
for (auto t = e->block.head; t; t = t->next) { for (auto t = e->block.list.head; t; t = t->next) {
build_bool_block (block, (expr_t *) t->expr); build_bool_block (block, (expr_t *) t->expr);
} }
return; return;