summaryrefslogtreecommitdiff
path: root/libbindgen/src/codegen/mod.rs
diff options
context:
space:
mode:
authorbors-servo <lbergstrom+bors@mozilla.com>2017-01-11 04:13:47 -0800
committerGitHub <noreply@github.com>2017-01-11 04:13:47 -0800
commit54aba18b3808f07de607137a6aee1a625b076784 (patch)
tree8155da9285d21e72a8510cdb0428d7763c0f566a /libbindgen/src/codegen/mod.rs
parent6bfeae155155a12849033e1c5199ca6e48e8b22c (diff)
parent66447ff277181073d14bb04c7947eec805cd0623 (diff)
Auto merge of #387 - emilio:trace-improvements, r=fitzgen
Improve tracing so it doesn't ignore opaque stuff when it shouldn't Concretely, trace through functions, pointers, arrays, references, resolved type references, and template references, which are the types for which either: * There's no special meaning to be opaque, or * They're just placeholders that point to other types.
Diffstat (limited to 'libbindgen/src/codegen/mod.rs')
-rw-r--r--libbindgen/src/codegen/mod.rs38
1 files changed, 20 insertions, 18 deletions
diff --git a/libbindgen/src/codegen/mod.rs b/libbindgen/src/codegen/mod.rs
index 6e63a791..d12c3d2a 100644
--- a/libbindgen/src/codegen/mod.rs
+++ b/libbindgen/src/codegen/mod.rs
@@ -1879,7 +1879,13 @@ impl ToRustTy for Type {
TypeKind::ResolvedTypeRef(inner) => inner.to_rust_ty(ctx),
TypeKind::TemplateAlias(ref spelling, inner, _) |
TypeKind::Alias(ref spelling, inner) => {
- if item.is_opaque(ctx) {
+ let applicable_named_args =
+ item.applicable_template_args(ctx)
+ .into_iter()
+ .filter(|arg| ctx.resolve_type(*arg).is_named())
+ .collect::<Vec<_>>();
+
+ if item.is_opaque(ctx) && !applicable_named_args.is_empty() {
// Pray if there's no available layout.
let layout = self.layout(ctx).unwrap_or_else(Layout::zero);
BlobTyBuilder::new(layout).build()
@@ -1888,11 +1894,15 @@ impl ToRustTy for Type {
inner) {
ty
} else {
- utils::build_templated_path(item, ctx, true)
+ utils::build_templated_path(item,
+ ctx,
+ applicable_named_args)
}
}
TypeKind::Comp(ref info) => {
- if item.is_opaque(ctx) || info.has_non_type_template_params() {
+ let template_args = item.applicable_template_args(ctx);
+ if info.has_non_type_template_params() ||
+ (item.is_opaque(ctx) && !template_args.is_empty()) {
return match self.layout(ctx) {
Some(layout) => BlobTyBuilder::new(layout).build(),
None => {
@@ -1904,7 +1914,7 @@ impl ToRustTy for Type {
};
}
- utils::build_templated_path(item, ctx, false)
+ utils::build_templated_path(item, ctx, template_args)
}
TypeKind::BlockPointer => {
let void = raw_type(ctx, "c_void");
@@ -2215,23 +2225,15 @@ mod utils {
pub fn build_templated_path(item: &Item,
ctx: &BindgenContext,
- only_named: bool)
+ template_args: Vec<ItemId>)
-> P<ast::Ty> {
let path = item.namespace_aware_canonical_path(ctx);
-
let builder = aster::AstBuilder::new().ty().path();
- let template_args = if only_named {
- item.applicable_template_args(ctx)
- .iter()
- .filter(|arg| ctx.resolve_type(**arg).is_named())
- .map(|arg| arg.to_rust_ty(ctx))
- .collect::<Vec<_>>()
- } else {
- item.applicable_template_args(ctx)
- .iter()
- .map(|arg| arg.to_rust_ty(ctx))
- .collect::<Vec<_>>()
- };
+
+ let template_args = template_args
+ .iter()
+ .map(|arg| arg.to_rust_ty(ctx))
+ .collect::<Vec<_>>();
// XXX: I suck at aster.
if path.len() == 1 {