@@ -97,43 +97,22 @@ pub fn generate_data_types<'ink>(
97
97
}
98
98
}
99
99
100
- // Separate function types from other types to process them later
101
- let mut function_types = vec ! [ ] ;
102
- let mut non_function_types = vec ! [ ] ;
103
-
100
+ // now create all other types (enum's, arrays, etc.)
104
101
for ( name, user_type) in & types {
105
- if let DataTypeInformation :: Struct { source : StructSource :: Pou ( PouType :: Function | PouType :: Method { .. } , ..) , .. } = user_type. get_type_information ( ) {
106
- function_types. push ( ( * name, * user_type) ) ;
107
- } else {
108
- non_function_types. push ( ( * name, * user_type) ) ;
109
- }
110
- }
111
-
112
- // First create all POU types (excluding functions/methods) - this includes function blocks like ClassA, ClassB
113
- for ( name, user_type) in & pou_types {
114
- let gen_type = generator. create_type ( name, user_type) ?;
115
- generator. types_index . associate_pou_type ( name, gen_type) ?
116
- }
117
-
118
- // Then create function types now that all POU types are available
119
- for ( name, user_type) in & function_types {
120
102
let gen_type = generator. create_type ( name, user_type) ?;
121
103
generator. types_index . associate_type ( name, gen_type) ?
122
104
//Get and associate debug type
123
105
}
124
106
125
- // Finally create all non-function types (enum's, arrays, VTable structs, etc.)
126
- for ( name, user_type) in & non_function_types {
107
+ for ( name, user_type) in & pou_types {
127
108
let gen_type = generator. create_type ( name, user_type) ?;
128
- generator. types_index . associate_type ( name, gen_type) ?
129
- //Get and associate debug type
109
+ generator. types_index . associate_pou_type ( name, gen_type) ?
130
110
}
131
111
132
- // Combine all types in the order they were processed
112
+ // Combine the types and pou_types into a single Vector
133
113
let mut types_to_init = VecDeque :: new ( ) ;
114
+ types_to_init. extend ( types) ;
134
115
types_to_init. extend ( pou_types) ;
135
- types_to_init. extend ( function_types) ;
136
- types_to_init. extend ( non_function_types) ;
137
116
// now since all types should be available in the llvm index, we can think about constructing and associating
138
117
for ( _, user_type) in & types_to_init {
139
118
//Expand all types
@@ -197,7 +176,7 @@ pub fn generate_data_types<'ink>(
197
176
}
198
177
199
178
impl < ' ink > DataTypeGenerator < ' ink , ' _ > {
200
- fn create_function_type ( & mut self , name : & str ) -> Result < FunctionType < ' ink > , Diagnostic > {
179
+ fn create_function_type ( & self , name : & str ) -> Result < FunctionType < ' ink > , Diagnostic > {
201
180
let return_type_dt = self . index . find_return_type ( name) . unwrap_or ( self . index . get_void_type ( ) ) ;
202
181
203
182
let return_type = self
@@ -211,20 +190,8 @@ impl<'ink> DataTypeGenerator<'ink, '_> {
211
190
// For methods, we need to add the 'this' parameter as the first parameter
212
191
if let Some ( PouIndexEntry :: Method { parent_name, .. } ) = self . index . find_pou ( name) {
213
192
// Get the owner class type and add it as the first parameter (this pointer)
214
- // If the parent type is not available yet (e.g., during early type creation),
215
- // we'll create a properly named opaque struct as placeholder
216
- if let Ok ( owner_type) = self . types_index . get_associated_pou_type ( parent_name) {
193
+ if let Ok ( owner_type) = self . types_index . get_associated_type ( parent_name) {
217
194
parameter_types. push ( owner_type. ptr_type ( AddressSpace :: from ( ADDRESS_SPACE_GENERIC ) ) . into ( ) ) ;
218
- } else {
219
- // Create an opaque struct type with the exact same name that will be used
220
- // when the full type is created. This ensures LLVM will treat them as the same type.
221
- let opaque_struct = self . llvm . context . opaque_struct_type ( parent_name) ;
222
- let opaque_type: BasicTypeEnum = opaque_struct. into ( ) ;
223
-
224
- // Register it in the POU type index for this generation session
225
- let _ = self . types_index . associate_pou_type ( parent_name, opaque_type. as_any_type_enum ( ) ) ;
226
-
227
- parameter_types. push ( opaque_type. ptr_type ( AddressSpace :: from ( ADDRESS_SPACE_GENERIC ) ) . into ( ) ) ;
228
195
}
229
196
}
230
197
@@ -239,11 +206,10 @@ impl<'ink> DataTypeGenerator<'ink, '_> {
239
206
240
207
parameter_types. extend ( declared_params) ;
241
208
242
- let fn_type = match return_type {
209
+ let fn_type = match dbg ! ( return_type) {
243
210
AnyTypeEnum :: IntType ( value) => value. fn_type ( parameter_types. as_slice ( ) , false ) ,
244
211
AnyTypeEnum :: VoidType ( value) => value. fn_type ( parameter_types. as_slice ( ) , false ) ,
245
- AnyTypeEnum :: FloatType ( value) => value. fn_type ( parameter_types. as_slice ( ) , false ) ,
246
- _ => unimplemented ! ( "Unsupported function return type: {:?}" , return_type) ,
212
+ _ => unimplemented ! ( ) ,
247
213
} ;
248
214
249
215
Ok ( fn_type)
@@ -282,11 +248,9 @@ impl<'ink> DataTypeGenerator<'ink, '_> {
282
248
StructSource :: Pou ( PouType :: Function | PouType :: Method { .. } , ..) => {
283
249
let gen_type = self . create_function_type ( name) ?;
284
250
285
- // Associate the function type in the POU index
251
+ // TODO(vosa): Strictly speaking we don't need to register in LLVM index, i.e. `return Ok(gen_type.as_any_type_enum())` would suffice without breaking any tests; re-think approach with AnyType changes in API
286
252
self . types_index . associate_pou_type ( name, gen_type. as_any_type_enum ( ) ) ?;
287
-
288
- // Return the function type
289
- Ok ( gen_type. as_any_type_enum ( ) )
253
+ self . types_index . get_associated_function_type ( name) . map ( |it| it. as_any_type_enum ( ) )
290
254
}
291
255
StructSource :: Pou ( ..) => self
292
256
. types_index
0 commit comments