shithub: scc

Download patch

ref: 4e4c6ff3b58ea36c945f4aeeb3357dca5ca6b080
parent: 1725167772a8ad3a3cb5089751c38991532d2cb5
author: Roberto E. Vargas Caballero <[email protected]>
date: Sun Jul 7 16:08:35 EDT 2013

Pass the namespace to declarator

declarator can be used also in struct/union fields declaration, so
we need some way of saying it to insert in another namespace. This
is the reason why we pass it the desired namespace.

--- a/decl.c
+++ b/decl.c
@@ -11,7 +11,7 @@
 char parser_out_home;
 
 static struct symbol *cursym;
-static void declarator(struct ctype *tp);
+static void declarator(struct ctype *tp, unsigned char ns);
 
 static struct symbol *
 namespace(register unsigned char ns, unsigned char alloc)
@@ -38,13 +38,13 @@
 }
 
 static void
-dirdcl(register struct ctype *tp)
+dirdcl(register struct ctype *tp, unsigned char ns)
 {
 	if (accept('(')) {
-		declarator(tp);
+		declarator(tp, ns);
 		expect(')');
 	} else if (yytoken == IDEN) {
-		cursym = namespace(tp->c_typedef ? NS_TYPEDEF : NS_IDEN, 1);
+		cursym = namespace(ns, 1);
 		next();
 	} else {
 		error("expected '(' or identifier before of '%s'", yytext);
@@ -136,7 +136,7 @@
 }
 
 static void
-declarator(struct ctype *tp)
+declarator(struct ctype *tp, unsigned char ns)
 {
 	unsigned char qlf[NR_DECLARATORS];
 	register unsigned char *bp, *lim;
@@ -160,7 +160,7 @@
 	if (bp == lim)
 		error("Too much type declarators");
 
-	dirdcl(tp);
+	dirdcl(tp, ns);
 
 	for (lim = bp - 1, bp = qlf; bp < lim; ++bp)
 		pushtype(*bp);
@@ -195,7 +195,7 @@
 		struct node *sp, *np;
 		register struct ctype *tp;
 
-		declarator(base);
+		declarator(base, base->c_typedef ? NS_TYPEDEF : NS_IDEN);
 		tp = decl_type(base);
 		(cursym->ctype = tp)->refcnt++;
 		sp = nodesym(cursym);
@@ -216,8 +216,7 @@
 {
 	register struct ctype *tp;
 
-repeat:
-	if (!(tp = spec())) {
+repeat: if (!(tp = spec())) {
 		if (curctx != CTX_OUTER || yytoken != IDEN)
 			return NULL;
 		tp = newctype();