-
Notifications
You must be signed in to change notification settings - Fork 721
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add custom attributes to fn
items
#3088
base: main
Are you sure you want to change the base?
Changes from all commits
7440755
027ee8f
9176a56
b95ea83
8bf98e3
3afa60b
3f811a2
8ce3503
a5add12
133ac06
a2a5359
5268ae4
c2dc13b
c7676f0
eb3f139
9f3c861
5de3677
53a3653
48e7547
94c67b8
0d066fb
5b259ff
c854516
2b9b41b
ea82940
9036b10
875348d
98a4881
c769d52
17dbb68
0920eee
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,9 @@ | |
pub use crate::ir::analysis::DeriveTrait; | ||
pub use crate::ir::derive::CanDerive as ImplementsTrait; | ||
pub use crate::ir::enum_ty::{EnumVariantCustomBehavior, EnumVariantValue}; | ||
pub use crate::ir::function::FunctionKind; | ||
pub use crate::ir::int::IntKind; | ||
use crate::HashSet; | ||
use std::fmt; | ||
|
||
/// An enum to allow ignoring parsing of macros. | ||
|
@@ -133,9 +135,7 @@ pub trait ParseCallbacks: fmt::Debug { | |
/// | ||
/// If no additional attributes are wanted, this function should return an | ||
/// empty `Vec`. | ||
fn add_attributes(&self, _info: &AttributeInfo<'_>) -> Vec<String> { | ||
vec![] | ||
} | ||
fn process_attributes(&self, _info: &AttributeInfo<'_>, _attributes: &mut HashSet<String>) {} | ||
|
||
/// Process a source code comment. | ||
fn process_comment(&self, _comment: &str) -> Option<String> { | ||
|
@@ -231,15 +231,31 @@ pub struct DeriveInfo<'a> { | |
pub kind: TypeKind, | ||
} | ||
|
||
/// Relevant information about a type to which new attributes will be added using | ||
/// Relevant information about an item to which new attributes will be added using | ||
/// [`ParseCallbacks::add_attributes`]. | ||
#[derive(Debug)] | ||
#[non_exhaustive] | ||
pub struct AttributeInfo<'a> { | ||
/// The name of the type. | ||
/// The name of the item. | ||
pub name: &'a str, | ||
/// The kind of the type. | ||
pub kind: TypeKind, | ||
/// The kind of the item. | ||
pub kind: AttributeItemKind, | ||
} | ||
|
||
#[derive(Debug, Clone, Copy, PartialEq, Eq)] | ||
/// The kind of the current item. | ||
pub enum AttributeItemKind { | ||
/// The item is a Rust `struct`. | ||
Struct, | ||
/// The item is a Rust `enum`. | ||
Enum, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is the callback only called on the main enum / struct / union definition, or also for each of the struct fields / enum variants? For example, one might want to feature guard certain struct fields. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Only called on the actual enums I think; they can be implemented in different ways so I think it might be a bit harder to do. We should definitely add more info/context to all Lots of variants in this sentence. |
||
/// The item is a Rust `union`. | ||
Union, | ||
/// The item is a Rust variable. | ||
Var, | ||
/// The item is a Rust `fn`. | ||
Function(FunctionKind), | ||
// TODO: Add `Alias` variant and more information about other items | ||
} | ||
|
||
#[derive(Debug, Clone, Copy, PartialEq, Eq)] | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it be possible to add the doc comment to this struct?
In my case, I would like to feature guard items, based on information provided in doc comments.
In my fork of bindgen I added a custom callback for this purpose, but perhaps I could use this callback in the future.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can already do this on
alias
branch:yields
A few issues I've come up with:
Formatting of attributes is inconsistent. We need to consistently format attributes.I've made a function that normalizes attributes.