]> git.xonotic.org Git - xonotic/gmqcc.git/commitdiff
handling return
authorWolfgang Bumiller <wolfgang.linux@bumiller.com>
Thu, 26 Jul 2012 21:22:51 +0000 (23:22 +0200)
committerWolfgang Bumiller <wolfgang.linux@bumiller.com>
Thu, 26 Jul 2012 21:22:51 +0000 (23:22 +0200)
parser.c

index 1eeda391f2dc85c6e0221662f5f0bdac4c5fd844..4717e4e2020526b15dad85e72a1dc22ead4536c6 100644 (file)
--- 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;
     }
 }