Skip to content

Commit f29b9e0

Browse files
committed
Add small codegen utility make_enumerator_ord()
1 parent d7ca792 commit f29b9e0

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

godot-codegen/src/central_generator.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ fn make_central_items(api: &ExtensionApi, build_config: &str, ctx: &mut Context)
385385
.push(ident(&util::shout_to_pascal(name)));
386386
result
387387
.variant_op_enumerators_ord
388-
.push(Literal::i32_unsuffixed(op.value));
388+
.push(util::make_enumerator_ord(op.value));
389389
}
390390

391391
for enum_ in api.global_enums.iter() {
@@ -499,7 +499,7 @@ fn make_enumerator(
499499
let enumerator_name = &type_names.json_builtin_name;
500500
let pascal_name = to_pascal_case(enumerator_name);
501501
let rust_ty = to_rust_type(enumerator_name, None, ctx);
502-
let ord = Literal::i32_unsuffixed(value);
502+
let ord = util::make_enumerator_ord(value);
503503

504504
(ident(&pascal_name), rust_ty.to_token_stream(), ord)
505505
}

godot-codegen/src/class_generator.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -684,7 +684,7 @@ fn make_notification_enum(
684684
let mut notification_enumerators_ord = Vec::new();
685685
for (constant_ident, constant_value) in all_constants {
686686
notification_enumerators_pascal.push(constant_ident);
687-
notification_enumerators_ord.push(constant_value);
687+
notification_enumerators_ord.push(util::make_enumerator_ord(constant_value));
688688
}
689689

690690
let code = quote! {

godot-codegen/src/util.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ pub fn make_enum_definition(enum_: &Enum) -> TokenStream {
3535

3636
for enumerator in values {
3737
let name = make_enumerator_name(&enumerator.name, &enum_.name);
38-
let ordinal = Literal::i32_unsuffixed(enumerator.value);
38+
let ordinal = make_enumerator_ord(enumerator.value);
3939

4040
enumerators.push(quote! {
4141
pub const #name: Self = Self { ord: #ordinal };
@@ -120,7 +120,7 @@ pub fn make_enum_definition(enum_: &Enum) -> TokenStream {
120120
let err = sys::PrimitiveConversionError::new(via);
121121
let ord = i32::try_from(via).map_err(|_| err)?;
122122
<Self as crate::obj::EngineEnum>::try_from_ord(ord).ok_or(err)
123-
}
123+
}
124124

125125
fn try_into_via(self) -> std::result::Result<Self::Via, Self::IntoViaError> {
126126
Ok(<Self as crate::obj::EngineEnum>::ord(self).into())
@@ -486,6 +486,10 @@ pub fn parse_native_structures_format(input: &str) -> Option<Vec<NativeStructure
486486
.collect()
487487
}
488488

489+
pub(crate) fn make_enumerator_ord(ord: i32) -> Literal {
490+
Literal::i32_unsuffixed(ord)
491+
}
492+
489493
pub(crate) fn to_rust_expr(expr: &str, ty: &RustTy) -> TokenStream {
490494
// println!("\n> to_rust_expr({expr}, {ty:?})");
491495

0 commit comments

Comments
 (0)