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
|
|
@ -1506,12 +1506,14 @@ func nonnegintconst(n *Node) int64 {
|
|||
return vi.Int64()
|
||||
}
|
||||
|
||||
// Is n a Go language constant (as opposed to a compile-time constant)?
|
||||
// isGoConst reports whether n is a Go language constant (as opposed to a
|
||||
// compile-time constant).
|
||||
//
|
||||
// Expressions derived from nil, like string([]byte(nil)), while they
|
||||
// may be known at compile time, are not Go language constants.
|
||||
// Only called for expressions known to evaluated to compile-time
|
||||
// constants.
|
||||
func isgoconst(n *Node) bool {
|
||||
func (n *Node) isGoConst() bool {
|
||||
if n.Orig != nil {
|
||||
n = n.Orig
|
||||
}
|
||||
|
|
@ -1545,18 +1547,18 @@ func isgoconst(n *Node) bool {
|
|||
OCOMPLEX,
|
||||
OREAL,
|
||||
OIMAG:
|
||||
if isgoconst(n.Left) && (n.Right == nil || isgoconst(n.Right)) {
|
||||
if n.Left.isGoConst() && (n.Right == nil || n.Right.isGoConst()) {
|
||||
return true
|
||||
}
|
||||
|
||||
case OCONV:
|
||||
if okforconst[n.Type.Etype] && isgoconst(n.Left) {
|
||||
if okforconst[n.Type.Etype] && n.Left.isGoConst() {
|
||||
return true
|
||||
}
|
||||
|
||||
case OLEN, OCAP:
|
||||
l := n.Left
|
||||
if isgoconst(l) {
|
||||
if l.isGoConst() {
|
||||
return true
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue