summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEmilio Cobos Álvarez <emilio@crisal.io>2017-01-24 11:51:34 +0100
committerEmilio Cobos Álvarez <emilio@crisal.io>2017-01-24 11:51:34 +0100
commit15630c6562d8a1f2f95169a09344ef6e2becd56c (patch)
treede09082a4df8ca23ab5669c716591f4462cafbca
parentf804f9eb6fcd7caf032b337c448e7314d3247664 (diff)
Make it work in rust stable, and incidentally fix #425
The problem with #425 was the following: We were parsing the methods after reaching the JS::Value definition. Those methods contained a JSWhyMagic that we hadn't seen, so we parsed it as being in the JS:: module.
-rw-r--r--src/codegen/mod.rs32
-rw-r--r--src/ir/function.rs8
-rw-r--r--tests/expectations/tests/issue-410.rs6
-rw-r--r--tests/expectations/tests/reparented_replacement.rs2
-rw-r--r--tests/expectations/tests/template.rs14
5 files changed, 33 insertions, 29 deletions
diff --git a/src/codegen/mod.rs b/src/codegen/mod.rs
index 578a8d0c..45a7b1b7 100644
--- a/src/codegen/mod.rs
+++ b/src/codegen/mod.rs
@@ -40,19 +40,17 @@ fn root_import_depth(ctx: &BindgenContext, item: &Item) -> usize {
.fold(1, |i, _| i + 1)
}
-fn top_level_module_path(ctx: &BindgenContext, item: &Item) -> Vec<ast::Ident> {
+fn top_level_path(ctx: &BindgenContext, item: &Item) -> Vec<ast::Ident> {
let mut path = vec![ctx.rust_ident_raw("self")];
- let super_ = ctx.rust_ident_raw("super");
+ if ctx.options().enable_cxx_namespaces {
+ let super_ = ctx.rust_ident_raw("super");
- for _ in 0..root_import_depth(ctx, item) {
- path.push(super_.clone());
+ for _ in 0..root_import_depth(ctx, item) {
+ path.push(super_.clone());
+ }
}
- let root = ctx.root_module().canonical_name(ctx);
- let root_ident = ctx.rust_ident(&root);
-
- path.push(root_ident);
path
}
@@ -60,10 +58,16 @@ fn root_import(ctx: &BindgenContext, module: &Item) -> P<ast::Item> {
assert!(ctx.options().enable_cxx_namespaces, "Somebody messed it up");
assert!(module.is_module());
+ let mut path = top_level_path(ctx, module);
+
+ let root = ctx.root_module().canonical_name(ctx);
+ let root_ident = ctx.rust_ident(&root);
+ path.push(root_ident);
+
let use_root = aster::AstBuilder::new()
.item()
.use_()
- .ids(top_level_module_path(ctx, module))
+ .ids(path)
.build()
.build();
@@ -550,10 +554,12 @@ impl CodeGenerator for Type {
};
let typedef = if let Some(mut p) = simple_enum_path {
- p.segments.insert(0, ast::PathSegment {
- identifier: ctx.ext_cx().ident_of("self"),
- parameters: None,
- });
+ for ident in top_level_path(ctx, item).into_iter().rev() {
+ p.segments.insert(0, ast::PathSegment {
+ identifier: ident,
+ parameters: None,
+ });
+ }
typedef.use_().build(p).as_(rust_name)
} else {
let mut generics = typedef.type_(rust_name).generics();
diff --git a/src/ir/function.rs b/src/ir/function.rs
index 50c442db..6e205f1b 100644
--- a/src/ir/function.rs
+++ b/src/ir/function.rs
@@ -165,8 +165,7 @@ impl FunctionSig {
let name = arg.spelling();
let name =
if name.is_empty() { None } else { Some(name) };
- let ty = Item::from_ty(&arg_ty, Some(*arg), None, ctx)
- .expect("Argument?");
+ let ty = Item::from_ty_or_ref(arg_ty, Some(*arg), None, ctx);
(name, ty)
})
.collect()
@@ -178,8 +177,7 @@ impl FunctionSig {
cursor.visit(|c| {
if c.kind() == CXCursor_ParmDecl {
let ty =
- Item::from_ty(&c.cur_type(), Some(c), None, ctx)
- .expect("ParmDecl?");
+ Item::from_ty_or_ref(c.cur_type(), Some(c), None, ctx);
let name = c.spelling();
let name =
if name.is_empty() { None } else { Some(name) };
@@ -218,7 +216,7 @@ impl FunctionSig {
}
let ty_ret_type = try!(ty.ret_type().ok_or(ParseError::Continue));
- let ret = try!(Item::from_ty(&ty_ret_type, None, None, ctx));
+ let ret = Item::from_ty_or_ref(ty_ret_type, None, None, ctx);
let abi = get_abi(ty.call_conv());
Ok(Self::new(ret, args, ty.is_variadic(), abi))
diff --git a/tests/expectations/tests/issue-410.rs b/tests/expectations/tests/issue-410.rs
index 570e88ba..0c91e2b7 100644
--- a/tests/expectations/tests/issue-410.rs
+++ b/tests/expectations/tests/issue-410.rs
@@ -10,7 +10,6 @@ pub mod root {
pub mod JS {
#[allow(unused_imports)]
use self::super::super::root;
- pub use self::root::_bindgen_ty_1 as JSWhyMagic;
#[repr(C)]
#[derive(Debug, Copy)]
pub struct Value {
@@ -24,18 +23,19 @@ pub mod root {
extern "C" {
#[link_name = "_ZN2JS5Value1aE10JSWhyMagic"]
pub fn Value_a(this: *mut root::JS::Value,
- arg1: root::JS::JSWhyMagic);
+ arg1: root::JSWhyMagic);
}
impl Clone for Value {
fn clone(&self) -> Self { *self }
}
impl Value {
#[inline]
- pub unsafe fn a(&mut self, arg1: root::JS::JSWhyMagic) {
+ pub unsafe fn a(&mut self, arg1: root::JSWhyMagic) {
Value_a(&mut *self, arg1)
}
}
}
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub enum _bindgen_ty_1 { }
+ pub use self::super::root::_bindgen_ty_1 as JSWhyMagic;
}
diff --git a/tests/expectations/tests/reparented_replacement.rs b/tests/expectations/tests/reparented_replacement.rs
index a50a446d..684c75ed 100644
--- a/tests/expectations/tests/reparented_replacement.rs
+++ b/tests/expectations/tests/reparented_replacement.rs
@@ -25,5 +25,5 @@ pub mod root {
fn clone(&self) -> Self { *self }
}
}
- pub use self::root::foo::Bar as ReferencesBar;
+ pub use self::super::root::foo::Bar as ReferencesBar;
}
diff --git a/tests/expectations/tests/template.rs b/tests/expectations/tests/template.rs
index 5864ac73..22e5a087 100644
--- a/tests/expectations/tests/template.rs
+++ b/tests/expectations/tests/template.rs
@@ -12,13 +12,6 @@ pub struct Foo<T, U> {
pub m_member_arr: [T; 1usize],
pub _phantom_1: ::std::marker::PhantomData<U>,
}
-#[test]
-fn __bindgen_test_layout_template_1() {
- assert_eq!(::std::mem::size_of::<Foo<::std::os::raw::c_int, ::std::os::raw::c_int>>()
- , 24usize);
- assert_eq!(::std::mem::align_of::<Foo<::std::os::raw::c_int, ::std::os::raw::c_int>>()
- , 8usize);
-}
extern "C" {
#[link_name = "_Z3bar3FooIiiE"]
pub fn bar(foo: Foo<::std::os::raw::c_int, ::std::os::raw::c_int>);
@@ -176,6 +169,13 @@ pub struct TemplateWithVar<T> {
pub _phantom_0: ::std::marker::PhantomData<T>,
}
#[test]
+fn __bindgen_test_layout_template_1() {
+ assert_eq!(::std::mem::size_of::<Foo<::std::os::raw::c_int, ::std::os::raw::c_int>>()
+ , 24usize);
+ assert_eq!(::std::mem::align_of::<Foo<::std::os::raw::c_int, ::std::os::raw::c_int>>()
+ , 8usize);
+}
+#[test]
fn __bindgen_test_layout_template_2() {
assert_eq!(::std::mem::size_of::<WithDtor<::std::os::raw::c_int>>() ,
4usize);