1
+
2
+ use solc_ast_rs_types:: types:: * ;
3
+ use solc_ast_rs_types:: visit;
4
+ use solc_ast_rs_types:: visit:: * ;
5
+ use crate :: types:: InteractableNode ;
6
+
7
+ pub struct DefinitionFinder {
8
+ id : i64 ,
9
+ node : Option < InteractableNode > ,
10
+ }
11
+
12
+ impl < ' ast > Visit < ' ast > for DefinitionFinder {
13
+ fn visit_contract_definition ( & mut self , contract : & ' ast ContractDefinition ) {
14
+ if contract. id == self . id {
15
+ self . node = Some ( InteractableNode :: ContractDefinition ( contract. clone ( ) ) ) ;
16
+ } else {
17
+ visit:: visit_contract_definition ( self , contract) ;
18
+ }
19
+ }
20
+ fn visit_function_definition ( & mut self , function : & ' ast FunctionDefinition ) {
21
+ if function. id == self . id {
22
+ self . node = Some ( InteractableNode :: FunctionDefinition ( function. clone ( ) ) ) ;
23
+ } else {
24
+ visit:: visit_function_definition ( self , function) ;
25
+ }
26
+ }
27
+ fn visit_modifier_definition ( & mut self , modifier : & ' ast ModifierDefinition ) {
28
+ if modifier. id == self . id {
29
+ self . node = Some ( InteractableNode :: ModifierDefinition ( modifier. clone ( ) ) ) ;
30
+ } else {
31
+ visit:: visit_modifier_definition ( self , modifier) ;
32
+ }
33
+ }
34
+ fn visit_struct_definition ( & mut self , struct_def : & ' ast StructDefinition ) {
35
+ if struct_def. id == self . id {
36
+ self . node = Some ( InteractableNode :: StructDefinition ( struct_def. clone ( ) ) ) ;
37
+ } else {
38
+ visit:: visit_struct_definition ( self , struct_def) ;
39
+ }
40
+ }
41
+ fn visit_enum_definition ( & mut self , enum_def : & ' ast EnumDefinition ) {
42
+ if enum_def. id == self . id {
43
+ self . node = Some ( InteractableNode :: EnumDefinition ( enum_def. clone ( ) ) ) ;
44
+ } else {
45
+ visit:: visit_enum_definition ( self , enum_def) ;
46
+ }
47
+ }
48
+ fn visit_variable_declaration ( & mut self , variable : & ' ast VariableDeclaration ) {
49
+ if variable. id == self . id {
50
+ self . node = Some ( InteractableNode :: VariableDeclaration ( variable. clone ( ) ) ) ;
51
+ } else {
52
+ visit:: visit_variable_declaration ( self , variable) ;
53
+ }
54
+ }
55
+ fn visit_event_definition ( & mut self , event : & ' ast EventDefinition ) {
56
+ if event. id == self . id {
57
+ self . node = Some ( InteractableNode :: EventDefinition ( event. clone ( ) ) ) ;
58
+ } else {
59
+ visit:: visit_event_definition ( self , event) ;
60
+ }
61
+ }
62
+ fn visit_enum_value ( & mut self , enum_value : & ' ast EnumValue ) {
63
+ if enum_value. id == self . id {
64
+ self . node = Some ( InteractableNode :: EnumValue ( enum_value. clone ( ) ) ) ;
65
+ } else {
66
+ visit:: visit_enum_value ( self , enum_value) ;
67
+ }
68
+ }
69
+ }
70
+
71
+ impl DefinitionFinder {
72
+
73
+ pub fn new ( id : i64 ) -> Self {
74
+ DefinitionFinder {
75
+ id,
76
+ node : None ,
77
+ }
78
+ }
79
+
80
+ pub fn find ( & mut self , src : & SourceUnit ) -> Option < InteractableNode > {
81
+ self . visit_source_unit ( src) ;
82
+ self . node . clone ( )
83
+ }
84
+ }
0 commit comments