Skip to content

Add optional rfl::SourceMap support to rfl::yaml::read and rfl::yaml::load - #45

Closed
clockblocker wants to merge 1 commit into
wave-base-15from
yaml-source-map
Closed

clockblocker wants to merge 1 commit into
wave-base-15from
yaml-source-map

Conversation

@clockblocker

@clockblocker clockblocker commented Nov 25, 2026 •

Copy link
Copy Markdown
Owner

Part 4 of 4 (split from #40; stacked on #44).

Summary

  • Adds an opt-in rfl::SourceMap type mapping ErrorDetail::PathSegment paths to value/key rfl::SourceLocation entries (plus find_nearest fallback to the deepest enclosing ancestor with exact = false, including when a matched node itself has no recorded value location).
  • Keeps non-template SourceMap implementation out-of-line in src/rfl/SourceMap.cpp via Pimpl (no <map> in header) and keeps SourceMap.hpp out of umbrella include/rfl.hpp so non-YAML TUs pay no compile-time cost; all lookup methods and operator== are noexcept.
  • Uses a bounds-safe SourceMap::Builder + opaque SourceMap::NodeId (checking for duplicate keys before pushing so no orphan nodes are ever allocated and duplicate subtrees are skipped cleanly).
  • Exposes RFL_API rfl::yaml::build_source_map(const YAML::Node&) in src/rfl/yaml/Reader.cpp reusing Reader::ActiveNodeGuard (recursing only into maps/sequences, never scalar leaves), and adds SourceMap* overloads on rfl::yaml::read and rfl::yaml::load.
  • Documents rfl::SourceMap in docs/content/supported_formats/yaml.md and adds tests in tests/yaml/test_source_map.cpp.

Verification

  • Full shared-library CMake suite (-DREFLECTCPP_BUILD_SHARED=ON -DREFLECTCPP_JSON=ON -DREFLECTCPP_YAML=ON -DREFLECTCPP_STRICT_WARNINGS=ON with -fvisibility=hidden): 631/631 passed.
  • C++20 and C++23 (-DREFLECTCPP_USE_STD_EXPECTED) self-contained header and test compile checks passed.

…:load

Add an opt-in rfl::SourceMap type mapping ErrorDetail::PathSegment paths to
rfl::SourceLocation entries (value and mapping key locations, plus
find_nearest fallback to the deepest enclosing ancestor with exact = false).

- Move the non-template SourceMap implementation out of the header into
  src/rfl/SourceMap.cpp (via Pimpl) and keep SourceMap.hpp out of the
  umbrella rfl.hpp header so non-YAML TUs pay no compile-time cost.
- Replace raw node-index mutators with a bounds-safe SourceMap::Builder
  and opaque SourceMap::NodeId.
- Expose RFL_API rfl::yaml::build_source_map(const YAML::Node&) in
  src/rfl/yaml/Reader.cpp, reusing Reader::ActiveNodeGuard for cycle safety.
- Add SourceMap* overloads for rfl::yaml::read and rfl::yaml::load that
  clear the map up front and populate it on success.
@clockblocker

Copy link
Copy Markdown
Owner Author

Branch is preserved on fork and showcase/all-lanes (d0f1fca1) as a reference artifact and parked in #117 (Moonshots & Possible Scope Creep).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant