Skip to content

Commit 283b3c4

Browse files
committed
update count visited.
1 parent 93165b7 commit 283b3c4

File tree

1 file changed

+26
-7
lines changed

1 file changed

+26
-7
lines changed

tasks/ast_codegen/src/generators/count_unvisited.rs

+26-7
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use syn::Fields;
2+
13
use crate::{schema::RType, CodegenCtx, Generator, GeneratorOutput};
24

35
pub struct CountUnvisited;
@@ -12,17 +14,34 @@ impl Generator for CountUnvisited {
1214
let (ast, visitable, unvisited_ids) =
1315
ctx.ty_table.iter().fold((0, 0, Vec::new()), |(mut ast, mut vis, mut ids), it| {
1416
let it = &*it.borrow();
15-
match it {
16-
RType::Enum(_) | RType::Struct(_) => {
17-
ast += 1;
18-
if it.visitable() {
19-
vis += 1;
17+
let typ = match it {
18+
RType::Enum(e) => {
19+
if e.item.variants.iter().any(|it| matches!(it.fields, Fields::Named(_))) {
20+
Some("enum with named fields")
21+
} else if e
22+
.item
23+
.variants
24+
.iter()
25+
.any(|it| matches!(it.fields, Fields::Unnamed(_)))
26+
{
27+
Some("enum with unnamed fields")
2028
} else {
21-
ids.push(it.ident().cloned().unwrap().to_string());
29+
Some("enum")
2230
}
2331
}
24-
_ => {}
32+
RType::Struct(_) => Some("struct"),
33+
_ => None,
34+
};
35+
36+
if let Some(typ) = typ {
37+
ast += 1;
38+
if it.visitable() {
39+
vis += 1;
40+
} else {
41+
ids.push(format!("{} {}", typ, it.ident().cloned().unwrap().to_string(),));
42+
}
2543
}
44+
ids.sort();
2645
(ast, vis, ids)
2746
});
2847

0 commit comments

Comments
 (0)