| ... | ... | @@ -52,6 +52,7 @@ const Stats = struct { |
| 52 | 52 | files: u32, |
| 53 | 53 | tokens: u64, |
| 54 | 54 | nodes: u64, |
| 55 | source_size: u64, |
| 55 | 56 | /// Count per token tag index |
| 56 | 57 | token_stats: []u64, |
| 57 | 58 | /// Count per node tag index |
| ... | ... | @@ -208,6 +209,7 @@ pub fn run(gpa: Allocator, arena: Allocator, io: Io, args: []const []const u8) ! |
| 208 | 209 | .files = 0, |
| 209 | 210 | .tokens = 0, |
| 210 | 211 | .nodes = 0, |
| 212 | .source_size = 0, |
| 211 | 213 | .serializer = .{ .writer = &stdout_writer.interface }, |
| 212 | 214 | .root_struct = try stats.serializer.beginStruct(.{}), |
| 213 | 215 | .token_stats = try arena.alloc(u64, @typeInfo(std.zig.Token.Tag).@"enum".field_names.len), |
| ... | ... | @@ -243,6 +245,7 @@ pub fn run(gpa: Allocator, arena: Allocator, io: Io, args: []const []const u8) ! |
| 243 | 245 | try agg_struct.field("file_count", stats.files, .{}); |
| 244 | 246 | try agg_struct.field("token_count", stats.tokens, .{}); |
| 245 | 247 | try agg_struct.field("node_count", stats.nodes, .{}); |
| 248 | try agg_struct.field("source_size", stats.source_size, .{}); |
| 246 | 249 | |
| 247 | 250 | const token_names = @typeInfo(std.zig.Token.Tag).@"enum".field_names; |
| 248 | 251 | const node_names = @typeInfo(std.zig.Ast.Node.Tag).@"enum".field_names; |
| ... | ... | @@ -430,6 +433,7 @@ fn fmtPathFile( |
| 430 | 433 | |
| 431 | 434 | try zon_struct.field("token_count", tree.tokens.len, .{}); |
| 432 | 435 | try zon_struct.field("node_count", tree.nodes.len, .{}); |
| 436 | try zon_struct.field("source_size", stat.size, .{}); |
| 433 | 437 | |
| 434 | 438 | const token_names = @typeInfo(std.zig.Token.Tag).@"enum".field_names; |
| 435 | 439 | const node_names = @typeInfo(std.zig.Ast.Node.Tag).@"enum".field_names; |
| ... | ... | @@ -480,6 +484,7 @@ fn fmtPathFile( |
| 480 | 484 | stats.tokens += tree.tokens.len; |
| 481 | 485 | stats.nodes += tree.nodes.len; |
| 482 | 486 | stats.files += 1; |
| 487 | stats.source_size += stat.size; |
| 483 | 488 | } |
| 484 | 489 | |
| 485 | 490 | // As a heuristic, we make enough capacity for the same as the input source. |