ast_expression_init((ast_expression*)self, (ast_expression_codegen*)&ast_switch_codegen);
self->operand = op;
- self->cases = NULL;
ast_propagate_effects(self, 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);
ir_block *bout = NULL;
ir_block *bfall = NULL;
size_t bout_id;
- size_t c;
char typestr[1024];
uint16_t cmpinstr;
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];
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 */
{
ast_expression expression;
ast_expression *operand;
- ast_switch_case *cases;
+ std::vector<ast_switch_case> cases;
};
ast_switch* ast_switch_new(lex_ctx_t ctx, ast_expression *op);
return false;
}
swcase.code = (ast_expression*)caseblock;
- vec_push(switchnode->cases, swcase);
+ switchnode->cases.push_back(swcase);
while (true) {
ast_expression *expr;
if (parser->tok == '}')