Commit fcfea247 authored by Daniel Martí's avatar Daniel Martí

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: default avatarMatthew Dempsky <mdempsky@google.com>
Reviewed-by: default avatarBrad Fitzpatrick <bradfitz@golang.org>
parent 97677273
...@@ -332,13 +332,10 @@ func ismulticall(l Nodes) bool { ...@@ -332,13 +332,10 @@ func ismulticall(l Nodes) bool {
switch n.Op { switch n.Op {
default: default:
return false return false
case OCALLFUNC, OCALLMETH, OCALLINTER: case OCALLFUNC, OCALLMETH, OCALLINTER:
break
}
// call must return multiple values // call must return multiple values
return n.Left.Type.NumResults() > 1 return n.Left.Type.NumResults() > 1
}
} }
// copyRet emits t1, t2, ... = n, where n is a function call, // copyRet emits t1, t2, ... = n, where n is a function call,
...@@ -381,7 +378,9 @@ func (o *Order) call(n *Node) { ...@@ -381,7 +378,9 @@ func (o *Order) call(n *Node) {
n.Right = o.expr(n.Right, nil) // ODDDARG temp n.Right = o.expr(n.Right, nil) // ODDDARG temp
o.callArgs(&n.List) o.callArgs(&n.List)
if n.Op == OCALLFUNC { if n.Op != OCALLFUNC {
return
}
keepAlive := func(i int) { keepAlive := func(i int) {
// If the argument is really a pointer being converted to uintptr, // If the argument is really a pointer being converted to uintptr,
// arrange for the pointer to be kept alive until the call returns, // arrange for the pointer to be kept alive until the call returns,
...@@ -413,7 +412,6 @@ func (o *Order) call(n *Node) { ...@@ -413,7 +412,6 @@ func (o *Order) call(n *Node) {
} }
} }
} }
}
} }
// mapAssign appends n to o.out, introducing temporaries // mapAssign appends n to o.out, introducing temporaries
...@@ -766,7 +764,9 @@ func (o *Order) stmt(n *Node) { ...@@ -766,7 +764,9 @@ func (o *Order) stmt(n *Node) {
if n2.Ninit.Len() != 0 { if n2.Ninit.Len() != 0 {
Fatalf("order select ninit") Fatalf("order select ninit")
} }
if r != nil { if r == nil {
continue
}
switch r.Op { switch r.Op {
default: default:
Dump("select case", r) Dump("select case", r)
...@@ -870,13 +870,11 @@ func (o *Order) stmt(n *Node) { ...@@ -870,13 +870,11 @@ func (o *Order) stmt(n *Node) {
} }
} }
} }
orderBlock(&n2.Nbody)
}
// Now that we have accumulated all the temporaries, clean them. // Now that we have accumulated all the temporaries, clean them.
// Also insert any ninit queued during the previous loop. // Also insert any ninit queued during the previous loop.
// (The temporary cleaning must follow that ninit work.) // (The temporary cleaning must follow that ninit work.)
for _, n3 := range n.List.Slice() { for _, n3 := range n.List.Slice() {
orderBlock(&n3.Nbody)
n3.Nbody.Prepend(o.cleanTempNoPop(t)...) n3.Nbody.Prepend(o.cleanTempNoPop(t)...)
// TODO(mdempsky): Is this actually necessary? // TODO(mdempsky): Is this actually necessary?
......
...@@ -347,10 +347,13 @@ func staticcopy(l *Node, r *Node, out *[]*Node) bool { ...@@ -347,10 +347,13 @@ func staticcopy(l *Node, r *Node, out *[]*Node) bool {
n.Type = e.Expr.Type n.Type = e.Expr.Type
if e.Expr.Op == OLITERAL { if e.Expr.Op == OLITERAL {
gdata(n, e.Expr, int(n.Type.Width)) gdata(n, e.Expr, int(n.Type.Width))
} else { continue
}
ll := n.copy() ll := n.copy()
ll.Orig = ll // completely separate 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 // Requires computation, but we're
// copying someone else's computation. // copying someone else's computation.
rr := orig.copy() rr := orig.copy()
...@@ -360,8 +363,6 @@ func staticcopy(l *Node, r *Node, out *[]*Node) bool { ...@@ -360,8 +363,6 @@ func staticcopy(l *Node, r *Node, out *[]*Node) bool {
setlineno(rr) setlineno(rr)
*out = append(*out, nod(OAS, ll, rr)) *out = append(*out, nod(OAS, ll, rr))
} }
}
}
return true return true
} }
...@@ -449,7 +450,8 @@ func staticassign(l *Node, r *Node, out *[]*Node) bool { ...@@ -449,7 +450,8 @@ func staticassign(l *Node, r *Node, out *[]*Node) bool {
n.Type = e.Expr.Type n.Type = e.Expr.Type
if e.Expr.Op == OLITERAL { if e.Expr.Op == OLITERAL {
gdata(n, e.Expr, int(n.Type.Width)) gdata(n, e.Expr, int(n.Type.Width))
} else { continue
}
setlineno(e.Expr) setlineno(e.Expr)
a := n.copy() a := n.copy()
a.Orig = a // completely separate copy a.Orig = a // completely separate copy
...@@ -457,7 +459,6 @@ func staticassign(l *Node, r *Node, out *[]*Node) bool { ...@@ -457,7 +459,6 @@ func staticassign(l *Node, r *Node, out *[]*Node) bool {
*out = append(*out, nod(OAS, a, e.Expr)) *out = append(*out, nod(OAS, a, e.Expr))
} }
} }
}
return true return true
......
...@@ -3089,7 +3089,8 @@ func typecheckcomplit(n *Node) *Node { ...@@ -3089,7 +3089,8 @@ func typecheckcomplit(n *Node) *Node {
if f == nil { if f == nil {
if ci := lookdot1(nil, l.Sym, t, t.Fields(), 2); ci != nil { // Case-insensitive lookup. 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) 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) p, _ := dotpath(l.Sym, t, nil, true)
if p == nil { if p == nil {
yyerror("unknown field '%v' in struct literal of type %v", l.Sym, t) yyerror("unknown field '%v' in struct literal of type %v", l.Sym, t)
...@@ -3102,7 +3103,6 @@ func typecheckcomplit(n *Node) *Node { ...@@ -3102,7 +3103,6 @@ func typecheckcomplit(n *Node) *Node {
} }
ep = append(ep, l.Sym.Name) ep = append(ep, l.Sym.Name)
yyerror("cannot use promoted field %v in struct literal of type %v", strings.Join(ep, "."), t) yyerror("cannot use promoted field %v in struct literal of type %v", strings.Join(ep, "."), t)
}
continue continue
} }
fielddup(f.Sym.Name, hash) fielddup(f.Sym.Name, hash)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment