diff options
author | Nick Fitzgerald <fitzgen@gmail.com> | 2017-09-29 12:16:36 -0700 |
---|---|---|
committer | Nick Fitzgerald <fitzgen@gmail.com> | 2017-09-29 12:20:49 -0700 |
commit | 64d73c28600686dff5a54d2a1afb737e291f9e08 (patch) | |
tree | 941bfb20f260351e635bbcdd0f4df3fb78ac6366 /src | |
parent | c160b20218ecd85b2dfc141485b85beec88bac4f (diff) |
ir: Prefer using known semantic parents
When choosing a parent ID for a type that we are parsing, prefer known semantic
parents over the provided parent ID. It seems like we shouldn't even be passing
explicit parent IDs around (they're often buggy), and instead should expand the
`known_semantic_parent` infrastructure, but I'll leave that to some future work.
Fixes #1048
Diffstat (limited to 'src')
-rw-r--r-- | src/ir/comp.rs | 1 | ||||
-rw-r--r-- | src/ir/context.rs | 22 | ||||
-rw-r--r-- | src/ir/item.rs | 3 |
3 files changed, 16 insertions, 10 deletions
diff --git a/src/ir/comp.rs b/src/ir/comp.rs index fc17ab8f..e1b2a1f0 100644 --- a/src/ir/comp.rs +++ b/src/ir/comp.rs @@ -1152,6 +1152,7 @@ impl CompInfo { let inner = Item::parse(cur, Some(potential_id), ctx) .expect("Inner ClassDecl"); + assert_eq!(ctx.resolve_item(inner).parent_id(), potential_id); ci.inner_types.push(inner); diff --git a/src/ir/context.rs b/src/ir/context.rs index b540d152..5b6b46ef 100644 --- a/src/ir/context.rs +++ b/src/ir/context.rs @@ -751,25 +751,29 @@ impl BindgenContext { let typerefs = self.collect_typerefs(); for (id, ty, loc, parent_id) in typerefs { - let _resolved = - { - let resolved = Item::from_ty(&ty, loc, parent_id, self) + let _resolved = { + let resolved = Item::from_ty(&ty, loc, parent_id, self) .unwrap_or_else(|_| { warn!("Could not resolve type reference, falling back \ to opaque blob"); Item::new_opaque_type(self.next_item_id(), &ty, self) }); - let item = self.items.get_mut(&id).unwrap(); - *item.kind_mut().as_type_mut().unwrap().kind_mut() = - TypeKind::ResolvedTypeRef(resolved); - resolved - }; + let item = self.items.get_mut(&id).unwrap(); + *item.kind_mut().as_type_mut().unwrap().kind_mut() = + TypeKind::ResolvedTypeRef(resolved); + + resolved + }; // Something in the STL is trolling me. I don't need this assertion // right now, but worth investigating properly once this lands. // // debug_assert!(self.items.get(&resolved).is_some(), "How?"); + // + // if let Some(parent_id) = parent_id { + // assert_eq!(self.items[&resolved].parent_id(), parent_id); + // } } } @@ -953,7 +957,7 @@ impl BindgenContext { self.compute_bitfield_units(); self.process_replacements(); } - + self.deanonymize_fields(); // And assert once again, because resolving type refs and processing diff --git a/src/ir/item.rs b/src/ir/item.rs index 8a5a143b..955793c1 100644 --- a/src/ir/item.rs +++ b/src/ir/item.rs @@ -1216,7 +1216,8 @@ impl ClangItemParser for Item { ctx, )); } - parent_id.or_else(|| ctx.known_semantic_parent(definition)) + ctx.known_semantic_parent(definition) + .or(parent_id) .unwrap_or(ctx.current_module()) } None => relevant_parent_id, |