Skip to content

Commit

Permalink
Simplify type remapping (#2964)
Browse files Browse the repository at this point in the history
  • Loading branch information
kennykerr authored Apr 2, 2024
1 parent 5a92928 commit 52ee594
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 25 deletions.
12 changes: 4 additions & 8 deletions crates/libs/metadata/src/reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,7 @@ impl Reader {
}

pub fn remap_type(&self, type_name: &TypeName) -> Option<TypeName> {
if self.sys {
None
} else {
REMAP_TYPES.iter().find_map(|(key, value)| (type_name == key).then(|| value.clone()))
}
REMAP_TYPES.iter().find_map(|(key, value)| (type_name == key).then(|| value.clone()))
}

pub fn core_type(&self, type_name: &TypeName) -> Option<Type> {
Expand Down Expand Up @@ -264,8 +260,8 @@ impl Reader {
}

// TODO: this should be in riddle's Rust generator if at all - perhaps as convertible types rather than remapped types since there's already some precedent for that.
const REMAP_TYPES: [(TypeName, TypeName); 2] = [(TypeName::D2D_MATRIX_3X2_F, TypeName::Matrix3x2), (TypeName::D3DMATRIX, TypeName::Matrix4x4)];
const REMAP_TYPES: [(TypeName, TypeName); 3] = [(TypeName::D2D_MATRIX_3X2_F, TypeName::Matrix3x2), (TypeName::D3DMATRIX, TypeName::Matrix4x4), (TypeName::HRESULT, TypeName::HResult)];

// TODO: get rid of at least the second tuple if not the whole thing.
const CORE_TYPES: [(TypeName, Type); 13] = [(TypeName::GUID, Type::GUID), (TypeName::IUnknown, Type::IUnknown), (TypeName::HResult, Type::HRESULT), (TypeName::HRESULT, Type::HRESULT), (TypeName::HSTRING, Type::String), (TypeName::BSTR, Type::BSTR), (TypeName::IInspectable, Type::IInspectable), (TypeName::PSTR, Type::PSTR), (TypeName::PWSTR, Type::PWSTR), (TypeName::Type, Type::Type), (TypeName::CHAR, Type::I8), (TypeName::VARIANT, Type::VARIANT), (TypeName::PROPVARIANT, Type::PROPVARIANT)];
const SYS_CORE_TYPES: [(TypeName, Type); 11] = [(TypeName::GUID, Type::GUID), (TypeName::IUnknown, Type::IUnknown), (TypeName::HResult, Type::HRESULT), (TypeName::HRESULT, Type::HRESULT), (TypeName::HSTRING, Type::String), (TypeName::BSTR, Type::BSTR), (TypeName::IInspectable, Type::IInspectable), (TypeName::PSTR, Type::PSTR), (TypeName::PWSTR, Type::PWSTR), (TypeName::Type, Type::Type), (TypeName::CHAR, Type::I8)];
const CORE_TYPES: [(TypeName, Type); 12] = [(TypeName::GUID, Type::GUID), (TypeName::IUnknown, Type::IUnknown), (TypeName::HResult, Type::HRESULT), (TypeName::HSTRING, Type::String), (TypeName::BSTR, Type::BSTR), (TypeName::IInspectable, Type::IInspectable), (TypeName::PSTR, Type::PSTR), (TypeName::PWSTR, Type::PWSTR), (TypeName::Type, Type::Type), (TypeName::CHAR, Type::I8), (TypeName::VARIANT, Type::VARIANT), (TypeName::PROPVARIANT, Type::PROPVARIANT)];
const SYS_CORE_TYPES: [(TypeName, Type); 10] = [(TypeName::GUID, Type::GUID), (TypeName::IUnknown, Type::IUnknown), (TypeName::HResult, Type::HRESULT), (TypeName::HSTRING, Type::String), (TypeName::BSTR, Type::BSTR), (TypeName::IInspectable, Type::IInspectable), (TypeName::PSTR, Type::PSTR), (TypeName::PWSTR, Type::PWSTR), (TypeName::Type, Type::Type), (TypeName::CHAR, Type::I8)];
2 changes: 1 addition & 1 deletion crates/libs/sys/features.json

Large diffs are not rendered by default.

32 changes: 16 additions & 16 deletions crates/libs/sys/src/Windows/Wdk/Graphics/Direct3D/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4479,14 +4479,14 @@ impl Clone for D3DHAL_DP2LINESTRIP {
}
}
#[repr(C)]
#[cfg(all(feature = "Win32_Graphics_Direct3D", feature = "Win32_Graphics_Direct3D9"))]
#[cfg(all(feature = "Foundation_Numerics", feature = "Win32_Graphics_Direct3D9"))]
pub struct D3DHAL_DP2MULTIPLYTRANSFORM {
pub xfrmType: super::super::super::Win32::Graphics::Direct3D9::D3DTRANSFORMSTATETYPE,
pub matrix: super::super::super::Win32::Graphics::Direct3D::D3DMATRIX,
pub matrix: super::super::super::Foundation::Numerics::Matrix4x4,
}
#[cfg(all(feature = "Win32_Graphics_Direct3D", feature = "Win32_Graphics_Direct3D9"))]
#[cfg(all(feature = "Foundation_Numerics", feature = "Win32_Graphics_Direct3D9"))]
impl Copy for D3DHAL_DP2MULTIPLYTRANSFORM {}
#[cfg(all(feature = "Win32_Graphics_Direct3D", feature = "Win32_Graphics_Direct3D9"))]
#[cfg(all(feature = "Foundation_Numerics", feature = "Win32_Graphics_Direct3D9"))]
impl Clone for D3DHAL_DP2MULTIPLYTRANSFORM {
fn clone(&self) -> Self {
*self
Expand Down Expand Up @@ -4735,14 +4735,14 @@ impl Clone for D3DHAL_DP2SETTEXLOD {
}
}
#[repr(C)]
#[cfg(all(feature = "Win32_Graphics_Direct3D", feature = "Win32_Graphics_Direct3D9"))]
#[cfg(all(feature = "Foundation_Numerics", feature = "Win32_Graphics_Direct3D9"))]
pub struct D3DHAL_DP2SETTRANSFORM {
pub xfrmType: super::super::super::Win32::Graphics::Direct3D9::D3DTRANSFORMSTATETYPE,
pub matrix: super::super::super::Win32::Graphics::Direct3D::D3DMATRIX,
pub matrix: super::super::super::Foundation::Numerics::Matrix4x4,
}
#[cfg(all(feature = "Win32_Graphics_Direct3D", feature = "Win32_Graphics_Direct3D9"))]
#[cfg(all(feature = "Foundation_Numerics", feature = "Win32_Graphics_Direct3D9"))]
impl Copy for D3DHAL_DP2SETTRANSFORM {}
#[cfg(all(feature = "Win32_Graphics_Direct3D", feature = "Win32_Graphics_Direct3D9"))]
#[cfg(all(feature = "Foundation_Numerics", feature = "Win32_Graphics_Direct3D9"))]
impl Clone for D3DHAL_DP2SETTRANSFORM {
fn clone(&self) -> Self {
*self
Expand Down Expand Up @@ -13247,14 +13247,14 @@ impl Clone for D3DNTHAL_DP2LINESTRIP {
}
}
#[repr(C)]
#[cfg(all(feature = "Win32_Graphics_Direct3D", feature = "Win32_Graphics_Direct3D9"))]
#[cfg(all(feature = "Foundation_Numerics", feature = "Win32_Graphics_Direct3D9"))]
pub struct D3DNTHAL_DP2MULTIPLYTRANSFORM {
pub xfrmType: super::super::super::Win32::Graphics::Direct3D9::D3DTRANSFORMSTATETYPE,
pub matrix: super::super::super::Win32::Graphics::Direct3D::D3DMATRIX,
pub matrix: super::super::super::Foundation::Numerics::Matrix4x4,
}
#[cfg(all(feature = "Win32_Graphics_Direct3D", feature = "Win32_Graphics_Direct3D9"))]
#[cfg(all(feature = "Foundation_Numerics", feature = "Win32_Graphics_Direct3D9"))]
impl Copy for D3DNTHAL_DP2MULTIPLYTRANSFORM {}
#[cfg(all(feature = "Win32_Graphics_Direct3D", feature = "Win32_Graphics_Direct3D9"))]
#[cfg(all(feature = "Foundation_Numerics", feature = "Win32_Graphics_Direct3D9"))]
impl Clone for D3DNTHAL_DP2MULTIPLYTRANSFORM {
fn clone(&self) -> Self {
*self
Expand Down Expand Up @@ -13514,14 +13514,14 @@ impl Clone for D3DNTHAL_DP2SETTEXLOD {
}
}
#[repr(C)]
#[cfg(all(feature = "Win32_Graphics_Direct3D", feature = "Win32_Graphics_Direct3D9"))]
#[cfg(all(feature = "Foundation_Numerics", feature = "Win32_Graphics_Direct3D9"))]
pub struct D3DNTHAL_DP2SETTRANSFORM {
pub xfrmType: super::super::super::Win32::Graphics::Direct3D9::D3DTRANSFORMSTATETYPE,
pub matrix: super::super::super::Win32::Graphics::Direct3D::D3DMATRIX,
pub matrix: super::super::super::Foundation::Numerics::Matrix4x4,
}
#[cfg(all(feature = "Win32_Graphics_Direct3D", feature = "Win32_Graphics_Direct3D9"))]
#[cfg(all(feature = "Foundation_Numerics", feature = "Win32_Graphics_Direct3D9"))]
impl Copy for D3DNTHAL_DP2SETTRANSFORM {}
#[cfg(all(feature = "Win32_Graphics_Direct3D", feature = "Win32_Graphics_Direct3D9"))]
#[cfg(all(feature = "Foundation_Numerics", feature = "Win32_Graphics_Direct3D9"))]
impl Clone for D3DNTHAL_DP2SETTRANSFORM {
fn clone(&self) -> Self {
*self
Expand Down

0 comments on commit 52ee594

Please sign in to comment.