diff options
author | bors-servo <lbergstrom+bors@mozilla.com> | 2016-10-29 13:28:42 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-10-29 13:28:42 -0500 |
commit | 3618f55f8067b11da15b0cc6650c229ffef3d170 (patch) | |
tree | c5c72920cf63b3bf2153d56b1df2f85525243491 | |
parent | f7b5fae91b212345bc8ce462cc700f4619e2a708 (diff) | |
parent | ececf400d1493abc2d641fb278ea6b23fe962e87 (diff) |
Auto merge of #161 - upsuper:safe-canonical-type, r=emilio
Use safe_canonical_type for parse time
This should fix #160.
r? @emilio
-rw-r--r-- | src/ir/ty.rs | 25 | ||||
-rw-r--r-- | src/ir/var.rs | 15 |
2 files changed, 21 insertions, 19 deletions
diff --git a/src/ir/ty.rs b/src/ir/ty.rs index 3a17b374..bbb666bc 100644 --- a/src/ir/ty.rs +++ b/src/ir/ty.rs @@ -122,13 +122,10 @@ impl Type { } /// Is this an integer type? - pub fn is_integer(&self, ctx: &BindgenContext) -> bool { + pub fn is_integer(&self) -> bool { match self.kind { - TypeKind::UnresolvedTypeRef(..) => false, - _ => match self.canonical_type(ctx).kind { - TypeKind::Int(..) => true, - _ => false, - } + TypeKind::Int(..) => true, + _ => false, } } @@ -311,12 +308,17 @@ impl Type { } } + /// See safe_canonical_type. + pub fn canonical_type<'tr>(&'tr self, ctx: &'tr BindgenContext) -> &'tr Type { + self.safe_canonical_type(ctx).expect("Should have been resolved after parsing!") + } + /// Returns the canonical type of this type, that is, the "inner type". /// /// For example, for a `typedef`, the canonical type would be the /// `typedef`ed type, for a template specialization, would be the template - /// its specializing, and so on. - pub fn canonical_type<'tr>(&'tr self, ctx: &'tr BindgenContext) -> &'tr Type { + /// its specializing, and so on. Return None if the type is unresolved. + pub fn safe_canonical_type<'tr>(&'tr self, ctx: &'tr BindgenContext) -> Option<&'tr Type> { match self.kind { TypeKind::Named(..) | TypeKind::Array(..) | @@ -329,16 +331,15 @@ impl Type { TypeKind::Void | TypeKind::NullPtr | TypeKind::BlockPointer | - TypeKind::Pointer(..) => self, + TypeKind::Pointer(..) => Some(self), TypeKind::ResolvedTypeRef(inner) | TypeKind::Alias(_, inner) | TypeKind::TemplateAlias(inner, _) | TypeKind::TemplateRef(inner, _) - => ctx.resolve_type(inner).canonical_type(ctx), + => ctx.resolve_type(inner).safe_canonical_type(ctx), - TypeKind::UnresolvedTypeRef(..) - => unreachable!("Should have been resolved after parsing!"), + TypeKind::UnresolvedTypeRef(..) => None, } } } diff --git a/src/ir/var.rs b/src/ir/var.rs index 3dd975ee..e9245e1a 100644 --- a/src/ir/var.rs +++ b/src/ir/var.rs @@ -119,13 +119,14 @@ impl ClangSubItemParser for Var { // tests/headers/inner_const.hpp // // That's fine because in that case we know it's not a literal. - let value = context.safe_resolve_type(ty).map_or(None, |t| { - if t.is_integer(context) { - get_integer_literal_from_cursor(&cursor, context.translation_unit()) - } else { - None - } - }); + let value = context.safe_resolve_type(ty) + .and_then(|t| t.safe_canonical_type(context)).and_then(|t| { + if t.is_integer() { + get_integer_literal_from_cursor(&cursor, context.translation_unit()) + } else { + None + } + }); let mangling = cursor_mangling(&cursor); |