Class: Archruby::Ruby::VarPropagation
- Inherits:
-
Object
- Object
- Archruby::Ruby::VarPropagation
- Defined in:
- lib/archruby/ruby/var_propagation.rb
Instance Attribute Summary collapse
-
#vars ⇒ Object
readonly
Returns the value of attribute vars.
Instance Method Summary collapse
- #find_var(var_name) ⇒ Object
-
#initialize ⇒ VarPropagation
constructor
A new instance of VarPropagation.
- #push(var_name, line_number, type = nil) ⇒ Object
- #put_type(var_name, type) ⇒ Object
Constructor Details
#initialize ⇒ VarPropagation
Returns a new instance of VarPropagation.
6 7 8 |
# File 'lib/archruby/ruby/var_propagation.rb', line 6 def initialize @vars = [] end |
Instance Attribute Details
#vars ⇒ Object (readonly)
Returns the value of attribute vars.
4 5 6 |
# File 'lib/archruby/ruby/var_propagation.rb', line 4 def vars @vars end |
Instance Method Details
#find_var(var_name) ⇒ Object
35 36 37 38 39 40 41 42 |
# File 'lib/archruby/ruby/var_propagation.rb', line 35 def find_var var_name vars.each do | var | if var.keys.first == var_name return var end end return nil end |
#push(var_name, line_number, type = nil) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/archruby/ruby/var_propagation.rb', line 10 def push var_name, line_number, type = nil var = find_var var_name if var lines = var[var.keys.first][:lines] lines.push(line_number) else @vars.push( { var_name => { :lines => [line_number], :type => type } } ) end end |
#put_type(var_name, type) ⇒ Object
28 29 30 31 32 33 |
# File 'lib/archruby/ruby/var_propagation.rb', line 28 def put_type var_name, type var = find_var var_name if var var[var.keys.first][:type] = type end end |