def _post_assignement_operation(self, expression): left = get(expression.expression_left) right = get(expression.expression_right) if isinstance(left, list): # tuple expression: if isinstance(right, list): # unbox assigment assert len(left) == len(right) for idx, _ in enumerate(left): if not left[idx] is None: operation = convert_assignment( left[idx], right[idx], expression.type, expression.expression_return_type, ) operation.set_expression(expression) self._result.append(operation) set_val(expression, None) else: assert isinstance(right, TupleVariable) for idx, _ in enumerate(left): if not left[idx] is None: index = idx # The following test is probably always true? if (isinstance(left[idx], LocalVariableInitFromTuple) and left[idx].tuple_index is not None): index = left[idx].tuple_index operation = Unpack(left[idx], right, index) operation.set_expression(expression) self._result.append(operation) set_val(expression, None) # Tuple with only one element. We need to convert the assignment to a Unpack # Ex: # (uint a,,) = g() elif (isinstance(left, LocalVariableInitFromTuple) and left.tuple_index is not None and isinstance(right, TupleVariable)): operation = Unpack(left, right, left.tuple_index) operation.set_expression(expression) self._result.append(operation) set_val(expression, None) else: # Init of array, like # uint8[2] var = [1,2]; if isinstance(right, list): operation = InitArray(right, left) operation.set_expression(expression) self._result.append(operation) set_val(expression, left) else: operation = convert_assignment( left, right, expression.type, expression.expression_return_type) operation.set_expression(expression) self._result.append(operation) # Return left to handle # a = b = 1; set_val(expression, left)
def _post_assignement_operation(self, expression): left = get(expression.expression_left) right = get(expression.expression_right) if isinstance(left, list): # tuple expression: if isinstance(right, list): # unbox assigment assert len(left) == len(right) for idx in range(len(left)): if not left[idx] is None: operation = convert_assignment(left[idx], right[idx], expression.type, expression.expression_return_type) operation.set_expression(expression) self._result.append(operation) set_val(expression, None) else: assert isinstance(right, TupleVariable) for idx in range(len(left)): if not left[idx] is None: operation = Unpack(left[idx], right, idx) operation.set_expression(expression) self._result.append(operation) set_val(expression, None) else: # Init of array, like # uint8[2] var = [1,2]; if isinstance(right, list): operation = InitArray(right, left) operation.set_expression(expression) self._result.append(operation) set_val(expression, left) else: operation = convert_assignment(left, right, expression.type, expression.expression_return_type) operation.set_expression(expression) self._result.append(operation) # Return left to handle # a = b = 1; set_val(expression, left)