cmd: remove some unnecessary gotos

Pick the low-hanging fruit, which are the gotos that don't go very far
and labels that aren't used often. All of them have easy replacements
with breaks and returns.

One slightly tricky rewrite is defaultlitreuse. We cannot use a defer
func to reset lineno, because one of its return paths does not reset
lineno, and thus broke toolstash -cmp.

Passes toolstash -cmp on std cmd.

Change-Id: Id1c0967868d69bb073addc7c5c3017ca91ff966f
Reviewed-on: https://go-review.googlesource.com/110063
Run-TryBot: Daniel Martí <mvdan@mvdan.cc>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
This commit is contained in:
Daniel Martí 2018-04-29 22:17:23 +09:00
parent 030ac2c719
commit 9ecf899b29
7 changed files with 25 additions and 41 deletions

View file

@ -1344,6 +1344,8 @@ func defaultlitreuse(n *Node, t *types.Type, reuse canReuseNode) *Node {
default:
yyerror("defaultlit: unknown literal: %v", n)
}
lineno = lno
return n
case CTxxx:
Fatalf("defaultlit: idealkind is CTxxx: %+v", n)
@ -1354,28 +1356,19 @@ func defaultlitreuse(n *Node, t *types.Type, reuse canReuseNode) *Node {
t1 = t
}
n = convlit1(n, t1, false, reuse)
lineno = lno
return n
case CTINT:
t1 = types.Types[TINT]
goto num
case CTRUNE:
t1 = types.Runetype
goto num
case CTFLT:
t1 = types.Types[TFLOAT64]
goto num
case CTCPLX:
t1 = types.Types[TCOMPLEX128]
goto num
}
lineno = lno
return n
num:
// Note: n.Val().Ctype() can be CTxxx (not a constant) here
// in the case of an untyped non-constant value, like 1<<i.
v1 := n.Val()