Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(ast_tools): rename is_visited to has_visitor #8893

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions tasks/ast_tools/src/generators/ast_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ impl Generator for AstBuilderGenerator {
.types
.iter()
.filter(|&type_def| {
let is_visited = match type_def {
TypeDef::Struct(struct_def) => struct_def.visit.is_visited(),
TypeDef::Enum(enum_def) => enum_def.visit.is_visited(),
let has_visitor = match type_def {
TypeDef::Struct(struct_def) => struct_def.visit.has_visitor(),
TypeDef::Enum(enum_def) => enum_def.visit.has_visitor(),
_ => false,
};
let is_blacklisted = BLACK_LIST.contains(&type_def.name());
is_visited && !is_blacklisted
has_visitor && !is_blacklisted
})
.map(|type_def| generate_builder_methods(type_def, schema))
.collect::<TokenStream>();
Expand Down
4 changes: 2 additions & 2 deletions tasks/ast_tools/src/generators/ast_kind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,10 @@ impl Generator for AstKindGenerator {
for type_def in &mut schema.types {
match type_def {
TypeDef::Struct(struct_def) => {
struct_def.kind.has_kind = struct_def.visit.is_visited();
struct_def.kind.has_kind = struct_def.visit.has_visitor();
}
TypeDef::Enum(enum_def) => {
enum_def.kind.has_kind = enum_def.visit.is_visited();
enum_def.kind.has_kind = enum_def.visit.has_visitor();
}
_ => {}
}
Expand Down
16 changes: 8 additions & 8 deletions tasks/ast_tools/src/generators/visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,21 +46,21 @@ impl Generator for VisitGenerator {
}

/// Create names for `visit_*` methods and `walk_*` functions for all `Vec`s
/// whose inner type is visited.
/// whose inner type has a visitor.
fn prepare(&self, schema: &mut Schema) {
for type_id in schema.types.indices() {
let Some(vec_def) = schema.types[type_id].as_vec() else { continue };

let inner_type = vec_def.inner_type(schema);
let plural_snake_name = match inner_type {
TypeDef::Struct(struct_def) => {
if !struct_def.visit.is_visited() {
if !struct_def.visit.has_visitor() {
continue;
}
struct_def.plural_snake_name()
}
TypeDef::Enum(enum_def) => {
if !enum_def.visit.is_visited() {
if !enum_def.visit.has_visitor() {
continue;
}
enum_def.plural_snake_name()
Expand Down Expand Up @@ -136,7 +136,7 @@ fn parse_visit_attr(location: AttrLocation, part: AttrPart) -> Result<()> {
/// Parse `#[scope]` attr.
fn parse_scope_attr(location: AttrLocation, part: AttrPart) -> Result<()> {
fn get_or_create_scope(struct_def: &mut StructDef) -> Result<&mut Scope> {
if !struct_def.visit.is_visited() {
if !struct_def.visit.has_visitor() {
return Err(());
}

Expand Down Expand Up @@ -566,8 +566,8 @@ impl VisitBuilder<'_> {
let inner_visit_fn_name = inherits_type.visit.visitor_name();
let Some(inner_visit_fn_name) = inner_visit_fn_name else {
panic!(
"When an enum inherits variants from another enum and the inheritor is visited, \
the inherited enum must also be visited: `{}` inheriting from `{}`",
"When an enum inherits variants from another enum and the inheritor has a visitor, \
the inherited enum must also have a visitor: `{}` inheriting from `{}`",
enum_def.name(),
inherits_type.name(),
);
Expand Down Expand Up @@ -867,7 +867,7 @@ impl VisitBuilder<'_> {

/// Generate visitor calls for a `Vec`.
///
/// If `Vec` has its own visitor (it does when inner type is a struct or enum which is visited),
/// If `Vec` has its own visitor (it does when inner type is a struct or enum which has a visitor),
/// generates a call to that visitor e.g. `visitor.visit_statements(&it.statements)`.
///
/// Otherwise, generates code to loop through the `Vec`'s elements and call the inner type's visitor:
Expand Down Expand Up @@ -897,7 +897,7 @@ impl VisitBuilder<'_> {
trailing_semicolon: bool,
) -> Option<(/* visit */ TokenStream, /* visit_mut */ TokenStream)> {
if let Some(visit_fn_name) = vec_def.visit.visitor_name() {
// Inner type is a struct or enum which is visited. This `Vec` has own visitor.
// Inner type is a struct or enum which has a visitor. This `Vec` has its own visitor.
let visit_fn_ident = create_ident(visit_fn_name);
return Some(Self::generate_visit_with_visit_args(
&visit_fn_ident,
Expand Down
18 changes: 9 additions & 9 deletions tasks/ast_tools/src/schema/extensions/visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ pub struct VisitStruct {
}

impl VisitStruct {
/// Returns `true` if this struct is visited.
pub fn is_visited(&self) -> bool {
/// Returns `true` if this struct has a visitor.
pub fn has_visitor(&self) -> bool {
self.visitor_names.is_some()
}

/// Get name of visitor method for this struct, if it is visited.
/// Get name of visitor method for this struct, if it has a visitor.
pub fn visitor_name(&self) -> Option<&str> {
self.visitor_names.as_ref().map(|names| names.visit.as_str())
}
Expand All @@ -29,12 +29,12 @@ pub struct VisitEnum {
}

impl VisitEnum {
/// Returns `true` if this enum is visited.
pub fn is_visited(&self) -> bool {
/// Returns `true` if this enum has a visitor.
pub fn has_visitor(&self) -> bool {
self.visitor_names.is_some()
}

/// Get name of visitor method for this enum, if it is visited.
/// Get name of visitor method for this enum, if it has a visitor.
pub fn visitor_name(&self) -> Option<&str> {
self.visitor_names.as_ref().map(|names| names.visit.as_str())
}
Expand All @@ -49,13 +49,13 @@ pub struct VisitVec {
}

impl VisitVec {
/// Returns `true` if this `Vec` is visited.
/// Returns `true` if this `Vec` has a visitor.
#[expect(dead_code)]
pub fn is_visited(&self) -> bool {
pub fn has_visitor(&self) -> bool {
self.visitor_names.is_some()
}

/// Get name of visitor method for this `Vec`, if it is visited.
/// Get name of visitor method for this `Vec`, if it has a visitor.
pub fn visitor_name(&self) -> Option<&str> {
self.visitor_names.as_ref().map(|names| names.visit.as_str())
}
Expand Down
Loading