mirror of
https://github.com/Sarsoo/csbindgen.git
synced 2024-12-23 06:56:27 +00:00
search used struct in type_alias function parameter
This commit is contained in:
parent
4d900612c8
commit
e6152665d7
9
csbindgen-tests/build.rs
vendored
9
csbindgen-tests/build.rs
vendored
@ -116,5 +116,14 @@ fn main() -> Result<(), Box<dyn Error>> {
|
|||||||
// .csharp_dll_name("libbullet3")
|
// .csharp_dll_name("libbullet3")
|
||||||
// .generate_to_file("src/bullet3_ffi.rs", "../dotnet-sandbox/bullet3_bindgen.cs")?;
|
// .generate_to_file("src/bullet3_ffi.rs", "../dotnet-sandbox/bullet3_bindgen.cs")?;
|
||||||
|
|
||||||
|
|
||||||
|
csbindgen::Builder::new()
|
||||||
|
.input_bindgen_file("src/libpng16.rs")
|
||||||
|
//.method_filter(|x| x.starts_with("png_"))
|
||||||
|
.csharp_namespace("PixivApi.ImageFile")
|
||||||
|
.csharp_class_name("LibPng16")
|
||||||
|
.csharp_dll_name("libpng16")
|
||||||
|
.generate_csharp_file("../dotnet-sandbox/libpng16_csbindgen.cs")?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
7
csbindgen-tests/src/lib.rs
vendored
7
csbindgen-tests/src/lib.rs
vendored
@ -66,6 +66,13 @@ mod lz4_ffi;
|
|||||||
// println!("{:?}", hoge);
|
// println!("{:?}", hoge);
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// #[no_mangle]
|
||||||
|
// pub extern "C" fn string_char(str: char) {
|
||||||
|
// println!("{}", str);
|
||||||
|
// }
|
||||||
|
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
pub struct NfcCard {
|
pub struct NfcCard {
|
||||||
pub delegate: unsafe extern "C" fn(ByteArray) -> ByteArray
|
pub delegate: unsafe extern "C" fn(ByteArray) -> ByteArray
|
||||||
|
4354
csbindgen-tests/src/libpng16.rs
vendored
Normal file
4354
csbindgen-tests/src/libpng16.rs
vendored
Normal file
File diff suppressed because it is too large
Load Diff
@ -1,4 +1,4 @@
|
|||||||
use std::collections::HashMap;
|
use std::{collections::HashMap};
|
||||||
|
|
||||||
use crate::type_meta::{RustType, TypeKind};
|
use crate::type_meta::{RustType, TypeKind};
|
||||||
|
|
||||||
@ -38,12 +38,26 @@ impl AliasMap {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn normalize(&self, name: &String) -> String {
|
pub fn normalize(&self, name: &String) -> (String, Option<RustType>) {
|
||||||
match self.type_aliases.get(name) {
|
match self.type_aliases.get(name) {
|
||||||
Some(x) => self.normalize(&x.type_name),
|
Some(x) => {
|
||||||
None => name.to_owned(),
|
let d = self.normalize_deep(x);
|
||||||
|
(d.type_name.clone(), Some(d))
|
||||||
|
}
|
||||||
|
None => (name.to_owned(), None)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn normalize_deep(&self, name: &RustType) -> RustType {
|
||||||
|
match self.type_aliases.get(&name.type_name) {
|
||||||
|
Some(x) => self.normalize_deep(x),
|
||||||
|
None => name.clone(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn iter(&self) -> std::collections::hash_map::Iter<String, RustType> {
|
||||||
|
self.type_aliases.iter()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
@ -80,10 +94,10 @@ mod test {
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
assert_eq!(map.normalize(&"SSIZE_T".to_string()), "c_longlong");
|
assert_eq!(map.normalize(&"SSIZE_T".to_string()).0, "c_longlong");
|
||||||
assert_eq!(map.normalize(&"SSIZE_T2".to_string()), "c_longlong");
|
assert_eq!(map.normalize(&"SSIZE_T2".to_string()).0, "c_longlong");
|
||||||
assert_eq!(map.normalize(&"c_longlong".to_string()), "c_longlong");
|
assert_eq!(map.normalize(&"c_longlong".to_string()).0, "c_longlong");
|
||||||
assert_eq!(map.normalize(&"c_longlong".to_string()), "c_longlong");
|
assert_eq!(map.normalize(&"c_longlong".to_string()).0, "c_longlong");
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
map.get_mapped_value(&"SSIZE_T".to_string())
|
map.get_mapped_value(&"SSIZE_T".to_string())
|
||||||
|
@ -65,7 +65,7 @@ pub(crate) fn generate(
|
|||||||
let mut field_map = FieldMap::new();
|
let mut field_map = FieldMap::new();
|
||||||
for struct_type in &structs {
|
for struct_type in &structs {
|
||||||
for field in &struct_type.fields {
|
for field in &struct_type.fields {
|
||||||
let struct_type_normalized = aliases.normalize(&struct_type.struct_name);
|
let (struct_type_normalized, _) = aliases.normalize(&struct_type.struct_name);
|
||||||
collect_field_types(
|
collect_field_types(
|
||||||
&mut field_map,
|
&mut field_map,
|
||||||
&aliases,
|
&aliases,
|
||||||
@ -103,8 +103,12 @@ fn collect_using_types(
|
|||||||
collect_using_types(using_types, aliases, &p.rust_type);
|
collect_using_types(using_types, aliases, &p.rust_type);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
let normalized = aliases.normalize(&rust_type.type_name);
|
let (normalized, normalized_rust_type) = aliases.normalize(&rust_type.type_name);
|
||||||
using_types.insert(normalized.clone());
|
if let Some(x) = normalized_rust_type {
|
||||||
|
collect_using_types(using_types, aliases, &x);
|
||||||
|
} else {
|
||||||
|
using_types.insert(normalized.clone());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -124,23 +128,27 @@ fn collect_field_types(
|
|||||||
collect_field_types(field_map, aliases, struct_type_normalized, &p.rust_type);
|
collect_field_types(field_map, aliases, struct_type_normalized, &p.rust_type);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
let normalized = aliases.normalize(&rust_type.type_name);
|
let (normalized, normalized_rust_type) = aliases.normalize(&rust_type.type_name);
|
||||||
field_map.insert(struct_type_normalized, &normalized);
|
if let Some(x) = normalized_rust_type {
|
||||||
|
collect_field_types(field_map, aliases, struct_type_normalized, &x);
|
||||||
|
} else {
|
||||||
|
field_map.insert(struct_type_normalized, &normalized);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// #[test]
|
#[test]
|
||||||
// fn test() {
|
fn test() {
|
||||||
// let path = std::env::current_dir().unwrap();
|
let path = std::env::current_dir().unwrap();
|
||||||
// println!("starting dir: {}", path.display()); // csbindgen/csbindgen
|
println!("starting dir: {}", path.display()); // csbindgen/csbindgen
|
||||||
|
|
||||||
// Builder::new()
|
Builder::new()
|
||||||
// .input_bindgen_file("csbindgen-tests/src/lz4.rs")
|
.input_bindgen_file("csbindgen-tests/src/liblz4.rs")
|
||||||
// .csharp_class_name("LibLz4")
|
.csharp_class_name("LibLz4")
|
||||||
// .csharp_dll_name("csbindgen_tests")
|
.csharp_dll_name("csbindgen_tests")
|
||||||
// .generate_to_file(
|
.generate_to_file(
|
||||||
// "csbindgen-tests/src/lz4_ffi.rs",
|
"csbindgen-tests/src/lz4_ffi.rs",
|
||||||
// "dotnet-sandbox/lz4_bindgen.cs",
|
"dotnet-sandbox/lz4_bindgen.cs",
|
||||||
// )
|
)
|
||||||
// .unwrap();
|
.unwrap();
|
||||||
// }
|
}
|
||||||
|
1090
dotnet-sandbox/libpng16_csbindgen.cs
vendored
Normal file
1090
dotnet-sandbox/libpng16_csbindgen.cs
vendored
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user