]> Cypherpunks repositories - gostls13.git/commitdiff
allow "defer close(chan)"
authorKen Thompson <ken@golang.org>
Wed, 29 Apr 2009 00:20:18 +0000 (17:20 -0700)
committerKen Thompson <ken@golang.org>
Wed, 29 Apr 2009 00:20:18 +0000 (17:20 -0700)
bug found by anton

R=r
OCL=28001
CL=28001

src/cmd/gc/go.y

index 74475b4b373df4bbd4ca67dcc155c0c003cbba4a..4c326f1e72d1fcf2d142dccb8a0cf411ca47d3ac 100644 (file)
@@ -54,7 +54,7 @@
 %type  <node>          if_stmt if_body if_header select_stmt condition
 %type  <node>          simple_stmt osimple_stmt range_stmt semi_stmt
 %type  <node>          expr uexpr pexpr expr_list oexpr oexpr_list expr_list_r
-%type  <node>          exprsym3_list_r exprsym3
+%type  <node>          exprsym3_list_r exprsym3 pseudocall
 %type  <node>          name labelname onew_name new_name new_name_list_r new_field
 %type  <node>          vardcl_list_r vardcl Avardcl Bvardcl
 %type  <node>          interfacedcl_list_r interfacedcl interfacedcl1
@@ -547,15 +547,13 @@ semi_stmt:
        {
                $$ = nod(OCONTINUE, $2, N);
        }
-|      LGO pexpr '(' oexpr_list ')'
+|      LGO pseudocall
        {
-               $$ = nod(OCALL, $2, $4);
-               $$ = nod(OPROC, $$, N);
+               $$ = nod(OPROC, $2, N);
        }
-|      LDEFER pexpr '(' oexpr_list ')'
+|      LDEFER pseudocall
        {
-               $$ = nod(OCALL, $2, $4);
-               $$ = nod(ODEFER, $$, N);
+               $$ = nod(ODEFER, $2, N);
        }
 |      LGOTO new_name
        {
@@ -823,6 +821,22 @@ uexpr:
                $$ = nod(ORECV, $2, N);
        }
 
+/*
+ * call-like statements that
+ * can be preceeded by 'defer' and 'go'
+ */
+pseudocall:
+       pexpr '(' oexpr_list ')'
+       {
+               $$ = unsafenmagic($1, $3);
+               if($$ == N)
+                       $$ = nod(OCALL, $1, $3);
+       }
+|      LCLOSE '(' expr ')'
+       {
+               $$ = nod(OCLOSE, $3, N);
+       }
+
 pexpr:
        LLITERAL
        {
@@ -881,20 +895,11 @@ pexpr:
        {
                $$ = nod(OSLICE, $1, $3);
        }
-|      pexpr '(' oexpr_list ')'
-       {
-               $$ = unsafenmagic($1, $3);
-               if($$ == N)
-                       $$ = nod(OCALL, $1, $3);
-       }
+|      pseudocall
 |      LLEN '(' expr ')'
        {
                $$ = nod(OLEN, $3, N);
        }
-|      LCLOSE '(' expr ')'
-       {
-               $$ = nod(OCLOSE, $3, N);
-       }
 |      LCLOSED '(' expr ')'
        {
                $$ = nod(OCLOSED, $3, N);