@@ -584,6 +584,7 @@ fn make_method_definition(
584
584
__call_fn( __method_bind, #receiver_arg, __args_ptr, return_ptr) ;
585
585
} ;
586
586
587
+ let is_virtual = false ;
587
588
make_function_definition (
588
589
method_name_str,
589
590
special_cases:: is_private ( class_name, & method. name ) ,
@@ -594,6 +595,7 @@ fn make_method_definition(
594
595
init_code,
595
596
& varcall_invocation,
596
597
& ptrcall_invocation,
598
+ is_virtual,
597
599
ctx,
598
600
)
599
601
}
@@ -634,6 +636,7 @@ fn make_builtin_method_definition(
634
636
__call_fn( #receiver_arg, __args_ptr, return_ptr, __args. len( ) as i32 ) ;
635
637
} ;
636
638
639
+ let is_virtual = false ;
637
640
make_function_definition (
638
641
method_name_str,
639
642
special_cases:: is_private ( class_name, & method. name ) ,
@@ -644,6 +647,7 @@ fn make_builtin_method_definition(
644
647
init_code,
645
648
& ptrcall_invocation,
646
649
& ptrcall_invocation,
650
+ is_virtual,
647
651
ctx,
648
652
)
649
653
}
@@ -669,8 +673,9 @@ pub(crate) fn make_utility_function_definition(
669
673
__call_fn( return_ptr, __args_ptr, __args. len( ) as i32 ) ;
670
674
} ;
671
675
676
+ let is_virtual = false ;
672
677
make_function_definition (
673
- & function . name ,
678
+ function_name_str ,
674
679
false ,
675
680
TokenStream :: new ( ) ,
676
681
& function. arguments ,
@@ -679,6 +684,7 @@ pub(crate) fn make_utility_function_definition(
679
684
init_code,
680
685
& invocation,
681
686
& invocation,
687
+ is_virtual,
682
688
ctx,
683
689
)
684
690
}
@@ -714,6 +720,7 @@ fn make_function_definition(
714
720
init_code : TokenStream ,
715
721
varcall_invocation : & TokenStream ,
716
722
ptrcall_invocation : & TokenStream ,
723
+ is_virtual : bool ,
717
724
ctx : & mut Context ,
718
725
) -> TokenStream {
719
726
let vis = if is_private {
@@ -761,10 +768,17 @@ fn make_function_definition(
761
768
ptrcall_invocation,
762
769
prepare_arg_types,
763
770
error_fn_context,
771
+ is_virtual,
764
772
ctx,
765
773
) ;
766
774
767
- if let Some ( variant_ffi) = variant_ffi. as_ref ( ) {
775
+ if is_virtual {
776
+ quote ! {
777
+ fn #fn_name( #receiver #( #params, ) * ) #return_decl {
778
+ #call_code
779
+ }
780
+ }
781
+ } else if let Some ( variant_ffi) = variant_ffi. as_ref ( ) {
768
782
// varcall (using varargs)
769
783
let sys_method = & variant_ffi. sys_method ;
770
784
quote ! {
@@ -864,13 +878,15 @@ fn make_params(
864
878
[ params, variant_types, arg_exprs, arg_names]
865
879
}
866
880
881
+ #[ allow( clippy:: too_many_arguments) ]
867
882
fn make_return (
868
883
return_value : Option < & MethodReturn > ,
869
884
variant_ffi : Option < & VariantFfi > ,
870
885
varcall_invocation : & TokenStream ,
871
886
ptrcall_invocation : & TokenStream ,
872
887
prepare_arg_types : TokenStream ,
873
888
error_fn_context : TokenStream , // only for panic message
889
+ is_virtual : bool ,
874
890
ctx : & mut Context ,
875
891
) -> ( TokenStream , TokenStream ) {
876
892
let return_decl: TokenStream ;
@@ -885,8 +901,13 @@ fn make_return(
885
901
return_ty = None ;
886
902
}
887
903
888
- let call = match ( variant_ffi, return_ty) {
889
- ( Some ( variant_ffi) , Some ( return_ty) ) => {
904
+ let call = match ( is_virtual, variant_ffi, return_ty) {
905
+ ( true , _, _) => {
906
+ quote ! {
907
+ unimplemented!( )
908
+ }
909
+ }
910
+ ( false , Some ( variant_ffi) , Some ( return_ty) ) => {
890
911
// If the return type is not Variant, then convert to concrete target type
891
912
let return_expr = match return_ty {
892
913
RustTy :: BuiltinIdent ( ident) if ident == "Variant" => quote ! { variant } ,
@@ -908,7 +929,7 @@ fn make_return(
908
929
#return_expr
909
930
}
910
931
}
911
- ( Some ( _) , None ) => {
932
+ ( false , Some ( _) , None ) => {
912
933
// Note: __err may remain unused if the #call does not handle errors (e.g. utility fn, ptrcall, ...)
913
934
// TODO use Result instead of panic on error
914
935
quote ! {
@@ -921,22 +942,22 @@ fn make_return(
921
942
}
922
943
}
923
944
}
924
- ( None , Some ( RustTy :: EngineClass { tokens, .. } ) ) => {
945
+ ( false , None , Some ( RustTy :: EngineClass { tokens, .. } ) ) => {
925
946
let return_ty = tokens;
926
947
quote ! {
927
948
<#return_ty>:: from_sys_init_opt( |return_ptr| {
928
949
#ptrcall_invocation
929
950
} )
930
951
}
931
952
}
932
- ( None , Some ( return_ty) ) => {
953
+ ( false , None , Some ( return_ty) ) => {
933
954
quote ! {
934
955
<#return_ty as sys:: GodotFfi >:: from_sys_init_default( |return_ptr| {
935
956
#ptrcall_invocation
936
957
} )
937
958
}
938
959
}
939
- ( None , None ) => {
960
+ ( false , None , None ) => {
940
961
quote ! {
941
962
let return_ptr = std:: ptr:: null_mut( ) ;
942
963
#ptrcall_invocation
@@ -983,19 +1004,35 @@ fn special_virtual_methods() -> TokenStream {
983
1004
}
984
1005
985
1006
fn make_virtual_method ( class_method : & ClassMethod , ctx : & mut Context ) -> TokenStream {
986
- let method_name = ident ( virtual_method_name ( class_method) ) ;
1007
+ let method_name = virtual_method_name ( class_method) ;
987
1008
988
1009
// Virtual methods are never static.
989
1010
assert ! ( !class_method. is_static) ;
990
1011
991
1012
let receiver = make_receiver_self_param ( false , class_method. is_const ) ;
992
- let [ params, _, _, _] = make_params ( & class_method. arguments , class_method. is_vararg , ctx) ;
993
1013
994
- quote ! {
995
- fn #method_name ( #receiver #( #params , ) * ) {
996
- unimplemented!( )
997
- }
998
- }
1014
+ // make_return requests these token streams, but they won't be used for
1015
+ // virtual methods. We can provide empty streams.
1016
+ let varcall_invocation = TokenStream :: new ( ) ;
1017
+ let ptrcall_invocation = TokenStream :: new ( ) ;
1018
+ let init_code = TokenStream :: new ( ) ;
1019
+ let variant_ffi = None ;
1020
+
1021
+ let is_virtual = true ;
1022
+ let is_private = false ;
1023
+ make_function_definition (
1024
+ method_name,
1025
+ is_private,
1026
+ receiver,
1027
+ & class_method. arguments ,
1028
+ class_method. return_value . as_ref ( ) ,
1029
+ variant_ffi,
1030
+ init_code,
1031
+ & varcall_invocation,
1032
+ & ptrcall_invocation,
1033
+ is_virtual,
1034
+ ctx,
1035
+ )
999
1036
}
1000
1037
1001
1038
fn make_all_virtual_methods (
0 commit comments