From 405449901cf4ecaa2d9a0feb5b900327c2c404a2 Mon Sep 17 00:00:00 2001 From: Marijn Suijten Date: Mon, 10 Jan 2022 21:07:54 +0100 Subject: [PATCH] generator: Exclude static macro code (`macros.rs`) from the generator (#552) Much like `platform_types.rs` and `vk.rs` before, there is no need to generate this file as its contents are completely static. This allows direct editing of the file without realizing that a copy lives in the generator - and will overwrite `macros.rs` when the generator is being run. --- generator/src/lib.rs | 203 ------------------------------------------- 1 file changed, 203 deletions(-) diff --git a/generator/src/lib.rs b/generator/src/lib.rs index 438eaac..2cc2117 100644 --- a/generator/src/lib.rs +++ b/generator/src/lib.rs @@ -132,197 +132,6 @@ fn khronos_link(name: &S) -> Literal { )) } -pub fn define_handle_macro() -> TokenStream { - quote! { - #[macro_export] - macro_rules! define_handle{ - ($name: ident, $ty: ident) => { - define_handle!($name, $ty, doc = ""); - }; - ($name: ident, $ty: ident, $doc_link: meta) => { - #[repr(transparent)] - #[derive(Eq, PartialEq, Ord, PartialOrd, Clone, Copy, Hash)] - #[$doc_link] - pub struct $name(*mut u8); - impl Default for $name { - fn default() -> Self { - Self::null() - } - } - - impl Handle for $name { - const TYPE: ObjectType = ObjectType::$ty; - fn as_raw(self) -> u64 { self.0 as u64 } - fn from_raw(x: u64) -> Self { Self(x as _) } - } - - unsafe impl Send for $name {} - unsafe impl Sync for $name {} - - impl $name { - pub const fn null() -> Self { - Self(::std::ptr::null_mut()) - } - } - - impl fmt::Pointer for $name { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - fmt::Pointer::fmt(&self.0, f) - } - } - - impl fmt::Debug for $name { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - fmt::Debug::fmt(&self.0, f) - } - } - } - } - } -} - -pub fn handle_nondispatchable_macro() -> TokenStream { - quote! { - #[macro_export] - macro_rules! handle_nondispatchable { - ($name: ident, $ty: ident) => { - handle_nondispatchable!($name, $ty, doc = ""); - }; - ($name: ident, $ty: ident, $doc_link: meta) => { - #[repr(transparent)] - #[derive(Eq, PartialEq, Ord, PartialOrd, Clone, Copy, Hash, Default)] - #[$doc_link] - pub struct $name(u64); - - impl Handle for $name { - const TYPE: ObjectType = ObjectType::$ty; - fn as_raw(self) -> u64 { self.0 as u64 } - fn from_raw(x: u64) -> Self { Self(x as _) } - } - - impl $name{ - pub const fn null() -> Self { - Self(0) - } - } - - impl fmt::Pointer for $name { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "0x{:x}", self.0) - } - } - - impl fmt::Debug for $name { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "0x{:x}", self.0) - } - } - } - } - } -} -pub fn vk_bitflags_wrapped_macro() -> TokenStream { - quote! { - #[macro_export] - macro_rules! vk_bitflags_wrapped { - ($name: ident, $flag_type: ty) => { - - impl Default for $name { - fn default() -> Self { - Self(0) - } - } - - impl $name { - #[inline] - pub const fn empty() -> Self { - Self(0) - } - - #[inline] - pub const fn from_raw(x: $flag_type) -> Self { Self(x) } - - #[inline] - pub const fn as_raw(self) -> $flag_type { self.0 } - - #[inline] - pub fn is_empty(self) -> bool { - self == Self::empty() - } - - #[inline] - pub fn intersects(self, other: Self) -> bool { - self & other != Self::empty() - } - - /// Returns whether `other` is a subset of `self` - #[inline] - pub fn contains(self, other: Self) -> bool { - self & other == other - } - } - - impl ::std::ops::BitOr for $name { - type Output = Self; - - #[inline] - fn bitor(self, rhs: Self) -> Self { - Self(self.0 | rhs.0) - } - } - - impl ::std::ops::BitOrAssign for $name { - #[inline] - fn bitor_assign(&mut self, rhs: Self) { - *self = *self | rhs - } - } - - impl ::std::ops::BitAnd for $name { - type Output = Self; - - #[inline] - fn bitand(self, rhs: Self) -> Self { - Self(self.0 & rhs.0) - } - } - - impl ::std::ops::BitAndAssign for $name { - #[inline] - fn bitand_assign(&mut self, rhs: Self) { - *self = *self & rhs - } - } - - impl ::std::ops::BitXor for $name { - type Output = Self; - - #[inline] - fn bitxor(self, rhs: Self) -> Self { - Self(self.0 ^ rhs.0) - } - } - - impl ::std::ops::BitXorAssign for $name { - #[inline] - fn bitxor_assign(&mut self, rhs: Self) { - *self = *self ^ rhs - } - } - - impl ::std::ops::Not for $name { - type Output = Self; - - #[inline] - fn not(self) -> Self { - Self(!self.0) - } - } - } - } - } -} - fn is_opaque_type(ty: &str) -> bool { matches!( ty, @@ -2731,22 +2540,11 @@ pub fn write_source_code>(vk_headers_dir: &Path, src_dir: P) { extras: const_debugs, } = generate_const_debugs(&const_values); - let bitflags_macro = vk_bitflags_wrapped_macro(); - let handle_nondispatchable_macro = handle_nondispatchable_macro(); - let define_handle_macro = define_handle_macro(); - - let macros_code = quote! { - #bitflags_macro - #handle_nondispatchable_macro - #define_handle_macro - }; - let src_dir = src_dir.as_ref(); let vk_dir = src_dir.join("vk"); std::fs::create_dir_all(&vk_dir).expect("failed to create vk dir"); - let mut vk_macros_file = File::create(vk_dir.join("macros.rs")).expect("vk/macros.rs"); let mut vk_features_file = File::create(vk_dir.join("features.rs")).expect("vk/features.rs"); let mut vk_definitions_file = File::create(vk_dir.join("definitions.rs")).expect("vk/definitions.rs"); @@ -2831,7 +2629,6 @@ pub fn write_source_code>(vk_headers_dir: &Path, src_dir: P) { #(#aliases)* }; - write!(&mut vk_macros_file, "{}", macros_code).expect("Unable to write vk/macros.rs"); write!(&mut vk_features_file, "{}", feature_code).expect("Unable to write vk/features.rs"); write!(&mut vk_definitions_file, "{}", definition_code) .expect("Unable to write vk/definitions.rs");