ref: 567766b0cb773c76a9ec0d16246bd27b4a46b851
parent: 6f5af8562ed5547ddaeb15ba7ed4a334318ca53f
author: Michael Forney <mforney@mforney.org>
date: Tue Jun 27 23:24:57 EDT 2017
Remove unused memb from Trait and rename funcs -> proto These are prototype declarations that must be implemented by the impl (not necessarily functions), so proto seems like a better name.
--- a/mi/flatten.c
+++ b/mi/flatten.c
@@ -751,10 +751,10 @@
char *name;
size_t i;
- for (i = 0; i < tr->nfuncs; i++) {
- name = declname(tr->funcs[i]);
+ for (i = 0; i < tr->nproto; i++) {
+ name = declname(tr->proto[i]);
if (!strcmp(fn, name)) {
- proto = tr->funcs[i];
+ proto = tr->proto[i];
dcl = htget(proto->decl.impls, ty);
var = mkexpr(loc, Ovar, dcl->decl.name, NULL);
var->expr.type = dcl->decl.type;
--- a/parse/export.c
+++ b/parse/export.c
@@ -60,10 +60,8 @@
tagtype(st, tr->param, ingeneric, hidelocal);
for (i = 0; i < tr->naux; i++)
tagtype(st, tr->aux[i], ingeneric, hidelocal);
- for (i = 0; i < tr->nmemb; i++)
- tagnode(st, tr->memb[i], ingeneric, hidelocal);
- for (i = 0; i < tr->nfuncs; i++)
- tagnode(st, tr->funcs[i], ingeneric, hidelocal);
+ for (i = 0; i < tr->nproto; i++)
+ tagnode(st, tr->proto[i], ingeneric, hidelocal);
}
static void tagtype(Stab *st, Type *t, int ingeneric, int hidelocal)
@@ -261,13 +259,9 @@
tr->param->vis = tr->vis;
for (i = 0; i < tr->naux; i++)
tr->aux[i]->vis = tr->vis;
- for (i = 0; i < tr->nmemb; i++) {
- tr->memb[i]->decl.vis = tr->vis;
- tagnode(st, tr->memb[i], 0, hidelocal);
- }
- for (i = 0; i < tr->nfuncs; i++) {
- tr->funcs[i]->decl.vis = tr->vis;
- tagnode(st, tr->funcs[i], 0, hidelocal);
+ for (i = 0; i < tr->nproto; i++) {
+ tr->proto[i]->decl.vis = tr->vis;
+ tagnode(st, tr->proto[i], 0, hidelocal);
}
}
free(k);
--- a/parse/gram.y
+++ b/parse/gram.y
@@ -229,8 +229,8 @@
| traitdef {
size_t i;
puttrait(file->file.globls, $1->name, $1);
- for (i = 0; i < $1->nfuncs; i++)
- putdcl(file->file.globls, $1->funcs[i]);
+ for (i = 0; i < $1->nproto; i++)
+ putdcl(file->file.globls, $1->proto[i]);
}
| tydef {
puttype(file->file.globls, mkname($1.loc, $1.name), $1.type);
@@ -344,8 +344,8 @@
size_t i;
$1->vis = Visexport;
puttrait(file->file.globls, $1->name, $1);
- for (i = 0; i < $1->nfuncs; i++)
- putdcl(file->file.globls, $1->funcs[i]);
+ for (i = 0; i < $1->nproto; i++)
+ putdcl(file->file.globls, $1->proto[i]);
}
| implstmt {
$1->impl.vis = Visexport;
@@ -411,7 +411,6 @@
mkname($2->loc, $2->id), $3,
$4.types, $4.ntypes,
NULL, 0,
- NULL, 0,
1);
}
| Ttrait Tident generictype optauxtypes Tasn traitbody Tendblk /* trait definition */ {
@@ -419,7 +418,6 @@
$$ = mktrait($1->loc,
mkname($2->loc, $2->id), $3,
$4.types, $4.ntypes,
- NULL, 0,
$6.nl, $6.nn,
0);
for (i = 0; i < $6.nn; i++) {
--- a/parse/infer.c
+++ b/parse/infer.c
@@ -248,13 +248,13 @@
return;
if (ty->type == Tyslice || ty->type == Tyarray || ty->type == Typtr)
return;
- for (i = 0; i < tr->nfuncs; i++) {
+ for (i = 0; i < tr->nproto; i++) {
ty = exprtype(n->iterstmt.seq);
- if (hthas(tr->funcs[i]->decl.impls, ty))
+ if (hthas(tr->proto[i]->decl.impls, ty))
continue;
lappend(&st->specializationscope, &st->nspecializationscope, stab);
lappend(&st->specializations, &st->nspecializations, n);
- lappend(&st->genericdecls, &st->ngenericdecls, tr->funcs[i]);
+ lappend(&st->genericdecls, &st->ngenericdecls, tr->proto[i]);
}
}
@@ -1779,9 +1779,9 @@
*/
if (file->file.globls->name)
setns(dcl->decl.name, file->file.globls->name);
- for (j = 0; j < t->nfuncs; j++) {
- if (nsnameeq(dcl->decl.name, t->funcs[j]->decl.name)) {
- proto = t->funcs[j];
+ for (j = 0; j < t->nproto; j++) {
+ if (nsnameeq(dcl->decl.name, t->proto[j]->decl.name)) {
+ proto = t->proto[j];
break;
}
}
@@ -2493,16 +2493,16 @@
typesub(st, d, 0);
} else if (n->type == Niterstmt) {
tr = traittab[Tciter];
- assert(tr->nfuncs == 2);
+ assert(tr->nproto == 2);
ty = exprtype(n->iterstmt.seq);
it = itertype(st, n->iterstmt.seq, mktype(n->loc, Tybool));
- d = specializedcl(tr->funcs[0], it, &name);
- htput(tr->funcs[0]->decl.impls, ty, d);
+ d = specializedcl(tr->proto[0], it, &name);
+ htput(tr->proto[0]->decl.impls, ty, d);
it = itertype(st, n->iterstmt.seq, mktype(n->loc, Tyvoid));
- d = specializedcl(tr->funcs[1], it, &name);
- htput(tr->funcs[1]->decl.impls, ty, d);
+ d = specializedcl(tr->proto[1], it, &name);
+ htput(tr->proto[1]->decl.impls, ty, d);
} else {
die("unknown node for specialization\n");
}
--- a/parse/parse.h
+++ b/parse/parse.h
@@ -164,10 +164,8 @@
Type *param; /* the type parameter */
Type **aux; /* auxiliary parameters */
size_t naux;
- Node **memb; /* type must have these members */
- size_t nmemb;
- Node **funcs; /* and declare these funcs */
- size_t nfuncs;
+ Node **proto; /* type must implement these prototypes */
+ size_t nproto;
char isproto; /* is it a prototype (for exporting purposes) */
char ishidden; /* should user code be able to use this? */
@@ -431,8 +429,7 @@
Trait *mktrait(Srcloc l, Node *name,
Type *param,
Type **aux, size_t naux,
- Node **memb, size_t nmemb,
- Node **funcs, size_t nfuncs,
+ Node **proto, size_t nproto,
int isproto);
Type *mktylike(Srcloc l, Ty ty); /* constrains tyvar t like it was builtin ty */
Ucon *finducon(Type *t, Node *name);
--- a/parse/type.c
+++ b/parse/type.c
@@ -141,8 +141,7 @@
/* steals memb, funcs */
Trait *mktrait(Srcloc loc, Node *name, Type *param,
Type **aux, size_t naux,
- Node **memb, size_t nmemb,
- Node **funcs, size_t nfuncs,
+ Node **proto, size_t nproto,
int isproto)
{
Trait *t;
@@ -155,12 +154,10 @@
t->vis = Visintern;
t->name = name;
t->param = param;
- t->memb = memb;
- t->nmemb = nmemb;
+ t->proto = proto;
+ t->nproto = nproto;
t->aux = aux;
t->naux = naux;
- t->funcs = funcs;
- t->nfuncs = nfuncs;
t->isproto = isproto;
traittab = xrealloc(traittab, ntraittab * sizeof(Trait *));
@@ -924,7 +921,7 @@
func->decl.isglobl = 1;
func->decl.isextern = 1;
- lappend(&tr->funcs, &tr->nfuncs, func);
+ lappend(&tr->proto, &tr->nproto, func);
putdcl(st, func);
/* __iterfin__ : (it : @a#, outval : @b# -> void) */
@@ -944,7 +941,7 @@
func->decl.isglobl = 1;
func->decl.isextern = 1;
- lappend(&tr->funcs, &tr->nfuncs, func);
+ lappend(&tr->proto, &tr->nproto, func);
putdcl(st, func);
}
@@ -960,7 +957,6 @@
#define Tc(c, n) \
tr = mktrait(Zloc, \
mkname(Zloc, n), NULL, \
- NULL, 0, \
NULL, 0, \
NULL, 0, \
0); \
--- a/parse/use.c
+++ b/parse/use.c
@@ -288,12 +288,9 @@
wrint(fd, tr->naux);
for (i = 0; i < tr->naux; i++)
wrtype(fd, tr->aux[i]);
- wrint(fd, tr->nmemb);
- for (i = 0; i < tr->nmemb; i++)
- wrsym(fd, tr->memb[i]);
- wrint(fd, tr->nfuncs);
- for (i = 0; i < tr->nfuncs; i++)
- wrsym(fd, tr->funcs[i]);
+ wrint(fd, tr->nproto);
+ for (i = 0; i < tr->nproto; i++)
+ wrsym(fd, tr->proto[i]);
}
static void wrtype(FILE *fd, Type *ty)
@@ -407,7 +404,7 @@
Trait *traitunpickle(FILE *fd)
{
Trait *tr;
- Node *fn;
+ Node *proto;
size_t i, n;
intptr_t uid;
@@ -415,7 +412,6 @@
tr = mktrait(Zloc, NULL, NULL,
NULL, 0,
NULL, 0,
- NULL, 0,
0);
uid = rdint(fd);
if (rdint(fd) == Vishidden)
@@ -428,13 +424,10 @@
for (i = 0; i < tr->naux; i++)
rdtype(fd, &tr->aux[i]);
n = rdint(fd);
- for (i = 0; i < n; i++)
- lappend(&tr->memb, &tr->nmemb, rdsym(fd, tr));
- n = rdint(fd);
for (i = 0; i < n; i++) {
- fn = rdsym(fd, tr);
- fn->decl.impls = mkht(tyhash, tyeq);
- lappend(&tr->funcs, &tr->nfuncs, fn);
+ proto = rdsym(fd, tr);
+ proto->decl.impls = mkht(tyhash, tyeq);
+ lappend(&tr->proto, &tr->nproto, proto);
}
htput(trmap, itop(uid), tr);
return tr;
@@ -837,8 +830,8 @@
Node *proto;
dclname = declname(dcl);
- for (i = 0; i < tr->nfuncs; i++) {
- proto = tr->funcs[i];
+ for (i = 0; i < tr->nproto; i++) {
+ proto = tr->proto[i];
protoname = declname(proto);
len = strlen(protoname);
p = strstr(dclname, protoname);
@@ -979,8 +972,8 @@
if (!tr->ishidden) {
tr->vis = vis;
puttrait(s, tr->name, tr);
- for (i = 0; i < tr->nfuncs; i++) {
- putdcl(s, tr->funcs[i]);
+ for (i = 0; i < tr->nproto; i++) {
+ putdcl(s, tr->proto[i]);
}
}
break;