Use std::vector for ast blocks

This commit is contained in:
Dale Weiler 2015-01-15 14:15:44 -05:00
parent 987f765c20
commit 2e037832d3
5 changed files with 29 additions and 44 deletions

16
ast.cpp
View file

@ -1177,7 +1177,6 @@ ast_function* ast_function_new(lex_ctx_t ctx, const char *name, ast_value *vtype
self->vtype = vtype;
self->name = name ? util_strdup(name) : NULL;
self->blocks = NULL;
self->labelcount = 0;
self->builtin = 0;
@ -1223,9 +1222,8 @@ void ast_function_delete(ast_function *self)
for (i = 0; i < vec_size(self->static_names); ++i)
mem_d(self->static_names[i]);
vec_free(self->static_names);
for (i = 0; i < vec_size(self->blocks); ++i)
ast_delete(self->blocks[i]);
vec_free(self->blocks);
for (auto &it : self->blocks)
ast_delete(it);
vec_free(self->breakblocks);
vec_free(self->continueblocks);
if (self->varargs)
@ -1785,8 +1783,6 @@ bool ast_function_codegen(ast_function *self, ir_builder *ir)
ast_expression *ec;
ast_expression_codegen *cgen;
size_t i;
(void)ir;
irf = self->ir_func;
@ -1825,7 +1821,7 @@ bool ast_function_codegen(ast_function *self, ir_builder *ir)
return false;
}
if (!vec_size(self->blocks)) {
if (self->blocks.empty()) {
compile_error(ast_ctx(self), "function `%s` has no body", self->name);
return false;
}
@ -1860,9 +1856,9 @@ bool ast_function_codegen(ast_function *self, ir_builder *ir)
}
}
for (i = 0; i < vec_size(self->blocks); ++i) {
cgen = self->blocks[i]->expression.codegen;
if (!(*cgen)((ast_expression*)self->blocks[i], self, false, &dummy))
for (auto &it : self->blocks) {
cgen = it->expression.codegen;
if (!(*cgen)((ast_expression*)it, self, false, &dummy))
return false;
}

2
ast.h
View file

@ -649,7 +649,7 @@ struct ast_function
* here to use in ast_function_label.
*/
char labelbuf[64];
ast_block* *blocks;
std::vector<ast_block*> blocks;
ast_value *varargs;
ast_value *argc;
ast_value *fixedparams;

View file

@ -1926,7 +1926,6 @@ void ftepp_add_define(ftepp_t *ftepp, const char *source, const char *name)
lex_ctx_t ctx = { "__builtin__", 0, 0 };
ctx.file = source;
macro = ppmacro_new(ctx, name);
/*vec_push(ftepp->macros, macro);*/
util_htset(ftepp->macros, name, macro);
}

View file

@ -85,7 +85,7 @@ static ast_expression *intrin_isfinite(intrin_t *intrin) {
)
);
vec_push(func->blocks, block);
func->blocks.push_back(block);
intrin_reg(intrin, value, func);
return (ast_expression*)value;;
@ -130,7 +130,7 @@ static ast_expression *intrin_isinf(intrin_t *intrin) {
);
value->expression.params.push_back(x);
vec_push(func->blocks, body);
func->blocks.push_back(body);
intrin_reg(intrin, value, func);
@ -175,7 +175,7 @@ static ast_expression *intrin_isnan(intrin_t *intrin) {
);
value->expression.params.push_back(arg1);
vec_push(func->blocks, body);
func->blocks.push_back(body);
intrin_reg(intrin, value, func);
@ -205,7 +205,7 @@ static ast_expression *intrin_isnormal(intrin_t *intrin) {
)
);
vec_push(func->blocks, body);
func->blocks.push_back(body);
intrin_reg(intrin, value, func);
return (ast_expression*)value;
}
@ -241,7 +241,7 @@ static ast_expression *intrin_signbit(intrin_t *intrin) {
)
);
vec_push(func->blocks, body);
func->blocks.push_back(body);
intrin_reg(intrin, value, func);
return (ast_expression*)value;
}
@ -294,7 +294,7 @@ static ast_expression *intrin_acosh(intrin_t *intrin) {
)
);
vec_push(func->blocks, body);
func->blocks.push_back(body);
intrin_reg(intrin, value, func);
return (ast_expression*)value;
}
@ -347,7 +347,7 @@ static ast_expression *intrin_asinh(intrin_t *intrin) {
)
);
vec_push(func->blocks, body);
func->blocks.push_back(body);
intrin_reg(intrin, value, func);
return (ast_expression*)value;
}
@ -396,7 +396,7 @@ static ast_expression *intrin_atanh(intrin_t *intrin) {
)
);
vec_push(func->blocks, body);
func->blocks.push_back(body);
intrin_reg(intrin, value, func);
return (ast_expression*)value;
}
@ -509,8 +509,7 @@ static ast_expression *intrin_exp(intrin_t *intrin) {
)
);
vec_push(func->blocks, body);
func->blocks.push_back(body);
intrin_reg(intrin, value, func);
return (ast_expression*)value;
}
@ -540,8 +539,7 @@ static ast_expression *intrin_exp2(intrin_t *intrin) {
)
);
vec_push(func->blocks, body);
func->blocks.push_back(body);
intrin_reg(intrin, value, func);
return (ast_expression*)value;
}
@ -576,7 +574,7 @@ static ast_expression *intrin_expm1(intrin_t *intrin) {
)
);
vec_push(func->blocks, body);
func->blocks.push_back(body);
intrin_reg(intrin, value, func);
return (ast_expression*)value;
}
@ -1021,8 +1019,7 @@ static ast_expression *intrin_pow(intrin_t *intrin) {
);
/* } */
vec_push(func->blocks, body);
func->blocks.push_back(body);
intrin_reg(intrin, value, func);
return (ast_expression*)value;
}
@ -1118,9 +1115,8 @@ static ast_expression *intrin_mod(intrin_t *intrin) {
)
);
vec_push(func->blocks, body);
func->blocks.push_back(body);
intrin_reg(intrin, value, func);
return (ast_expression*)value;
}
@ -1158,10 +1154,8 @@ static ast_expression *intrin_fabs(intrin_t *intrin) {
value->expression.params.push_back(arg1);
vec_push(func->blocks, body);
func->blocks.push_back(body);
intrin_reg(intrin, value, func);
return (ast_expression*)value;
}
@ -1232,9 +1226,8 @@ static ast_expression *intrin_epsilon(intrin_t *intrin) {
)
);
vec_push(func->blocks, body);
func->blocks.push_back(body);
intrin_reg(intrin, value, func);
return (ast_expression*)value;
}
@ -1273,9 +1266,8 @@ static ast_expression *intrin_nan(intrin_t *intrin) {
)
);
vec_push(func->blocks, block);
func->blocks.push_back(block);
intrin_reg(intrin, value, func);
return (ast_expression*)value;
}
@ -1321,9 +1313,8 @@ static ast_expression *intrin_inf(intrin_t *intrin) {
)
);
vec_push(func->blocks, block);
func->blocks.push_back(block);
intrin_reg(intrin, value, func);
return (ast_expression*)value;
}
@ -1866,9 +1857,8 @@ static ast_expression *intrin_ln(intrin_t *intrin) {
)
);
vec_push(func->blocks, block);
func->blocks.push_back(block);
intrin_reg(intrin, value, func);
return (ast_expression*)value;
}
@ -1891,7 +1881,7 @@ static ast_expression *intrin_log_variant(intrin_t *intrin, const char *name, fl
)
);
vec_push(func->blocks, body);
func->blocks.push_back(body);
intrin_reg(intrin, value, func);
return (ast_expression*)value;
}
@ -1948,7 +1938,7 @@ static ast_expression *intrin_shift_variant(intrin_t *intrin, const char *name,
)
);
vec_push(func->blocks, body);
func->blocks.push_back(body);
intrin_reg(intrin, value, func);
return (ast_expression*)value;
}

View file

@ -4096,7 +4096,7 @@ static bool parse_function_body(parser_t *parser, ast_value *var)
goto enderrfn;
}
vec_push(func->blocks, block);
func->blocks.push_back(block);
parser->function = old;
if (!parser_leaveblock(parser))
@ -4356,7 +4356,7 @@ static bool parser_create_array_accessor(parser_t *parser, ast_value *array, con
return false;
}
vec_push(func->blocks, body);
func->blocks.push_back(body);
*out = fval;
parser->accessors.push_back(fval);