mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2025-04-03 16:01:38 +00:00
[qfcc] Support typed compound initializers
Explicitly typed compound initializers are what C uses and allows them to initialized `auto` vars and even pass through `...`. Not tested yet other than ensuring existing tests didn't break.
This commit is contained in:
parent
a7f9d96a02
commit
2115e962fe
4 changed files with 29 additions and 3 deletions
|
@ -100,6 +100,7 @@ typedef struct element_s {
|
|||
typedef struct element_chain_s {
|
||||
element_t *head;
|
||||
element_t **tail;
|
||||
const type_t *type; ///< inferred if null
|
||||
} element_chain_t;
|
||||
|
||||
typedef struct ex_listitem_s {
|
||||
|
|
|
@ -150,8 +150,9 @@ get_type (const expr_t *e)
|
|||
case ex_select:
|
||||
internal_error (e, "unexpected expression type");
|
||||
case ex_label:
|
||||
case ex_compound:
|
||||
return nullptr;
|
||||
case ex_compound:
|
||||
return e->compound.type;
|
||||
case ex_bool:
|
||||
if (options.code.progsversion == PROG_ID_VERSION)
|
||||
return &type_float;
|
||||
|
|
|
@ -365,6 +365,9 @@ assign_elements (expr_t *local_expr, const expr_t *init,
|
|||
expr_t *
|
||||
initialized_temp_expr (const type_t *type, const expr_t *expr)
|
||||
{
|
||||
if (expr->type == ex_compound && expr->compound.type) {
|
||||
type = expr->compound.type;
|
||||
}
|
||||
expr_t *block = new_block_expr (0);
|
||||
|
||||
//type = unalias_type (type);
|
||||
|
|
|
@ -211,6 +211,7 @@ int yylex (YYSTYPE *yylval, YYLTYPE *yylloc);
|
|||
%type <mut_expr> opt_init_semi opt_expr comma_expr
|
||||
%type <expr> expr
|
||||
%type <expr> compound_init
|
||||
%type <spec> opt_cast
|
||||
%type <mut_expr> element_list expr_list
|
||||
%type <designator> designator designator_spec
|
||||
%type <element> element
|
||||
|
@ -1698,8 +1699,28 @@ var_initializer
|
|||
;
|
||||
|
||||
compound_init
|
||||
: '{' element_list optional_comma '}' { $$ = $2; }
|
||||
| '{' '}' { $$ = 0; }
|
||||
: opt_cast '{' element_list optional_comma '}'
|
||||
{
|
||||
auto type = resolve_type_spec ($1);
|
||||
$3->compound.type = type;
|
||||
$$ = $3;
|
||||
}
|
||||
| opt_cast '{' '}'
|
||||
{
|
||||
auto type = resolve_type_spec ($1);
|
||||
if (type) {
|
||||
auto elements = new_compound_init ();
|
||||
elements->compound.type = type;
|
||||
$$ = elements;
|
||||
} else {
|
||||
$$ = nullptr;
|
||||
}
|
||||
}
|
||||
;
|
||||
|
||||
opt_cast
|
||||
: '(' typename ')' { $$ = $2; }
|
||||
| /*empty*/ { $$ = (specifier_t) {}; }
|
||||
;
|
||||
|
||||
method_optional_state_expr
|
||||
|
|
Loading…
Reference in a new issue