Skip to content
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

Simpler code generation #3370

Merged
merged 2 commits into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 0 additions & 12 deletions crates/libs/bindgen/src/types/cpp_fn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,18 +228,6 @@ impl CppFn {
}
}
}
ReturnHint::ReturnVoid => {
let where_clause = method.write_where(writer, false);

quote! {
#cfg
#[inline]
pub unsafe fn #name<#generics>(#params) #abi_return_type #where_clause {
#link
#name(#args)
}
}
}
};

quote! {
Expand Down
18 changes: 2 additions & 16 deletions crates/libs/bindgen/src/types/cpp_method.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ pub enum ReturnHint {
ResultVoid,
ReturnStruct,
ReturnValue,
ReturnVoid,
}

#[derive(Copy, Clone, PartialEq, Debug)]
Expand Down Expand Up @@ -187,12 +186,9 @@ impl CppMethod {
false
};

// TODO: ignore this attribute and just return HRESULT/BOOL/NTSTATUS/whatever and let the caller user `.ok()` if
// they want to treat it as a Result with a single success value.
if !def.has_attribute("CanReturnMultipleSuccessValuesAttribute") {
match &signature.return_type.0 {
Type::Void if is_retval => return_hint = ReturnHint::ReturnValue,
Type::Void => return_hint = ReturnHint::ReturnVoid,
Type::HRESULT => {
if is_retval {
return_hint = ReturnHint::ResultValue
Expand Down Expand Up @@ -283,6 +279,7 @@ impl CppMethod {
let args = self.write_args();
let params = self.write_params(writer);
let generics = self.write_generics();
let abi_return_type = self.write_return(writer);

match self.return_hint {
ReturnHint::Query(..) => {
Expand Down Expand Up @@ -386,24 +383,14 @@ impl CppMethod {
}
}
ReturnHint::None => {
let return_type = self.signature.return_type.0.write_default(writer);
let where_clause = self.write_where(writer, false);

quote! {
pub unsafe fn #name<#generics>(&self, #params) -> #return_type #where_clause {
pub unsafe fn #name<#generics>(&self, #params) #abi_return_type #where_clause {
(windows_core::Interface::vtable(self).#vname)(windows_core::Interface::as_raw(self), #args)
}
}
}
ReturnHint::ReturnVoid => {
let where_clause = self.write_where(writer, false);

quote! {
pub unsafe fn #name<#generics>(&self, #params) #where_clause {
(windows_core::Interface::vtable(self).#vname)(windows_core::Interface::as_raw(self),#args)
}
}
}
}
}

Expand Down Expand Up @@ -494,7 +481,6 @@ impl CppMethod {
}

let return_type = match self.return_hint {
ReturnHint::ReturnVoid => quote! {},
ReturnHint::Query(..) | ReturnHint::QueryOptional(..) | ReturnHint::ResultVoid => {
quote! { -> windows_core::Result<()> }
}
Expand Down
19 changes: 0 additions & 19 deletions crates/libs/bindgen/src/types/cpp_struct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,24 +146,6 @@ impl CppStruct {
derive.extend(["Debug", "PartialEq"]);
}

let type_kind = if writer.config.sys {
quote! {}
} else if is_copyable {
quote! {
#cfg
impl windows_core::TypeKind for #name {
type TypeKind = windows_core::CopyType;
}
}
} else {
quote! {
#cfg
impl windows_core::TypeKind for #name {
type TypeKind = windows_core::CloneType;
}
}
};

let default = if writer.config.sys {
quote! {}
} else {
Expand Down Expand Up @@ -230,7 +212,6 @@ impl CppStruct {
#constants
#manual_clone
#default
#type_kind
};

for nested in self.nested.values() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,6 @@ impl Default for HID_XFER_PACKET {
unsafe { core::mem::zeroed() }
}
}
impl windows_core::TypeKind for HID_XFER_PACKET {
type TypeKind = windows_core::CopyType;
}
#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct VHF_CONFIG {
Expand Down Expand Up @@ -73,6 +70,3 @@ impl Default for VHF_CONFIG {
unsafe { core::mem::zeroed() }
}
}
impl windows_core::TypeKind for VHF_CONFIG {
type TypeKind = windows_core::CopyType;
}
Loading
Loading