summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRuss Cox <rsc@golang.org>2010-01-26 10:40:28 -0800
committerRuss Cox <rsc@golang.org>2010-01-26 10:40:28 -0800
commitb1a2356951dcb5b639299684da6bfab76fc918e4 (patch)
tree22219a93d35aeca5486a099c7e5840d03b4473ca /src
parent246a2a1af14b65c8f8ffca9b2a4437bb8c0f799e (diff)
downloadgolang-b1a2356951dcb5b639299684da6bfab76fc918e4.tar.gz
gc: fix chan <- chan precedence.
also allow func() func(). R=ken2 CC=golang-dev http://codereview.appspot.com/194078
Diffstat (limited to 'src')
-rw-r--r--src/cmd/gc/go.y71
-rw-r--r--src/cmd/gc/print.c8
-rw-r--r--src/cmd/gc/subr.c14
-rw-r--r--src/pkg/reflect/all_test.go2
4 files changed, 48 insertions, 47 deletions
diff --git a/src/cmd/gc/go.y b/src/cmd/gc/go.y
index d73311fff..db9b0db5b 100644
--- a/src/cmd/gc/go.y
+++ b/src/cmd/gc/go.y
@@ -73,7 +73,7 @@
%type <node> convtype dotdotdot
%type <node> indcl interfacetype structtype ptrtype
-%type <node> chantype non_chan_type othertype non_fn_type fntype
+%type <node> recvchantype non_recvchantype othertype fnret_type fntype
%type <sym> hidden_importsym hidden_pkg_importsym
@@ -86,8 +86,8 @@
%type <list> hidden_structdcl_list ohidden_structdcl_list
%type <type> hidden_type hidden_type_misc hidden_pkgtype
-%type <type> hidden_type_func hidden_type_non_func
-%type <type> hidden_type_chan hidden_type_non_chan
+%type <type> hidden_type_func
+%type <type> hidden_type_recv_chan hidden_type_non_recv_chan
%left LOROR
%left LANDAND
@@ -923,7 +923,7 @@ dotdotdot:
}
ntype:
- chantype
+ recvchantype
| fntype
| othertype
| ptrtype
@@ -934,19 +934,15 @@ ntype:
}
non_expr_type:
- chantype
+ recvchantype
| fntype
| othertype
| '*' non_expr_type
{
$$ = nod(OIND, $2, N);
}
-| '(' non_expr_type ')'
- {
- $$ = $2;
- }
-non_chan_type:
+non_recvchantype:
fntype
| othertype
| ptrtype
@@ -956,8 +952,9 @@ non_chan_type:
$$ = $2;
}
-non_fn_type:
- chantype
+fnret_type:
+ recvchantype
+| fntype
| othertype
| ptrtype
| dotname
@@ -986,12 +983,12 @@ othertype:
// array literal of nelem
$$ = nod(OTARRAY, $2, $4);
}
-| LCOMM LCHAN ntype
+| LCHAN non_recvchantype
{
- $$ = nod(OTCHAN, $3, N);
- $$->etype = Crecv;
+ $$ = nod(OTCHAN, $2, N);
+ $$->etype = Cboth;
}
-| LCHAN LCOMM non_chan_type
+| LCHAN LCOMM ntype
{
$$ = nod(OTCHAN, $3, N);
$$->etype = Csend;
@@ -1009,11 +1006,11 @@ ptrtype:
$$ = nod(OIND, $2, N);
}
-chantype:
- LCHAN ntype
+recvchantype:
+ LCOMM LCHAN ntype
{
- $$ = nod(OTCHAN, $2, N);
- $$->etype = Cboth;
+ $$ = nod(OTCHAN, $3, N);
+ $$->etype = Crecv;
}
structtype:
@@ -1132,7 +1129,7 @@ fnres:
{
$$ = nil;
}
-| non_fn_type
+| fnret_type
{
$$ = list1(nod(ODCLFIELD, N, $1));
}
@@ -1588,17 +1585,13 @@ hidden_pkgtype:
hidden_type:
hidden_type_misc
-| hidden_type_chan
+| hidden_type_recv_chan
| hidden_type_func
-hidden_type_non_chan:
+hidden_type_non_recv_chan:
hidden_type_misc
| hidden_type_func
-hidden_type_non_func:
- hidden_type_misc
-| hidden_type_chan
-
hidden_type_misc:
hidden_importsym
{
@@ -1639,22 +1632,22 @@ hidden_type_misc:
{
$$ = ptrto($2);
}
-| LCOMM LCHAN hidden_type
+| LCHAN hidden_type_non_recv_chan
{
$$ = typ(TCHAN);
- $$->type = $3;
- $$->chan = Crecv;
+ $$->type = $2;
+ $$->chan = Cboth;
}
-| LCHAN LCOMM hidden_type_non_chan
+| LCHAN '(' hidden_type_recv_chan ')'
{
$$ = typ(TCHAN);
$$->type = $3;
- $$->chan = Csend;
+ $$->chan = Cboth;
}
-| LCHAN LCOMM '(' hidden_type_chan ')'
+| LCHAN LCOMM hidden_type
{
$$ = typ(TCHAN);
- $$->type = $4;
+ $$->type = $3;
$$->chan = Csend;
}
| LDDD
@@ -1662,12 +1655,12 @@ hidden_type_misc:
$$ = typ(TDDD);
}
-hidden_type_chan:
- LCHAN hidden_type
+hidden_type_recv_chan:
+ LCOMM LCHAN hidden_type
{
$$ = typ(TCHAN);
- $$->type = $2;
- $$->chan = Cboth;
+ $$->type = $3;
+ $$->chan = Crecv;
}
hidden_type_func:
@@ -1723,7 +1716,7 @@ hidden_funres:
{
$$ = $2;
}
-| hidden_type_non_func
+| hidden_type
{
$$ = list1(nod(ODCLFIELD, N, typenod($1)));
}
diff --git a/src/cmd/gc/print.c b/src/cmd/gc/print.c
index bbb7b0fbd..91f012d8b 100644
--- a/src/cmd/gc/print.c
+++ b/src/cmd/gc/print.c
@@ -7,7 +7,6 @@
enum
{
PFIXME = 0,
- PCHAN = 0,
};
void
@@ -173,7 +172,12 @@ exprfmt(Fmt *f, Node *n, int prec)
exprfmt(f, n->left, 0);
} else {
fmtprint(f, " ");
- exprfmt(f, n->left, PCHAN);
+ if(n->left->op == OTCHAN && n->left->etype == Crecv) {
+ fmtprint(f, "(");
+ exprfmt(f, n->left, 0);
+ fmtprint(f, ")");
+ } else
+ exprfmt(f, n->left, 0);
}
break;
diff --git a/src/cmd/gc/subr.c b/src/cmd/gc/subr.c
index e8aaabcc4..74ca4cc2c 100644
--- a/src/cmd/gc/subr.c
+++ b/src/cmd/gc/subr.c
@@ -292,7 +292,7 @@ Sym*
restrictlookup(char *name, Pkg *pkg)
{
if(!exportname(name) && pkg != localpkg)
- yyerror("cannot refer to unexported name %s.%s", pkg, name);
+ yyerror("cannot refer to unexported name %s.%s", pkg->name, name);
return pkglookup(name, pkg);
}
@@ -1105,10 +1105,10 @@ Tpretty(Fmt *fp, Type *t)
case Crecv:
return fmtprint(fp, "<-chan %T", t->type);
case Csend:
- if(t->type != T && t->type->etype == TCHAN)
- return fmtprint(fp, "chan<- (%T)", t->type);
return fmtprint(fp, "chan<- %T", t->type);
}
+ if(t->type != T && t->type->etype == TCHAN && t->type->chan == Crecv)
+ return fmtprint(fp, "chan (%T)", t->type);
return fmtprint(fp, "chan %T", t->type);
case TMAP:
@@ -1150,10 +1150,14 @@ Tpretty(Fmt *fp, Type *t)
fmtprint(fp, " ?unknown-type?");
break;
}
- if(t1->etype != TFIELD && t1->etype != TFUNC) {
+ if(t1->etype != TFIELD) {
fmtprint(fp, " %T", t1);
break;
}
+ if(t1->sym == S) {
+ fmtprint(fp, " %T", t1->type);
+ break;
+ }
default:
t1 = getoutargx(t)->type;
fmtprint(fp, " (");
@@ -1180,7 +1184,7 @@ Tpretty(Fmt *fp, Type *t)
case TINTER:
fmtprint(fp, "interface {");
for(t1=t->type; t1!=T; t1=t1->down) {
- fmtprint(fp, " %hS %hhT", t1->sym, t1->type);
+ fmtprint(fp, " %hS%hhT", t1->sym, t1->type);
if(t1->down)
fmtprint(fp, ";");
}
diff --git a/src/pkg/reflect/all_test.go b/src/pkg/reflect/all_test.go
index f9721f6b4..221ca06df 100644
--- a/src/pkg/reflect/all_test.go
+++ b/src/pkg/reflect/all_test.go
@@ -150,7 +150,7 @@ var typeTests = []pair{
b()
})
}{},
- "interface { a (func(func(int) (int)) (func(func(int)) (int))); b () }",
+ "interface { a(func(func(int) int) func(func(int)) int); b() }",
},
}