Class: Cenit::Algorithms::Rewriter

Inherits:
Parser::Rewriter
  • Object
show all
Defined in:
lib/cenit/algorithms/rewriter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Rewriter

Returns a new instance of Rewriter.



9
10
11
12
13
14
# File 'lib/cenit/algorithms/rewriter.rb', line 9

def initialize(options = {})
  @options = options || {}
  @logs = options[:logs] || {}
  @self_linker = options[:self_linker]
  @interpreter = options[:interpreter]
end

Instance Attribute Details

#logsObject (readonly)

Returns the value of attribute logs.



7
8
9
# File 'lib/cenit/algorithms/rewriter.rb', line 7

def logs
  @logs
end

Instance Method Details

#on_send(node) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/cenit/algorithms/rewriter.rb', line 16

def on_send(node)
  super
  if node.children[0].nil? && node.type == :send
    method_name = node.children[1]
    if @self_linker && !@self_linker.link?(method_name)
      report_error("error linking #{method_name}")
    end
    (@logs[:self_sends] ||= Set.new) << method_name
    if @interpreter
      prefix = @interpreter.__prefix__(method_name, @self_linker)
      insert_before(node.location.expression, prefix)
    end
  end
end