mirror of
https://github.com/DarkPlacesEngine/gmqcc.git
synced 2025-01-31 03:50:36 +00:00
Filling up remaining gotos at the end of a function for when the label is defined after the goto; erroring for missing labels
This commit is contained in:
parent
2ec8ef4406
commit
e2602e6b87
1 changed files with 11 additions and 0 deletions
11
parser.c
11
parser.c
|
@ -2382,6 +2382,7 @@ static bool parse_statement(parser_t *parser, ast_block *block, ast_expression *
|
|||
}
|
||||
else if (parser->tok == ':')
|
||||
{
|
||||
size_t i;
|
||||
ast_label *label;
|
||||
if (!parser_next(parser)) {
|
||||
parseerror(parser, "expected label name");
|
||||
|
@ -2400,6 +2401,13 @@ static bool parse_statement(parser_t *parser, ast_block *block, ast_expression *
|
|||
parseerror(parser, "parse error after label");
|
||||
return false;
|
||||
}
|
||||
for (i = 0; i < vec_size(parser->gotos); ++i) {
|
||||
if (!strcmp(parser->gotos[i]->name, label->name)) {
|
||||
ast_goto_set_label(parser->gotos[i], label);
|
||||
vec_remove(parser->gotos, i, 1);
|
||||
--i;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
else if (parser->tok == ';')
|
||||
|
@ -3913,6 +3921,7 @@ skipvar:
|
|||
}
|
||||
else if (parser->tok == '{' || parser->tok == '[')
|
||||
{
|
||||
size_t i;
|
||||
if (localblock) {
|
||||
parseerror(parser, "cannot declare functions within functions");
|
||||
break;
|
||||
|
@ -3921,6 +3930,8 @@ skipvar:
|
|||
if (!parse_function_body(parser, var))
|
||||
break;
|
||||
ast_delete(basetype);
|
||||
for (i = 0; i < vec_size(parser->gotos); ++i)
|
||||
parseerror(parser, "undefined label: `%s`", parser->gotos[i]->name);
|
||||
vec_free(parser->gotos);
|
||||
vec_free(parser->labels);
|
||||
return true;
|
||||
|
|
Loading…
Reference in a new issue