Skip to content

Commit fc9d994

Browse files
committed
change bitfields from u64 to i64
1 parent e1f1ce3 commit fc9d994

File tree

5 files changed

+12
-19
lines changed

5 files changed

+12
-19
lines changed

godot-codegen/src/generator/enums.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -197,11 +197,11 @@ fn make_enum_engine_trait_impl(enum_: &Enum) -> TokenStream {
197197
// }
198198

199199
impl #engine_trait for #name {
200-
fn try_from_ord(ord: u64) -> Option<Self> {
200+
fn try_from_ord(ord: i64) -> Option<Self> {
201201
Some(Self { ord })
202202
}
203203

204-
fn ord(self) -> u64 {
204+
fn ord(self) -> i64 {
205205
self.ord
206206
}
207207
}

godot-codegen/src/models/domain/enums.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ impl Enum {
3939
/// The type we use to represent values of this enum.
4040
pub fn ord_type(&self) -> Ident {
4141
if self.is_bitfield {
42-
ident("u64")
42+
ident("i64")
4343
} else {
4444
ident("i32")
4545
}
@@ -126,7 +126,7 @@ pub struct Enumerator {
126126
#[derive(Clone)]
127127
pub enum EnumeratorValue {
128128
Enum(i32),
129-
Bitfield(u64),
129+
Bitfield(i64),
130130
}
131131

132132
impl EnumeratorValue {
@@ -145,7 +145,7 @@ impl EnumeratorValue {
145145
// Conversion is safe because i64 is used in the original JSON.
146146
match self {
147147
EnumeratorValue::Enum(i) => *i as i64,
148-
EnumeratorValue::Bitfield(i) => *i as i64,
148+
EnumeratorValue::Bitfield(i) => *i,
149149
}
150150
}
151151

godot-codegen/src/models/domain_mapping.rs

+1-8
Original file line numberDiff line numberDiff line change
@@ -571,14 +571,7 @@ impl Enum {
571571
impl Enumerator {
572572
pub fn from_json(json: &JsonEnumConstant, rust_name: Ident, is_bitfield: bool) -> Self {
573573
let value = if is_bitfield {
574-
let ord = json.value.try_into().unwrap_or_else(|_| {
575-
panic!(
576-
"bitfield value {} = {} is negative; please report this",
577-
json.name, json.value
578-
)
579-
});
580-
581-
EnumeratorValue::Bitfield(ord)
574+
EnumeratorValue::Bitfield(json.value)
582575
} else {
583576
let ord = json.value.try_into().unwrap_or_else(|_| {
584577
panic!(

godot-core/src/obj/traits.rs

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

168168
/// Auto-implemented for all engine-provided bitfields.
169169
pub trait EngineBitfield: Copy {
170-
fn try_from_ord(ord: u64) -> Option<Self>;
170+
fn try_from_ord(ord: i64) -> Option<Self>;
171171

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

175-
fn from_ord(ord: u64) -> Self {
175+
fn from_ord(ord: i64) -> Self {
176176
Self::try_from_ord(ord)
177177
.unwrap_or_else(|| panic!("ordinal {ord} does not map to any valid bit flag"))
178178
}

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)