Merge pull request #90 from Cyres/repr-transparent
Use repr(transparent) where possible and apply rustfmt to those files
This commit is contained in:
commit
4797c12c89
734
ash/src/vk.rs
734
ash/src/vk.rs
File diff suppressed because it is too large
Load diff
|
@ -88,7 +88,7 @@ pub fn define_handle_macro() -> Tokens {
|
||||||
macro_rules! define_handle{
|
macro_rules! define_handle{
|
||||||
($name: ident) => {
|
($name: ident) => {
|
||||||
#[derive(Clone, Copy, Debug)]
|
#[derive(Clone, Copy, Debug)]
|
||||||
#[repr(C)]
|
#[repr(transparent)]
|
||||||
pub struct $name{
|
pub struct $name{
|
||||||
ptr: *mut u8
|
ptr: *mut u8
|
||||||
}
|
}
|
||||||
|
@ -117,7 +117,7 @@ pub fn handle_nondispatchable_macro() -> Tokens {
|
||||||
quote!{
|
quote!{
|
||||||
macro_rules! handle_nondispatchable {
|
macro_rules! handle_nondispatchable {
|
||||||
($name: ident) => {
|
($name: ident) => {
|
||||||
#[repr(C)]
|
#[repr(transparent)]
|
||||||
#[derive(Eq, PartialEq, Ord, PartialOrd, Clone, Copy, Hash, Default)]
|
#[derive(Eq, PartialEq, Ord, PartialOrd, Clone, Copy, Hash, Default)]
|
||||||
pub struct $name (uint64_t);
|
pub struct $name (uint64_t);
|
||||||
|
|
||||||
|
@ -525,8 +525,7 @@ impl CommandExt for vkxml::Command {
|
||||||
.map(|field| match field.basetype.as_str() {
|
.map(|field| match field.basetype.as_str() {
|
||||||
"VkDevice" | "VkCommandBuffer" | "VkQueue" => true,
|
"VkDevice" | "VkCommandBuffer" | "VkQueue" => true,
|
||||||
_ => false,
|
_ => false,
|
||||||
})
|
}).unwrap_or(false);
|
||||||
.unwrap_or(false);
|
|
||||||
match self.name.as_str() {
|
match self.name.as_str() {
|
||||||
"vkGetInstanceProcAddr" => FunctionType::Static,
|
"vkGetInstanceProcAddr" => FunctionType::Static,
|
||||||
"vkCreateInstance"
|
"vkCreateInstance"
|
||||||
|
@ -674,11 +673,9 @@ fn generate_function_pointers(ident: Ident, commands: &[&vkxml::Command]) -> quo
|
||||||
let name = field.param_ident();
|
let name = field.param_ident();
|
||||||
let ty = field.type_tokens();
|
let ty = field.type_tokens();
|
||||||
(name, ty)
|
(name, ty)
|
||||||
})
|
}).collect();
|
||||||
.collect();
|
|
||||||
params
|
params
|
||||||
})
|
}).collect();
|
||||||
.collect();
|
|
||||||
|
|
||||||
let params_names: Vec<Vec<_>> = params
|
let params_names: Vec<Vec<_>> = params
|
||||||
.iter()
|
.iter()
|
||||||
|
@ -687,8 +684,7 @@ fn generate_function_pointers(ident: Ident, commands: &[&vkxml::Command]) -> quo
|
||||||
.iter()
|
.iter()
|
||||||
.map(|&(param_name, _)| param_name)
|
.map(|&(param_name, _)| param_name)
|
||||||
.collect()
|
.collect()
|
||||||
})
|
}).collect();
|
||||||
.collect();
|
|
||||||
let param_names_ref = ¶ms_names;
|
let param_names_ref = ¶ms_names;
|
||||||
let expanded_params: Vec<_> = params
|
let expanded_params: Vec<_> = params
|
||||||
.iter()
|
.iter()
|
||||||
|
@ -699,8 +695,7 @@ fn generate_function_pointers(ident: Ident, commands: &[&vkxml::Command]) -> quo
|
||||||
quote!{
|
quote!{
|
||||||
#(#inner_params_iter,)*
|
#(#inner_params_iter,)*
|
||||||
}
|
}
|
||||||
})
|
}).collect();
|
||||||
.collect();
|
|
||||||
let expanded_params_ref = &expanded_params;
|
let expanded_params_ref = &expanded_params;
|
||||||
|
|
||||||
let return_types: Vec<_> = commands
|
let return_types: Vec<_> = commands
|
||||||
|
@ -787,8 +782,7 @@ pub fn generate_extension_constants<'a>(
|
||||||
.filter_map(|item| match item {
|
.filter_map(|item| match item {
|
||||||
vk_parse::ExtensionItem::Require { items, .. } => Some(items.iter()),
|
vk_parse::ExtensionItem::Require { items, .. } => Some(items.iter()),
|
||||||
_ => None,
|
_ => None,
|
||||||
})
|
}).flat_map(|iter| iter);
|
||||||
.flat_map(|iter| iter);
|
|
||||||
let enum_tokens = items.filter_map(|item| match item {
|
let enum_tokens = items.filter_map(|item| match item {
|
||||||
vk_parse::InterfaceItem::Enum(_enum) => {
|
vk_parse::InterfaceItem::Enum(_enum) => {
|
||||||
use vk_parse::EnumSpec;
|
use vk_parse::EnumSpec;
|
||||||
|
@ -853,8 +847,7 @@ pub fn generate_extension_commands(
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
_ => None,
|
_ => None,
|
||||||
})
|
}).flat_map(|iter| iter)
|
||||||
.flat_map(|iter| iter)
|
|
||||||
.collect_vec();
|
.collect_vec();
|
||||||
let name = format!("{}Fn", extension_name.to_camel_case());
|
let name = format!("{}Fn", extension_name.to_camel_case());
|
||||||
let ident = Ident::from(&name[2..]);
|
let ident = Ident::from(&name[2..]);
|
||||||
|
@ -904,7 +897,7 @@ pub fn generate_bitmask(bitmask: &vkxml::Bitmask) -> Option<Tokens> {
|
||||||
let name = &bitmask.name[2..];
|
let name = &bitmask.name[2..];
|
||||||
let ident = Ident::from(name);
|
let ident = Ident::from(name);
|
||||||
Some(quote!{
|
Some(quote!{
|
||||||
#[repr(C)]
|
#[repr(transparent)]
|
||||||
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||||
pub struct #ident(Flags);
|
pub struct #ident(Flags);
|
||||||
vk_bitflags_wrapped!(#ident, 0b0, Flags);
|
vk_bitflags_wrapped!(#ident, 0b0, Flags);
|
||||||
|
@ -958,8 +951,7 @@ pub fn bitflags_impl_block(
|
||||||
let variant_ident = constant.variant_ident(enum_name);
|
let variant_ident = constant.variant_ident(enum_name);
|
||||||
let tokens = constant.to_tokens();
|
let tokens = constant.to_tokens();
|
||||||
(variant_ident, tokens)
|
(variant_ident, tokens)
|
||||||
})
|
}).collect_vec();
|
||||||
.collect_vec();
|
|
||||||
|
|
||||||
let notations = constants.iter().map(|constant| {
|
let notations = constants.iter().map(|constant| {
|
||||||
constant.notation().map(|n| {
|
constant.notation().map(|n| {
|
||||||
|
@ -969,14 +961,16 @@ pub fn bitflags_impl_block(
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
let variants = variants.iter().zip(notations.clone()).map(
|
let variants =
|
||||||
|((variant_ident, value), ref notation)| {
|
variants
|
||||||
|
.iter()
|
||||||
|
.zip(notations.clone())
|
||||||
|
.map(|((variant_ident, value), ref notation)| {
|
||||||
quote!{
|
quote!{
|
||||||
#notation
|
#notation
|
||||||
pub const #variant_ident: Self = #ident(#value);
|
pub const #variant_ident: Self = #ident(#value);
|
||||||
}
|
}
|
||||||
},
|
});
|
||||||
);
|
|
||||||
quote!{
|
quote!{
|
||||||
impl #ident {
|
impl #ident {
|
||||||
#(#variants)*
|
#(#variants)*
|
||||||
|
@ -997,8 +991,7 @@ pub fn generate_enum<'a>(
|
||||||
.filter_map(|elem| match *elem {
|
.filter_map(|elem| match *elem {
|
||||||
vkxml::EnumerationElement::Enum(ref constant) => Some(constant),
|
vkxml::EnumerationElement::Enum(ref constant) => Some(constant),
|
||||||
_ => None,
|
_ => None,
|
||||||
})
|
}).collect_vec();
|
||||||
.collect_vec();
|
|
||||||
for constant in &constants {
|
for constant in &constants {
|
||||||
const_cache.insert(constant.name.as_str());
|
const_cache.insert(constant.name.as_str());
|
||||||
}
|
}
|
||||||
|
@ -1013,7 +1006,7 @@ pub fn generate_enum<'a>(
|
||||||
|
|
||||||
let impl_bitflags = bitflags_impl_block(ident, &_enum.name, &constants);
|
let impl_bitflags = bitflags_impl_block(ident, &_enum.name, &constants);
|
||||||
let q = quote!{
|
let q = quote!{
|
||||||
#[repr(C)]
|
#[repr(transparent)]
|
||||||
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||||
pub struct #ident(pub(crate) Flags);
|
pub struct #ident(pub(crate) Flags);
|
||||||
vk_bitflags_wrapped!(#ident, #all_bits_term, Flags);
|
vk_bitflags_wrapped!(#ident, #all_bits_term, Flags);
|
||||||
|
@ -1024,7 +1017,7 @@ pub fn generate_enum<'a>(
|
||||||
let impl_block = bitflags_impl_block(ident, &_enum.name, &constants);
|
let impl_block = bitflags_impl_block(ident, &_enum.name, &constants);
|
||||||
let enum_quote = quote!{
|
let enum_quote = quote!{
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)]
|
||||||
#[repr(C)]
|
#[repr(transparent)]
|
||||||
pub struct #ident(pub(crate) i32);
|
pub struct #ident(pub(crate) i32);
|
||||||
#impl_block
|
#impl_block
|
||||||
};
|
};
|
||||||
|
@ -1087,8 +1080,7 @@ fn is_static_array(field: &vkxml::Field) -> bool {
|
||||||
.map(|ty| match ty {
|
.map(|ty| match ty {
|
||||||
vkxml::ArrayType::Static => true,
|
vkxml::ArrayType::Static => true,
|
||||||
_ => false,
|
_ => false,
|
||||||
})
|
}).unwrap_or(false)
|
||||||
.unwrap_or(false)
|
|
||||||
}
|
}
|
||||||
pub fn derive_default(_struct: &vkxml::Struct, union_types: &HashSet<&str>) -> Option<Tokens> {
|
pub fn derive_default(_struct: &vkxml::Struct, union_types: &HashSet<&str>) -> Option<Tokens> {
|
||||||
let name = name_to_tokens(&_struct.name);
|
let name = name_to_tokens(&_struct.name);
|
||||||
|
@ -1344,13 +1336,11 @@ pub fn generate_feature(feature: &vkxml::Feature, commands: &CommandMap) -> quot
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
})
|
}).collect()
|
||||||
.collect()
|
|
||||||
} else {
|
} else {
|
||||||
vec![]
|
vec![]
|
||||||
}
|
}
|
||||||
})
|
}).filter_map(|cmd_ref| commands.get(&cmd_ref.name))
|
||||||
.filter_map(|cmd_ref| commands.get(&cmd_ref.name))
|
|
||||||
.fold(
|
.fold(
|
||||||
(Vec::new(), Vec::new(), Vec::new(), Vec::new()),
|
(Vec::new(), Vec::new(), Vec::new(), Vec::new()),
|
||||||
|mut acc, &cmd_ref| {
|
|mut acc, &cmd_ref| {
|
||||||
|
@ -1440,8 +1430,7 @@ pub fn write_source_code(path: &Path) {
|
||||||
.filter_map(|item| match item {
|
.filter_map(|item| match item {
|
||||||
vk_parse::RegistryItem::Extensions { items: ext, .. } => Some(ext),
|
vk_parse::RegistryItem::Extensions { items: ext, .. } => Some(ext),
|
||||||
_ => None,
|
_ => None,
|
||||||
})
|
}).nth(0)
|
||||||
.nth(0)
|
|
||||||
.expect("extension");
|
.expect("extension");
|
||||||
|
|
||||||
let spec = vk_parse::parse_file_as_vkxml(path);
|
let spec = vk_parse::parse_file_as_vkxml(path);
|
||||||
|
@ -1451,8 +1440,7 @@ pub fn write_source_code(path: &Path) {
|
||||||
.filter_map(|elem| match elem {
|
.filter_map(|elem| match elem {
|
||||||
vkxml::RegistryElement::Commands(ref cmds) => Some(cmds),
|
vkxml::RegistryElement::Commands(ref cmds) => Some(cmds),
|
||||||
_ => None,
|
_ => None,
|
||||||
})
|
}).flat_map(|cmds| cmds.elements.iter().map(|cmd| (cmd.name.clone(), cmd)))
|
||||||
.flat_map(|cmds| cmds.elements.iter().map(|cmd| (cmd.name.clone(), cmd)))
|
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
let features: Vec<&vkxml::Feature> = spec
|
let features: Vec<&vkxml::Feature> = spec
|
||||||
|
@ -1461,8 +1449,7 @@ pub fn write_source_code(path: &Path) {
|
||||||
.filter_map(|elem| match elem {
|
.filter_map(|elem| match elem {
|
||||||
vkxml::RegistryElement::Features(ref features) => Some(features),
|
vkxml::RegistryElement::Features(ref features) => Some(features),
|
||||||
_ => None,
|
_ => None,
|
||||||
})
|
}).flat_map(|features| features.elements.iter())
|
||||||
.flat_map(|features| features.elements.iter())
|
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
let definitions: Vec<&vkxml::DefinitionsElement> = spec
|
let definitions: Vec<&vkxml::DefinitionsElement> = spec
|
||||||
|
@ -1471,8 +1458,7 @@ pub fn write_source_code(path: &Path) {
|
||||||
.filter_map(|elem| match elem {
|
.filter_map(|elem| match elem {
|
||||||
vkxml::RegistryElement::Definitions(ref definitions) => Some(definitions),
|
vkxml::RegistryElement::Definitions(ref definitions) => Some(definitions),
|
||||||
_ => None,
|
_ => None,
|
||||||
})
|
}).flat_map(|definitions| definitions.elements.iter())
|
||||||
.flat_map(|definitions| definitions.elements.iter())
|
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
let enums: Vec<&vkxml::Enumeration> = spec
|
let enums: Vec<&vkxml::Enumeration> = spec
|
||||||
|
@ -1481,14 +1467,12 @@ pub fn write_source_code(path: &Path) {
|
||||||
.filter_map(|elem| match elem {
|
.filter_map(|elem| match elem {
|
||||||
vkxml::RegistryElement::Enums(ref enums) => Some(enums),
|
vkxml::RegistryElement::Enums(ref enums) => Some(enums),
|
||||||
_ => None,
|
_ => None,
|
||||||
})
|
}).flat_map(|enums| {
|
||||||
.flat_map(|enums| {
|
|
||||||
enums.elements.iter().filter_map(|_enum| match *_enum {
|
enums.elements.iter().filter_map(|_enum| match *_enum {
|
||||||
vkxml::EnumsElement::Enumeration(ref e) => Some(e),
|
vkxml::EnumsElement::Enumeration(ref e) => Some(e),
|
||||||
_ => None,
|
_ => None,
|
||||||
})
|
})
|
||||||
})
|
}).collect();
|
||||||
.collect();
|
|
||||||
|
|
||||||
let constants: Vec<&vkxml::Constant> = spec
|
let constants: Vec<&vkxml::Constant> = spec
|
||||||
.elements
|
.elements
|
||||||
|
@ -1496,8 +1480,7 @@ pub fn write_source_code(path: &Path) {
|
||||||
.filter_map(|elem| match elem {
|
.filter_map(|elem| match elem {
|
||||||
vkxml::RegistryElement::Constants(ref constants) => Some(constants),
|
vkxml::RegistryElement::Constants(ref constants) => Some(constants),
|
||||||
_ => None,
|
_ => None,
|
||||||
})
|
}).flat_map(|constants| constants.elements.iter())
|
||||||
.flat_map(|constants| constants.elements.iter())
|
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
let mut const_cache = HashSet::new();
|
let mut const_cache = HashSet::new();
|
||||||
|
@ -1525,8 +1508,7 @@ pub fn write_source_code(path: &Path) {
|
||||||
.filter_map(|def| match def {
|
.filter_map(|def| match def {
|
||||||
vkxml::DefinitionsElement::Union(ref union) => Some(union.name.as_str()),
|
vkxml::DefinitionsElement::Union(ref union) => Some(union.name.as_str()),
|
||||||
_ => None,
|
_ => None,
|
||||||
})
|
}).collect::<HashSet<&str>>();
|
||||||
.collect::<HashSet<&str>>();
|
|
||||||
|
|
||||||
let definition_code: Vec<_> = definitions
|
let definition_code: Vec<_> = definitions
|
||||||
.into_iter()
|
.into_iter()
|
||||||
|
|
Loading…
Reference in a new issue