+ free_fieldlist(t->structure.field_list);
+ }
+
+ static void structure_prepare_type(struct parse_context *c,
+ struct type *t, int parse_time)
+ {
+ int cnt = 0;
+ struct fieldlist *f;
+
+ if (!parse_time || t->structure.fields)
+ return;
+
+ for (f = t->structure.field_list; f; f=f->prev) {
+ int ok;
+ cnt += 1;
+
+ if (f->f.type->prepare_type)
+ f->f.type->prepare_type(c, f->f.type, 1);
+ if (f->init == NULL)
+ continue;
+ do {
+ ok = 1;
+ propagate_types(f->init, c, &ok, f->f.type, 0);
+ } while (ok == 2);
+ if (!ok)
+ c->parse_error = 1; // NOTEST
+ }
+
+ t->structure.nfields = cnt;
+ t->structure.fields = calloc(cnt, sizeof(struct field));
+ f = t->structure.field_list;
+ while (cnt > 0) {
+ int a = f->f.type->align;
+ cnt -= 1;
+ t->structure.fields[cnt] = f->f;
+ if (t->size & (a-1))
+ t->size = (t->size | (a-1)) + 1;
+ t->structure.fields[cnt].offset = t->size;
+ t->size += ((f->f.type->size - 1) | (a-1)) + 1;
+ if (a > t->align)
+ t->align = a;
+
+ if (f->init && !c->parse_error) {
+ struct value vl = interp_exec(c, f->init, NULL);
+ t->structure.fields[cnt].init =
+ global_alloc(c, f->f.type, NULL, &vl);
+ }
+
+ f = f->prev;
+ }