Class: FastRuby::InferenceUpdater

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

Defined Under Namespace

Classes: AddInfer

Instance Method Summary collapse

Constructor Details

#initialize(inferencer) ⇒ InferenceUpdater

Returns a new instance of InferenceUpdater.



44
45
46
# File 'lib/fastruby/builder/inference_updater.rb', line 44

def initialize(inferencer)
  @inferencer = inferencer
end

Instance Method Details

#call(tree) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/fastruby/builder/inference_updater.rb', line 48

def call(tree)
  variable_hash = Hash.new
  
  # search variable assignments
  tree.walk_tree do |subtree|
    if subtree.node_type == :lasgn and subtree[2]
      types = @inferencer.infer(subtree[2])
      lname = subtree[1]
      if types.size == 1
        if variable_hash[lname]
          if variable_hash[lname] != types.first
            variable_hash[lname] = :dynamic
          end
        else
          variable_hash[lname] = types.first
        end
      elsif types.size == 0
        variable_hash[lname] = :dynamic
      end 
    end
  end
  
  add_infer = AddInfer.new
  add_infer.variable_hash = variable_hash
  
  add_infer.process(tree)
end