class SyntaxTree::YARV::DataFlowGraph

def verify

Verify that we constructed the data flow graph correctly.
def verify
  # Check that the first block has no arguments.
  raise unless block_flows.fetch(blocks.first.id).in.empty?
  # Check all control flow edges between blocks pass the right number of
  # arguments.
  blocks.each do |block|
    block_flow = block_flows.fetch(block.id)
    if block.outgoing_blocks.empty?
      # With no outgoing blocks, there should be no output arguments.
      raise unless block_flow.out.empty?
    else
      # Check with outgoing blocks...
      block.outgoing_blocks.each do |outgoing_block|
        outgoing_flow = block_flows.fetch(outgoing_block.id)
        # The block should have as many output arguments as the
        # outgoing block has input arguments.
        raise unless block_flow.out.size == outgoing_flow.in.size
      end
    end
  end
end