ref: 1a9d4b863e4d94c483339e5ef4874119edd51f46
parent: 3825a62a980ee98a8b9a1f451081fedccd082cc4
author: Ori Bernstein <[email protected]>
date: Mon Jan 9 16:45:40 EST 2012
Set up scope chains properly.
--- a/parse/infer.c
+++ b/parse/infer.c
@@ -14,6 +14,16 @@
static void infernode(Node *n, Type *ret);
+static void setsuper(Stab *st, Stab *super)
+{
+ Stab *s;
+
+ /* verify that we don't accidentally create loops */
+ for (s = super; s; s = s->super)
+ assert(s->super != st);
+ st->super = super;
+}
+
/* find the most accurate type mapping */
static Type *tf(Type *t)
{
@@ -339,6 +349,7 @@
inferdecl(n);
break;
case Nblock:
+ setsuper(n->block.scope, curstab());
pushstab(n->block.scope);
for (i = 0; i < n->block.nstmts; i++)
infernode(n->block.stmts[i], ret);
@@ -359,6 +370,7 @@
inferexpr(n, ret);
break;
case Nfunc:
+ setsuper(n->func.scope, curstab());
pushstab(n->func.scope);
inferfunc(n);
popstab();
--- a/parse/stab.c
+++ b/parse/stab.c
@@ -83,7 +83,8 @@
do {
if ((s = htget(st->dcl, n)))
return s;
- } while (st->super);
+ st = st->super;
+ } while (st);
return NULL;
}
@@ -94,7 +95,8 @@
do {
if ((t = htget(st->ty, n)))
return t->type;
- } while (st->super);
+ st = st->super;
+ } while (st);
return NULL;
}
@@ -104,7 +106,8 @@
do {
if ((s = htget(st->ns, n)))
return s;
- } while (st->super);
+ st = st->super;
+ } while (st);
return NULL;
}