scc

simple C compiler
git clone git://git.2f30.org/scc
Log | Files | Refs | README | LICENSE

commit c5e705ef14f8038a051f258fe741919f4988ef7d
parent 808ce90786c3b900eeaa6a5048c26838e7d0e456
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Wed, 14 May 2014 14:53:57 +0200

Fix struct declaration

struct declaration was broken, and we were clearing the fields, so was
not usseful at all.

Diffstat:
Mcc1/decl.c | 15++++++---------
Mcc1/types.c | 3+--
2 files changed, 7 insertions(+), 11 deletions(-)

diff --git a/cc1/decl.c b/cc1/decl.c @@ -335,21 +335,19 @@ static Type * newtag(uint8_t tag) { register Symbol *sym; - Type *tp; + register Type *tp; if (yytoken == IDEN) { - sym = lookup(yytext, NS_TAG); - if (sym) { - if (sym->type->op != tag) - goto bad_tag; - } else { + if ((sym = lookup(yytext, NS_TAG)) == NULL) sym = install(yytext, NS_TAG); - } next(); } else { sym = install("", NS_TAG); } - tp = sym->type = mktype(NULL, tag, 0); + if (!(tp = sym->type)) + tp = sym->type = mktype(NULL, tag, 0); + if (tp->op != tag) + goto bad_tag; return tp; bad_tag: @@ -365,7 +363,6 @@ structdcl(void) tag = yylval.token; next(); tp = newtag(tag); - tp->u.fields = NULL; if (accept('{')) { if (tp->defined) goto redefined; diff --git a/cc1/types.c b/cc1/types.c @@ -170,11 +170,10 @@ mktype(Type *tp, uint8_t op, uint16_t nelem) case STRUCT: letter = L_STRUCT; break; default: letter = tp->letter; } - bp = xmalloc(sizeof(*bp)); + bp = xcalloc(1, sizeof(*bp)); bp->next = *tbl; bp->type = tp; bp->op = op; - bp->u.nelem = nelem; bp->letter = letter; return *tbl = bp; }