Fix bug in localvariable init expression parsing

pull/14/head
Josselin 6 years ago
parent 88df50ce57
commit 1c189aa610
  1. 7
      slither/core/cfg/node.py
  2. 3
      slither/core/variables/variable.py
  3. 10
      slither/solcParsing/cfg/nodeSolc.py

@ -126,7 +126,12 @@ class Node(SourceMapping, ChildFunction):
def add_variable_declaration(self, var):
assert self._variable_declaration is None
self._variable_declaration = var
self._expression = var.expression
if var.expression:
self._vars_written += [var]
@property
def variable_declaration(self):
return self._variable_declaration
def __str__(self):
txt = NodeType.str(self._node_type) + ' '+ str(self.expression)

@ -17,7 +17,6 @@ class Variable(SourceMapping):
self._mappingTo = None
self._initial_expression = None
self._type = None
self._expression = None
self._initialized = None
self._visibility = None
@ -26,7 +25,7 @@ class Variable(SourceMapping):
"""
Expression: Expression of the node (if initialized)
"""
return self._expression
return self._initial_expression
@property
def initialized(self):

@ -1,4 +1,5 @@
from slither.core.cfg.node import Node
from slither.core.cfg.nodeType import NodeType
from slither.solcParsing.expressions.expressionParsing import parse_expression
from slither.visitors.expression.readVar import ReadVar
from slither.visitors.expression.writeVar import WriteVar
@ -22,9 +23,15 @@ class NodeSolc(Node):
self._unparsed_expression = expression
def analyze_expressions(self, caller_context):
if self.type == NodeType.VARIABLE:
self._expression = self.variable_declaration.expression
if self._unparsed_expression:
expression = parse_expression(self._unparsed_expression, caller_context)
self._expression = expression
self._unparsed_expression = None
if self.expression:
expression = self.expression
pp = ReadVar(expression)
self._expression_vars_read = pp.result()
vars_read = [ExportValues(v).result() for v in self._expression_vars_read]
@ -47,5 +54,4 @@ class NodeSolc(Node):
calls = [item for sublist in calls for item in sublist]
self._calls = [c for c in calls if isinstance(c, (Function, SolidityFunction))]
self._unparsed_expression = None
self._expression = expression

Loading…
Cancel
Save