cgen: simplify bulk_etc method's generated code

This commit is contained in:
Nigel Tao committed 2023-06-05 13:28:16 +10:00
1 parent 2865c5bfbd
commit 4a2f570d56
3 files changed
+58 -26

No files matched your search

+21
View File
@@ -382,6 +382,27 @@ func (g *gen) writeExprRepr(b *buffer, n *a.Expr, depth uint32) error {
return nil
}
func (g *gen) writeExprXMinusY(b *buffer, x *a.Expr, y *a.Expr, depth uint32) error {
if x.Operator() == t.IDXBinaryPlus {
if x.LHS().AsExpr().Eq(y) {
return g.writeExpr(b, x.RHS().AsExpr(), false, depth)
} else if x.RHS().AsExpr().Eq(y) {
return g.writeExpr(b, x.LHS().AsExpr(), false, depth)
}
}
b.writes("(")
if err := g.writeExpr(b, x, false, depth); err != nil {
return err
}
b.writes(" - ")
if err := g.writeExpr(b, y, false, depth); err != nil {
return err
}
b.writes(")")
return nil
}
func (g *gen) writeExprAs(b *buffer, lhs *a.Expr, rhs *a.TypeExpr, depth uint32) error {
// Drop the "& redundantMask" in "(foo & redundantMask) as base.uxx". It's
// redundant in C/C++ (but not in Wuffs).