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

Add initial riddle support for methods and parameters #2554

Merged
merged 8 commits into from
Jun 27, 2023
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
5 changes: 3 additions & 2 deletions crates/libs/metadata/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,7 @@ impl<'a> Reader<'a> {
pub fn field_is_const(&self, row: Field) -> bool {
self.field_attributes(row).any(|attribute| self.attribute_name(attribute) == "ConstAttribute")
}
// TODO: enclosing craziness is only needed for nested structs - get rid of those in metadata vnext and this goes away.
pub fn field_type(&self, row: Field, enclosing: Option<TypeDef>) -> Type {
let mut blob = self.row_blob(row.0, 2);
blob.read_usize();
Expand Down Expand Up @@ -880,8 +881,8 @@ impl<'a> Reader<'a> {
pub fn type_def_attributes(&self, row: TypeDef) -> impl Iterator<Item = Attribute> {
self.row_attributes(row.0, HasAttribute::TypeDef(row))
}
pub fn type_def_generics(&self, row: TypeDef) -> impl Iterator<Item = Type> {
self.row_equal_range(row.0, TABLE_GENERICPARAM, 2, TypeOrMethodDef::TypeDef(row).encode()).map(|row| Type::GenericParam(GenericParam(row)))
pub fn type_def_generics(&self, row: TypeDef) -> Vec<Type> {
self.row_equal_range(row.0, TABLE_GENERICPARAM, 2, TypeOrMethodDef::TypeDef(row).encode()).map(|row| Type::GenericParam(GenericParam(row))).collect()
}
pub fn type_def_interface_impls(&self, row: TypeDef) -> impl Iterator<Item = InterfaceImpl> {
self.row_equal_range(row.0, TABLE_INTERFACEIMPL, 0, (row.0.row + 1) as _).map(InterfaceImpl)
Expand Down
Binary file modified crates/targets/aarch64_msvc/lib/windows.0.48.0.lib
Binary file not shown.
Binary file modified crates/targets/i686_msvc/lib/windows.0.48.0.lib
Binary file not shown.
Binary file modified crates/targets/x86_64_msvc/lib/windows.0.48.0.lib
Binary file not shown.
1 change: 1 addition & 0 deletions crates/tests/riddle/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
mod nested_struct;
mod params;
mod r#struct;

use std::process::Command;
Expand Down
307 changes: 307 additions & 0 deletions crates/tests/riddle/src/params.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,307 @@
// Bindings generated by `riddle` 0.0.1

#![allow(
non_snake_case,
non_upper_case_globals,
non_camel_case_types,
dead_code,
clippy::all
)]
#[repr(transparent)]
pub struct IParams(::windows_core::IUnknown);
impl IParams {
pub fn Nothing(&self) -> ::windows_core::Result<()> {
let this = self;
unsafe {
(::windows_core::Interface::vtable(this).Nothing)(::windows_core::Interface::as_raw(
this,
))
.ok()
}
}
pub fn Bool(&self, a: &mut bool, b: &mut bool) -> ::windows_core::Result<bool> {
let this = self;
unsafe {
let mut result__ = ::std::mem::zeroed();
(::windows_core::Interface::vtable(this).Bool)(
::windows_core::Interface::as_raw(this),
a,
b,
&mut result__,
)
.from_abi(result__)
}
}
pub fn I8(&self, a: &mut i8, b: &mut i8) -> ::windows_core::Result<i8> {
let this = self;
unsafe {
let mut result__ = ::std::mem::zeroed();
(::windows_core::Interface::vtable(this).I8)(
::windows_core::Interface::as_raw(this),
a,
b,
&mut result__,
)
.from_abi(result__)
}
}
pub fn U8(&self, a: &mut u8, b: &mut u8) -> ::windows_core::Result<u8> {
let this = self;
unsafe {
let mut result__ = ::std::mem::zeroed();
(::windows_core::Interface::vtable(this).U8)(
::windows_core::Interface::as_raw(this),
a,
b,
&mut result__,
)
.from_abi(result__)
}
}
pub fn I16(&self, a: &mut i16, b: &mut i16) -> ::windows_core::Result<i16> {
let this = self;
unsafe {
let mut result__ = ::std::mem::zeroed();
(::windows_core::Interface::vtable(this).I16)(
::windows_core::Interface::as_raw(this),
a,
b,
&mut result__,
)
.from_abi(result__)
}
}
pub fn U16(&self, a: &mut u16, b: &mut u16) -> ::windows_core::Result<u16> {
let this = self;
unsafe {
let mut result__ = ::std::mem::zeroed();
(::windows_core::Interface::vtable(this).U16)(
::windows_core::Interface::as_raw(this),
a,
b,
&mut result__,
)
.from_abi(result__)
}
}
pub fn I32(&self, a: &mut i32, b: &mut i32) -> ::windows_core::Result<i32> {
let this = self;
unsafe {
let mut result__ = ::std::mem::zeroed();
(::windows_core::Interface::vtable(this).I32)(
::windows_core::Interface::as_raw(this),
a,
b,
&mut result__,
)
.from_abi(result__)
}
}
pub fn U32(&self, a: &mut u32, b: &mut u32) -> ::windows_core::Result<u32> {
let this = self;
unsafe {
let mut result__ = ::std::mem::zeroed();
(::windows_core::Interface::vtable(this).U32)(
::windows_core::Interface::as_raw(this),
a,
b,
&mut result__,
)
.from_abi(result__)
}
}
pub fn I64(&self, a: &mut i64, b: &mut i64) -> ::windows_core::Result<i64> {
let this = self;
unsafe {
let mut result__ = ::std::mem::zeroed();
(::windows_core::Interface::vtable(this).I64)(
::windows_core::Interface::as_raw(this),
a,
b,
&mut result__,
)
.from_abi(result__)
}
}
pub fn U64(&self, a: &mut u64, b: &mut u64) -> ::windows_core::Result<u64> {
let this = self;
unsafe {
let mut result__ = ::std::mem::zeroed();
(::windows_core::Interface::vtable(this).U64)(
::windows_core::Interface::as_raw(this),
a,
b,
&mut result__,
)
.from_abi(result__)
}
}
pub fn F32(&self, a: &mut f32, b: &mut f32) -> ::windows_core::Result<f32> {
let this = self;
unsafe {
let mut result__ = ::std::mem::zeroed();
(::windows_core::Interface::vtable(this).F32)(
::windows_core::Interface::as_raw(this),
a,
b,
&mut result__,
)
.from_abi(result__)
}
}
pub fn F64(&self, a: &mut f64, b: &mut f64) -> ::windows_core::Result<f64> {
let this = self;
unsafe {
let mut result__ = ::std::mem::zeroed();
(::windows_core::Interface::vtable(this).F64)(
::windows_core::Interface::as_raw(this),
a,
b,
&mut result__,
)
.from_abi(result__)
}
}
pub fn ISize(&self, a: &mut isize, b: &mut isize) -> ::windows_core::Result<isize> {
let this = self;
unsafe {
let mut result__ = ::std::mem::zeroed();
(::windows_core::Interface::vtable(this).ISize)(
::windows_core::Interface::as_raw(this),
a,
b,
&mut result__,
)
.from_abi(result__)
}
}
pub fn USize(&self, a: &mut usize, b: &mut usize) -> ::windows_core::Result<usize> {
let this = self;
unsafe {
let mut result__ = ::std::mem::zeroed();
(::windows_core::Interface::vtable(this).USize)(
::windows_core::Interface::as_raw(this),
a,
b,
&mut result__,
)
.from_abi(result__)
}
}
}
::windows_core::imp::interface_hierarchy!(
IParams,
::windows_core::IUnknown,
::windows_core::IInspectable
);
impl ::core::cmp::PartialEq for IParams {
fn eq(&self, other: &Self) -> bool {
self.0 == other.0
}
}
impl ::core::cmp::Eq for IParams {}
impl ::core::fmt::Debug for IParams {
fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
f.debug_tuple("IParams").field(&self.0).finish()
}
}
impl ::windows_core::RuntimeType for IParams {
const SIGNATURE: ::windows_core::imp::ConstBuffer =
::windows_core::imp::ConstBuffer::from_slice(b"TODO");
}
unsafe impl ::windows_core::Interface for IParams {
type Vtable = IParams_Vtbl;
}
impl ::core::clone::Clone for IParams {
fn clone(&self) -> Self {
Self(self.0.clone())
}
}
unsafe impl ::windows_core::ComInterface for IParams {
const IID: ::windows_core::GUID = ::windows_core::GUID::zeroed();
}
#[repr(C)]
#[doc(hidden)]
pub struct IParams_Vtbl {
pub base__: ::windows_core::IInspectable_Vtbl,
pub Nothing:
unsafe extern "system" fn(this: *mut ::core::ffi::c_void) -> ::windows_core::HRESULT,
pub Bool: unsafe extern "system" fn(
this: *mut ::core::ffi::c_void,
a: *mut bool,
b: *mut bool,
result__: *mut bool,
) -> ::windows_core::HRESULT,
pub I8: unsafe extern "system" fn(
this: *mut ::core::ffi::c_void,
a: *mut i8,
b: *mut i8,
result__: *mut i8,
) -> ::windows_core::HRESULT,
pub U8: unsafe extern "system" fn(
this: *mut ::core::ffi::c_void,
a: *mut u8,
b: *mut u8,
result__: *mut u8,
) -> ::windows_core::HRESULT,
pub I16: unsafe extern "system" fn(
this: *mut ::core::ffi::c_void,
a: *mut i16,
b: *mut i16,
result__: *mut i16,
) -> ::windows_core::HRESULT,
pub U16: unsafe extern "system" fn(
this: *mut ::core::ffi::c_void,
a: *mut u16,
b: *mut u16,
result__: *mut u16,
) -> ::windows_core::HRESULT,
pub I32: unsafe extern "system" fn(
this: *mut ::core::ffi::c_void,
a: *mut i32,
b: *mut i32,
result__: *mut i32,
) -> ::windows_core::HRESULT,
pub U32: unsafe extern "system" fn(
this: *mut ::core::ffi::c_void,
a: *mut u32,
b: *mut u32,
result__: *mut u32,
) -> ::windows_core::HRESULT,
pub I64: unsafe extern "system" fn(
this: *mut ::core::ffi::c_void,
a: *mut i64,
b: *mut i64,
result__: *mut i64,
) -> ::windows_core::HRESULT,
pub U64: unsafe extern "system" fn(
this: *mut ::core::ffi::c_void,
a: *mut u64,
b: *mut u64,
result__: *mut u64,
) -> ::windows_core::HRESULT,
pub F32: unsafe extern "system" fn(
this: *mut ::core::ffi::c_void,
a: *mut f32,
b: *mut f32,
result__: *mut f32,
) -> ::windows_core::HRESULT,
pub F64: unsafe extern "system" fn(
this: *mut ::core::ffi::c_void,
a: *mut f64,
b: *mut f64,
result__: *mut f64,
) -> ::windows_core::HRESULT,
pub ISize: unsafe extern "system" fn(
this: *mut ::core::ffi::c_void,
a: *mut isize,
b: *mut isize,
result__: *mut isize,
) -> ::windows_core::HRESULT,
pub USize: unsafe extern "system" fn(
this: *mut ::core::ffi::c_void,
a: *mut usize,
b: *mut usize,
result__: *mut usize,
) -> ::windows_core::HRESULT,
}
18 changes: 18 additions & 0 deletions crates/tests/riddle/tests/params.idl
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
mod Test {
interface IParams {
fn Nothing();
fn Bool(a: bool, b: bool) -> bool;
fn I8(a: i8, b: i8) -> i8;
fn U8(a: u8, b: u8) -> u8;
fn I16(a: i16, b: i16) -> i16;
fn U16(a: u16, b: u16) -> u16;
fn I32(a: i32, b: i32) -> i32;
fn U32(a: u32, b: u32) -> u32;
fn I64(a: i64, b: i64) -> i64;
fn U64(a: u64, b: u64) -> u64;
fn F32(a: f32, b: f32) -> f32;
fn F64(a: f64, b: f64) -> f64;
fn ISize(a: isize, b: isize) -> isize;
fn USize(a: usize, b: usize) -> usize;
}
}
Loading