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