]> Cypherpunks repositories - gostls13.git/commitdiff
use _f007·filename for func literals.
authorRuss Cox <rsc@golang.org>
Fri, 3 Apr 2009 01:32:57 +0000 (18:32 -0700)
committerRuss Cox <rsc@golang.org>
Fri, 3 Apr 2009 01:32:57 +0000 (18:32 -0700)
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

src/cmd/gc/dcl.c
src/cmd/gc/lex.c

index 2e467249bb0b664bd4991345aaa5f6661816537c..51c76be752dc6f898ed5dc7446e1d6322564d74c 100644 (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;
index 3477a2cffc9f2a0a2f7880f5df0eb49470554a76..4e577a63c846c0e7c06dfcbf3a8d53dddb1b0942 100644 (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