scc

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

commit 3763a1341f92c675ec2c2fdadf32902eca2466ce
parent 5a274755b0b8da4357c3ed3193033dcba6f6796d
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Thu,  4 Jul 2013 16:09:03 +0200

Link the symbol with the type

We were not linking the type with the defined symbol. It was
a important error.

Diffstat:
Mdecl.c | 1+
Msymbol.h | 9+++++----
Mtypes.c | 7+++++++
3 files changed, 13 insertions(+), 4 deletions(-)

diff --git a/decl.c b/decl.c @@ -171,6 +171,7 @@ listdcl(struct ctype *tp) "type defaults to 'int' in declaration of '%s'", yytext); } + linkctype(tp, cursym); sp = nodesym(cursym); if (tp->type == FTN && yytoken == '{') { np = node2(ODEF, sp, function(cursym)); diff --git a/symbol.h b/symbol.h @@ -37,7 +37,7 @@ struct ctype { }; struct symbol { - struct ctype ctype; + struct ctype *ctype; unsigned char ctx; unsigned char ns; char *name; @@ -61,12 +61,13 @@ extern unsigned char btype(unsigned char, unsigned char tok); extern void new_ctx(void); extern void del_ctx(void); extern void freesyms(void); -extern struct symbol *lookup(register const char *s, char ns); -extern struct symbol *find(register const char *s, char ns); +extern struct symbol *lookup(const char *s, char ns); +extern struct symbol *find(const char *s, char ns); extern void insert(struct symbol *sym, unsigned char ctx); extern void storage(struct ctype *cp, unsigned char mod); extern struct ctype *newctype(void); -extern void delctype(register struct ctype *tp); +extern void delctype(struct ctype *tp); +extern void linkctype(struct ctype *tp, struct symbol *sym); #ifndef NDEBUG extern void ptype(register struct ctype *t); diff --git a/types.c b/types.c @@ -22,6 +22,13 @@ newctype(void) } void +linkctype(register struct ctype *tp, register struct symbol *sym) +{ + sym->ctype = tp; + ++tp->refcnt; +} + +void delctype(register struct ctype *tp) { if (--tp->refcnt == 0) {