1
0
mirror of https://github.com/golang/go synced 2024-11-19 15:44:44 -07:00

cmd/compile: further simplify walkprint

Passes toolstash-check.

Change-Id: I6386a37a35221de8d3944253beee668927810f17
Reviewed-on: https://go-review.googlesource.com/55096
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
This commit is contained in:
Josh Bleecher Snyder 2017-05-19 17:18:50 -07:00
parent 8b68fafd1f
commit 385ca9ae9a

View File

@ -2024,7 +2024,7 @@ func walkprint(nn *Node, init *Nodes) *Node {
notfirst := false notfirst := false
calls := []*Node{mkcall("printlock", nil, init)} calls := []*Node{mkcall("printlock", nil, init)}
for i1, n := range nn.List.Slice() { for i, n := range nn.List.Slice() {
if notfirst { if notfirst {
calls = append(calls, mkcall("printsp", nil, init)) calls = append(calls, mkcall("printsp", nil, init))
} }
@ -2048,52 +2048,48 @@ func walkprint(nn *Node, init *Nodes) *Node {
n = defaultlit(n, types.Types[TINT64]) n = defaultlit(n, types.Types[TINT64])
} }
n = defaultlit(n, nil) n = defaultlit(n, nil)
nn.List.SetIndex(i1, n) nn.List.SetIndex(i, n)
if n.Type == nil || n.Type.Etype == TFORW { if n.Type == nil || n.Type.Etype == TFORW {
continue continue
} }
t := n.Type
et := n.Type.Etype
var on *Node var on *Node
switch { switch n.Type.Etype {
case n.Type.IsInterface(): case TINTER:
if n.Type.IsEmptyInterface() { if n.Type.IsEmptyInterface() {
on = syslook("printeface") on = syslook("printeface")
} else { } else {
on = syslook("printiface") on = syslook("printiface")
} }
on = substArgTypes(on, n.Type) // any-1 on = substArgTypes(on, n.Type) // any-1
case n.Type.IsPtr() || et == TCHAN || et == TMAP || et == TFUNC || et == TUNSAFEPTR: case TPTR32, TPTR64, TCHAN, TMAP, TFUNC, TUNSAFEPTR:
on = syslook("printpointer") on = syslook("printpointer")
on = substArgTypes(on, n.Type) // any-1 on = substArgTypes(on, n.Type) // any-1
case n.Type.IsSlice(): case TSLICE:
on = syslook("printslice") on = syslook("printslice")
on = substArgTypes(on, n.Type) // any-1 on = substArgTypes(on, n.Type) // any-1
case isInt[et]: case TUINT64:
if et == TUINT64 { if isRuntimePkg(n.Type.Sym.Pkg) && n.Type.Sym.Name == "hex" {
if isRuntimePkg(t.Sym.Pkg) && t.Sym.Name == "hex" {
on = syslook("printhex") on = syslook("printhex")
} else { } else {
on = syslook("printuint") on = syslook("printuint")
} }
} else { case TINT, TUINT, TUINTPTR, TINT8, TUINT8, TINT16, TUINT16, TINT32, TUINT32, TINT64:
on = syslook("printint") on = syslook("printint")
} case TFLOAT32, TFLOAT64:
case isFloat[et]:
on = syslook("printfloat") on = syslook("printfloat")
case isComplex[et]: case TCOMPLEX64, TCOMPLEX128:
on = syslook("printcomplex") on = syslook("printcomplex")
case et == TBOOL: case TBOOL:
on = syslook("printbool") on = syslook("printbool")
case et == TSTRING: case TSTRING:
on = syslook("printstring") on = syslook("printstring")
default: default:
badtype(OPRINT, n.Type, nil) badtype(OPRINT, n.Type, nil)
continue continue
} }
t = on.Type.Params().Field(0).Type t := on.Type.Params().Field(0).Type
if !eqtype(t, n.Type) { if !eqtype(t, n.Type) {
n = nod(OCONV, n, nil) n = nod(OCONV, n, nil)