[qfcc] Support struct/enum/handle in type_ref

Forward declarations in generic type refs might have surprising effects
(though they seem to work anyway), but at least they won't cause parse
errors.
This commit is contained in:
Bill Currie 2024-12-23 21:44:07 +09:00
parent 85e6df9374
commit 4bdc27b0cd
2 changed files with 26 additions and 1 deletions

View file

@ -666,6 +666,25 @@ decl_expr (specifier_t spec, const expr_t *init, rua_ctx_t *ctx)
return append_decl (decl, sym, init);
}
static const expr_t *
forward_decl_expr (symbol_t *tag, int sueh, const type_t *base_type)
{
symbol_t *sym;
if (sueh == 's' || sueh == 'u') {
sym = find_struct (sueh, tag, nullptr);
sym->type = find_type (sym->type);
} else if (sueh == 'e') {
sym = find_enum (tag);
} else if (sueh == 'h') {
sym = find_handle (tag, base_type);
sym->type = find_type (sym->type);
} else {
internal_error (0, "invalude decl thing");
}
return new_symbol_expr (sym);
}
static symtab_t *
pop_scope (symtab_t *current)
{
@ -1337,6 +1356,9 @@ type_ref
specifier_t spec = default_type ($1, 0);
$$ = new_type_expr (spec.type);
}
| STRUCT tag { $$ = forward_decl_expr ($2, $1, nullptr); }
| ENUM tag { $$ = forward_decl_expr ($2, 'e', nullptr); }
| handle tag { $$ = forward_decl_expr ($2, 'h', $1.type); }
| CLASS_NAME { $$ = new_type_expr ($1->type); }
| TYPE_NAME
{

View file

@ -142,6 +142,9 @@ find_handle (symbol_t *tag, const type_t *type)
t->columns = 1;
t->alignment = type->alignment;
}
if (sym->type->type != type->type) {
error (0, "@handle %s redeclared with different base type", tag->name);
}
return sym;
}