shithub: scc

Download patch

ref: 6363b621d371ca732a5a63212199bd059cd507d0
parent: 17de97a568d0c405dba08f9a5356fefcf687b3ac
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Mon Sep 23 17:02:03 EDT 2013

Allow registration of defined symbols in namespace

namespace registers the symbol detected in the lexical analysis
in a namespace. At the moment, it raised an error when we try
register again a name in the same namespace, but this is not
the behaviour we want in the case of forward declarations, so
we need a way of indicating this case. After this change
alloc > 0 means allocate a new symbol if no defined, alloc == 0
means no allocate a new symbol if no defined and raises an error
and alloc < 0 means no raises an error when the symbol is already
defined.

--- a/decl.c
+++ b/decl.c
@@ -14,7 +14,7 @@
 static void declarator(struct ctype *tp, unsigned char ns);
 
 static struct symbol *
-namespace(register unsigned char ns, unsigned char alloc)
+namespace(register unsigned char ns, signed char alloc)
 {
 	register struct symbol *sym = yyval.sym;
 	unsigned char yyns = sym->ns;
@@ -31,6 +31,8 @@
 			sym->ns = ns;
 			return sym;
 		} else if (yyns == ns && sym->ctx == curctx) {
+			if (alloc < 0)
+				return sym;
 			error("redeclaration of '%s'", yytext);
 		}
 		return lookup(yytext, ns);
--