6g cleanup suggested by ken.
remove TPTR wrapper around TMAP, TCHAN, TSTRING.
R=ken
OCL=22406
CL=22409
diff --git a/src/cmd/gc/const.c b/src/cmd/gc/const.c
index eefc277..8552812 100644
--- a/src/cmd/gc/const.c
+++ b/src/cmd/gc/const.c
@@ -61,8 +61,6 @@
goto bad1;
case Wlitnil:
- if(isptrto(t, TSTRING))
- goto bad1;
switch(et) {
default:
goto bad1;
@@ -71,6 +69,8 @@
case TPTR64:
case TINTER:
case TARRAY:
+ case TMAP:
+ case TCHAN:
break;
}
break;
@@ -80,7 +80,7 @@
defaultlit(n);
return;
}
- if(isptrto(t, TSTRING))
+ if(et == TSTRING)
break;
goto bad1;
@@ -127,7 +127,7 @@
goto bad1;
// only done as string(CONST)
- if(isptrto(t, TSTRING)) {
+ if(et == TSTRING) {
Rune rune;
int l;
String *s;
@@ -180,7 +180,7 @@
goto bad1;
}
n->type = t;
-
+
return;
bad1:
diff --git a/src/cmd/gc/dcl.c b/src/cmd/gc/dcl.c
index 38174b8..162495e 100644
--- a/src/cmd/gc/dcl.c
+++ b/src/cmd/gc/dcl.c
@@ -495,14 +495,6 @@
if(n->op != ODCLFIELD || n->type == T)
fatal("stotype: oops %N\n", n);
- switch(n->type->etype) {
- case TCHAN:
- case TMAP:
- case TSTRING:
- yyerror("%T can exist only in pointer form", n->type);
- break;
- }
-
switch(n->val.ctype) {
case CTSTR:
note = n->val.u.sval;
@@ -749,15 +741,6 @@
pushdcl(s);
}
- if(t != T) {
- switch(t->etype) {
- case TCHAN:
- case TMAP:
- case TSTRING:
- yyerror("%T can exist only in pointer form", t);
- }
- }
-
redeclare("variable", s);
s->vargen = gen;
s->oname = n;
diff --git a/src/cmd/gc/export.c b/src/cmd/gc/export.c
index de5f990..7b9fce6 100644
--- a/src/cmd/gc/export.c
+++ b/src/cmd/gc/export.c
@@ -59,7 +59,7 @@
if(t == T)
return;
- if(t->printed || t == types[t->etype] || t == types[TSTRING])
+ if(t->printed || t == types[t->etype])
return;
t->printed = 1;
diff --git a/src/cmd/gc/go.h b/src/cmd/gc/go.h
index da4f871..a46e76a 100644
--- a/src/cmd/gc/go.h
+++ b/src/cmd/gc/go.h
@@ -626,6 +626,7 @@
Type* aindex(Node*, Type*);
int isnil(Node*);
int isptrto(Type*, int);
+int istype(Type*, int);
int isptrsarray(Type*);
int isptrdarray(Type*);
int issarray(Type*);
diff --git a/src/cmd/gc/go.y b/src/cmd/gc/go.y
index 313d480..db12ee0 100644
--- a/src/cmd/gc/go.y
+++ b/src/cmd/gc/go.y
@@ -1031,7 +1031,6 @@
$$ = typ(TMAP);
$$->down = $3;
$$->type = $5;
- $$ = ptrto($$);
}
| structtype
@@ -1116,21 +1115,18 @@
$$ = typ(TCHAN);
$$->type = $3;
$$->chan = Crecv;
- $$ = ptrto($$);
}
| LCHAN LCOMM Anon_chan_type
{
$$ = typ(TCHAN);
$$->type = $3;
$$->chan = Csend;
- $$ = ptrto($$);
}
| LMAP '[' type ']' Atype
{
$$ = typ(TMAP);
$$->down = $3;
$$->type = $5;
- $$ = ptrto($$);
}
| '*' Atype
{
@@ -1153,21 +1149,18 @@
$$ = typ(TCHAN);
$$->type = $3;
$$->chan = Crecv;
- $$ = ptrto($$);
}
| LCHAN LCOMM Bnon_chan_type
{
$$ = typ(TCHAN);
$$->type = $3;
$$->chan = Csend;
- $$ = ptrto($$);
}
| LMAP '[' type ']' Btype
{
$$ = typ(TMAP);
$$->down = $3;
$$->type = $5;
- $$ = ptrto($$);
}
| '*' Btype
{
@@ -1184,7 +1177,6 @@
$$ = typ(TCHAN);
$$->type = $2;
$$->chan = Cboth;
- $$ = ptrto($$);
}
Bchantype:
@@ -1193,7 +1185,6 @@
$$ = typ(TCHAN);
$$->type = $2;
$$->chan = Cboth;
- $$ = ptrto($$);
}
structtype:
@@ -1865,7 +1856,6 @@
$$ = typ(TMAP);
$$->down = $3;
$$->type = $5;
- $$ = ptrto($$);
}
| LSTRUCT '{' ohidden_structdcl_list '}'
{
@@ -1886,14 +1876,12 @@
$$ = typ(TCHAN);
$$->type = $3;
$$->chan = Crecv;
- $$ = ptrto($$);
}
| LCHAN LCOMM hidden_type1
{
$$ = typ(TCHAN);
$$->type = $3;
$$->chan = Csend;
- $$ = ptrto($$);
}
| LDDD
{
@@ -1906,7 +1894,6 @@
$$ = typ(TCHAN);
$$->type = $2;
$$->chan = Cboth;
- $$ = ptrto($$);
}
| '(' ohidden_funarg_list ')' ohidden_funres
{
diff --git a/src/cmd/gc/lex.c b/src/cmd/gc/lex.c
index a98164e..c3a6511 100644
--- a/src/cmd/gc/lex.c
+++ b/src/cmd/gc/lex.c
@@ -1150,6 +1150,8 @@
case TPTR32:
case TPTR64:
case TINTER:
+ case TMAP:
+ case TCHAN:
okforeq[i] = 1;
break;
}
@@ -1196,8 +1198,6 @@
continue;
}
t = typ(etype);
- if(etype == TSTRING)
- t = ptrto(t);
t->sym = s;
dowidth(t);
diff --git a/src/cmd/gc/subr.c b/src/cmd/gc/subr.c
index ac79087..98127e2 100644
--- a/src/cmd/gc/subr.c
+++ b/src/cmd/gc/subr.c
@@ -295,10 +295,10 @@
if(issimple[t->etype])
a = ASIMP; // simple mem
else
- if(isptrto(t, TSTRING))
+ if(t->etype == TSTRING)
a = ASTRING; // string
else
- if(isptr[t->etype])
+ if(isptr[simtype[t->etype]])
a = APTR; // pointer
else
if(t->etype == TARRAY && t->bound < 0)
@@ -608,12 +608,8 @@
return Wtfloat;
case TBOOL:
return Wtbool;
-
- case TPTR32:
- case TPTR64:
- if(isptrto(t, TSTRING))
- return Wtstr;
- break;
+ case TSTRING:
+ return Wtstr;
}
return Wtunkn;
}
@@ -976,6 +972,7 @@
[TBOOL] = "bool",
[TANY] = "any",
[TDDD] = "...",
+ [TSTRING] = "string",
};
int
@@ -988,7 +985,7 @@
&& t->sym != S
&& !(fp->flags&FmtLong)) {
s = t->sym;
- if(t == types[t->etype] || t == types[TSTRING])
+ if(t == types[t->etype])
return fmtprint(fp, "%s", s->name);
if(exporting) {
if(fp->flags & FmtShort)
@@ -1012,28 +1009,21 @@
switch(t->etype) {
case TPTR32:
case TPTR64:
- t1 = t->type;
- if(t1 != T) {
- switch(t1->etype) {
- case TSTRING:
- return fmtprint(fp, "string");
- case TMAP:
- return fmtprint(fp, "map[%T] %T", t1->down, t1->type);
- case TCHAN:
- return fmtprint(fp, "chan %T", t1->type);
- }
- }
if(fp->flags&FmtShort) // pass flag thru for methodsym
- return fmtprint(fp, "*%hT", t1);
- return fmtprint(fp, "*%T", t1);
+ return fmtprint(fp, "*%hT", t->type);
+ return fmtprint(fp, "*%T", t->type);
- // Should not see these: should see ptr instead, handled above.
- case TSTRING:
- return fmtprint(fp, "STRING", t->type);
case TCHAN:
- return fmtprint(fp, "CHAN %T", t->type);
+ switch(t->chan) {
+ case Crecv:
+ return fmtprint(fp, "<-chan %T", t->type);
+ case Csend:
+ return fmtprint(fp, "chan<- %T", t->type);
+ }
+ return fmtprint(fp, "chan %T", t->type);
+
case TMAP:
- return fmtprint(fp, "MAP[%T] %T", t->down, t->type);
+ return fmtprint(fp, "map[%T] %T", t->down, t->type);
case TFUNC:
// t->type is method struct
@@ -1124,8 +1114,6 @@
return -1;
}
-
-
int
Tconv(Fmt *fp)
{
@@ -1158,7 +1146,7 @@
}
et = t->etype;
- snprint(buf, sizeof buf, "%E.", et);
+ snprint(buf, sizeof buf, "%E ", et);
if(t->sym != S) {
snprint(buf1, sizeof(buf1), "<%S>", t->sym);
strncat(buf, buf1, sizeof(buf));
@@ -1190,7 +1178,7 @@
break;
case TINTER:
- strncat(buf, "I{", sizeof(buf));
+ strncat(buf, "{", sizeof(buf));
if(fp->flags & FmtLong) {
for(t1=t->type; t1!=T; t1=t1->down) {
snprint(buf1, sizeof(buf1), "%lT;", t1);
@@ -1212,7 +1200,7 @@
break;
case TMAP:
- snprint(buf, sizeof(buf), "MAP[%T]%T", t->down, t->type);
+ snprint(buf, sizeof(buf), "[%T]%T", t->down, t->type);
break;
case TARRAY:
@@ -1225,7 +1213,7 @@
case TPTR32:
case TPTR64:
- snprint(buf1, sizeof(buf1), "*%T", t->type);
+ snprint(buf1, sizeof(buf1), "%T", t->type);
strncat(buf, buf1, sizeof(buf));
break;
}
@@ -1442,6 +1430,12 @@
}
int
+istype(Type *t, int et)
+{
+ return t != T && t->etype == et;
+}
+
+int
isptrsarray(Type *t)
{
if(isptrto(t, TARRAY))
@@ -1627,10 +1621,9 @@
switch(t->etype) {
case TARRAY:
case TSTRUCT:
+ case TMAP:
return 1;
}
- if(isptr[t->etype] && t->type != T && t->type->etype == TMAP)
- return 1;
return 0;
}
diff --git a/src/cmd/gc/walk.c b/src/cmd/gc/walk.c
index 3639878..99dd118 100644
--- a/src/cmd/gc/walk.c
+++ b/src/cmd/gc/walk.c
@@ -441,7 +441,7 @@
if(cl == 2 && cr == 1) {
// a,b = map[] - mapaccess2
walktype(r->left, Erv);
- if(!isptrto(r->left->type, TMAP))
+ if(!istype(r->left->type, TMAP))
break;
l = mapop(n, top);
if(l == N)
@@ -455,7 +455,7 @@
if(cl == 2 && cr == 1) {
// a,b = <chan - chanrecv2
walktype(r->left, Erv);
- if(!isptrto(r->left->type, TCHAN))
+ if(!istype(r->left->type, TCHAN))
break;
l = chanop(n, top);
if(l == N)
@@ -499,7 +499,7 @@
case OINDEXPTR:
if(cl == 1 && cr == 2) {
// map[] = a,b - mapassign2
- if(!isptrto(l->left->type, TMAP))
+ if(!istype(l->left->type, TMAP))
break;
l = mapop(n, top);
if(l == N)
@@ -580,7 +580,7 @@
// to string
if(l->type != T)
- if(isptrto(t, TSTRING)) {
+ if(istype(t, TSTRING)) {
if(isint[l->type->etype]) {
indir(n, stringop(n, top));
goto ret;
@@ -659,7 +659,7 @@
}
// map literal
- if(isptr[t->etype] && t->type != t && t->type->etype == TMAP) {
+ if(t->etype == TMAP) {
r = maplit(n);
indir(n, r);
goto ret;
@@ -700,7 +700,7 @@
goto shft;
goto com;
}
- if(!isptrto(l->left->type, TMAP))
+ if(!istype(l->left->type, TMAP))
goto com;
indir(n, mapop(n, top));
goto ret;
@@ -771,7 +771,7 @@
case OGT:
case OADD:
case OASOP:
- if(isptrto(n->left->type, TSTRING)) {
+ if(istype(n->left->type, TSTRING)) {
indir(n, stringop(n, top));
goto ret;
}
@@ -854,8 +854,7 @@
// BOTCH - convert each index opcode
// to look like this and get rid of OINDEXPTR
- if(isptr[t->etype])
- if(isptrto(t, TSTRING) || isptrto(t->type, TSTRING)) {
+ if(istype(t, TSTRING) || isptrto(t, TSTRING)) {
// right side must be an int
if(top != Erv)
goto nottop;
@@ -889,8 +888,6 @@
}
if(!eqtype(n->right->type, t->down, 0))
goto badt;
- if(n->op != OINDEXPTR)
- goto badt;
n->op = OINDEX;
n->type = t->type;
if(top == Erv)
@@ -945,7 +942,7 @@
t = n->left->type;
if(t == T)
goto ret;
- if(isptr[t->etype])
+ if(isptr[t->etype]) //XXX?
t = t->type;
if(t->etype == TSTRING) {
indir(n, stringop(n, top));
@@ -1088,9 +1085,8 @@
if(n->left->type == T)
goto ret;
et = n->left->type->etype;
- if(!okforadd[et])
- if(!isptrto(n->left->type, TSTRING))
- goto badt;
+ if(!okforadd[et] && et != TSTRING)
+ goto badt;
t = types[TBOOL];
break;
@@ -1424,10 +1420,6 @@
t = expr->left->type;
if(t == T)
goto bad;
- if(isptr[t->etype])
- t = t->type;
- if(t == T)
- goto bad;
if(t->etype != TCHAN)
goto bad;
a = old2new(name, t->type);
@@ -2042,55 +2034,29 @@
Node*
makecompat(Node *n)
{
- Node *r, *on;
- Type *t, *t0;
+ Type *t;
- t0 = n->type;
- if(t0 == T)
- goto bad;
+ t = n->type;
- if(t0->etype == TARRAY)
- return arrayop(n, Erv);
-
- if(!isptr[t0->etype])
- goto bad;
-
- t = t0->type;
- if(t == T)
- goto bad;
-
+ if(t != T)
switch(t->etype) {
- case TSTRING:
- goto bad;
-
- // the call looks like new(MAP[int]int)
- // but internally we see new(*MAP[int]int)
+ case TARRAY:
+ return arrayop(n, Erv);
case TMAP:
- r = mapop(n, Erv);
- break;
-
- // the call looks like new(CHAN int)
- // but internally we see new(*CHAN int)
+ return mapop(n, Erv);
case TCHAN:
- r = chanop(n, Erv);
- break;
-
- default:
- if(n->left != N)
- yyerror("cannot make(%T, expr)", t0);
- dowidth(t);
- on = syslook("mal", 1);
- argtype(on, t);
- r = nodintconst(t->width);
- r = nod(OCALL, on, r);
- walktype(r, Erv);
- break;
+ return chanop(n, Erv);
}
- return r;
+ /*
+ * ken had code to malloc here,
+ * but rsc cut it out so that make(int)
+ * is diagnosed as an error (probably meant new).
+ * might come back once we know the
+ * language semantics for make(int).
+ */
-bad:
- yyerror("cannot make(%T)", t0);
+ yyerror("cannot make(%T)", t);
return n;
}
@@ -2101,17 +2067,7 @@
Type *t;
t = n->type;
- if(t == T)
- goto bad;
-
- switch(t->etype) {
- case TFUNC:
- case TSTRING:
- case TMAP:
- case TCHAN:
- goto bad;
-
- default:
+ if(t != T && t->etype != TFUNC) {
if(n->left != N)
yyerror("cannot new(%T, expr)", t);
dowidth(t);
@@ -2120,12 +2076,9 @@
r = nodintconst(t->width);
r = nod(OCALL, on, r);
walktype(r, Erv);
- break;
+ return r;
}
- return r;
-
-bad:
yyerror("cannot new(%T)", t);
return n;
}
@@ -2195,7 +2148,7 @@
case OINDEX:
// sys_indexstring(s, i)
c = n->left;
- if(isptrto(c->type->type, TSTRING)) {
+ if(istype(c->type->type, TSTRING)) {
// lhs is string or *string
c = nod(OIND, c, N);
c->type = c->left->type->type;
@@ -2228,11 +2181,8 @@
}
Type*
-fixmap(Type *tm)
+fixmap(Type *t)
{
- Type *t;
-
- t = tm->type;
if(t == T)
goto bad;
if(t->etype != TMAP)
@@ -2246,18 +2196,13 @@
return t;
bad:
- yyerror("not a map: %lT", tm);
+ yyerror("not a map: %lT", t);
return T;
}
Type*
-fixchan(Type *tm)
+fixchan(Type *t)
{
- Type *t;
-
- if(tm == T)
- goto bad;
- t = tm->type;
if(t == T)
goto bad;
if(t->etype != TCHAN)
@@ -2270,7 +2215,7 @@
return t;
bad:
- yyerror("not a channel: %lT", tm);
+ yyerror("not a channel: %lT", t);
return T;
}
@@ -2282,8 +2227,6 @@
Node *on;
int cl, cr;
-//dump("mapop", n);
-
r = n;
switch(n->op) {
default:
@@ -2460,7 +2403,7 @@
// rewrite map[index] op= right
// into tmpi := index; map[tmpi] = map[tmpi] op right
- t = n->left->left->type->type;
+ t = n->left->left->type;
a = nod(OXXX, N, N);
tempname(a, t->down); // tmpi
r = nod(OAS, a, n->left->right); // tmpi := index
@@ -2968,7 +2911,7 @@
goto out;
if(n->left->op == OINDEX)
- if(isptrto(n->left->left->type, TMAP)) {
+ if(istype(n->left->left->type, TMAP)) {
indir(n, mapop(n, Elv));
goto out;
}
@@ -3134,9 +3077,9 @@
goto badt;
walktype(nr->left, Erv);
t = nr->left->type;
- if(!isptrto(t, TCHAN))
+ if(!istype(t, TCHAN))
goto badt;
- a = old2new(nl->left, t->type->type);
+ a = old2new(nl->left, t->type);
n = a;
a = old2new(nl->right, types[TBOOL]);
n = list(n, a);
@@ -3575,6 +3518,7 @@
var = nod(OXXX, N, N);
tempname(var, t);
+ nnew = nil;
if(b < 0) {
// slice
nnew = nod(OMAKE, N, N);
@@ -3617,7 +3561,7 @@
Node *var, *r, *a;
t = n->type;
- if(!isptr[t->etype] || t->type == T || t->type->etype != TMAP)
+ if(t->etype != TMAP)
fatal("maplit: not map");
var = nod(OXXX, N, N);