static void parser_addglobal(parser_t *parser, const char *name, ast_expression *e)
{
- vec_push(parser->globals, e);
+ parser->globals.push_back(e);
util_htset(parser->htglobals, name, e);
}
ast_block_delete(block);
goto enderr;
}
- vec_push(parser->functions, func);
+ parser->functions.push_back(func);
}
parser_enterblock(parser);
enderrfn:
(void)!parser_leaveblock(parser);
- vec_pop(parser->functions);
+ parser->functions.pop_back();
ast_function_delete(func);
var->constval.vfunc = NULL;
vec_push(func->blocks, body);
*out = fval;
- vec_push(parser->accessors, fval);
+ parser->accessors.push_back(fval);
return true;
}
was_end = false;
if (!strcmp(var->name, "end_sys_globals")) {
var->uses++;
- parser->crc_globals = vec_size(parser->globals);
+ parser->crc_globals = parser->globals.size();
was_end = true;
}
else if (!strcmp(var->name, "end_sys_fields")) {
var->uses++;
- parser->crc_fields = vec_size(parser->fields);
+ parser->crc_fields = parser->fields.size();
was_end = true;
}
if (was_end && var->expression.vtype == TYPE_FIELD) {
/* deal with global variables, fields, functions */
if (!nofields && var->expression.vtype == TYPE_FIELD && parser->tok != '=') {
var->isfield = true;
- vec_push(parser->fields, (ast_expression*)var);
+ parser->fields.push_back((ast_expression*)var);
util_htset(parser->htfields, var->name, var);
if (isvector) {
for (i = 0; i < 3; ++i) {
- vec_push(parser->fields, (ast_expression*)me[i]);
+ parser->fields.push_back((ast_expression*)me[i]);
util_htset(parser->htfields, me[i]->name, me[i]);
}
}
ast_value_set_name(var, defname);
/* push it to the to-be-generated globals */
- vec_push(parser->globals, (ast_expression*)var);
+ parser->globals.push_back((ast_expression*)var);
/* same game for the vector members */
if (isvector) {
vec_append(defname, ln, me[i]->name);
ast_member_set_name(me[i], defname);
- vec_push(parser->globals, (ast_expression*)me[i]);
+ parser->globals.push_back((ast_expression*)me[i]);
}
}
vec_free(defname);
parseerror(parser, "failed to allocate function for `%s`", var->name);
break;
}
- vec_push(parser->functions, func);
+ parser->functions.push_back(func);
func->builtin = -builtin_num-1;
}
else
localblock->locals.pop_back();
/* push it to the to-be-generated globals */
- vec_push(parser->globals, (ast_expression*)var);
+ parser->globals.push_back((ast_expression*)var);
if (isvector)
for (i = 0; i < 3; ++i)
- vec_push(parser->globals, (ast_expression*)last_me[i]);
+ parser->globals.push_back((ast_expression*)last_me[i]);
folded_const = true;
}
if (parser->ast_cleaned)
return;
parser->ast_cleaned = true;
- for (i = 0; i < vec_size(parser->accessors); ++i) {
- ast_delete(parser->accessors[i]->constval.vfunc);
- parser->accessors[i]->constval.vfunc = NULL;
- ast_delete(parser->accessors[i]);
- }
- for (i = 0; i < vec_size(parser->functions); ++i) {
- ast_delete(parser->functions[i]);
- }
- for (i = 0; i < vec_size(parser->fields); ++i) {
- ast_delete(parser->fields[i]);
- }
- for (i = 0; i < vec_size(parser->globals); ++i) {
- ast_delete(parser->globals[i]);
+ for (auto &it : parser->accessors) {
+ ast_delete(it->constval.vfunc);
+ it->constval.vfunc = nullptr;
+ ast_delete(it);
}
- vec_free(parser->accessors);
- vec_free(parser->functions);
- vec_free(parser->globals);
- vec_free(parser->fields);
+ for (auto &it : parser->functions) ast_delete(it);
+ for (auto &it : parser->globals) ast_delete(it);
+ for (auto &it : parser->fields) ast_delete(it);
for (i = 0; i < vec_size(parser->variables); ++i)
util_htdel(parser->variables[i]);
}
static bool parser_set_coverage_func(parser_t *parser, ir_builder *ir) {
- size_t i;
ast_expression *expr;
ast_value *cov;
ast_function *func;
if (!OPTS_OPTION_BOOL(OPTION_COVERAGE))
return true;
- func = NULL;
- for (i = 0; i != vec_size(parser->functions); ++i) {
- if (!strcmp(parser->functions[i]->name, "coverage")) {
- func = parser->functions[i];
+ func = nullptr;
+ for (auto &it : parser->functions) {
+ if (!strcmp(it->name, "coverage")) {
+ func = it;
break;
}
}
bool parser_finish(parser_t *parser, const char *output)
{
- size_t i;
- ir_builder *ir;
- bool retval = true;
+ ir_builder *ir;
+ bool retval = true;
if (compile_errors) {
con_out("*** there were compile errors\n");
return false;
}
- for (i = 0; i < vec_size(parser->fields); ++i) {
- ast_value *field;
+ for (auto &it : parser->fields) {
bool hasvalue;
- if (!ast_istype(parser->fields[i], ast_value))
+ if (!ast_istype(it, ast_value))
continue;
- field = (ast_value*)parser->fields[i];
+ ast_value *field = (ast_value*)it;
hasvalue = field->hasvalue;
field->hasvalue = false;
if (!ast_global_codegen((ast_value*)field, ir, true)) {
(void)!ir_value_set_field(field->ir_v, ifld);
}
}
- for (i = 0; i < vec_size(parser->globals); ++i) {
+ for (auto &it : parser->globals) {
ast_value *asvalue;
- if (!ast_istype(parser->globals[i], ast_value))
+ if (!ast_istype(it, ast_value))
continue;
- asvalue = (ast_value*)(parser->globals[i]);
+ asvalue = (ast_value*)it;
if (!asvalue->uses && !asvalue->hasvalue && asvalue->expression.vtype != TYPE_FUNCTION) {
retval = retval && !compile_warning(ast_ctx(asvalue), WARN_UNUSED_VARIABLE,
"unused global: `%s`", asvalue->name);
/* Build function vararg accessor ast tree now before generating
* immediates, because the accessors may add new immediates
*/
- for (i = 0; i < vec_size(parser->functions); ++i) {
- ast_function *f = parser->functions[i];
+ for (auto &f : parser->functions) {
if (f->varargs) {
if (parser->max_param_count > f->vtype->expression.params.size()) {
f->varargs->expression.count = parser->max_param_count - f->vtype->expression.params.size();
/* before generating any functions we need to set the coverage_func */
if (!parser_set_coverage_func(parser, ir))
return false;
-
- for (i = 0; i < vec_size(parser->globals); ++i) {
- ast_value *asvalue;
- if (!ast_istype(parser->globals[i], ast_value))
+ for (auto &it : parser->globals) {
+ if (!ast_istype(it, ast_value))
continue;
- asvalue = (ast_value*)(parser->globals[i]);
+ ast_value *asvalue = (ast_value*)it;
if (!(asvalue->expression.flags & AST_FLAG_INITIALIZED))
{
if (asvalue->cvq == CV_CONST && !asvalue->hasvalue)
return false;
}
}
- for (i = 0; i < vec_size(parser->fields); ++i) {
- ast_value *asvalue;
- asvalue = (ast_value*)(parser->fields[i]->next);
-
+ for (auto &it : parser->fields) {
+ ast_value *asvalue = (ast_value*)it->next;
if (!ast_istype((ast_expression*)asvalue, ast_value))
continue;
if (asvalue->expression.vtype != TYPE_ARRAY)
ir_builder_delete(ir);
return false;
}
- for (i = 0; i < vec_size(parser->functions); ++i) {
- ast_function *f = parser->functions[i];
+ for (auto &f : parser->functions) {
if (!ast_function_codegen(f, ir)) {
con_out("failed to generate function %s\n", f->name);
ir_builder_delete(ir);
if (OPTS_OPTION_BOOL(OPTION_DUMP))
ir_builder_dump(ir, con_out);
- for (i = 0; i < vec_size(parser->functions); ++i) {
- if (!ir_function_finalize(parser->functions[i]->ir_func)) {
- con_out("failed to finalize function %s\n", parser->functions[i]->name);
+ for (auto &it : parser->functions) {
+ if (!ir_function_finalize(it->ir_func)) {
+ con_out("failed to finalize function %s\n", it->name);
ir_builder_delete(ir);
return false;
}