scc

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

commit b1bd61b5a79e46e298759723f528a4e025a5c6f5
parent e8eef01cc0830c227e5e55788f90e2dc52c64116
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Wed, 23 Apr 2014 16:28:06 +0200

Add break, continue and switch parameters to context

Context is going to be called every time a new variable
context is created, so it is a good idea to add where
the break, continue jumps are going to go, and
also was it the last switch

Diffstat:
cc1.h | 8++++++--
decl.c | 2+-
stmt.c | 2+-
symbol.c | 4++--
4 files changed, 10 insertions(+), 6 deletions(-)

diff --git a/cc1.h b/cc1.h @@ -124,7 +124,11 @@ extern Symbol *lookup(char *s, unsigned char ns), *install(char *s, unsigned char ns); -extern void context(void (*fun)(void)); +typedef void Ctxfun(Symbol *, Symbol *, Symbol *); + +extern Ctxfun compound; +extern void context(Ctxfun *fun, + Symbol *lbreak, Symbol *lcont, Symbol *lswitch); extern Type *typename(void); @@ -243,6 +247,6 @@ extern Node #define ISNODECMP(n) (ISNODEBIN(n) && (n)->u.op & 0x40) extern Node *expr(void); -extern void extdecl(void), decl(void), compound(void); +extern void extdecl(void), decl(void); #endif diff --git a/decl.c b/decl.c @@ -504,7 +504,7 @@ extdecl(void) curfun = sym; emitfun(sym); emitsframe(sym); - context(compound); + context(compound, NULL, NULL, NULL); emiteframe(sym); /* FIX: sym is not used */ freesyms(NS_LABEL); return; diff --git a/stmt.c b/stmt.c @@ -27,7 +27,7 @@ Return(void) } void -compound(void) +compound(Symbol *lbreak, Symbol *lcont, Symbol *lswitch) { expect('{'); while (!accept('}')) { diff --git a/symbol.c b/symbol.c @@ -44,13 +44,13 @@ freesyms(uint8_t ns) } void -context(void (*fun)(void)) +context(Ctxfun *fun, Symbol *lbreak, Symbol *lcont, Symbol *lswitch) { uint8_t ns; ns = namespace; ++curctx; - fun(); + (*fun)(lbreak, lcont, lswitch); --curctx; namespace = ns;