1
0
mirror of https://github.com/golang/go synced 2024-11-22 20:24:47 -07:00

cmd/compile: change typecheck.iscmp into ir.Op.IsCmp

Change-Id: If89089cbd79b7ff030d856df3a7e6b7862c0f4ec
Reviewed-on: https://go-review.googlesource.com/c/go/+/345412
Trust: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
TryBot-Result: Go Bot <gobot@golang.org>
This commit is contained in:
Matthew Dempsky 2021-08-26 11:29:44 -07:00
parent 5e6a7e9b86
commit 1f8d4562de
4 changed files with 12 additions and 14 deletions

View File

@ -334,6 +334,16 @@ const (
OEND
)
// IsCmp reports whether op is a comparison operation (==, !=, <, <=,
// >, or >=).
func (op Op) IsCmp() bool {
switch op {
case OEQ, ONE, OLT, OLE, OGT, OGE:
return true
}
return false
}
// Nodes is a pointer to a slice of *Node.
// For fields that are not used in most nodes, this is used instead of
// a slice to save space.

View File

@ -903,7 +903,7 @@ func (subst *subster) node(n ir.Node) ir.Node {
ir.EditChildren(m, edit)
m.SetTypecheck(1)
if typecheck.IsCmp(x.Op()) {
if x.Op().IsCmp() {
transformCompare(m.(*ir.BinaryExpr))
} else {
switch x.Op() {

View File

@ -77,10 +77,6 @@ func tcShift(n, l, r ir.Node) (ir.Node, ir.Node, *types.Type) {
return l, r, t
}
func IsCmp(op ir.Op) bool {
return iscmp[op]
}
// tcArith typechecks operands of a binary arithmetic expression.
// The result of tcArith MUST be assigned back to original operands,
// t is the type of the expression, and should be set by the caller. e.g:
@ -96,7 +92,7 @@ func tcArith(n ir.Node, op ir.Op, l, r ir.Node) (ir.Node, ir.Node, *types.Type)
t = r.Type()
}
aop := ir.OXXX
if iscmp[n.Op()] && t.Kind() != types.TIDEAL && !types.Identical(l.Type(), r.Type()) {
if n.Op().IsCmp() && t.Kind() != types.TIDEAL && !types.Identical(l.Type(), r.Type()) {
// comparison is okay as long as one side is
// assignable to the other. convert so they have
// the same type.

View File

@ -329,14 +329,6 @@ func InitUniverse() {
// special
okfor[ir.OCAP] = okforcap[:]
okfor[ir.OLEN] = okforlen[:]
// comparison
iscmp[ir.OLT] = true
iscmp[ir.OGT] = true
iscmp[ir.OGE] = true
iscmp[ir.OLE] = true
iscmp[ir.OEQ] = true
iscmp[ir.ONE] = true
}
func makeErrorInterface() *types.Type {