Skip to content

Commit

Permalink
Add first-class types for PCSTR and PCWSTR (#1550)
Browse files Browse the repository at this point in the history
  • Loading branch information
kennykerr authored Feb 18, 2022
1 parent 6c55e2d commit 7afc3d4
Show file tree
Hide file tree
Showing 577 changed files with 76,834 additions and 118,314 deletions.
2 changes: 1 addition & 1 deletion crates/libs/bindgen/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use super::*;

pub fn gen(def: &Field, gen: &Gen) -> TokenStream {
let name = gen_ident(def.name());
let ty = def.get_type(None);
let ty = def.get_type(None).to_const();
let cfg = def.cfg();
let doc = gen.doc(&cfg);
let features = gen.cfg(&cfg);
Expand Down
16 changes: 16 additions & 0 deletions crates/libs/bindgen/src/names.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,22 @@ pub fn gen_element_name(def: &Type, gen: &Gen) -> TokenStream {
let crate_name = gen_crate_name(gen);
quote! { ::#crate_name::core::HRESULT }
}
Type::PSTR => {
let crate_name = gen_crate_name(gen);
quote! { ::#crate_name::core::PSTR }
}
Type::PWSTR => {
let crate_name = gen_crate_name(gen);
quote! { ::#crate_name::core::PWSTR }
}
Type::PCSTR => {
let crate_name = gen_crate_name(gen);
quote! { ::#crate_name::core::PCSTR }
}
Type::PCWSTR => {
let crate_name = gen_crate_name(gen);
quote! { ::#crate_name::core::PCWSTR }
}
Type::Win32Array((kind, len)) => {
let name = gen_default_type(kind, gen);
let len = Literal::u32_unsuffixed(*len);
Expand Down
2 changes: 1 addition & 1 deletion crates/libs/bindgen/src/replacements/bstr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ pub fn gen() -> TokenStream {

unsafe {
SysAllocStringLen(
PWSTR(value.as_ptr()),
::windows::core::PCWSTR(value.as_ptr()),
value.len() as u32,
)
}
Expand Down
4 changes: 0 additions & 4 deletions crates/libs/bindgen/src/replacements/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,10 @@ mod bool32;
mod bstr;
mod handle;
mod ntstatus;
mod pstr;
mod pwstr;

pub fn gen(def: &TypeDef) -> Option<TokenStream> {
match def.type_name() {
TypeName::BOOL => Some(bool32::gen()),
TypeName::PWSTR => Some(pwstr::gen()),
TypeName::PSTR => Some(pstr::gen()),
TypeName::BSTR => Some(bstr::gen()),
TypeName::NTSTATUS => Some(ntstatus::gen()),
TypeName::HANDLE => Some(handle::gen()),
Expand Down
60 changes: 0 additions & 60 deletions crates/libs/bindgen/src/replacements/pstr.rs

This file was deleted.

71 changes: 0 additions & 71 deletions crates/libs/bindgen/src/replacements/pwstr.rs

This file was deleted.

10 changes: 8 additions & 2 deletions crates/libs/metadata/src/type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ pub enum Type {
IUnknown,
IInspectable,
HRESULT,
PSTR,
PWSTR,
PCSTR,
PCWSTR,
TypeName, // Used for parsing attribute blobs
GenericParam(&'static str),
MethodDef(MethodDef),
Expand Down Expand Up @@ -139,7 +143,7 @@ impl Type {
pub fn is_convertible(&self) -> bool {
match self {
Self::TypeDef(t) => t.is_convertible(),
Self::String | Self::IInspectable | Self::GUID | Self::IUnknown | Self::GenericParam(_) => true,
Self::String | Self::IInspectable | Self::GUID | Self::IUnknown | Self::GenericParam(_) | Self::PCSTR | Self::PCWSTR => true,
Self::WinrtConstRef(kind) => kind.is_convertible(),
_ => false,
}
Expand Down Expand Up @@ -230,6 +234,8 @@ impl Type {
pub fn to_const(self) -> Self {
match self {
Self::MutPtr((kind, pointers)) => Self::ConstPtr((kind, pointers)),
Self::PSTR => Self::PCSTR,
Self::PWSTR => Self::PCWSTR,
_ => self,
}
}
Expand Down Expand Up @@ -257,7 +263,7 @@ impl Type {

pub fn has_replacement(&self) -> bool {
match self {
Self::HRESULT => true,
Self::HRESULT | Self::PCSTR | Self::PCWSTR => true,
Self::TypeDef(def) => def.is_handle(),
_ => false,
}
Expand Down
2 changes: 1 addition & 1 deletion crates/libs/metadata/src/type_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,4 +224,4 @@ fn is_well_known(type_name: TypeName) -> bool {

const REMAP_TYPES: [(TypeName, TypeName); 1] = [(TypeName::D2D_MATRIX_3X2_F, TypeName::Matrix3x2)];

const WELL_KNOWN_TYPES: [(TypeName, Type); 9] = [(TypeName::GUID, Type::GUID), (TypeName::IUnknown, Type::IUnknown), (TypeName::HResult, Type::HRESULT), (TypeName::HRESULT, Type::HRESULT), (TypeName::HSTRING, Type::String), (TypeName::IInspectable, Type::IInspectable), (TypeName::LARGE_INTEGER, Type::I64), (TypeName::ULARGE_INTEGER, Type::U64), (TypeName::Type, Type::TypeName)];
const WELL_KNOWN_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::IInspectable, Type::IInspectable), (TypeName::LARGE_INTEGER, Type::I64), (TypeName::ULARGE_INTEGER, Type::U64), (TypeName::Type, Type::TypeName), (TypeName::PSTR, Type::PSTR), (TypeName::PWSTR, Type::PWSTR)];
Original file line number Diff line number Diff line change
Expand Up @@ -1777,35 +1777,29 @@ impl ::core::clone::Clone for DML_GRU_OPERATOR_DESC {
}
}
#[repr(C)]
#[doc = "*Required features: 'Win32_AI_MachineLearning_DirectML', 'Win32_Foundation'*"]
#[cfg(feature = "Win32_Foundation")]
#[doc = "*Required features: 'Win32_AI_MachineLearning_DirectML'*"]
pub struct DML_INPUT_GRAPH_EDGE_DESC {
pub GraphInputIndex: u32,
pub ToNodeIndex: u32,
pub ToNodeInputIndex: u32,
pub Name: super::super::super::Foundation::PSTR,
pub Name: ::windows_sys::core::PCSTR,
}
#[cfg(feature = "Win32_Foundation")]
impl ::core::marker::Copy for DML_INPUT_GRAPH_EDGE_DESC {}
#[cfg(feature = "Win32_Foundation")]
impl ::core::clone::Clone for DML_INPUT_GRAPH_EDGE_DESC {
fn clone(&self) -> Self {
*self
}
}
#[repr(C)]
#[doc = "*Required features: 'Win32_AI_MachineLearning_DirectML', 'Win32_Foundation'*"]
#[cfg(feature = "Win32_Foundation")]
#[doc = "*Required features: 'Win32_AI_MachineLearning_DirectML'*"]
pub struct DML_INTERMEDIATE_GRAPH_EDGE_DESC {
pub FromNodeIndex: u32,
pub FromNodeOutputIndex: u32,
pub ToNodeIndex: u32,
pub ToNodeInputIndex: u32,
pub Name: super::super::super::Foundation::PSTR,
pub Name: ::windows_sys::core::PCSTR,
}
#[cfg(feature = "Win32_Foundation")]
impl ::core::marker::Copy for DML_INTERMEDIATE_GRAPH_EDGE_DESC {}
#[cfg(feature = "Win32_Foundation")]
impl ::core::clone::Clone for DML_INTERMEDIATE_GRAPH_EDGE_DESC {
fn clone(&self) -> Self {
*self
Expand Down Expand Up @@ -2135,15 +2129,12 @@ impl ::core::clone::Clone for DML_OPERATOR_DESC {
}
}
#[repr(C)]
#[doc = "*Required features: 'Win32_AI_MachineLearning_DirectML', 'Win32_Foundation'*"]
#[cfg(feature = "Win32_Foundation")]
#[doc = "*Required features: 'Win32_AI_MachineLearning_DirectML'*"]
pub struct DML_OPERATOR_GRAPH_NODE_DESC {
pub Operator: IDMLOperator,
pub Name: super::super::super::Foundation::PSTR,
pub Name: ::windows_sys::core::PCSTR,
}
#[cfg(feature = "Win32_Foundation")]
impl ::core::marker::Copy for DML_OPERATOR_GRAPH_NODE_DESC {}
#[cfg(feature = "Win32_Foundation")]
impl ::core::clone::Clone for DML_OPERATOR_GRAPH_NODE_DESC {
fn clone(&self) -> Self {
*self
Expand Down Expand Up @@ -2454,17 +2445,14 @@ pub const DML_OPERATOR_DYNAMIC_QUANTIZE_LINEAR: DML_OPERATOR_TYPE = 148i32;
#[doc = "*Required features: 'Win32_AI_MachineLearning_DirectML'*"]
pub const DML_OPERATOR_ROI_ALIGN1: DML_OPERATOR_TYPE = 149i32;
#[repr(C)]
#[doc = "*Required features: 'Win32_AI_MachineLearning_DirectML', 'Win32_Foundation'*"]
#[cfg(feature = "Win32_Foundation")]
#[doc = "*Required features: 'Win32_AI_MachineLearning_DirectML'*"]
pub struct DML_OUTPUT_GRAPH_EDGE_DESC {
pub FromNodeIndex: u32,
pub FromNodeOutputIndex: u32,
pub GraphOutputIndex: u32,
pub Name: super::super::super::Foundation::PSTR,
pub Name: ::windows_sys::core::PCSTR,
}
#[cfg(feature = "Win32_Foundation")]
impl ::core::marker::Copy for DML_OUTPUT_GRAPH_EDGE_DESC {}
#[cfg(feature = "Win32_Foundation")]
impl ::core::clone::Clone for DML_OUTPUT_GRAPH_EDGE_DESC {
fn clone(&self) -> Self {
*self
Expand Down
Loading

0 comments on commit 7afc3d4

Please sign in to comment.