}
} else {
token_t t;
+ size_t size, align;
if (darg->var->pointer_level && (!darg->var->array_size || darg->var->pointer_level == 1)) {
t = PSI_T_POINTER;
t = real_decl_type(darg->type)->type;
}
+ size = psi_t_size(t) * (darg->var->array_size ?: 1);
+
if (i) {
decl_arg *last = s->args->args[i-1];
- darg->layout = init_decl_struct_layout(
- psi_t_align(t, last->layout->pos + last->layout->len),
- psi_t_size(t) * darg->var->array_size);
+
+ align = psi_t_align(t, last->layout->pos + last->layout->len);
} else {
- darg->layout = init_decl_struct_layout(0, psi_t_size(t));
+ align = 0;
}
+
+ darg->layout = init_decl_struct_layout(align, size);
}
if (s->size < darg->layout->pos + darg->layout->len) {
s->size = darg->layout->pos + darg->layout->len;
+ /* FIXME: align struct */
}
}
n = N;
}
+%type decl_struct_args_block {decl_args*}
+%destructor decl_struct_args_block {free_decl_args($$);}
+decl_struct_args_block(args_) ::= LBRACE struct_args(args) RBRACE. {
+ args_ = args;
+}
%type decl_struct_args {decl_args*}
%destructor decl_struct_args {free_decl_args($$);}
-decl_struct_args(args_) ::= LBRACE struct_args(args) RBRACE. {
+decl_struct_args(args_) ::= decl_struct_args_block(args). {
args_ = args;
}
decl_struct_args(args_) ::= EOS. {
}
%type decl_typedef_body {decl_typedef*}
%destructor decl_typedef_body {free_decl_typedef($$);}
+decl_typedef_body(def) ::= struct_name(N) struct_size(size_) decl_struct_args_block(args) NAME(ALIAS). {
+ def = init_decl_typedef(ALIAS->text, init_decl_type(PSI_T_STRUCT, N->text));
+ def->token = ALIAS;
+ def->type->strct = init_decl_struct(N->text, args);
+ def->type->strct->token = N;
+ def->type->strct->size = size_;
+}
decl_typedef_body(def) ::= decl_type(type) NAME(ALIAS). {
def = init_decl_typedef(ALIAS->text, type);
def->token = ALIAS;
}
-
/* support opaque types */
decl_typedef_body(def) ::= VOID(V) indirection(i) NAME(ALIAS). {
def = init_decl_typedef(ALIAS->text, init_decl_type(i?PSI_T_POINTER:V->type, V->text));