Commit c249a8de authored by Russ Cox's avatar Russ Cox

rename various magic names.

	sigi and sigt:
	sys·sigi_inter -> sigi·inter
	sys·sigt_int -> sigt·int
	Package·sigt_Type -> sigt·Package.Type

	local type T in file x.go T_x -> T·x
	second one T_x_1 -> T·x·1

	method names M on T  T_M -> T·M

correctly handle local embedded types

init functions are the only place left that use underscores

R=ken
OCL=18377
CL=18377
parent 90e5574f
...@@ -516,6 +516,7 @@ gentramp(Type *t, Sig *b) ...@@ -516,6 +516,7 @@ gentramp(Type *t, Sig *b)
int c, d, o; int c, d, o;
Prog *p; Prog *p;
Type *f; Type *f;
Sym *msym;
e = lookup(b->name); e = lookup(b->name);
for(d=0; d<nelem(dotlist); d++) { for(d=0; d<nelem(dotlist); d++) {
...@@ -585,14 +586,12 @@ out: ...@@ -585,14 +586,12 @@ out:
f = dotlist[0].field; f = dotlist[0].field;
//JMP main·Sub_test2(SB) //JMP main·Sub_test2(SB)
snprint(namebuf, sizeof(namebuf), "%s_%s",
f->sym->name, b->name);
if(isptr[f->type->etype]) if(isptr[f->type->etype])
f = f->type; f = f->type;
p = pc; p = pc;
gins(AJMP, N, N); gins(AJMP, N, N);
p->to.type = D_EXTERN; p->to.type = D_EXTERN;
p->to.sym = pkglookup(namebuf, f->type->sym->opackage); p->to.sym = methodsym(lookup(b->name), f->type);
//print("6. %P\n", p); //print("6. %P\n", p);
} }
...@@ -661,9 +660,7 @@ dumpsigt(void) ...@@ -661,9 +660,7 @@ dumpsigt(void)
a->name = s1->name; a->name = s1->name;
a->hash = PRIME8*stringhash(a->name) + PRIME9*typehash(f->type, 0); a->hash = PRIME8*stringhash(a->name) + PRIME9*typehash(f->type, 0);
a->perm = o; a->perm = o;
snprint(namebuf, sizeof(namebuf), "%s_%s", a->sym = methodsym(f->sym, t);
at.sym->name+5, f->sym->name);
a->sym = lookup(namebuf);
a->offset = f->embedded; // need trampoline a->offset = f->embedded; // need trampoline
o++; o++;
...@@ -813,9 +810,7 @@ dumpsigi(void) ...@@ -813,9 +810,7 @@ dumpsigi(void)
a->hash = PRIME8*stringhash(a->name) + PRIME9*typehash(f->type, 0); a->hash = PRIME8*stringhash(a->name) + PRIME9*typehash(f->type, 0);
a->perm = o; a->perm = o;
snprint(namebuf, sizeof(namebuf), "%s_%s", a->sym = methodsym(f->sym, t);
at.sym->name+5, f->sym->name);
a->sym = lookup(namebuf);
a->offset = 0; a->offset = 0;
o++; o++;
......
...@@ -200,8 +200,8 @@ methcmp(Type *t1, Type *t2) ...@@ -200,8 +200,8 @@ methcmp(Type *t1, Type *t2)
return 1; return 1;
} }
Node* Sym*
methodname(Node *n, Type *t) methodsym(Sym *nsym, Type *t)
{ {
Sym *s; Sym *s;
char buf[NSYMB]; char buf[NSYMB];
...@@ -213,12 +213,24 @@ methodname(Node *n, Type *t) ...@@ -213,12 +213,24 @@ methodname(Node *n, Type *t)
if(s == S) if(s == S)
goto bad; goto bad;
snprint(buf, sizeof(buf), "%s_%s", s->name, n->sym->name); snprint(buf, sizeof(buf), "%#hT·%s", t, nsym->name);
return newname(pkglookup(buf, s->opackage)); //print("methodname %s\n", buf);
return pkglookup(buf, s->opackage);
bad: bad:
yyerror("illegal <this> type: %T", t); yyerror("illegal <this> type: %T", t);
return n; return S;
}
Node*
methodname(Node *n, Type *t)
{
Sym *s;
s = methodsym(n->sym, t);
if(s == S)
return n;
return newname(s);
} }
/* /*
...@@ -449,7 +461,6 @@ stotype(Node *n, Type **t) ...@@ -449,7 +461,6 @@ stotype(Node *n, Type **t)
{ {
Type *f; Type *f;
Iter save; Iter save;
char buf[100];
String *note; String *note;
n = listfirst(&save, &n); n = listfirst(&save, &n);
...@@ -740,7 +751,6 @@ addtyp(Type *n, int ctxt) ...@@ -740,7 +751,6 @@ addtyp(Type *n, int ctxt)
{ {
Dcl *r, *d; Dcl *r, *d;
Sym *s; Sym *s;
char *p;
static int typgen; static int typgen;
if(n==T || n->sym == S) if(n==T || n->sym == S)
...@@ -753,9 +763,7 @@ addtyp(Type *n, int ctxt) ...@@ -753,9 +763,7 @@ addtyp(Type *n, int ctxt)
else { else {
r = autodcl; r = autodcl;
pushdcl(s); pushdcl(s);
p = smprint("%s_%d", s->name, ++typgen); n->vargen = ++typgen;
n->xsym = lookup(p);
free(p);
} }
if(s->tblock == block) if(s->tblock == block)
...@@ -1168,8 +1176,19 @@ Node* ...@@ -1168,8 +1176,19 @@ Node*
embedded(Sym *s) embedded(Sym *s)
{ {
Node *n; Node *n;
char *name;
// Names sometimes have disambiguation junk
// appended after a center dot. Discard it when
// making the name for the embedded struct field.
enum { CenterDot = 0xB7 };
name = s->name;
if(utfrune(s->name, CenterDot)) {
name = strdup(s->name);
*utfrune(name, CenterDot) = 0;
}
n = newname(lookup(s->name)); n = newname(lookup(name));
n = nod(ODCLFIELD, n, N); n = nod(ODCLFIELD, n, N);
n->embedded = 1; n->embedded = 1;
if(s == S) if(s == S)
......
...@@ -135,7 +135,6 @@ struct Type ...@@ -135,7 +135,6 @@ struct Type
Type* method; Type* method;
Sym* sym; Sym* sym;
Sym* xsym; // export sym
int32 vargen; // unique name for OTYPE/ONAME int32 vargen; // unique name for OTYPE/ONAME
Node* nname; Node* nname;
...@@ -190,7 +189,6 @@ struct Node ...@@ -190,7 +189,6 @@ struct Node
Val val; Val val;
Sym* osym; // import Sym* osym; // import
Sym* fsym; // import
Sym* psym; // import Sym* psym; // import
Sym* sym; // various Sym* sym; // various
int32 vargen; // unique name for OTYPE/ONAME int32 vargen; // unique name for OTYPE/ONAME
...@@ -665,6 +663,7 @@ void defaultlit(Node*); ...@@ -665,6 +663,7 @@ void defaultlit(Node*);
int listcount(Node*); int listcount(Node*);
void addmethod(Node*, Type*, int); void addmethod(Node*, Type*, int);
Node* methodname(Node*, Type*); Node* methodname(Node*, Type*);
Sym* methodsym(Sym*, Type*);
Type* functype(Node*, Node*, Node*); Type* functype(Node*, Node*, Node*);
char* thistypenam(Node*); char* thistypenam(Node*);
void funcnam(Type*, char*); void funcnam(Type*, char*);
......
...@@ -984,12 +984,17 @@ Tpretty(Fmt *fp, Type *t) ...@@ -984,12 +984,17 @@ Tpretty(Fmt *fp, Type *t)
if(t == types[t->etype] || t == types[TSTRING]) if(t == types[t->etype] || t == types[TSTRING])
return fmtprint(fp, "%s", s->name); return fmtprint(fp, "%s", s->name);
if(exporting) { if(exporting) {
if(t->xsym != S) if(fp->flags & FmtShort)
s = t->xsym; fmtprint(fp, "%hS", s);
else
fmtprint(fp, "%lS", s);
if(strcmp(s->opackage, package) == 0) if(strcmp(s->opackage, package) == 0)
if(s->otype != t || !s->export) if(s->otype != t || !s->export) {
return fmtprint(fp, "%lS_%s", s, filename); fmtprint(fp, "·%s", filename);
return fmtprint(fp, "%lS", s); if(t->vargen)
fmtprint(fp, "·%d", t->vargen);
}
return 0;
} }
return fmtprint(fp, "%S", s); return fmtprint(fp, "%S", s);
} }
...@@ -1606,12 +1611,11 @@ globalsig(Type *t) ...@@ -1606,12 +1611,11 @@ globalsig(Type *t)
int et; int et;
Sym *s; Sym *s;
char buf[NSYMB]; char buf[NSYMB];
char *glob; char *sigx;
if(t == T) if(t == T)
return S; return S;
glob = "sys";
et = t->etype; et = t->etype;
switch(et) { switch(et) {
default: default:
...@@ -1620,7 +1624,8 @@ globalsig(Type *t) ...@@ -1620,7 +1624,8 @@ globalsig(Type *t)
case TINTER: case TINTER:
case TDDD: case TDDD:
if(isnilinter(t)) { if(isnilinter(t)) {
snprint(buf, sizeof(buf), "%s_%s", "sigi", "inter"); sigx = "sigi";
strcpy(buf, "inter");
goto out; goto out;
} }
return S; return S;
...@@ -1660,10 +1665,11 @@ globalsig(Type *t) ...@@ -1660,10 +1665,11 @@ globalsig(Type *t)
return S; return S;
if(strcmp(t->sym->name, types[et]->sym->name) != 0) if(strcmp(t->sym->name, types[et]->sym->name) != 0)
return S; return S;
snprint(buf, sizeof(buf), "%s_%S", "sigt", t->sym); sigx = "sigt";
snprint(buf, sizeof(buf), "%#T", t);
out: out:
s = pkglookup(buf, glob); s = pkglookup(buf, sigx);
if(s->oname == N) { if(s->oname == N) {
s->oname = newname(s); s->oname = newname(s);
s->oname->type = types[TUINT8]; s->oname->type = types[TUINT8];
...@@ -1709,8 +1715,6 @@ signame(Type *t, int block) ...@@ -1709,8 +1715,6 @@ signame(Type *t, int block)
block = s->tblock; block = s->tblock;
if(block > 1) { if(block > 1) {
snprint(buf, sizeof(buf), "%s_%d%s", e, block, s->name);
// record internal type for signature generation // record internal type for signature generation
x = mal(sizeof(*x)); x = mal(sizeof(*x));
x->op = OTYPE; x->op = OTYPE;
...@@ -1719,10 +1723,9 @@ signame(Type *t, int block) ...@@ -1719,10 +1723,9 @@ signame(Type *t, int block)
x->forw = signatlist; x->forw = signatlist;
x->block = block; x->block = block;
signatlist = x; signatlist = x;
} else }
snprint(buf, sizeof(buf), "%s_%s", e, s->name); snprint(buf, sizeof(buf), "%#T", t);
ss = pkglookup(buf, e);
ss = pkglookup(buf, s->opackage);
if(ss->oname == N) { if(ss->oname == N) {
ss->oname = newname(ss); ss->oname = newname(ss);
ss->oname->type = types[TUINT8]; ss->oname->type = types[TUINT8];
...@@ -2494,7 +2497,6 @@ adddot(Node *n) ...@@ -2494,7 +2497,6 @@ adddot(Node *n)
{ {
Type *t; Type *t;
Sym *s; Sym *s;
Node *l;
int c, d; int c, d;
walktype(n->left, Erv); walktype(n->left, Erv);
......
...@@ -47,29 +47,29 @@ static Map* hash[1009]; ...@@ -47,29 +47,29 @@ static Map* hash[1009];
#define END nil,0,0,nil #define END nil,0,0,nil
Sigi sys·sigi_inter[2] = { (byte*)"interface {}", 0, 0, nil, 0, 0 }; Sigi sigi·inter[2] = { (byte*)"interface {}", 0, 0, nil, 0, 0 };
Sigt sys·sigt_int8[2] = { (byte*)"int8", ASIMP, 1, nil, END }; Sigt sigt·int8[2] = { (byte*)"int8", ASIMP, 1, nil, END };
Sigt sys·sigt_int16[2] = { (byte*)"int16", ASIMP, 2, nil, END }; Sigt sigt·int16[2] = { (byte*)"int16", ASIMP, 2, nil, END };
Sigt sys·sigt_int32[2] = { (byte*)"int32", ASIMP, 4, nil, END }; Sigt sigt·int32[2] = { (byte*)"int32", ASIMP, 4, nil, END };
Sigt sys·sigt_int64[2] = { (byte*)"int64", ASIMP, 8, nil, END }; Sigt sigt·int64[2] = { (byte*)"int64", ASIMP, 8, nil, END };
Sigt sys·sigt_uint8[2] = { (byte*)"uint8", ASIMP, 1, nil, END }; Sigt sigt·uint8[2] = { (byte*)"uint8", ASIMP, 1, nil, END };
Sigt sys·sigt_uint16[2] = { (byte*)"uint16", ASIMP, 2, nil, END }; Sigt sigt·uint16[2] = { (byte*)"uint16", ASIMP, 2, nil, END };
Sigt sys·sigt_uint32[2] = { (byte*)"uint32", ASIMP, 4, nil, END }; Sigt sigt·uint32[2] = { (byte*)"uint32", ASIMP, 4, nil, END };
Sigt sys·sigt_uint64[2] = { (byte*)"uint64", ASIMP, 8, nil, END }; Sigt sigt·uint64[2] = { (byte*)"uint64", ASIMP, 8, nil, END };
Sigt sys·sigt_float32[2] = { (byte*)"float32", ASIMP, 4, nil, END }; Sigt sigt·float32[2] = { (byte*)"float32", ASIMP, 4, nil, END };
Sigt sys·sigt_float64[2] = { (byte*)"float64", ASIMP, 8, nil, END }; Sigt sigt·float64[2] = { (byte*)"float64", ASIMP, 8, nil, END };
//Sigt sys·sigt_float80[2] = { (byte*)"float80", ASIMP, 0, nil, END }; //Sigt sigt·float80[2] = { (byte*)"float80", ASIMP, 0, nil, END };
Sigt sys·sigt_bool[2] = { (byte*)"bool", ASIMP, 1, nil, END }; Sigt sigt·bool[2] = { (byte*)"bool", ASIMP, 1, nil, END };
Sigt sys·sigt_string[2] = { (byte*)"string", ASTRING, 8, nil, END }; Sigt sigt·string[2] = { (byte*)"string", ASTRING, 8, nil, END };
Sigt sys·sigt_int[2] = { (byte*)"int", ASIMP, 4, nil, END }; Sigt sigt·int[2] = { (byte*)"int", ASIMP, 4, nil, END };
Sigt sys·sigt_uint[2] = { (byte*)"uint", ASIMP, 4, nil, END }; Sigt sigt·uint[2] = { (byte*)"uint", ASIMP, 4, nil, END };
Sigt sys·sigt_uintptr[2] = { (byte*)"uintptr", ASIMP, 8, nil, END }; Sigt sigt·uintptr[2] = { (byte*)"uintptr", ASIMP, 8, nil, END };
Sigt sys·sigt_float[2] = { (byte*)"float", ASIMP, 4, nil, END }; Sigt sigt·float[2] = { (byte*)"float", ASIMP, 4, nil, END };
static void static void
printsigi(Sigi *si) printsigi(Sigi *si)
......
...@@ -22,7 +22,7 @@ errchk: ./convlit.go: unmatched error messages: ...@@ -22,7 +22,7 @@ errchk: ./convlit.go: unmatched error messages:
hello, world hello, world
=========== ./interface2.go =========== ./interface2.go
cannot convert type *main.S_interface2 to interface main.I_interface2: missing method Foo cannot convert type *main.S·interface2 to interface main.I·interface2: missing method Foo
throw: interface conversion throw: interface conversion
SIGSEGV: segmentation violation SIGSEGV: segmentation violation
Faulting address: 0x0 Faulting address: 0x0
...@@ -30,7 +30,7 @@ pc: xxx ...@@ -30,7 +30,7 @@ pc: xxx
=========== ./interface3.go =========== ./interface3.go
cannot convert type *main.S_interface3 to interface main.I2_interface3: missing method Name cannot convert type *main.S·interface3 to interface main.I2·interface3: missing method Name
throw: interface conversion throw: interface conversion
SIGSEGV: segmentation violation SIGSEGV: segmentation violation
Faulting address: 0x0 Faulting address: 0x0
......
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