mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-26 17:01:35 +01:00
lang/token: add IsXBinaryTildeModOp
This commit is contained in:
1 parent
a4ec3f8e92
commit
1f3df26c7f
2 files changed
+9
-6
No files matched your search
@@ -286,9 +286,11 @@ func (g *gen) writeExprUnaryOp(b *buffer, n *a.Expr, depth uint32) error {
|
||||
}
|
||||
|
||||
func (g *gen) writeExprBinaryOp(b *buffer, n *a.Expr, depth uint32) error {
|
||||
opName, lhsCast, overallCast := "", false, n.MType().IsSmallInteger()
|
||||
|
||||
op := n.Operator()
|
||||
opName := ""
|
||||
lhsCast := false
|
||||
overallCast := n.MType().IsSmallInteger() || op.IsXBinaryTildeModOp()
|
||||
|
||||
switch op {
|
||||
case t.IDXBinaryPlus, t.IDXBinaryPipe, t.IDXBinaryHat, t.IDXBinaryTildeModPlus:
|
||||
if lcv := n.LHS().AsExpr().ConstValue(); (lcv != nil) && (lcv.Sign() == 0) {
|
||||
@@ -296,13 +298,11 @@ func (g *gen) writeExprBinaryOp(b *buffer, n *a.Expr, depth uint32) error {
|
||||
} else if rcv := n.RHS().AsExpr().ConstValue(); (rcv != nil) && (rcv.Sign() == 0) {
|
||||
return g.writeExpr(b, n.LHS().AsExpr(), false, depth)
|
||||
}
|
||||
overallCast = overallCast || (op == t.IDXBinaryTildeModPlus)
|
||||
|
||||
case t.IDXBinaryMinus, t.IDXBinaryTildeModMinus:
|
||||
if rcv := n.RHS().AsExpr().ConstValue(); (rcv != nil) && (rcv.Sign() == 0) {
|
||||
return g.writeExpr(b, n.LHS().AsExpr(), false, depth)
|
||||
}
|
||||
overallCast = overallCast || (op == t.IDXBinaryTildeModMinus)
|
||||
|
||||
case t.IDXBinaryStar, t.IDXBinaryTildeModStar:
|
||||
if lcv := n.LHS().AsExpr().ConstValue(); (lcv != nil) && (lcv.Cmp(one) == 0) {
|
||||
@@ -314,7 +314,6 @@ func (g *gen) writeExprBinaryOp(b *buffer, n *a.Expr, depth uint32) error {
|
||||
} else if (rcv != nil) && (rcv.Sign() == 0) && n.LHS().AsExpr().Effect().Pure() {
|
||||
return g.writeExpr(b, n.RHS().AsExpr(), false, depth)
|
||||
}
|
||||
overallCast = overallCast || (op == t.IDXBinaryTildeModStar)
|
||||
|
||||
case t.IDXBinaryTildeSatPlus, t.IDXBinaryTildeSatMinus:
|
||||
uBits := uintBits(n.MType().QID())
|
||||
@@ -337,7 +336,6 @@ func (g *gen) writeExprBinaryOp(b *buffer, n *a.Expr, depth uint32) error {
|
||||
} else if lhs := n.LHS().AsExpr(); lhs.ConstValue() != nil {
|
||||
lhsCast = true
|
||||
}
|
||||
overallCast = overallCast || (op == t.IDXBinaryTildeModShiftL)
|
||||
}
|
||||
|
||||
if opName == "" {
|
||||
|
||||
@@ -57,6 +57,9 @@ func (x ID) IsBuiltIn() bool { return x < nBuiltInIDs }
|
||||
|
||||
func (x ID) IsUnaryOp() bool { return minOp <= x && x <= maxOp && unaryForms[x] != 0 }
|
||||
func (x ID) IsBinaryOp() bool { return minOp <= x && x <= maxOp && binaryForms[x] != 0 }
|
||||
func (x ID) IsXBinaryTildeModOp() bool {
|
||||
return minXBinaryTildeModOp <= x && x <= maxXBinaryTildeModOp && binaryForms[x] != 0
|
||||
}
|
||||
func (x ID) IsAssociativeOp() bool { return minOp <= x && x <= maxOp && associativeForms[x] != 0 }
|
||||
|
||||
func (x ID) IsLiteral(m *Map) bool {
|
||||
@@ -283,6 +286,8 @@ const (
|
||||
minAmbiguousOp = 0x40
|
||||
maxAmbiguousOp = 0x6F
|
||||
minXOp = 0x70
|
||||
minXBinaryTildeModOp = 0x80
|
||||
maxXBinaryTildeModOp = 0x87
|
||||
maxXOp = 0xAF
|
||||
maxOp = 0xAF
|
||||
|
||||
|
||||
Reference in new issue
Block a user