@@ -11,12 +11,12 @@ use quote::{format_ident, quote, ToTokens};
11
11
use std:: path:: Path ;
12
12
13
13
use crate :: api_parser:: * ;
14
- use crate :: central_generator:: { collect_builtin_types, BuiltinTypeInfo } ;
14
+ use crate :: central_generator:: collect_builtin_types;
15
15
use crate :: context:: NotificationEnum ;
16
16
use crate :: util:: {
17
17
ident, make_string_name, option_as_slice, parse_native_structures_format, safe_ident,
18
- to_pascal_case, to_rust_expr, to_rust_type, to_rust_type_abi, to_snake_case,
19
- NativeStructuresField ,
18
+ to_pascal_case, to_rust_expr, to_rust_type, to_rust_type_abi, to_snake_case, ClassCodegenLevel ,
19
+ MethodTableKey , NativeStructuresField ,
20
20
} ;
21
21
use crate :: {
22
22
codegen_special_cases, special_cases, util, Context , GeneratedBuiltin , GeneratedBuiltinModule ,
@@ -280,27 +280,26 @@ pub(crate) fn generate_builtin_class_files(
280
280
let mut modules = vec ! [ ] ;
281
281
for class in api. builtin_classes . iter ( ) {
282
282
let module_name = ModName :: from_godot ( & class. name ) ;
283
- let class_name = TyName :: from_godot ( & class. name ) ;
284
- let inner_class_name = TyName :: from_godot ( & format ! ( "Inner{}" , class. name) ) ;
283
+ let builtin_name = TyName :: from_godot ( & class. name ) ;
284
+ let inner_builtin_name = TyName :: from_godot ( & format ! ( "Inner{}" , class. name) ) ;
285
285
286
- if special_cases:: is_builtin_type_deleted ( & class_name ) {
286
+ if special_cases:: is_builtin_type_deleted ( & builtin_name ) {
287
287
continue ;
288
288
}
289
289
290
- let type_info = builtin_types_map
290
+ let _type_info = builtin_types_map
291
291
. get ( & class. name )
292
292
. unwrap_or_else ( || panic ! ( "builtin type not found: {}" , class. name) ) ;
293
293
294
- let generated_class =
295
- make_builtin_class ( class, & class_name, & inner_class_name, type_info, ctx) ;
294
+ let generated_class = make_builtin_class ( class, & builtin_name, & inner_builtin_name, ctx) ;
296
295
let file_contents = generated_class. code ;
297
296
298
297
let out_path = gen_path. join ( format ! ( "{}.rs" , module_name. rust_mod) ) ;
299
298
300
299
submit_fn ( out_path, file_contents) ;
301
300
302
301
modules. push ( GeneratedBuiltinModule {
303
- class_name : inner_class_name ,
302
+ class_name : inner_builtin_name ,
304
303
module_name,
305
304
} ) ;
306
305
}
@@ -494,17 +493,12 @@ fn make_class(class: &Class, class_name: &TyName, ctx: &mut Context) -> Generate
494
493
} ;
495
494
496
495
let constructor = make_constructor ( class, ctx) ;
497
- let get_method_table = util:: get_api_level ( class) . table_global_getter ( ) ;
496
+ let api_level = util:: get_api_level ( class) ;
498
497
499
498
let FnDefinitions {
500
499
functions : methods,
501
500
builders,
502
- } = make_methods (
503
- option_as_slice ( & class. methods ) ,
504
- class_name,
505
- & get_method_table,
506
- ctx,
507
- ) ;
501
+ } = make_methods ( option_as_slice ( & class. methods ) , class_name, & api_level, ctx) ;
508
502
509
503
let enums = make_enums ( option_as_slice ( & class. enums ) , class_name, ctx) ;
510
504
let constants = make_constants ( option_as_slice ( & class. constants ) , class_name, ctx) ;
@@ -806,9 +800,8 @@ fn workaround_constant_collision(all_constants: &mut Vec<(Ident, i32)>) {
806
800
807
801
fn make_builtin_class (
808
802
class : & BuiltinClass ,
809
- class_name : & TyName ,
803
+ builtin_name : & TyName ,
810
804
inner_class_name : & TyName ,
811
- type_info : & BuiltinTypeInfo ,
812
805
ctx : & mut Context ,
813
806
) -> GeneratedBuiltin {
814
807
let outer_class = if let RustTy :: BuiltinIdent ( ident) = to_rust_type ( & class. name , None , ctx) {
@@ -830,14 +823,13 @@ fn make_builtin_class(
830
823
builders,
831
824
} = make_builtin_methods (
832
825
option_as_slice ( & class. methods ) ,
833
- class_name ,
826
+ builtin_name ,
834
827
inner_class_name,
835
- type_info,
836
828
ctx,
837
829
) ;
838
830
839
- let enums = make_enums ( & class_enums, class_name , ctx) ;
840
- let special_constructors = make_special_builtin_methods ( class_name , ctx) ;
831
+ let enums = make_enums ( & class_enums, builtin_name , ctx) ;
832
+ let special_constructors = make_special_builtin_methods ( builtin_name , ctx) ;
841
833
842
834
// mod re_export needed, because class should not appear inside the file module, and we can't re-export private struct as pub
843
835
let code = quote ! {
@@ -1017,26 +1009,27 @@ fn make_builtin_module_file(classes_and_modules: Vec<GeneratedBuiltinModule>) ->
1017
1009
fn make_methods (
1018
1010
methods : & [ ClassMethod ] ,
1019
1011
class_name : & TyName ,
1020
- get_method_table : & Ident ,
1012
+ api_level : & ClassCodegenLevel ,
1021
1013
ctx : & mut Context ,
1022
1014
) -> FnDefinitions {
1023
- let definitions = methods
1024
- . iter ( )
1025
- . map ( |method| make_method_definition ( method, class_name, get_method_table, ctx) ) ;
1015
+ let get_method_table = api_level. table_global_getter ( ) ;
1016
+
1017
+ let definitions = methods. iter ( ) . map ( |method| {
1018
+ make_method_definition ( method, class_name, api_level, & get_method_table, ctx)
1019
+ } ) ;
1026
1020
1027
1021
FnDefinitions :: expand ( definitions)
1028
1022
}
1029
1023
1030
1024
fn make_builtin_methods (
1031
1025
methods : & [ BuiltinClassMethod ] ,
1032
- class_name : & TyName ,
1026
+ builtin_name : & TyName ,
1033
1027
inner_class_name : & TyName ,
1034
- type_info : & BuiltinTypeInfo ,
1035
1028
ctx : & mut Context ,
1036
1029
) -> FnDefinitions {
1037
- let definitions = methods. iter ( ) . map ( |method| {
1038
- make_builtin_method_definition ( method , class_name , inner_class_name , type_info , ctx )
1039
- } ) ;
1030
+ let definitions = methods
1031
+ . iter ( )
1032
+ . map ( |method| make_builtin_method_definition ( method , builtin_name , inner_class_name , ctx ) ) ;
1040
1033
1041
1034
FnDefinitions :: expand ( definitions)
1042
1035
}
@@ -1082,12 +1075,11 @@ fn make_special_builtin_methods(class_name: &TyName, _ctx: &Context) -> TokenStr
1082
1075
fn make_method_definition (
1083
1076
method : & ClassMethod ,
1084
1077
class_name : & TyName ,
1078
+ api_level : & ClassCodegenLevel ,
1085
1079
get_method_table : & Ident ,
1086
1080
ctx : & mut Context ,
1087
1081
) -> FnDefinition {
1088
- if codegen_special_cases:: is_method_excluded ( method, false , ctx)
1089
- || special_cases:: is_deleted ( class_name, & method. name )
1090
- {
1082
+ if special_cases:: is_deleted ( class_name, method, ctx) {
1091
1083
return FnDefinition :: none ( ) ;
1092
1084
}
1093
1085
/*if method.map_args(|args| args.is_empty()) {
@@ -1119,10 +1111,14 @@ fn make_method_definition(
1119
1111
quote ! { sys:: interface_fn!( object_method_bind_ptrcall) }
1120
1112
} ;
1121
1113
1122
- let fn_ptr = util:: make_class_method_ptr_name ( & class_name. godot_ty , method) ;
1114
+ let table_index = ctx. get_table_index ( & MethodTableKey :: ClassMethod {
1115
+ api_level : * api_level,
1116
+ class_ty : class_name. clone ( ) ,
1117
+ method_name : method. name . clone ( ) ,
1118
+ } ) ;
1123
1119
1124
1120
let init_code = quote ! {
1125
- let __method_bind = sys:: #get_method_table( ) . #fn_ptr ;
1121
+ let __method_bind = sys:: #get_method_table( ) . fptr_by_index ( #table_index ) ;
1126
1122
let __call_fn = #function_provider;
1127
1123
} ;
1128
1124
@@ -1156,12 +1152,11 @@ fn make_method_definition(
1156
1152
1157
1153
fn make_builtin_method_definition (
1158
1154
method : & BuiltinClassMethod ,
1159
- class_name : & TyName ,
1155
+ builtin_name : & TyName ,
1160
1156
inner_class_name : & TyName ,
1161
- type_info : & BuiltinTypeInfo ,
1162
1157
ctx : & mut Context ,
1163
1158
) -> FnDefinition {
1164
- if codegen_special_cases :: is_builtin_method_excluded ( method) {
1159
+ if special_cases :: is_builtin_deleted ( builtin_name , method) {
1165
1160
return FnDefinition :: none ( ) ;
1166
1161
}
1167
1162
@@ -1175,10 +1170,13 @@ fn make_builtin_method_definition(
1175
1170
let is_varcall = method. is_vararg ;
1176
1171
let variant_ffi = is_varcall. then ( VariantFfi :: type_ptr) ;
1177
1172
1178
- let fn_ptr = util:: make_builtin_method_ptr_name ( & type_info. type_names , method) ;
1173
+ let table_index = ctx. get_table_index ( & MethodTableKey :: BuiltinMethod {
1174
+ builtin_ty : builtin_name. clone ( ) ,
1175
+ method_name : method. name . clone ( ) ,
1176
+ } ) ;
1179
1177
1180
1178
let init_code = quote ! {
1181
- let __call_fn = sys:: builtin_method_table( ) . #fn_ptr ;
1179
+ let __call_fn = sys:: builtin_method_table( ) . fptr_by_index ( #table_index ) ;
1182
1180
} ;
1183
1181
1184
1182
let receiver = make_receiver ( method. is_static , method. is_const , quote ! { self . sys_ptr } ) ;
@@ -1191,7 +1189,7 @@ fn make_builtin_method_definition(
1191
1189
& FnSignature {
1192
1190
function_name : method_name_str,
1193
1191
surrounding_class : Some ( inner_class_name) ,
1194
- is_private : special_cases:: is_private ( class_name , & method. name ) ,
1192
+ is_private : special_cases:: is_private ( builtin_name , & method. name ) ,
1195
1193
is_virtual : false ,
1196
1194
qualifier : FnQualifier :: for_method ( method. is_const , method. is_static ) ,
1197
1195
0 commit comments