def _is_rightmost_operation(node: NodeBase, depth: int) -> bool: # Check if the node is the final operation within the expression parents = node.parents( depth, {"nodeType": "BinaryOperation", "typeDescriptions.typeString": "bool"} ) return not next( (i for i in parents if i.leftExpression == node or node.is_child_of(i.leftExpression)), False, )
def _check_left_operator(node: NodeBase, depth: int) -> bool: # Find the nearest parent boolean where this node sits on the left side of # the comparison, and return True if that node's operator is || parents = node.parents( depth, {"nodeType": "BinaryOperation", "typeDescriptions.typeString": "bool"} ) op = next( i for i in parents if i.leftExpression == node or node.is_child_of(i.leftExpression) ).operator return op == "||"
def _set_invalid_error_string(source_node: NodeBase, pc_map: Dict) -> None: # set custom error string for INVALID opcodes node = source_node.children(include_children=False, offset_limits=pc_map["offset"])[0] if node.nodeType == "IndexAccess": pc_map["dev"] = "Index out of range" elif node.nodeType == "BinaryOperation": if node.operator == "/": pc_map["dev"] = "Division by zero" elif node.operator == "%": pc_map["dev"] = "Modulus by zero"
def _get_active_fn(source_node: NodeBase, offset: Tuple[int, int]) -> Tuple[NodeBase, str]: fn_node = source_node.children( depth=2, required_offset=offset, filters={"nodeType": "FunctionDefinition"} )[0] name = getattr(fn_node, "name", None) if not name: if getattr(fn_node, "kind", "function") != "function": name = f"<{fn_node.kind}>" elif getattr(fn_node, "isConstructor", False): name = "<constructor>" else: name = "<fallback>" return fn_node, f"{fn_node.parent().name}.{name}"