diff options
author | Emilio Cobos Álvarez <emilio@crisal.io> | 2017-01-24 11:51:34 +0100 |
---|---|---|
committer | Emilio Cobos Álvarez <emilio@crisal.io> | 2017-01-24 11:51:34 +0100 |
commit | 15630c6562d8a1f2f95169a09344ef6e2becd56c (patch) | |
tree | de09082a4df8ca23ab5669c716591f4462cafbca /src | |
parent | f804f9eb6fcd7caf032b337c448e7314d3247664 (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.
Diffstat (limited to 'src')
-rw-r--r-- | src/codegen/mod.rs | 32 | ||||
-rw-r--r-- | src/ir/function.rs | 8 |
2 files changed, 22 insertions, 18 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)) |