pub const Fixups = struct unused_var_decls: std.AutoHashMapUnmanaged(Ast.TokenIndex, void) = .emptyThe key is the mut token (var/const) of the variable declaration that should have a _ = foo; inserted afterwards.
gut_functions: std.AutoHashMapUnmanaged(Ast.Node.Index, void) = .emptyThe functions in this unordered set of AST fn decl nodes will render with a function body of @trap() instead, with all parameters discarded.
omit_nodes: std.AutoHashMapUnmanaged(Ast.Node.Index, void) = .emptyThese global declarations will be omitted.
replace_nodes_with_string: std.AutoHashMapUnmanaged(Ast.Node.Index, []const u8) = .emptyThese expressions will be replaced with the string value.
append_string_after_node: std.AutoHashMapUnmanaged(Ast.Node.Index, []const u8) = .emptyThe string value will be inserted directly after the node.
replace_nodes_with_node: std.AutoHashMapUnmanaged(Ast.Node.Index, Ast.Node.Index) = .emptyThese nodes will be replaced with a different node.
rename_identifiers: std.array_hash_map.String([]const u8) = .emptyChange all identifier names matching the key to be value instead.
rebase_imported_paths: ?[]const u8 = nullAll @import builtin calls which refer to a file path will be prefixed with this path.
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84pub const Fixups = struct {
/// The key is the mut token (`var`/`const`) of the variable declaration
/// that should have a `_ = foo;` inserted afterwards.
unused_var_decls: std.AutoHashMapUnmanaged(Ast.TokenIndex, void) = .empty,
/// The functions in this unordered set of AST fn decl nodes will render
/// with a function body of `@trap()` instead, with all parameters
/// discarded.
gut_functions: std.AutoHashMapUnmanaged(Ast.Node.Index, void) = .empty,
/// These global declarations will be omitted.
omit_nodes: std.AutoHashMapUnmanaged(Ast.Node.Index, void) = .empty,
/// These expressions will be replaced with the string value.
replace_nodes_with_string: std.AutoHashMapUnmanaged(Ast.Node.Index, []const u8) = .empty,
/// The string value will be inserted directly after the node.
append_string_after_node: std.AutoHashMapUnmanaged(Ast.Node.Index, []const u8) = .empty,
/// These nodes will be replaced with a different node.
replace_nodes_with_node: std.AutoHashMapUnmanaged(Ast.Node.Index, Ast.Node.Index) = .empty,
/// Change all identifier names matching the key to be value instead.
rename_identifiers: std.array_hash_map.String([]const u8) = .empty,
/// All `@import` builtin calls which refer to a file path will be prefixed
/// with this path.
rebase_imported_paths: ?[]const u8 = null,
pub fn count(f: Fixups) usize {
return f.unused_var_decls.count() +
f.gut_functions.count() +
f.omit_nodes.count() +
f.replace_nodes_with_string.count() +
f.append_string_after_node.count() +
f.replace_nodes_with_node.count() +
f.rename_identifiers.count() +
@intFromBool(f.rebase_imported_paths != null);
}
pub fn clearRetainingCapacity(f: *Fixups) void {
f.unused_var_decls.clearRetainingCapacity();
f.gut_functions.clearRetainingCapacity();
f.omit_nodes.clearRetainingCapacity();
f.replace_nodes_with_string.clearRetainingCapacity();
f.append_string_after_node.clearRetainingCapacity();
f.replace_nodes_with_node.clearRetainingCapacity();
f.rename_identifiers.clearRetainingCapacity();
f.rebase_imported_paths = null;
}
pub fn deinit(f: *Fixups, gpa: Allocator) void {
f.unused_var_decls.deinit(gpa);
f.gut_functions.deinit(gpa);
f.omit_nodes.deinit(gpa);
f.replace_nodes_with_string.deinit(gpa);
f.append_string_after_node.deinit(gpa);
f.replace_nodes_with_node.deinit(gpa);
f.rename_identifiers.deinit(gpa);
f.* = undefined;
}
}