summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorNick Fitzgerald <fitzgen@gmail.com>2017-04-03 17:00:15 -0700
committerNick Fitzgerald <fitzgen@gmail.com>2017-04-03 17:12:28 -0700
commit582aa969c70a69f19d2aedb4c418c32e1c99b3c0 (patch)
tree8367580923d156d27816b41f03385cd41e93c329 /src
parentd4fce37939fbcebd04e7b7efec6930cfd717b13d (diff)
Fall back to opaque types rather than panicking on parse failure
Diffstat (limited to 'src')
-rw-r--r--src/ir/context.rs4
-rw-r--r--src/ir/item.rs9
-rw-r--r--src/ir/ty.rs14
3 files changed, 16 insertions, 11 deletions
diff --git a/src/ir/context.rs b/src/ir/context.rs
index c95d5179..fa001ba6 100644
--- a/src/ir/context.rs
+++ b/src/ir/context.rs
@@ -424,7 +424,9 @@ impl<'ctx> BindgenContext<'ctx> {
for (id, ty, loc, parent_id) in typerefs {
let _resolved = {
let resolved = Item::from_ty(&ty, loc, parent_id, self)
- .expect("What happened?");
+ .unwrap_or_else(|_| {
+ Item::new_opaque_type(self.next_item_id(), &ty, self)
+ });
let mut item = self.items.get_mut(&id).unwrap();
*item.kind_mut().as_type_mut().unwrap().kind_mut() =
diff --git a/src/ir/item.rs b/src/ir/item.rs
index 89422e87..5477dee9 100644
--- a/src/ir/item.rs
+++ b/src/ir/item.rs
@@ -433,10 +433,11 @@ impl Item {
}
}
- fn new_opaque_type(with_id: ItemId,
- ty: &clang::Type,
- ctx: &mut BindgenContext)
- -> ItemId {
+ /// Construct a new opaque item type.
+ pub fn new_opaque_type(with_id: ItemId,
+ ty: &clang::Type,
+ ctx: &mut BindgenContext)
+ -> ItemId {
let ty = Opaque::from_clang_ty(ty);
let kind = ItemKind::Type(ty);
let parent = ctx.root_module();
diff --git a/src/ir/ty.rs b/src/ir/ty.rs
index 60d750ed..a28727c9 100644
--- a/src/ir/ty.rs
+++ b/src/ir/ty.rs
@@ -1093,12 +1093,14 @@ impl Type {
name = location.spelling();
}
- let complex = CompInfo::from_ty(potential_id,
- ty,
- Some(location),
- ctx)
- .expect("C'mon");
- TypeKind::Comp(complex)
+ if let Ok(complex) = CompInfo::from_ty(potential_id,
+ ty,
+ Some(location),
+ ctx) {
+ TypeKind::Comp(complex)
+ } else {
+ return Ok(ParseResult::New(Opaque::from_clang_ty(ty), None));
+ }
}
CXCursor_TypeAliasTemplateDecl => {
debug!("TypeAliasTemplateDecl");