Skip to content

Commit b95ea83

Browse files
committed
feat: implement for regular functions
1 parent 9176a56 commit b95ea83

File tree

3 files changed

+16
-7
lines changed

3 files changed

+16
-7
lines changed

bindgen/callbacks.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! A public API for more fine-grained customization of bindgen behavior.
22
33
pub use crate::ir::analysis::DeriveTrait;
4-
pub use crate::ir::comp::MethodKind as AttributeMethodKind;
4+
pub use crate::ir::function::FunctionKind;
55
pub use crate::ir::derive::CanDerive as ImplementsTrait;
66
pub use crate::ir::enum_ty::{EnumVariantCustomBehavior, EnumVariantValue};
77
pub use crate::ir::int::IntKind;
@@ -242,7 +242,7 @@ pub struct AttributeInfo<'a> {
242242
/// The kind of the item.
243243
pub kind: AttributeItemKind,
244244
/// The kind of a method item.
245-
pub method_kind: Option<AttributeMethodKind>,
245+
pub fn_kind: Option<FunctionKind>,
246246
}
247247

248248
#[derive(Debug, Clone, Copy, PartialEq, Eq)]

bindgen/codegen/mod.rs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1071,7 +1071,7 @@ impl CodeGenerator for Type {
10711071
cb.add_attributes(&AttributeInfo {
10721072
name: &name,
10731073
kind: AttributeItemKind::Struct,
1074-
method_kind: None,
1074+
fn_kind: None,
10751075
})
10761076
});
10771077
attributes.extend(
@@ -2538,7 +2538,7 @@ impl CodeGenerator for CompInfo {
25382538
} else {
25392539
AttributeItemKind::Struct
25402540
},
2541-
method_kind: None,
2541+
fn_kind: None,
25422542
})
25432543
});
25442544
attributes.extend(custom_attributes.iter().map(|s| s.parse().unwrap()));
@@ -3154,7 +3154,7 @@ impl Method {
31543154
cb.add_attributes(&AttributeInfo {
31553155
name: &canonical_name,
31563156
kind: AttributeItemKind::Function,
3157-
method_kind: Some(self.kind()),
3157+
fn_kind: Some(FunctionKind::Method(self.kind())),
31583158
})
31593159
});
31603160
attrs.extend(custom_attributes.iter().map(|s| s.parse().unwrap()));
@@ -3740,7 +3740,7 @@ impl CodeGenerator for Enum {
37403740
cb.add_attributes(&AttributeInfo {
37413741
name: &name,
37423742
kind: AttributeItemKind::Enum,
3743-
method_kind: None,
3743+
fn_kind: None,
37443744
})
37453745
});
37463746
attrs.extend(custom_attributes.iter().map(|s| s.parse().unwrap()));
@@ -4605,6 +4605,15 @@ impl CodeGenerator for Function {
46054605

46064606
let mut attributes = vec![];
46074607

4608+
let custom_attributes = ctx.options().all_callbacks(|cb| {
4609+
cb.add_attributes(&AttributeInfo {
4610+
name: &canonical_name,
4611+
kind: AttributeItemKind::Function,
4612+
fn_kind: Some(self.kind()),
4613+
})
4614+
});
4615+
attributes.extend(custom_attributes.iter().map(|s| s.parse().unwrap()));
4616+
46084617
if true {
46094618
let must_use = signature.must_use() || {
46104619
let ret_ty = signature

bindgen/ir/function.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const RUST_DERIVE_FUNPTR_LIMIT: usize = 12;
1919

2020
/// What kind of function are we looking at?
2121
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
22-
pub(crate) enum FunctionKind {
22+
pub enum FunctionKind {
2323
/// A plain, free function.
2424
Function,
2525
/// A method of some kind.

0 commit comments

Comments
 (0)