static void parser_enterblock(parser_t *parser);
static bool parser_leaveblock(parser_t *parser);
static void parser_addlocal(parser_t *parser, const char *name, ast_expression *e);
+static bool parse_typedef(parser_t *parser);
static bool parse_variable(parser_t *parser, ast_block *localblock, bool nofields, bool is_const, ast_value *cached_typedef);
static ast_block* parse_block(parser_t *parser, bool warnreturn);
static bool parse_block_into(parser_t *parser, ast_block *block, bool warnreturn);
return v;
}
-static ast_value* parser_find_typedef(parser_t *parser, const char *name)
+static ast_value* parser_find_typedef(parser_t *parser, const char *name, size_t upto)
{
size_t i, hash;
ast_value *e;
hash = util_hthash(parser->typedefs[0], name);
- for (i = vec_size(parser->typedefs); i > 0;) {
+ for (i = vec_size(parser->typedefs); i > upto;) {
--i;
if ( (e = (ast_value*)util_htgeth(parser->typedefs[i], name, hash)) )
return e;
typevar = NULL;
if (parser->tok == TOKEN_IDENT)
- typevar = parser_find_typedef(parser, parser_tokval(parser));
+ typevar = parser_find_typedef(parser, parser_tokval(parser), 0);
if (typevar || parser->tok == TOKEN_TYPENAME) {
if (opts_standard != COMPILER_GMQCC) {
{
ast_value *typevar = NULL;
if (parser->tok == TOKEN_IDENT)
- typevar = parser_find_typedef(parser, parser_tokval(parser));
+ typevar = parser_find_typedef(parser, parser_tokval(parser), 0);
if (typevar || parser->tok == TOKEN_TYPENAME || parser->tok == '.')
{
}
return true;
}
+ else if (!strcmp(parser_tokval(parser), "typedef"))
+ {
+ if (!parser_next(parser)) {
+ parseerror(parser, "expected type definition after 'typedef'");
+ return false;
+ }
+ return parse_typedef(parser);
+ }
parseerror(parser, "Unexpected keyword");
return false;
}
return NULL;
}
if (parser->tok == TOKEN_IDENT)
- cached_typedef = parser_find_typedef(parser, parser_tokval(parser));
+ cached_typedef = parser_find_typedef(parser, parser_tokval(parser), 0);
if (!cached_typedef && parser->tok != TOKEN_TYPENAME) {
parseerror(parser, "expected typename");
return NULL;
return false;
}
- if ( (oldtype = parser_find_typedef(parser, typevar->name)) ) {
+ if ( (oldtype = parser_find_typedef(parser, typevar->name, vec_last(parser->_blocktypedefs))) ) {
parseerror(parser, "type `%s` has already been declared here: %s:%i",
typevar->name, ast_ctx(oldtype).file, ast_ctx(oldtype).line);
ast_delete(typevar);
{
ast_value *istype = NULL;
if (parser->tok == TOKEN_IDENT)
- istype = parser_find_typedef(parser, parser_tokval(parser));
+ istype = parser_find_typedef(parser, parser_tokval(parser), 0);
if (istype || parser->tok == TOKEN_TYPENAME || parser->tok == '.')
{
vec_push(parser->variables, parser->htfields = util_htnew(PARSER_HT_SIZE));
vec_push(parser->variables, parser->htglobals = util_htnew(PARSER_HT_SIZE));
vec_push(parser->typedefs, util_htnew(TYPEDEF_HT_SIZE));
+ vec_push(parser->_blocktypedefs, 0);
return true;
}