Beispiel #1
0
 def _post_index_access(self, expression):
     left = get(expression.expression_left)
     right = get(expression.expression_right)
     # Left can be a type for abi.decode(var, uint[2])
     if isinstance(left, Type):
         # Nested type are not yet supported by abi.decode, so the assumption
         # Is that the right variable must be a constant
         assert isinstance(right, Constant)
         t = ArrayType(left, right.value)
         set_val(expression, t)
         return
     val = ReferenceVariable(self._node)
     # access to anonymous array
     # such as [0,1][x]
     if isinstance(left, list):
         init_array_val = TemporaryVariable(self._node)
         init_array_right = left
         left = init_array_val
         operation = InitArray(init_array_right, init_array_val)
         operation.set_expression(expression)
         self._result.append(operation)
     operation = Index(val, left, right, expression.type)
     operation.set_expression(expression)
     self._result.append(operation)
     set_val(expression, val)
Beispiel #2
0
def convert_to_push(ir, node):
    """
    Convert a call to a PUSH operaiton

    The funciton assume to receive a correct IR
    The checks must be done by the caller

    May necessitate to create an intermediate operation (InitArray)
    Necessitate to return the lenght (see push documentation)
    As a result, the function return may return a list
    """

    # TODO remove Push Operator, and change this to existing operators

    lvalue = ir.lvalue
    if isinstance(ir.arguments[0], list):
        ret = []

        val = TemporaryVariable(node)
        operation = InitArray(ir.arguments[0], val)
        operation.set_expression(ir.expression)
        ret.append(operation)

        prev_ir = ir
        ir = Push(ir.destination, val)
        ir.set_expression(prev_ir.expression)

        length = Literal(len(operation.init_values), 'uint256')
        t = operation.init_values[0].type
        ir.lvalue.set_type(ArrayType(t, length))

        ret.append(ir)

        if lvalue:
            length = Length(ir.array, lvalue)
            length.set_expression(ir.expression)
            length.lvalue.points_to = ir.lvalue
            ret.append(length)

        return ret

    prev_ir = ir
    ir = Push(ir.destination, ir.arguments[0])
    ir.set_expression(prev_ir.expression)

    if lvalue:
        ret = []
        ret.append(ir)

        length = Length(ir.array, lvalue)
        length.set_expression(ir.expression)
        length.lvalue.points_to = ir.lvalue
        ret.append(length)
        return ret

    return ir
Beispiel #3
0
 def _post_index_access(self, expression):
     left = get(expression.expression_left)
     right = get(expression.expression_right)
     val = ReferenceVariable(self._node)
     # access to anonymous array
     # such as [0,1][x]
     if isinstance(left, list):
         init_array_val = TemporaryVariable(self._node)
         init_array_right = left
         left = init_array_val
         operation = InitArray(init_array_right, init_array_val)
         operation.set_expression(expression)
         self._result.append(operation)
     operation = Index(val, left, right, expression.type)
     operation.set_expression(expression)
     self._result.append(operation)
     set_val(expression, val)