Skip to content

Commit 65497ec

Browse files
committed
minor
1 parent f797166 commit 65497ec

File tree

7 files changed

+161
-57
lines changed

7 files changed

+161
-57
lines changed

slither/core/cfg/scope.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
from slither.core.declarations.function import Function
66

77

8+
# pylint: disable=too-few-public-methods
89
class Scope:
9-
10-
def __init__(self, is_checked:bool, is_yul: bool, scope: Union["Scope", "Function"]):
11-
self.nodes: List[Node] = []
10+
def __init__(self, is_checked: bool, is_yul: bool, scope: Union["Scope", "Function"]):
11+
self.nodes: List["Node"] = []
1212
self.is_checked = is_checked
1313
self.is_yul = is_yul
14-
self.father = scope
14+
self.father = scope

slither/core/declarations/contract.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1115,12 +1115,16 @@ def add_constructor_variables(self):
11151115
constructor_variable.set_offset(self.source_mapping, self.compilation_unit)
11161116
self._functions[constructor_variable.canonical_name] = constructor_variable
11171117

1118-
prev_node = self._create_node(constructor_variable, 0, variable_candidate, constructor_variable)
1118+
prev_node = self._create_node(
1119+
constructor_variable, 0, variable_candidate, constructor_variable
1120+
)
11191121
variable_candidate.node_initialization = prev_node
11201122
counter = 1
11211123
for v in self.state_variables[idx + 1 :]:
11221124
if v.expression and not v.is_constant:
1123-
next_node = self._create_node(constructor_variable, counter, v, prev_node.scope)
1125+
next_node = self._create_node(
1126+
constructor_variable, counter, v, prev_node.scope
1127+
)
11241128
v.node_initialization = next_node
11251129
prev_node.add_son(next_node)
11261130
next_node.add_father(prev_node)
@@ -1143,12 +1147,16 @@ def add_constructor_variables(self):
11431147
constructor_variable.set_offset(self.source_mapping, self.compilation_unit)
11441148
self._functions[constructor_variable.canonical_name] = constructor_variable
11451149

1146-
prev_node = self._create_node(constructor_variable, 0, variable_candidate, constructor_variable)
1150+
prev_node = self._create_node(
1151+
constructor_variable, 0, variable_candidate, constructor_variable
1152+
)
11471153
variable_candidate.node_initialization = prev_node
11481154
counter = 1
11491155
for v in self.state_variables[idx + 1 :]:
11501156
if v.expression and v.is_constant:
1151-
next_node = self._create_node(constructor_variable, counter, v, prev_node.scope)
1157+
next_node = self._create_node(
1158+
constructor_variable, counter, v, prev_node.scope
1159+
)
11521160
v.node_initialization = next_node
11531161
prev_node.add_son(next_node)
11541162
next_node.add_father(prev_node)
@@ -1157,7 +1165,9 @@ def add_constructor_variables(self):
11571165

11581166
break
11591167

1160-
def _create_node(self, func: Function, counter: int, variable: "Variable", scope: Union[Scope, Function]):
1168+
def _create_node(
1169+
self, func: Function, counter: int, variable: "Variable", scope: Union[Scope, Function]
1170+
):
11611171
from slither.core.cfg.node import Node, NodeType
11621172
from slither.core.expressions import (
11631173
AssignmentOperationType,

slither/core/declarations/function.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1531,7 +1531,9 @@ def _analyze_calls(self):
15311531
###################################################################################
15321532
###################################################################################
15331533

1534-
def new_node(self, node_type: "NodeType", src: Union[str, Dict], scope: Union[Scope, "Function"]) -> "Node":
1534+
def new_node(
1535+
self, node_type: "NodeType", src: Union[str, Dict], scope: Union[Scope, "Function"]
1536+
) -> "Node":
15351537
from slither.core.cfg.node import Node
15361538

15371539
node = Node(node_type, self._counter_nodes, scope)

slither/slithir/operations/binary.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ def __str__(self): # pylint: disable=too-many-branches
131131

132132

133133
class Binary(OperationWithLValue):
134-
def __init__(self, result, left_variable, right_variable, operation_type: BinaryType, is_checked: bool=False):
134+
def __init__(self, result, left_variable, right_variable, operation_type: BinaryType):
135135
assert is_valid_rvalue(left_variable) or isinstance(left_variable, Function)
136136
assert is_valid_rvalue(right_variable) or isinstance(right_variable, Function)
137137
assert is_valid_lvalue(result)
@@ -144,7 +144,6 @@ def __init__(self, result, left_variable, right_variable, operation_type: Binary
144144
result.set_type(ElementaryType("bool"))
145145
else:
146146
result.set_type(left_variable.type)
147-
self.is_checked = is_checked
148147

149148
@property
150149
def read(self):

slither/solc_parsing/declarations/function.py

Lines changed: 81 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -329,13 +329,17 @@ def analyze_content(self):
329329
###################################################################################
330330
###################################################################################
331331

332-
def _new_node(self, node_type: NodeType, src: Union[str, Dict], scope: Union[Scope, "Function"]) -> NodeSolc:
332+
def _new_node(
333+
self, node_type: NodeType, src: Union[str, Dict], scope: Union[Scope, "Function"]
334+
) -> NodeSolc:
333335
node = self._function.new_node(node_type, src, scope)
334336
node_parser = NodeSolc(node)
335337
self._node_to_nodesolc[node] = node_parser
336338
return node_parser
337339

338-
def _new_yul_block(self, src: Union[str, Dict], father_scope: Union[Scope, Function]) -> YulBlock:
340+
def _new_yul_block(
341+
self, src: Union[str, Dict], father_scope: Union[Scope, Function]
342+
) -> YulBlock:
339343
scope = Scope(False, True, father_scope)
340344
node = self._function.new_node(NodeType.ASSEMBLY, src, scope)
341345
contract = None
@@ -366,26 +370,42 @@ def _parse_if(self, if_statement: Dict, node: NodeSolc) -> NodeSolc:
366370
condition = if_statement["condition"]
367371
# Note: check if the expression could be directly
368372
# parsed here
369-
condition_node = self._new_node(NodeType.IF, condition["src"], node.underlying_node.scope)
373+
condition_node = self._new_node(
374+
NodeType.IF, condition["src"], node.underlying_node.scope
375+
)
370376
condition_node.add_unparsed_expression(condition)
371377
link_underlying_nodes(node, condition_node)
372-
true_scope = Scope(node.underlying_node.scope.is_checked, False, node.underlying_node.scope)
373-
trueStatement = self._parse_statement(if_statement["trueBody"], condition_node, true_scope)
378+
true_scope = Scope(
379+
node.underlying_node.scope.is_checked, False, node.underlying_node.scope
380+
)
381+
trueStatement = self._parse_statement(
382+
if_statement["trueBody"], condition_node, true_scope
383+
)
374384
if "falseBody" in if_statement and if_statement["falseBody"]:
375-
false_scope = Scope(node.underlying_node.scope.is_checked, False, node.underlying_node.scope)
376-
falseStatement = self._parse_statement(if_statement["falseBody"], condition_node, false_scope)
385+
false_scope = Scope(
386+
node.underlying_node.scope.is_checked, False, node.underlying_node.scope
387+
)
388+
falseStatement = self._parse_statement(
389+
if_statement["falseBody"], condition_node, false_scope
390+
)
377391
else:
378392
children = if_statement[self.get_children("children")]
379393
condition = children[0]
380394
# Note: check if the expression could be directly
381395
# parsed here
382-
condition_node = self._new_node(NodeType.IF, condition["src"], node.underlying_node.scope)
396+
condition_node = self._new_node(
397+
NodeType.IF, condition["src"], node.underlying_node.scope
398+
)
383399
condition_node.add_unparsed_expression(condition)
384400
link_underlying_nodes(node, condition_node)
385-
true_scope = Scope(node.underlying_node.scope.is_checked, False, node.underlying_node.scope)
401+
true_scope = Scope(
402+
node.underlying_node.scope.is_checked, False, node.underlying_node.scope
403+
)
386404
trueStatement = self._parse_statement(children[1], condition_node, true_scope)
387405
if len(children) == 3:
388-
false_scope = Scope(node.underlying_node.scope.is_checked, False, node.underlying_node.scope)
406+
false_scope = Scope(
407+
node.underlying_node.scope.is_checked, False, node.underlying_node.scope
408+
)
389409
falseStatement = self._parse_statement(children[2], condition_node, false_scope)
390410

391411
endIf_node = self._new_node(NodeType.ENDIF, if_statement["src"], node.underlying_node.scope)
@@ -400,21 +420,29 @@ def _parse_if(self, if_statement: Dict, node: NodeSolc) -> NodeSolc:
400420
def _parse_while(self, whilte_statement: Dict, node: NodeSolc) -> NodeSolc:
401421
# WhileStatement = 'while' '(' Expression ')' Statement
402422

403-
node_startWhile = self._new_node(NodeType.STARTLOOP, whilte_statement["src"], node.underlying_node.scope)
423+
node_startWhile = self._new_node(
424+
NodeType.STARTLOOP, whilte_statement["src"], node.underlying_node.scope
425+
)
404426

405427
body_scope = Scope(node.underlying_node.scope.is_checked, False, node.underlying_node.scope)
406428
if self.is_compact_ast:
407-
node_condition = self._new_node(NodeType.IFLOOP, whilte_statement["condition"]["src"], node.underlying_node.scope)
429+
node_condition = self._new_node(
430+
NodeType.IFLOOP, whilte_statement["condition"]["src"], node.underlying_node.scope
431+
)
408432
node_condition.add_unparsed_expression(whilte_statement["condition"])
409433
statement = self._parse_statement(whilte_statement["body"], node_condition, body_scope)
410434
else:
411435
children = whilte_statement[self.get_children("children")]
412436
expression = children[0]
413-
node_condition = self._new_node(NodeType.IFLOOP, expression["src"], node.underlying_node.scope)
437+
node_condition = self._new_node(
438+
NodeType.IFLOOP, expression["src"], node.underlying_node.scope
439+
)
414440
node_condition.add_unparsed_expression(expression)
415441
statement = self._parse_statement(children[1], node_condition, body_scope)
416442

417-
node_endWhile = self._new_node(NodeType.ENDLOOP, whilte_statement["src"], node.underlying_node.scope)
443+
node_endWhile = self._new_node(
444+
NodeType.ENDLOOP, whilte_statement["src"], node.underlying_node.scope
445+
)
418446

419447
link_underlying_nodes(node, node_startWhile)
420448
link_underlying_nodes(node_startWhile, node_condition)
@@ -550,8 +578,12 @@ def _parse_for(self, statement: Dict, node: NodeSolc) -> NodeSolc:
550578
else:
551579
pre, cond, post, body = self._parse_for_legacy_ast(statement)
552580

553-
node_startLoop = self._new_node(NodeType.STARTLOOP, statement["src"], node.underlying_node.scope)
554-
node_endLoop = self._new_node(NodeType.ENDLOOP, statement["src"], node.underlying_node.scope)
581+
node_startLoop = self._new_node(
582+
NodeType.STARTLOOP, statement["src"], node.underlying_node.scope
583+
)
584+
node_endLoop = self._new_node(
585+
NodeType.ENDLOOP, statement["src"], node.underlying_node.scope
586+
)
555587

556588
last_scope = node.underlying_node.scope
557589

@@ -597,13 +629,21 @@ def _parse_for(self, statement: Dict, node: NodeSolc) -> NodeSolc:
597629

598630
def _parse_dowhile(self, do_while_statement: Dict, node: NodeSolc) -> NodeSolc:
599631

600-
node_startDoWhile = self._new_node(NodeType.STARTLOOP, do_while_statement["src"], node.underlying_node.scope)
601-
condition_scope = Scope(node.underlying_node.scope.is_checked, False, node.underlying_node.scope)
632+
node_startDoWhile = self._new_node(
633+
NodeType.STARTLOOP, do_while_statement["src"], node.underlying_node.scope
634+
)
635+
condition_scope = Scope(
636+
node.underlying_node.scope.is_checked, False, node.underlying_node.scope
637+
)
602638

603639
if self.is_compact_ast:
604-
node_condition = self._new_node(NodeType.IFLOOP, do_while_statement["condition"]["src"], condition_scope)
640+
node_condition = self._new_node(
641+
NodeType.IFLOOP, do_while_statement["condition"]["src"], condition_scope
642+
)
605643
node_condition.add_unparsed_expression(do_while_statement["condition"])
606-
statement = self._parse_statement(do_while_statement["body"], node_condition, condition_scope)
644+
statement = self._parse_statement(
645+
do_while_statement["body"], node_condition, condition_scope
646+
)
607647
else:
608648
children = do_while_statement[self.get_children("children")]
609649
# same order in the AST as while
@@ -633,7 +673,9 @@ def _parse_try_catch(self, statement: Dict, node: NodeSolc) -> NodeSolc:
633673

634674
if externalCall is None:
635675
raise ParsingError("Try/Catch not correctly parsed by Slither %s" % statement)
636-
catch_scope = Scope(node.underlying_node.scope.is_checked, False, node.underlying_node.scope)
676+
catch_scope = Scope(
677+
node.underlying_node.scope.is_checked, False, node.underlying_node.scope
678+
)
637679
new_node = self._new_node(NodeType.TRY, statement["src"], catch_scope)
638680
new_node.add_unparsed_expression(externalCall)
639681
link_underlying_nodes(node, new_node)
@@ -675,7 +717,9 @@ def _parse_variable_definition(self, statement: Dict, node: NodeSolc) -> NodeSol
675717
self._add_local_variable(local_var_parser)
676718
# local_var.analyze(self)
677719

678-
new_node = self._new_node(NodeType.VARIABLE, statement["src"], node.underlying_node.scope)
720+
new_node = self._new_node(
721+
NodeType.VARIABLE, statement["src"], node.underlying_node.scope
722+
)
679723
new_node.underlying_node.add_variable_declaration(local_var)
680724
link_underlying_nodes(node, new_node)
681725
return new_node
@@ -758,7 +802,9 @@ def _parse_variable_definition(self, statement: Dict, node: NodeSolc) -> NodeSol
758802
"typeDescriptions": {"typeString": "tuple()"},
759803
}
760804
node = new_node
761-
new_node = self._new_node(NodeType.EXPRESSION, statement["src"], node.underlying_node.scope)
805+
new_node = self._new_node(
806+
NodeType.EXPRESSION, statement["src"], node.underlying_node.scope
807+
)
762808
new_node.add_unparsed_expression(expression)
763809
link_underlying_nodes(node, new_node)
764810

@@ -838,7 +884,9 @@ def _parse_variable_definition(self, statement: Dict, node: NodeSolc) -> NodeSol
838884
],
839885
}
840886
node = new_node
841-
new_node = self._new_node(NodeType.EXPRESSION, statement["src"], node.underlying_node.scope)
887+
new_node = self._new_node(
888+
NodeType.EXPRESSION, statement["src"], node.underlying_node.scope
889+
)
842890
new_node.add_unparsed_expression(expression)
843891
link_underlying_nodes(node, new_node)
844892

@@ -860,7 +908,9 @@ def _parse_variable_definition_init_tuple(
860908
link_underlying_nodes(node, new_node)
861909
return new_node
862910

863-
def _parse_statement(self, statement: Dict, node: NodeSolc, scope: Union[Scope, Function]) -> NodeSolc:
911+
def _parse_statement(
912+
self, statement: Dict, node: NodeSolc, scope: Union[Scope, Function]
913+
) -> NodeSolc:
864914
"""
865915
866916
Return:
@@ -1146,7 +1196,9 @@ def _parse_modifier(self, modifier: Dict):
11461196

11471197
for m in ExportValues(m).result():
11481198
if isinstance(m, Function):
1149-
node_parser = self._new_node(NodeType.EXPRESSION, modifier["src"], self.underlying_function)
1199+
node_parser = self._new_node(
1200+
NodeType.EXPRESSION, modifier["src"], self.underlying_function
1201+
)
11501202
node_parser.add_unparsed_expression(modifier)
11511203
# The latest entry point is the entry point, or the latest modifier call
11521204
if self._function.modifiers:
@@ -1163,7 +1215,9 @@ def _parse_modifier(self, modifier: Dict):
11631215
)
11641216

11651217
elif isinstance(m, Contract):
1166-
node_parser = self._new_node(NodeType.EXPRESSION, modifier["src"], self.underlying_function)
1218+
node_parser = self._new_node(
1219+
NodeType.EXPRESSION, modifier["src"], self.underlying_function
1220+
)
11671221
node_parser.add_unparsed_expression(modifier)
11681222
# The latest entry point is the entry point, or the latest constructor call
11691223
if self._function.explicit_base_constructor_calls_statements:

slither/solc_parsing/declarations/modifier.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,9 @@ def analyze_content(self):
9393
# self._analyze_read_write()
9494
# self._analyze_calls()
9595

96-
def _parse_statement(self, statement: Dict, node: NodeSolc, scope: Union[Scope, "Function"]) -> NodeSolc:
96+
def _parse_statement(
97+
self, statement: Dict, node: NodeSolc, scope: Union[Scope, "Function"]
98+
) -> NodeSolc:
9799
name = statement[self.get_key()]
98100
if name == "PlaceholderStatement":
99101
placeholder_node = self._new_node(NodeType.PLACEHOLDER, statement["src"], scope)

0 commit comments

Comments
 (0)