]> Cypherpunks repositories - gostls13.git/commitdiff
better import/export
authorKen Thompson <ken@golang.org>
Fri, 13 Jun 2008 04:48:56 +0000 (21:48 -0700)
committerKen Thompson <ken@golang.org>
Fri, 13 Jun 2008 04:48:56 +0000 (21:48 -0700)
SVN=122584

src/cmd/gc/export.c
src/cmd/gc/go.h
src/cmd/gc/go.y
src/cmd/gc/lex.c
src/cmd/gc/subr.c
test/float_lit.go

index b1ddfea625479055dd2039006965f8a8b3b7ef14..4904855770091618dc4f9ed39b585da6e9d4a618 100644 (file)
@@ -14,11 +14,13 @@ markexport(Node *n)
 loop:
        if(n == N)
                return;
+
        if(n->op == OLIST) {
                markexport(n->left);
                n = n->right;
                goto loop;
        }
+
        if(n->op != OEXPORT)
                fatal("markexport: op no OEXPORT: %O", n->op);
 
@@ -252,6 +254,8 @@ dumpexport(void)
        Bprint(bout, "   import\n");
        Bprint(bout, "   ((\n");
 
+       Bprint(bout, "    package %s\n", package);
+
        // print it depth first
        for(d=exportlist->forw; d!=D; d=d->forw) {
                dynlineno = d->lineno;
@@ -266,6 +270,19 @@ dumpexport(void)
 /*
  * ******* 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*
 getimportsym(Node *ss)
 {
@@ -276,9 +293,6 @@ getimportsym(Node *ss)
                fatal("getimportsym: oops1 %N\n", ss);
 
        pkg = ss->psym->name;
-       if(pkgmyname != S)
-               pkg = pkgmyname->name;
-
        s = pkglookup(ss->sym->name, pkg);
 
        /* botch - need some diagnostic checking for the following assignment */
index 3ccefa8484716922fc4d7abe1ed9ab58193e35fa..5c65a0139b9716a0ada7a426e411cf16e895ddb4 100644 (file)
@@ -333,6 +333,7 @@ EXTERN      Sym*    hash[NHASH];
 EXTERN Sym*    dclstack;
 EXTERN Sym*    b0stack;
 EXTERN Sym*    pkgmyname;      // my name for package
+EXTERN Sym*    pkgimportname;  // package name from imported package
 EXTERN int     tptr;           // either TPTR32 or TPTR64
 extern char*   sysimport;
 
@@ -498,6 +499,7 @@ Type*       forwdcl(Sym*);
 /*
  *     export.c
  */
+void   renamepkg(Node*);
 void   markexport(Node*);
 void   dumpe(Sym*);
 void   dumpexport(void);
index ce7c89a810d129c1d93316002e43a2dc5507a3af..c20606300901b4746c340d80771188d53e2db789 100644 (file)
@@ -86,7 +86,7 @@ import:
 |      LIMPORT '(' import_stmt_list_r osemi ')'
 
 import_stmt:
-       import_here import_there
+       import_here import_package import_there
 
 import_here:
        LLITERAL
@@ -109,6 +109,17 @@ import_here:
                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:
        hidden_import_list_r ')' ')'
        {
@@ -1330,11 +1341,11 @@ hidden_import:
 isym:
        sym '.' sym
        {
-               $1->lexical = LPACK;
                $$ = nod(OIMPORT, N, N);
                $$->osym = $1;
                $$->psym = $1;
                $$->sym = $3;
+               renamepkg($$);
        }
 |      '(' sym ')' sym '.' sym
        {
@@ -1342,6 +1353,7 @@ isym:
                $$->osym = $2;
                $$->psym = $4;
                $$->sym = $6;
+               renamepkg($$);
        }
 
 hidden_importsym:
@@ -1349,6 +1361,7 @@ hidden_importsym:
 |      '!' isym
        {
                $$ = $2;
+               $$->etype = 1;
        }
 
 hidden_importfield:
index 96380c647b2e8a9f87bf5bca86f7261691c602ec..03b7b859272f0b7295f57b43cb103fa52f39d856 100644 (file)
@@ -868,6 +868,7 @@ static      struct
        "true",         LTRUE,          Txxx,
        "type",         LTYPE,          Txxx,
        "var",          LVAR,           Txxx,
+       "sys",          LPACK,          Txxx,
 
        "notwithstanding",              LIGNORE,        Txxx,
        "thetruthofthematter",          LIGNORE,        Txxx,
index efbef36c43c6f4cb21c82da7b03f5d0cc0abb9fb..919589ac48da50a6345d0c7cc5cec05626df05a8 100644 (file)
@@ -871,7 +871,7 @@ Tconv(Fmt *fp)
                break;
 
        case TMAP:
-               snprint(buf, sizeof(buf), "[%T]%T", t->down, t->type);
+               snprint(buf, sizeof(buf), "MAP[%T]%T", t->down, t->type);
                break;
 
        case TARRAY:
index b43ae58ccf5670eabed641dd847f8e1d74f8189c..e5e95e68eb470a7397afc321b04bdf5a0f9598f6 100644 (file)
@@ -18,7 +18,7 @@ func
 close(da double, ia, ib int64, pow int) bool
 {
        db := double(ia) / double(ib);
-       db = db*pow10(pow);
+       db *= pow10(pow);
 
        if da == 0 {
                if db == 0 {
@@ -27,17 +27,12 @@ close(da double, ia, ib int64, pow int) bool
                return false;
        }
 
-       dd := da-db;
-       if dd < 0 {
-               dd = -dd;
-       }
-
-       de := da;
+       de := (da-db) /da;
        if de < 0 {
                de = -de;
        }
 
-       if de*1.0e-14 > dd {
+       if de < 1.0e-14 {
                return true;
        }
        return false;