Commit 416b2754 authored by Russ Cox's avatar Russ Cox

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
parent 9ef3d8e2
...@@ -583,7 +583,7 @@ funclit1(Type *type, Node *body) ...@@ -583,7 +583,7 @@ funclit1(Type *type, Node *body)
// declare function. // declare function.
vargen++; vargen++;
snprint(namebuf, sizeof(namebuf), "_f%.3ld", vargen); snprint(namebuf, sizeof(namebuf), "_f%.3ld·%s", vargen, filename);
f = newname(lookup(namebuf)); f = newname(lookup(namebuf));
addvar(f, ft, PFUNC); addvar(f, ft, PFUNC);
f->funcdepth = 0; f->funcdepth = 0;
......
...@@ -138,15 +138,23 @@ void ...@@ -138,15 +138,23 @@ void
setfilename(char *file) setfilename(char *file)
{ {
char *p; char *p;
int c;
p = strrchr(file, '/'); p = strrchr(file, '/');
if(p != nil) if(p != nil)
file = p+1; file = p+1;
strncpy(namebuf, file, sizeof(namebuf)); strncpy(namebuf, file, sizeof(namebuf));
p = strchr(namebuf, '.'); p = strrchr(namebuf, '.');
if(p != nil) if(p != nil && strcmp(p, ".go") == 0)
*p = 0; *p = 0;
filename = strdup(namebuf); 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 int
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment