Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
178 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
8 changes: 8 additions & 0 deletions
8
bindgen-tests/tests/expectations/tests/remove_template_alias.rs
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// bindgen-flags: --remove-alias "int.*" | ||
|
||
typedef long long int64; | ||
typedef int int32; | ||
typedef int32 i32; | ||
|
||
struct int32_ { | ||
int32 inner; | ||
}; | ||
|
||
int64 foo(); | ||
int32 bar(); | ||
i32 baz(); | ||
struct int32_ qux(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
// bindgen-flags: --remove-alias "Wrapped" | ||
|
||
template<typename T> | ||
using Wrapped = T; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
use syn::visit_mut::{visit_type_mut, VisitMut}; | ||
use syn::{Item, Type}; | ||
|
||
use crate::BindgenOptions; | ||
|
||
pub(super) fn remove_alias(items: &mut Vec<Item>, options: &BindgenOptions) { | ||
let visitors: Vec<_> = items | ||
.iter() | ||
.enumerate() | ||
.rev() | ||
.filter_map(|(index, item)| { | ||
if let Item::Type(alias_item) = item { | ||
if alias_item.generics.params.is_empty() { | ||
let ident = alias_item.ident.to_string(); | ||
if options.remove_alias.matches(&ident) { | ||
return Some(( | ||
index, | ||
Visitor { | ||
ident, | ||
ty: alias_item.ty.clone(), | ||
}, | ||
)); | ||
} | ||
} | ||
} | ||
None | ||
}) | ||
.collect(); | ||
|
||
for (index, mut visitor) in visitors { | ||
items.remove(index); | ||
for item in items.iter_mut() { | ||
visitor.visit_item_mut(item); | ||
} | ||
} | ||
} | ||
|
||
struct Visitor { | ||
ident: String, | ||
ty: Box<Type>, | ||
} | ||
|
||
impl VisitMut for Visitor { | ||
fn visit_type_mut(&mut self, ty: &mut Type) { | ||
if let Type::Path(type_path) = ty { | ||
if type_path.path.is_ident(&self.ident) { | ||
*ty = self.ty.as_ref().clone(); | ||
} | ||
} | ||
|
||
visit_type_mut::<_>(self, ty) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters