ref: f0ee120a741971da6866221aaf4cff034b8d8522
parent: 989ac22e7b289abcd175369ff890d14c912eb540
author: Roberto E. Vargas Caballero <[email protected]>
date: Sun Nov 16 07:29:37 EST 2014
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.
--- a/cc1/cc1.h
+++ b/cc1/cc1.h
@@ -83,10 +83,11 @@
*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);
--- a/cc1/decl.c
+++ b/cc1/decl.c
@@ -47,6 +47,7 @@
size_t siz;
Type *pars[NR_FUNPARAM], **tp = &pars[0];
+ pushctx();
expect('(');
do {
@@ -66,6 +67,9 @@
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 @@
} else if (yytoken == '{') {
curfun = sym;
emitfun(sym);
- context(NULL, NULL, NULL);
+ compound(NULL, NULL, NULL);
emitefun();
+ popctx();
return;
}
} while (accept(','));
--- a/cc1/stmt.c
+++ b/cc1/stmt.c
@@ -311,12 +311,13 @@
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 @@
stmt(lbreak, lcont, lswitch);
}
}
+
+end_compound:
+ expect('}');
+ popctx();
+ return;
}
static void
@@ -338,7 +344,7 @@
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;
--- a/cc1/symbol.c
+++ b/cc1/symbol.c
@@ -50,10 +50,14 @@
}
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);