Merge pull request #524 from crytic/bugfix/ifloop-ordering

Fix ordering of sons when parsing for loop
pull/535/head
Feist Josselin 4 years ago committed by GitHub
commit 9ed1cb133a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      slither/core/cfg/node.py
  2. 2
      slither/core/declarations/function.py
  3. 20
      slither/solc_parsing/declarations/function.py

@ -650,13 +650,13 @@ class Node(SourceMapping, ChildFunction):
@property @property
def son_true(self) -> Optional["Node"]: def son_true(self) -> Optional["Node"]:
if self.type == NodeType.IF: if self.type in [NodeType.IF, NodeType.IFLOOP]:
return self._sons[0] return self._sons[0]
return None return None
@property @property
def son_false(self) -> Optional["Node"]: def son_false(self) -> Optional["Node"]:
if self.type == NodeType.IF and len(self._sons) >= 1: if self.type in [NodeType.IF, NodeType.IFLOOP] and len(self._sons) >= 1:
return self._sons[1] return self._sons[1]
return None return None

@ -1282,7 +1282,7 @@ class Function(ChildContract, ChildInheritance, SourceMapping):
if node.irs: if node.irs:
label += "\nIRs:\n" + "\n".join([str(ir) for ir in node.irs]) label += "\nIRs:\n" + "\n".join([str(ir) for ir in node.irs])
content += '{}[label="{}"];\n'.format(node.node_id, label) content += '{}[label="{}"];\n'.format(node.node_id, label)
if node.type == NodeType.IF: if node.type in [NodeType.IF, NodeType.IFLOOP]:
true_node = node.son_true true_node = node.son_true
if true_node: if true_node:
content += '{}->{}[label="True"];\n'.format(node.node_id, true_node.node_id) content += '{}->{}[label="True"];\n'.format(node.node_id, true_node.node_id)

@ -398,18 +398,24 @@ class FunctionSolc:
node_condition = self._new_node(NodeType.IFLOOP, condition["src"]) node_condition = self._new_node(NodeType.IFLOOP, condition["src"])
node_condition.add_unparsed_expression(condition) node_condition.add_unparsed_expression(condition)
link_underlying_nodes(node_startLoop, node_condition) link_underlying_nodes(node_startLoop, node_condition)
link_underlying_nodes(node_condition, node_endLoop)
node_beforeBody = node_condition
else: else:
node_condition = node_startLoop node_condition = None
node_beforeBody = node_startLoop
node_body = self._parse_statement(body, node_beforeBody)
node_body = self._parse_statement(body, node_condition) if node_condition:
link_underlying_nodes(node_condition, node_endLoop)
node_LoopExpression = None node_LoopExpression = None
if loop_expression: if loop_expression:
node_LoopExpression = self._parse_statement(loop_expression, node_body) node_LoopExpression = self._parse_statement(loop_expression, node_body)
link_underlying_nodes(node_LoopExpression, node_condition) link_underlying_nodes(node_LoopExpression, node_beforeBody)
else: else:
link_underlying_nodes(node_body, node_condition) link_underlying_nodes(node_body, node_beforeBody)
if not condition: if not condition:
if not loop_expression: if not loop_expression:
@ -497,13 +503,15 @@ class FunctionSolc:
# expression = parse_expression(candidate, self) # expression = parse_expression(candidate, self)
node_condition.add_unparsed_expression(expression) node_condition.add_unparsed_expression(expression)
link_underlying_nodes(node_startLoop, node_condition) link_underlying_nodes(node_startLoop, node_condition)
link_underlying_nodes(node_condition, node_endLoop)
hasCondition = True hasCondition = True
else: else:
hasCondition = False hasCondition = False
node_statement = self._parse_statement(children[-1], node_condition) node_statement = self._parse_statement(children[-1], node_condition)
if hasCondition:
link_underlying_nodes(node_condition, node_endLoop)
node_LoopExpression = node_statement node_LoopExpression = node_statement
if hasLoopExpression: if hasLoopExpression:
if len(children) > 2: if len(children) > 2:

Loading…
Cancel
Save