Class: RenameRewriter

Inherits:
SexpProcessor
  • Object
show all
Defined in:
lib/bud/rewrite.rb

Overview

Look for rename statements and define the necessary scratch collections

Instance Method Summary collapse

Constructor Details

#initialize(bud_instance) ⇒ RenameRewriter

Returns a new instance of RenameRewriter



313
314
315
316
317
318
# File 'lib/bud/rewrite.rb', line 313

def initialize(bud_instance)
  super()
  self.require_empty = false
  self.expected = Sexp
  @bud_instance = bud_instance
end

Instance Method Details

#process_call(exp) ⇒ Object



330
331
332
333
334
335
336
337
338
339
340
# File 'lib/bud/rewrite.rb', line 330

def process_call(exp)
  tag, recv, op, *args = exp

  if op == :rename
    raise Bud::CompileError, "reduce takes two arguments" unless args.size == 2
    namelit, schemahash = args
    register_scratch(namelit[1], schemahash)
  end

  return s(tag, process(recv), op, *(args.map{|a| process(a)}))
end

#register_scratch(name, schemahash) ⇒ Object



320
321
322
323
324
325
326
327
328
# File 'lib/bud/rewrite.rb', line 320

def register_scratch(name, schemahash)
  # define a scratch with the name and schema in this rename block
  hash, key_array, val_array = schemahash
  key_array ||= []
  val_array ||= []
  key_cols = key_array.map{|i| i[1] if i.class <= Sexp}.compact
  val_cols = val_array.map{|i| i[1] if i.class <= Sexp}.compact
  @bud_instance.scratch(name, key_cols=>val_cols)
end