diff options
author | Michael Forney <mforney@mforney.org> | 2019-02-15 20:14:50 -0800 |
---|---|---|
committer | Michael Forney <mforney@mforney.org> | 2019-02-15 20:14:50 -0800 |
commit | 2c7f9d3a0131ca4f2060d05edfa2a67a190cd11f (patch) | |
tree | 29c16db95f0d8899a3ee3e8eb50aa8704609f300 | |
parent | e8b57d5e943171add23fc3674a34dbbb93d49046 (diff) |
Some small cleanups
-rw-r--r-- | init.c | 28 |
1 files changed, 12 insertions, 16 deletions
@@ -88,7 +88,7 @@ subobj(struct initparser *p, struct type *t, uint64_t off) off += p->sub->offset; if (++p->sub == p->obj + LEN(p->obj)) fatal("internal error: too many designators"); - p->sub->type = t; + p->sub->type = typeunqual(t, NULL); p->sub->offset = off; p->sub->iscur = false; } @@ -174,42 +174,38 @@ focus(struct initparser *p) default: t = p->sub->type; } - subobj(p, typeunqual(t, NULL), 0); + subobj(p, t, 0); } static void advance(struct initparser *p) { struct type *t; - uint64_t offset; for (;;) { --p->sub; - switch (p->sub->type->kind) { + t = p->sub->type; + switch (t->kind) { case TYPEARRAY: ++p->sub->idx; - if (p->sub->type->incomplete) - updatearray(p->sub->type, p->sub->idx); - if (p->sub->idx < p->sub->type->array.length) { - t = p->sub->type->base; - offset = t->size * p->sub->idx; - goto done; + if (t->incomplete) + updatearray(t, p->sub->idx); + if (p->sub->idx < t->array.length) { + subobj(p, t->base, t->base->size * p->sub->idx); + return; } break; case TYPESTRUCT: p->sub->mem = p->sub->mem->next; if (p->sub->mem) { - t = p->sub->mem->type; - offset = p->sub->mem->offset; - goto done; + subobj(p, p->sub->mem->type, p->sub->mem->offset); + return; } break; } if (p->sub == p->cur) error(&tok.loc, "too many initializers for type"); } -done: - subobj(p, typeunqual(t, NULL), offset); } /* 6.7.9 Initialization */ @@ -245,7 +241,7 @@ parseinit(struct scope *s, struct type *t) } expr = assignexpr(s); for (;;) { - t = typeunqual(p.sub->type, NULL); + t = p.sub->type; switch (t->kind) { case TYPEARRAY: if (expr->flags & EXPRFLAG_DECAYED && expr->unary.base->kind == EXPRSTRING) { |