]> de.git.xonotic.org Git - xonotic/gmqcc.git/commitdiff
fix for loops
authorWolfgang Bumiller <wry.git@bumiller.com>
Tue, 20 Jan 2015 19:55:27 +0000 (20:55 +0100)
committerWolfgang Bumiller <wry.git@bumiller.com>
Tue, 20 Jan 2015 19:55:27 +0000 (20:55 +0100)
parser.cpp
tests/forloop.qc [new file with mode: 0644]
tests/forloop.tmpl [new file with mode: 0644]

index 75f9312fc4bcd5ba61305e39889af8c46deb71d5..72f5479095c3b4a4ae3dacdf7a48fcdafbdc5b4e 100644 (file)
@@ -2480,18 +2480,20 @@ static bool parse_for_go(parser_t *parser, ast_block *block, ast_expression **ou
         initexpr = parse_expression_leave(parser, false, false, false);
         if (!initexpr)
             goto onerr;
-
         /* move on to condition */
         if (parser->tok != ';') {
             parseerror(parser, "expected semicolon after for-loop initializer");
             goto onerr;
         }
-
         if (!parser_next(parser)) {
             parseerror(parser, "expected for-loop condition");
             goto onerr;
         }
     }
+    else if (!parser_next(parser)) {
+        parseerror(parser, "expected for-loop condition");
+        goto onerr;
+    }
 
     /* parse the condition */
     if (parser->tok != ';') {
@@ -5685,6 +5687,8 @@ skipvar:
             ast_delete(basetype);
             for (auto &it : parser->gotos)
                 parseerror(parser, "undefined label: `%s`", it->name);
+            parser->gotos.clear();
+            parser->labels.clear();
             return true;
         } else {
             ast_expression *cexp;
diff --git a/tests/forloop.qc b/tests/forloop.qc
new file mode 100644 (file)
index 0000000..17512bd
--- /dev/null
@@ -0,0 +1,13 @@
+void main() {
+    float j;
+    for (j = 0; j < 2; ++j)
+        print("+");
+
+    for (float i = 0; i < 5; ++i)
+        print("*");
+
+    for (;;) {
+        print("\n");
+        break;
+    }
+}
diff --git a/tests/forloop.tmpl b/tests/forloop.tmpl
new file mode 100644 (file)
index 0000000..2718dfc
--- /dev/null
@@ -0,0 +1,5 @@
+I: forloop.qc
+D: test for loops
+T: -execute
+C: -std=gmqcc
+M: ++*****