Skip to content

Commit

Permalink
Make mangled name available to generated_xxx_override callbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
Molot2032 committed Feb 2, 2025
1 parent 979b581 commit cb823bc
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
2 changes: 2 additions & 0 deletions bindgen/callbacks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,8 @@ pub enum TypeKind {
pub struct ItemInfo<'a> {
/// The name of the item
pub name: &'a str,
/// The mangled name of the item, if available
pub mangled_name: Option<&'a str>,
/// The kind of item
pub kind: ItemKind,
}
Expand Down
7 changes: 4 additions & 3 deletions bindgen/ir/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -784,26 +784,27 @@ impl ClangSubItemParser for Function {
// but seems easy enough to handle it here.
name.push_str("_destructor");
}
let mangled_name = cursor_mangling(context, &cursor);

let link_name = context.options().last_callback(|callbacks| {
callbacks.generated_link_name_override(ItemInfo {
name: name.as_str(),
mangled_name: mangled_name.as_deref(),
kind: ItemKind::Function,
})
});

if let Some(nm) = context.options().last_callback(|callbacks| {
callbacks.generated_name_override(ItemInfo {
name: name.as_str(),
mangled_name: mangled_name.as_deref(),
kind: ItemKind::Function,
})
}) {
name = nm;
}
assert!(!name.is_empty(), "Empty function name.");

let mangled_name = cursor_mangling(context, &cursor);

let function = Self::new(
name.clone(),
mangled_name,
Expand Down
4 changes: 3 additions & 1 deletion bindgen/ir/var.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,10 +271,12 @@ impl ClangSubItemParser for Var {
}
CXCursor_VarDecl => {
let mut name = cursor.spelling();
let mangling = cursor_mangling(ctx, &cursor);

let link_name = ctx.options().last_callback(|callbacks| {
callbacks.generated_link_name_override(ItemInfo {
name: name.as_str(),
mangled_name: mangling.as_deref(),
kind: ItemKind::Var,
})
});
Expand All @@ -283,6 +285,7 @@ impl ClangSubItemParser for Var {
if let Some(nm) = ctx.options().last_callback(|callbacks| {
callbacks.generated_name_override(ItemInfo {
name: name.as_str(),
mangled_name: mangling.as_deref(),
kind: ItemKind::Var,
})
}) {
Expand Down Expand Up @@ -365,7 +368,6 @@ impl ClangSubItemParser for Var {
.map(VarType::String)
};

let mangling = cursor_mangling(ctx, &cursor);
let var =
Var::new(name, mangling, link_name, ty, value, is_const);

Expand Down

0 comments on commit cb823bc

Please sign in to comment.