7
7
8
8
use crate :: generator:: default_parameters;
9
9
use crate :: models:: domain:: { FnParam , FnQualifier , Function , RustTy } ;
10
+ use crate :: special_cases;
10
11
use crate :: util:: safe_ident;
11
12
use proc_macro2:: TokenStream ;
12
13
use quote:: { format_ident, quote} ;
@@ -119,12 +120,15 @@ pub fn make_function_definition(
119
120
( TokenStream :: new ( ) , TokenStream :: new ( ) )
120
121
} ;
121
122
122
- let [ params, param_types, arg_names] = make_params_exprs (
123
- sig. params ( ) . iter ( ) ,
124
- sig. is_virtual ( ) ,
125
- !has_default_params, // For *_full function, we don't need impl AsObjectArg<T> parameters
126
- !has_default_params, // or arg.as_object_arg() calls.
127
- ) ;
123
+ let [ params, param_types, arg_names] = if sig. is_virtual ( ) {
124
+ make_params_exprs_virtual ( sig. params ( ) . iter ( ) , sig)
125
+ } else {
126
+ make_params_exprs (
127
+ sig. params ( ) . iter ( ) ,
128
+ !has_default_params, // For *_full function, we don't need impl AsObjectArg<T> parameters
129
+ !has_default_params, // or arg.as_object_arg() calls.
130
+ )
131
+ } ;
128
132
129
133
let rust_function_name_str = sig. name ( ) ;
130
134
@@ -202,7 +206,6 @@ pub fn make_function_definition(
202
206
// A function() may call try_function(), its arguments should not have .as_object_arg().
203
207
let [ _, _, arg_names_without_asarg] = make_params_exprs (
204
208
sig. params ( ) . iter ( ) ,
205
- false ,
206
209
!has_default_params, // For *_full function, we don't need impl AsObjectArg<T> parameters
207
210
false , // or arg.as_object_arg() calls.
208
211
) ;
@@ -307,10 +310,9 @@ pub fn make_vis(is_private: bool) -> TokenStream {
307
310
// ----------------------------------------------------------------------------------------------------------------------------------------------
308
311
// Implementation
309
312
310
- // Method could possibly be split -- only one invocation uses all 3 return values, the rest uses only index [0] or [2] .
313
+ /// For non-virtual functions, returns the parameter declarations, type tokens, and names .
311
314
pub ( crate ) fn make_params_exprs < ' a > (
312
315
method_args : impl Iterator < Item = & ' a FnParam > ,
313
- is_virtual : bool ,
314
316
param_is_impl_asarg : bool ,
315
317
arg_is_asarg : bool ,
316
318
) -> [ Vec < TokenStream > ; 3 ] {
@@ -328,7 +330,7 @@ pub(crate) fn make_params_exprs<'a>(
328
330
object_arg,
329
331
impl_as_object_arg,
330
332
..
331
- } if !is_virtual => {
333
+ } => {
332
334
// Parameter declarations in signature: impl AsObjectArg<T>
333
335
if param_is_impl_asarg {
334
336
params. push ( quote ! { #param_name: #impl_as_object_arg } ) ;
@@ -346,8 +348,40 @@ pub(crate) fn make_params_exprs<'a>(
346
348
param_types. push ( quote ! { #object_arg } ) ;
347
349
}
348
350
351
+ // All other methods and parameter types: standard handling.
352
+ _ => {
353
+ params. push ( quote ! { #param_name: #param_ty } ) ;
354
+ arg_names. push ( quote ! { #param_name } ) ;
355
+ param_types. push ( quote ! { #param_ty } ) ;
356
+ }
357
+ }
358
+ }
359
+
360
+ [ params, param_types, arg_names]
361
+ }
362
+
363
+ /// For virtual functions, returns the parameter declarations, type tokens, and names.
364
+ pub ( crate ) fn make_params_exprs_virtual < ' a > (
365
+ method_args : impl Iterator < Item = & ' a FnParam > ,
366
+ function_sig : & dyn Function ,
367
+ ) -> [ Vec < TokenStream > ; 3 ] {
368
+ let mut params = vec ! [ ] ;
369
+ let mut param_types = vec ! [ ] ; // or non-generic params
370
+ let mut arg_names = vec ! [ ] ;
371
+
372
+ for param in method_args {
373
+ let param_name = & param. name ;
374
+ let param_ty = & param. type_ ;
375
+
376
+ match & param. type_ {
349
377
// Virtual methods accept Option<Gd<T>>, since we don't know whether objects are nullable or required.
350
- RustTy :: EngineClass { .. } if is_virtual => {
378
+ RustTy :: EngineClass { .. }
379
+ if !special_cases:: is_class_method_param_required (
380
+ function_sig. surrounding_class ( ) . unwrap ( ) ,
381
+ function_sig. name ( ) ,
382
+ param_name,
383
+ ) =>
384
+ {
351
385
params. push ( quote ! { #param_name: Option <#param_ty> } ) ;
352
386
arg_names. push ( quote ! { #param_name } ) ;
353
387
param_types. push ( quote ! { #param_ty } ) ;
0 commit comments