From: Wolfgang (Blub) Bumiller Date: Sat, 18 Aug 2012 14:20:45 +0000 (+0200) Subject: Revert "let ast_node have a use-counter, helpful for the parser to delete unused... X-Git-Tag: 0.1-rc1~210 X-Git-Url: https://git.xonotic.org/?p=xonotic%2Fgmqcc.git;a=commitdiff_plain;h=897bd5727e61d8a7b9c3bc557818834c06fd84a4;ds=sidebyside Revert "let ast_node have a use-counter, helpful for the parser to delete unused fields which otherwise get lost in the void" This reverts commit 25ffd11aa63c018632f3906092622353f79a8129. --- diff --git a/ast.c b/ast.c index d776e6e..e4d1859 100644 --- a/ast.c +++ b/ast.c @@ -57,7 +57,6 @@ static void ast_node_init(ast_node *self, lex_ctx ctx, int nodetype) self->node.context = ctx; self->node.destroy = &_ast_node_destroy; self->node.keep = false; - self->node.uses = 0; self->node.nodetype = nodetype; } @@ -256,9 +255,6 @@ ast_binary* ast_binary_new(lex_ctx ctx, int op, else self->expression.vtype = left->expression.vtype; - ast_use(left); - ast_use(right); - return self; } @@ -292,10 +288,6 @@ ast_binstore* ast_binstore_new(lex_ctx ctx, int storop, int op, else self->expression.next = NULL; - ast_use(left); - ast_use(right); - ast_use(left); - return self; } @@ -316,8 +308,6 @@ ast_unary* ast_unary_new(lex_ctx ctx, int op, self->op = op; self->operand = expr; - ast_use(expr); - return self; } @@ -335,8 +325,6 @@ ast_return* ast_return_new(lex_ctx ctx, ast_expression *expr) self->operand = expr; - ast_use(expr); - return self; } @@ -373,9 +361,6 @@ ast_entfield* ast_entfield_new(lex_ctx ctx, ast_expression *entity, ast_expressi self->entity = entity; self->field = field; - ast_use(entity); - ast_use(field); - return self; } @@ -415,8 +400,6 @@ ast_member* ast_member_new(lex_ctx ctx, ast_expression *owner, unsigned int fiel self->owner = owner; self->field = field; - ast_use(owner); - return self; } @@ -441,10 +424,6 @@ ast_ifthen* ast_ifthen_new(lex_ctx ctx, ast_expression *cond, ast_expression *on self->on_true = ontrue; self->on_false = onfalse; - ast_use(cond); - if (ontrue) ast_use(ontrue); - if (onfalse) ast_use(onfalse); - return self; } @@ -474,10 +453,6 @@ ast_ternary* ast_ternary_new(lex_ctx ctx, ast_expression *cond, ast_expression * self->on_false = onfalse; self->phi_out = NULL; - ast_use(cond); - ast_use(ontrue); - ast_use(onfalse); - return self; } @@ -506,12 +481,6 @@ ast_loop* ast_loop_new(lex_ctx ctx, self->increment = increment; self->body = body; - if (initexpr) ast_use(initexpr); - if (precond) ast_use(precond); - if (postcond) ast_use(postcond); - if (increment) ast_use(increment); - if (body) ast_use(body); - return self; } @@ -540,20 +509,11 @@ ast_call* ast_call_new(lex_ctx ctx, MEM_VECTOR_INIT(self, params); self->func = funcexpr; - ast_use(funcexpr); return self; } MEM_VEC_FUNCTIONS(ast_call, ast_expression*, params) -bool ast_call_add_param(ast_call *self, ast_expression *expr) -{ - if (!ast_call_params_add(self, expr)) - return false; - ast_use(expr); - return true; -} - void ast_call_delete(ast_call *self) { size_t i; @@ -578,9 +538,6 @@ ast_store* ast_store_new(lex_ctx ctx, int op, self->dest = dest; self->source = source; - ast_use(dest); - ast_use(source); - return self; } @@ -606,14 +563,6 @@ ast_block* ast_block_new(lex_ctx ctx) MEM_VEC_FUNCTIONS(ast_block, ast_value*, locals) MEM_VEC_FUNCTIONS(ast_block, ast_expression*, exprs) -bool ast_block_add_expr(ast_block *self, ast_expression *expr) -{ - if (!ast_block_exprs_add(self, expr)) - return false; - ast_use(expr); - return true; -} - void ast_block_delete(ast_block *self) { size_t i; diff --git a/ast.h b/ast.h index 4f26742..0059e82 100644 --- a/ast.h +++ b/ast.h @@ -81,13 +81,8 @@ typedef struct * prevents its dtor from destroying this node as well. */ bool keep; - /* usecount - so we can delete unused _x,_y and _z nodes... */ - size_t uses; } ast_node_common; -#define ast_use(n) ((ast_node*)(n))->node.uses++ -#define ast_unuse(n) ((ast_node*)(n))->node.uses-- - #define ast_delete(x) ( ( (ast_node*)(x) ) -> node.destroy )((ast_node*)(x)) #define ast_unref(x) do \ { \ @@ -423,8 +418,6 @@ bool ast_call_codegen(ast_call*, ast_function*, bool lvalue, ir_value**); MEM_VECTOR_PROTO(ast_call, ast_expression*, params); -bool ast_call_add_param(ast_call*, ast_expression*); - /* Blocks * */ @@ -442,8 +435,6 @@ bool ast_block_set_type(ast_block*, ast_expression *from); MEM_VECTOR_PROTO(ast_block, ast_value*, locals); MEM_VECTOR_PROTO(ast_block, ast_expression*, exprs); -bool ast_block_add_expr(ast_block*, ast_expression *expr); - bool ast_block_codegen(ast_block*, ast_function*, bool lvalue, ir_value**); /* Function diff --git a/parser.c b/parser.c index 1ee5cad..24be6ec 100644 --- a/parser.c +++ b/parser.c @@ -517,12 +517,12 @@ static bool parser_sy_pop(parser_t *parser, shunt *sy) case opid1(','): if (blocks[0]) { - if (!ast_block_add_expr(blocks[0], exprs[1])) + if (!ast_block_exprs_add(blocks[0], exprs[1])) return false; } else { blocks[0] = ast_block_new(ctx); - if (!ast_block_add_expr(blocks[0], exprs[0]) || - !ast_block_add_expr(blocks[0], exprs[1])) + if (!ast_block_exprs_add(blocks[0], exprs[0]) || + !ast_block_exprs_add(blocks[0], exprs[1])) { return false; } @@ -900,7 +900,7 @@ static bool parser_close_call(parser_t *parser, shunt *sy) if (!params) { /* 1 param */ paramcount = 1; - if (!ast_call_add_param(call, sy->out[sy->out_count].out)) { + if (!ast_call_params_add(call, sy->out[sy->out_count].out)) { ast_delete(sy->out[sy->out_count].out); parseerror(parser, "out of memory"); return false; @@ -1698,7 +1698,7 @@ static ast_block* parser_parse_block(parser_t *parser) } if (!expr) continue; - if (!ast_block_add_expr(block, expr)) { + if (!ast_block_exprs_add(block, expr)) { ast_delete(expr); ast_block_delete(block); block = NULL;