mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
cmd/compile/internal/gc: add some Node methods
Focus on "isfoo" funcs that take a *Node, and conver them to isFoo methods instead. This makes for more idiomatic Go code, and also more readable func names. Found candidates with grep, and applied most changes with sed. The funcs chosen were isgoconst, isnil, and isblank. All had the same signature, func(*Node) bool. While at it, camelCase the isliteral and iszero function names. Don't move these to methods, as they are only used in the backend part of gc, which might one day be split into a separate package. Passes toolstash -cmp on std cmd. Change-Id: I4df081b12d36c46c253167c8841c5a841f1c5a16 Reviewed-on: https://go-review.googlesource.com/105555 Run-TryBot: Daniel Martí <mvdan@mvdan.cc> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
This commit is contained in:
parent
d69760064f
commit
2b2348ab14
16 changed files with 70 additions and 68 deletions
|
|
@ -56,7 +56,7 @@ func init1(n *Node, out *[]*Node) {
|
|||
switch n.Class() {
|
||||
case PEXTERN, PFUNC:
|
||||
default:
|
||||
if isblank(n) && n.Name.Curfn == nil && n.Name.Defn != nil && n.Name.Defn.Initorder() == InitNotStarted {
|
||||
if n.isBlank() && n.Name.Curfn == nil && n.Name.Defn != nil && n.Name.Defn.Initorder() == InitNotStarted {
|
||||
// blank names initialization is part of init() but not
|
||||
// when they are inside a function.
|
||||
break
|
||||
|
|
@ -115,7 +115,7 @@ func init1(n *Node, out *[]*Node) {
|
|||
Dump("defn", defn)
|
||||
Fatalf("init1: bad defn")
|
||||
}
|
||||
if isblank(defn.Left) && candiscard(defn.Right) {
|
||||
if defn.Left.isBlank() && candiscard(defn.Right) {
|
||||
defn.Op = OEMPTY
|
||||
defn.Left = nil
|
||||
defn.Right = nil
|
||||
|
|
@ -126,7 +126,7 @@ func init1(n *Node, out *[]*Node) {
|
|||
if Debug['j'] != 0 {
|
||||
fmt.Printf("%v\n", n.Sym)
|
||||
}
|
||||
if isblank(n) || !staticinit(n, out) {
|
||||
if n.isBlank() || !staticinit(n, out) {
|
||||
if Debug['%'] != 0 {
|
||||
Dump("nonstatic", defn)
|
||||
}
|
||||
|
|
@ -303,7 +303,7 @@ func staticcopy(l *Node, r *Node, out *[]*Node) bool {
|
|||
return true
|
||||
|
||||
case OLITERAL:
|
||||
if iszero(r) {
|
||||
if isZero(r) {
|
||||
return true
|
||||
}
|
||||
gdata(l, r, int(l.Type.Width))
|
||||
|
|
@ -380,7 +380,7 @@ func staticassign(l *Node, r *Node, out *[]*Node) bool {
|
|||
return staticcopy(l, r, out)
|
||||
|
||||
case OLITERAL:
|
||||
if iszero(r) {
|
||||
if isZero(r) {
|
||||
return true
|
||||
}
|
||||
gdata(l, r, int(l.Type.Width))
|
||||
|
|
@ -578,7 +578,7 @@ func staticname(t *types.Type) *Node {
|
|||
return n
|
||||
}
|
||||
|
||||
func isliteral(n *Node) bool {
|
||||
func isLiteral(n *Node) bool {
|
||||
// Treat nils as zeros rather than literals.
|
||||
return n.Op == OLITERAL && n.Val().Ctype() != CTNIL
|
||||
}
|
||||
|
|
@ -607,7 +607,7 @@ const (
|
|||
func getdyn(n *Node, top bool) initGenType {
|
||||
switch n.Op {
|
||||
default:
|
||||
if isliteral(n) {
|
||||
if isLiteral(n) {
|
||||
return initConst
|
||||
}
|
||||
return initDynamic
|
||||
|
|
@ -742,7 +742,7 @@ func fixedlit(ctxt initContext, kind initKind, n *Node, var_ *Node, init *Nodes)
|
|||
continue
|
||||
}
|
||||
|
||||
islit := isliteral(value)
|
||||
islit := isLiteral(value)
|
||||
if (kind == initKindStatic && !islit) || (kind == initKindDynamic && islit) {
|
||||
continue
|
||||
}
|
||||
|
|
@ -898,7 +898,7 @@ func slicelit(ctxt initContext, n *Node, var_ *Node, init *Nodes) {
|
|||
continue
|
||||
}
|
||||
|
||||
if isliteral(value) {
|
||||
if isLiteral(value) {
|
||||
continue
|
||||
}
|
||||
|
||||
|
|
@ -1264,7 +1264,7 @@ func initplan(n *Node) {
|
|||
|
||||
func addvalue(p *InitPlan, xoffset int64, n *Node) {
|
||||
// special case: zero can be dropped entirely
|
||||
if iszero(n) {
|
||||
if isZero(n) {
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -1284,13 +1284,13 @@ func addvalue(p *InitPlan, xoffset int64, n *Node) {
|
|||
p.E = append(p.E, InitEntry{Xoffset: xoffset, Expr: n})
|
||||
}
|
||||
|
||||
func iszero(n *Node) bool {
|
||||
func isZero(n *Node) bool {
|
||||
switch n.Op {
|
||||
case OLITERAL:
|
||||
switch u := n.Val().U.(type) {
|
||||
default:
|
||||
Dump("unexpected literal", n)
|
||||
Fatalf("iszero")
|
||||
Fatalf("isZero")
|
||||
case *NilVal:
|
||||
return true
|
||||
case string:
|
||||
|
|
@ -1310,7 +1310,7 @@ func iszero(n *Node) bool {
|
|||
if n1.Op == OKEY {
|
||||
n1 = n1.Right
|
||||
}
|
||||
if !iszero(n1) {
|
||||
if !isZero(n1) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
|
@ -1318,7 +1318,7 @@ func iszero(n *Node) bool {
|
|||
|
||||
case OSTRUCTLIT:
|
||||
for _, n1 := range n.List.Slice() {
|
||||
if !iszero(n1.Left) {
|
||||
if !isZero(n1.Left) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue