mirror of
https://github.com/golang/go
synced 2024-11-18 08:04:40 -07:00
cmd/compile: some cleanup with old irgen code
- Un-export Convertop: it's only used by tcConv. - Remove AssignOp1: introduced in CL 349614, only used by irgen. - Un-export Assignop: it was exported to be used by irgen only. Change-Id: I7e78b35d90f165c537cf32a104156bf2a13ca8b8 Reviewed-on: https://go-review.googlesource.com/c/go/+/532516 Reviewed-by: Keith Randall <khr@google.com> Reviewed-by: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Auto-Submit: Cuong Manh Le <cuong.manhle.vn@gmail.com> Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
This commit is contained in:
parent
38db0316f4
commit
10da3b64af
@ -69,7 +69,7 @@ func tcArith(n ir.Node, op ir.Op, l, r ir.Node) (ir.Node, ir.Node, *types.Type)
|
||||
// The conversion allocates, so only do it if the concrete type is huge.
|
||||
converted := false
|
||||
if r.Type().Kind() != types.TBLANK {
|
||||
aop, _ = Assignop(l.Type(), r.Type())
|
||||
aop, _ = assignOp(l.Type(), r.Type())
|
||||
if aop != ir.OXXX {
|
||||
if r.Type().IsInterface() && !l.Type().IsInterface() && !types.IsComparable(l.Type()) {
|
||||
base.Errorf("invalid operation: %v (operator %v not defined on %s)", n, op, typekind(l.Type()))
|
||||
@ -88,7 +88,7 @@ func tcArith(n ir.Node, op ir.Op, l, r ir.Node) (ir.Node, ir.Node, *types.Type)
|
||||
}
|
||||
|
||||
if !converted && l.Type().Kind() != types.TBLANK {
|
||||
aop, _ = Assignop(r.Type(), l.Type())
|
||||
aop, _ = assignOp(r.Type(), l.Type())
|
||||
if aop != ir.OXXX {
|
||||
if l.Type().IsInterface() && !r.Type().IsInterface() && !types.IsComparable(r.Type()) {
|
||||
base.Errorf("invalid operation: %v (operator %v not defined on %s)", n, op, typekind(r.Type()))
|
||||
@ -352,7 +352,7 @@ func tcConv(n *ir.ConvExpr) ir.Node {
|
||||
n.SetType(nil)
|
||||
return n
|
||||
}
|
||||
op, why := Convertop(n.X.Op() == ir.OLITERAL, t, n.Type())
|
||||
op, why := convertOp(n.X.Op() == ir.OLITERAL, t, n.Type())
|
||||
if op == ir.OXXX {
|
||||
// Due to //go:nointerface, we may be stricter than types2 here (#63333).
|
||||
base.ErrorfAt(n.Pos(), errors.InvalidConversion, "cannot convert %L to type %v%s", n.X, n.Type(), why)
|
||||
|
@ -600,8 +600,8 @@ func tcSwitchExpr(n *ir.SwitchStmt) {
|
||||
} else if t.IsInterface() && !n1.Type().IsInterface() && !types.IsComparable(n1.Type()) {
|
||||
base.ErrorfAt(ncase.Pos(), errors.UndefinedOp, "invalid case %L in switch (incomparable type)", n1)
|
||||
} else {
|
||||
op1, _ := Assignop(n1.Type(), t)
|
||||
op2, _ := Assignop(t, n1.Type())
|
||||
op1, _ := assignOp(n1.Type(), t)
|
||||
op2, _ := assignOp(t, n1.Type())
|
||||
if op1 == ir.OXXX && op2 == ir.OXXX {
|
||||
if n.Tag != nil {
|
||||
base.ErrorfAt(ncase.Pos(), errors.MismatchedTypes, "invalid case %v in switch on %v (mismatched types %v and %v)", n1, n.Tag, n1.Type(), t)
|
||||
|
@ -237,7 +237,7 @@ func assignconvfn(n ir.Node, t *types.Type, context func() string) ir.Node {
|
||||
return n
|
||||
}
|
||||
|
||||
op, why := Assignop(n.Type(), t)
|
||||
op, why := assignOp(n.Type(), t)
|
||||
if op == ir.OXXX {
|
||||
base.Errorf("cannot use %L as type %v in %s%s", n, t, context(), why)
|
||||
op = ir.OCONV
|
||||
@ -253,7 +253,7 @@ func assignconvfn(n ir.Node, t *types.Type, context func() string) ir.Node {
|
||||
// If so, return op code to use in conversion.
|
||||
// If not, return OXXX. In this case, the string return parameter may
|
||||
// hold a reason why. In all other cases, it'll be the empty string.
|
||||
func Assignop(src, dst *types.Type) (ir.Op, string) {
|
||||
func assignOp(src, dst *types.Type) (ir.Op, string) {
|
||||
if src == dst {
|
||||
return ir.OCONVNOP, ""
|
||||
}
|
||||
@ -265,10 +265,7 @@ func Assignop(src, dst *types.Type) (ir.Op, string) {
|
||||
if types.Identical(src, dst) {
|
||||
return ir.OCONVNOP, ""
|
||||
}
|
||||
return Assignop1(src, dst)
|
||||
}
|
||||
|
||||
func Assignop1(src, dst *types.Type) (ir.Op, string) {
|
||||
// 2. src and dst have identical underlying types and
|
||||
// a. either src or dst is not a named type, or
|
||||
// b. both are empty interface types, or
|
||||
@ -367,7 +364,7 @@ func Assignop1(src, dst *types.Type) (ir.Op, string) {
|
||||
// If not, return OXXX. In this case, the string return parameter may
|
||||
// hold a reason why. In all other cases, it'll be the empty string.
|
||||
// srcConstant indicates whether the value of type src is a constant.
|
||||
func Convertop(srcConstant bool, src, dst *types.Type) (ir.Op, string) {
|
||||
func convertOp(srcConstant bool, src, dst *types.Type) (ir.Op, string) {
|
||||
if src == dst {
|
||||
return ir.OCONVNOP, ""
|
||||
}
|
||||
@ -390,7 +387,7 @@ func Convertop(srcConstant bool, src, dst *types.Type) (ir.Op, string) {
|
||||
}
|
||||
|
||||
// 1. src can be assigned to dst.
|
||||
op, why := Assignop(src, dst)
|
||||
op, why := assignOp(src, dst)
|
||||
if op != ir.OXXX {
|
||||
return op, why
|
||||
}
|
||||
|
@ -1209,7 +1209,7 @@ func checkassignto(src *types.Type, dst ir.Node) {
|
||||
return
|
||||
}
|
||||
|
||||
if op, why := Assignop(src, dst.Type()); op == ir.OXXX {
|
||||
if op, why := assignOp(src, dst.Type()); op == ir.OXXX {
|
||||
base.Errorf("cannot assign %v to %L in multiple assignment%s", src, dst, why)
|
||||
return
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user