1
0
mirror of https://github.com/golang/go synced 2024-11-12 01:50:22 -07:00

use _f007·filename for func literals.

this avoids problems people have run into with
multiple closures in the same package.

when preparing filename, only cut off .go, not .anything.
this fixes a bug tgs ran into with foo.pb.go and foo.go
in the same package.

also turn bad identifier chars from filename into
underscores: a-b.pb.go => a_b_pb

R=ken
OCL=27050
CL=27050
This commit is contained in:
Russ Cox 2009-04-02 18:32:57 -07:00
parent 9ef3d8e2e7
commit 416b27548e
2 changed files with 11 additions and 3 deletions

View File

@ -583,7 +583,7 @@ funclit1(Type *type, Node *body)
// declare function.
vargen++;
snprint(namebuf, sizeof(namebuf), "_f%.3ld", vargen);
snprint(namebuf, sizeof(namebuf), "_f%.3ld·%s", vargen, filename);
f = newname(lookup(namebuf));
addvar(f, ft, PFUNC);
f->funcdepth = 0;

View File

@ -138,15 +138,23 @@ void
setfilename(char *file)
{
char *p;
int c;
p = strrchr(file, '/');
if(p != nil)
file = p+1;
strncpy(namebuf, file, sizeof(namebuf));
p = strchr(namebuf, '.');
if(p != nil)
p = strrchr(namebuf, '.');
if(p != nil && strcmp(p, ".go") == 0)
*p = 0;
filename = strdup(namebuf);
// turn invalid identifier chars into _
for(p=filename; *p; p++) {
c = *p & 0xFF;
if(c < 0x80 && !isalpha(c) && !isdigit(c) && c != '_')
*p = '_';
}
}
int