Skip to content

Commit 87e253d

Browse files
committed
Move enum_kind_is_signed to a method on IKind
1 parent 3d418de commit 87e253d

File tree

2 files changed

+19
-17
lines changed

2 files changed

+19
-17
lines changed

src/gen.rs

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -700,22 +700,6 @@ fn const_to_rs(ctx: &mut GenCtx, name: String, val: i64, val_ty: ast::Ty) -> P<a
700700
})
701701
}
702702

703-
fn enum_kind_is_signed(kind: IKind) -> bool {
704-
match kind {
705-
IBool => false,
706-
ISChar => true,
707-
IUChar => false,
708-
IShort => true,
709-
IUShort => false,
710-
IInt => true,
711-
IUInt => false,
712-
ILong => true,
713-
IULong => false,
714-
ILongLong => true,
715-
IULongLong => false,
716-
}
717-
}
718-
719703
fn enum_size_to_rust_type_name(signed: bool, size: usize) -> &'static str {
720704
match (signed, size) {
721705
(true, 1) => "i8",
@@ -774,7 +758,7 @@ fn cenum_to_rs(ctx: &mut GenCtx,
774758
-> Vec<P<ast::Item>> {
775759
let enum_name = ctx.ext_cx.ident_of(&name);
776760
let enum_ty = ctx.ext_cx.ty_ident(ctx.span, enum_name);
777-
let enum_is_signed = enum_kind_is_signed(kind);
761+
let enum_is_signed = kind.is_signed();
778762

779763
let mut variants = vec![];
780764
let mut found_values = HashMap::new();

src/types.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,24 @@ pub enum IKind {
174174
IULongLong
175175
}
176176

177+
impl IKind {
178+
pub fn is_signed(self) -> bool {
179+
match self {
180+
IBool => false,
181+
ISChar => true,
182+
IUChar => false,
183+
IShort => true,
184+
IUShort => false,
185+
IInt => true,
186+
IUInt => false,
187+
ILong => true,
188+
IULong => false,
189+
ILongLong => true,
190+
IULongLong => false,
191+
}
192+
}
193+
}
194+
177195
#[derive(Copy, Clone, PartialEq)]
178196
pub enum FKind {
179197
FFloat,

0 commit comments

Comments
 (0)