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/syntax/ident.rs b/syntax/ident.rs
index 66f7365..354790a 100644
--- a/syntax/ident.rs
+++ b/syntax/ident.rs
@@ -1,6 +1,5 @@
use crate::syntax::check::Check;
-use crate::syntax::namespace::Namespace;
-use crate::syntax::{error, Api};
+use crate::syntax::{error, Api, CppName};
use proc_macro2::Ident;
fn check(cx: &mut Check, ident: &Ident) {
@@ -13,28 +12,31 @@
}
}
-pub(crate) fn check_all(cx: &mut Check, namespace: &Namespace, apis: &[Api]) {
- for segment in namespace {
+fn check_ident(cx: &mut Check, ident: &CppName) {
+ for segment in &ident.ns {
check(cx, segment);
}
+ check(cx, &ident.ident);
+}
+pub(crate) fn check_all(cx: &mut Check, apis: &[Api]) {
for api in apis {
match api {
Api::Include(_) | Api::Impl(_) => {}
Api::Struct(strct) => {
- check(cx, &strct.ident);
+ check_ident(cx, &strct.ident.cxx);
for field in &strct.fields {
check(cx, &field.ident);
}
}
Api::Enum(enm) => {
- check(cx, &enm.ident);
+ check_ident(cx, &enm.ident.cxx);
for variant in &enm.variants {
check(cx, &variant.ident);
}
}
Api::CxxType(ety) | Api::RustType(ety) => {
- check(cx, &ety.ident);
+ check_ident(cx, &ety.ident.cxx);
}
Api::CxxFunction(efn) | Api::RustFunction(efn) => {
check(cx, &efn.ident.rust);
@@ -43,7 +45,7 @@
}
}
Api::TypeAlias(alias) => {
- check(cx, &alias.ident);
+ check_ident(cx, &alias.ident.cxx);
}
}
}