summaryrefslogtreecommitdiff
path: root/src/cmd/gc/walk.c
diff options
context:
space:
mode:
authorRuss Cox <rsc@golang.org>2009-01-09 15:21:41 -0800
committerRuss Cox <rsc@golang.org>2009-01-09 15:21:41 -0800
commit70f6ac6afc99213436eb96ff17858d3b6ff7e30b (patch)
tree0bb25d93f5296427df934e40a633a02468d7d7c4 /src/cmd/gc/walk.c
parentbc23ce679061b8f41f551578181b9feeb24f5c0a (diff)
downloadgolang-70f6ac6afc99213436eb96ff17858d3b6ff7e30b.tar.gz
clean up automatic indirect, delete some dead code.
R=ken OCL=22454 CL=22457
Diffstat (limited to 'src/cmd/gc/walk.c')
-rw-r--r--src/cmd/gc/walk.c119
1 files changed, 53 insertions, 66 deletions
diff --git a/src/cmd/gc/walk.c b/src/cmd/gc/walk.c
index 99dd118e2..e7a95d269 100644
--- a/src/cmd/gc/walk.c
+++ b/src/cmd/gc/walk.c
@@ -165,6 +165,33 @@ indir(Node *nl, Node *nr)
}
void
+implicitstar(Node **nn)
+{
+ Type *t;
+ Node *n;
+
+ // insert implicit * if needed
+ n = *nn;
+ t = n->type;
+ if(t == T || !isptr[t->etype])
+ return;
+ t = t->type;
+ if(t == T)
+ return;
+ switch(t->etype) {
+ case TMAP:
+ case TSTRING:
+ case TARRAY:
+ break;
+ default:
+ return;
+ }
+ n = nod(OIND, n, N);
+ walktype(n, Elv);
+ *nn = n;
+}
+
+void
walktype(Node *n, int top)
{
Node *r, *l;
@@ -437,7 +464,6 @@ loop:
break;
case OINDEX:
- case OINDEXPTR:
if(cl == 2 && cr == 1) {
// a,b = map[] - mapaccess2
walktype(r->left, Erv);
@@ -496,7 +522,6 @@ loop:
switch(l->op) {
case OINDEX:
- case OINDEXPTR:
if(cl == 1 && cr == 2) {
// map[] = a,b - mapassign2
if(!istype(l->left->type, TMAP))
@@ -581,11 +606,13 @@ loop:
// to string
if(l->type != T)
if(istype(t, TSTRING)) {
- if(isint[l->type->etype]) {
+ et = l->type->etype;
+ if(isint[et]) {
indir(n, stringop(n, top));
goto ret;
}
- if(bytearraysz(l->type) != -2) {
+ if(et == TARRAY)
+ if(istype(l->type->type, TUINT8)) {
n->op = OARRAY;
indir(n, stringop(n, top));
goto ret;
@@ -593,11 +620,11 @@ loop:
}
// convert dynamic to static generated by ONEW/OMAKE
- if(issarray(t) && isdarray(l->type))
+ if(isfixedarray(t) && isslice(l->type))
goto ret;
// convert static array to dynamic array
- if(isdarray(t) && issarray(l->type)) {
+ if(isslice(t) && isfixedarray(l->type)) {
if(eqtype(t->type->type, l->type->type->type, 0)) {
indir(n, arrayop(n, Erv));
goto ret;
@@ -795,10 +822,9 @@ loop:
if(top != Erv)
goto nottop;
walktype(n->left, Erv);
+ implicitstar(&n->left);
evconst(n);
t = n->left->type;
- if(t != T && isptr[t->etype])
- t = t->type;
if(t == T)
goto ret;
switch(t->etype) {
@@ -819,10 +845,9 @@ loop:
if(top != Erv)
goto nottop;
walktype(n->left, Erv);
+ implicitstar(&n->left);
evconst(n);
t = n->left->type;
- if(t != T && isptr[t->etype])
- t = t->type;
if(t == T)
goto ret;
switch(t->etype) {
@@ -837,7 +862,6 @@ loop:
goto ret;
case OINDEX:
- case OINDEXPTR:
if(top == Etop)
goto nottop;
@@ -848,36 +872,29 @@ loop:
goto ret;
defaultlit(n->left);
+ implicitstar(&n->left);
+
t = n->left->type;
if(t == T)
goto ret;
-// BOTCH - convert each index opcode
-// to look like this and get rid of OINDEXPTR
- if(istype(t, TSTRING) || isptrto(t, TSTRING)) {
+ switch(t->etype) {
+ default:
+ goto badt;
+
+ case TSTRING:
// right side must be an int
if(top != Erv)
goto nottop;
if(n->right->type == T) {
convlit(n->right, types[TINT]);
if(n->right->type == T)
- goto ret;
+ break;
}
if(!isint[n->right->type->etype])
goto badt;
indir(n, stringop(n, top));
- goto ret;
- }
-
- // left side is indirect
- if(isptr[t->etype]) {
- t = t->type;
- n->op = OINDEXPTR;
- }
-
- switch(t->etype) {
- default:
- goto badt;
+ break;
case TMAP:
// right side must be map type
@@ -888,7 +905,6 @@ loop:
}
if(!eqtype(n->right->type, t->down, 0))
goto badt;
- n->op = OINDEX;
n->type = t->type;
if(top == Erv)
indir(n, mapop(n, top));
@@ -939,11 +955,10 @@ loop:
if(n->left == N || n->right == N)
goto ret;
convlit(n->left, types[TSTRING]);
+ implicitstar(&n->left);
t = n->left->type;
if(t == T)
goto ret;
- if(isptr[t->etype]) //XXX?
- t = t->type;
if(t->etype == TSTRING) {
indir(n, stringop(n, top));
goto ret;
@@ -1064,7 +1079,7 @@ loop:
case ONE:
if(n->left->type == T)
goto ret;
- if(isdarray(n->left->type)) {
+ if(isslice(n->left->type)) {
t = types[TBOOL];
break;
}
@@ -1912,7 +1927,7 @@ ascompat(Type *dst, Type *src)
if(eqtype(dst, src, 0))
return 1;
- if(isdarray(dst) && issarray(src))
+ if(isslice(dst) && isfixedarray(src))
return 1;
if(isnilinter(dst) || isnilinter(src))
@@ -1973,7 +1988,7 @@ loop:
argtype(on, l->type->type); // any-1
break;
}
- if(isdarray(l->type)) {
+ if(isslice(l->type)) {
on = syslook("printarray", 1);
argtype(on, l->type); // any-1
break;
@@ -2147,15 +2162,9 @@ stringop(Node *n, int top)
case OINDEX:
// sys_indexstring(s, i)
- c = n->left;
- if(istype(c->type->type, TSTRING)) {
- // lhs is string or *string
- c = nod(OIND, c, N);
- c->type = c->left->type->type;
- }
r = nod(OCONV, n->right, N);
r->type = types[TINT];
- r = list(c, r);
+ r = list(n->left, r);
on = syslook("indexstring", 0);
r = nod(OCALL, on, r);
break;
@@ -2284,11 +2293,6 @@ mapop(Node *n, int top)
}
a = n->right; // key
-// if(!isptr[t->down->etype]) {
-// a = nod(OADDR, a, N);
-// a->type = ptrto(t);
-// }
-
r = a;
a = n->left; // map
r = list(a, r);
@@ -2916,12 +2920,6 @@ convas(Node *n)
goto out;
}
- if(n->left->op == OINDEXPTR)
- if(n->left->left->type->etype == TMAP) {
- indir(n, mapop(n, Elv));
- goto out;
- }
-
if(n->left->op == OSEND)
if(n->left->type != T) {
indir(n, chanop(n, Elv));
@@ -2937,7 +2935,7 @@ convas(Node *n)
goto out;
}
- if(isdarray(lt) && issarray(rt)) {
+ if(isslice(lt) && isfixedarray(rt)) {
if(!eqtype(lt->type->type, rt->type->type, 0))
goto bad;
indir(n, arrayop(n, Etop));
@@ -3040,18 +3038,14 @@ multi:
break;
case OINDEX:
- case OINDEXPTR:
// check if rhs is a map index.
- // if so, types are bool,maptype
+ // if so, types are valuetype,bool
if(cl != 2)
goto badt;
walktype(nr->left, Elv);
t = nr->left->type;
- if(t != T && isptr[t->etype])
- t = t->type;
- if(t == T || t->etype != TMAP)
+ if(!istype(t, TMAP))
goto badt;
-
a = old2new(nl->left, t->type);
n = a;
a = old2new(nl->right, types[TBOOL]);
@@ -3110,6 +3104,7 @@ dorange(Node *nn)
if(nn->op != ORANGE)
fatal("dorange not ORANGE");
+ implicitstar(&nn->right);
k = nn->left;
m = nn->right;
local = nn->etype;
@@ -3128,16 +3123,8 @@ dorange(Node *nn)
goto out;
if(t->etype == TARRAY)
goto ary;
- if(isptrto(t, TARRAY)) {
- t = t->type;
- goto ary;
- }
if(t->etype == TMAP)
goto map;
- if(isptrto(t, TMAP)) {
- t = t->type;
- goto map;
- }
yyerror("range must be over map/array");
goto out;