class LatticeRefRewriter

Rewrite references to lattice identifiers that appear in rule bodies. A reference to a lattice identifier returns the associated lattice wrapper. When the identifier appears at the top-level of the rule RHS, that is fine (since we want the wrapper to do wiring). But for references that appear inside rule bodies, we want to instead fetch the current value associated with the lattice wrapper.

Public Class Methods

new(bud_instance) click to toggle source
Calls superclass method
# File lib/bud/rewrite.rb, line 415
def initialize(bud_instance)
  super()
  self.require_empty = false
  self.expected = Sexp
  @bud_instance = bud_instance
  @elem_stack = []
end

Public Instance Methods

is_lattice?(op) click to toggle source
# File lib/bud/rewrite.rb, line 460
def is_lattice?(op)
  @bud_instance.lattices.has_key? op.to_sym
end
process_array(exp) click to toggle source
# File lib/bud/rewrite.rb, line 432
def process_array(exp)
  new_body = exp.sexp_body.map {|t| push_and_process(t)}
  return s(:array, *new_body)
end
process_call(exp) click to toggle source
# File lib/bud/rewrite.rb, line 442
def process_call(exp)
  tag, recv, op, *args = exp

  if recv.nil? and args.empty? and is_lattice?(op) and @elem_stack.size > 0
    return s(:call, exp, :current_value)
  else
    return s(tag, process(recv), op, *(args.map{|a| process(a)}))
  end
end
process_hash(exp) click to toggle source
# File lib/bud/rewrite.rb, line 437
def process_hash(exp)
  new_body = exp.sexp_body.map {|t| push_and_process(t)}
  return s(:hash, *new_body)
end
process_iter(exp) click to toggle source
# File lib/bud/rewrite.rb, line 423
def process_iter(exp)
  tag, recv, iter_args, body = exp
  new_body = push_and_process(body)
  if (iter_args == 0)
    iter_args = s(:args)
  end
  return s(tag, process(recv), process(iter_args), new_body)
end
push_and_process(exp) click to toggle source
# File lib/bud/rewrite.rb, line 452
def push_and_process(exp)
  obj_id = exp.object_id
  @elem_stack.push(obj_id)
  rv = process(exp)
  raise Bud::Error unless @elem_stack.pop == obj_id
  return rv
end