mirror of
https://github.com/DarkPlacesEngine/gmqcc.git
synced 2025-01-18 14:21:36 +00:00
fix for loops
This commit is contained in:
parent
5968e3faa0
commit
5c64437189
3 changed files with 24 additions and 2 deletions
|
@ -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;
|
||||
|
|
13
tests/forloop.qc
Normal file
13
tests/forloop.qc
Normal file
|
@ -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;
|
||||
}
|
||||
}
|
5
tests/forloop.tmpl
Normal file
5
tests/forloop.tmpl
Normal file
|
@ -0,0 +1,5 @@
|
|||
I: forloop.qc
|
||||
D: test for loops
|
||||
T: -execute
|
||||
C: -std=gmqcc
|
||||
M: ++*****
|
Loading…
Reference in a new issue