Add support for index on anonymous arrays (close #139)

pull/132/head
Josselin 6 years ago
parent 98fdc339ab
commit 314c8cb0e3
  1. 3
      slither/core/solidity_types/array_type.py
  2. 8
      slither/visitors/slithir/expression_to_slithir.py

@ -1,12 +1,15 @@
from slither.core.variables.variable import Variable from slither.core.variables.variable import Variable
from slither.core.solidity_types.type import Type from slither.core.solidity_types.type import Type
from slither.core.expressions.expression import Expression from slither.core.expressions.expression import Expression
from slither.core.expressions import Literal
class ArrayType(Type): class ArrayType(Type):
def __init__(self, t, length): def __init__(self, t, length):
assert isinstance(t, Type) assert isinstance(t, Type)
if length: if length:
if isinstance(length, int):
length = Literal(length)
assert isinstance(length, Expression) assert isinstance(length, Expression)
super(ArrayType, self).__init__() super(ArrayType, self).__init__()
self._type = t self._type = t

@ -160,6 +160,14 @@ class ExpressionToSlithIR(ExpressionVisitor):
left = get(expression.expression_left) left = get(expression.expression_left)
right = get(expression.expression_right) right = get(expression.expression_right)
val = ReferenceVariable(self._node) 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)
self._result.append(operation)
operation = Index(val, left, right, expression.type) operation = Index(val, left, right, expression.type)
self._result.append(operation) self._result.append(operation)
set_val(expression, val) set_val(expression, val)

Loading…
Cancel
Save