reduced variable count

pull/2069/head
Tiko7454 1 year ago
parent a958bc446d
commit b7e7287417
  1. 23
      slither/solc_parsing/declarations/function.py

@ -1403,16 +1403,13 @@ class FunctionSolc(CallerContextExpression):
def __make_temporary_variable_declaration_node_from_condition( def __make_temporary_variable_declaration_node_from_condition(
self, self,
node_expression: "Expression", node: Node,
node_source_mapping: SourceMapping,
node_scope: Union[Scope, Function],
node_function: Function,
temp_var: Optional[LocalVariable] = None temp_var: Optional[LocalVariable] = None
) -> (Node, LocalVariable): ) -> (Node, LocalVariable):
temp_var_node_parser = self._new_node( temp_var_node_parser = self._new_node(
NodeType.VARIABLE, NodeType.VARIABLE,
node_source_mapping, node.source_mapping,
node_scope node.scope
) )
temp_var_node = temp_var_node_parser.underlying_node temp_var_node = temp_var_node_parser.underlying_node
if temp_var is None: if temp_var is None:
@ -1422,11 +1419,11 @@ class FunctionSolc(CallerContextExpression):
temp_var.type = ElementaryType('bool') temp_var.type = ElementaryType('bool')
temp_var.initialized = True temp_var.initialized = True
temp_var.set_location('default') temp_var.set_location('default')
temp_var.set_function(node_function) temp_var.set_function(node.function)
temp_var_node.add_expression( temp_var_node.add_expression(
AssignmentOperation( AssignmentOperation(
Identifier(temp_var), Identifier(temp_var),
node_expression, node.expression,
AssignmentOperationType.ASSIGN, AssignmentOperationType.ASSIGN,
None None
) )
@ -1466,10 +1463,7 @@ class FunctionSolc(CallerContextExpression):
if has_cond.result(): if has_cond.result():
if node.is_conditional(): if node.is_conditional():
temp_var_node, temp_var = self.__make_temporary_variable_declaration_node_from_condition( temp_var_node, temp_var = self.__make_temporary_variable_declaration_node_from_condition(
node.expression, node
node.source_mapping,
node.scope,
node.function
) )
if node.type == NodeType.IF: if node.type == NodeType.IF:
self.__link_node_immediately_before(temp_var_node, node) self.__link_node_immediately_before(temp_var_node, node)
@ -1480,10 +1474,7 @@ class FunctionSolc(CallerContextExpression):
if begin_loop_node: # if BEGIN_LOOP is IF_LOOP's father, IF_LOOP represents `while` if begin_loop_node: # if BEGIN_LOOP is IF_LOOP's father, IF_LOOP represents `while`
temp_var_node_pre_loop = temp_var_node temp_var_node_pre_loop = temp_var_node
temp_var_node_during_loop, _ = self.__make_temporary_variable_declaration_node_from_condition( temp_var_node_during_loop, _ = self.__make_temporary_variable_declaration_node_from_condition(
if_loop_node.expression, if_loop_node,
if_loop_node.source_mapping,
if_loop_node.scope,
if_loop_node.function,
temp_var temp_var
) )
self.__link_node_immediately_before(temp_var_node_during_loop, if_loop_node, begin_loop_node) self.__link_node_immediately_before(temp_var_node_during_loop, if_loop_node, begin_loop_node)

Loading…
Cancel
Save