1
0
mirror of https://github.com/golang/go synced 2024-11-18 22:24:50 -07:00

assignment in select

with new select operator

R=r
OCL=15418
CL=15418
This commit is contained in:
Ken Thompson 2008-09-16 20:51:50 -07:00
parent 592d2e3d8d
commit 304440356d
3 changed files with 37 additions and 1 deletions

View File

@ -702,6 +702,8 @@ Node* reorder4(Node*);
Node* structlit(Node*);
Node* arraylit(Node*);
Node* maplit(Node*);
Node* selectas(Node*, Node*);
Node* old2new(Node*, Type*);
/*
* const.c

View File

@ -427,7 +427,7 @@ complex_stmt:
// right will point to next case
// done in casebody()
poptodcl();
$$ = nod(OAS, colas($2, $4), $4);
$$ = nod(OAS, selectas($2,$4), $4);
$$ = nod(OXCASE, $$, N);
}
| LDEFAULT ':'

View File

@ -1232,6 +1232,30 @@ out:
return r;
}
Node*
selectas(Node *name, Node *expr)
{
Node *a;
Type *t;
if(expr == N || expr->op != ORECV)
goto bad;
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);
return a;
bad:
return name;
}
void
walkselect(Node *sel)
{
@ -1270,6 +1294,16 @@ walkselect(Node *sel)
yyerror("select cases must be send or recv");
break;
case OAS:
// convert new syntax (a=recv(chan)) to (recv(a,chan))
if(n->left->right == N || n->left->right->op != ORECV) {
yyerror("select cases must be send or recv");
break;
}
n->left->right->right = n->left->right->left;
n->left->right->left = n->left->left;
n->left = n->left->right;
case OSEND:
case ORECV:
if(oc != N) {