[dev.regabi] cmd/compile: use []*CaseStmt in {Select,Switch}Stmt

Select and switch statements only ever contain case statements, so
change their Cases fields from Nodes to []*CaseStmt. This allows
removing a bunch of type assertions throughout the compiler.

CaseStmt should be renamed to CaseClause, and SelectStmt should
probably have its own CommClause type instead (like in go/ast and
cmd/compile/internal/syntax), but this is a good start.

Passes toolstash -cmp.

Change-Id: I2d41d616d44512c2be421e1e2ff13d0ee8b238ad
Reviewed-on: https://go-review.googlesource.com/c/go/+/280442
Trust: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
This commit is contained in:
Matthew Dempsky 2020-12-26 22:23:45 -08:00
parent fbc4458c06
commit a59d26603f
13 changed files with 73 additions and 53 deletions

View file

@ -71,7 +71,6 @@ func walkSwitchExpr(sw *ir.SwitchStmt) {
var defaultGoto ir.Node
var body ir.Nodes
for _, ncase := range sw.Cases {
ncase := ncase.(*ir.CaseStmt)
label := typecheck.AutoLabel(".s")
jmp := ir.NewBranchStmt(ncase.Pos(), ir.OGOTO, label)
@ -96,7 +95,7 @@ func walkSwitchExpr(sw *ir.SwitchStmt) {
body.Append(br)
}
}
sw.Cases.Set(nil)
sw.Cases = nil
if defaultGoto == nil {
br := ir.NewBranchStmt(base.Pos, ir.OBREAK, nil)
@ -259,7 +258,6 @@ func allCaseExprsAreSideEffectFree(sw *ir.SwitchStmt) bool {
// enough.
for _, ncase := range sw.Cases {
ncase := ncase.(*ir.CaseStmt)
for _, v := range ncase.List {
if v.Op() != ir.OLITERAL {
return false
@ -325,7 +323,6 @@ func walkSwitchType(sw *ir.SwitchStmt) {
var defaultGoto, nilGoto ir.Node
var body ir.Nodes
for _, ncase := range sw.Cases {
ncase := ncase.(*ir.CaseStmt)
caseVar := ncase.Var
// For single-type cases with an interface type,
@ -384,7 +381,7 @@ func walkSwitchType(sw *ir.SwitchStmt) {
body.Append(ncase.Body...)
body.Append(br)
}
sw.Cases.Set(nil)
sw.Cases = nil
if defaultGoto == nil {
defaultGoto = br