ref: e89a6b09545f09a0f9f6491d0f4614d19d8847cd
parent: 7b45d388ae914b853e330a1ce35881e4f7910fdf
author: Ori Bernstein <[email protected]>
date: Thu May 15 09:01:33 EDT 2014
Actually write out impls to usefiles.
--- a/parse/gram.y
+++ b/parse/gram.y
@@ -194,7 +194,9 @@
toplev : package
| use {lappend(&file->file.uses, &file->file.nuses, $1);}
- | implstmt {lappend(&file->file.stmts, &file->file.nstmts, $1);}
+ | implstmt {
+ lappend(&file->file.stmts, &file->file.nstmts, $1);
+ }
| traitdef {
size_t i;
puttrait(file->file.globls, $1->name, $1);
@@ -320,7 +322,10 @@
| Tident Tdot name {$$ = $3; setns($3, $1->str);}
;
-implstmt: Timpl name type {$$ = mkimplstmt($1->line, $2, $3, NULL, 0);}
+implstmt: Timpl name type {
+ $$ = mkimplstmt($1->line, $2, $3, NULL, 0);
+ $$->impl.isproto = 1;
+ }
| Timpl name type Tasn Tendln implbody Tendblk {
$$ = mkimplstmt($1->line, $2, $3, $6.nl, $6.nn);
}
--- a/parse/infer.c
+++ b/parse/infer.c
@@ -859,11 +859,10 @@
fatal(nx->line, "Missing trait impl body for %s %s\n", namestr(nx->impl.traitname), tystr(nx->impl.type));
htdel(exports->impl, k[i]);
putimpl(exports, ng);
- lappend(&exportimpls, &nexportimpls, ng);
+ ng->impl.vis = Visexport;
} else {
if (!ng) {
putimpl(globls, nx);
- lappend(&exportimpls, &nexportimpls, nx);
} else {
fatal(nx->line, "Double trait impl body for %s %s on line %d\n",
namestr(nx->impl.traitname), tystr(nx->impl.type), ng->line);
--- a/parse/node.c
+++ b/parse/node.c
@@ -15,8 +15,8 @@
size_t maxnid;
Node **decls;
size_t ndecls;
-Node **exportimpls;
-size_t nexportimpls;
+Node **impls;
+size_t nimpls;
Node *mknode(int line, Ntype nt)
{
@@ -194,6 +194,7 @@
n->impl.type = t;
n->impl.decls = decls;
n->impl.ndecls = ndecls;
+ lappend(&impls, &nimpls, n);
return n;
}
--- a/parse/parse.h
+++ b/parse/parse.h
@@ -319,8 +319,8 @@
extern size_t ntraittab;
extern Node **decls; /* decl id -> decl map */
extern size_t ndecls;
-extern Node **exportimpls;
-extern size_t nexportimpls;
+extern Node **impls;
+extern size_t nimpls;
extern size_t maxnid; /* the maximum node id generated so far */
extern int ispureop[];
--- a/parse/use.c
+++ b/parse/use.c
@@ -899,10 +899,12 @@
}
}
- for (i = 0; i < nexportimpls; i++) {
- if (exportimpls[i]->impl.vis == Visexport || exportimpls[i]->impl.vis == Vishidden) {
+ for (i = 0; i < nimpls; i++) {
+ if (impls[i]->impl.isproto)
+ continue;
+ if (impls[i]->impl.vis == Visexport || impls[i]->impl.vis == Vishidden) {
wrbyte(f, 'I');
- implpickle(f, exportimpls[i]);
+ implpickle(f, impls[i]);
}
}