Skip to content

Commit

Permalink
feat: implement for regular functions
Browse files Browse the repository at this point in the history
  • Loading branch information
oberrich committed Jan 11, 2025
1 parent 9176a56 commit b95ea83
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
4 changes: 2 additions & 2 deletions bindgen/callbacks.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! A public API for more fine-grained customization of bindgen behavior.
pub use crate::ir::analysis::DeriveTrait;
pub use crate::ir::comp::MethodKind as AttributeMethodKind;
pub use crate::ir::function::FunctionKind;
pub use crate::ir::derive::CanDerive as ImplementsTrait;
pub use crate::ir::enum_ty::{EnumVariantCustomBehavior, EnumVariantValue};
pub use crate::ir::int::IntKind;
Expand Down Expand Up @@ -242,7 +242,7 @@ pub struct AttributeInfo<'a> {
/// The kind of the item.
pub kind: AttributeItemKind,
/// The kind of a method item.
pub method_kind: Option<AttributeMethodKind>,
pub fn_kind: Option<FunctionKind>,
}

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
Expand Down
17 changes: 13 additions & 4 deletions bindgen/codegen/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1071,7 +1071,7 @@ impl CodeGenerator for Type {
cb.add_attributes(&AttributeInfo {
name: &name,
kind: AttributeItemKind::Struct,
method_kind: None,
fn_kind: None,
})
});
attributes.extend(
Expand Down Expand Up @@ -2538,7 +2538,7 @@ impl CodeGenerator for CompInfo {
} else {
AttributeItemKind::Struct
},
method_kind: None,
fn_kind: None,
})
});
attributes.extend(custom_attributes.iter().map(|s| s.parse().unwrap()));
Expand Down Expand Up @@ -3154,7 +3154,7 @@ impl Method {
cb.add_attributes(&AttributeInfo {
name: &canonical_name,
kind: AttributeItemKind::Function,
method_kind: Some(self.kind()),
fn_kind: Some(FunctionKind::Method(self.kind())),
})
});
attrs.extend(custom_attributes.iter().map(|s| s.parse().unwrap()));
Expand Down Expand Up @@ -3740,7 +3740,7 @@ impl CodeGenerator for Enum {
cb.add_attributes(&AttributeInfo {
name: &name,
kind: AttributeItemKind::Enum,
method_kind: None,
fn_kind: None,
})
});
attrs.extend(custom_attributes.iter().map(|s| s.parse().unwrap()));
Expand Down Expand Up @@ -4605,6 +4605,15 @@ impl CodeGenerator for Function {

let mut attributes = vec![];

let custom_attributes = ctx.options().all_callbacks(|cb| {
cb.add_attributes(&AttributeInfo {
name: &canonical_name,
kind: AttributeItemKind::Function,
fn_kind: Some(self.kind()),
})
});
attributes.extend(custom_attributes.iter().map(|s| s.parse().unwrap()));

if true {
let must_use = signature.must_use() || {
let ret_ty = signature
Expand Down
2 changes: 1 addition & 1 deletion bindgen/ir/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const RUST_DERIVE_FUNPTR_LIMIT: usize = 12;

/// What kind of function are we looking at?
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
pub(crate) enum FunctionKind {
pub enum FunctionKind {
/// A plain, free function.
Function,
/// A method of some kind.
Expand Down

0 comments on commit b95ea83

Please sign in to comment.