Class: Ibex::Frontend::Resolution
- Inherits:
-
Object
- Object
- Ibex::Frontend::Resolution
- Defined in:
- lib/ibex/frontend/resolution.rb,
sig/ibex/frontend/resolution.rbs
Overview
Immutable result of resolving one root grammar and its fragment closure.
Constant Summary collapse
- EMPTY_CHAIN =
Array.new(0).freeze
Instance Attribute Summary collapse
- #files ⇒ Array[String] readonly
- #root ⇒ AST::Root readonly
- #root_directory ⇒ String readonly
- #root_path ⇒ String readonly
Instance Method Summary collapse
- #copy_provenance(entry) ⇒ IR::source_provenance
- #deep_freeze_ast(value) ⇒ Object
- #include_chain_for(rule) ⇒ Array[IR::source_provenance]
-
#initialize(root:, root_path:, root_directory:, files:, include_chains:) ⇒ Resolution
constructor
A new instance of Resolution.
Constructor Details
#initialize(root:, root_path:, root_directory:, files:, include_chains:) ⇒ Resolution
Returns a new instance of Resolution.
17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/ibex/frontend/resolution.rb', line 17 def initialize(root:, root_path:, root_directory:, files:, include_chains:) @root = deep_freeze_ast(root) @root_path = root_path.dup.freeze @root_directory = root_directory.dup.freeze @files = files.map { |file| file.dup.freeze }.freeze chains = {} #: Hash[AST::Rule, Array[IR::source_provenance]] @include_chains = chains.compare_by_identity include_chains.each do |rule, chain| frozen_chain = chain.map { |entry| copy_provenance(entry) }.freeze @include_chains[rule] = frozen_chain end @include_chains.freeze freeze end |
Instance Attribute Details
#files ⇒ Array[String] (readonly)
13 14 15 |
# File 'lib/ibex/frontend/resolution.rb', line 13 def files @files end |
#root ⇒ AST::Root (readonly)
10 11 12 |
# File 'lib/ibex/frontend/resolution.rb', line 10 def root @root end |
#root_directory ⇒ String (readonly)
12 13 14 |
# File 'lib/ibex/frontend/resolution.rb', line 12 def root_directory @root_directory end |
#root_path ⇒ String (readonly)
11 12 13 |
# File 'lib/ibex/frontend/resolution.rb', line 11 def root_path @root_path end |
Instance Method Details
#copy_provenance(entry) ⇒ IR::source_provenance
56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/ibex/frontend/resolution.rb', line 56 def copy_provenance(entry) span = entry[:byte_span] frozen_span = span && { start: span[:start], end: span[:end] } #: IR::byte_span? frozen_span&.freeze provenance = { file: entry[:file]&.dup&.freeze, root: entry[:root]&.dup&.freeze, byte_span: frozen_span } #: IR::source_provenance provenance.freeze end |
#deep_freeze_ast(value) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/ibex/frontend/resolution.rb', line 40 def deep_freeze_ast(value) case value when Struct value.each_pair { |_name, child| deep_freeze_ast(child) } when Array value.each { |child| deep_freeze_ast(child) } when Hash value.each do |key, child| deep_freeze_ast(key) deep_freeze_ast(child) end end value.freeze end |
#include_chain_for(rule) ⇒ Array[IR::source_provenance]
33 34 35 |
# File 'lib/ibex/frontend/resolution.rb', line 33 def include_chain_for(rule) @include_chains.fetch(rule, EMPTY_CHAIN) end |