From: Wolfgang (Blub) Bumiller Date: Sun, 2 Dec 2012 17:02:44 +0000 (+0100) Subject: Sanity check in ast_generate_accessors X-Git-Tag: 0.1.9~124^2~1 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=c926c4cb59dcae5aeedf7c45d7a020babd185717;p=xonotic%2Fgmqcc.git Sanity check in ast_generate_accessors --- diff --git a/ast.c b/ast.c index 69a16fe..f388eb3 100644 --- a/ast.c +++ b/ast.c @@ -1400,23 +1400,40 @@ error: /* clean up */ return false; } -bool ast_generate_accessors(ast_value *asvalue, ir_builder *ir) +bool ast_generate_accessors(ast_value *self, ir_builder *ir) { - if (asvalue->setter) { - if (!ast_global_codegen (asvalue->setter, ir, false) || - !ast_function_codegen(asvalue->setter->constval.vfunc, ir) || - !ir_function_finalize(asvalue->setter->constval.vfunc->ir_func)) + size_t i; + if (!self->setter || !self->getter) + return true; + for (i = 0; i < self->expression.count; ++i) { + if (!self->ir_values) { + compile_error(ast_ctx(self), "internal error: no array values generated for `%s`", self->name); + return false; + } + if (!self->ir_values[i]) { + compile_error(ast_ctx(self), "internal error: not all array values have been generated for `%s`", self->name); + return false; + } + if (self->ir_values[i]->life) { + compile_error(ast_ctx(self), "internal error: function containing `%s` already generated", self->name); + return false; + } + } + if (self->setter) { + if (!ast_global_codegen (self->setter, ir, false) || + !ast_function_codegen(self->setter->constval.vfunc, ir) || + !ir_function_finalize(self->setter->constval.vfunc->ir_func)) { - compile_error(ast_ctx(asvalue), "internal error: failed to generate setter for `%s`", asvalue->name); + compile_error(ast_ctx(self), "internal error: failed to generate setter for `%s`", self->name); return false; } } - if (asvalue->getter) { - if (!ast_global_codegen (asvalue->getter, ir, false) || - !ast_function_codegen(asvalue->getter->constval.vfunc, ir) || - !ir_function_finalize(asvalue->getter->constval.vfunc->ir_func)) + if (self->getter) { + if (!ast_global_codegen (self->getter, ir, false) || + !ast_function_codegen(self->getter->constval.vfunc, ir) || + !ir_function_finalize(self->getter->constval.vfunc->ir_func)) { - compile_error(ast_ctx(asvalue), "internal error: failed to generate getter for `%s`", asvalue->name); + compile_error(ast_ctx(self), "internal error: failed to generate getter for `%s`", self->name); return false; } }