Skip to content

Commit

Permalink
update count visited.
Browse files Browse the repository at this point in the history
  • Loading branch information
rzvxa committed Jun 24, 2024
1 parent 93165b7 commit 283b3c4
Showing 1 changed file with 26 additions and 7 deletions.
33 changes: 26 additions & 7 deletions tasks/ast_codegen/src/generators/count_unvisited.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use syn::Fields;

use crate::{schema::RType, CodegenCtx, Generator, GeneratorOutput};

pub struct CountUnvisited;
Expand All @@ -12,17 +14,34 @@ impl Generator for CountUnvisited {
let (ast, visitable, unvisited_ids) =
ctx.ty_table.iter().fold((0, 0, Vec::new()), |(mut ast, mut vis, mut ids), it| {
let it = &*it.borrow();
match it {
RType::Enum(_) | RType::Struct(_) => {
ast += 1;
if it.visitable() {
vis += 1;
let typ = match it {
RType::Enum(e) => {
if e.item.variants.iter().any(|it| matches!(it.fields, Fields::Named(_))) {
Some("enum with named fields")
} else if e
.item
.variants
.iter()
.any(|it| matches!(it.fields, Fields::Unnamed(_)))
{
Some("enum with unnamed fields")
} else {
ids.push(it.ident().cloned().unwrap().to_string());
Some("enum")
}
}
_ => {}
RType::Struct(_) => Some("struct"),
_ => None,
};

if let Some(typ) = typ {
ast += 1;
if it.visitable() {
vis += 1;
} else {
ids.push(format!("{} {}", typ, it.ident().cloned().unwrap().to_string(),));
}
}
ids.sort();
(ast, vis, ids)
});

Expand Down

0 comments on commit 283b3c4

Please sign in to comment.