Commit d33e37a7 authored by Josh Bleecher Snyder's avatar Josh Bleecher Snyder

cmd/compile: further sinit.go cleanup

Follow-up to CL 20674.

Passes toolstash -cmp.

Change-Id: I065fd4cd80d996c1e6566773189401ca4630c1ca
Reviewed-on: https://go-review.googlesource.com/20692
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: 's avatarDave Cheney <dave@cheney.net>
parent 82625649
...@@ -514,7 +514,7 @@ func isliteral(n *Node) bool { ...@@ -514,7 +514,7 @@ func isliteral(n *Node) bool {
return n.Op == OLITERAL && n.Val().Ctype() != CTNIL return n.Op == OLITERAL && n.Val().Ctype() != CTNIL
} }
func simplename(n *Node) bool { func (n *Node) isSimpleName() bool {
return n.Op == ONAME && n.Addable && n.Class&PHEAP == 0 && n.Class != PPARAMREF return n.Op == ONAME && n.Addable && n.Class&PHEAP == 0 && n.Class != PPARAMREF
} }
...@@ -1045,7 +1045,7 @@ func anylit(ctxt int, n *Node, var_ *Node, init *Nodes) { ...@@ -1045,7 +1045,7 @@ func anylit(ctxt int, n *Node, var_ *Node, init *Nodes) {
Fatalf("anylit: not struct") Fatalf("anylit: not struct")
} }
if simplename(var_) && n.List.Len() > 4 { if var_.isSimpleName() && n.List.Len() > 4 {
if ctxt == 0 { if ctxt == 0 {
// lay out static data // lay out static data
vstat := staticname(t, ctxt) vstat := staticname(t, ctxt)
...@@ -1071,7 +1071,7 @@ func anylit(ctxt int, n *Node, var_ *Node, init *Nodes) { ...@@ -1071,7 +1071,7 @@ func anylit(ctxt int, n *Node, var_ *Node, init *Nodes) {
} }
// initialize of not completely specified // initialize of not completely specified
if simplename(var_) || n.List.Len() < structcount(t) { if var_.isSimpleName() || n.List.Len() < structcount(t) {
a := Nod(OAS, var_, nil) a := Nod(OAS, var_, nil)
typecheck(&a, Etop) typecheck(&a, Etop)
walkexpr(&a, init) walkexpr(&a, init)
...@@ -1089,7 +1089,7 @@ func anylit(ctxt int, n *Node, var_ *Node, init *Nodes) { ...@@ -1089,7 +1089,7 @@ func anylit(ctxt int, n *Node, var_ *Node, init *Nodes) {
break break
} }
if simplename(var_) && n.List.Len() > 4 { if var_.isSimpleName() && n.List.Len() > 4 {
if ctxt == 0 { if ctxt == 0 {
// lay out static data // lay out static data
vstat := staticname(t, ctxt) vstat := staticname(t, ctxt)
...@@ -1115,7 +1115,7 @@ func anylit(ctxt int, n *Node, var_ *Node, init *Nodes) { ...@@ -1115,7 +1115,7 @@ func anylit(ctxt int, n *Node, var_ *Node, init *Nodes) {
} }
// initialize of not completely specified // initialize of not completely specified
if simplename(var_) || int64(n.List.Len()) < t.Bound { if var_.isSimpleName() || int64(n.List.Len()) < t.Bound {
a := Nod(OAS, var_, nil) a := Nod(OAS, var_, nil)
typecheck(&a, Etop) typecheck(&a, Etop)
walkexpr(&a, init) walkexpr(&a, init)
...@@ -1141,7 +1141,7 @@ func oaslit(n *Node, init *Nodes) bool { ...@@ -1141,7 +1141,7 @@ func oaslit(n *Node, init *Nodes) bool {
// not a special composit literal assignment // not a special composit literal assignment
return false return false
} }
if !simplename(n.Left) { if !n.Left.isSimpleName() {
// not a special composit literal assignment // not a special composit literal assignment
return false return false
} }
...@@ -1337,85 +1337,79 @@ func isvaluelit(n *Node) bool { ...@@ -1337,85 +1337,79 @@ func isvaluelit(n *Node) bool {
// gen_as_init attempts to emit static data for n and reports whether it succeeded. // gen_as_init attempts to emit static data for n and reports whether it succeeded.
// If reportOnly is true, it does not emit static data and does not modify the AST. // If reportOnly is true, it does not emit static data and does not modify the AST.
func gen_as_init(n *Node, reportOnly bool) bool { func gen_as_init(n *Node, reportOnly bool) bool {
var nr *Node success := genAsInitNoCheck(n, reportOnly)
var nl *Node if !success && n.Dodata == 2 {
var nam Node Dump("\ngen_as_init", n)
Fatalf("gen_as_init couldn't make data statement")
}
return success
}
func genAsInitNoCheck(n *Node, reportOnly bool) bool {
if n.Dodata == 0 { if n.Dodata == 0 {
goto no return false
} }
nr = n.Right nr := n.Right
nl = n.Left nl := n.Left
if nr == nil { if nr == nil {
var nam Node var nam Node
if !stataddr(&nam, nl) { return stataddr(&nam, nl) && nam.Class == PEXTERN
goto no
}
if nam.Class != PEXTERN {
goto no
}
return true
} }
if nr.Type == nil || !Eqtype(nl.Type, nr.Type) { if nr.Type == nil || !Eqtype(nl.Type, nr.Type) {
goto no return false
}
if !stataddr(&nam, nl) {
goto no
} }
if nam.Class != PEXTERN { var nam Node
goto no if !stataddr(&nam, nl) || nam.Class != PEXTERN {
return false
} }
switch nr.Op { switch nr.Op {
default: default:
goto no return false
case OCONVNOP: case OCONVNOP:
nr = nr.Left nr = nr.Left
if nr == nil || nr.Op != OSLICEARR { if nr == nil || nr.Op != OSLICEARR {
goto no return false
} }
fallthrough fallthrough
// fall through
case OSLICEARR: case OSLICEARR:
if nr.Right.Op == OKEY && nr.Right.Left == nil && nr.Right.Right == nil { if nr.Right.Op != OKEY || nr.Right.Left != nil || nr.Right.Right != nil {
nr = nr.Left return false
nl := nr }
if nr == nil || nr.Op != OADDR { nr = nr.Left
goto no if nr == nil || nr.Op != OADDR {
} return false
nr = nr.Left }
if nr == nil || nr.Op != ONAME { ptr := nr
goto no nr = nr.Left
} if nr == nil || nr.Op != ONAME {
return false
// nr is the array being converted to a slice }
if nr.Type == nil || nr.Type.Etype != TARRAY || nr.Type.Bound < 0 {
goto no
}
if !reportOnly { // nr is the array being converted to a slice
nam.Xoffset += int64(Array_array) if nr.Type == nil || nr.Type.Etype != TARRAY || nr.Type.Bound < 0 {
gdata(&nam, nl, int(Types[Tptr].Width)) return false
}
nam.Xoffset += int64(Array_nel) - int64(Array_array) if !reportOnly {
var nod1 Node nam.Xoffset += int64(Array_array)
Nodconst(&nod1, Types[TINT], nr.Type.Bound) gdata(&nam, ptr, Widthptr)
gdata(&nam, &nod1, Widthint)
nam.Xoffset += int64(Array_cap) - int64(Array_nel) nam.Xoffset += int64(Array_nel) - int64(Array_array)
gdata(&nam, &nod1, Widthint) var nod1 Node
} Nodconst(&nod1, Types[TINT], nr.Type.Bound)
gdata(&nam, &nod1, Widthint)
return true nam.Xoffset += int64(Array_cap) - int64(Array_nel)
gdata(&nam, &nod1, Widthint)
} }
goto no return true
case OLITERAL: case OLITERAL:
break break
...@@ -1423,7 +1417,7 @@ func gen_as_init(n *Node, reportOnly bool) bool { ...@@ -1423,7 +1417,7 @@ func gen_as_init(n *Node, reportOnly bool) bool {
switch nr.Type.Etype { switch nr.Type.Etype {
default: default:
goto no return false
case TBOOL, TINT8, TUINT8, TINT16, TUINT16, case TBOOL, TINT8, TUINT8, TINT16, TUINT16,
TINT32, TUINT32, TINT64, TUINT64, TINT32, TUINT32, TINT64, TUINT64,
...@@ -1446,12 +1440,4 @@ func gen_as_init(n *Node, reportOnly bool) bool { ...@@ -1446,12 +1440,4 @@ func gen_as_init(n *Node, reportOnly bool) bool {
} }
return true return true
no:
if n.Dodata == 2 {
Dump("\ngen_as_init", n)
Fatalf("gen_as_init couldnt make data statement")
}
return false
} }
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