From fec07921a4eef78453a5705d3cac502e7cfb6665 Mon Sep 17 00:00:00 2001 From: Wolfgang Bumiller Date: Thu, 19 Jul 2012 18:14:08 +0200 Subject: [PATCH] removing params vector from ast_function, params are stored in its ast_value only --- ast.c | 9 ++------- ast.h | 4 ++-- test/ast-macros.h | 5 ++++- 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/ast.c b/ast.c index e50f168..d519919 100644 --- a/ast.c +++ b/ast.c @@ -399,7 +399,6 @@ ast_function* ast_function_new(lex_ctx ctx, const char *name, ast_value *vtype) self->vtype = vtype; self->name = name ? util_strdup(name) : NULL; MEM_VECTOR_INIT(self, blocks); - MEM_VECTOR_INIT(self, params); self->labelcount = 0; self->builtin = 0; @@ -417,7 +416,6 @@ ast_function* ast_function_new(lex_ctx ctx, const char *name, ast_value *vtype) } MEM_VEC_FUNCTIONS(ast_function, ast_block*, blocks) -MEM_VEC_FUNCTIONS(ast_function, ast_value*, params) void ast_function_delete(ast_function *self) { @@ -436,9 +434,6 @@ void ast_function_delete(ast_function *self) for (i = 0; i < self->blocks_count; ++i) ast_delete(self->blocks[i]); MEM_VECTOR_CLEAR(self, blocks); - for (i = 0; i < self->params_count; ++i) - ast_delete(self->params[i]); - MEM_VECTOR_CLEAR(self, params); mem_d(self); } @@ -614,9 +609,9 @@ bool ast_function_codegen(ast_function *self, ir_builder *ir) return false; } - for (i = 0; i < self->params_count; ++i) + for (i = 0; i < self->vtype->params_count; ++i) { - if (!ir_function_params_add(irf, self->params[i]->expression.vtype)) + if (!ir_function_params_add(irf, self->vtype->params[i]->expression.vtype)) return false; } diff --git a/ast.h b/ast.h index a08c4c0..458d80f 100644 --- a/ast.h +++ b/ast.h @@ -116,6 +116,8 @@ struct ast_value_s */ MEM_VECTOR_MAKE(ast_value*, params); }; +MEM_VECTOR_PROTO(ast_value, ast_value*, params); + ast_value* ast_value_new(lex_ctx ctx, const char *name, int qctype); /* This will NOT delete an underlying ast_function */ void ast_value_delete(ast_value*); @@ -358,7 +360,6 @@ struct ast_function_s char labelbuf[64]; MEM_VECTOR_MAKE(ast_block*, blocks); - MEM_VECTOR_MAKE(ast_value*, params); }; ast_function* ast_function_new(lex_ctx ctx, const char *name, ast_value *vtype); /* This will NOT delete the underlying ast_value */ @@ -369,7 +370,6 @@ void ast_function_delete(ast_function*); const char* ast_function_label(ast_function*, const char *prefix); MEM_VECTOR_PROTO(ast_function, ast_block*, blocks); -MEM_VECTOR_PROTO(ast_function, ast_value*, params); bool ast_function_codegen(ast_function *self, ir_builder *builder); diff --git a/test/ast-macros.h b/test/ast-macros.h index 5b92a38..c17b753 100644 --- a/test/ast-macros.h +++ b/test/ast-macros.h @@ -77,6 +77,7 @@ do { \ #define BUILTIN(name, outtype, number) \ do { \ ast_function *func_##name; \ + ast_value *thisfuncval; \ ast_function *thisfunc; \ DEFVAR(return_##name); \ VARnamed(TYPE_FUNCTION, name, name); \ @@ -86,6 +87,8 @@ do { \ func_##name = ast_function_new(ctx, #name, name); \ thisfunc = func_##name; \ (void)thisfunc; \ + thisfuncval = name; \ + (void)thisfuncval; \ assert(functions_add(func_##name) >= 0); \ func_##name->builtin = number; @@ -95,7 +98,7 @@ do { \ do { \ DEFVAR(parm); \ VARnamed(ptype, parm, name); \ - assert(ast_function_params_add(thisfunc, parm)); \ + assert(ast_value_params_add(thisfuncval, parm)); \ } while(0) #define FUNCTION(name, outtype) \ -- 2.39.2