mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
cmd/compile: rename strlit, Bool, and Int64 *Node accessors
The Node type has shortcuts to access bool and int Values:
func (n *Node) Int64() int64
for n.Val().U.(*Mpint).Int64()
func (n *Node) Bool() bool
for n.Val().U.(bool)
I was convinced we didn't have one for string literal nodes, until I
noticed that we do, it's just called strlit, it's not a method, and
it's later in the file:
func strlit(n *Node) string
This change, for consistency:
- Renames strlit to StringVal and makes it a *Node method
- Renames Bool and Int64 to BoolVal and Int64Val
- Moves StringVal near the other two
Change-Id: I18e635384c35eb3a238fd52b1ccd322b1a74d733
Reviewed-on: https://go-review.googlesource.com/c/go/+/261361
Trust: Alberto Donizetti <alb.donizetti@gmail.com>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
This commit is contained in:
parent
7c58ef732e
commit
e2931612b0
10 changed files with 72 additions and 69 deletions
|
|
@ -1271,7 +1271,7 @@ func (s *state) stmt(n *Node) {
|
|||
// We're assigning a slicing operation back to its source.
|
||||
// Don't write back fields we aren't changing. See issue #14855.
|
||||
i, j, k := rhs.SliceBounds()
|
||||
if i != nil && (i.Op == OLITERAL && i.Val().Ctype() == CTINT && i.Int64() == 0) {
|
||||
if i != nil && (i.Op == OLITERAL && i.Val().Ctype() == CTINT && i.Int64Val() == 0) {
|
||||
// [0:...] is the same as [:...]
|
||||
i = nil
|
||||
}
|
||||
|
|
@ -1301,7 +1301,7 @@ func (s *state) stmt(n *Node) {
|
|||
case OIF:
|
||||
if Isconst(n.Left, CTBOOL) {
|
||||
s.stmtList(n.Left.Ninit)
|
||||
if n.Left.Bool() {
|
||||
if n.Left.BoolVal() {
|
||||
s.stmtList(n.Nbody)
|
||||
} else {
|
||||
s.stmtList(n.Rlist)
|
||||
|
|
@ -2610,7 +2610,7 @@ func (s *state) expr(n *Node) *ssa.Value {
|
|||
// Replace "abc"[1] with 'b'.
|
||||
// Delayed until now because "abc"[1] is not an ideal constant.
|
||||
// See test/fixedbugs/issue11370.go.
|
||||
return s.newValue0I(ssa.OpConst8, types.Types[TUINT8], int64(int8(strlit(n.Left)[n.Right.Int64()])))
|
||||
return s.newValue0I(ssa.OpConst8, types.Types[TUINT8], int64(int8(n.Left.StringVal()[n.Right.Int64Val()])))
|
||||
}
|
||||
a := s.expr(n.Left)
|
||||
i := s.expr(n.Right)
|
||||
|
|
@ -2619,7 +2619,7 @@ func (s *state) expr(n *Node) *ssa.Value {
|
|||
ptrtyp := s.f.Config.Types.BytePtr
|
||||
ptr := s.newValue1(ssa.OpStringPtr, ptrtyp, a)
|
||||
if Isconst(n.Right, CTINT) {
|
||||
ptr = s.newValue1I(ssa.OpOffPtr, ptrtyp, n.Right.Int64(), ptr)
|
||||
ptr = s.newValue1I(ssa.OpOffPtr, ptrtyp, n.Right.Int64Val(), ptr)
|
||||
} else {
|
||||
ptr = s.newValue2(ssa.OpAddPtr, ptrtyp, ptr, i)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue