mirror of
https://github.com/Sarsoo/csbindgen.git
synced 2024-12-23 06:56:27 +00:00
WIP fix pointer pointer
This commit is contained in:
parent
6f2617f40f
commit
5f1207ae20
31
csbindgen-tests/build.rs
vendored
31
csbindgen-tests/build.rs
vendored
@ -31,14 +31,14 @@ fn main() -> Result<(), Box<dyn Error>> {
|
|||||||
// .generate()?
|
// .generate()?
|
||||||
// .write_to_file("src/quiche.rs")?;
|
// .write_to_file("src/quiche.rs")?;
|
||||||
|
|
||||||
// bindgen::Builder::default()
|
bindgen::Builder::default()
|
||||||
// .header("c/bullet3/PhysicsClientC_API.h")
|
.header("c/bullet3/PhysicsClientC_API.h")
|
||||||
// .header("c/bullet3/PhysicsClientSharedMemory_C_API.h")
|
.header("c/bullet3/PhysicsClientSharedMemory_C_API.h")
|
||||||
// .header("c/bullet3/PhysicsClientSharedMemory2_C_API.h")
|
.header("c/bullet3/PhysicsClientSharedMemory2_C_API.h")
|
||||||
// .header("c/bullet3/PhysicsDirectC_API.h")
|
.header("c/bullet3/PhysicsDirectC_API.h")
|
||||||
// .header("c/bullet3/SharedMemoryPublic.h")
|
.header("c/bullet3/SharedMemoryPublic.h")
|
||||||
// .generate()?
|
.generate()?
|
||||||
// .write_to_file("src/bullet3.rs")?;
|
.write_to_file("src/bullet3.rs")?;
|
||||||
|
|
||||||
csbindgen::Builder::default()
|
csbindgen::Builder::default()
|
||||||
.input_bindgen_file("src/lz4.rs")
|
.input_bindgen_file("src/lz4.rs")
|
||||||
@ -83,13 +83,14 @@ fn main() -> Result<(), Box<dyn Error>> {
|
|||||||
// .csharp_dll_name("libquiche")
|
// .csharp_dll_name("libquiche")
|
||||||
// .generate_to_file("src/quiche_ffi.rs", "../dotnet-sandbox/quiche_bindgen.cs")?;
|
// .generate_to_file("src/quiche_ffi.rs", "../dotnet-sandbox/quiche_bindgen.cs")?;
|
||||||
|
|
||||||
// csbindgen::Builder::new()
|
csbindgen::Builder::new()
|
||||||
// .input_bindgen_file("src/bullet3.rs")
|
.input_bindgen_file("src/bullet3.rs")
|
||||||
// .method_filter(|x| x.starts_with("b3"))
|
.method_filter(|x| x.starts_with("b3"))
|
||||||
// .rust_method_prefix("csbindgen_bullet3_")
|
.rust_method_prefix("csbindgen_bullet3_")
|
||||||
// .csharp_class_name("LibBullet3")
|
.csharp_entry_point_prefix("csbindgen_bullet3_")
|
||||||
// .csharp_dll_name("libbullet3")
|
.csharp_class_name("LibBullet3")
|
||||||
// .generate_to_file("src/bullet3_ffi.rs", "../dotnet-sandbox/bullet3_bindgen.cs")?;
|
.csharp_dll_name("libbullet3")
|
||||||
|
.generate_to_file("src/bullet3_ffi.rs", "../dotnet-sandbox/bullet3_bindgen.cs")?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -258,8 +258,7 @@ pub fn reduce_enum(
|
|||||||
fn parse_type(t: &syn::Type) -> RustType {
|
fn parse_type(t: &syn::Type) -> RustType {
|
||||||
match t {
|
match t {
|
||||||
syn::Type::Ptr(t) => {
|
syn::Type::Ptr(t) => {
|
||||||
let has_const = t.const_token.is_some();
|
let has_const = t.const_token.is_some(); // not is has_mut
|
||||||
// let has_mut = t.mutability.is_some();
|
|
||||||
|
|
||||||
if let syn::Type::Path(path) = &*t.elem {
|
if let syn::Type::Path(path) = &*t.elem {
|
||||||
return RustType {
|
return RustType {
|
||||||
@ -272,13 +271,18 @@ fn parse_type(t: &syn::Type) -> RustType {
|
|||||||
};
|
};
|
||||||
} else if let syn::Type::Ptr(t) = &*t.elem {
|
} else if let syn::Type::Ptr(t) = &*t.elem {
|
||||||
if let syn::Type::Path(path) = &*t.elem {
|
if let syn::Type::Path(path) = &*t.elem {
|
||||||
|
let has_const2 = t.const_token.is_some();
|
||||||
|
|
||||||
|
let pointer_type = match (has_const, has_const2) {
|
||||||
|
(true, true) => PointerType::ConstPointerPointer,
|
||||||
|
(true, false) => PointerType::ConstMutPointerPointer,
|
||||||
|
(false, true) => PointerType::MutConstPointerPointer,
|
||||||
|
(false, false) => PointerType::MutPointerPointer,
|
||||||
|
};
|
||||||
|
|
||||||
return RustType {
|
return RustType {
|
||||||
type_name: path.path.segments.last().unwrap().ident.to_string(),
|
type_name: path.path.segments.last().unwrap().ident.to_string(),
|
||||||
type_kind: TypeKind::Pointer(if has_const {
|
type_kind: TypeKind::Pointer(pointer_type),
|
||||||
PointerType::ConstPointerPointer
|
|
||||||
} else {
|
|
||||||
PointerType::MutPointerPointer
|
|
||||||
}),
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -77,6 +77,8 @@ pub enum PointerType {
|
|||||||
MutPointer,
|
MutPointer,
|
||||||
ConstPointerPointer,
|
ConstPointerPointer,
|
||||||
MutPointerPointer,
|
MutPointerPointer,
|
||||||
|
ConstMutPointerPointer,
|
||||||
|
MutConstPointerPointer
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
@ -103,6 +105,8 @@ impl RustType {
|
|||||||
MutPointer => sb.push_str("*mut"),
|
MutPointer => sb.push_str("*mut"),
|
||||||
ConstPointerPointer => sb.push_str("*const *const"),
|
ConstPointerPointer => sb.push_str("*const *const"),
|
||||||
MutPointerPointer => sb.push_str("*mut *mut"),
|
MutPointerPointer => sb.push_str("*mut *mut"),
|
||||||
|
ConstMutPointerPointer =>sb.push_str("*const *mut"),
|
||||||
|
MutConstPointerPointer =>sb.push_str("*mut *mut"),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -305,12 +309,13 @@ impl RustType {
|
|||||||
sb.push_str(convert_type_name(use_type.type_name.as_str()));
|
sb.push_str(convert_type_name(use_type.type_name.as_str()));
|
||||||
|
|
||||||
if use_alias {
|
if use_alias {
|
||||||
|
use PointerType::*;
|
||||||
if let TypeKind::Pointer(p) = &use_type.type_kind {
|
if let TypeKind::Pointer(p) = &use_type.type_kind {
|
||||||
match p {
|
match p {
|
||||||
PointerType::MutPointer | PointerType::ConstPointer => {
|
MutPointer | ConstPointer => {
|
||||||
sb.push('*');
|
sb.push('*');
|
||||||
}
|
}
|
||||||
PointerType::MutPointerPointer | PointerType::ConstPointerPointer => {
|
MutPointerPointer | ConstPointerPointer | MutConstPointerPointer | ConstMutPointerPointer => {
|
||||||
sb.push_str("**");
|
sb.push_str("**");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -318,11 +323,12 @@ impl RustType {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if let TypeKind::Pointer(p) = &self.type_kind {
|
if let TypeKind::Pointer(p) = &self.type_kind {
|
||||||
|
use PointerType::*;
|
||||||
match p {
|
match p {
|
||||||
PointerType::MutPointer | PointerType::ConstPointer => {
|
MutPointer | ConstPointer => {
|
||||||
sb.push('*');
|
sb.push('*');
|
||||||
}
|
}
|
||||||
PointerType::MutPointerPointer | PointerType::ConstPointerPointer => {
|
MutPointerPointer | ConstPointerPointer | MutConstPointerPointer | ConstMutPointerPointer => {
|
||||||
sb.push_str("**");
|
sb.push_str("**");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
878
dotnet-sandbox/bullet3_bindgen.cs
vendored
878
dotnet-sandbox/bullet3_bindgen.cs
vendored
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user