Class: FastRuby::LocalsInference

Inherits:
Object
  • Object
show all
Defined in:
lib/fastruby/builder/locals_inference.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#infer_lvar_mapObject

Returns the value of attribute infer_lvar_map.



24
25
26
# File 'lib/fastruby/builder/locals_inference.rb', line 24

def infer_lvar_map
  @infer_lvar_map
end

#infer_selfObject

Returns the value of attribute infer_self.



23
24
25
# File 'lib/fastruby/builder/locals_inference.rb', line 23

def infer_self
  @infer_self
end

Instance Method Details

#call(arg) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/fastruby/builder/locals_inference.rb', line 26

def call(arg)
  if arg.find_tree{|subtree| subtree.node_type == :lvar && @infer_lvar_map[subtree[1]]}
    transform_block = proc do |tree|
      if tree.node_type == :lvar
        next tree unless @infer_lvar_map
        lvar_type = @infer_lvar_map[tree[1]]
        next tree unless lvar_type
        fs(:call, tree, :infer, fs(:arglist, fs(:const, lvar_type.to_s.to_sym)))
      elsif tree.node_type == :iter
        if tree[1][2] == :_static
          tree
        end
      elsif tree.node_type == :call
        if tree[2] == :infer
          tree[1]
        end
      else
        nil
      end
    end
    
    arg.transform &transform_block
  else      
    arg
  end
end