Passes toolstash-check.
Change-Id: Ieaef20b7649787727b69469f93ffc942022bc079
Reviewed-on: https://go-review.googlesource.com/c/go/+/195198
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
var strs []string
i2 := i1
for i2 < len(s) && Isconst(s[i2], CTSTR) {
- strs = append(strs, s[i2].Val().U.(string))
+ strs = append(strs, strlit(s[i2]))
i2++
}
switch nl.Type.Etype {
case TSTRING:
if Isconst(nl, CTSTR) {
- setintconst(n, int64(len(nl.Val().U.(string))))
+ setintconst(n, int64(len(strlit(nl))))
}
case TARRAY:
if !hascallchan(nl) {
n := p.expr(x)
if Isconst(n, CTSTR) && n.Sym == nil {
nstr = n
- chunks = append(chunks, nstr.Val().U.(string))
+ chunks = append(chunks, strlit(nstr))
}
for i := len(adds) - 1; i >= 0; i-- {
if Isconst(r, CTSTR) && r.Sym == nil {
if nstr != nil {
// Collapse r into nstr instead of adding to n.
- chunks = append(chunks, r.Val().U.(string))
+ chunks = append(chunks, strlit(r))
continue
}
nstr = r
- chunks = append(chunks, nstr.Val().U.(string))
+ chunks = append(chunks, strlit(nstr))
} else {
if len(chunks) > 1 {
nstr.SetVal(Val{U: strings.Join(chunks, "")})
haslit := false
for _, n1 := range n.List.Slice() {
hasbyte = hasbyte || n1.Op == OBYTES2STR
- haslit = haslit || n1.Op == OLITERAL && len(n1.Val().U.(string)) != 0
+ haslit = haslit || n1.Op == OLITERAL && len(strlit(n1)) != 0
}
if haslit && hasbyte {
case OSTR2BYTES:
if l.Class() == PEXTERN && r.Left.Op == OLITERAL {
- sval := r.Left.Val().U.(string)
+ sval := strlit(r.Left)
slicebytes(l, sval, len(sval))
return true
}
// 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(n.Left.Val().U.(string)[n.Right.Int64()])))
+ return s.newValue0I(ssa.OpConst8, types.Types[TUINT8], int64(int8(strlit(n.Left)[n.Right.Int64()])))
}
a := s.expr(n.Left)
i := s.expr(n.Right)
yyerror("invalid %s index %v (index must be non-negative)", why, n.Right)
} else if t.IsArray() && x >= t.NumElem() {
yyerror("invalid array index %v (out of bounds for %d-element array)", n.Right, t.NumElem())
- } else if Isconst(n.Left, CTSTR) && x >= int64(len(n.Left.Val().U.(string))) {
- yyerror("invalid string index %v (out of bounds for %d-byte string)", n.Right, len(n.Left.Val().U.(string)))
+ } else if Isconst(n.Left, CTSTR) && x >= int64(len(strlit(n.Left))) {
+ yyerror("invalid string index %v (out of bounds for %d-byte string)", n.Right, len(strlit(n.Left)))
} else if n.Right.Val().U.(*Mpint).Cmp(maxintval[TINT]) > 0 {
yyerror("invalid %s index %v (index too large)", why, n.Right)
}
} else if tp != nil && tp.NumElem() >= 0 && r.Int64() > tp.NumElem() {
yyerror("invalid slice index %v (out of bounds for %d-element array)", r, tp.NumElem())
return false
- } else if Isconst(l, CTSTR) && r.Int64() > int64(len(l.Val().U.(string))) {
- yyerror("invalid slice index %v (out of bounds for %d-byte string)", r, len(l.Val().U.(string)))
+ } else if Isconst(l, CTSTR) && r.Int64() > int64(len(strlit(l))) {
+ yyerror("invalid slice index %v (out of bounds for %d-byte string)", r, len(strlit(l)))
return false
} else if r.Val().U.(*Mpint).Cmp(maxintval[TINT]) > 0 {
yyerror("invalid slice index %v (index too large)", r)
}
var l []*Node
- s := n.Left.Val().U.(string)
+ s := strlit(n.Left)
i := 0
for _, r := range s {
l = append(l, nod(OKEY, nodintconst(int64(i)), nodintconst(int64(r))))
yyerror("index out of bounds")
}
} else if Isconst(n.Left, CTSTR) {
- n.SetBounded(bounded(r, int64(len(n.Left.Val().U.(string)))))
+ n.SetBounded(bounded(r, int64(len(strlit(n.Left)))))
if Debug['m'] != 0 && n.Bounded() && !Isconst(n.Right, CTINT) {
Warn("index bounds check elided")
}
case OSTR2BYTES:
s := n.Left
if Isconst(s, CTSTR) {
- sc := s.Val().U.(string)
+ sc := strlit(s)
// Allocate a [n]byte of the right size.
t := types.NewArray(types.Types[TUINT8], int64(len(sc)))
for i := 0; i < len(s); {
var strs []string
for i < len(s) && Isconst(s[i], CTSTR) {
- strs = append(strs, s[i].Val().U.(string))
+ strs = append(strs, strlit(s[i]))
i++
}
if len(strs) > 0 {
case TSTRING:
cs := ""
if Isconst(n, CTSTR) {
- cs = n.Val().U.(string)
+ cs = strlit(n)
}
switch cs {
case " ":
sz := int64(0)
for _, n1 := range n.List.Slice() {
if n1.Op == OLITERAL {
- sz += int64(len(n1.Val().U.(string)))
+ sz += int64(len(strlit(n1)))
}
}
// Length-only checks are ok, though.
maxRewriteLen = 0
}
- if s := cs.Val().U.(string); len(s) <= maxRewriteLen {
+ if s := strlit(cs); len(s) <= maxRewriteLen {
if len(s) > 0 {
ncs = safeexpr(ncs, init)
}