Skip to content

Commit

Permalink
DRAFT: Move overridden generated types into windows crate
Browse files Browse the repository at this point in the history
  • Loading branch information
MarijnS95 committed May 13, 2021
1 parent a352ad7 commit 1a15dc0
Show file tree
Hide file tree
Showing 30 changed files with 438 additions and 737 deletions.
2 changes: 1 addition & 1 deletion crates/bindings/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ fn main() -> std::io::Result<()> {
Windows::Win32::System::Memory::{
GetProcessHeap, HeapAlloc, HeapFree, HEAP_NONE,
},
Windows::Win32::System::OleAutomation::{BSTR, GetErrorInfo, IErrorInfo, SetErrorInfo},
Windows::Win32::System::OleAutomation::{GetErrorInfo, IErrorInfo, SetErrorInfo},
Windows::Win32::System::SystemServices::{
GetProcAddress, LoadLibraryA, FreeLibrary, CO_E_NOTINITIALIZED, E_POINTER,
},
Expand Down
33 changes: 33 additions & 0 deletions crates/gen/src/parser/element_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ pub enum ElementType {
IInspectable,
HRESULT,
Matrix3x2,

PWSTR,
PSTR,
BSTR,

TypeName,
GenericParam(tables::GenericParam),
Array((Box<Signature>, u32)),
Expand Down Expand Up @@ -134,6 +139,9 @@ impl ElementType {
("Windows.Win32.System.WinRT", "IInspectable") => Self::IInspectable,
("Windows.Win32.System.SystemServices", "LARGE_INTEGER") => Self::I64,
("Windows.Win32.System.SystemServices", "ULARGE_INTEGER") => Self::U64,
("Windows.Win32.System.SystemServices", "PWSTR") => Self::PWSTR,
("Windows.Win32.System.SystemServices", "PSTR") => Self::PSTR,
("Windows.Win32.System.OleAutomation", "BSTR") => Self::BSTR,
("Windows.Win32.Graphics.Direct2D", "D2D_MATRIX_3X2_F") => Self::Matrix3x2,
("System", "Type") => Self::TypeName,
_ => Self::from_type_def(type_ref.resolve(), Vec::new()),
Expand Down Expand Up @@ -228,6 +236,9 @@ impl ElementType {
let numerics = gen.namespace("Windows.Foundation.Numerics");
quote! { #numerics Matrix3x2 }
}
Self::PWSTR => quote!(::windows::PWSTR),
Self::PSTR => quote!(::windows::PSTR),
Self::BSTR => quote!(::windows::BSTR),
Self::Array((kind, len)) => {
let name = kind.gen_win32(gen);
let len = Literal::u32_unsuffixed(*len);
Expand Down Expand Up @@ -283,6 +294,9 @@ impl ElementType {
let numerics = gen.namespace("Windows.Foundation.Numerics");
quote! { #numerics Matrix3x2 }
}
Self::PWSTR => quote!(::windows::PWSTR),
Self::PSTR => quote!(::windows::PSTR),
Self::BSTR => quote!(::windows::BSTR_abi),
Self::Array((kind, len)) => {
let name = kind.gen_win32_abi(gen);
let len = Literal::u32_unsuffixed(*len);
Expand Down Expand Up @@ -374,6 +388,18 @@ impl ElementType {
Self::Callback(t) => t.dependencies(),
Self::Constant(t) => t.dependencies(),
Self::Array((signature, _)) => signature.dependencies(),

// TODO: These should be specified in bindings/src/main.rs instead!
// Or in the `exclude` list in type_reader if linked, overridden
// and publicly exported from bstr.rs.
Self::BSTR => {
let reader = TypeReader::get();
vec![
reader.resolve_type("Windows.Win32.System.OleAutomation", "SysFreeString"),
reader.resolve_type("Windows.Win32.System.OleAutomation", "SysAllocStringLen"),
reader.resolve_type("Windows.Win32.System.OleAutomation", "SysStringLen"),
]
}
_ => Vec::new(),
}
}
Expand Down Expand Up @@ -415,6 +441,10 @@ impl ElementType {
Self::String
| Self::IInspectable
| Self::IUnknown
| Self::PWSTR
| Self::PSTR
// See Struct::is_blittable edgecase
// | Self::BSTR
| Self::GenericParam(_)
| Self::Class(_)
| Self::Interface(_)
Expand All @@ -434,6 +464,9 @@ impl ElementType {
| Self::Guid
| Self::IUnknown
| Self::Matrix3x2
| Self::PWSTR
| Self::PSTR
| Self::BSTR
| Self::GenericParam(_)
| Self::Class(_)
| Self::Interface(_)
Expand Down
3 changes: 3 additions & 0 deletions crates/gen/src/parser/type_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,9 @@ impl TypeReader {
("Windows.Win32.Graphics.Direct2D", "D2D_MATRIX_3X2_F"),
("Windows.Win32.System.SystemServices", "LARGE_INTEGER"),
("Windows.Win32.System.SystemServices", "ULARGE_INTEGER"),
("Windows.Win32.System.SystemServices", "PWSTR"),
("Windows.Win32.System.SystemServices", "PSTR"),
("Windows.Win32.System.OleAutomation", "BSTR"),
];

for (namespace, name) in exclude {
Expand Down
191 changes: 0 additions & 191 deletions crates/gen/src/types/bstr.rs

This file was deleted.

6 changes: 0 additions & 6 deletions crates/gen/src/types/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
pub use super::*;

mod bool32;
mod bstr;
mod callback;
mod class;
mod com_interface;
Expand All @@ -13,16 +12,13 @@ mod handle;
mod interface;
mod matrix3x2;
mod matrix4x4;
mod pstr;
mod pwstr;
mod r#struct;
mod timespan;
mod vector2;
mod vector3;
mod vector4;

pub use bool32::*;
pub use bstr::*;
pub use callback::*;
pub use class::*;
pub use com_interface::*;
Expand All @@ -33,8 +29,6 @@ pub use handle::*;
pub use interface::*;
pub use matrix3x2::*;
pub use matrix4x4::*;
pub use pstr::*;
pub use pwstr::*;
pub use r#enum::*;
pub use r#struct::*;
pub use timespan::*;
Expand Down
49 changes: 0 additions & 49 deletions crates/gen/src/types/pstr.rs

This file was deleted.

Loading

0 comments on commit 1a15dc0

Please sign in to comment.