mirror of
https://github.com/golang/go
synced 2024-11-22 23:50:03 -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:
parent
5e6a7e9b86
commit
1f8d4562de
@ -334,6 +334,16 @@ const (
|
|||||||
OEND
|
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.
|
// Nodes is a pointer to a slice of *Node.
|
||||||
// For fields that are not used in most nodes, this is used instead of
|
// For fields that are not used in most nodes, this is used instead of
|
||||||
// a slice to save space.
|
// a slice to save space.
|
||||||
|
@ -903,7 +903,7 @@ func (subst *subster) node(n ir.Node) ir.Node {
|
|||||||
ir.EditChildren(m, edit)
|
ir.EditChildren(m, edit)
|
||||||
|
|
||||||
m.SetTypecheck(1)
|
m.SetTypecheck(1)
|
||||||
if typecheck.IsCmp(x.Op()) {
|
if x.Op().IsCmp() {
|
||||||
transformCompare(m.(*ir.BinaryExpr))
|
transformCompare(m.(*ir.BinaryExpr))
|
||||||
} else {
|
} else {
|
||||||
switch x.Op() {
|
switch x.Op() {
|
||||||
|
@ -77,10 +77,6 @@ func tcShift(n, l, r ir.Node) (ir.Node, ir.Node, *types.Type) {
|
|||||||
return l, r, t
|
return l, r, t
|
||||||
}
|
}
|
||||||
|
|
||||||
func IsCmp(op ir.Op) bool {
|
|
||||||
return iscmp[op]
|
|
||||||
}
|
|
||||||
|
|
||||||
// tcArith typechecks operands of a binary arithmetic expression.
|
// tcArith typechecks operands of a binary arithmetic expression.
|
||||||
// The result of tcArith MUST be assigned back to original operands,
|
// 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:
|
// 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()
|
t = r.Type()
|
||||||
}
|
}
|
||||||
aop := ir.OXXX
|
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
|
// comparison is okay as long as one side is
|
||||||
// assignable to the other. convert so they have
|
// assignable to the other. convert so they have
|
||||||
// the same type.
|
// the same type.
|
||||||
|
@ -329,14 +329,6 @@ func InitUniverse() {
|
|||||||
// special
|
// special
|
||||||
okfor[ir.OCAP] = okforcap[:]
|
okfor[ir.OCAP] = okforcap[:]
|
||||||
okfor[ir.OLEN] = okforlen[:]
|
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 {
|
func makeErrorInterface() *types.Type {
|
||||||
|
Loading…
Reference in New Issue
Block a user