Use std::vector for static_names

This commit is contained in:
Dale Weiler 2015-01-15 15:15:35 -05:00
parent 0ecfe18f49
commit 6e68526680
3 changed files with 13 additions and 25 deletions

32
ast.cpp
View file

@ -1188,8 +1188,6 @@ ast_function* ast_function_new(lex_ctx_t ctx, const char *name, ast_value *vtype
self->argc = NULL; self->argc = NULL;
self->fixedparams = NULL; self->fixedparams = NULL;
self->return_value = NULL; self->return_value = NULL;
self->static_names = NULL;
self->static_count = 0; self->static_count = 0;
return self; return self;
@ -1201,7 +1199,6 @@ cleanup:
void ast_function_delete(ast_function *self) void ast_function_delete(ast_function *self)
{ {
size_t i;
if (self->name) if (self->name)
mem_d((void*)self->name); mem_d((void*)self->name);
if (self->vtype) { if (self->vtype) {
@ -1213,9 +1210,8 @@ void ast_function_delete(ast_function *self)
*/ */
ast_unref(self->vtype); ast_unref(self->vtype);
} }
for (i = 0; i < vec_size(self->static_names); ++i) for (auto &it : self->static_names)
mem_d(self->static_names[i]); mem_d(it);
vec_free(self->static_names);
for (auto &it : self->blocks) for (auto &it : self->blocks)
ast_delete(it); ast_delete(it);
if (self->varargs) if (self->varargs)
@ -3339,9 +3335,8 @@ bool ast_state_codegen(ast_state *self, ast_function *func, bool lvalue, ir_valu
bool ast_call_codegen(ast_call *self, ast_function *func, bool lvalue, ir_value **out) bool ast_call_codegen(ast_call *self, ast_function *func, bool lvalue, ir_value **out)
{ {
ast_expression_codegen *cgen; ast_expression_codegen *cgen;
ir_value **params; std::vector<ir_value*> params;
ir_instr *callinstr; ir_instr *callinstr;
size_t i;
ir_value *funval = NULL; ir_value *funval = NULL;
@ -3362,17 +3357,15 @@ bool ast_call_codegen(ast_call *self, ast_function *func, bool lvalue, ir_value
if (!funval) if (!funval)
return false; return false;
params = NULL;
/* parameters */ /* parameters */
for (auto &it : self->params) { for (auto &it : self->params) {
ir_value *param; ir_value *param;
cgen = it->codegen; cgen = it->codegen;
if (!(*cgen)(it, func, false, &param)) if (!(*cgen)(it, func, false, &param))
goto error; return false;
if (!param) if (!param)
goto error; return false;
vec_push(params, param); params.push_back(param);
} }
/* varargs counter */ /* varargs counter */
@ -3393,20 +3386,15 @@ bool ast_call_codegen(ast_call *self, ast_function *func, bool lvalue, ir_value
ast_function_label(func, "call"), ast_function_label(func, "call"),
funval, !!(self->func->flags & AST_FLAG_NORETURN)); funval, !!(self->func->flags & AST_FLAG_NORETURN));
if (!callinstr) if (!callinstr)
goto error; return false;
for (i = 0; i < vec_size(params); ++i) { for (auto &it : params)
ir_call_param(callinstr, params[i]); ir_call_param(callinstr, it);
}
*out = ir_call_value(callinstr); *out = ir_call_value(callinstr);
self->expression.outr = *out; self->expression.outr = *out;
codegen_output_type(self, *out); codegen_output_type(self, *out);
vec_free(params);
return true; return true;
error:
vec_free(params);
return false;
} }

2
ast.h
View file

@ -631,7 +631,7 @@ struct ast_function
int builtin; int builtin;
/* list of used-up names for statics without the count suffix */ /* list of used-up names for statics without the count suffix */
char **static_names; std::vector<char*> static_names;
/* number of static variables, by convention this includes the /* number of static variables, by convention this includes the
* ones without the count-suffix - remember this when dealing * ones without the count-suffix - remember this when dealing
* with savegames. uint instead of size_t as %zu in printf is * with savegames. uint instead of size_t as %zu in printf is

View file

@ -5435,7 +5435,7 @@ static bool parse_variable(parser_t *parser, ast_block *localblock, bool nofield
* counter value. * counter value.
* The counter is incremented either way. * The counter is incremented either way.
*/ */
sn_size = vec_size(parser->function->static_names); sn_size = parser->function->static_names.size();
for (sn = 0; sn != sn_size; ++sn) { for (sn = 0; sn != sn_size; ++sn) {
if (strcmp(parser->function->static_names[sn], var->name) == 0) if (strcmp(parser->function->static_names[sn], var->name) == 0)
break; break;
@ -5447,7 +5447,7 @@ static bool parse_variable(parser_t *parser, ast_block *localblock, bool nofield
mem_d(num); mem_d(num);
} }
else else
vec_push(parser->function->static_names, util_strdup(var->name)); parser->function->static_names.push_back(util_strdup(var->name));
parser->function->static_count++; parser->function->static_count++;
ast_value_set_name(var, defname); ast_value_set_name(var, defname);