[qfcc] Support { } as nil in nested initializers

Did top-level earlier, but forgot to add support for deeper nestings.
This commit is contained in:
Bill Currie 2020-03-06 20:32:37 +09:00
parent 1250fe7446
commit 07e6baf32f
2 changed files with 21 additions and 5 deletions

View file

@ -450,7 +450,10 @@ init_elements (struct def_s *def, expr_t *eles)
if (element->expr) {
c = constant_expr (element->expr);
} else {
c = convert_nil (new_nil_expr (), type);
c = new_nil_expr ();
}
if (c->type == ex_nil) {
c = convert_nil (c, type);
}
append_expr (local_expr, assign_expr (unary_expr ('.', ptr), c));
}

View file

@ -1148,7 +1148,8 @@ opt_initializer
var_initializer
: '=' expr { $$ = $2; }
| '=' '{' element_list optional_comma '}' { $$ = $3; }
| '=' '{' { $<spec>$ = $<spec>-1; }
element_list optional_comma '}' { $$ = $4; }
| '=' '{' '}'
{
if (is_scalar ($<spec>-1.type)) {
@ -1169,14 +1170,26 @@ element_list
$$ = new_block_expr ();
append_expr ($$, $1);
}
| element_list ',' element
| element_list ',' {$<spec>$ = $<spec>0; } element
{
append_expr ($$, $3);
append_expr ($$, $4);
}
;
element
: '{' element_list optional_comma '}' { $$ = $2; }
: '{' { $<spec>$ = $<spec>0; }
element_list optional_comma '}' { $$ = $3; }
| '{' '}'
{
// FIXME doesn't check the right type (does prove the inherited
// attributes have been passed down correctly though). The problem
// is that the type of the sub elements needs to be extracted if
// possible
if (is_scalar ($<spec>0.type)) {
error (0, "empty scalar initializer");
}
$$ = new_nil_expr ();
}
| expr { $$ = $1; }
;