Convert math functions
Converts the following functions from build/make/common/math.mk:
- math_max
- math_min
- math_gt_or_eq
- math_gt
- math_lt
Fixes: 213497955
Test: go test
Change-Id: I8c4e8fee321f03b813428fa10038fa8f06188cef
diff --git a/mk2rbc/expr.go b/mk2rbc/expr.go
index e78f492..3f355ac 100644
--- a/mk2rbc/expr.go
+++ b/mk2rbc/expr.go
@@ -728,6 +728,36 @@
}
}
+type binaryOpExpr struct {
+ left, right starlarkExpr
+ op string
+ returnType starlarkType
+}
+
+func (b *binaryOpExpr) emit(gctx *generationContext) {
+ b.left.emit(gctx)
+ gctx.write(" " + b.op + " ")
+ b.right.emit(gctx)
+}
+
+func (b *binaryOpExpr) typ() starlarkType {
+ return b.returnType
+}
+
+func (b *binaryOpExpr) emitListVarCopy(gctx *generationContext) {
+ b.emit(gctx)
+}
+
+func (b *binaryOpExpr) transform(transformer func(expr starlarkExpr) starlarkExpr) starlarkExpr {
+ b.left = b.left.transform(transformer)
+ b.right = b.right.transform(transformer)
+ if replacement := transformer(b); replacement != nil {
+ return replacement
+ } else {
+ return b
+ }
+}
+
type badExpr struct {
errorLocation ErrorLocation
message string