cproc

Unnamed repository; edit this file 'description' to name the repository.
git clone git://git.nihaljere.xyz/cproc
Log | Files | Refs | Submodules | README | LICENSE

commit 1bc3f5f9bdf956e50cb38046f41bf5f61b49d306
parent 9d3c8863100040175c56d7ba53ca98a9ad637e57
Author: Michael Forney <mforney@mforney.org>
Date:   Wed, 13 Mar 2019 18:51:25 -0700

Drop base parameter from mktype

Diffstat:
Mdecl.c | 4++--
Mtype.c | 40++++++++++++++++++++++++----------------
Mtype.h | 2+-
3 files changed, 27 insertions(+), 19 deletions(-)

diff --git a/decl.c b/decl.c @@ -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; diff --git a/type.c b/type.c @@ -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) { diff --git a/type.h b/type.h @@ -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);