@@ -79,14 +79,18 @@ struct MethodInitGroup {
79
79
}
80
80
81
81
impl MethodInitGroup {
82
- fn new ( class_godot_name : & str , class_var : Ident , method_inits : Vec < MethodInit > ) -> Self {
82
+ fn new (
83
+ godot_class_name : & str ,
84
+ class_var : Option < Ident > ,
85
+ method_inits : Vec < MethodInit > ,
86
+ ) -> Self {
83
87
Self {
84
- class_name : ident ( class_godot_name ) ,
88
+ class_name : ident ( godot_class_name ) ,
85
89
// Only create class variable if any methods have been added.
86
- class_var_init : if method_inits. is_empty ( ) {
90
+ class_var_init : if class_var . is_none ( ) || method_inits. is_empty ( ) {
87
91
None
88
92
} else {
89
- let initializer_expr = util:: make_sname_ptr ( class_godot_name ) ;
93
+ let initializer_expr = util:: make_sname_ptr ( godot_class_name ) ;
90
94
Some ( quote ! {
91
95
let #class_var = #initializer_expr;
92
96
} )
@@ -111,7 +115,7 @@ struct AccessorMethod {
111
115
112
116
// ----------------------------------------------------------------------------------------------------------------------------------------------
113
117
114
- pub struct TypeNames {
118
+ pub struct BuiltinName {
115
119
/// Name in JSON: "int" or "PackedVector2Array"
116
120
pub json_builtin_name : String ,
117
121
@@ -125,15 +129,15 @@ pub struct TypeNames {
125
129
pub sys_variant_type : Ident ,
126
130
}
127
131
128
- impl Eq for TypeNames { }
132
+ impl Eq for BuiltinName { }
129
133
130
- impl PartialEq for TypeNames {
134
+ impl PartialEq for BuiltinName {
131
135
fn eq ( & self , other : & Self ) -> bool {
132
136
self . json_builtin_name == other. json_builtin_name
133
137
}
134
138
}
135
139
136
- impl std:: hash:: Hash for TypeNames {
140
+ impl std:: hash:: Hash for BuiltinName {
137
141
fn hash < H : Hasher > ( & self , state : & mut H ) {
138
142
self . json_builtin_name . hash ( state) ;
139
143
}
@@ -144,7 +148,7 @@ impl std::hash::Hash for TypeNames {
144
148
/// Allows collecting all builtin TypeNames before generating methods
145
149
pub ( crate ) struct BuiltinTypeInfo < ' a > {
146
150
pub value : i32 ,
147
- pub type_names : TypeNames ,
151
+ pub type_names : BuiltinName ,
148
152
149
153
/// If `variant_get_ptr_destructor` returns a non-null function pointer for this type.
150
154
/// List is directly sourced from extension_api.json (information would also be in variant_destruct.cpp).
@@ -1010,6 +1014,8 @@ fn populate_class_methods(
1010
1014
class_ty : & TyName ,
1011
1015
ctx : & mut Context ,
1012
1016
) {
1017
+ // Note: already checked outside whether class is active in codegen.
1018
+
1013
1019
let class_var = format_ident ! ( "sname_{}" , & class. name) ;
1014
1020
let mut method_inits = vec ! [ ] ;
1015
1021
@@ -1049,23 +1055,32 @@ fn populate_class_methods(
1049
1055
}
1050
1056
}
1051
1057
1052
- table. method_init_groups . push ( MethodInitGroup :: new (
1053
- & class_ty. godot_ty ,
1054
- class_var,
1055
- method_inits,
1056
- ) ) ;
1057
- table. class_count += 1 ;
1058
+ // No methods available, or all excluded (e.g. virtual ones) -> no group needed.
1059
+ if !method_inits. is_empty ( ) {
1060
+ table. method_init_groups . push ( MethodInitGroup :: new (
1061
+ & class_ty. godot_ty ,
1062
+ Some ( class_var) ,
1063
+ method_inits,
1064
+ ) ) ;
1065
+
1066
+ table. class_count += 1 ;
1067
+ }
1058
1068
}
1059
1069
1060
1070
fn populate_builtin_methods (
1061
1071
table : & mut IndexedMethodTable ,
1062
1072
builtin_class : & BuiltinClass ,
1063
- builtin_name : & TypeNames ,
1073
+ builtin_name : & BuiltinName ,
1064
1074
ctx : & mut Context ,
1065
1075
) {
1066
- let class_var = format_ident ! ( "sname_{}" , & builtin_class. name) ;
1067
1076
let mut method_inits = vec ! [ ] ;
1068
1077
1078
+ // Skip types such as int, float, bool.
1079
+ // TODO separate BuiltinName + TyName needed?
1080
+ if special_cases:: is_builtin_type_deleted ( & TyName :: from_godot ( & builtin_class. name ) ) {
1081
+ return ;
1082
+ }
1083
+
1069
1084
for method in option_as_slice ( & builtin_class. methods ) {
1070
1085
let builtin_ty = TyName :: from_godot ( & builtin_class. name ) ;
1071
1086
if special_cases:: is_builtin_deleted ( & builtin_ty, method) {
@@ -1105,7 +1120,7 @@ fn populate_builtin_methods(
1105
1120
1106
1121
table. method_init_groups . push ( MethodInitGroup :: new (
1107
1122
& builtin_class. name ,
1108
- class_var ,
1123
+ None , // load_builtin_method() doesn't need a StringName for the class, as it accepts the VariantType enum.
1109
1124
method_inits,
1110
1125
) ) ;
1111
1126
table. class_count += 1 ;
@@ -1141,7 +1156,7 @@ fn make_class_method_init(
1141
1156
1142
1157
fn make_builtin_method_init (
1143
1158
method : & BuiltinClassMethod ,
1144
- type_name : & TypeNames ,
1159
+ type_name : & BuiltinName ,
1145
1160
index : usize ,
1146
1161
) -> TokenStream {
1147
1162
let method_name_str = method. name . as_str ( ) ;
@@ -1229,7 +1244,7 @@ pub(crate) fn collect_builtin_types(api: &ExtensionApi) -> HashMap<String, Built
1229
1244
operators = None ;
1230
1245
}
1231
1246
1232
- let type_names = TypeNames {
1247
+ let type_names = BuiltinName {
1233
1248
json_builtin_name : class_name. clone ( ) ,
1234
1249
snake_case : to_snake_case ( & class_name) ,
1235
1250
//shout_case: shout_case.to_string(),
@@ -1263,7 +1278,7 @@ fn collect_variant_operators(api: &ExtensionApi) -> Vec<&EnumConstant> {
1263
1278
}
1264
1279
1265
1280
fn make_enumerator (
1266
- type_names : & TypeNames ,
1281
+ type_names : & BuiltinName ,
1267
1282
value : i32 ,
1268
1283
ctx : & mut Context ,
1269
1284
) -> ( Ident , TokenStream , Literal ) {
@@ -1287,7 +1302,7 @@ fn make_opaque_type(name: &str, size: usize) -> TokenStream {
1287
1302
}
1288
1303
1289
1304
fn make_variant_fns (
1290
- type_names : & TypeNames ,
1305
+ type_names : & BuiltinName ,
1291
1306
has_destructor : bool ,
1292
1307
constructors : Option < & Vec < Constructor > > ,
1293
1308
operators : Option < & Vec < Operator > > ,
@@ -1341,7 +1356,7 @@ fn make_variant_fns(
1341
1356
}
1342
1357
1343
1358
fn make_construct_fns (
1344
- type_names : & TypeNames ,
1359
+ type_names : & BuiltinName ,
1345
1360
constructors : Option < & Vec < Constructor > > ,
1346
1361
builtin_types : & HashMap < String , BuiltinTypeInfo > ,
1347
1362
) -> ( TokenStream , TokenStream ) {
@@ -1420,7 +1435,7 @@ fn make_construct_fns(
1420
1435
1421
1436
/// Lists special cases for useful constructors
1422
1437
fn make_extra_constructors (
1423
- type_names : & TypeNames ,
1438
+ type_names : & BuiltinName ,
1424
1439
constructors : & Vec < Constructor > ,
1425
1440
builtin_types : & HashMap < String , BuiltinTypeInfo > ,
1426
1441
) -> ( Vec < TokenStream > , Vec < TokenStream > ) {
@@ -1464,7 +1479,7 @@ fn make_extra_constructors(
1464
1479
( extra_decls, extra_inits)
1465
1480
}
1466
1481
1467
- fn make_destroy_fns ( type_names : & TypeNames , has_destructor : bool ) -> ( TokenStream , TokenStream ) {
1482
+ fn make_destroy_fns ( type_names : & BuiltinName , has_destructor : bool ) -> ( TokenStream , TokenStream ) {
1468
1483
if !has_destructor || is_trivial ( type_names) {
1469
1484
return ( TokenStream :: new ( ) , TokenStream :: new ( ) ) ;
1470
1485
}
@@ -1488,7 +1503,7 @@ fn make_destroy_fns(type_names: &TypeNames, has_destructor: bool) -> (TokenStrea
1488
1503
}
1489
1504
1490
1505
fn make_operator_fns (
1491
- type_names : & TypeNames ,
1506
+ type_names : & BuiltinName ,
1492
1507
operators : Option < & Vec < Operator > > ,
1493
1508
json_name : & str ,
1494
1509
sys_name : & str ,
@@ -1529,7 +1544,7 @@ fn make_operator_fns(
1529
1544
1530
1545
/// Returns true if the type is so trivial that most of its operations are directly provided by Rust, and there is no need
1531
1546
/// to expose the construct/destruct/operator methods from Godot
1532
- fn is_trivial ( type_names : & TypeNames ) -> bool {
1547
+ fn is_trivial ( type_names : & BuiltinName ) -> bool {
1533
1548
let list = [ "bool" , "int" , "float" ] ;
1534
1549
1535
1550
list. contains ( & type_names. json_builtin_name . as_str ( ) )
0 commit comments