summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnthony Ramine <n.oxyde@gmail.com>2016-03-10 21:25:55 +0100
committerAnthony Ramine <n.oxyde@gmail.com>2016-03-10 21:25:58 +0100
commit87e253d855d470ef4e89d95a19512feb7ea28fac (patch)
treec3633a14c8a5dd8d1edc53eb61a16274ea53d0bf
parent3d418de415f80901843bef2f8aee03ce80b90031 (diff)
Move enum_kind_is_signed to a method on IKind
-rw-r--r--src/gen.rs18
-rw-r--r--src/types.rs18
2 files changed, 19 insertions, 17 deletions
diff --git a/src/gen.rs b/src/gen.rs
index e26fbffb..ad87507b 100644
--- a/src/gen.rs
+++ b/src/gen.rs
@@ -700,22 +700,6 @@ fn const_to_rs(ctx: &mut GenCtx, name: String, val: i64, val_ty: ast::Ty) -> P<a
})
}
-fn enum_kind_is_signed(kind: IKind) -> bool {
- match kind {
- IBool => false,
- ISChar => true,
- IUChar => false,
- IShort => true,
- IUShort => false,
- IInt => true,
- IUInt => false,
- ILong => true,
- IULong => false,
- ILongLong => true,
- IULongLong => false,
- }
-}
-
fn enum_size_to_rust_type_name(signed: bool, size: usize) -> &'static str {
match (signed, size) {
(true, 1) => "i8",
@@ -774,7 +758,7 @@ fn cenum_to_rs(ctx: &mut GenCtx,
-> Vec<P<ast::Item>> {
let enum_name = ctx.ext_cx.ident_of(&name);
let enum_ty = ctx.ext_cx.ty_ident(ctx.span, enum_name);
- let enum_is_signed = enum_kind_is_signed(kind);
+ let enum_is_signed = kind.is_signed();
let mut variants = vec![];
let mut found_values = HashMap::new();
diff --git a/src/types.rs b/src/types.rs
index 14526fd0..a8726b53 100644
--- a/src/types.rs
+++ b/src/types.rs
@@ -174,6 +174,24 @@ pub enum IKind {
IULongLong
}
+impl IKind {
+ pub fn is_signed(self) -> bool {
+ match self {
+ IBool => false,
+ ISChar => true,
+ IUChar => false,
+ IShort => true,
+ IUShort => false,
+ IInt => true,
+ IUInt => false,
+ ILong => true,
+ IULong => false,
+ ILongLong => true,
+ IULongLong => false,
+ }
+ }
+}
+
#[derive(Copy, Clone, PartialEq)]
pub enum FKind {
FFloat,