1
0
mirror of https://github.com/golang/go synced 2024-11-25 03:07:56 -07:00

eliminate package global name space

R=ken2
CC=golang-dev
https://golang.org/cl/194071
This commit is contained in:
Russ Cox 2010-01-25 18:31:35 -08:00
parent 1912632019
commit 531e6b77c8
3 changed files with 17 additions and 13 deletions

View 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:

View 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");

View 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