Commit 30444035 authored by Ken Thompson's avatar Ken Thompson

assignment in select

with new select operator

R=r
OCL=15418
CL=15418
parent 592d2e3d
...@@ -702,6 +702,8 @@ Node* reorder4(Node*); ...@@ -702,6 +702,8 @@ Node* reorder4(Node*);
Node* structlit(Node*); Node* structlit(Node*);
Node* arraylit(Node*); Node* arraylit(Node*);
Node* maplit(Node*); Node* maplit(Node*);
Node* selectas(Node*, Node*);
Node* old2new(Node*, Type*);
/* /*
* const.c * const.c
......
...@@ -427,7 +427,7 @@ complex_stmt: ...@@ -427,7 +427,7 @@ complex_stmt:
// right will point to next case // right will point to next case
// done in casebody() // done in casebody()
poptodcl(); poptodcl();
$$ = nod(OAS, colas($2, $4), $4); $$ = nod(OAS, selectas($2,$4), $4);
$$ = nod(OXCASE, $$, N); $$ = nod(OXCASE, $$, N);
} }
| LDEFAULT ':' | LDEFAULT ':'
......
...@@ -1232,6 +1232,30 @@ out: ...@@ -1232,6 +1232,30 @@ out:
return r; 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 void
walkselect(Node *sel) walkselect(Node *sel)
{ {
...@@ -1270,6 +1294,16 @@ walkselect(Node *sel) ...@@ -1270,6 +1294,16 @@ walkselect(Node *sel)
yyerror("select cases must be send or recv"); yyerror("select cases must be send or recv");
break; 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 OSEND:
case ORECV: case ORECV:
if(oc != N) { if(oc != N) {
......
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