shithub: scc

Download patch

ref: 3763a1341f92c675ec2c2fdadf32902eca2466ce
parent: 5a274755b0b8da4357c3ed3193033dcba6f6796d
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Thu Jul 4 12:09:03 EDT 2013

Link the symbol with the type

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

--- a/decl.c
+++ b/decl.c
@@ -171,6 +171,7 @@
 				      "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));
--- a/symbol.h
+++ b/symbol.h
@@ -37,7 +37,7 @@
 };
 
 struct symbol {
-	struct ctype ctype;
+	struct ctype *ctype;
 	unsigned char ctx;
 	unsigned char ns;
 	char *name;
@@ -61,12 +61,13 @@
 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);
--- a/types.c
+++ b/types.c
@@ -22,6 +22,13 @@
 }
 
 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) {
--