ref: 23f4bc49055d8a9a28648b1c6e52f24eb4425ddf
parent: 80126fceaea7d2fc98094d1e280757f686bead22
author: Ori Bernstein <[email protected]>
date: Sun Jul 22 00:58:39 EDT 2012
Merge usefile namespaces If we load multiple usefiles that contribute to the same namespace, we should merge the namespaces instead of erroring.
--- a/parse/use.c
+++ b/parse/use.c
@@ -11,6 +11,22 @@
#include "parse.h"
+static Stab *findstab(Stab *st, char *pkg)
+{
+ Node *n;
+ Stab *s;
+
+ n = mkname(-1, pkg);
+ if (getns(st, n)) {
+ s = getns(st, n);
+ } else {
+ s = mkstab();
+ s->name = n;
+ putns(st, s);
+ }
+ return s;
+}
+
static int loaduse(FILE *f, Stab *st)
{
char *pkg;
@@ -30,15 +46,11 @@
if (pkg && !strcmp(pkg, namestr(st->name))) {
s = st;
} else {
- s = mkstab();
- s->name = mkname(-1, pkg);
- putns(st, s);
+ s = findstab(st, pkg);
}
} else {
if (pkg) {
- s = mkstab();
- s->name = mkname(-1, pkg);
- putns(st, s);
+ s = findstab(st, pkg);
} else {
s = st;
}
@@ -46,8 +58,6 @@
while ((c = fgetc(f)) != 'Z') {
switch(c) {
case 'G':
- die("We didn't implement generics yet!");
- break;
case 'D':
dcl = symunpickle(f);
putdcl(s, dcl);