cmd/compile: early return/continue to unindent some code

While at it, also simplify a couple of switches.

Doesn't pass toolstash -cmp on std cmd, because orderBlock(&n2.Nbody) is
moved further down to the n3 loop.

Change-Id: I20a2a6c21eb9a183a59572e0fca401a5041fc40a
Reviewed-on: https://go-review.googlesource.com/104416
Run-TryBot: Daniel Martí <mvdan@mvdan.cc>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
This commit is contained in:
Daniel Martí 2018-04-03 13:17:28 +01:00
parent 9767727353
commit fcfea24742
3 changed files with 163 additions and 164 deletions

View file

@ -332,14 +332,11 @@ func ismulticall(l Nodes) bool {
switch n.Op {
default:
return false
case OCALLFUNC, OCALLMETH, OCALLINTER:
break
}
// call must return multiple values
return n.Left.Type.NumResults() > 1
}
}
// copyRet emits t1, t2, ... = n, where n is a function call,
// and then returns the list t1, t2, ....
@ -381,7 +378,9 @@ func (o *Order) call(n *Node) {
n.Right = o.expr(n.Right, nil) // ODDDARG temp
o.callArgs(&n.List)
if n.Op == OCALLFUNC {
if n.Op != OCALLFUNC {
return
}
keepAlive := func(i int) {
// If the argument is really a pointer being converted to uintptr,
// arrange for the pointer to be kept alive until the call returns,
@ -414,7 +413,6 @@ func (o *Order) call(n *Node) {
}
}
}
}
// mapAssign appends n to o.out, introducing temporaries
// to make sure that all map assignments have the form m[k] = x.
@ -766,7 +764,9 @@ func (o *Order) stmt(n *Node) {
if n2.Ninit.Len() != 0 {
Fatalf("order select ninit")
}
if r != nil {
if r == nil {
continue
}
switch r.Op {
default:
Dump("select case", r)
@ -870,13 +870,11 @@ func (o *Order) stmt(n *Node) {
}
}
}
orderBlock(&n2.Nbody)
}
// Now that we have accumulated all the temporaries, clean them.
// Also insert any ninit queued during the previous loop.
// (The temporary cleaning must follow that ninit work.)
for _, n3 := range n.List.Slice() {
orderBlock(&n3.Nbody)
n3.Nbody.Prepend(o.cleanTempNoPop(t)...)
// TODO(mdempsky): Is this actually necessary?

View file

@ -347,10 +347,13 @@ func staticcopy(l *Node, r *Node, out *[]*Node) bool {
n.Type = e.Expr.Type
if e.Expr.Op == OLITERAL {
gdata(n, e.Expr, int(n.Type.Width))
} else {
continue
}
ll := n.copy()
ll.Orig = ll // completely separate copy
if !staticassign(ll, e.Expr, out) {
if staticassign(ll, e.Expr, out) {
continue
}
// Requires computation, but we're
// copying someone else's computation.
rr := orig.copy()
@ -360,8 +363,6 @@ func staticcopy(l *Node, r *Node, out *[]*Node) bool {
setlineno(rr)
*out = append(*out, nod(OAS, ll, rr))
}
}
}
return true
}
@ -449,7 +450,8 @@ func staticassign(l *Node, r *Node, out *[]*Node) bool {
n.Type = e.Expr.Type
if e.Expr.Op == OLITERAL {
gdata(n, e.Expr, int(n.Type.Width))
} else {
continue
}
setlineno(e.Expr)
a := n.copy()
a.Orig = a // completely separate copy
@ -457,7 +459,6 @@ func staticassign(l *Node, r *Node, out *[]*Node) bool {
*out = append(*out, nod(OAS, a, e.Expr))
}
}
}
return true

View file

@ -3089,7 +3089,8 @@ func typecheckcomplit(n *Node) *Node {
if f == nil {
if ci := lookdot1(nil, l.Sym, t, t.Fields(), 2); ci != nil { // Case-insensitive lookup.
yyerror("unknown field '%v' in struct literal of type %v (but does have %v)", l.Sym, t, ci.Sym)
} else {
continue
}
p, _ := dotpath(l.Sym, t, nil, true)
if p == nil {
yyerror("unknown field '%v' in struct literal of type %v", l.Sym, t)
@ -3102,7 +3103,6 @@ func typecheckcomplit(n *Node) *Node {
}
ep = append(ep, l.Sym.Name)
yyerror("cannot use promoted field %v in struct literal of type %v", strings.Join(ep, "."), t)
}
continue
}
fielddup(f.Sym.Name, hash)