1
0
mirror of https://github.com/golang/go synced 2024-11-05 17:36:15 -07:00

cmd/compile: remove typecheck.Orig* functions

Same as CL 526397, but for typecheck.

Change-Id: Ia8f19a54ffaa2ae3b86a4c66cbe6d973482796cd
Reviewed-on: https://go-review.googlesource.com/c/go/+/526236
Auto-Submit: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
This commit is contained in:
Cuong Manh Le 2023-09-12 10:45:54 +07:00 committed by Gopher Robot
parent aa381c538a
commit e50bbae2de
4 changed files with 8 additions and 64 deletions

View File

@ -355,26 +355,17 @@ func ForCapture(fn *ir.Func) []VarAndLoop {
})
postNotNil := x.Post != nil
var tmpFirstDcl *ir.AssignStmt
var tmpFirstDcl ir.Node
if postNotNil {
// body' = prebody +
// (6) if tmp_first {tmp_first = false} else {Post} +
// if !cond {break} + ...
tmpFirst := typecheck.TempAt(base.Pos, fn, types.Types[types.TBOOL])
// tmpFirstAssign assigns val to tmpFirst
tmpFirstAssign := func(val bool) *ir.AssignStmt {
s := ir.NewAssignStmt(x.Pos(), tmpFirst, typecheck.OrigBool(tmpFirst, val))
s.SetTypecheck(1)
return s
}
tmpFirstDcl = tmpFirstAssign(true)
tmpFirstDcl.Def = true // also declares tmpFirst
tmpFirstSetFalse := tmpFirstAssign(false)
tmpFirstDcl = typecheck.Stmt(ir.NewAssignStmt(x.Pos(), tmpFirst, ir.NewBool(base.Pos, true)))
tmpFirstSetFalse := typecheck.Stmt(ir.NewAssignStmt(x.Pos(), tmpFirst, ir.NewBool(base.Pos, false)))
ifTmpFirst := ir.NewIfStmt(x.Pos(), tmpFirst, ir.Nodes{tmpFirstSetFalse}, ir.Nodes{x.Post})
ifTmpFirst.SetTypecheck(1)
preBody.Append(ifTmpFirst)
ifTmpFirst.PtrInit().Append(typecheck.Stmt(ir.NewDecl(base.Pos, ir.ODCL, tmpFirst))) // declares tmpFirst
preBody.Append(typecheck.Stmt(ifTmpFirst))
}
// body' = prebody +

View File

@ -1033,7 +1033,7 @@ func addStr(n *ir.AddStringExpr) ir.Node {
for _, c := range s {
strs = append(strs, ir.StringVal(c))
}
return typecheck.OrigConst(n, constant.MakeString(strings.Join(strs, "")))
return ir.NewConstExpr(constant.MakeString(strings.Join(strs, "")), n)
}
newList := make([]ir.Node, 0, need)
for i := 0; i < len(s); i++ {
@ -1046,9 +1046,7 @@ func addStr(n *ir.AddStringExpr) ir.Node {
i2++
}
nl := ir.Copy(n).(*ir.AddStringExpr)
nl.List = s[i:i2]
newList = append(newList, typecheck.OrigConst(nl, constant.MakeString(strings.Join(strs, ""))))
newList = append(newList, ir.NewConstExpr(constant.MakeString(strings.Join(strs, "")), s[i]))
i = i2 - 1
} else {
newList = append(newList, s[i])

View File

@ -8,7 +8,6 @@ import (
"fmt"
"go/constant"
"go/token"
"internal/types/errors"
"math"
"math/big"
"unicode"
@ -330,50 +329,6 @@ func makeComplex(real, imag constant.Value) constant.Value {
return constant.BinaryOp(constant.ToFloat(real), token.ADD, constant.MakeImag(constant.ToFloat(imag)))
}
// For matching historical "constant OP overflow" error messages.
// TODO(mdempsky): Replace with error messages like go/types uses.
var overflowNames = [...]string{
ir.OADD: "addition",
ir.OSUB: "subtraction",
ir.OMUL: "multiplication",
ir.OLSH: "shift",
ir.OXOR: "bitwise XOR",
ir.OBITNOT: "bitwise complement",
}
// OrigConst returns an OLITERAL with orig n and value v.
func OrigConst(n ir.Node, v constant.Value) ir.Node {
lno := ir.SetPos(n)
v = ConvertVal(v, n.Type(), false)
base.Pos = lno
switch v.Kind() {
case constant.Int:
if constant.BitLen(v) <= ir.ConstPrec {
break
}
fallthrough
case constant.Unknown:
what := overflowNames[n.Op()]
if what == "" {
base.Fatalf("unexpected overflow: %v", n.Op())
}
base.ErrorfAt(n.Pos(), errors.NumericOverflow, "constant %v overflow", what)
n.SetType(nil)
return n
}
return ir.NewConstExpr(v, n)
}
func OrigBool(n ir.Node, v bool) ir.Node {
return OrigConst(n, constant.MakeBool(v))
}
func OrigInt(n ir.Node, v int64) ir.Node {
return OrigConst(n, constant.MakeInt64(v))
}
// DefaultLit on both nodes simultaneously;
// if they're both ideal going in they better
// get the same type going out.

View File

@ -274,7 +274,7 @@ func walkLenCap(n *ir.UnaryExpr, init *ir.Nodes) ir.Node {
}
if t.IsArray() {
safeExpr(n.X, init)
con := typecheck.OrigInt(n, t.NumElem())
con := ir.NewConstExpr(constant.MakeInt64(t.NumElem()), n)
con.SetTypecheck(1)
return con
}