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

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: Dave Cheney <dave@cheney.net>
This commit is contained in:
Josh Bleecher Snyder 2016-03-14 14:03:57 -07:00
parent 8262564971
commit d33e37a7e3

View File

@ -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) {
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) {
} }
// 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) {
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) {
} }
// 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 {
// 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,71 +1337,68 @@ 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) { var nam Node
goto no if !stataddr(&nam, nl) || nam.Class != PEXTERN {
} return false
if nam.Class != PEXTERN {
goto no
} }
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 {
goto no
} }
nr = nr.Left nr = nr.Left
if nr == nil || nr.Op != OADDR {
return false
}
ptr := nr
nr = nr.Left
if nr == nil || nr.Op != ONAME { if nr == nil || nr.Op != ONAME {
goto no return false
} }
// nr is the array being converted to a slice // nr is the array being converted to a slice
if nr.Type == nil || nr.Type.Etype != TARRAY || nr.Type.Bound < 0 { if nr.Type == nil || nr.Type.Etype != TARRAY || nr.Type.Bound < 0 {
goto no return false
} }
if !reportOnly { if !reportOnly {
nam.Xoffset += int64(Array_array) nam.Xoffset += int64(Array_array)
gdata(&nam, nl, int(Types[Tptr].Width)) gdata(&nam, ptr, Widthptr)
nam.Xoffset += int64(Array_nel) - int64(Array_array) nam.Xoffset += int64(Array_nel) - int64(Array_array)
var nod1 Node var nod1 Node
@ -1413,9 +1410,6 @@ func gen_as_init(n *Node, reportOnly bool) bool {
} }
return true return true
}
goto no
case OLITERAL: case OLITERAL:
break break
@ -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 {
} }
return true return true
no:
if n.Dodata == 2 {
Dump("\ngen_as_init", n)
Fatalf("gen_as_init couldnt make data statement")
}
return false
} }