]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: change typecheck.iscmp into ir.Op.IsCmp
authorMatthew Dempsky <mdempsky@google.com>
Thu, 26 Aug 2021 18:29:44 +0000 (11:29 -0700)
committerMatthew Dempsky <mdempsky@google.com>
Thu, 26 Aug 2021 19:07:27 +0000 (19:07 +0000)
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>

src/cmd/compile/internal/ir/node.go
src/cmd/compile/internal/noder/stencil.go
src/cmd/compile/internal/typecheck/expr.go
src/cmd/compile/internal/typecheck/universe.go

index f071cb78ce56db74703f29be24d5c06802a76e18..8784f9ef994d653c40fb2d374d8efe12bab92d36 100644 (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.
index b3ff4b8855c7b157b34ae38b1e26671201a93daa..0c6bb5100c6708d4b18ba4f0f6cb42cad091e6cb 100644 (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() {
index 7e974dfda863a0bc378d68fc0be98a8ec30bb222..d83bc65bed620d7e9c5dc48b8f97e83bce39460d 100644 (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.
index 54f3c89c24544cff2d1ad345726e9e74b4573274..a7c84dc8d82207018859c00ca4fda4c254745fec 100644 (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 {