8
8
use std:: collections:: HashMap ;
9
9
use std:: vec:: Vec ;
10
10
11
- use analysis:: bounds:: Bounds ;
11
+ use analysis:: bounds:: { Bounds , CallbackInfo } ;
12
12
use analysis:: function_parameters:: { self , Parameters , Transformation , TransformationType } ;
13
- use analysis:: out_parameters:: use_function_return_for_result;
14
13
use analysis:: imports:: Imports ;
15
14
use analysis:: out_parameters;
15
+ use analysis:: out_parameters:: use_function_return_for_result;
16
16
use analysis:: ref_mode:: RefMode ;
17
17
use analysis:: return_value;
18
18
use analysis:: rust_type:: * ;
@@ -22,9 +22,9 @@ use config;
22
22
use env:: Env ;
23
23
use library:: { self , Function , FunctionKind , Nullable , Parameter , ParameterScope , Type } ;
24
24
use nameutil;
25
+ use std:: borrow:: Borrow ;
25
26
use traits:: * ;
26
27
use version:: Version ;
27
- use std:: borrow:: Borrow ;
28
28
29
29
#[ derive( Clone , Copy , Debug , PartialEq , Eq ) ]
30
30
pub enum Visibility {
@@ -197,48 +197,18 @@ fn analyze_function(
197
197
if let Ok ( s) = used_rust_type ( env, par. typ ) {
198
198
used_types. push ( s) ;
199
199
}
200
- let ( to_glib_extra, type_string ) = bounds. add_for_parameter ( env, func, par, async ) ;
200
+ let ( to_glib_extra, callback_info ) = bounds. add_for_parameter ( env, func, par, async ) ;
201
201
if let Some ( to_glib_extra) = to_glib_extra {
202
202
to_glib_extras. insert ( pos, to_glib_extra) ;
203
203
}
204
- if let Some ( ( callback_type, success_parameters, error_parameters, bound_name) ) = type_string {
205
- // Checks for /*Ignored*/ or other error comments
206
- if callback_type. find ( "/*" ) . is_some ( ) {
207
- commented = true ;
208
- }
209
- let func_name = func. c_identifier . as_ref ( ) . unwrap ( ) ;
210
- let finish_func_name = finish_function_name ( func_name) ;
211
- let mut output_params = vec ! [ ] ;
212
- let mut ffi_ret = None ;
213
- if let Some ( function) = find_function ( env, & finish_func_name) {
214
- if use_function_return_for_result ( env, function. ret . typ ) {
215
- ffi_ret = Some ( function. ret . clone ( ) ) ;
216
- }
217
-
218
- output_params. extend ( function. parameters . clone ( ) ) ;
219
- for param in & mut output_params {
220
- if nameutil:: needs_mangling ( & param. name ) {
221
- param. name = nameutil:: mangle_keywords ( & * param. name ) . into_owned ( ) ;
222
- }
223
- }
224
- }
225
- trampoline = Some ( AsyncTrampoline {
226
- is_method : func. kind == FunctionKind :: Method ,
227
- name : format ! ( "{}_trampoline" , func. name) ,
228
- finish_func_name,
229
- callback_type,
230
- bound_name,
231
- output_params,
232
- ffi_ret,
233
- } ) ;
234
-
235
- async_future = Some ( AsyncFuture {
236
- is_method : func. kind == FunctionKind :: Method ,
237
- name : format ! ( "{}_future" , func. name) ,
238
- success_parameters,
239
- error_parameters,
240
- } ) ;
241
- }
204
+ analyze_async (
205
+ env,
206
+ func,
207
+ callback_info,
208
+ & mut commented,
209
+ & mut trampoline,
210
+ & mut async_future,
211
+ ) ;
242
212
let type_error =
243
213
!( async & & * env. library . type_ ( par. typ ) == Type :: Fundamental ( library:: Fundamental :: Pointer ) ) &&
244
214
parameter_rust_type ( env, par. typ , par. direction , Nullable ( false ) , RefMode :: None )
@@ -376,6 +346,60 @@ pub fn is_carray_with_direct_elements(env: &Env, typ: library::TypeId) -> bool {
376
346
}
377
347
}
378
348
349
+ fn analyze_async (
350
+ env : & Env ,
351
+ func : & library:: Function ,
352
+ callback_info : Option < CallbackInfo > ,
353
+ commented : & mut bool ,
354
+ trampoline : & mut Option < AsyncTrampoline > ,
355
+ async_future : & mut Option < AsyncFuture > ,
356
+ ) {
357
+ if let Some ( CallbackInfo {
358
+ callback_type,
359
+ success_parameters,
360
+ error_parameters,
361
+ bound_name,
362
+ } ) = callback_info
363
+ {
364
+ // Checks for /*Ignored*/ or other error comments
365
+ if callback_type. find ( "/*" ) . is_some ( ) {
366
+ * commented = true ;
367
+ }
368
+ let func_name = func. c_identifier . as_ref ( ) . unwrap ( ) ;
369
+ let finish_func_name = finish_function_name ( func_name) ;
370
+ let mut output_params = vec ! [ ] ;
371
+ let mut ffi_ret = None ;
372
+ if let Some ( function) = find_function ( env, & finish_func_name) {
373
+ if use_function_return_for_result ( env, function. ret . typ ) {
374
+ ffi_ret = Some ( function. ret . clone ( ) ) ;
375
+ }
376
+
377
+ output_params. extend ( function. parameters . clone ( ) ) ;
378
+ for param in & mut output_params {
379
+ if nameutil:: needs_mangling ( & param. name ) {
380
+ param. name = nameutil:: mangle_keywords ( & * param. name ) . into_owned ( ) ;
381
+ }
382
+ }
383
+ }
384
+ * trampoline = Some ( AsyncTrampoline {
385
+ is_method : func. kind == FunctionKind :: Method ,
386
+ name : format ! ( "{}_trampoline" , func. name) ,
387
+ finish_func_name,
388
+ callback_type,
389
+ bound_name,
390
+ output_params,
391
+ ffi_ret,
392
+ } ) ;
393
+
394
+ * async_future = Some ( AsyncFuture {
395
+ is_method : func. kind == FunctionKind :: Method ,
396
+ name : format ! ( "{}_future" , func. name) ,
397
+ success_parameters,
398
+ error_parameters,
399
+ } ) ;
400
+ }
401
+ }
402
+
379
403
pub fn find_function < ' a > ( env : & ' a Env , c_identifier : & str ) -> Option < & ' a Function > {
380
404
let find = |functions : & ' a [ Function ] | -> Option < & ' a Function > {
381
405
for function in functions {
0 commit comments