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*);
Node* structlit(Node*);
Node* arraylit(Node*);
Node* maplit(Node*);
Node* selectas(Node*, Node*);
Node* old2new(Node*, Type*);
/*
* const.c
......
......@@ -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 ':'
......
......@@ -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) {
......
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