Skip to content

Commit 36adfe8

Browse files
committed
changed bitfields to be i64 instead of u64
1 parent 8ecd619 commit 36adfe8

File tree

5 files changed

+15
-22
lines changed

5 files changed

+15
-22
lines changed

godot-codegen/src/generator/enums.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -89,15 +89,15 @@ pub fn make_enum_definition(enum_: &Enum) -> TokenStream {
8989
}
9090
}
9191
};
92-
enum_ord_type = quote! { u64 };
92+
enum_ord_type = quote! { i64 };
9393
self_as_trait = quote! { <Self as crate::obj::EngineBitfield> };
9494
engine_impl = quote! {
9595
impl crate::obj::EngineBitfield for #rust_enum_name {
96-
fn try_from_ord(ord: u64) -> Option<Self> {
96+
fn try_from_ord(ord: i64) -> Option<Self> {
9797
Some(Self { ord })
9898
}
9999

100-
fn ord(self) -> u64 {
100+
fn ord(self) -> i64 {
101101
self.ord
102102
}
103103
}
@@ -128,7 +128,7 @@ pub fn make_enum_definition(enum_: &Enum) -> TokenStream {
128128

129129
// Enumerator ordinal stored as i32, since that's enough to hold all current values and the default repr in C++.
130130
// Public interface is i64 though, for consistency (and possibly forward compatibility?).
131-
// Bitfield ordinals are stored as u64. See also: https://github.com/godotengine/godot-cpp/pull/1320
131+
// Bitfield ordinals are stored as i64.
132132
quote! {
133133
#[repr(transparent)]
134134
#[derive(#( #derives ),*)]
@@ -172,8 +172,8 @@ pub fn make_enumerator_ord(ord: i32) -> Literal {
172172
// ----------------------------------------------------------------------------------------------------------------------------------------------
173173
// Implementation
174174

175-
fn make_bitfield_flag_ord(ord: u64) -> Literal {
176-
Literal::u64_suffixed(ord)
175+
fn make_bitfield_flag_ord(ord: i64) -> Literal {
176+
Literal::i64_suffixed(ord)
177177
}
178178

179179
fn make_enumerator_definition(enumerator: &Enumerator) -> TokenStream {

godot-codegen/src/models/domain.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -201,15 +201,15 @@ pub struct Enumerator {
201201
}
202202
pub enum EnumeratorValue {
203203
Enum(i32),
204-
Bitfield(u64),
204+
Bitfield(i64),
205205
}
206206

207207
impl EnumeratorValue {
208208
pub fn to_i64(&self) -> i64 {
209209
// Conversion is safe because i64 is used in the original JSON.
210210
match self {
211211
EnumeratorValue::Enum(i) => *i as i64,
212-
EnumeratorValue::Bitfield(i) => *i as i64,
212+
EnumeratorValue::Bitfield(i) => *i,
213213
}
214214
}
215215

godot-codegen/src/models/domain_mapping.rs

+1-8
Original file line numberDiff line numberDiff line change
@@ -543,14 +543,7 @@ impl Enum {
543543
impl Enumerator {
544544
pub fn from_json(json: &JsonEnumConstant, rust_name: Ident, is_bitfield: bool) -> Self {
545545
let value = if is_bitfield {
546-
let ord = json.value.try_into().unwrap_or_else(|_| {
547-
panic!(
548-
"bitfield value {} = {} is negative; please report this",
549-
json.name, json.value
550-
)
551-
});
552-
553-
EnumeratorValue::Bitfield(ord)
546+
EnumeratorValue::Bitfield(json.value)
554547
} else {
555548
let ord = json.value.try_into().unwrap_or_else(|_| {
556549
panic!(

godot-core/src/obj/traits.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -161,12 +161,12 @@ pub trait EngineEnum: Copy {
161161

162162
/// Auto-implemented for all engine-provided bitfields.
163163
pub trait EngineBitfield: Copy {
164-
fn try_from_ord(ord: u64) -> Option<Self>;
164+
fn try_from_ord(ord: i64) -> Option<Self>;
165165

166166
/// Ordinal value of the bit flag, as specified in Godot.
167-
fn ord(self) -> u64;
167+
fn ord(self) -> i64;
168168

169-
fn from_ord(ord: u64) -> Self {
169+
fn from_ord(ord: i64) -> Self {
170170
Self::try_from_ord(ord)
171171
.unwrap_or_else(|| panic!("ordinal {ord} does not map to any valid bit flag"))
172172
}

itest/rust/src/object_tests/property_template_test.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,12 @@ fn property_template_test(ctx: &TestContext) {
6161
let mut rust_usage = rust_prop.get("usage").unwrap().to::<i64>();
6262

6363
// the GDSscript variables are script variables, and so have `PROPERTY_USAGE_SCRIPT_VARIABLE` set.
64-
if rust_usage == PropertyUsageFlags::STORAGE.ord() as i64 {
64+
if rust_usage == PropertyUsageFlags::STORAGE.ord() {
6565
// `PROPERTY_USAGE_SCRIPT_VARIABLE` does the same thing as `PROPERTY_USAGE_STORAGE` and so
6666
// GDScript doesn't set both if it doesn't need to.
67-
rust_usage = PropertyUsageFlags::SCRIPT_VARIABLE.ord() as i64
67+
rust_usage = PropertyUsageFlags::SCRIPT_VARIABLE.ord()
6868
} else {
69-
rust_usage |= PropertyUsageFlags::SCRIPT_VARIABLE.ord() as i64;
69+
rust_usage |= PropertyUsageFlags::SCRIPT_VARIABLE.ord();
7070
}
7171

7272
rust_prop.set("usage", rust_usage);

0 commit comments

Comments
 (0)