Skip to content

binary_op

Classes:

Functions:

AddBinOp

Bases: BinaryOp

AssignmentBinOp

Bases: BinaryOp

BitAndBinOp

Bases: BinaryOp

BitOrBinOp

Bases: BinaryOp

BitXorBinOp

Bases: BinaryOp

DivBinOp

Bases: BinaryOp

EqBinOp

Bases: BinaryOp

GeBinOp

Bases: BinaryOp

GtBinOp

Bases: BinaryOp

LeBinOp

Bases: BinaryOp

LogicalAndBinOp

Bases: BinaryOp

LogicalOrBinOp

Bases: BinaryOp

LtBinOp

Bases: BinaryOp

ModBinOp

Bases: BinaryOp

MulBinOp

Bases: BinaryOp

NeBinOp

Bases: BinaryOp

SubBinOp

Bases: BinaryOp

binary_op_type_for_opcode

binary_op_type_for_opcode(op_code: str) -> type[BinaryOp]
Source code in src/irx/astx/binary_op.py
137
138
139
140
141
142
143
144
145
146
def binary_op_type_for_opcode(op_code: str) -> type[astx.BinaryOp]:
    """
    title: Return the specialized BinaryOp subclass for an opcode.
    parameters:
      op_code:
        type: str
    returns:
      type: type[astx.BinaryOp]
    """
    return _BINARY_OP_TYPES.get(op_code, astx.BinaryOp)

specialize_binary_op

specialize_binary_op(node: BinaryOp) -> BinaryOp
Source code in src/irx/astx/binary_op.py
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
def specialize_binary_op(node: astx.BinaryOp) -> astx.BinaryOp:
    """
    title: Return a specialized BinaryOp instance for the given opcode.
    parameters:
      node:
        type: astx.BinaryOp
    returns:
      type: astx.BinaryOp
    """
    target_type = binary_op_type_for_opcode(node.op_code)
    if target_type is astx.BinaryOp or isinstance(node, target_type):
        return node

    specialized = target_type(
        node.op_code,
        node.lhs,
        node.rhs,
        loc=node.loc,
        parent=node.parent,
    )
    specialized.__dict__.update(vars(node))
    return specialized