summaryrefslogtreecommitdiff
path: root/parse
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2015-02-25 13:19:25 -0500
committerOri Bernstein <ori@eigenstate.org>2015-03-10 22:21:31 -0700
commitc483ee1a87247d164b0daeb5d3a7ca797316c8dc (patch)
tree205e90d0b3ea2e5876dc71cf0d2c38efb4ca035e /parse
parent7b05b361a006818de16f7239a6f64ac8da521021 (diff)
downloadmc-c483ee1a87247d164b0daeb5d3a7ca797316c8dc.tar.gz
Implement type description dumping.
Diffstat (limited to 'parse')
-rw-r--r--parse/gram.y3
-rw-r--r--parse/infer.c6
-rw-r--r--parse/parse.h12
-rw-r--r--parse/specialize.c1
-rw-r--r--parse/stab.c30
-rw-r--r--parse/use.c19
6 files changed, 40 insertions, 31 deletions
diff --git a/parse/gram.y b/parse/gram.y
index 9fb49f5..6a4ca0c 100644
--- a/parse/gram.y
+++ b/parse/gram.y
@@ -281,7 +281,7 @@ optident: Tident {$$ = $1;}
;
package : Tpkg optident Tasn pkgbody Tendblk {
- if (file->file.globls->_name)
+ if (file->file.globls->name)
lfatal($1->loc, "Package already declared\n");
if ($2) {
updatens(file->file.globls, $2->id);
@@ -406,6 +406,7 @@ tydef : Ttype typeid {$$ = $2;}
$$ = $2;
if ($$.nparams == 0) {
$$.type = mktyname($2.loc, mkname($2.loc, $2.name), $4);
+ lappend(&file->file.tydefs, &file->file.ntydefs, $$.type);
} else {
$$.type = mktygeneric($2.loc, mkname($2.loc, $2.name), $2.params, $2.nparams, $4);
}
diff --git a/parse/infer.c b/parse/infer.c
index 70c5db8..f866a8c 100644
--- a/parse/infer.c
+++ b/parse/infer.c
@@ -1471,8 +1471,8 @@ static void specializeimpl(Inferstate *st, Node *n)
to do namespace dependent comparisons for specializing, we need to set the
namespace here.
*/
- if (file->file.globls->_name)
- setns(dcl->decl.name, file->file.globls->_name);
+ if (file->file.globls->name)
+ setns(dcl->decl.name, file->file.globls->name);
for (j = 0; j < t->nfuncs; j++) {
if (nameeq(dcl->decl.name, t->funcs[j]->decl.name)) {
proto = t->funcs[j];
@@ -1703,11 +1703,13 @@ static Type *tyfix(Inferstate *st, Node *ctx, Type *orig)
for (i = 0; i < t->nsub; i++)
t->sub[i] = tyfix(st, ctx, t->sub[i]);
}
+
if (t->type == Tyvar) {
if (debugopt['T'])
dump(file, stdout);
lfatal(t->loc, "underconstrained type %s near %s", tyfmt(buf, 1024, t), ctxstr(st, ctx));
}
+
if (debugopt['u'] && !tyeq(orig, t)) {
from = tystr(orig);
to = tystr(t);
diff --git a/parse/parse.h b/parse/parse.h
index 664aab6..7225803 100644
--- a/parse/parse.h
+++ b/parse/parse.h
@@ -123,7 +123,7 @@ struct Tok {
struct Stab {
Stab *super;
- char *_name;
+ char *name;
/* Contents of stab.
* types and values are in separate namespaces. */
@@ -166,9 +166,11 @@ struct Type {
Node **sdecls; /* Tystruct: decls in struct */
Ucon **udecls; /* Tyunion: decls in union */
};
- char issynth; /* Tyname: whether this is synthesized or not */
- char ishidden; /* Tyname: whether this is hidden or not */
- char ispkglocal; /* Tyname: whether this is package local or not */
+
+ char issynth; /* Tyname: whether this is synthesized or not */
+ char ishidden; /* Tyname: whether this is hidden or not */
+ char ispkglocal; /* Tyname: whether this is package local or not */
+ char isimport; /* Tyname: whether tyis type was imported. */
};
struct Ucon {
@@ -211,6 +213,8 @@ struct Node {
Node **stmts;
size_t nstmts;
Stab *globls;
+ size_t ntydefs;
+ Type **tydefs;
} file;
struct {
diff --git a/parse/specialize.c b/parse/specialize.c
index 4cb38a0..d869c2c 100644
--- a/parse/specialize.c
+++ b/parse/specialize.c
@@ -52,6 +52,7 @@ Type *tyspecialize(Type *t, Htab *tsmap, Htab *delayed)
htput(tsmap, t, ret);
for (i = 0; i < t->ngparam; i++)
lappend(&ret->arg, &ret->narg, tyspecialize(t->gparam[i], tsmap, delayed));
+ lappend(&file->file.tydefs, &file->file.ntydefs, ret);
break;
case Tyname:
arg = NULL;
diff --git a/parse/stab.c b/parse/stab.c
index 98b7f69..a8c11ee 100644
--- a/parse/stab.c
+++ b/parse/stab.c
@@ -191,7 +191,7 @@ Stab *getns_str(Stab *st, char *name)
Stab *s;
do {
- if (streq(st->_name, name))
+ if (streq(st->name, name))
return st;
if ((s = htget(st->ns, name)))
return s;
@@ -263,8 +263,8 @@ void putdcl(Stab *st, Node *s)
}
void forcedcl (Stab *st, Node *s) {
- if (st->_name)
- setns(s->decl.name, st->_name);
+ if (st->name)
+ setns(s->decl.name, st->name);
htput(st->dcl, s->decl.name, s);
assert(htget(st->dcl, s->decl.name) != NULL);
}
@@ -304,10 +304,10 @@ void puttype(Stab *st, Node *n, Type *t)
Tydefn *td;
Type *ty;
- if (st->_name)
- setns(n, st->_name);
- if (st->_name && t && t->name)
- setns(t->name, st->_name);
+ if (st->name)
+ setns(n, st->name);
+ if (st->name && t && t->name)
+ setns(t->name, st->name);
ty = gettype(st, n);
if (!ty) {
@@ -387,8 +387,8 @@ void putimpl(Stab *st, Node *n)
fatal(n, "Trait %s already implemented over %s at %s:%d",
namestr(n->impl.traitname), tystr(n->impl.type),
fname(n->loc), lnum(n->loc));
- if (st->_name)
- setns(n->impl.traitname, st->_name);
+ if (st->name)
+ setns(n->impl.traitname, st->name);
htput(st->impl, n, n);
}
@@ -408,10 +408,10 @@ void putns(Stab *st, Stab *scope)
{
Stab *s;
- s = getns_str(st, scope->_name);
+ s = getns_str(st, scope->name);
if (s)
- lfatal(Zloc, "Namespace %s already defined", st->_name);
- htput(st->ns, scope->_name, scope);
+ lfatal(Zloc, "Namespace %s already defined", st->name);
+ htput(st->ns, scope->name, scope);
}
/*
@@ -425,9 +425,9 @@ void updatens(Stab *st, char *name)
size_t i, nk;
Tydefn *td;
- if (st->_name)
- die("Stab %s already has namespace; Can't set to %s", st->_name, name);
- st->_name = strdup(name);
+ if (st->name)
+ die("Stab %s already has namespace; Can't set to %s", st->name, name);
+ st->name = strdup(name);
k = htkeys(st->dcl, &nk);
for (i = 0; i < nk; i++)
setns(k[i], name);
diff --git a/parse/use.c b/parse/use.c
index 06d702c..184eb6a 100644
--- a/parse/use.c
+++ b/parse/use.c
@@ -48,7 +48,7 @@ static void wrstab(FILE *fd, Stab *val)
size_t n, i;
void **keys;
- wrstr(fd, val->_name);
+ wrstr(fd, val->name);
/* write decls */
keys = htkeys(val->dcl, &n);
@@ -86,7 +86,7 @@ static Stab *rdstab(FILE *fd)
/* read dcls */
st = mkstab();
- st->_name = rdstr(fd);
+ st->name = rdstr(fd);
n = rdint(fd);
for (i = 0; i < n; i++)
putdcl(st, rdsym(fd, NULL));
@@ -340,6 +340,7 @@ static Type *tyunpickle(FILE *fd)
t = rdbyte(fd);
ty = mktype(Zloc, t);
+ ty->isimport = 1;
if (rdbyte(fd) == Vishidden)
ty->ishidden = 1;
/* tid is generated; don't write */
@@ -704,7 +705,7 @@ static Stab *findstab(Stab *st, char *pkg)
Stab *s;
if (!pkg) {
- if (!st->_name)
+ if (!st->name)
return st;
else
return NULL;
@@ -713,7 +714,7 @@ static Stab *findstab(Stab *st, char *pkg)
s = getns_str(st, pkg);
if (!s) {
s = mkstab();
- s->_name = strdup(pkg);
+ s->name = strdup(pkg);
putns(st, s);
}
return s;
@@ -827,8 +828,8 @@ int loaduse(FILE *f, Stab *st, Vis vis)
/* if the package names match up, or the usefile has no declared
* package, then we simply add to the current stab. Otherwise,
* we add a new stab under the current one */
- if (st->_name) {
- if (pkg && !strcmp(pkg, st->_name)) {
+ if (st->name) {
+ if (pkg && !strcmp(pkg, st->name)) {
s = st;
} else {
s = findstab(st, pkg);
@@ -841,7 +842,7 @@ int loaduse(FILE *f, Stab *st, Vis vis)
}
}
if (!s) {
- printf("could not find matching package for merge: %s\n", st->_name);
+ printf("could not find matching package for merge: %s\n", st->name);
exit(1);
}
tidmap = mkht(ptrhash, ptreq);
@@ -964,8 +965,8 @@ void writeuse(FILE *f, Node *file)
/* usefile name */
wrbyte(f, 'U');
wrint(f, Useversion); /* use version */
- if (st->_name)
- wrstr(f, st->_name);
+ if (st->name)
+ wrstr(f, st->name);
else
wrstr(f, NULL);