summaryrefslogtreecommitdiff
path: root/parse/use.c
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2017-04-21 23:35:46 -0700
committerOri Bernstein <ori@eigenstate.org>2017-04-21 23:35:46 -0700
commit69823fb059b309c0d78b819ea331489c206b83b3 (patch)
tree56e5106ef2a540fa8addf03d874daa3c40ee9bad /parse/use.c
parent518175c179216ecf8a6bf9129f330cfc8997cf15 (diff)
downloadmc-69823fb059b309c0d78b819ea331489c206b83b3.tar.gz
Dedup conflicting use statements.
Diffstat (limited to 'parse/use.c')
-rw-r--r--parse/use.c17
1 files changed, 13 insertions, 4 deletions
diff --git a/parse/use.c b/parse/use.c
index 94a1e7e..ae3a68b 100644
--- a/parse/use.c
+++ b/parse/use.c
@@ -24,6 +24,7 @@ static Node *unpickle(FILE *fd);
/* type fixup list */
static Htab *tydeduptab; /* map from name -> type, contains all Tynames loaded ever */
+static Htab *trdeduptab; /* map from name -> type, contains all Tynames loaded ever */
static Htab *tidmap; /* map from tid -> type */
static Htab *trmap; /* map from trait id -> trait */
static Htab *initmap; /* map from init name -> int */
@@ -796,7 +797,7 @@ static void fixtypemappings(Stab *st)
static void fixtraitmappings(Stab *st)
{
size_t i;
- Trait *t;
+ Trait *t, *tr;
/*
* merge duplicate definitions.
@@ -808,10 +809,16 @@ static void fixtraitmappings(Stab *st)
t = htget(trmap, itop(traitfixid[i]));
if (!t)
die("Unable to find trait for id %zd\n", traitfixid[i]);
+
+ tr = htget(trdeduptab, t->name);
+ if (!tr) {
+ htput(trdeduptab, t->name, t);
+ tr = t;
+ }
if (traitfixdest[i])
- *traitfixdest[i] = t;
+ *traitfixdest[i] = tr;
if (traitfixtype[i])
- settrait(traitfixtype[i], t);
+ settrait(traitfixtype[i], tr);
}
lfree(&traitfixdest, &ntraitfixdest);
@@ -888,6 +895,8 @@ int loaduse(char *path, FILE *f, Stab *st, Vis vis)
pushstab(file->file.globls);
if (!tydeduptab)
tydeduptab = mkht(tyhash, tyeq);
+ if (!trdeduptab)
+ trdeduptab = mkht(namehash, nameeq);
if (fgetc(f) != 'U')
return 0;
v = rdint(f);
@@ -962,8 +971,8 @@ foundextlib:
break;
case 'R':
tr = traitunpickle(f);
- tr->vis = vis;
if (!tr->ishidden) {
+ tr->vis = vis;
puttrait(s, tr->name, tr);
for (i = 0; i < tr->nfuncs; i++) {
putdcl(s, tr->funcs[i]);