X-Git-Url: https://git.xonotic.org/?p=xonotic%2Fgmqcc.git;a=blobdiff_plain;f=ast.c;h=bb15b3570ec68f8b2d2b797e3c796890941af9c1;hp=332f708fbad59d4c9c951e728641df9494c57ba8;hb=ab79dbd22aa7551c702a8990cb4347e8823a2f17;hpb=179da9241c50a79f76ac9ec9c097702ec21ad2b3 diff --git a/ast.c b/ast.c index 332f708..bb15b35 100644 --- a/ast.c +++ b/ast.c @@ -1025,7 +1025,7 @@ bool ast_call_check_types(ast_call *self, ast_expression *va_type) for (i = 0; i < count; ++i) { if (ast_istype(self->params[i], ast_argpipe)) { - // warn about type safety instead + /* warn about type safety instead */ if (i+1 != count) { compile_error(ast_ctx(self), "argpipe must be the last parameter to a function call"); return false; @@ -1047,7 +1047,7 @@ bool ast_call_check_types(ast_call *self, ast_expression *va_type) if (count > vec_size(func->params) && func->varparam) { for (; i < count; ++i) { if (ast_istype(self->params[i], ast_argpipe)) { - // warn about type safety instead + /* warn about type safety instead */ if (i+1 != count) { compile_error(ast_ctx(self), "argpipe must be the last parameter to a function call"); return false; @@ -1055,11 +1055,11 @@ bool ast_call_check_types(ast_call *self, ast_expression *va_type) if (!ast_call_check_vararg(self, va_type, func->varparam)) retval = false; } - if (!ast_compare_type(self->params[i], func->varparam)) + else if (!ast_compare_type(self->params[i], func->varparam)) { ast_type_to_string(self->params[i], tgot, sizeof(tgot)); ast_type_to_string(func->varparam, texp, sizeof(texp)); - compile_error(ast_ctx(self), "invalid type for parameter %u in function call: expected %s, got %s", + compile_error(ast_ctx(self), "invalid type for variadic parameter %u in function call: expected %s, got %s", (unsigned int)(i+1), texp, tgot); /* we don't immediately return */ retval = false; @@ -1152,16 +1152,15 @@ ast_function* ast_function_new(lex_ctx ctx, const char *name, ast_value *vtype) { ast_instantiate(ast_function, ctx, ast_function_delete); - if (!vtype || - vtype->hasvalue || - vtype->expression.vtype != TYPE_FUNCTION) - { + if (!vtype) { + compile_error(ast_ctx(self), "internal error: ast_function_new condition 0"); + goto cleanup; + } else if (vtype->hasvalue || vtype->expression.vtype != TYPE_FUNCTION) { compile_error(ast_ctx(self), "internal error: ast_function_new condition %i %i type=%i (probably 2 bodies?)", (int)!vtype, (int)vtype->hasvalue, vtype->expression.vtype); - mem_d(self); - return NULL; + goto cleanup; } self->vtype = vtype; @@ -1186,6 +1185,10 @@ ast_function* ast_function_new(lex_ctx ctx, const char *name, ast_value *vtype) self->return_value = NULL; return self; + +cleanup: + mem_d(self); + return NULL; } void ast_function_delete(ast_function *self) @@ -1560,7 +1563,7 @@ bool ast_global_codegen(ast_value *self, ir_builder *ir, bool isfield) return true; error: /* clean up */ - ir_value_delete(v); + if(v) ir_value_delete(v); return false; } @@ -2880,9 +2883,13 @@ bool ast_loop_codegen(ast_loop *self, ast_function *func, bool lvalue, ir_value /* Now all blocks are in place */ /* From 'bin' we jump to whatever comes first */ if (bprecond) tmpblock = bprecond; - else if (bbody) tmpblock = bbody; + else tmpblock = bbody; /* can never be null */ + + /* DEAD CODE else if (bpostcond) tmpblock = bpostcond; else tmpblock = bout; + */ + if (!ir_block_create_jump(bin, ast_ctx(self), tmpblock)) return false; @@ -2890,10 +2897,13 @@ bool ast_loop_codegen(ast_loop *self, ast_function *func, bool lvalue, ir_value if (bprecond) { ir_block *ontrue, *onfalse; - if (bbody) ontrue = bbody; + ontrue = bbody; /* can never be null */ + + /* all of this is dead code else if (bincrement) ontrue = bincrement; - else if (bpostcond) ontrue = bpostcond; - else ontrue = bprecond; + else ontrue = bpostcond; + */ + onfalse = bout; if (self->pre_not) { tmpblock = ontrue; @@ -2931,9 +2941,13 @@ bool ast_loop_codegen(ast_loop *self, ast_function *func, bool lvalue, ir_value { ir_block *ontrue, *onfalse; if (bprecond) ontrue = bprecond; - else if (bbody) ontrue = bbody; + else ontrue = bbody; /* can never be null */ + + /* all of this is dead code else if (bincrement) ontrue = bincrement; else ontrue = bpostcond; + */ + onfalse = bout; if (self->post_not) { tmpblock = ontrue;