WIP fix pointer pointer

This commit is contained in:
neuecc 2023-03-07 18:07:41 +09:00
parent 6f2617f40f
commit 5f1207ae20
4 changed files with 476 additions and 465 deletions

View File

@ -31,14 +31,14 @@ fn main() -> Result<(), Box<dyn Error>> {
// .generate()?
// .write_to_file("src/quiche.rs")?;
// bindgen::Builder::default()
// .header("c/bullet3/PhysicsClientC_API.h")
// .header("c/bullet3/PhysicsClientSharedMemory_C_API.h")
// .header("c/bullet3/PhysicsClientSharedMemory2_C_API.h")
// .header("c/bullet3/PhysicsDirectC_API.h")
// .header("c/bullet3/SharedMemoryPublic.h")
// .generate()?
// .write_to_file("src/bullet3.rs")?;
bindgen::Builder::default()
.header("c/bullet3/PhysicsClientC_API.h")
.header("c/bullet3/PhysicsClientSharedMemory_C_API.h")
.header("c/bullet3/PhysicsClientSharedMemory2_C_API.h")
.header("c/bullet3/PhysicsDirectC_API.h")
.header("c/bullet3/SharedMemoryPublic.h")
.generate()?
.write_to_file("src/bullet3.rs")?;
csbindgen::Builder::default()
.input_bindgen_file("src/lz4.rs")
@ -83,13 +83,14 @@ fn main() -> Result<(), Box<dyn Error>> {
// .csharp_dll_name("libquiche")
// .generate_to_file("src/quiche_ffi.rs", "../dotnet-sandbox/quiche_bindgen.cs")?;
// csbindgen::Builder::new()
// .input_bindgen_file("src/bullet3.rs")
// .method_filter(|x| x.starts_with("b3"))
// .rust_method_prefix("csbindgen_bullet3_")
// .csharp_class_name("LibBullet3")
// .csharp_dll_name("libbullet3")
// .generate_to_file("src/bullet3_ffi.rs", "../dotnet-sandbox/bullet3_bindgen.cs")?;
csbindgen::Builder::new()
.input_bindgen_file("src/bullet3.rs")
.method_filter(|x| x.starts_with("b3"))
.rust_method_prefix("csbindgen_bullet3_")
.csharp_entry_point_prefix("csbindgen_bullet3_")
.csharp_class_name("LibBullet3")
.csharp_dll_name("libbullet3")
.generate_to_file("src/bullet3_ffi.rs", "../dotnet-sandbox/bullet3_bindgen.cs")?;
Ok(())
}

View File

@ -258,8 +258,7 @@ pub fn reduce_enum(
fn parse_type(t: &syn::Type) -> RustType {
match t {
syn::Type::Ptr(t) => {
let has_const = t.const_token.is_some();
// let has_mut = t.mutability.is_some();
let has_const = t.const_token.is_some(); // not is has_mut
if let syn::Type::Path(path) = &*t.elem {
return RustType {
@ -272,13 +271,18 @@ fn parse_type(t: &syn::Type) -> RustType {
};
} else if let syn::Type::Ptr(t) = &*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 {
type_name: path.path.segments.last().unwrap().ident.to_string(),
type_kind: TypeKind::Pointer(if has_const {
PointerType::ConstPointerPointer
} else {
PointerType::MutPointerPointer
}),
type_kind: TypeKind::Pointer(pointer_type),
};
}
}

View File

@ -77,6 +77,8 @@ pub enum PointerType {
MutPointer,
ConstPointerPointer,
MutPointerPointer,
ConstMutPointerPointer,
MutConstPointerPointer
}
#[derive(Clone, Debug)]
@ -103,6 +105,8 @@ impl RustType {
MutPointer => sb.push_str("*mut"),
ConstPointerPointer => sb.push_str("*const *const"),
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()));
if use_alias {
use PointerType::*;
if let TypeKind::Pointer(p) = &use_type.type_kind {
match p {
PointerType::MutPointer | PointerType::ConstPointer => {
MutPointer | ConstPointer => {
sb.push('*');
}
PointerType::MutPointerPointer | PointerType::ConstPointerPointer => {
MutPointerPointer | ConstPointerPointer | MutConstPointerPointer | ConstMutPointerPointer => {
sb.push_str("**");
}
}
@ -318,11 +323,12 @@ impl RustType {
}
if let TypeKind::Pointer(p) = &self.type_kind {
use PointerType::*;
match p {
PointerType::MutPointer | PointerType::ConstPointer => {
MutPointer | ConstPointer => {
sb.push('*');
}
PointerType::MutPointerPointer | PointerType::ConstPointerPointer => {
MutPointerPointer | ConstPointerPointer | MutConstPointerPointer | ConstMutPointerPointer => {
sb.push_str("**");
}
}

File diff suppressed because it is too large Load Diff