]> Cypherpunks repositories - gostls13.git/commitdiff
eliminate package global name space
authorRuss Cox <rsc@golang.org>
Tue, 26 Jan 2010 02:31:35 +0000 (18:31 -0800)
committerRuss Cox <rsc@golang.org>
Tue, 26 Jan 2010 02:31:35 +0000 (18:31 -0800)
R=ken2
CC=golang-dev
https://golang.org/cl/194071

src/cmd/gc/go.y
src/cmd/gc/lex.c
src/cmd/ld/go.c

index 4f7c5db34ee69b7d06e54a9e896560d09dd37858..d73311fff5d852c1f9ac8f70415b3d5a6a0879b1 100644 (file)
@@ -237,14 +237,13 @@ import_package:
                importpkg->name = $2->name;
                importpkg->direct = 1;
 
-               // PGNS: fixme
+               // NOTE(rsc): This is no longer a technical restriction:
+               // the 6g tool chain would work just fine without giving
+               // special meaning to a package being named main.
+               // Other implementations might need the restriction
+               // (gccgo does), so it stays in the language and the compiler.
                if(strcmp($2->name, "main") == 0)
                        yyerror("cannot import package main");
-
-               // PGNS: This should go away once we get
-               // rid of the global package name space.
-               if(localpkg->name && strcmp($2->name, localpkg->name) == 0 && !compiling_runtime)
-                       yyerror("package cannot import itself");
        }
 
 import_there:
index bf86df5b82fecd7c4fcd4b6ebada9ce5834e0bd1..7e2896822e32c4787018fad126db536ecb99fce0 100644 (file)
@@ -285,9 +285,7 @@ importfile(Val *f, int line)
        Strlit *path;
        char cleanbuf[1024];
 
-       // TODO(rsc): don't bother reloading imports more than once
-
-       // PGNS: canonicalize import path for ./ imports in findpkg.
+       // TODO(rsc): don't bother reloading imports more than once?
 
        if(f->ctype != CTSTR) {
                yyerror("import statement not a string");
index 1797f34d3028931ea8b768f4d89f130737ede3c3..4385e463ff86a1699b192daec73ef72160b84529 100644 (file)
@@ -73,7 +73,7 @@ static int parsepkgdata(char*, char*, char**, char*, char**, char**, char**);
 void
 ldpkg(Biobuf *f, char *pkg, int64 len, char *filename)
 {
-       char *data, *p0, *p1;
+       char *data, *p0, *p1, *name;
 
        if(debug['g'])
                return;
@@ -111,10 +111,18 @@ ldpkg(Biobuf *f, char *pkg, int64 len, char *filename)
                        return;
                }
                p0 += 8;
-               while(*p0 == ' ' || *p0 == '\t' || *p0 == '\n')
+               while(p0 < p1 && *p0 == ' ' || *p0 == '\t' || *p0 == '\n')
                        p0++;
-               while(*p0 != ' ' && *p0 != '\t' && *p0 != '\n')
+               name = p0;
+               while(p0 < p1 && *p0 != ' ' && *p0 != '\t' && *p0 != '\n')
                        p0++;
+               if(p0 < p1) {
+                       *p0++ = '\0';
+                       if(strcmp(pkg, "main") == 0 && strcmp(name, "main") != 0)
+                               fprint(2, "%s: %s: not package main (package %s)\n", argv0, filename, name);
+                       else if(strcmp(pkg, "main") != 0 && strcmp(name, "main") == 0)
+                               fprint(2, "%s: %s: importing %s, found package main", argv0, filename, pkg);
+               }
                loadpkgdata(filename, pkg, p0, p1 - p0);
        }
 
@@ -131,7 +139,6 @@ ldpkg(Biobuf *f, char *pkg, int64 len, char *filename)
                return;
        }
 
-       // PGNS: Should be using import path, not pkg.
        loadpkgdata(filename, pkg, p0, p1 - p0);
 
        // look for dynld section