OSDN Git Service

compiler: Permit a general expression in case x := <-c.
authorian <ian@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 1 Feb 2012 14:29:28 +0000 (14:29 +0000)
committerian <ian@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 1 Feb 2012 14:29:28 +0000 (14:29 +0000)
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@183802 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/go/gofrontend/parse.cc

index 06faeb6..1359f4c 100644 (file)
@@ -4640,9 +4640,14 @@ Parse::send_or_recv_stmt(bool* is_send, Expression** channel, Expression** val,
       if (token->is_op(OPERATOR_COLONEQ))
        {
          // case rv := <-c:
-         if (!this->advance_token()->is_op(OPERATOR_CHANOP))
+         this->advance_token();
+         Expression* e = this->expression(PRECEDENCE_NORMAL, false, false,
+                                          NULL);
+         Receive_expression* re = e->receive_expression();
+         if (re == NULL)
            {
-             error_at(this->location(), "expected %<<-%>");
+             if (!e->is_error_expression())
+               error_at(this->location(), "expected receive expression");
              return false;
            }
          if (recv_var == "_")
@@ -4653,8 +4658,7 @@ Parse::send_or_recv_stmt(bool* is_send, Expression** channel, Expression** val,
            }
          *is_send = false;
          *varname = gogo->pack_hidden_name(recv_var, is_rv_exported);
-         this->advance_token();
-         *channel = this->expression(PRECEDENCE_NORMAL, false, true, NULL);
+         *channel = re->channel();
          return true;
        }
       else if (token->is_op(OPERATOR_COMMA))
@@ -4671,9 +4675,15 @@ Parse::send_or_recv_stmt(bool* is_send, Expression** channel, Expression** val,
              if (token->is_op(OPERATOR_COLONEQ))
                {
                  // case rv, rc := <-c:
-                 if (!this->advance_token()->is_op(OPERATOR_CHANOP))
+                 this->advance_token();
+                 Expression* e = this->expression(PRECEDENCE_NORMAL, false,
+                                                  false, NULL);
+                 Receive_expression* re = e->receive_expression();
+                 if (re == NULL)
                    {
-                     error_at(this->location(), "expected %<<-%>");
+                     if (!e->is_error_expression())
+                       error_at(this->location(),
+                                "expected receive expression");
                      return false;
                    }
                  if (recv_var == "_" && recv_closed == "_")
@@ -4689,9 +4699,7 @@ Parse::send_or_recv_stmt(bool* is_send, Expression** channel, Expression** val,
                  if (recv_closed != "_")
                    *closedname = gogo->pack_hidden_name(recv_closed,
                                                         is_rc_exported);
-                 this->advance_token();
-                 *channel = this->expression(PRECEDENCE_NORMAL, false, true,
-                                             NULL);
+                 *channel = re->channel();
                  return true;
                }