SlithIR: add points_to property to ReferenceVariable

pull/58/head
Josselin 6 years ago
parent 68f32a980c
commit 87acb73841
  1. 11
      slither/slithir/convert.py
  2. 24
      slither/slithir/variables/reference.py

@ -511,10 +511,21 @@ def apply_ir_heuristics(irs, node):
# irs = replace_calls(irs) # irs = replace_calls(irs)
irs = remove_unused(irs) irs = remove_unused(irs)
find_references_origin(irs)
reset_variable_number(irs) reset_variable_number(irs)
return irs return irs
def find_references_origin(irs):
"""
Make lvalue of each Index, Member operation
points to the left variable
"""
for ir in irs:
if isinstance(ir, (Index, Member)):
ir.lvalue.points_to = ir.variable_left
def reset_variable_number(result): def reset_variable_number(result):
""" """
Reset the number associated to slithIR variables Reset the number associated to slithIR variables

@ -1,6 +1,8 @@
from slither.core.variables.variable import Variable
from slither.core.children.child_node import ChildNode from slither.core.children.child_node import ChildNode
from slither.core.declarations import Contract, Enum, SolidityVariableComposed
from slither.core.variables.variable import Variable
class ReferenceVariable(ChildNode, Variable): class ReferenceVariable(ChildNode, Variable):
@ -10,6 +12,7 @@ class ReferenceVariable(ChildNode, Variable):
super(ReferenceVariable, self).__init__() super(ReferenceVariable, self).__init__()
self._index = ReferenceVariable.COUNTER self._index = ReferenceVariable.COUNTER
ReferenceVariable.COUNTER += 1 ReferenceVariable.COUNTER += 1
self._points_to = None
@property @property
def index(self): def index(self):
@ -19,6 +22,25 @@ class ReferenceVariable(ChildNode, Variable):
def index(self, idx): def index(self, idx):
self._index = idx self._index = idx
@property
def points_to(self):
"""
Return the variable pointer by the reference
It is the left member of a Index or Member operator
"""
return self._points_to
@points_to.setter
def points_to(self, points_to):
# Can only be a rvalue of
# Member or Index operator
from slither.slithir.utils.utils import is_valid_lvalue
assert is_valid_lvalue(points_to) \
or points_to == SolidityVariableComposed('msg.data') \
or isinstance(points_to, (Contract, Enum))
self._points_to = points_to
@property @property
def name(self): def name(self):
return 'REF_{}'.format(self.index) return 'REF_{}'.format(self.index)

Loading…
Cancel
Save