2008-06-04 15:37:38 -06:00
|
|
|
// Copyright 2009 The Go Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
#include "go.h"
|
|
|
|
#include "y.tab.h"
|
|
|
|
|
|
|
|
void
|
2008-09-26 22:27:26 -06:00
|
|
|
addexportsym(Sym *s)
|
2008-06-04 15:37:38 -06:00
|
|
|
{
|
|
|
|
Dcl *d, *r;
|
|
|
|
|
|
|
|
d = mal(sizeof(*d));
|
|
|
|
d->dsym = s;
|
|
|
|
d->dnode = N;
|
2008-06-13 19:16:23 -06:00
|
|
|
d->lineno = lineno;
|
2008-06-04 15:37:38 -06:00
|
|
|
|
|
|
|
r = exportlist;
|
|
|
|
d->back = r->back;
|
|
|
|
r->back->forw = d;
|
|
|
|
r->back = d;
|
|
|
|
}
|
|
|
|
|
2008-09-26 22:27:26 -06:00
|
|
|
void
|
|
|
|
exportsym(Sym *s)
|
|
|
|
{
|
|
|
|
if(s == S)
|
|
|
|
return;
|
|
|
|
if(s->export != 0)
|
|
|
|
return;
|
|
|
|
s->export = 1;
|
|
|
|
|
|
|
|
addexportsym(s);
|
|
|
|
}
|
|
|
|
|
2008-06-04 15:37:38 -06:00
|
|
|
void
|
2008-09-24 15:12:21 -06:00
|
|
|
makeexportsym(Type *t)
|
2008-06-04 15:37:38 -06:00
|
|
|
{
|
|
|
|
Sym *s;
|
|
|
|
|
2008-09-24 15:12:21 -06:00
|
|
|
if(t->sym == S) {
|
2008-06-04 15:37:38 -06:00
|
|
|
exportgen++;
|
2008-07-08 18:19:17 -06:00
|
|
|
snprint(namebuf, sizeof(namebuf), "_e%s_%.3ld", filename, exportgen);
|
2008-06-04 15:37:38 -06:00
|
|
|
s = lookup(namebuf);
|
|
|
|
s->lexical = LATYPE;
|
|
|
|
s->otype = t;
|
|
|
|
t->sym = s;
|
|
|
|
}
|
2008-09-24 15:12:21 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
reexport(Type *t)
|
|
|
|
{
|
|
|
|
if(t == T)
|
|
|
|
fatal("reexport: type nil");
|
|
|
|
makeexportsym(t);
|
2008-09-26 22:27:26 -06:00
|
|
|
dumpexporttype(t->sym);
|
2008-06-04 15:37:38 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
dumpexportconst(Sym *s)
|
|
|
|
{
|
|
|
|
Node *n;
|
|
|
|
Type *t;
|
|
|
|
|
|
|
|
if(s->exported != 0)
|
|
|
|
return;
|
|
|
|
s->exported = 1;
|
|
|
|
|
|
|
|
n = s->oconst;
|
|
|
|
if(n == N || n->op != OLITERAL)
|
2008-07-27 14:09:15 -06:00
|
|
|
fatal("dumpexportconst: oconst nil: %S", s);
|
2008-06-04 15:37:38 -06:00
|
|
|
|
|
|
|
t = n->type; // may or may not be specified
|
|
|
|
if(t != T)
|
|
|
|
reexport(t);
|
|
|
|
|
|
|
|
Bprint(bout, "\tconst ");
|
|
|
|
if(s->export != 0)
|
|
|
|
Bprint(bout, "!");
|
|
|
|
Bprint(bout, "%lS ", s);
|
|
|
|
if(t != T)
|
|
|
|
Bprint(bout, "%lS ", t->sym);
|
|
|
|
|
|
|
|
switch(n->val.ctype) {
|
|
|
|
default:
|
2008-07-27 14:09:15 -06:00
|
|
|
fatal("dumpexportconst: unknown ctype: %S", s);
|
2008-06-04 15:37:38 -06:00
|
|
|
case CTINT:
|
|
|
|
case CTSINT:
|
|
|
|
case CTUINT:
|
2008-08-11 14:22:04 -06:00
|
|
|
Bprint(bout, "%B\n", n->val.u.xval);
|
2008-08-08 18:13:31 -06:00
|
|
|
break;
|
2008-06-04 15:37:38 -06:00
|
|
|
case CTBOOL:
|
2008-08-08 18:13:31 -06:00
|
|
|
Bprint(bout, "0x%llux\n", n->val.u.bval);
|
2008-06-04 15:37:38 -06:00
|
|
|
break;
|
|
|
|
case CTFLT:
|
2008-08-08 18:13:31 -06:00
|
|
|
Bprint(bout, "%.17e\n", mpgetflt(n->val.u.fval));
|
2008-06-04 15:37:38 -06:00
|
|
|
break;
|
|
|
|
case CTSTR:
|
2008-08-08 18:13:31 -06:00
|
|
|
Bprint(bout, "\"%Z\"\n", n->val.u.sval);
|
2008-06-04 15:37:38 -06:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
dumpexportvar(Sym *s)
|
|
|
|
{
|
|
|
|
Node *n;
|
|
|
|
Type *t;
|
|
|
|
|
|
|
|
if(s->exported != 0)
|
|
|
|
return;
|
|
|
|
s->exported = 1;
|
|
|
|
|
|
|
|
n = s->oname;
|
2008-07-05 18:43:25 -06:00
|
|
|
if(n == N || n->type == T) {
|
2008-07-14 21:40:48 -06:00
|
|
|
yyerror("variable exported but not defined: %S", s);
|
2008-07-05 18:43:25 -06:00
|
|
|
return;
|
|
|
|
}
|
2008-06-04 15:37:38 -06:00
|
|
|
|
|
|
|
t = n->type;
|
|
|
|
reexport(t);
|
|
|
|
|
|
|
|
Bprint(bout, "\tvar ");
|
|
|
|
if(s->export != 0)
|
|
|
|
Bprint(bout, "!");
|
|
|
|
Bprint(bout, "%lS %lS\n", s, t->sym);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
dumpexporttype(Sym *s)
|
|
|
|
{
|
|
|
|
Type *t, *f;
|
|
|
|
Sym *ts;
|
2008-09-26 22:27:26 -06:00
|
|
|
int et, forw;
|
2008-06-04 15:37:38 -06:00
|
|
|
|
|
|
|
if(s->exported != 0)
|
|
|
|
return;
|
|
|
|
s->exported = 1;
|
|
|
|
|
|
|
|
t = s->otype;
|
2008-07-05 18:43:25 -06:00
|
|
|
if(t == T) {
|
2008-07-14 21:40:48 -06:00
|
|
|
yyerror("type exported but not defined: %S", s);
|
2008-07-05 18:43:25 -06:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-06-04 15:37:38 -06:00
|
|
|
if(t->sym != s)
|
2008-07-27 14:09:15 -06:00
|
|
|
fatal("dumpexporttype: cross reference: %S", s);
|
2008-06-04 15:37:38 -06:00
|
|
|
|
|
|
|
et = t->etype;
|
|
|
|
switch(et) {
|
|
|
|
default:
|
|
|
|
if(et < 0 || et >= nelem(types) || types[et] == T)
|
2008-07-27 14:09:15 -06:00
|
|
|
fatal("dumpexporttype: basic type: %S %E", s, et);
|
2008-06-04 15:37:38 -06:00
|
|
|
/* type 5 */
|
2008-09-22 13:45:01 -06:00
|
|
|
Bprint(bout, "\ttype ");
|
|
|
|
if(s->export != 0)
|
|
|
|
Bprint(bout, "!");
|
|
|
|
Bprint(bout, "%lS %d\n", s, et);
|
2008-06-04 15:37:38 -06:00
|
|
|
break;
|
|
|
|
|
|
|
|
case TARRAY:
|
|
|
|
reexport(t->type);
|
|
|
|
|
|
|
|
/* type 2 */
|
|
|
|
Bprint(bout, "\ttype ");
|
|
|
|
if(s->export != 0)
|
|
|
|
Bprint(bout, "!");
|
2008-08-28 16:17:37 -06:00
|
|
|
if(t->bound >= 0)
|
|
|
|
Bprint(bout, "%lS [%lud] %lS\n", s, t->bound, t->type->sym);
|
|
|
|
else
|
2008-08-27 18:28:30 -06:00
|
|
|
Bprint(bout, "%lS [] %lS\n", s, t->type->sym);
|
2008-06-04 15:37:38 -06:00
|
|
|
break;
|
|
|
|
|
|
|
|
case TPTR32:
|
|
|
|
case TPTR64:
|
2008-09-24 15:12:21 -06:00
|
|
|
if(t->type == T)
|
|
|
|
fatal("dumpexporttype: ptr %S", s);
|
2008-09-29 21:33:51 -06:00
|
|
|
if(t->type->etype == TFORW) {
|
|
|
|
yyerror("export of a undefined forward reference: %S", s);
|
|
|
|
break;
|
|
|
|
}
|
2008-09-26 22:27:26 -06:00
|
|
|
makeexportsym(t->type);
|
|
|
|
ts = t->type->sym;
|
|
|
|
if(ts->exported == 0)
|
|
|
|
addexportsym(ts);
|
2008-06-04 15:37:38 -06:00
|
|
|
|
|
|
|
/* type 6 */
|
|
|
|
Bprint(bout, "\ttype ");
|
|
|
|
if(s->export != 0)
|
|
|
|
Bprint(bout, "!");
|
2008-09-26 22:27:26 -06:00
|
|
|
Bprint(bout, "%lS *%lS\n", s, ts);
|
2008-09-24 15:12:21 -06:00
|
|
|
|
2008-06-04 15:37:38 -06:00
|
|
|
break;
|
|
|
|
|
|
|
|
case TFUNC:
|
|
|
|
for(f=t->type; f!=T; f=f->down) {
|
|
|
|
if(f->etype != TSTRUCT)
|
2008-07-27 14:09:15 -06:00
|
|
|
fatal("dumpexporttype: funct not field: %T", f);
|
2008-06-04 15:37:38 -06:00
|
|
|
reexport(f);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* type 3 */
|
|
|
|
Bprint(bout, "\ttype ");
|
|
|
|
if(s->export != 0)
|
|
|
|
Bprint(bout, "!");
|
|
|
|
Bprint(bout, "%lS (", s);
|
|
|
|
for(f=t->type; f!=T; f=f->down) {
|
|
|
|
if(f != t->type)
|
|
|
|
Bprint(bout, " ");
|
|
|
|
Bprint(bout, "%lS", f->sym);
|
|
|
|
}
|
|
|
|
Bprint(bout, ")\n");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TSTRUCT:
|
|
|
|
case TINTER:
|
|
|
|
for(f=t->type; f!=T; f=f->down) {
|
|
|
|
if(f->etype != TFIELD)
|
2008-07-27 14:09:15 -06:00
|
|
|
fatal("dumpexporttype: funct not field: %lT", f);
|
2008-06-04 15:37:38 -06:00
|
|
|
reexport(f->type);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* type 4 */
|
|
|
|
Bprint(bout, "\ttype ");
|
|
|
|
if(s->export)
|
|
|
|
Bprint(bout, "!");
|
|
|
|
Bprint(bout, "%lS %c", s, (et==TSTRUCT)? '{': '<');
|
|
|
|
for(f=t->type; f!=T; f=f->down) {
|
|
|
|
ts = f->type->sym;
|
|
|
|
if(f != t->type)
|
|
|
|
Bprint(bout, " ");
|
|
|
|
Bprint(bout, "%s %lS", f->sym->name, ts);
|
|
|
|
}
|
|
|
|
Bprint(bout, "%c\n", (et==TSTRUCT)? '}': '>');
|
|
|
|
break;
|
2008-06-15 21:24:30 -06:00
|
|
|
|
|
|
|
case TMAP:
|
|
|
|
reexport(t->type);
|
|
|
|
reexport(t->down);
|
|
|
|
|
2008-09-24 15:12:21 -06:00
|
|
|
/* type 1 */
|
2008-06-15 21:24:30 -06:00
|
|
|
Bprint(bout, "\ttype ");
|
|
|
|
if(s->export != 0)
|
|
|
|
Bprint(bout, "!");
|
|
|
|
Bprint(bout, "%lS [%lS] %lS\n", s, t->down->sym, t->type->sym);
|
|
|
|
break;
|
2008-07-12 14:08:53 -06:00
|
|
|
|
|
|
|
case TCHAN:
|
|
|
|
reexport(t->type);
|
|
|
|
|
|
|
|
/* type 8 */
|
|
|
|
Bprint(bout, "\ttype ");
|
|
|
|
if(s->export != 0)
|
|
|
|
Bprint(bout, "!");
|
|
|
|
Bprint(bout, "%lS %d %lS\n", s, t->chan, t->type->sym);
|
|
|
|
break;
|
2008-06-04 15:37:38 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
dumpe(Sym *s)
|
|
|
|
{
|
|
|
|
switch(s->lexical) {
|
|
|
|
default:
|
2008-07-14 21:40:48 -06:00
|
|
|
yyerror("unknown export symbol: %S", s, s->lexical);
|
2008-06-04 15:37:38 -06:00
|
|
|
break;
|
|
|
|
case LPACK:
|
2008-07-14 21:40:48 -06:00
|
|
|
yyerror("package export symbol: %S", s);
|
2008-06-04 15:37:38 -06:00
|
|
|
break;
|
|
|
|
case LATYPE:
|
|
|
|
case LBASETYPE:
|
2008-09-26 22:27:26 -06:00
|
|
|
//print("TYPE %S\n", s);
|
2008-06-04 15:37:38 -06:00
|
|
|
dumpexporttype(s);
|
|
|
|
break;
|
|
|
|
case LNAME:
|
2008-09-26 22:27:26 -06:00
|
|
|
//print("VAR %S\n", s);
|
2008-06-04 15:37:38 -06:00
|
|
|
dumpexportvar(s);
|
|
|
|
break;
|
|
|
|
case LACONST:
|
2008-09-26 22:27:26 -06:00
|
|
|
//print("CONST %S\n", s);
|
2008-06-04 15:37:38 -06:00
|
|
|
dumpexportconst(s);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-09-23 13:48:52 -06:00
|
|
|
void
|
|
|
|
dumpm(Sym *s)
|
|
|
|
{
|
|
|
|
Type *t, *f;
|
|
|
|
|
|
|
|
switch(s->lexical) {
|
|
|
|
default:
|
|
|
|
return;
|
|
|
|
|
|
|
|
case LATYPE:
|
|
|
|
case LBASETYPE:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
t = s->otype;
|
|
|
|
if(t == T) {
|
|
|
|
yyerror("type exported but not defined: %S", s);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for(f=t->method; f!=T; f=f->down) {
|
|
|
|
if(f->etype != TFIELD)
|
|
|
|
fatal("dumpexporttype: method not field: %lT", f);
|
|
|
|
reexport(f->type);
|
|
|
|
Bprint(bout, "\tfunc %S %lS\n", f->sym, f->type->sym);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-06-04 15:37:38 -06:00
|
|
|
void
|
|
|
|
dumpexport(void)
|
|
|
|
{
|
|
|
|
Dcl *d;
|
2008-08-03 18:25:15 -06:00
|
|
|
int32 lno;
|
2008-06-04 15:37:38 -06:00
|
|
|
|
2008-06-26 18:54:44 -06:00
|
|
|
lno = lineno;
|
2008-06-04 15:37:38 -06:00
|
|
|
|
|
|
|
Bprint(bout, " import\n");
|
|
|
|
Bprint(bout, " ((\n");
|
|
|
|
|
2008-06-12 22:48:56 -06:00
|
|
|
Bprint(bout, " package %s\n", package);
|
|
|
|
|
2008-09-23 13:48:52 -06:00
|
|
|
// first pass dump vars/types depth first
|
2008-06-04 15:37:38 -06:00
|
|
|
for(d=exportlist->forw; d!=D; d=d->forw) {
|
2008-06-26 18:54:44 -06:00
|
|
|
lineno = d->lineno;
|
2008-06-04 15:37:38 -06:00
|
|
|
dumpe(d->dsym);
|
|
|
|
}
|
|
|
|
|
2008-09-23 13:48:52 -06:00
|
|
|
// second pass dump methods
|
|
|
|
for(d=exportlist->forw; d!=D; d=d->forw) {
|
|
|
|
lineno = d->lineno;
|
|
|
|
dumpm(d->dsym);
|
|
|
|
}
|
|
|
|
|
2008-09-26 22:27:26 -06:00
|
|
|
// third pass pick up redefs from previous passes
|
|
|
|
for(d=exportlist->forw; d!=D; d=d->forw) {
|
|
|
|
lineno = d->lineno;
|
|
|
|
dumpe(d->dsym);
|
|
|
|
}
|
|
|
|
|
2008-06-04 15:37:38 -06:00
|
|
|
Bprint(bout, " ))\n");
|
|
|
|
|
2008-06-26 18:54:44 -06:00
|
|
|
lineno = lno;
|
2008-06-04 15:37:38 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* ******* import *******
|
|
|
|
*/
|
2008-09-24 15:12:21 -06:00
|
|
|
|
|
|
|
void
|
|
|
|
checkimports(void)
|
|
|
|
{
|
|
|
|
Sym *s;
|
|
|
|
Type *t, *t1;
|
|
|
|
uint32 h;
|
|
|
|
int et;
|
|
|
|
|
2008-09-26 22:27:26 -06:00
|
|
|
return;
|
|
|
|
|
2008-09-24 15:12:21 -06:00
|
|
|
for(h=0; h<NHASH; h++)
|
|
|
|
for(s = hash[h]; s != S; s = s->link) {
|
|
|
|
t = s->otype;
|
|
|
|
if(t == T)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
et = t->etype;
|
|
|
|
switch(t->etype) {
|
|
|
|
case TFORW:
|
|
|
|
print("ci-1: %S %lT\n", s, t);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TPTR32:
|
|
|
|
case TPTR64:
|
|
|
|
if(t->type == T) {
|
|
|
|
print("ci-2: %S %lT\n", s, t);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
t1 = t->type;
|
|
|
|
if(t1 == T) {
|
|
|
|
print("ci-3: %S %lT\n", s, t1);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
et = t1->etype;
|
|
|
|
if(et == TFORW) {
|
|
|
|
print("%L: ci-4: %S %lT\n", lineno, s, t);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-06-12 22:48:56 -06:00
|
|
|
void
|
|
|
|
renamepkg(Node *n)
|
|
|
|
{
|
|
|
|
if(n->psym == pkgimportname)
|
|
|
|
if(pkgmyname != S)
|
|
|
|
n->psym = pkgmyname;
|
|
|
|
}
|
|
|
|
|
2008-06-11 22:06:26 -06:00
|
|
|
Sym*
|
|
|
|
getimportsym(Node *ss)
|
|
|
|
{
|
|
|
|
char *pkg;
|
|
|
|
Sym *s;
|
|
|
|
|
|
|
|
if(ss->op != OIMPORT)
|
2008-07-27 14:09:15 -06:00
|
|
|
fatal("getimportsym: oops1 %N", ss);
|
2008-06-11 22:06:26 -06:00
|
|
|
|
|
|
|
pkg = ss->psym->name;
|
|
|
|
s = pkglookup(ss->sym->name, pkg);
|
|
|
|
|
|
|
|
/* botch - need some diagnostic checking for the following assignment */
|
|
|
|
s->opackage = ss->osym->name;
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
2008-06-04 15:37:38 -06:00
|
|
|
Type*
|
|
|
|
importlooktype(Node *n)
|
|
|
|
{
|
|
|
|
Sym *s;
|
|
|
|
|
2008-06-11 22:06:26 -06:00
|
|
|
s = getimportsym(n);
|
2008-06-04 15:37:38 -06:00
|
|
|
if(s->otype == T)
|
2008-07-27 14:09:15 -06:00
|
|
|
fatal("importlooktype: oops2 %S", s);
|
2008-06-04 15:37:38 -06:00
|
|
|
return s->otype;
|
|
|
|
}
|
|
|
|
|
|
|
|
Type**
|
|
|
|
importstotype(Node *fl, Type **t, Type *uber)
|
|
|
|
{
|
|
|
|
Type *f;
|
|
|
|
Iter save;
|
|
|
|
Node *n;
|
|
|
|
|
|
|
|
n = listfirst(&save, &fl);
|
|
|
|
|
|
|
|
loop:
|
|
|
|
if(n == N) {
|
|
|
|
*t = T;
|
|
|
|
return t;
|
|
|
|
}
|
|
|
|
f = typ(TFIELD);
|
|
|
|
f->type = importlooktype(n);
|
|
|
|
|
|
|
|
if(n->fsym != S) {
|
|
|
|
f->nname = newname(n->fsym);
|
|
|
|
} else {
|
|
|
|
vargen++;
|
|
|
|
snprint(namebuf, sizeof(namebuf), "_m%.3ld", vargen);
|
|
|
|
f->nname = newname(lookup(namebuf));
|
|
|
|
}
|
|
|
|
f->sym = f->nname->sym;
|
|
|
|
|
|
|
|
*t = f;
|
|
|
|
t = &f->down;
|
|
|
|
|
|
|
|
n = listnext(&save);
|
|
|
|
goto loop;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
importcount(Type *t)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
Type *f;
|
|
|
|
|
|
|
|
if(t == T || t->etype != TSTRUCT)
|
|
|
|
fatal("importcount: not a struct: %N", t);
|
|
|
|
|
|
|
|
i = 0;
|
|
|
|
for(f=t->type; f!=T; f=f->down)
|
|
|
|
i = i+1;
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
importfuncnam(Type *t)
|
|
|
|
{
|
|
|
|
Node *n;
|
|
|
|
Type *t1;
|
|
|
|
|
|
|
|
if(t->etype != TFUNC)
|
2008-07-27 14:09:15 -06:00
|
|
|
fatal("importfuncnam: not func %T", t);
|
2008-06-04 15:37:38 -06:00
|
|
|
|
|
|
|
if(t->thistuple > 0) {
|
|
|
|
t1 = t->type;
|
|
|
|
if(t1->sym == S)
|
|
|
|
fatal("importfuncnam: no this");
|
|
|
|
n = newname(t1->sym);
|
|
|
|
vargen++;
|
|
|
|
n->vargen = vargen;
|
|
|
|
t1->nname = n;
|
|
|
|
}
|
|
|
|
if(t->outtuple > 0) {
|
|
|
|
t1 = t->type->down;
|
|
|
|
if(t1->sym == S)
|
|
|
|
fatal("importfuncnam: no output");
|
|
|
|
n = newname(t1->sym);
|
|
|
|
vargen++;
|
|
|
|
n->vargen = vargen;
|
|
|
|
t1->nname = n;
|
|
|
|
}
|
|
|
|
if(t->intuple > 0) {
|
|
|
|
t1 = t->type->down->down;
|
|
|
|
if(t1->sym == S)
|
|
|
|
fatal("importfuncnam: no input");
|
|
|
|
n = newname(t1->sym);
|
|
|
|
vargen++;
|
|
|
|
n->vargen = vargen;
|
|
|
|
t1->nname = n;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
importaddtyp(Node *ss, Type *t)
|
|
|
|
{
|
|
|
|
Sym *s;
|
|
|
|
|
|
|
|
s = getimportsym(ss);
|
2008-09-26 18:41:23 -06:00
|
|
|
if(s->otype != T) {
|
|
|
|
// here we should try to discover if
|
|
|
|
// the new type is the same as the old type
|
|
|
|
if(eqtype(t, s->otype, 0))
|
|
|
|
return;
|
2008-09-26 22:27:26 -06:00
|
|
|
if(isptrto(t, TFORW)) {
|
2008-09-26 18:41:23 -06:00
|
|
|
return; // hard part
|
2008-09-26 22:27:26 -06:00
|
|
|
}
|
2008-09-26 18:41:23 -06:00
|
|
|
warn("redeclare import %S from %lT to %lT",
|
|
|
|
s, s->otype, t);
|
|
|
|
return;
|
2008-06-04 15:37:38 -06:00
|
|
|
}
|
2008-09-26 18:41:23 -06:00
|
|
|
addtyp(newtype(s), t, PEXTERN);
|
2008-06-04 15:37:38 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* LCONST importsym LITERAL
|
|
|
|
* untyped constant
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
doimportc1(Node *ss, Val *v)
|
|
|
|
{
|
|
|
|
Node *n;
|
|
|
|
Sym *s;
|
|
|
|
|
|
|
|
n = nod(OLITERAL, N, N);
|
|
|
|
n->val = *v;
|
|
|
|
|
|
|
|
s = getimportsym(ss);
|
|
|
|
if(s->oconst == N) {
|
|
|
|
// botch sould ask if already declared the same
|
|
|
|
dodclconst(newname(s), n);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* LCONST importsym importsym LITERAL
|
|
|
|
* typed constant
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
doimportc2(Node *ss, Node *st, Val *v)
|
|
|
|
{
|
|
|
|
Node *n;
|
|
|
|
Type *t;
|
|
|
|
Sym *s;
|
|
|
|
|
|
|
|
n = nod(OLITERAL, N, N);
|
|
|
|
n->val = *v;
|
|
|
|
|
|
|
|
t = importlooktype(st);
|
|
|
|
n->type = t;
|
|
|
|
|
|
|
|
s = getimportsym(ss);
|
|
|
|
if(s->oconst == N) {
|
|
|
|
// botch sould ask if already declared the same
|
|
|
|
dodclconst(newname(s), n);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* LVAR importsym importsym
|
|
|
|
* variable
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
doimportv1(Node *ss, Node *st)
|
|
|
|
{
|
|
|
|
Type *t;
|
|
|
|
Sym *s;
|
|
|
|
|
|
|
|
t = importlooktype(st);
|
|
|
|
s = getimportsym(ss);
|
|
|
|
if(s->oname == N || !eqtype(t, s->oname->type, 0)) {
|
|
|
|
addvar(newname(s), t, dclcontext);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* LTYPE importsym [ importsym ] importsym
|
|
|
|
* array type
|
|
|
|
*/
|
|
|
|
void
|
2008-06-15 21:24:30 -06:00
|
|
|
doimport1(Node *ss, Node *si, Node *st)
|
2008-06-04 15:37:38 -06:00
|
|
|
{
|
2008-06-15 21:24:30 -06:00
|
|
|
Type *t;
|
|
|
|
Sym *s;
|
|
|
|
|
|
|
|
t = typ(TMAP);
|
|
|
|
s = pkglookup(si->sym->name, si->psym->name);
|
|
|
|
t->down = s->otype;
|
|
|
|
s = pkglookup(st->sym->name, st->psym->name);
|
|
|
|
t->type = s->otype;
|
|
|
|
|
|
|
|
importaddtyp(ss, t);
|
2008-06-04 15:37:38 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* LTYPE importsym [ LLITERAL ] importsym
|
|
|
|
* array type
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
doimport2(Node *ss, Val *b, Node *st)
|
|
|
|
{
|
|
|
|
Type *t;
|
|
|
|
Sym *s;
|
|
|
|
|
2008-08-28 16:17:37 -06:00
|
|
|
t = typ(TARRAY);
|
|
|
|
t->bound = -1;
|
|
|
|
if(b != nil)
|
2008-08-27 18:28:30 -06:00
|
|
|
t->bound = mpgetfix(b->u.xval);
|
2008-06-04 15:37:38 -06:00
|
|
|
s = pkglookup(st->sym->name, st->psym->name);
|
|
|
|
t->type = s->otype;
|
|
|
|
|
|
|
|
importaddtyp(ss, t);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* LTYPE importsym '(' importsym_list ')'
|
|
|
|
* function/method type
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
doimport3(Node *ss, Node *n)
|
|
|
|
{
|
|
|
|
Type *t;
|
|
|
|
|
|
|
|
t = typ(TFUNC);
|
|
|
|
|
|
|
|
t->type = importlooktype(n->left);
|
|
|
|
t->type->down = importlooktype(n->right->left);
|
|
|
|
t->type->down->down = importlooktype(n->right->right);
|
|
|
|
|
|
|
|
t->thistuple = importcount(t->type);
|
|
|
|
t->outtuple = importcount(t->type->down);
|
|
|
|
t->intuple = importcount(t->type->down->down);
|
2008-08-08 18:13:31 -06:00
|
|
|
dowidth(t);
|
2008-06-04 15:37:38 -06:00
|
|
|
importfuncnam(t);
|
|
|
|
|
|
|
|
importaddtyp(ss, t);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* LTYPE importsym '{' importsym_list '}'
|
|
|
|
* structure type
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
doimport4(Node *ss, Node *n)
|
|
|
|
{
|
|
|
|
Type *t;
|
|
|
|
|
|
|
|
t = typ(TSTRUCT);
|
|
|
|
importstotype(n, &t->type, t);
|
2008-07-09 18:15:10 -06:00
|
|
|
dowidth(t);
|
2008-06-04 15:37:38 -06:00
|
|
|
|
|
|
|
importaddtyp(ss, t);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* LTYPE importsym LLITERAL
|
|
|
|
* basic type
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
doimport5(Node *ss, Val *v)
|
|
|
|
{
|
|
|
|
int et;
|
|
|
|
Type *t;
|
|
|
|
|
2008-08-08 18:13:31 -06:00
|
|
|
et = mpgetfix(v->u.xval);
|
2008-06-04 15:37:38 -06:00
|
|
|
if(et <= 0 || et >= nelem(types) || types[et] == T)
|
2008-07-27 14:09:15 -06:00
|
|
|
fatal("doimport5: bad type index: %E", et);
|
2008-06-04 15:37:38 -06:00
|
|
|
|
|
|
|
t = typ(et);
|
|
|
|
t->sym = S;
|
|
|
|
|
|
|
|
importaddtyp(ss, t);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* LTYPE importsym * importsym
|
|
|
|
* pointer type
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
doimport6(Node *ss, Node *st)
|
|
|
|
{
|
|
|
|
Type *t;
|
|
|
|
Sym *s;
|
|
|
|
|
|
|
|
s = pkglookup(st->sym->name, st->psym->name);
|
|
|
|
t = s->otype;
|
|
|
|
if(t == T)
|
|
|
|
t = forwdcl(s);
|
|
|
|
else
|
|
|
|
t = ptrto(t);
|
|
|
|
|
|
|
|
importaddtyp(ss, t);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* LTYPE importsym '<' importsym '>'
|
|
|
|
* interface type
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
doimport7(Node *ss, Node *n)
|
|
|
|
{
|
|
|
|
Type *t;
|
|
|
|
|
|
|
|
t = typ(TINTER);
|
|
|
|
importstotype(n, &t->type, t);
|
2008-07-09 18:15:10 -06:00
|
|
|
dowidth(t);
|
2008-06-04 15:37:38 -06:00
|
|
|
|
|
|
|
importaddtyp(ss, t);
|
|
|
|
}
|
2008-07-12 14:08:53 -06:00
|
|
|
|
|
|
|
/*
|
|
|
|
* LTYPE importsym chdir importsym
|
|
|
|
* interface type
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
doimport8(Node *ss, Val *v, Node *st)
|
|
|
|
{
|
|
|
|
Type *t;
|
|
|
|
Sym *s;
|
|
|
|
int dir;
|
|
|
|
|
|
|
|
s = pkglookup(st->sym->name, st->psym->name);
|
2008-08-08 18:13:31 -06:00
|
|
|
dir = mpgetfix(v->u.xval);
|
2008-07-12 14:08:53 -06:00
|
|
|
|
|
|
|
t = typ(TCHAN);
|
|
|
|
s = pkglookup(st->sym->name, st->psym->name);
|
|
|
|
t->type = s->otype;
|
|
|
|
t->chan = dir;
|
|
|
|
|
|
|
|
importaddtyp(ss, t);
|
|
|
|
}
|
2008-09-14 17:57:55 -06:00
|
|
|
|
|
|
|
/*
|
|
|
|
* LFUNC importsym sym
|
|
|
|
* method type
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
doimport9(Sym *sf, Node *ss)
|
|
|
|
{
|
|
|
|
Sym *sfun;
|
|
|
|
|
|
|
|
sfun = getimportsym(ss);
|
|
|
|
addmethod(newname(sf), sfun->otype, 0);
|
|
|
|
}
|