[blang-ast][U1] Source locations end to end - #129
Conversation
Phase-1 spec ceremony output for unit U1 (REQ-001): - spec.md: user stories, FR-001..FR-010, success criteria, assumptions - plan.md: technical context, constitution check, structure, strategy - research.md: decisions R1-R8 grounded in verified code facts - data-model.md, contracts/dump-locations-cli.md, quickstart.md - tasks.md: T001-T020 ending with per-unit gates (evaluation.md) - checklists/requirements.md: spec quality checklist (all pass) No implementation in this commit.
REQ-001: every AST node carries an accurate SourceLocation {file,line,col}.
Lexer/reader:
- LexerReader counts 1-based line/col in popChar (single consumption funnel)
and retains the filename; fixes the multi-line-token line-drift bug
(newlines inside string/char constants are now counted).
- SymbolInfo widened to freeze each token's line/col at scan time, so
positions survive symbol-list replay / setCurrentPos backtracking.
- Lexer::getTokenLocation()/getFileName(); getLineNumber/Position delegate
to the current token. Per-token stdout echo gated behind setTraceEnabled.
AST + parser:
- New SourceLocation.h value type; mLocation + accessors on Statement,
Symbol, Type bases (no common base introduced — parser shape frozen).
- Every Parse factory stamps its node at the construct's first token;
expression parser stamps primaries/postfix/binary nodes; assignment and
desugared nodes inherit the leftmost/originating location. No reachable
node keeps line/col 0 (verified over all 113 pass files).
Diagnostics:
- CompileError carries a SourceLocation snapshotted at throw time via
COMPILE_ERROR; reporting no longer reads the live lexer. Message FORMAT
unchanged (U2 owns reformatting); C++ __FILE__/__LINE__ retained for a
future --debug-compiler mode.
Tooling:
- qcc --dump-locations: deterministic pre-order <file>:<line>:<col>
<NodeKind> dump via new LocationDumper (typeid-demangled kinds). Implies
parse-only, no LLVM dependency, byte-clean stdout.
- Two committed goldens: test_files/golden/{func_simple,match_basic}.locations.
- CMakeLists, CLAUDE.md updated.
Gates (all green): run_tests.sh 162/162 (LLVM) + 154/154 (parse-only);
test_codegen.sh 63/63; leak-check concurrency subset 6/6 0 leaks; both
golden diffs exit 0; corpus zero-location check clean; LLVM/parse-only dump
parity; deterministic across runs.
Phase 3 (Implement) complete — ready for code auditAll per-unit gates from evaluation.md were run locally and are green: Gate A — LLVM build, full suites
Gate B — parse-only build
U1-specific checks (evaluation.md §Unit-specific)
Gate C — leak-check (sanity; U1 touches no runtime/ARC)
Note on Gate D (quiet-compile): NOT expected to pass at U1 — quiet-by-default is U2's scope. Default-mode stdout is intentionally unchanged; Auditor notes folded in: (1) COMPILE_ERROR count corrected to ~215 in spec docs; (2) corpus smoke check added to quickstart.md and run; (3) T008 covered QProtocolDefinition.cpp (QParser.cpp is an empty placeholder — no stamping needed). Diffstat: 26 files changed (+387/−68); 3 new files (SourceLocation.h, LocationDumper.h/.cpp) + 2 goldens. |
Unit U1 — Phase 1 (create spec) — DRAFT, no implementation yet
Epic: blang-ast (docs/epics/blang-ast/). Covers REQ-001: every AST node carries a source location (file, line, column).
Speckit artifacts (specs/001-source-locations/)
Unit done-when (workplan.md U1)
--dump-locationsflag; two committed goldens (test_files/golden/{func_simple,match_basic}.locations); both diffs exit 0; no node at line/col 0; all suites green in both build modes.For the spec audit (Phase 2)
Please apply the Spec audit rubric in docs/epics/blang-ast/evaluation.md. Implementation (Phase 3) will not begin until this spec is approved.