scc

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

commit b2fc11b3d2e07e84e2868f5aab8319612257855c
parent ec0bbf93d441cac0db795007d80b1dcdc32e91d0
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Mon, 17 Mar 2014 07:42:06 +0100

Fix order of evaluation in declarators

Declarations must be evaluated in reverse order of the expressions
in the same form, so we need a queue instead of a stack, so the
recursive function was not correct.

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

diff --git a/decl.c b/decl.c @@ -90,24 +90,41 @@ expected: error: error(err, yytext); } +/* TODO: Add a token2 field in yylval to avoid yylval.sym->u.c */ + static struct dcldata* declarator0(struct dcldata *dp, uint8_t ns, int8_t flags) { - if (accept('*')) { - register uint8_t qlf = 0; - while (yytoken == TQUALIFIER) { + uint8_t buffer[NR_DECLARATORS]; + register uint8_t *bp, n, qlf; + + bp = buffer; + for (n = 0; accept('*'); ++n) { + if (n == NR_DECLARATORS) + goto too_much_declarators; + qlf = 0; + if (yytoken == TQUALIFIER) { qlf |= yylval.sym->u.c; next(); } - dp = declarator0(dp, ns, flags); + *bp++ = qlf; + } + + dp = directdcl(dp, ns, flags); + + bp = buffer; + while (n--) { if (dp->op == 255) - error("too much declarators"); + goto too_much_declarators; dp->op = PTR; - dp->u.qlf = qlf; - return dp + 1; - } else { - return directdcl(dp, ns, TQUALIFIER); + dp->u.qlf = *bp++; + ++dp; } + + return dp; + +too_much_declarators: + error("too much declarators"); } static struct symbol *