From: Wolfgang Bumiller Date: Thu, 26 Jul 2012 21:22:51 +0000 (+0200) Subject: handling return X-Git-Tag: 0.1-rc1~397 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=a0d78e985c928bb209345f398f99a6bacc55de14;p=xonotic%2Fgmqcc.git handling return --- diff --git a/parser.c b/parser.c index 1eeda39..4717e4e 100644 --- a/parser.c +++ b/parser.c @@ -556,6 +556,26 @@ static bool parser_body_do(parser_t *parser, ast_block *block) return false; return true; } + else if (parser->tok == TOKEN_KEYWORD) + { + if (!strcmp(parser_tokval(parser), "return")) + { + ast_expression *exp = parser_expression(parser); + ast_return *ret; + if (!exp) + return false; + ret = ast_return_new(exp->expression.node.context, exp); + if (!ret) { + ast_delete(exp); + return false; + } + if (!ast_block_exprs_add(block, (ast_expression*)ret)) { + ast_delete(ret); + return false; + } + return true; + } + } else if (parser->tok == '{') { /* a block */ @@ -567,8 +587,10 @@ static bool parser_body_do(parser_t *parser, ast_block *block) ast_expression *exp = parser_expression(parser); if (!exp) return false; - if (!ast_block_exprs_add(block, exp)) + if (!ast_block_exprs_add(block, exp)) { + ast_delete(exp); return false; + } return true; } }