diff options
author | Emilio Cobos Álvarez <emilio@crisal.io> | 2020-12-19 19:20:27 +0100 |
---|---|---|
committer | Emilio Cobos Álvarez <emilio@crisal.io> | 2020-12-19 19:28:24 +0100 |
commit | 5c821867f237f0248b981da90a7607dfe9e328ae (patch) | |
tree | 3f360c80dc797ce029e60a1040aa8ad76e64e875 | |
parent | ea4164c85c6a305379e4cc70465aae15afedf3d7 (diff) |
var: Avoid a bit of duplication with fit_macro_constants.
-rw-r--r-- | src/ir/var.rs | 66 |
1 files changed, 24 insertions, 42 deletions
diff --git a/src/ir/var.rs b/src/ir/var.rs index 64f15703..49c4f304 100644 --- a/src/ir/var.rs +++ b/src/ir/var.rs @@ -118,52 +118,34 @@ impl DotAttributes for Var { } fn default_macro_constant_type(ctx: &BindgenContext, value: i64) -> IntKind { - if ctx.options().fit_macro_constants { - if value < 0 || - ctx.options().default_macro_constant_type == - MacroTypeVariation::Signed + if value < 0 || + ctx.options().default_macro_constant_type == + MacroTypeVariation::Signed + { + if value < i32::min_value() as i64 || value > i32::max_value() as i64 { + IntKind::I64 + } else if !ctx.options().fit_macro_constants || + value < i16::min_value() as i64 || + value > i16::max_value() as i64 { - if value < i32::min_value() as i64 || - value > i32::max_value() as i64 - { - IntKind::I64 - } else if value < i16::min_value() as i64 || - value > i16::max_value() as i64 - { - IntKind::I32 - } else if value < i8::min_value() as i64 || - value > i8::max_value() as i64 - { - IntKind::I16 - } else { - IntKind::I8 - } - } else if value > u32::max_value() as i64 { - IntKind::U64 - } else if value > u16::max_value() as i64 { - IntKind::U32 - } else if value > u8::max_value() as i64 { - IntKind::U16 - } else { - IntKind::U8 - } - } else { - if value < 0 || - ctx.options().default_macro_constant_type == - MacroTypeVariation::Signed + IntKind::I32 + } else if value < i8::min_value() as i64 || + value > i8::max_value() as i64 { - if value < i32::min_value() as i64 || - value > i32::max_value() as i64 - { - IntKind::I64 - } else { - IntKind::I32 - } - } else if value > u32::max_value() as i64 { - IntKind::U64 + IntKind::I16 } else { - IntKind::U32 + IntKind::I8 } + } else if value > u32::max_value() as i64 { + IntKind::U64 + } else if !ctx.options().fit_macro_constants || + value > u16::max_value() as i64 + { + IntKind::U32 + } else if value > u8::max_value() as i64 { + IntKind::U16 + } else { + IntKind::U8 } } |