Implement basic support for namespaces
Next steps are:
* use qualified paths where needed
* create a single detail module per crate; this requires access to qualified paths.
* add support for reopened namespaces within the same C++ library
* add support for reopened namespaces across C++ libraries
PiperOrigin-RevId: 441183150
diff --git a/rs_bindings_from_cc/ir.rs b/rs_bindings_from_cc/ir.rs
index 0ccdebc..1a59edb 100644
--- a/rs_bindings_from_cc/ir.rs
+++ b/rs_bindings_from_cc/ir.rs
@@ -451,6 +451,14 @@
}
#[derive(Debug, PartialEq, Eq, Hash, Clone, Deserialize)]
+pub struct Namespace {
+ pub name: Identifier,
+ pub id: ItemId,
+ #[serde(default)]
+ pub child_item_ids: Vec<ItemId>,
+}
+
+#[derive(Debug, PartialEq, Eq, Hash, Clone, Deserialize)]
pub enum Item {
Func(Func),
Record(Record),
@@ -458,6 +466,7 @@
TypeAlias(TypeAlias),
UnsupportedItem(UnsupportedItem),
Comment(Comment),
+ Namespace(Namespace),
}
impl Item {
@@ -469,6 +478,7 @@
Item::Enum(enum_) => enum_.id,
Item::UnsupportedItem(unsupported) => unsupported.id,
Item::Comment(comment) => comment.id,
+ Item::Namespace(namespace) => namespace.id,
}
}
}
@@ -609,6 +619,13 @@
})
}
+ pub fn namespaces(&self) -> impl Iterator<Item = &Namespace> {
+ self.items().filter_map(|item| match item {
+ Item::Namespace(ns) => Some(ns),
+ _ => None,
+ })
+ }
+
pub fn item_for_type<T>(&self, ty: &T) -> Result<&Item>
where
T: TypeWithDeclId + std::fmt::Debug,