1
0
mirror of https://github.com/golang/go synced 2024-11-25 08:07:57 -07:00

gc: small fixes for printing.

mark OADDR inserted by typecheck as implicit
OCOPY takes ->left and ->right, not ->list
OMAKE*'s can all have arguments
precedence for OIND was initalized twice

fixes #2414

R=rsc, dave
CC=golang-dev
https://golang.org/cl/5319065
This commit is contained in:
Luuk van Dijk 2011-11-02 15:36:33 +01:00
parent ee24bfc058
commit 29a5ae657f
3 changed files with 8 additions and 10 deletions

View File

@ -921,7 +921,6 @@ static int opprec[] = {
[OINDEXMAP] = 8, [OINDEXMAP] = 8,
[OINDEX] = 8, [OINDEX] = 8,
[OIND] = 8,
[ODOTINTER] = 8, [ODOTINTER] = 8,
[ODOTMETH] = 8, [ODOTMETH] = 8,
[ODOTPTR] = 8, [ODOTPTR] = 8,
@ -1146,6 +1145,7 @@ exprfmt(Fmt *f, Node *n, int prec)
exprfmt(f, n->left, nprec); exprfmt(f, n->left, nprec);
return fmtprint(f, "[%N]", n->right); return fmtprint(f, "[%N]", n->right);
case OCOPY:
case OCOMPLEX: case OCOMPLEX:
return fmtprint(f, "%#O(%N, %N)", n->op, n->left, n->right); return fmtprint(f, "%#O(%N, %N)", n->op, n->left, n->right);
@ -1167,7 +1167,6 @@ exprfmt(Fmt *f, Node *n, int prec)
case OCAP: case OCAP:
case OCLOSE: case OCLOSE:
case OLEN: case OLEN:
case OCOPY:
case OMAKE: case OMAKE:
case ONEW: case ONEW:
case OPANIC: case OPANIC:
@ -1188,13 +1187,11 @@ exprfmt(Fmt *f, Node *n, int prec)
return fmtprint(f, "(%,H...)", n->list); return fmtprint(f, "(%,H...)", n->list);
return fmtprint(f, "(%,H)", n->list); return fmtprint(f, "(%,H)", n->list);
case OMAKESLICE:
if(count(n->list) > 2)
return fmtprint(f, "make(%T, %N, %N)", n->type, n->left, n->right); // count list, but print l/r?
return fmtprint(f, "make(%T, %N)", n->type, n->left);
case OMAKEMAP: case OMAKEMAP:
case OMAKECHAN: case OMAKECHAN:
case OMAKESLICE:
if(n->list->next)
return fmtprint(f, "make(%T, %,H)", n->type, n->list->next);
return fmtprint(f, "make(%T)", n->type); return fmtprint(f, "make(%T)", n->type);
case OADD: case OADD:

View File

@ -745,6 +745,7 @@ reswitch:
defaultlit(&n->right->right, T); defaultlit(&n->right->right, T);
if(isfixedarray(n->left->type)) { if(isfixedarray(n->left->type)) {
n->left = nod(OADDR, n->left, N); n->left = nod(OADDR, n->left, N);
n->left->implicit = 1;
typecheck(&n->left, top); typecheck(&n->left, top);
} }
if(n->right->left != N) { if(n->right->left != N) {

View File

@ -148,7 +148,7 @@ func (b *Bar2) NoLeak() int { // ERROR "b does not escape"
} }
func (b *Bar2) Leak() []int { // ERROR "leaking param: b" func (b *Bar2) Leak() []int { // ERROR "leaking param: b"
return b.i[:] // ERROR "&b.i escapes to heap" return b.i[:] // ERROR "b.i escapes to heap"
} }
func (b *Bar2) AlsoNoLeak() []int { // ERROR "b does not escape" func (b *Bar2) AlsoNoLeak() []int { // ERROR "b does not escape"
@ -156,12 +156,12 @@ func (b *Bar2) AlsoNoLeak() []int { // ERROR "b does not escape"
} }
func (b *Bar2) LeakSelf() { // ERROR "leaking param: b" func (b *Bar2) LeakSelf() { // ERROR "leaking param: b"
b.ii = b.i[0:4] // ERROR "&b.i escapes to heap" b.ii = b.i[0:4] // ERROR "b.i escapes to heap"
} }
func (b *Bar2) LeakSelf2() { // ERROR "leaking param: b" func (b *Bar2) LeakSelf2() { // ERROR "leaking param: b"
var buf []int var buf []int
buf = b.i[0:] // ERROR "&b.i escapes to heap" buf = b.i[0:] // ERROR "b.i escapes to heap"
b.ii = buf b.ii = buf
} }