void ast_unary_delete(ast_unary *self)
{
- ast_unref(self->operand);
+ if (self->operand) ast_unref(self->operand);
ast_expression_delete((ast_expression*)self);
mem_d(self);
}
ast_loop* ast_loop_new(lex_ctx ctx,
ast_expression *initexpr,
- ast_expression *precond,
- ast_expression *postcond,
+ ast_expression *precond, bool pre_not,
+ ast_expression *postcond, bool post_not,
ast_expression *increment,
ast_expression *body)
{
self->increment = increment;
self->body = body;
+ self->pre_not = pre_not;
+ self->post_not = post_not;
+
if (initexpr)
ast_propagate_effects(self, initexpr);
if (precond)
from = self->labelbuf + sizeof(self->labelbuf)-1;
*from-- = 0;
do {
- unsigned int digit = id % 10;
- *from = digit + '0';
+ *from-- = (id%10) + '0';
id /= 10;
} while (id);
+ ++from;
memcpy(from - len, prefix, len);
return from - len;
}
}
#define codegen_output_type(a,o) (_ast_codegen_output_type(&((a)->expression),(o)))
-#define codegen_output_type_expr(a,o) (_ast_codegen_output_type(a,(o)))
bool ast_value_codegen(ast_value *self, ast_function *func, bool lvalue, ir_value **out)
{
}
/* TODO: check return types */
- if (!self->curblock->is_return)
+ if (!self->curblock->final)
{
if (!self->vtype->expression.next ||
self->vtype->expression.next->expression.vtype == TYPE_VOID)
{
ast_expression_codegen *gen;
if (func->curblock->final && !ast_istype(self->exprs[i], ast_label)) {
- if (OPTS_FLAG(ALLOW_UNREACHABLE_CODE))
- continue;
- compile_error(ast_ctx(self->exprs[i]), "unreachable statement");
- return false;
+ if (compile_warning(ast_ctx(self->exprs[i]), WARN_UNREACHABLE_CODE, "unreachable statement"))
+ return false;
+ continue;
}
gen = self->exprs[i]->expression.codegen;
if (!(*gen)(self->exprs[i], func, false, out))
else if (bpostcond) ontrue = bpostcond;
else ontrue = bprecond;
onfalse = bout;
+ if (self->pre_not) {
+ tmpblock = ontrue;
+ ontrue = onfalse;
+ onfalse = tmpblock;
+ }
if (!ir_block_create_if(end_bprecond, ast_ctx(self), precond, ontrue, onfalse))
return false;
}
else if (bincrement) ontrue = bincrement;
else ontrue = bpostcond;
onfalse = bout;
+ if (self->post_not) {
+ tmpblock = ontrue;
+ ontrue = onfalse;
+ onfalse = tmpblock;
+ }
if (!ir_block_create_if(end_bpostcond, ast_ctx(self), postcond, ontrue, onfalse))
return false;
}