mirror of
https://github.com/golang/go
synced 2024-10-14 03:43:28 +00:00
better import/export
SVN=122584
This commit is contained in:
parent
67e141b637
commit
343f5aa7b4
|
@ -14,11 +14,13 @@ markexport(Node *n)
|
||||||
loop:
|
loop:
|
||||||
if(n == N)
|
if(n == N)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if(n->op == OLIST) {
|
if(n->op == OLIST) {
|
||||||
markexport(n->left);
|
markexport(n->left);
|
||||||
n = n->right;
|
n = n->right;
|
||||||
goto loop;
|
goto loop;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(n->op != OEXPORT)
|
if(n->op != OEXPORT)
|
||||||
fatal("markexport: op no OEXPORT: %O", n->op);
|
fatal("markexport: op no OEXPORT: %O", n->op);
|
||||||
|
|
||||||
|
@ -252,6 +254,8 @@ dumpexport(void)
|
||||||
Bprint(bout, " import\n");
|
Bprint(bout, " import\n");
|
||||||
Bprint(bout, " ((\n");
|
Bprint(bout, " ((\n");
|
||||||
|
|
||||||
|
Bprint(bout, " package %s\n", package);
|
||||||
|
|
||||||
// print it depth first
|
// print it depth first
|
||||||
for(d=exportlist->forw; d!=D; d=d->forw) {
|
for(d=exportlist->forw; d!=D; d=d->forw) {
|
||||||
dynlineno = d->lineno;
|
dynlineno = d->lineno;
|
||||||
|
@ -266,6 +270,19 @@ dumpexport(void)
|
||||||
/*
|
/*
|
||||||
* ******* import *******
|
* ******* import *******
|
||||||
*/
|
*/
|
||||||
|
void
|
||||||
|
renamepkg(Node *n)
|
||||||
|
{
|
||||||
|
if(n->psym == pkgimportname)
|
||||||
|
if(pkgmyname != S)
|
||||||
|
n->psym = pkgmyname;
|
||||||
|
|
||||||
|
if(n->psym->lexical != LPACK) {
|
||||||
|
warn("%S is becoming a package behind your back", n->psym);
|
||||||
|
n->psym->lexical = LPACK;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Sym*
|
Sym*
|
||||||
getimportsym(Node *ss)
|
getimportsym(Node *ss)
|
||||||
{
|
{
|
||||||
|
@ -276,9 +293,6 @@ getimportsym(Node *ss)
|
||||||
fatal("getimportsym: oops1 %N\n", ss);
|
fatal("getimportsym: oops1 %N\n", ss);
|
||||||
|
|
||||||
pkg = ss->psym->name;
|
pkg = ss->psym->name;
|
||||||
if(pkgmyname != S)
|
|
||||||
pkg = pkgmyname->name;
|
|
||||||
|
|
||||||
s = pkglookup(ss->sym->name, pkg);
|
s = pkglookup(ss->sym->name, pkg);
|
||||||
|
|
||||||
/* botch - need some diagnostic checking for the following assignment */
|
/* botch - need some diagnostic checking for the following assignment */
|
||||||
|
|
|
@ -333,6 +333,7 @@ EXTERN Sym* hash[NHASH];
|
||||||
EXTERN Sym* dclstack;
|
EXTERN Sym* dclstack;
|
||||||
EXTERN Sym* b0stack;
|
EXTERN Sym* b0stack;
|
||||||
EXTERN Sym* pkgmyname; // my name for package
|
EXTERN Sym* pkgmyname; // my name for package
|
||||||
|
EXTERN Sym* pkgimportname; // package name from imported package
|
||||||
EXTERN int tptr; // either TPTR32 or TPTR64
|
EXTERN int tptr; // either TPTR32 or TPTR64
|
||||||
extern char* sysimport;
|
extern char* sysimport;
|
||||||
|
|
||||||
|
@ -498,6 +499,7 @@ Type* forwdcl(Sym*);
|
||||||
/*
|
/*
|
||||||
* export.c
|
* export.c
|
||||||
*/
|
*/
|
||||||
|
void renamepkg(Node*);
|
||||||
void markexport(Node*);
|
void markexport(Node*);
|
||||||
void dumpe(Sym*);
|
void dumpe(Sym*);
|
||||||
void dumpexport(void);
|
void dumpexport(void);
|
||||||
|
|
|
@ -86,7 +86,7 @@ import:
|
||||||
| LIMPORT '(' import_stmt_list_r osemi ')'
|
| LIMPORT '(' import_stmt_list_r osemi ')'
|
||||||
|
|
||||||
import_stmt:
|
import_stmt:
|
||||||
import_here import_there
|
import_here import_package import_there
|
||||||
|
|
||||||
import_here:
|
import_here:
|
||||||
LLITERAL
|
LLITERAL
|
||||||
|
@ -109,6 +109,17 @@ import_here:
|
||||||
importfile(&$2);
|
importfile(&$2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
import_package:
|
||||||
|
LPACKAGE sym
|
||||||
|
{
|
||||||
|
pkgimportname = $2;
|
||||||
|
|
||||||
|
// if we are not remapping the package name
|
||||||
|
// then the imported package name is LPACK
|
||||||
|
if(pkgmyname == S)
|
||||||
|
pkgimportname->lexical = LPACK;
|
||||||
|
}
|
||||||
|
|
||||||
import_there:
|
import_there:
|
||||||
hidden_import_list_r ')' ')'
|
hidden_import_list_r ')' ')'
|
||||||
{
|
{
|
||||||
|
@ -1330,11 +1341,11 @@ hidden_import:
|
||||||
isym:
|
isym:
|
||||||
sym '.' sym
|
sym '.' sym
|
||||||
{
|
{
|
||||||
$1->lexical = LPACK;
|
|
||||||
$$ = nod(OIMPORT, N, N);
|
$$ = nod(OIMPORT, N, N);
|
||||||
$$->osym = $1;
|
$$->osym = $1;
|
||||||
$$->psym = $1;
|
$$->psym = $1;
|
||||||
$$->sym = $3;
|
$$->sym = $3;
|
||||||
|
renamepkg($$);
|
||||||
}
|
}
|
||||||
| '(' sym ')' sym '.' sym
|
| '(' sym ')' sym '.' sym
|
||||||
{
|
{
|
||||||
|
@ -1342,6 +1353,7 @@ isym:
|
||||||
$$->osym = $2;
|
$$->osym = $2;
|
||||||
$$->psym = $4;
|
$$->psym = $4;
|
||||||
$$->sym = $6;
|
$$->sym = $6;
|
||||||
|
renamepkg($$);
|
||||||
}
|
}
|
||||||
|
|
||||||
hidden_importsym:
|
hidden_importsym:
|
||||||
|
@ -1349,6 +1361,7 @@ hidden_importsym:
|
||||||
| '!' isym
|
| '!' isym
|
||||||
{
|
{
|
||||||
$$ = $2;
|
$$ = $2;
|
||||||
|
$$->etype = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
hidden_importfield:
|
hidden_importfield:
|
||||||
|
|
|
@ -868,6 +868,7 @@ static struct
|
||||||
"true", LTRUE, Txxx,
|
"true", LTRUE, Txxx,
|
||||||
"type", LTYPE, Txxx,
|
"type", LTYPE, Txxx,
|
||||||
"var", LVAR, Txxx,
|
"var", LVAR, Txxx,
|
||||||
|
"sys", LPACK, Txxx,
|
||||||
|
|
||||||
"notwithstanding", LIGNORE, Txxx,
|
"notwithstanding", LIGNORE, Txxx,
|
||||||
"thetruthofthematter", LIGNORE, Txxx,
|
"thetruthofthematter", LIGNORE, Txxx,
|
||||||
|
|
|
@ -871,7 +871,7 @@ Tconv(Fmt *fp)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case TMAP:
|
case TMAP:
|
||||||
snprint(buf, sizeof(buf), "[%T]%T", t->down, t->type);
|
snprint(buf, sizeof(buf), "MAP[%T]%T", t->down, t->type);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case TARRAY:
|
case TARRAY:
|
||||||
|
|
|
@ -18,7 +18,7 @@ func
|
||||||
close(da double, ia, ib int64, pow int) bool
|
close(da double, ia, ib int64, pow int) bool
|
||||||
{
|
{
|
||||||
db := double(ia) / double(ib);
|
db := double(ia) / double(ib);
|
||||||
db = db*pow10(pow);
|
db *= pow10(pow);
|
||||||
|
|
||||||
if da == 0 {
|
if da == 0 {
|
||||||
if db == 0 {
|
if db == 0 {
|
||||||
|
@ -27,17 +27,12 @@ close(da double, ia, ib int64, pow int) bool
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
dd := da-db;
|
de := (da-db) /da;
|
||||||
if dd < 0 {
|
|
||||||
dd = -dd;
|
|
||||||
}
|
|
||||||
|
|
||||||
de := da;
|
|
||||||
if de < 0 {
|
if de < 0 {
|
||||||
de = -de;
|
de = -de;
|
||||||
}
|
}
|
||||||
|
|
||||||
if de*1.0e-14 > dd {
|
if de < 1.0e-14 {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
|
Loading…
Reference in a new issue