removing params vector from ast_function, params are stored in its ast_value only

This commit is contained in:
Wolfgang Bumiller 2012-07-19 18:14:08 +02:00
parent fe8457f9ba
commit fec07921a4
3 changed files with 8 additions and 10 deletions

9
ast.c
View file

@ -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;
}

4
ast.h
View file

@ -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);

View file

@ -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) \