summaryrefslogtreecommitdiff
path: root/src/codegen/mod.rs
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 /src/codegen/mod.rs
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.
Diffstat (limited to 'src/codegen/mod.rs')
-rw-r--r--src/codegen/mod.rs32
1 files changed, 19 insertions, 13 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();