generator: Improve alias readability by using Self:: as type (#409)

All enumeration aliases already extend the base type by being placed in
its `impl` block. Use `Self::` instead of repeating the type name. DRY.
This commit is contained in:
Marijn Suijten 2021-03-26 20:13:16 +01:00 committed by GitHub
parent 8d60a7eec2
commit 5bc52dcd0a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 315 additions and 356 deletions

File diff suppressed because it is too large Load diff

View file

@ -211,7 +211,7 @@ impl StructureType {
#[doc = "Generated from 'VK_VERSION_1_1'"]
impl StructureType {
pub const PHYSICAL_DEVICE_VARIABLE_POINTER_FEATURES: Self =
StructureType::PHYSICAL_DEVICE_VARIABLE_POINTERS_FEATURES;
Self::PHYSICAL_DEVICE_VARIABLE_POINTERS_FEATURES;
}
#[doc = "Generated from 'VK_VERSION_1_1'"]
impl StructureType {
@ -547,7 +547,7 @@ impl StructureType {
#[doc = "Generated from 'VK_VERSION_1_1'"]
impl StructureType {
pub const PHYSICAL_DEVICE_SHADER_DRAW_PARAMETER_FEATURES: Self =
StructureType::PHYSICAL_DEVICE_SHADER_DRAW_PARAMETERS_FEATURES;
Self::PHYSICAL_DEVICE_SHADER_DRAW_PARAMETERS_FEATURES;
}
#[doc = "Generated from 'VK_VERSION_1_2'"]
impl StructureType {

View file

@ -437,7 +437,7 @@ pub enum Constant {
BitPos(u32),
CExpr(vkxml::CExpression),
Text(String),
Alias(Ident, Ident),
Alias(Ident),
}
impl quote::ToTokens for Constant {
@ -462,7 +462,7 @@ impl quote::ToTokens for Constant {
let bit_string = interleave_number('_', 4, &bit_string);
syn::LitInt::new(&format!("0b{}", bit_string), Span::call_site()).to_tokens(tokens);
}
Constant::Alias(ref base, ref value) => tokens.extend(quote!(#base::#value)),
Constant::Alias(ref value) => tokens.extend(quote!(Self::#value)),
}
}
}
@ -1065,12 +1065,11 @@ pub fn generate_extension_constants<'a>(
}
EnumSpec::Alias { alias, extends } => {
if let Some(extends) = extends {
let ident = name_to_tokens(&extends);
let key = variant_ident(&extends, &alias);
if key == "DISPATCH_BASE" {
None
} else {
Some((Constant::Alias(ident, key), Some(extends.clone()), true))
Some((Constant::Alias(key), Some(extends.clone()), true))
}
} else {
None
@ -1336,7 +1335,7 @@ pub fn bitflags_impl_block(
.map(|constant| {
let variant_ident = constant.variant_ident(enum_name);
let constant = constant.constant();
let tokens = if let Constant::Alias(_, _) = &constant {
let tokens = if let Constant::Alias(_) = &constant {
quote!(#constant)
} else {
quote!(Self(#constant))