aboutsummaryrefslogtreecommitdiff
path: root/ir/item.rs
diff options
context:
space:
mode:
authorMatthew Maurer <mmaurer@google.com>2023-06-28 20:30:28 +0000
committerAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>2023-06-28 20:30:28 +0000
commite9148b61da7ecdf2ee09d44115b281bf96fbb22d (patch)
tree6f1dfe7a9abdae0fdb745e3672420f432b7d4cbe /ir/item.rs
parenta15fc56dc17e5bf7af8c3414dbeaad91b3d40a2b (diff)
parent18b18e49f3ec2e768f68aa4b8dcaf734085b231f (diff)
downloadbindgen-e9148b61da7ecdf2ee09d44115b281bf96fbb22d.tar.gz
Add autocxx support am: 3392e5ce33 am: 18b18e49f3
Original change: https://android-review.googlesource.com/c/platform/external/rust/crates/bindgen/+/2624797 Change-Id: Ia75e7c4f552a85104587147e4b36601d38dcfc4a Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
Diffstat (limited to 'ir/item.rs')
-rw-r--r--ir/item.rs32
1 files changed, 32 insertions, 0 deletions
diff --git a/ir/item.rs b/ir/item.rs
index a50d267..c35b2ac 100644
--- a/ir/item.rs
+++ b/ir/item.rs
@@ -823,6 +823,38 @@ impl Item {
}
}
+ /// Get this item's original C++ name, including any containing types, but without
+ /// the namespace name. For nested types, the C++ name differs from the Rust name, e.g.
+ /// a nested C++ type `A::B` would correspond to the Rust type `A_B`.
+ /// If the item or any of its containing types is anonymous, returns None.
+ pub fn original_name(&self, ctx: &BindgenContext) -> Option<String> {
+ let target = ctx.resolve_item(self.name_target(ctx));
+
+ // Get item and all ancestors until the first enclosing namespace.
+ let ancestors: Vec<_> = target
+ .ancestors(ctx)
+ .map(|id| ctx.resolve_item(id))
+ .take_while(|item| !item.is_module())
+ .collect();
+
+ if ancestors.iter().any(|item| item.is_anon()) {
+ return None;
+ }
+
+ let mut names: Vec<_> = ancestors
+ .iter()
+ .map(|item| {
+ let target = ctx.resolve_item(item.name_target(ctx));
+ target.base_name(ctx)
+ })
+ .filter(|name| !name.is_empty())
+ .collect();
+
+ names.reverse();
+
+ Some(names.join("::"))
+ }
+
/// Get the canonical name without taking into account the replaces
/// annotation.
///