-
Notifications
You must be signed in to change notification settings - Fork 531
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Simplify signature parameter handling inside
windows-bindgen
(#3456)
- Loading branch information
Showing
14 changed files
with
325 additions
and
346 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
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,69 @@ | ||
use super::*; | ||
|
||
#[derive(Clone, Debug, PartialEq, Eq)] | ||
pub struct Param { | ||
pub def: MethodParam, | ||
pub ty: Type, | ||
} | ||
|
||
impl std::ops::Deref for Param { | ||
type Target = Type; | ||
|
||
fn deref(&self) -> &Self::Target { | ||
&self.ty | ||
} | ||
} | ||
|
||
impl Param { | ||
pub fn is_convertible(&self) -> bool { | ||
self.is_input() && self.ty.is_convertible() | ||
} | ||
|
||
pub fn is_input(&self) -> bool { | ||
!self.def.flags().contains(ParamAttributes::Out) | ||
} | ||
|
||
pub fn is_optional(&self) -> bool { | ||
self.def.flags().contains(ParamAttributes::Optional) | ||
|| self.def.has_attribute("ReservedAttribute") | ||
} | ||
|
||
pub fn is_retval(&self) -> bool { | ||
if !self.ty.is_pointer() { | ||
return false; | ||
} | ||
|
||
if self.ty.is_void() { | ||
return false; | ||
} | ||
|
||
let flags = self.def.flags(); | ||
|
||
if flags.contains(ParamAttributes::In) | ||
|| !flags.contains(ParamAttributes::Out) | ||
|| flags.contains(ParamAttributes::Optional) | ||
{ | ||
return false; | ||
} | ||
|
||
for attribute in self.def.attributes() { | ||
if matches!( | ||
attribute.name(), | ||
"NativeArrayInfoAttribute" | "MemorySizeAttribute" | ||
) { | ||
return false; | ||
} | ||
} | ||
|
||
// If it's bigger than 128 bits, best to pass as a reference. | ||
if self.ty.deref().size() > 16 { | ||
return false; | ||
} | ||
|
||
true | ||
} | ||
|
||
pub fn write_ident(&self) -> TokenStream { | ||
to_ident(&self.def.name().to_lowercase()) | ||
} | ||
} |
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
6 changes: 3 additions & 3 deletions
6
crates/libs/bindgen/src/tables/param.rs → ...s/libs/bindgen/src/tables/method_param.rs
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
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
Oops, something went wrong.