@@ -10,11 +10,14 @@ use std::collections::HashMap;
1010/// Types of icalls.
1111#[ derive( Copy , Clone , PartialEq , Eq , Hash , Debug ) ]
1212pub ( crate ) enum IcallType {
13+ #[ cfg( feature = "ptrcall" ) ]
1314 Ptr ,
1415 Varargs ,
1516 Var ,
1617}
1718
19+ // The `return_type` field is currently only used when ptrcall is enabled
20+ #[ cfg_attr( not( feature = "ptrcall" ) , allow( dead_code) ) ]
1821pub ( crate ) struct MethodSig {
1922 pub ( crate ) return_type : Ty ,
2023 pub ( crate ) arguments : Vec < Ty > ,
@@ -107,6 +110,7 @@ impl MethodSig {
107110 // Only ptrcalls have "static" typing on their return types.
108111 // The other calling types always return `Variant`.
109112 let mut name = match icall_ty {
113+ #[ cfg( feature = "ptrcall" ) ]
110114 IcallType :: Ptr => format ! ( "icallptr_{}" , ty_arg_name( & self . return_type) ) ,
111115 IcallType :: Varargs => String :: from ( "icallvarargs_" ) ,
112116 IcallType :: Var => String :: from ( "icallvar_" ) ,
@@ -121,6 +125,7 @@ impl MethodSig {
121125 }
122126
123127 #[ allow( clippy:: single_match) ]
128+ #[ cfg( feature = "ptrcall" ) ]
124129 pub ( crate ) fn icall_type ( & self ) -> IcallType {
125130 if self . has_varargs {
126131 return IcallType :: Varargs ;
@@ -133,6 +138,15 @@ impl MethodSig {
133138
134139 IcallType :: Ptr
135140 }
141+
142+ #[ cfg( not( feature = "ptrcall" ) ) ]
143+ pub ( crate ) fn icall_type ( & self ) -> IcallType {
144+ if self . has_varargs {
145+ return IcallType :: Varargs ;
146+ }
147+
148+ IcallType :: Var
149+ }
136150}
137151
138152fn skip_method ( method : & GodotMethod , name : & str ) -> bool {
@@ -544,29 +558,26 @@ fn unsafe_reason(
544558
545559fn ret_recover ( ty : & Ty , icall_ty : IcallType ) -> TokenStream {
546560 match icall_ty {
561+ #[ cfg( feature = "ptrcall" ) ]
547562 IcallType :: Ptr => ty. to_return_post ( ) ,
548563 IcallType :: Varargs => {
549564 // only variant possible
550565 quote ! { ret }
551566 }
552- IcallType :: Var => {
553- let rust_type = ty. to_rust ( ) ;
554- // always a variant returned, use FromVariant
555- quote ! {
556- <#rust_type>:: from_variant( & ret) . expect( "Unexpected variant type" )
557- }
558- }
567+ IcallType :: Var => ty. to_return_post_variant ( ) ,
559568 }
560569}
561570
562571pub ( crate ) fn generate_icall ( name : String , sig : MethodSig ) -> TokenStream {
563572 match sig. icall_type ( ) {
573+ #[ cfg( feature = "ptrcall" ) ]
564574 IcallType :: Ptr => ptrcall:: generate_icall ( name, sig) ,
565575 IcallType :: Varargs => varargs_call:: generate_icall ( name, sig) ,
566576 IcallType :: Var => varcall:: generate_icall ( name, sig) ,
567577 }
568578}
569579
580+ #[ cfg( feature = "ptrcall" ) ]
570581mod ptrcall {
571582 use super :: * ;
572583 use quote:: { format_ident, quote} ;
0 commit comments