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 27e3cf0dedb657fe92c1c6928beb3d7882292262
parent d96c4e1ea2b24c14eb844f94cfb87af51b372c4f
Author: Michael Forney <mforney@mforney.org>
Date:   Thu, 30 Jan 2020 13:20:54 -0800

decl: Use list link to determine presence in tentative definition list

Diffstat:
Mcc.h | 10+++++-----
Mdecl.c | 18++++++------------
Mutil.c | 1+
3 files changed, 12 insertions(+), 17 deletions(-)

diff --git a/cc.h b/cc.h @@ -255,13 +255,13 @@ struct decl { struct type *type; enum typequal qual; struct value *value; + _Bool defined; - /* objects and functions */ - struct list link; - int align; /* may be more strict than type requires */ - _Bool tentative, defined; + /* link in list of tentative object definitions */ + struct list tentative; + /* alignment of object storage (may be stricter than type requires) */ + int align; - /* built-ins */ enum builtinkind builtin; }; diff --git a/decl.c b/decl.c @@ -65,14 +65,11 @@ mkdecl(enum declkind k, struct type *t, enum typequal tq, enum linkage linkage) struct decl *d; d = xmalloc(sizeof(*d)); + memset(d, 0, sizeof(*d)); d->kind = k; d->linkage = linkage; d->type = t; d->qual = tq; - d->tentative = false; - d->defined = false; - d->align = 0; - d->value = NULL; return d; } @@ -971,13 +968,10 @@ decl(struct scope *s, struct func *f) else funcinit(f, d, init); d->defined = true; - if (d->tentative) { - d->tentative = false; - listremove(&d->link); - } - } else if (!(sc & SCEXTERN) && !d->defined && !d->tentative) { - d->tentative = true; - listinsert(tentativedefns.prev, &d->link); + if (d->tentative.next) + listremove(&d->tentative); + } else if (!(sc & SCEXTERN) && !d->defined && !d->tentative.next) { + listinsert(tentativedefns.prev, &d->tentative); } break; case DECLFUNC: @@ -1053,5 +1047,5 @@ emittentativedefns(void) struct list *l; for (l = tentativedefns.next; l != &tentativedefns; l = l->next) - emitdata(listelement(l, struct decl, link), NULL); + emitdata(listelement(l, struct decl, tentative), NULL); } diff --git a/util.c b/util.c @@ -130,4 +130,5 @@ listremove(struct list *list) { list->next->prev = list->prev; list->prev->next = list->next; + list->next = list->prev = NULL; }