scc

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

commit 3b76352b214d6d634a54954f00bd31051e45fe9e
parent b030a1fcb12be82e5c78e76c3a9a3eb76879334c
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Mon, 17 Mar 2014 18:12:01 +0100

Add newiden function

This function will be used in declararions by directdcl and by enumdcl.

Diffstat:
Mdecl.c | 26+++++++++++++++-----------
1 file changed, 15 insertions(+), 11 deletions(-)

diff --git a/decl.c b/decl.c @@ -48,7 +48,19 @@ fundcl(struct dcldata *dp) return dp + 1; } -static struct dcldata* +static struct symbol * +newiden(uint8_t ns) +{ + struct symbol *sym; + + if ((sym = lookup(yytext, ns)) && sym->ctx == curctx) + error("redeclaration of '%s'", yytext); + sym = install(yytext, ns); + next(); + return sym; +} + +static struct dcldata * directdcl(struct dcldata *dp, uint8_t ns, int8_t flags) { register struct symbol *sym; @@ -63,11 +75,7 @@ directdcl(struct dcldata *dp, uint8_t ns, int8_t flags) goto expected; sym = install(NULL, ns); } else { - sym = lookup(yytext, ns); - if (sym && sym->ctx == curctx) - goto redeclared; - sym = install(yytext, ns); - next(); + sym = newiden(ns); } dp->op = IDEN; dp->u.sym = sym; @@ -82,12 +90,8 @@ directdcl(struct dcldata *dp, uint8_t ns, int8_t flags) } } -redeclared: - err = "redeclaration of '%s'"; - goto error; expected: - err = "expected '(' or identifier before of '%s'"; -error: error(err, yytext); + error("expected '(' or identifier before of '%s'" , yytext); } static struct dcldata*