diff options
-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 } } |