scc

Simple C99 Compiler
Log | Files | Refs | README | LICENSE

commit 4e4c6ff3b58ea36c945f4aeeb3357dca5ca6b080
parent 1725167772a8ad3a3cb5089751c38991532d2cb5
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Sun,  7 Jul 2013 20:08:35 +0200

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.

Diffstat:
decl.c | 17++++++++---------
1 file changed, 8 insertions(+), 9 deletions(-)

diff --git 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 @@ namespace(register unsigned char ns, unsigned char alloc) } 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 @@ spec(void) } 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 @@ declarator(struct ctype *tp) 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 @@ listdcl(struct ctype *base) 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 @@ decl(void) { register struct ctype *tp; -repeat: - if (!(tp = spec())) { +repeat: if (!(tp = spec())) { if (curctx != CTX_OUTER || yytoken != IDEN) return NULL; tp = newctype();