Skip to content

Commit

Permalink
refactor(ast_tools): rename visitable to is_visitable (#7104)
Browse files Browse the repository at this point in the history
Pure refactor. Just rename fields and vars from `visitable` to `is_visitable`, to be more descriptive.
  • Loading branch information
overlookmotel committed Nov 3, 2024
1 parent 9ed9501 commit 25d7554
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 24 deletions.
2 changes: 1 addition & 1 deletion tasks/ast_tools/src/generators/ast_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
2 changes: 1 addition & 1 deletion tasks/ast_tools/src/generators/ast_kind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
})
Expand Down
12 changes: 6 additions & 6 deletions tasks/ast_tools/src/generators/visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!");

Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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;
Expand Down
18 changes: 9 additions & 9 deletions tasks/ast_tools/src/rust_ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ pub struct EnumMeta {
pub inherits: Vec<Inherit>,
pub layout_32: Layout,
pub layout_64: Layout,
pub visitable: bool,
pub is_visitable: bool,
pub ast: bool,
pub module_path: String,
}
Expand All @@ -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,
}
Expand Down Expand Up @@ -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,
}
Expand All @@ -88,7 +88,7 @@ impl StructMeta {
Self {
layout_32: Layout::default(),
layout_64: Layout::default(),
visitable: false,
is_visitable: false,
ast: false,
module_path,
}
Expand Down Expand Up @@ -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,
}
}
Expand All @@ -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(&macro_.item)),
};
Expand Down
10 changes: 5 additions & 5 deletions tasks/ast_tools/src/schema/defs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}

Expand Down Expand Up @@ -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<FieldDef>,
#[serde(skip)]
pub has_lifetime: bool,
Expand All @@ -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<VariantDef>,
/// For `@inherits` inherited enum variants
pub inherits: Vec<InheritDef>,
Expand Down
4 changes: 2 additions & 2 deletions tasks/ast_tools/src/schema/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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,

Expand Down

0 comments on commit 25d7554

Please sign in to comment.