@@ -329,13 +329,17 @@ def analyze_content(self):
329
329
###################################################################################
330
330
###################################################################################
331
331
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 :
333
335
node = self ._function .new_node (node_type , src , scope )
334
336
node_parser = NodeSolc (node )
335
337
self ._node_to_nodesolc [node ] = node_parser
336
338
return node_parser
337
339
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 :
339
343
scope = Scope (False , True , father_scope )
340
344
node = self ._function .new_node (NodeType .ASSEMBLY , src , scope )
341
345
contract = None
@@ -366,26 +370,42 @@ def _parse_if(self, if_statement: Dict, node: NodeSolc) -> NodeSolc:
366
370
condition = if_statement ["condition" ]
367
371
# Note: check if the expression could be directly
368
372
# 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
+ )
370
376
condition_node .add_unparsed_expression (condition )
371
377
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
+ )
374
384
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
+ )
377
391
else :
378
392
children = if_statement [self .get_children ("children" )]
379
393
condition = children [0 ]
380
394
# Note: check if the expression could be directly
381
395
# 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
+ )
383
399
condition_node .add_unparsed_expression (condition )
384
400
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
+ )
386
404
trueStatement = self ._parse_statement (children [1 ], condition_node , true_scope )
387
405
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
+ )
389
409
falseStatement = self ._parse_statement (children [2 ], condition_node , false_scope )
390
410
391
411
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:
400
420
def _parse_while (self , whilte_statement : Dict , node : NodeSolc ) -> NodeSolc :
401
421
# WhileStatement = 'while' '(' Expression ')' Statement
402
422
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
+ )
404
426
405
427
body_scope = Scope (node .underlying_node .scope .is_checked , False , node .underlying_node .scope )
406
428
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
+ )
408
432
node_condition .add_unparsed_expression (whilte_statement ["condition" ])
409
433
statement = self ._parse_statement (whilte_statement ["body" ], node_condition , body_scope )
410
434
else :
411
435
children = whilte_statement [self .get_children ("children" )]
412
436
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
+ )
414
440
node_condition .add_unparsed_expression (expression )
415
441
statement = self ._parse_statement (children [1 ], node_condition , body_scope )
416
442
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
+ )
418
446
419
447
link_underlying_nodes (node , node_startWhile )
420
448
link_underlying_nodes (node_startWhile , node_condition )
@@ -550,8 +578,12 @@ def _parse_for(self, statement: Dict, node: NodeSolc) -> NodeSolc:
550
578
else :
551
579
pre , cond , post , body = self ._parse_for_legacy_ast (statement )
552
580
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
+ )
555
587
556
588
last_scope = node .underlying_node .scope
557
589
@@ -597,13 +629,21 @@ def _parse_for(self, statement: Dict, node: NodeSolc) -> NodeSolc:
597
629
598
630
def _parse_dowhile (self , do_while_statement : Dict , node : NodeSolc ) -> NodeSolc :
599
631
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
+ )
602
638
603
639
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
+ )
605
643
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
+ )
607
647
else :
608
648
children = do_while_statement [self .get_children ("children" )]
609
649
# same order in the AST as while
@@ -633,7 +673,9 @@ def _parse_try_catch(self, statement: Dict, node: NodeSolc) -> NodeSolc:
633
673
634
674
if externalCall is None :
635
675
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
+ )
637
679
new_node = self ._new_node (NodeType .TRY , statement ["src" ], catch_scope )
638
680
new_node .add_unparsed_expression (externalCall )
639
681
link_underlying_nodes (node , new_node )
@@ -675,7 +717,9 @@ def _parse_variable_definition(self, statement: Dict, node: NodeSolc) -> NodeSol
675
717
self ._add_local_variable (local_var_parser )
676
718
# local_var.analyze(self)
677
719
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
+ )
679
723
new_node .underlying_node .add_variable_declaration (local_var )
680
724
link_underlying_nodes (node , new_node )
681
725
return new_node
@@ -758,7 +802,9 @@ def _parse_variable_definition(self, statement: Dict, node: NodeSolc) -> NodeSol
758
802
"typeDescriptions" : {"typeString" : "tuple()" },
759
803
}
760
804
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
+ )
762
808
new_node .add_unparsed_expression (expression )
763
809
link_underlying_nodes (node , new_node )
764
810
@@ -838,7 +884,9 @@ def _parse_variable_definition(self, statement: Dict, node: NodeSolc) -> NodeSol
838
884
],
839
885
}
840
886
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
+ )
842
890
new_node .add_unparsed_expression (expression )
843
891
link_underlying_nodes (node , new_node )
844
892
@@ -860,7 +908,9 @@ def _parse_variable_definition_init_tuple(
860
908
link_underlying_nodes (node , new_node )
861
909
return new_node
862
910
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 :
864
914
"""
865
915
866
916
Return:
@@ -1146,7 +1196,9 @@ def _parse_modifier(self, modifier: Dict):
1146
1196
1147
1197
for m in ExportValues (m ).result ():
1148
1198
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
+ )
1150
1202
node_parser .add_unparsed_expression (modifier )
1151
1203
# The latest entry point is the entry point, or the latest modifier call
1152
1204
if self ._function .modifiers :
@@ -1163,7 +1215,9 @@ def _parse_modifier(self, modifier: Dict):
1163
1215
)
1164
1216
1165
1217
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
+ )
1167
1221
node_parser .add_unparsed_expression (modifier )
1168
1222
# The latest entry point is the entry point, or the latest constructor call
1169
1223
if self ._function .explicit_base_constructor_calls_statements :
0 commit comments