X-Git-Url: http://de.git.xonotic.org/?p=xonotic%2Fgmqcc.git;a=blobdiff_plain;f=ast.cpp;h=efff1116d0d1f00afabeb97e1a925d4b9e6bafbc;hp=6db9befa22d489980bc8b82b4d5fd1e1268c7cec;hb=539dc4a3dca0a40f465ee19a26663c0fffdf8a1e;hpb=987f765c201bd81a84fb20d8858de70a2f4e47ae diff --git a/ast.cpp b/ast.cpp index 6db9bef..efff111 100644 --- a/ast.cpp +++ b/ast.cpp @@ -864,7 +864,6 @@ ast_switch* ast_switch_new(lex_ctx_t ctx, ast_expression *op) ast_expression_init((ast_expression*)self, (ast_expression_codegen*)&ast_switch_codegen); self->operand = op; - self->cases = NULL; ast_propagate_effects(self, op); @@ -873,15 +872,13 @@ ast_switch* ast_switch_new(lex_ctx_t ctx, ast_expression *op) void ast_switch_delete(ast_switch *self) { - size_t i; ast_unref(self->operand); - for (i = 0; i < vec_size(self->cases); ++i) { - if (self->cases[i].value) - ast_unref(self->cases[i].value); - ast_unref(self->cases[i].code); + for (auto &it : self->cases) { + if (it.value) + ast_unref(it.value); + ast_unref(it.code); } - vec_free(self->cases); ast_expression_delete((ast_expression*)self); mem_d(self); @@ -1177,7 +1174,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 +1219,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 +1780,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 +1818,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 +1853,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; } @@ -3082,7 +3075,6 @@ bool ast_switch_codegen(ast_switch *self, ast_function *func, bool lvalue, ir_va ir_block *bout = NULL; ir_block *bfall = NULL; size_t bout_id; - size_t c; char typestr[1024]; uint16_t cmpinstr; @@ -3105,7 +3097,7 @@ bool ast_switch_codegen(ast_switch *self, ast_function *func, bool lvalue, ir_va if (!(*cgen)((ast_expression*)(self->operand), func, false, &irop)) return false; - if (!vec_size(self->cases)) + if (self->cases.empty()) return true; cmpinstr = type_eq_instr[irop->vtype]; @@ -3124,12 +3116,12 @@ bool ast_switch_codegen(ast_switch *self, ast_function *func, bool lvalue, ir_va vec_push(func->breakblocks, bout); /* Now create all cases */ - for (c = 0; c < vec_size(self->cases); ++c) { + for (auto &it : self->cases) { ir_value *cond, *val; ir_block *bcase, *bnot; size_t bnot_id; - ast_switch_case *swcase = &self->cases[c]; + ast_switch_case *swcase = ⁢ if (swcase->value) { /* A regular case */