From: Dale Weiler Date: Thu, 17 Oct 2013 07:39:14 +0000 (-0400) Subject: Enforce void type on accumulatable functions. X-Git-Tag: 0.3.5~15 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=4da820ef61ef6201723448802af85f50e25fd61a;p=xonotic%2Fgmqcc.git Enforce void type on accumulatable functions. --- diff --git a/parser.c b/parser.c index 628f89d..2ac19ec 100644 --- a/parser.c +++ b/parser.c @@ -3991,11 +3991,21 @@ static bool parse_function_body(parser_t *parser, ast_value *var) } /* accumulation? */ - if (var->hasvalue) { + if (var->hasvalue && var->expression.vtype == TYPE_FUNCTION) { ast_value *accum = NULL; ast_function *previous = NULL; char acname[1024]; + /* only void please */ + if (var->expression.next->vtype != TYPE_VOID) { + parseerror(parser, "accumulated function `%s` declared with return type `%s` (accumulated functions must return void)", + var->name, + type_name[var->expression.next->vtype] + ); + ast_block_delete(block); + goto enderr; + } + /* generate a new name increasing the accumulation count*/ util_snprintf(acname, sizeof(acname), "$ACCUMULATE_%s_%d", var->name, var->constval.vfunc->accumulation++); accum = ast_value_new(parser_ctx(parser), acname, ((ast_expression*)var)->vtype);