@@ -48,7 +48,7 @@ impl ContractDefinitionStruct {
4848 // be able to obtain it here, but for that we need bi-directional tree
4949 // navigation
5050 pub fn compute_abi_with_file_id ( & self , file_id : String ) -> Option < ContractAbi > {
51- let name = self . name ( ) . unparse ( ) ;
51+ let name = self . ir_node . name . unparse ( ) ;
5252 let functions = self . compute_abi_functions ( ) ?;
5353 let storage_layout = self . compute_storage_layout ( ) ?;
5454 Some ( ContractAbi {
@@ -66,12 +66,12 @@ impl ContractDefinitionStruct {
6666 functions. push ( constructor. compute_abi ( ) ?) ;
6767 }
6868 for function in & self . linearised_functions ( ) {
69- if function. is_public ( ) {
69+ if function. is_externally_visible ( ) {
7070 functions. push ( function. compute_abi ( ) ?) ;
7171 }
7272 }
7373 for state_variable in & self . linearised_state_variables ( ) {
74- if state_variable. is_public ( ) {
74+ if state_variable. is_externally_visible ( ) {
7575 functions. push ( state_variable. compute_abi ( ) ?) ;
7676 }
7777 }
@@ -106,7 +106,7 @@ impl ContractDefinitionStruct {
106106 ptr += remaining_bytes;
107107 }
108108
109- let label = state_variable. name ( ) . unparse ( ) ;
109+ let label = state_variable. ir_node . name . unparse ( ) ;
110110 let slot = ptr. div ( SemanticAnalysis :: SLOT_SIZE ) ;
111111 let offset = ptr % SemanticAnalysis :: SLOT_SIZE ;
112112 let r#type = self . semantic . type_canonical_name ( variable_type_id) ;
@@ -126,15 +126,15 @@ impl ContractDefinitionStruct {
126126}
127127
128128impl FunctionDefinitionStruct {
129- pub fn is_public ( & self ) -> bool {
129+ pub fn is_externally_visible ( & self ) -> bool {
130130 matches ! (
131131 self . visibility( ) ,
132132 FunctionVisibility :: Public | FunctionVisibility :: External
133133 )
134134 }
135135
136136 pub fn compute_abi ( & self ) -> Option < FunctionAbi > {
137- if !self . is_public ( ) {
137+ if !self . is_externally_visible ( ) {
138138 return None ;
139139 }
140140 let inputs = self . parameters ( ) . compute_abi ( ) ?;
@@ -146,7 +146,7 @@ impl FunctionDefinitionStruct {
146146
147147 Some ( FunctionAbi {
148148 node_id : self . ir_node . node_id ,
149- name : self . name ( ) . as_ref ( ) . map ( |name| name. unparse ( ) ) ,
149+ name : self . ir_node . name . as_ref ( ) . map ( |name| name. unparse ( ) ) ,
150150 kind : self . kind ( ) ,
151151 inputs,
152152 outputs,
@@ -155,13 +155,12 @@ impl FunctionDefinitionStruct {
155155 }
156156
157157 pub fn compute_selector ( & self ) -> Option < u32 > {
158- if !self . is_public ( ) {
158+ if !self . is_externally_visible ( ) {
159159 return None ;
160160 }
161- let name = self . name ( ) ?;
161+ let name = self . ir_node . name . as_ref ( ) ?. unparse ( ) ;
162162 let signature = format ! (
163163 "{name}({parameters})" ,
164- name = name. unparse( ) ,
165164 parameters = self . parameters( ) . compute_canonical_signature( ) ?,
166165 ) ;
167166
@@ -200,28 +199,33 @@ impl ParametersStruct {
200199}
201200
202201impl StateVariableDefinitionStruct {
203- pub fn is_public ( & self ) -> bool {
202+ pub fn is_externally_visible ( & self ) -> bool {
204203 matches ! ( self . visibility( ) , StateVariableVisibility :: Public )
205204 }
206205
207- pub fn compute_abi ( & self ) -> Option < FunctionAbi > {
208- if !self . is_public ( ) {
209- return None ;
210- }
211- let Some ( Definition :: StateVariable ( definition) ) = self
206+ fn extract_getter_type_parameters_abi (
207+ & self ,
208+ ) -> Option < ( Vec < FunctionParameter > , Vec < FunctionParameter > ) > {
209+ let Definition :: StateVariable ( definition) = self
212210 . semantic
213211 . binder
214- . find_definition_by_id ( self . ir_node . node_id )
212+ . find_definition_by_id ( self . ir_node . node_id ) ?
215213 else {
216- return None ;
214+ unreachable ! ( "definition is not a state variable" ) ;
217215 } ;
218- let ( inputs, outputs) = self
219- . semantic
220- . extract_function_type_parameters_abi ( definition. getter_type_id ?) ?;
216+ self . semantic
217+ . extract_function_type_parameters_abi ( definition. getter_type_id ?)
218+ }
219+
220+ pub fn compute_abi ( & self ) -> Option < FunctionAbi > {
221+ if !self . is_externally_visible ( ) {
222+ return None ;
223+ }
224+ let ( inputs, outputs) = self . extract_getter_type_parameters_abi ( ) ?;
221225
222226 Some ( FunctionAbi {
223227 node_id : self . ir_node . node_id ,
224- name : Some ( self . name ( ) . unparse ( ) ) ,
228+ name : Some ( self . ir_node . name . unparse ( ) ) ,
225229 kind : FunctionKind :: Regular ,
226230 inputs,
227231 outputs,
@@ -230,23 +234,14 @@ impl StateVariableDefinitionStruct {
230234 }
231235
232236 pub fn compute_selector ( & self ) -> Option < u32 > {
233- if !self . is_public ( ) {
237+ if !self . is_externally_visible ( ) {
234238 return None ;
235239 }
236- let Some ( Definition :: StateVariable ( definition) ) = self
237- . semantic
238- . binder
239- . find_definition_by_id ( self . ir_node . node_id )
240- else {
241- return None ;
242- } ;
243- let ( inputs, _) = self
244- . semantic
245- . extract_function_type_parameters_abi ( definition. getter_type_id ?) ?;
240+ let ( inputs, _) = self . extract_getter_type_parameters_abi ( ) ?;
246241
247242 let signature = format ! (
248243 "{name}({parameters})" ,
249- name = self . name( ) . unparse( ) ,
244+ name = self . ir_node . name. unparse( ) ,
250245 parameters = inputs
251246 . into_iter( )
252247 . map( |parameter| parameter. r#type)
0 commit comments