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

[dev.regabi] cmd/compile: use *ir.Name instead of ir.Node for CaseClause.Var

Passes toolstash -cmp.

Change-Id: Ib0b6ebf5751ffce2c9500dc67d78e54937ead208
Reviewed-on: https://go-review.googlesource.com/c/go/+/279449
Trust: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
This commit is contained in:
Cuong Manh Le 2020-12-30 01:24:30 +07:00
parent 37babc97bb
commit 850aa7c60c
6 changed files with 12 additions and 8 deletions

View File

@ -374,7 +374,7 @@ func (e *escape) stmt(n ir.Node) {
var ks []hole
for _, cas := range n.Cases { // cases
if typesw && n.Tag.(*ir.TypeSwitchGuard).Tag != nil {
cv := cas.Var.(*ir.Name)
cv := cas.Var
k := e.dcl(cv) // type switch variables have no ODCL.
if cv.Type().HasPointers() {
ks = append(ks, k.dotType(cv.Type(), cas, "switch case"))

View File

@ -230,14 +230,18 @@ func (n *CaseClause) copy() Node {
func (n *CaseClause) doChildren(do func(Node) error) error {
var err error
err = maybeDoList(n.init, err, do)
err = maybeDo(n.Var, err, do)
if n.Var != nil {
err = maybeDo(n.Var, err, do)
}
err = maybeDoList(n.List, err, do)
err = maybeDoList(n.Body, err, do)
return err
}
func (n *CaseClause) editChildren(edit func(Node) Node) {
editList(n.init, edit)
n.Var = maybeEdit(n.Var, edit)
if n.Var != nil {
n.Var = edit(n.Var).(*Name)
}
editList(n.List, edit)
editList(n.Body, edit)
}

View File

@ -172,7 +172,7 @@ func (n *BranchStmt) Sym() *types.Sym { return n.Label }
// A CaseClause is a case statement in a switch or select: case List: Body.
type CaseClause struct {
miniStmt
Var Node // declared variable for this case in type switch
Var *Name // declared variable for this case in type switch
List Nodes // list of expressions for switch, early select
Body Nodes
}

View File

@ -1187,7 +1187,7 @@ func (w *exportWriter) caseList(cases []*ir.CaseClause, namedTypeSwitch bool) {
w.pos(cas.Pos())
w.stmtList(cas.List)
if namedTypeSwitch {
w.localName(cas.Var.(*ir.Name))
w.localName(cas.Var)
}
w.stmtList(cas.Body)
}

View File

@ -631,7 +631,7 @@ func tcSwitchType(n *ir.SwitchStmt) {
nvar := ncase.Var
nvar.SetType(vt)
if vt != nil {
nvar = AssignExpr(nvar)
nvar = AssignExpr(nvar).(*ir.Name)
} else {
// Clause variable is broken; prevent typechecking.
nvar.SetTypecheck(1)

View File

@ -440,7 +440,7 @@ type typeClause struct {
body ir.Nodes
}
func (s *typeSwitch) Add(pos src.XPos, typ *types.Type, caseVar, jmp ir.Node) {
func (s *typeSwitch) Add(pos src.XPos, typ *types.Type, caseVar *ir.Name, jmp ir.Node) {
var body ir.Nodes
if caseVar != nil {
l := []ir.Node{
@ -450,7 +450,7 @@ func (s *typeSwitch) Add(pos src.XPos, typ *types.Type, caseVar, jmp ir.Node) {
typecheck.Stmts(l)
body.Append(l...)
} else {
caseVar = ir.BlankNode
caseVar = ir.BlankNode.(*ir.Name)
}
// cv, ok = iface.(type)