@@ -10,7 +10,7 @@ use std::collections::HashMap;
10
10
use std:: path:: { Path , PathBuf } ;
11
11
12
12
use crate :: api_parser:: * ;
13
- use crate :: util:: to_rust_type;
13
+ use crate :: util:: { to_pascal_case , to_rust_type, to_snake_case } ;
14
14
use crate :: { ident, util, Context } ;
15
15
16
16
struct CentralItems {
@@ -26,8 +26,8 @@ struct CentralItems {
26
26
}
27
27
28
28
pub ( crate ) struct TypeNames {
29
- /// "int" or "PackedVector2Array"
30
- pub pascal_case : String ,
29
+ /// Name in JSON: "int" or "PackedVector2Array"
30
+ pub json_builtin_name : String ,
31
31
32
32
/// "packed_vector2_array"
33
33
pub snake_case : String ,
@@ -379,6 +379,8 @@ fn make_central_items(api: &ExtensionApi, build_config: &str, ctx: &mut Context)
379
379
result
380
380
}
381
381
382
+ /// Creates a map from "normalized" class names (lowercase without underscore, makes it easy to map from different conventions)
383
+ /// to meta type information, including all the type name variants
382
384
fn collect_builtin_classes ( api : & ExtensionApi ) -> HashMap < String , & BuiltinClass > {
383
385
let mut class_map = HashMap :: new ( ) ;
384
386
for class in & api. builtin_classes {
@@ -417,34 +419,34 @@ pub(crate) fn collect_builtin_types(api: &ExtensionApi) -> HashMap<String, Built
417
419
418
420
// TODO cut down on the number of cached functions generated
419
421
// e.g. there's no point in providing operator< for int
420
- let pascal_case : String ;
422
+ let class_name : String ;
421
423
let has_destructor: bool ;
422
424
let constructors: Option < & Vec < Constructor > > ;
423
425
let operators: Option < & Vec < Operator > > ;
424
426
if let Some ( class) = class_map. get ( & normalized) {
425
- pascal_case = class. name . clone ( ) ;
427
+ class_name = class. name . clone ( ) ;
426
428
has_destructor = class. has_destructor ;
427
429
constructors = Some ( & class. constructors ) ;
428
430
operators = Some ( & class. operators ) ;
429
431
} else {
430
432
assert_eq ! ( normalized, "object" ) ;
431
- pascal_case = "Object" . to_string ( ) ;
433
+ class_name = "Object" . to_string ( ) ;
432
434
has_destructor = false ;
433
435
constructors = None ;
434
436
operators = None ;
435
437
}
436
438
437
439
let type_names = TypeNames {
438
- pascal_case ,
439
- snake_case : shout_case . to_ascii_lowercase ( ) ,
440
+ json_builtin_name : class_name . clone ( ) ,
441
+ snake_case : to_snake_case ( & class_name ) ,
440
442
//shout_case: shout_case.to_string(),
441
443
sys_variant_type : format_ident ! ( "GDEXTENSION_VARIANT_TYPE_{}" , shout_case) ,
442
444
} ;
443
445
444
446
let value = ty. value ;
445
447
446
448
builtin_types_map. insert (
447
- type_names. pascal_case . clone ( ) ,
449
+ type_names. json_builtin_name . clone ( ) ,
448
450
BuiltinTypeInfo {
449
451
value,
450
452
type_names,
@@ -473,23 +475,23 @@ fn make_enumerator(
473
475
ctx : & mut Context ,
474
476
) -> ( Ident , TokenStream , Literal ) {
475
477
//let shout_name = format_ident!("{}", type_names.shout_case);
476
- let ( first, rest) = type_names. pascal_case . split_at ( 1 ) ;
478
+ let ( first, rest) = type_names. json_builtin_name . split_at ( 1 ) ;
477
479
478
480
let pascal_name = format_ident ! ( "{}{}" , first. to_ascii_uppercase( ) , rest) ;
479
- let rust_ty = to_rust_type ( & type_names. pascal_case , ctx) ;
481
+ let rust_ty = to_rust_type ( & type_names. json_builtin_name , ctx) ;
480
482
let ord = Literal :: i32_unsuffixed ( value) ;
481
483
482
484
( pascal_name, rust_ty. to_token_stream ( ) , ord)
483
485
}
484
486
485
487
fn make_opaque_type ( name : & str , size : usize ) -> TokenStream {
486
- // Capitalize: "int" -> "Int"
488
+ let name = to_pascal_case ( name ) ;
487
489
let ( first, rest) = name. split_at ( 1 ) ;
490
+
491
+ // Capitalize: "int" -> "Int"
488
492
let ident = format_ident ! ( "Opaque{}{}" , first. to_ascii_uppercase( ) , rest) ;
489
- //let upper = format_ident!("SIZE_{}", name.to_uppercase());
490
493
quote ! {
491
494
pub type #ident = crate :: opaque:: Opaque <#size>;
492
- //pub const #upper: usize = #size;
493
495
}
494
496
}
495
497
@@ -574,11 +576,11 @@ fn make_construct_fns(
574
576
if let Some ( args) = & constructors[ 1 ] . arguments {
575
577
assert_eq ! ( args. len( ) , 1 ) ;
576
578
assert_eq ! ( args[ 0 ] . name, "from" ) ;
577
- assert_eq ! ( args[ 0 ] . type_, type_names. pascal_case ) ;
579
+ assert_eq ! ( args[ 0 ] . type_, type_names. json_builtin_name ) ;
578
580
} else {
579
581
panic ! (
580
582
"type {}: no constructor args found for copy constructor" ,
581
- type_names. pascal_case
583
+ type_names. json_builtin_name
582
584
) ;
583
585
}
584
586
@@ -734,7 +736,7 @@ fn format_load_error(ident: &impl std::fmt::Display) -> String {
734
736
fn is_trivial ( type_names : & TypeNames ) -> bool {
735
737
let list = [ "bool" , "int" , "float" ] ;
736
738
737
- list. contains ( & type_names. pascal_case . as_str ( ) )
739
+ list. contains ( & type_names. json_builtin_name . as_str ( ) )
738
740
}
739
741
740
742
fn shout_to_pascal ( shout_case : & str ) -> String {
0 commit comments