MEM_VEC_FUNCTIONS(parser_t, ast_function*, functions)
static bool GMQCC_WARN parser_pop_local(parser_t *parser);
-static bool parse_variable(parser_t *parser, ast_block *localblock);
+static bool parse_variable(parser_t *parser, ast_block *localblock, bool nofields);
static ast_block* parse_block(parser_t *parser, bool warnreturn);
static bool parse_block_into(parser_t *parser, ast_block *block, bool warnreturn);
static ast_expression* parse_statement_or_block(parser_t *parser);
parseerror(parser, "TODO: assignment of new variables to be non-const");
goto onerr;
- if (!parse_variable(parser, block))
+ if (!parse_variable(parser, block, true))
goto onerr;
}
else if (parser->tok != ';')
if (parsewarning(parser, WARN_EXTENSIONS, "missing 'local' keyword when declaring a local variable"))
return false;
}
- if (!parse_variable(parser, block))
+ if (!parse_variable(parser, block, false))
return false;
*out = NULL;
return true;
parseerror(parser, "expected variable declaration");
return false;
}
- if (!parse_variable(parser, block))
+ if (!parse_variable(parser, block, true))
return false;
*out = NULL;
return true;
return var;
}
-static bool parse_variable(parser_t *parser, ast_block *localblock)
+static bool parse_variable(parser_t *parser, ast_block *localblock, bool nofields)
{
ast_value *var;
ast_value *proto;
}
}
- if (var->expression.vtype == TYPE_FIELD)
+ if (!nofields && var->expression.vtype == TYPE_FIELD)
{
/* deal with field declarations */
old = parser_find_field(parser, var->name);
if (!localblock) {
/* deal with global variables, fields, functions */
- if (var->expression.vtype == TYPE_FIELD) {
+ if (!nofields && var->expression.vtype == TYPE_FIELD) {
if (!(retval = parser_t_fields_add(parser, varent)))
goto cleanup;
if (isvector) {
if (parser->tok == ',')
goto another;
- if (!var || (!localblock && basetype->expression.vtype == TYPE_FIELD)) {
+ if (!var || (!localblock && !nofields && basetype->expression.vtype == TYPE_FIELD)) {
parseerror(parser, "missing comma or semicolon while parsing variables");
break;
}
{
if (parser->tok == TOKEN_TYPENAME || parser->tok == '.')
{
- return parse_variable(parser, NULL);
+ return parse_variable(parser, NULL, false);
}
else if (parser->tok == TOKEN_KEYWORD)
{
/* handle 'var' and 'const' */
+ if (!strcmp(parser_tokval(parser), "var")) {
+ if (!parser_next(parser)) {
+ parseerror(parser, "expected variable declaration after 'var'");
+ return false;
+ }
+ return parse_variable(parser, NULL, true);
+ }
return false;
}
else if (parser->tok == '$')