feature. See also
. The project being documented here (as the example) is the Zig library itself.
Walk.walkBlock
fn walkBlock(
w: *Walk,
block_node: Ast.Node.Index,
statements: []const Ast.Node.Index,
) Error!void
File
Code
fn walkBlock(
w: *Walk,
block_node: Ast.Node.Index,
statements: []const Ast.Node.Index,
) Error!void {
_ = block_node;
const ast = w.ast;
for (statements) |stmt| {
switch (ast.nodeTag(stmt)) {
.global_var_decl,
.local_var_decl,
.simple_var_decl,
.aligned_var_decl,
=> {
const var_decl = ast.fullVarDecl(stmt).?;
if (var_decl.ast.init_node != .none and
isUndefinedIdent(w.ast, var_decl.ast.init_node.unwrap().?))
{
try w.transformations.append(.{ .delete_var_decl = .{
.var_decl_node = stmt,
.references = .empty,
} });
const name_tok = var_decl.ast.mut_token + 1;
const name_bytes = ast.tokenSlice(name_tok);
try w.replace_names.put(w.gpa, name_bytes, @intCast(w.transformations.items.len - 1));
} else {
try walkLocalVarDecl(w, var_decl);
}
},
else => {
switch (categorizeStmt(ast, stmt)) {
.discard_identifier => {},
.discard_undefined, .trap_call, .other => {
try w.transformations.append(.{ .delete_node = stmt });
},
}
try walkExpression(w, stmt);
},
}
}
}