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