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

Improve NTSTATUS constant literal generation #2860

Merged
merged 1 commit into from
Feb 20, 2024
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
10 changes: 9 additions & 1 deletion crates/libs/bindgen/src/rust/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ pub fn writer(writer: &Writer, def: metadata::Field) -> TokenStream {
let underlying_type = type_underlying_type(&ty);

if underlying_type == constant_type {
if ty == metadata::Type::HRESULT {
if is_signed_error(&ty) {
if let metadata::Value::I32(signed) = constant.value() {
value = format!("0x{:X}_u32 as _", signed).into();
}
Expand Down Expand Up @@ -78,6 +78,14 @@ pub fn writer(writer: &Writer, def: metadata::Field) -> TokenStream {
}
}

fn is_signed_error(ty: &metadata::Type) -> bool {
match ty {
metadata::Type::HRESULT => true,
metadata::Type::TypeDef(def, _) => def.type_name() == metadata::TypeName::NTSTATUS,
_ => false,
}
}

fn initializer(writer: &Writer, def: metadata::Field) -> Option<TokenStream> {
let value = constant(def)?;
let mut input = value.as_str();
Expand Down
1 change: 1 addition & 0 deletions crates/libs/metadata/src/type_name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ impl TypeName {
pub const CHAR: Self = Self::from_const("Windows.Win32.Foundation", "CHAR");
pub const BOOL: Self = Self::from_const("Windows.Win32.Foundation", "BOOL");
pub const WIN32_ERROR: Self = Self::from_const("Windows.Win32.Foundation", "WIN32_ERROR");
pub const NTSTATUS: Self = Self::from_const("Windows.Win32.Foundation", "NTSTATUS");

pub const D2D_MATRIX_3X2_F: Self = Self::from_const("Windows.Win32.Graphics.Direct2D.Common", "D2D_MATRIX_3X2_F");
pub const D3DMATRIX: Self = Self::from_const("Windows.Win32.Graphics.Direct3D", "D3DMATRIX");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1769,27 +1769,27 @@ pub const GUID_Unknown: ::windows_sys::core::GUID = ::windows_sys::core::GUID::f
pub const GUID_XAxis: ::windows_sys::core::GUID = ::windows_sys::core::GUID::from_u128(0xa36d02e0_c9f3_11cf_bfc7_444553540000);
pub const GUID_YAxis: ::windows_sys::core::GUID = ::windows_sys::core::GUID::from_u128(0xa36d02e1_c9f3_11cf_bfc7_444553540000);
pub const GUID_ZAxis: ::windows_sys::core::GUID = ::windows_sys::core::GUID::from_u128(0xa36d02e2_c9f3_11cf_bfc7_444553540000);
pub const HIDP_STATUS_BAD_LOG_PHY_VALUES: super::super::Foundation::NTSTATUS = -1072627706i32;
pub const HIDP_STATUS_BUFFER_TOO_SMALL: super::super::Foundation::NTSTATUS = -1072627705i32;
pub const HIDP_STATUS_BUTTON_NOT_PRESSED: super::super::Foundation::NTSTATUS = -1072627697i32;
pub const HIDP_STATUS_DATA_INDEX_NOT_FOUND: super::super::Foundation::NTSTATUS = -1072627699i32;
pub const HIDP_STATUS_DATA_INDEX_OUT_OF_RANGE: super::super::Foundation::NTSTATUS = -1072627698i32;
pub const HIDP_STATUS_I8042_TRANS_UNKNOWN: super::super::Foundation::NTSTATUS = -1072627703i32;
pub const HIDP_STATUS_I8242_TRANS_UNKNOWN: super::super::Foundation::NTSTATUS = -1072627703i32;
pub const HIDP_STATUS_INCOMPATIBLE_REPORT_ID: super::super::Foundation::NTSTATUS = -1072627702i32;
pub const HIDP_STATUS_INTERNAL_ERROR: super::super::Foundation::NTSTATUS = -1072627704i32;
pub const HIDP_STATUS_INVALID_PREPARSED_DATA: super::super::Foundation::NTSTATUS = -1072627711i32;
pub const HIDP_STATUS_INVALID_REPORT_LENGTH: super::super::Foundation::NTSTATUS = -1072627709i32;
pub const HIDP_STATUS_INVALID_REPORT_TYPE: super::super::Foundation::NTSTATUS = -1072627710i32;
pub const HIDP_STATUS_IS_VALUE_ARRAY: super::super::Foundation::NTSTATUS = -1072627700i32;
pub const HIDP_STATUS_NOT_BUTTON_ARRAY: super::super::Foundation::NTSTATUS = -1072627679i32;
pub const HIDP_STATUS_NOT_IMPLEMENTED: super::super::Foundation::NTSTATUS = -1072627680i32;
pub const HIDP_STATUS_NOT_VALUE_ARRAY: super::super::Foundation::NTSTATUS = -1072627701i32;
pub const HIDP_STATUS_NULL: super::super::Foundation::NTSTATUS = -2146369535i32;
pub const HIDP_STATUS_REPORT_DOES_NOT_EXIST: super::super::Foundation::NTSTATUS = -1072627696i32;
pub const HIDP_STATUS_SUCCESS: super::super::Foundation::NTSTATUS = 1114112i32;
pub const HIDP_STATUS_USAGE_NOT_FOUND: super::super::Foundation::NTSTATUS = -1072627708i32;
pub const HIDP_STATUS_VALUE_OUT_OF_RANGE: super::super::Foundation::NTSTATUS = -1072627707i32;
pub const HIDP_STATUS_BAD_LOG_PHY_VALUES: super::super::Foundation::NTSTATUS = 0xC0110006_u32 as _;
pub const HIDP_STATUS_BUFFER_TOO_SMALL: super::super::Foundation::NTSTATUS = 0xC0110007_u32 as _;
pub const HIDP_STATUS_BUTTON_NOT_PRESSED: super::super::Foundation::NTSTATUS = 0xC011000F_u32 as _;
pub const HIDP_STATUS_DATA_INDEX_NOT_FOUND: super::super::Foundation::NTSTATUS = 0xC011000D_u32 as _;
pub const HIDP_STATUS_DATA_INDEX_OUT_OF_RANGE: super::super::Foundation::NTSTATUS = 0xC011000E_u32 as _;
pub const HIDP_STATUS_I8042_TRANS_UNKNOWN: super::super::Foundation::NTSTATUS = 0xC0110009_u32 as _;
pub const HIDP_STATUS_I8242_TRANS_UNKNOWN: super::super::Foundation::NTSTATUS = 0xC0110009_u32 as _;
pub const HIDP_STATUS_INCOMPATIBLE_REPORT_ID: super::super::Foundation::NTSTATUS = 0xC011000A_u32 as _;
pub const HIDP_STATUS_INTERNAL_ERROR: super::super::Foundation::NTSTATUS = 0xC0110008_u32 as _;
pub const HIDP_STATUS_INVALID_PREPARSED_DATA: super::super::Foundation::NTSTATUS = 0xC0110001_u32 as _;
pub const HIDP_STATUS_INVALID_REPORT_LENGTH: super::super::Foundation::NTSTATUS = 0xC0110003_u32 as _;
pub const HIDP_STATUS_INVALID_REPORT_TYPE: super::super::Foundation::NTSTATUS = 0xC0110002_u32 as _;
pub const HIDP_STATUS_IS_VALUE_ARRAY: super::super::Foundation::NTSTATUS = 0xC011000C_u32 as _;
pub const HIDP_STATUS_NOT_BUTTON_ARRAY: super::super::Foundation::NTSTATUS = 0xC0110021_u32 as _;
pub const HIDP_STATUS_NOT_IMPLEMENTED: super::super::Foundation::NTSTATUS = 0xC0110020_u32 as _;
pub const HIDP_STATUS_NOT_VALUE_ARRAY: super::super::Foundation::NTSTATUS = 0xC011000B_u32 as _;
pub const HIDP_STATUS_NULL: super::super::Foundation::NTSTATUS = 0x80110001_u32 as _;
pub const HIDP_STATUS_REPORT_DOES_NOT_EXIST: super::super::Foundation::NTSTATUS = 0xC0110010_u32 as _;
pub const HIDP_STATUS_SUCCESS: super::super::Foundation::NTSTATUS = 0x110000_u32 as _;
pub const HIDP_STATUS_USAGE_NOT_FOUND: super::super::Foundation::NTSTATUS = 0xC0110004_u32 as _;
pub const HIDP_STATUS_VALUE_OUT_OF_RANGE: super::super::Foundation::NTSTATUS = 0xC0110005_u32 as _;
pub const HID_REVISION: u32 = 1u32;
pub const HID_USAGE_ALPHANUMERIC_14_SEGMENT_DIRECT_MAP: u16 = 69u16;
pub const HID_USAGE_ALPHANUMERIC_7_SEGMENT_DIRECT_MAP: u16 = 67u16;
Expand Down
Loading