Commit da094f19 authored by Russ Cox's avatar Russ Cox

cmd/compile: move OCASE/OXCASE Node.Nname into Node.Rlist (type switch variable)

$ sizeof -p cmd/compile/internal/gc Node
Node 168
$

Change-Id: I22bcea8099f308298c9db75c937f35e7fca906f1
Reviewed-on: https://go-review.googlesource.com/10535Reviewed-by: default avatarIan Lance Taylor <iant@golang.org>
Reviewed-by: default avatarJosh Bleecher Snyder <josharian@gmail.com>
parent bd4fff63
......@@ -604,9 +604,9 @@ func esc(e *EscState, n *Node, up *Node) {
if n.Op == OSWITCH && n.Left != nil && n.Left.Op == OTYPESW {
for ll := n.List; ll != nil; ll = ll.Next { // cases
// ll->n->nname is the variable per case
if ll.N.Nname != nil {
e.nodeEscState(ll.N.Nname).Escloopdepth = e.loopdepth
// ll.N.Rlist is the variable per case
if ll.N.Rlist != nil {
e.nodeEscState(ll.N.Rlist.N).Escloopdepth = e.loopdepth
}
}
}
......@@ -677,9 +677,11 @@ func esc(e *EscState, n *Node, up *Node) {
if n.Left != nil && n.Left.Op == OTYPESW {
for ll := n.List; ll != nil; ll = ll.Next {
// cases
// ntest->right is the argument of the .(type),
// ll->n->nname is the variable per case
escassign(e, ll.N.Nname, n.Left.Right)
// n.Left.Right is the argument of the .(type),
// ll.N.Rlist is the variable per case
if ll.N.Rlist != nil {
escassign(e, ll.N.Rlist.N, n.Left.Right)
}
}
}
......
......@@ -549,7 +549,7 @@ case:
// type switch - declare variable
nn = newname(n.Sym);
declare(nn, dclcontext);
$$.Nname = nn;
$$.Rlist = list1(nn);
// keep track of the instances for reporting unused
nn.Name.Defn = typesw.Right;
......@@ -595,7 +595,7 @@ case:
// type switch - declare variable
nn = newname(n.Sym);
declare(nn, dclcontext);
$$.Nname = nn;
$$.Rlist = list1(nn);
// keep track of the instances for reporting unused
nn.Name.Defn = typesw.Right;
......
......@@ -165,8 +165,8 @@ func typecheckswitch(n *Node) {
if top == Etype && n.Type != nil {
ll = ncase.List
nvar := ncase.Nname
if nvar != nil {
if ncase.Rlist != nil {
nvar := ncase.Rlist.N
if ll != nil && ll.Next == nil && ll.N.Type != nil && !Istype(ll.N.Type, TNIL) {
// single entry type switch
nvar.Name.Param.Ntype = typenod(ll.N.Type)
......@@ -176,7 +176,7 @@ func typecheckswitch(n *Node) {
}
typecheck(&nvar, Erv|Easgn)
ncase.Nname = nvar
ncase.Rlist.N = nvar
}
}
......@@ -378,9 +378,9 @@ func casebody(sw *Node, typeswvar *Node) {
}
stat = list(stat, Nod(OLABEL, jmp.Left, nil))
if typeswvar != nil && needvar && n.Nname != nil {
l := list1(Nod(ODCL, n.Nname, nil))
l = list(l, Nod(OAS, n.Nname, typeswvar))
if typeswvar != nil && needvar && n.Rlist != nil {
l := list1(Nod(ODCL, n.Rlist.N, nil))
l = list(l, Nod(OAS, n.Rlist.N, typeswvar))
typechecklist(l, Etop)
stat = concat(stat, l)
}
......@@ -645,12 +645,13 @@ func (s *typeSwitch) walk(sw *Node) {
// typeone generates an AST that jumps to the
// case body if the variable is of type t.
func (s *typeSwitch) typeone(t *Node) *Node {
name := t.Nname
var name *Node
var init *NodeList
if name == nil {
typecheck(&nblank, Erv|Easgn)
if t.Rlist == nil {
name = nblank
typecheck(&nblank, Erv|Easgn)
} else {
name = t.Rlist.N
init = list1(Nod(ODCL, name, nil))
}
......
......@@ -1618,7 +1618,7 @@ yydefault:
// type switch - declare variable
nn = newname(n.Sym)
declare(nn, dclcontext)
yyVAL.node.Nname = nn
yyVAL.node.Rlist = list1(nn)
// keep track of the instances for reporting unused
nn.Name.Defn = typesw.Right
......@@ -1670,7 +1670,7 @@ yydefault:
// type switch - declare variable
nn = newname(n.Sym)
declare(nn, dclcontext)
yyVAL.node.Nname = nn
yyVAL.node.Rlist = list1(nn)
// keep track of the instances for reporting unused
nn.Name.Defn = typesw.Right
......
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