Class: Furnace::AVM2::Transform::PropagateLabels

Inherits:
Object
  • Object
show all
Includes:
Visitor
Defined in:
lib/furnace-avm2/transform/propagate_labels.rb

Instance Method Summary collapse

Instance Method Details

#on_any(node) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/furnace-avm2/transform/propagate_labels.rb', line 12

def on_any(node)
  return if node.type == :root

  label = nil

  node.children.each do |child|
    if child.is_a?(AST::Node) && child.[:label]
      if label.nil? || child.[:label] < label
        label = child.[:label]
      end

      child..delete :label
    end
  end

  node.[:label] = label if label
end

#transform(ast, *stuff) ⇒ Object



6
7
8
9
10
# File 'lib/furnace-avm2/transform/propagate_labels.rb', line 6

def transform(ast, *stuff)
  visit ast      # propagate labels

  [ ast, *stuff ]
end