File tree 4 files changed +12
-19
lines changed
4 files changed +12
-19
lines changed Original file line number Diff line number Diff line change @@ -89,15 +89,15 @@ pub fn make_enum_definition(enum_: &Enum) -> TokenStream {
89
89
}
90
90
}
91
91
} ;
92
- enum_ord_type = quote ! { u64 } ;
92
+ enum_ord_type = quote ! { i64 } ;
93
93
self_as_trait = quote ! { <Self as crate :: obj:: EngineBitfield > } ;
94
94
engine_impl = quote ! {
95
95
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 > {
97
97
Some ( Self { ord } )
98
98
}
99
99
100
- fn ord( self ) -> u64 {
100
+ fn ord( self ) -> i64 {
101
101
self . ord
102
102
}
103
103
}
@@ -128,7 +128,7 @@ pub fn make_enum_definition(enum_: &Enum) -> TokenStream {
128
128
129
129
// Enumerator ordinal stored as i32, since that's enough to hold all current values and the default repr in C++.
130
130
// 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.
132
132
quote ! {
133
133
#[ repr( transparent) ]
134
134
#[ derive( #( #derives ) , * ) ]
@@ -172,8 +172,8 @@ pub fn make_enumerator_ord(ord: i32) -> Literal {
172
172
// ----------------------------------------------------------------------------------------------------------------------------------------------
173
173
// Implementation
174
174
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)
177
177
}
178
178
179
179
fn make_enumerator_definition ( enumerator : & Enumerator ) -> TokenStream {
Original file line number Diff line number Diff line change @@ -201,15 +201,15 @@ pub struct Enumerator {
201
201
}
202
202
pub enum EnumeratorValue {
203
203
Enum ( i32 ) ,
204
- Bitfield ( u64 ) ,
204
+ Bitfield ( i64 ) ,
205
205
}
206
206
207
207
impl EnumeratorValue {
208
208
pub fn to_i64 ( & self ) -> i64 {
209
209
// Conversion is safe because i64 is used in the original JSON.
210
210
match self {
211
211
EnumeratorValue :: Enum ( i) => * i as i64 ,
212
- EnumeratorValue :: Bitfield ( i) => * i as i64 ,
212
+ EnumeratorValue :: Bitfield ( i) => * i,
213
213
}
214
214
}
215
215
Original file line number Diff line number Diff line change @@ -543,14 +543,7 @@ impl Enum {
543
543
impl Enumerator {
544
544
pub fn from_json ( json : & JsonEnumConstant , rust_name : Ident , is_bitfield : bool ) -> Self {
545
545
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 )
554
547
} else {
555
548
let ord = json. value . try_into ( ) . unwrap_or_else ( |_| {
556
549
panic ! (
Original file line number Diff line number Diff line change @@ -161,12 +161,12 @@ pub trait EngineEnum: Copy {
161
161
162
162
/// Auto-implemented for all engine-provided bitfields.
163
163
pub trait EngineBitfield : Copy {
164
- fn try_from_ord ( ord : u64 ) -> Option < Self > ;
164
+ fn try_from_ord ( ord : i64 ) -> Option < Self > ;
165
165
166
166
/// Ordinal value of the bit flag, as specified in Godot.
167
- fn ord ( self ) -> u64 ;
167
+ fn ord ( self ) -> i64 ;
168
168
169
- fn from_ord ( ord : u64 ) -> Self {
169
+ fn from_ord ( ord : i64 ) -> Self {
170
170
Self :: try_from_ord ( ord)
171
171
. unwrap_or_else ( || panic ! ( "ordinal {ord} does not map to any valid bit flag" ) )
172
172
}
You can’t perform that action at this time.
0 commit comments