ref: 3b76352b214d6d634a54954f00bd31051e45fe9e
parent: b030a1fcb12be82e5c78e76c3a9a3eb76879334c
author: Roberto E. Vargas Caballero <[email protected]>
date: Mon Mar 17 14:12:01 EDT 2014
Add newiden function This function will be used in declararions by directdcl and by enumdcl.
--- a/decl.c
+++ b/decl.c
@@ -48,7 +48,19 @@
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 @@
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 @@
}
}
-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*