diff options
author | Michael Forney <mforney@mforney.org> | 2019-03-13 18:51:25 -0700 |
---|---|---|
committer | Michael Forney <mforney@mforney.org> | 2019-03-13 18:51:25 -0700 |
commit | 1bc3f5f9bdf956e50cb38046f41bf5f61b49d306 (patch) | |
tree | 82b2996e72756bb9e8526e97c5111720a467871d | |
parent | 9d3c8863100040175c56d7ba53ca98a9ad637e57 (diff) |
Drop base parameter from mktype
-rw-r--r-- | decl.c | 4 | ||||
-rw-r--r-- | type.c | 40 | ||||
-rw-r--r-- | type.h | 2 |
3 files changed, 27 insertions, 19 deletions
@@ -176,7 +176,7 @@ tagspec(struct scope *s) if (t->kind != kind) error(&tok.loc, "redeclaration of tag '%s' with different kind", tag); } else { - t = mktype(kind, NULL); + t = mktype(kind); if (kind == TYPEBASIC) { *t = typeint; t->basic.kind = BASICENUM; @@ -463,7 +463,7 @@ declaratortypes(struct scope *s, struct list *result, char **name, bool allowabs case TLPAREN: /* function declarator */ next(); func: - t = mktype(TYPEFUNC, NULL); + t = mktype(TYPEFUNC); t->func.isprototype = false; t->func.isvararg = false; t->func.isnoreturn = false; @@ -35,38 +35,43 @@ struct type typevalist = {.kind = TYPEARRAY, .size = 24, .align = 8, .array = {1 struct type typevalistptr = {.kind = TYPEPOINTER, .size = 8, .align = 8, .repr = &i64, .base = &typevaliststruct}; struct type * -mktype(enum typekind kind, struct type *base) +mktype(enum typekind kind) { struct type *t; t = xmalloc(sizeof(*t)); t->kind = kind; - t->base = base; t->incomplete = 0; return t; } struct type * -mkqualifiedtype(struct type *t, enum typequalifier tq) +mkqualifiedtype(struct type *base, enum typequalifier tq) { - if (tq) { - t = mktype(TYPEQUALIFIED, t); - t->qualified.kind = tq; - if (t->base) { - t->size = t->base->size; - t->align = t->base->align; - t->repr = t->base->repr; - } - // XXX: incomplete? + struct type *t; + + if (!tq) + return base; + t = mktype(TYPEQUALIFIED); + t->base = base; + t->qualified.kind = tq; + if (base) { + t->size = base->size; + t->align = base->align; + t->repr = base->repr; } + // XXX: incomplete? return t; } struct type * -mkpointertype(struct type *t) +mkpointertype(struct type *base) { - t = mktype(TYPEPOINTER, t); + struct type *t; + + t = mktype(TYPEPOINTER); + t->base = base; t->size = 8; t->align = 8; t->repr = &i64; @@ -75,9 +80,12 @@ mkpointertype(struct type *t) } struct type * -mkarraytype(struct type *t, uint64_t len) +mkarraytype(struct type *base, uint64_t len) { - t = mktype(TYPEARRAY, t); + struct type *t; + + t = mktype(TYPEARRAY); + t->base = base; t->array.length = len; t->incomplete = !len; if (t->base) { @@ -91,7 +91,7 @@ struct type { }; }; -struct type *mktype(enum typekind, struct type *base); +struct type *mktype(enum typekind); struct type *mkqualifiedtype(struct type *, enum typequalifier); struct type *mkpointertype(struct type *); struct type *mkarraytype(struct type *, uint64_t); |