mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2025-02-25 05:01:24 +00:00
[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:
parent
85e6df9374
commit
4bdc27b0cd
2 changed files with 26 additions and 1 deletions
|
@ -666,6 +666,25 @@ decl_expr (specifier_t spec, const expr_t *init, rua_ctx_t *ctx)
|
||||||
return append_decl (decl, sym, init);
|
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 *
|
static symtab_t *
|
||||||
pop_scope (symtab_t *current)
|
pop_scope (symtab_t *current)
|
||||||
{
|
{
|
||||||
|
@ -1337,7 +1356,10 @@ type_ref
|
||||||
specifier_t spec = default_type ($1, 0);
|
specifier_t spec = default_type ($1, 0);
|
||||||
$$ = new_type_expr (spec.type);
|
$$ = new_type_expr (spec.type);
|
||||||
}
|
}
|
||||||
| CLASS_NAME { $$ = new_type_expr ($1->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
|
| TYPE_NAME
|
||||||
{
|
{
|
||||||
if ($1.type_expr) {
|
if ($1.type_expr) {
|
||||||
|
|
|
@ -142,6 +142,9 @@ find_handle (symbol_t *tag, const type_t *type)
|
||||||
t->columns = 1;
|
t->columns = 1;
|
||||||
t->alignment = type->alignment;
|
t->alignment = type->alignment;
|
||||||
}
|
}
|
||||||
|
if (sym->type->type != type->type) {
|
||||||
|
error (0, "@handle %s redeclared with different base type", tag->name);
|
||||||
|
}
|
||||||
return sym;
|
return sym;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue