scc

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

commit f0ee120a741971da6866221aaf4cff034b8d8522
parent 989ac22e7b289abcd175369ff890d14c912eb540
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Sun, 16 Nov 2014 12:29:37 -0500

Remove context()

It is necessary to create a context with the parameters of functions,
but with the context() aproach it was not possible. This patch introduces
pushctx() and popctx() that allows a finner control.

Diffstat:
Mcc1/cc1.h | 3++-
Mcc1/decl.c | 7++++++-
Mcc1/stmt.c | 12+++++++++---
Mcc1/symbol.c | 8++++++--
4 files changed, 23 insertions(+), 7 deletions(-)

diff --git a/cc1/cc1.h b/cc1/cc1.h @@ -83,10 +83,11 @@ extern Symbol *lookup(char *s, unsigned char ns), *install(char *s, unsigned char ns); +extern void pushctx(void), popctx(void); + typedef struct caselist Caselist; extern void compound(Symbol *lbreak, Symbol *lcont, Caselist *lswitch); -extern void context(Symbol *lbreak, Symbol *lcont, Caselist *lswitch); extern Type *typename(void); diff --git a/cc1/decl.c b/cc1/decl.c @@ -47,6 +47,7 @@ fundcl(struct dcldata *dp) size_t siz; Type *pars[NR_FUNPARAM], **tp = &pars[0]; + pushctx(); expect('('); do { @@ -66,6 +67,9 @@ fundcl(struct dcldata *dp) siz = sizeof(*tp) * n; tp = (siz > 0) ? memcpy(xmalloc(siz), pars, siz) : NULL; + if (yytoken != '{') + popctx(); + return queue(dp, FTN, n, tp); } @@ -505,8 +509,9 @@ extdecl(void) } else if (yytoken == '{') { curfun = sym; emitfun(sym); - context(NULL, NULL, NULL); + compound(NULL, NULL, NULL); emitefun(); + popctx(); return; } } while (accept(',')); diff --git a/cc1/stmt.c b/cc1/stmt.c @@ -311,12 +311,13 @@ If(Symbol *lbreak, Symbol *lcont, Caselist *lswitch) void compound(Symbol *lbreak, Symbol *lcont, Caselist *lswitch) { + pushctx(); expect('{'); + for (;;) { switch (yytoken) { case '}': - next(); - return; + goto end_compound; case TYPEIDEN: if (ahead() == ':') goto statement; @@ -329,6 +330,11 @@ compound(Symbol *lbreak, Symbol *lcont, Caselist *lswitch) stmt(lbreak, lcont, lswitch); } } + +end_compound: + expect('}'); + popctx(); + return; } static void @@ -338,7 +344,7 @@ stmt(Symbol *lbreak, Symbol *lcont, Caselist *lswitch) Node *np; switch (yytoken) { - case '{': fun = context; break; + case '{': fun = compound; break; case RETURN: fun = Return; break; case WHILE: fun = While; break; case FOR: fun = For; break; diff --git a/cc1/symbol.c b/cc1/symbol.c @@ -50,10 +50,14 @@ freesyms(uint8_t ns) } void -context(Symbol *lbreak, Symbol *lcont, Caselist *lswitch) +pushctx(void) { ++curctx; - compound(lbreak, lcont, lswitch); +} + +void +popctx(void) +{ --curctx; freesyms(NS_IDEN); freesyms(NS_TAG);