aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--semantics.c20
-rw-r--r--test.c9
2 files changed, 19 insertions, 10 deletions
diff --git a/semantics.c b/semantics.c
index f491b2c..0913e65 100644
--- a/semantics.c
+++ b/semantics.c
@@ -94,21 +94,21 @@ void cscope_enter(CScope_t cs) {
}
void cscope_exit(CScope_t cs) {
- CSNode *lower = cs->top->next;
+ CSNode *top_o = cs->top;
CVar *vp;
CType *tp;
- for (vp = cs->top->vhead; vp; vp = vp->next)
+ cs->lvl--;
+ cs->top = top_o->next;
+ for (vp = top_o->vhead; vp; vp = vp->next)
ctable_clip(cs->tvar, bkdr_hash(vp->name), cs->lvl);
- for (tp = cs->top->thead; tp; tp = tp->next)
+ for (tp = top_o->thead; tp; tp = tp->next)
ctable_clip(cs->ttype, bkdr_hash(tp->name), cs->lvl);
- free(cs->top);
- cs->top = lower;
- cs->lvl--;
+ free(top_o);
}
void ctable_debug_print(CTable_t ct) {
int i;
- fprintf(stderr, "*** CTable ***\n");
+ fprintf(stderr, "\n*** CTable ***\n");
for (i = 0; i < MAX_TABLE_SIZE; i++)
if (ct->head[i])
{
@@ -118,13 +118,13 @@ void ctable_debug_print(CTable_t ct) {
fprintf(stderr, "->[%s:%d]", ct->pfunc(p), p->lvl);
fprintf(stderr, "\n");
}
- fprintf(stderr, "*** CTable ***\n");
+ fprintf(stderr, "*** CTable ***\n\n");
}
void cscope_debug_print(CScope_t cs) {
int lvl = cs->lvl;
CSNode *p;
- fprintf(stderr, "*** CScope ***\n");
+ fprintf(stderr, "****** CScope ******\n");
for (p = cs->top; p; p = p->next)
{
CVar *vp;
@@ -142,7 +142,7 @@ void cscope_debug_print(CScope_t cs) {
ctable_debug_print(cs->tvar);
fprintf(stderr, "Type Table:\n");
ctable_debug_print(cs->ttype);
- fprintf(stderr, "*** CScope ***\n");
+ fprintf(stderr, "****** CScope ******\n");
}
CVar *cscope_lookup_var(CScope_t cs, const char *name) {
diff --git a/test.c b/test.c
index 20b2968..21314b1 100644
--- a/test.c
+++ b/test.c
@@ -22,5 +22,14 @@ int main() {
PV("a");
PV("hello");
cscope_debug_print(scope);
+ cscope_enter(scope);
+ PV("a");
+ PV("yay");
+ PV("world");
+ cscope_debug_print(scope);
+ cscope_exit(scope);
+ cscope_debug_print(scope);
+ cscope_exit(scope);
+ cscope_debug_print(scope);
return 0;
}