From 25d7554ec4c20dc8ff2062ca8382978855879bb2 Mon Sep 17 00:00:00 2001 From: overlookmotel <557937+overlookmotel@users.noreply.github.com> Date: Sun, 3 Nov 2024 17:20:25 +0000 Subject: [PATCH] refactor(ast_tools): rename `visitable` to `is_visitable` (#7104) Pure refactor. Just rename fields and vars from `visitable` to `is_visitable`, to be more descriptive. --- tasks/ast_tools/src/generators/ast_builder.rs | 2 +- tasks/ast_tools/src/generators/ast_kind.rs | 2 +- tasks/ast_tools/src/generators/visit.rs | 12 ++++++------ tasks/ast_tools/src/rust_ast.rs | 18 +++++++++--------- tasks/ast_tools/src/schema/defs.rs | 10 +++++----- tasks/ast_tools/src/schema/mod.rs | 4 ++-- 6 files changed, 24 insertions(+), 24 deletions(-) diff --git a/tasks/ast_tools/src/generators/ast_builder.rs b/tasks/ast_tools/src/generators/ast_builder.rs index d402d3241c249..8dc320c8b9f59 100644 --- a/tasks/ast_tools/src/generators/ast_builder.rs +++ b/tasks/ast_tools/src/generators/ast_builder.rs @@ -26,7 +26,7 @@ impl Generator for AstBuilderGenerator { let fns = schema .defs .iter() - .filter(|it| it.visitable()) + .filter(|it| it.is_visitable()) .map(|it| generate_builder_fn(it, schema)) .collect_vec(); diff --git a/tasks/ast_tools/src/generators/ast_kind.rs b/tasks/ast_tools/src/generators/ast_kind.rs index 213f01eeb70de..0ea1184278f33 100644 --- a/tasks/ast_tools/src/generators/ast_kind.rs +++ b/tasks/ast_tools/src/generators/ast_kind.rs @@ -85,7 +85,7 @@ impl Generator for AstKindGenerator { .defs .iter() .filter(|def| { - let is_visitable = def.visitable(); + let is_visitable = def.is_visitable(); let is_blacklisted = BLACK_LIST.contains(&def.name()); is_visitable && !is_blacklisted }) diff --git a/tasks/ast_tools/src/generators/visit.rs b/tasks/ast_tools/src/generators/visit.rs index 39291f33ece0e..a3df85f3a0e59 100644 --- a/tasks/ast_tools/src/generators/visit.rs +++ b/tasks/ast_tools/src/generators/visit.rs @@ -149,7 +149,7 @@ impl<'a> VisitBuilder<'a> { .schema .defs .iter() - .filter(|it| it.visitable()) + .filter(|it| it.is_visitable()) .find(|it| it.name() == "Program") .expect("Couldn't find the `Program` type!"); @@ -179,7 +179,7 @@ impl<'a> VisitBuilder<'a> { fn get_visitor(&mut self, def: &TypeDef, collection: bool) -> Cow<'a, Ident> { let cache_ix = usize::from(collection); let (ident, as_type) = { - debug_assert!(def.visitable(), "{def:?}"); + debug_assert!(def.is_visitable(), "{def:?}"); let ident = def.ident(); let as_type = def.to_type(); @@ -305,8 +305,8 @@ impl<'a> VisitBuilder<'a> { let variant_name = &var.ident(); let type_id = typ.transparent_type_id()?; let def = self.schema.get(type_id)?; - let visitable = def.visitable(); - if visitable { + let is_visitable = def.is_visitable(); + if is_visitable { let visit = self.get_visitor(def, false); let (args_def, args) = var .markers @@ -337,7 +337,7 @@ impl<'a> VisitBuilder<'a> { let super_ = &it.super_; let type_name = super_.name().as_name().unwrap().to_string(); let def = super_.type_id().and_then(|id| self.schema.get(id))?; - if def.visitable() { + if def.is_visitable() { let snake_name = type_name.to_case(Case::Snake); let match_macro = format_ident!("match_{snake_name}"); let match_macro = quote!(#match_macro!(#ident)); @@ -429,7 +429,7 @@ impl<'a> VisitBuilder<'a> { .filter_map(|(ix, field)| { let analysis = field.typ.analysis(); let def = field.typ.transparent_type_id().and_then(|id| self.schema.get(id))?; - if !def.visitable() { + if !def.is_visitable() { return None; } let typ_wrapper = &analysis.wrapper; diff --git a/tasks/ast_tools/src/rust_ast.rs b/tasks/ast_tools/src/rust_ast.rs index b37a7ba7edb5b..ea0279b916bb4 100644 --- a/tasks/ast_tools/src/rust_ast.rs +++ b/tasks/ast_tools/src/rust_ast.rs @@ -33,7 +33,7 @@ pub struct EnumMeta { pub inherits: Vec, pub layout_32: Layout, pub layout_64: Layout, - pub visitable: bool, + pub is_visitable: bool, pub ast: bool, pub module_path: String, } @@ -44,7 +44,7 @@ impl EnumMeta { inherits: Vec::default(), layout_32: Layout::default(), layout_64: Layout::default(), - visitable: false, + is_visitable: false, ast: false, module_path, } @@ -78,7 +78,7 @@ impl Enum { pub struct StructMeta { pub layout_32: Layout, pub layout_64: Layout, - pub visitable: bool, + pub is_visitable: bool, pub ast: bool, pub module_path: String, } @@ -88,7 +88,7 @@ impl StructMeta { Self { layout_32: Layout::default(), layout_64: Layout::default(), - visitable: false, + is_visitable: false, ast: false, module_path, } @@ -180,10 +180,10 @@ impl AstType { } #[expect(unused)] - pub fn visitable(&self) -> bool { + pub fn is_visitable(&self) -> bool { match self { - AstType::Enum(it) => it.meta.visitable, - AstType::Struct(it) => it.meta.visitable, + AstType::Enum(it) => it.meta.is_visitable, + AstType::Struct(it) => it.meta.is_visitable, AstType::Macro(_) => false, } } @@ -192,11 +192,11 @@ impl AstType { match self { AstType::Enum(enum_) => { debug_assert!(enum_.meta.ast, "only AST types can be visitable!"); - enum_.meta.visitable = value; + enum_.meta.is_visitable = value; } AstType::Struct(struct_) => { debug_assert!(struct_.meta.ast, "only AST types can be visitable!"); - struct_.meta.visitable = value; + struct_.meta.is_visitable = value; } AstType::Macro(macro_) => return Err(unexpanded_macro_err(¯o_.item)), }; diff --git a/tasks/ast_tools/src/schema/defs.rs b/tasks/ast_tools/src/schema/defs.rs index 00f9ad7f4f20c..6a05e355e73c4 100644 --- a/tasks/ast_tools/src/schema/defs.rs +++ b/tasks/ast_tools/src/schema/defs.rs @@ -27,10 +27,10 @@ impl TypeDef { } } - pub fn visitable(&self) -> bool { + pub fn is_visitable(&self) -> bool { match self { - TypeDef::Struct(def) => def.visitable, - TypeDef::Enum(def) => def.visitable, + TypeDef::Struct(def) => def.is_visitable, + TypeDef::Enum(def) => def.is_visitable, } } @@ -60,7 +60,7 @@ pub struct StructDef { pub id: TypeId, pub name: String, #[serde(skip)] - pub visitable: bool, + pub is_visitable: bool, pub fields: Vec, #[serde(skip)] pub has_lifetime: bool, @@ -83,7 +83,7 @@ pub struct StructDef { pub struct EnumDef { pub id: TypeId, pub name: String, - pub visitable: bool, + pub is_visitable: bool, pub variants: Vec, /// For `@inherits` inherited enum variants pub inherits: Vec, diff --git a/tasks/ast_tools/src/schema/mod.rs b/tasks/ast_tools/src/schema/mod.rs index 12146c3de2f22..89e9b02e54ac5 100644 --- a/tasks/ast_tools/src/schema/mod.rs +++ b/tasks/ast_tools/src/schema/mod.rs @@ -170,7 +170,7 @@ fn lower_ast_enum(it @ rust::Enum { item, meta }: &rust::Enum, ctx: &EarlyCtx) - EnumDef { id: ctx.type_id(&it.ident().to_string()).unwrap(), name: it.ident().to_string(), - visitable: meta.visitable, + is_visitable: meta.is_visitable, variants: item .variants .iter() @@ -208,7 +208,7 @@ fn lower_ast_struct(it @ rust::Struct { item, meta }: &rust::Struct, ctx: &Early StructDef { id: ctx.type_id(&it.ident().to_string()).unwrap(), name: it.ident().to_string(), - visitable: meta.visitable, + is_visitable: meta.is_visitable, fields: item.fields.iter().map(|fi| lower_field(fi, ctx)).collect(), has_lifetime: item.generics.lifetimes().count() > 0,