summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorbors-servo <lbergstrom+bors@mozilla.com>2018-02-04 10:01:54 -0500
committerGitHub <noreply@github.com>2018-02-04 10:01:54 -0500
commit079d8383cc02cdce355af4cc8110317dfd362e37 (patch)
tree30406d1c6ac7c050e3023a6d136f4199d70e370a /src
parent92b86c5ca3b5aa14e23a19578898e7f43168a2fc (diff)
parented5776206ccd3873e372d4960208fe6cec1235f7 (diff)
Auto merge of #1246 - emilio:macro-constants, r=nox
ir: Make macro constants not being architecture-dependent. Fixes #1185
Diffstat (limited to 'src')
-rw-r--r--src/ir/var.rs27
1 files changed, 16 insertions, 11 deletions
diff --git a/src/ir/var.rs b/src/ir/var.rs
index c71a9314..84d6d9a0 100644
--- a/src/ir/var.rs
+++ b/src/ir/var.rs
@@ -113,6 +113,21 @@ impl DotAttributes for Var {
}
}
+// TODO(emilio): we could make this more (or less) granular, I guess.
+fn default_macro_constant_type(value: i64) -> IntKind {
+ if value < 0 {
+ if value < i32::min_value() as i64 {
+ IntKind::I64
+ } else {
+ IntKind::I32
+ }
+ } else if value > u32::max_value() as i64 {
+ IntKind::U64
+ } else {
+ IntKind::U32
+ }
+}
+
impl ClangSubItemParser for Var {
fn parse(
cursor: clang::Cursor,
@@ -189,17 +204,7 @@ impl ClangSubItemParser for Var {
EvalResult::Int(Wrapping(value)) => {
let kind = ctx.parse_callbacks()
.and_then(|c| c.int_macro(&name, value))
- .unwrap_or_else(|| if value < 0 {
- if value < i32::min_value() as i64 {
- IntKind::LongLong
- } else {
- IntKind::Int
- }
- } else if value > u32::max_value() as i64 {
- IntKind::ULongLong
- } else {
- IntKind::UInt
- });
+ .unwrap_or_else(|| default_macro_constant_type(value));
(TypeKind::Int(kind), VarType::Int(value))
}