ref: b8b1b240c2300954903272a543d9146b59d4f997
parent: 5cacde485bf6338bbf216b7a5249bb51c84e15fc
author: Ori Bernstein <[email protected]>
date: Wed Jan 16 21:47:13 EST 2013
Keep our symbol tables straight when specializing. We were generating namespace-free specialized names. This meant that we were pushing the namespace for specializing, but we never popped it. This is bad for two reasons. First, it means that our generics aren't namespaced, which can lead to name conflicts. Second, it means that we can end up with a bogus symtab at the top of the stack after calling specialize. This commit fixes things.
--- a/parse/specialize.c
+++ b/parse/specialize.c
@@ -136,7 +136,7 @@
if (n->expr.op == Ovar) {
d = getdcl(curstab(), n->expr.args[0]);
if (!d)
- die("Missing decl %s\n", namestr(n->expr.args[0]));
+ die("Missing decl %s", namestr(n->expr.args[0]));
if (d->decl.isgeneric)
d = specializedcl(d, n->expr.type, &n->expr.args[0]);
n->expr.did = d->decl.did;
@@ -169,6 +169,7 @@
fixup(n->matchstmt.val);
for (i = 0; i < n->matchstmt.nmatches; i++)
fixup(n->matchstmt.matches[i]);
+ break;
case Nmatch:
fixup(n->match.pat);
fixup(n->match.block);
@@ -316,7 +317,7 @@
p = buf;
end = buf + sz;
- p += snprintf(p, end - p, "$%d", t->tid);
+ p += snprintf(p, end - p, "$%d", (int)t->type);
for (i = 0; i < t->nsub; i++)
p += tidappend(p, end - p, t->sub[i]);
return p - buf;
@@ -327,6 +328,7 @@
char buf[1024];
char *p;
char *end;
+ Node *name;
if (!n->decl.isgeneric)
return n->decl.name;
@@ -335,7 +337,10 @@
p += snprintf(p, end - p, "%s", n->decl.name->name.name);
p += snprintf(p, end - p, "$%zd", n->decl.did);
tidappend(p, end - p, t);
- return mkname(n->line, buf);
+ name = mkname(n->line, buf);
+ if (n->decl.name->name.ns)
+ setns(name, n->decl.name->name.ns);
+ return name;
}
/*