shithub: mc

Download patch

ref: 7901a7550dfe881ef5f7ead2a84a05316351b573
parent: d0234eb0cd492eac9501ba1e359757ce90ccb234
author: Ori Bernstein <[email protected]>
date: Wed Mar 28 10:48:43 EDT 2012

Track the closure of vars.

--- a/parse/stab.c
+++ b/parse/stab.c
@@ -72,7 +72,6 @@
     st->ns = mkht(namehash, nameeq);
     st->dcl = mkht(namehash, nameeq);
     st->ty = mkht(namehash, nameeq);
-    st->closure = mkht(namehash, nameeq);
     return st;
 }
 
@@ -80,9 +79,18 @@
 Sym *getdcl(Stab *st, Node *n)
 {
     Sym *s;
+    Stab *orig;
+
+    orig = st;
     do {
-        if ((s = htget(st->dcl, n)))
+        if ((s = htget(st->dcl, n))) {
+            /* record that this is in the closure of this scope */
+            if (!st->closure)
+                st->closure = mkht(namehash, nameeq);
+            if (st != orig)
+                htput(st->closure, s->name, s);
             return s;
+        }
         st = st->super;
     } while (st);
     return NULL;
@@ -145,4 +153,3 @@
         fatal(scope->name->line, "Ns %s already defined", name(s->name));
     htput(st->ns, scope->name, scope);
 }
-