-
Notifications
You must be signed in to change notification settings - Fork 743
implement clone on builder #2134
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
Changes from all commits
db7949f
97fed55
576cd0f
001c6b5
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.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,6 +25,7 @@ impl Default for MacroParsingBehavior { | |
|
||
/// A trait to allow configuring different kinds of types in different | ||
/// situations. | ||
#[cfg(not(feature = "builder-clone"))] | ||
pub trait ParseCallbacks: fmt::Debug + UnwindSafe { | ||
/// This function will be run on every macro that is identified. | ||
fn will_parse_macro(&self, _name: &str) -> MacroParsingBehavior { | ||
|
@@ -104,3 +105,92 @@ pub trait ParseCallbacks: fmt::Debug + UnwindSafe { | |
vec![] | ||
} | ||
} | ||
|
||
/// The same trait as above, but clonable so that it can be included as a | ||
/// field in Builder when the builder-clone feature is enabled such that | ||
/// Builder implements Clone. | ||
#[cfg(feature = "builder-clone")] | ||
pub trait ParseCallbacks: | ||
fmt::Debug + UnwindSafe + dyn_clone::DynClone | ||
{ | ||
/// This function will be run on every macro that is identified. | ||
fn will_parse_macro(&self, _name: &str) -> MacroParsingBehavior { | ||
MacroParsingBehavior::Default | ||
} | ||
|
||
/// The integer kind an integer macro should have, given a name and the | ||
/// value of that macro, or `None` if you want the default to be chosen. | ||
fn int_macro(&self, _name: &str, _value: i64) -> Option<IntKind> { | ||
None | ||
} | ||
|
||
/// This will be run on every string macro. The callback cannot influence the further | ||
/// treatment of the macro, but may use the value to generate additional code or configuration. | ||
fn str_macro(&self, _name: &str, _value: &[u8]) {} | ||
|
||
/// This will be run on every function-like macro. The callback cannot | ||
/// influence the further treatment of the macro, but may use the value to | ||
/// generate additional code or configuration. | ||
/// | ||
/// The first parameter represents the name and argument list (including the | ||
/// parentheses) of the function-like macro. The second parameter represents | ||
/// the expansion of the macro as a sequence of tokens. | ||
fn func_macro(&self, _name: &str, _value: &[&[u8]]) {} | ||
|
||
/// This function should return whether, given an enum variant | ||
/// name, and value, this enum variant will forcibly be a constant. | ||
fn enum_variant_behavior( | ||
&self, | ||
_enum_name: Option<&str>, | ||
_original_variant_name: &str, | ||
_variant_value: EnumVariantValue, | ||
) -> Option<EnumVariantCustomBehavior> { | ||
None | ||
} | ||
|
||
/// Allows to rename an enum variant, replacing `_original_variant_name`. | ||
fn enum_variant_name( | ||
&self, | ||
_enum_name: Option<&str>, | ||
_original_variant_name: &str, | ||
_variant_value: EnumVariantValue, | ||
) -> Option<String> { | ||
None | ||
} | ||
|
||
/// Allows to rename an item, replacing `_original_item_name`. | ||
fn item_name(&self, _original_item_name: &str) -> Option<String> { | ||
None | ||
} | ||
|
||
/// This will be called on every file inclusion, with the full path of the included file. | ||
fn include_file(&self, _filename: &str) {} | ||
|
||
/// This will be called to determine whether a particular blocklisted type | ||
/// implements a trait or not. This will be used to implement traits on | ||
/// other types containing the blocklisted type. | ||
/// | ||
/// * `None`: use the default behavior | ||
/// * `Some(ImplementsTrait::Yes)`: `_name` implements `_derive_trait` | ||
/// * `Some(ImplementsTrait::Manually)`: any type including `_name` can't | ||
/// derive `_derive_trait` but can implemented it manually | ||
/// * `Some(ImplementsTrait::No)`: `_name` doesn't implement `_derive_trait` | ||
fn blocklisted_type_implements_trait( | ||
&self, | ||
_name: &str, | ||
_derive_trait: DeriveTrait, | ||
) -> Option<ImplementsTrait> { | ||
None | ||
} | ||
|
||
/// Provide a list of custom derive attributes. | ||
/// | ||
/// If no additional attributes are wanted, this function should return an | ||
/// empty `Vec`. | ||
fn add_derives(&self, _name: &str) -> Vec<String> { | ||
vec![] | ||
} | ||
} | ||
|
||
#[cfg(feature = "builder-clone")] | ||
dyn_clone::clone_trait_object!(ParseCallbacks); | ||
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. Can you elaborate on why this is needed instead of just having |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1687,6 +1687,7 @@ impl Drop for Diagnostic { | |
} | ||
|
||
/// A file which has not been saved to disk. | ||
#[derive(Clone)] | ||
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. This is not safe. |
||
pub struct UnsavedFile { | ||
x: CXUnsavedFile, | ||
/// The name of the unsaved file. Kept here to avoid leaving dangling pointers in | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
use bindgen::callbacks::*; | ||
|
||
#[derive(Debug)] | ||
#[derive(Clone, Debug)] | ||
struct EnumVariantRename; | ||
|
||
impl ParseCallbacks for EnumVariantRename { | ||
|
@@ -14,7 +14,7 @@ impl ParseCallbacks for EnumVariantRename { | |
} | ||
} | ||
|
||
#[derive(Debug)] | ||
#[derive(Clone, Debug)] | ||
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. Why is this needed? |
||
struct BlocklistedTypeImplementsTrait; | ||
|
||
impl ParseCallbacks for BlocklistedTypeImplementsTrait { | ||
|
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.
It is really unfortunate to duplicate all the trait here. Can we avoid this by using a macro instead?