Allow namespace override.
This change allows a
#[namespace (namespace = A::B)]
attribute for each item in a cxx::bridge.
We now have a fair number of different types of name floating
around:
* C++ identifiers
* C++ fully-qualified names
* Rust identifiers
* Rust fully-qualified names (future, when we support sub-modules)
* Items with both a Rust and C++ name (a 'Pair')
* Types with only a known Rust name, which can be resolved to a
C++ name.
This change attempts to put some sensible names for all these
things in syntax/mod.rs, and so that would be a good place to start
review.
At the moment, the Namespace (included in each CppName)
is ruthlessly cloned all over the place. As a given namespace is
likely to be applicable to many types and functions, it may
save significant memory in future to use Rc<> here. But let's not
optimise too early.
diff --git a/gen/src/mod.rs b/gen/src/mod.rs
index 2fee0e9..92e8ec8 100644
--- a/gen/src/mod.rs
+++ b/gen/src/mod.rs
@@ -5,6 +5,7 @@
mod file;
pub(super) mod fs;
pub(super) mod include;
+mod namespace_organizer;
pub(super) mod out;
mod write;
@@ -109,22 +110,22 @@
.ok_or(Error::NoBridgeMod)?;
let ref namespace = bridge.namespace;
let trusted = bridge.unsafety.is_some();
- let ref apis = syntax::parse_items(errors, bridge.content, trusted);
+ let ref apis = syntax::parse_items(errors, bridge.content, trusted, namespace);
let ref types = Types::collect(errors, apis);
errors.propagate()?;
- check::typecheck(errors, namespace, apis, types);
+ check::typecheck(errors, apis, types);
errors.propagate()?;
// Some callers may wish to generate both header and C++
// from the same token stream to avoid parsing twice. But others
// only need to generate one or the other.
Ok(GeneratedCode {
header: if opt.gen_header {
- write::gen(namespace, apis, types, opt, true).content()
+ write::gen(apis, types, opt, true).content()
} else {
Vec::new()
},
implementation: if opt.gen_implementation {
- write::gen(namespace, apis, types, opt, false).content()
+ write::gen(apis, types, opt, false).content()
} else {
Vec::new()
},