Class: Kumi::Core::Analyzer::Passes::AttachAnchorsPass

Inherits:
PassBase
  • Object
show all
Defined in:
lib/kumi/core/analyzer/passes/attach_anchors_pass.rb

Constant Summary collapse

NAST =
Kumi::Core::NAST

Constants inherited from PassBase

PassBase::HALT

Instance Method Summary collapse

Methods inherited from PassBase

contract_declared?, #debug, #debug_enabled?, declared_optional_reads, declared_reads, declared_writes, #initialize, optional_reads, reads, writes

Methods included from ErrorReporting

#inferred_location, #raise_localized_error, #raise_syntax_error, #raise_type_error, #report_enhanced_error, #report_error, #report_semantic_error, #report_syntax_error, #report_type_error

Constructor Details

This class inherits a constructor from Kumi::Core::Analyzer::Passes::PassBase

Instance Method Details

#run(_errors) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/kumi/core/analyzer/passes/attach_anchors_pass.rb', line 14

def run(_errors)
  @snast = get_state(:snast_module, required: true)
  @cross_axes = get_state(:cross_axes, required: false) || {}
  @outer_axes = get_state(:outer_axes, required: false) || {}

  out = {}
  @snast.decls.each do |name, decl|
    out[name] ||= {}

    wanted = axes_of(decl)
    wanted = axes_of(decl.body) if wanted.empty?

    # No anchors needed for scalars (rank-0)
    next if wanted.empty?

    out[name][wanted] = pick_anchor_fqn(decl.body, wanted)
  end

  state.with(:anchor_by_decl, out.freeze)
end