Module: Laser::Analysis::ControlFlow::AliasAnalysis

Included in:
ControlFlowGraph
Defined in:
lib/laser/analysis/control_flow/alias_analysis.rb

Overview

Finds the properties of how the code yields to a block argument. Should not be used on top-level code, naturally.

Instance Method Summary collapse

Instance Method Details

#value_aliases(value_to_match) ⇒ Object



25
26
27
# File 'lib/laser/analysis/control_flow/alias_analysis.rb', line 25

def value_aliases(value_to_match)
  value_to_match ? all_variables.select { |var| var.value == value_to_match} : []
end

#weak_local_aliases_for(initial, value_to_match = nil) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/laser/analysis/control_flow/alias_analysis.rb', line 7

def weak_local_aliases_for(initial, value_to_match = nil)
  good_blocks = reachable_vertices
  aliases = initial
  aliases.merge(value_aliases(value_to_match))
  worklist = aliases.map(&:uses).inject(:|)
  until worklist.empty?
    use = worklist.pop
    if use[1] && good_blocks.include?(use.block)
      if use[1] != :alias && aliases.add?(use[1])
        worklist.merge(use[1].uses)
      elsif use[1] == :alias && aliases.add?(use[2])
        worklist.merge(use[2].uses)
      end
    end
  end
  aliases
end