@@ -128,6 +128,7 @@ def visitTypeDefinition(self, ctx):
128
128
return Node (ctx = ctx ,
129
129
type = "TypeDefinition" ,
130
130
typeKeyword = ctx .TypeKeyword ().getText (),
131
+ name = ctx .identifier ().getText (),
131
132
elementaryTypeName = self .visit (ctx .elementaryTypeName ()))
132
133
133
134
@@ -467,7 +468,9 @@ def visitModifierDefinition(self, ctx):
467
468
type = 'ModifierDefinition' ,
468
469
name = ctx .identifier ().getText (),
469
470
parameters = parameters ,
470
- body = self .visit (ctx .block ()))
471
+ body = self .visit (ctx .block ()),
472
+ isVirtual = ctx .VirtualKeyword () is not None ,
473
+ isOverride = ctx .overrideSpecifier () is not None )
471
474
472
475
def visitStatement (self , ctx ):
473
476
return self .visit (ctx .getChild (0 ))
@@ -485,6 +488,13 @@ def visitRevertStatement(self, ctx):
485
488
type = 'RevertStatement' ,
486
489
functionCall = self .visit (ctx .functionCall ()))
487
490
491
+ def _index_of_child (self , ctx , child ):
492
+ for i in range (0 , len (ctx .children )):
493
+ if ctx .getChild (i ).getText () == child :
494
+ return i
495
+
496
+ return None
497
+
488
498
def visitExpression (self , ctx ):
489
499
490
500
children_length = len (ctx .children )
@@ -599,12 +609,28 @@ def visitExpression(self, ctx):
599
609
arguments = args ,
600
610
names = names )
601
611
602
- if ctx .getChild (1 ).getText () == '[' and ctx .getChild (3 ).getText () == ']' :
612
+ if (ctx .getChild (1 ).getText () == '[' and
613
+ ctx .getChild (2 ).getText () != ':' and
614
+ ctx .getChild (3 ).getText () == ']' ):
603
615
return Node (ctx = ctx ,
604
616
type = 'IndexAccess' ,
605
617
base = self .visit (ctx .getChild (0 )),
606
618
index = self .visit (ctx .getChild (2 )))
607
619
620
+ if ctx .getChild (1 ).getText () == '{' and ctx .getChild (3 ).getText () == '}' :
621
+ args = []
622
+ names = []
623
+
624
+ for nameValue in ctx .nameValueList ().nameValue ():
625
+ args .append (self .visit (nameValue .expression ()))
626
+ names .append (nameValue .identifier ().getText ())
627
+
628
+ return Node (ctx = ctx ,
629
+ type = 'FunctionCallOptions' ,
630
+ expression = self .visit (ctx .getChild (0 )),
631
+ arguments = args ,
632
+ names = names )
633
+
608
634
elif children_length == 5 :
609
635
# ternary
610
636
if ctx .getChild (1 ).getText () == '?' and ctx .getChild (3 ).getText () == ':' :
@@ -614,6 +640,30 @@ def visitExpression(self, ctx):
614
640
TrueExpression = self .visit (ctx .getChild (2 )),
615
641
FalseExpression = self .visit (ctx .getChild (4 )))
616
642
643
+ if 4 <= children_length <= 6 and ctx .getChild (1 ).getText () == '[' :
644
+ left_bracket_index = self ._index_of_child (ctx , '[' )
645
+ colon_index = self ._index_of_child (ctx , ':' )
646
+ right_bracket_index = self ._index_of_child (ctx , ']' )
647
+
648
+ if (left_bracket_index == 1 and
649
+ left_bracket_index < colon_index <= left_bracket_index + 2 and
650
+ colon_index < right_bracket_index <= colon_index + 2 and
651
+ right_bracket_index == children_length - 1 ):
652
+ indexLower = None
653
+ indexUpper = None
654
+
655
+ if colon_index == left_bracket_index + 2 :
656
+ indexLower = self .visit (ctx .getChild (left_bracket_index + 1 ))
657
+
658
+ if right_bracket_index == colon_index + 2 :
659
+ indexUpper = self .visit (ctx .getChild (colon_index + 1 ))
660
+
661
+ return Node (ctx = ctx ,
662
+ type = 'IndexRangeAccess' ,
663
+ base = self .visit (ctx .getChild (0 )),
664
+ indexLower = indexLower ,
665
+ indexUpper = indexUpper )
666
+
617
667
return self .visit (list (ctx .getChildren ()))
618
668
619
669
@@ -741,16 +791,16 @@ def visitIdentifierList(self, ctx: SolidityParser.IdentifierListContext):
741
791
def visitVariableDeclarationList (self , ctx : SolidityParser .VariableDeclarationListContext ):
742
792
result = []
743
793
for decl in self ._mapCommasToNulls (ctx .children ):
744
- if decl == None :
745
- return None
746
-
747
- result .append (self ._createNode (ctx = ctx ,
748
- type = 'VariableDeclaration' ,
749
- name = decl .identifier ().getText (),
750
- typeName = self .visit (decl .typeName ()),
751
- isStateVar = False ,
752
- isIndexed = False ,
753
- decl = decl ))
794
+ if decl is None :
795
+ result . append ( None )
796
+ else :
797
+ result .append (self ._createNode (ctx = ctx ,
798
+ type = 'VariableDeclaration' ,
799
+ name = decl .identifier ().getText (),
800
+ typeName = self .visit (decl .typeName ()),
801
+ isStateVar = False ,
802
+ isIndexed = False ,
803
+ decl = decl ))
754
804
755
805
return result
756
806
@@ -845,9 +895,16 @@ def visitAssemblyExpression(self, ctx):
845
895
return self .visit (ctx .getChild (0 ))
846
896
847
897
def visitAssemblyMember (self , ctx ):
898
+ identifier = ctx .identifier ()
899
+
900
+ if isinstance (identifier , list ):
901
+ name = [n .getText () for n in identifier ]
902
+ else :
903
+ name = identifier .getText ()
904
+
848
905
return Node (ctx = ctx ,
849
906
type = 'AssemblyMember' ,
850
- name = ctx . identifier (). getText () )
907
+ name = name )
851
908
852
909
def visitAssemblyCall (self , ctx ):
853
910
functionName = ctx .getChild (0 ).getText ()
@@ -935,8 +992,10 @@ def visitAssemblyAssignment(self, ctx):
935
992
936
993
if names .identifier ():
937
994
names = [self .visit (names .identifier ())]
938
- else :
995
+ elif names . assemblyIdentifierList () :
939
996
names = self .visit (names .assemblyIdentifierList ().identifier ())
997
+ else :
998
+ names = self .visit (names .assemblyMember ())
940
999
941
1000
return Node (ctx = ctx ,
942
1001
type = 'AssemblyAssignment' ,
@@ -1016,7 +1075,17 @@ def visitUserDefinedTypename(self, ctx):
1016
1075
name = ctx .getText ())
1017
1076
1018
1077
def visitReturnStatement (self , ctx ):
1019
- return self .visit (ctx .expression ())
1078
+ return Node (ctx = ctx ,
1079
+ type = "ReturnStatement" ,
1080
+ expression = self .visit (ctx .expression ()))
1081
+
1082
+ def visitBreakStatement (self , ctx ):
1083
+ return Node (ctx = ctx ,
1084
+ type = "BreakStatement" )
1085
+
1086
+ def visitContinueStatement (self , ctx ):
1087
+ return Node (ctx = ctx ,
1088
+ type = "ContinueStatement" )
1020
1089
1021
1090
def visitTerminal (self , ctx ):
1022
1091
return ctx .getText ()
0 commit comments