diff options
author | Teddy <[email protected]> | 2014-03-26 19:33:34 +0800 |
---|---|---|
committer | Teddy <[email protected]> | 2014-03-26 19:33:34 +0800 |
commit | eb001bab8f7a342afde93bd8c2c300a9e837db79 (patch) | |
tree | dcb89b53a2805bec0cf63c171976e9ecc3a6cad2 | |
parent | 5f2965bcaca608f0d9af84373565539ae384918d (diff) |
...
-rw-r--r-- | semantics.c | 20 | ||||
-rw-r--r-- | test.c | 9 |
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) { @@ -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; } |