| 1 | // Copyright (c) 2026 Alexander Medvednikov. All rights reserved. |
| 2 | // Use of this source code is governed by an MIT license |
| 3 | // that can be found in the LICENSE file. |
| 4 | module markused |
| 5 | |
| 6 | import v2.ast |
| 7 | import v2.types |
| 8 | |
| 9 | // mark_used_flat is the flat-input entry point for the markused pass. It |
| 10 | // accepts a FlatAst — the canonical post-parse representation — instead of |
| 11 | // a rehydrated []ast.File. |
| 12 | // |
| 13 | // The collect_defs phase reads each file's imports and top-level stmts via |
| 14 | // FlatAst.read_file_imports / FileCursor.stmts, so the per-file File struct |
| 15 | // (with its attribute/import/stmt slices and selector_names map) is never |
| 16 | // materialized. Function bodies are still decoded as legacy ast.Stmt and |
| 17 | // stored in FnInfo for walk_collected — that phase is the next slice to |
| 18 | // port. The differential harness in markused_diff_test.v guards |
| 19 | // bit-for-bit equality with the legacy walker at every step. |
| 20 | pub fn mark_used_flat(flat &ast.FlatAst, env &types.Environment) map[string]bool { |
| 21 | return mark_used_flat_with_options(flat, env, MarkUsedOptions{}) |
| 22 | } |
| 23 | |
| 24 | pub fn mark_used_flat_with_options(flat &ast.FlatAst, env &types.Environment, opts MarkUsedOptions) map[string]bool { |
| 25 | mut w := new_walker([]ast.File{}, env, opts) |
| 26 | w.collect_defs_from_flat(flat) |
| 27 | return w.walk_collected_from_flat(flat) |
| 28 | } |
| 29 | |