MCPcopy Index your code
hub / github.com/python/mypy / transform_op_expr

Function transform_op_expr

mypyc/irbuild/expression.py:711–744  ·  view source on GitHub ↗
(builder: IRBuilder, expr: OpExpr)

Source from the content-addressed store, hash-verified

709
710
711def transform_op_expr(builder: IRBuilder, expr: OpExpr) -> Value:
712 if expr.op in ("and", "or"):
713 return builder.shortcircuit_expr(expr)
714
715 # Special case for string formatting
716 if expr.op == "%" and isinstance(expr.left, (StrExpr, BytesExpr)):
717 ret = translate_printf_style_formatting(builder, expr.left, expr.right)
718 if ret is not None:
719 return ret
720
721 folded = try_constant_fold(builder, expr)
722 if folded:
723 return folded
724
725 borrow_left = False
726 borrow_right = False
727
728 ltype = builder.node_type(expr.left)
729 rtype = builder.node_type(expr.right)
730
731 # Special case some int ops to allow borrowing operands.
732 if is_int_rprimitive(ltype) and is_int_rprimitive(rtype):
733 if expr.op == "//":
734 expr = try_optimize_int_floor_divide(builder, expr)
735 if expr.op in int_borrow_friendly_op:
736 borrow_left = is_borrow_friendly_expr(builder, expr.right)
737 borrow_right = True
738 elif is_fixed_width_rtype(ltype) and is_fixed_width_rtype(rtype):
739 borrow_left = is_borrow_friendly_expr(builder, expr.right)
740 borrow_right = True
741
742 left = builder.accept(expr.left, can_borrow=borrow_left)
743 right = builder.accept(expr.right, can_borrow=borrow_right)
744 return builder.binary_op(left, right, expr.op, expr.line)
745
746
747def try_optimize_int_floor_divide(builder: IRBuilder, expr: OpExpr) -> OpExpr:

Callers 1

visit_op_exprMethod · 0.90

Calls 11

is_int_rprimitiveFunction · 0.90
is_borrow_friendly_exprFunction · 0.90
is_fixed_width_rtypeFunction · 0.90
isinstanceFunction · 0.85
try_constant_foldFunction · 0.85
shortcircuit_exprMethod · 0.80
node_typeMethod · 0.80
acceptMethod · 0.45
binary_opMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…