Class: Rubex::AST::Expression::RubyObjectElementRef
- Inherits:
-
AnalysedElementRef
- Object
- Base
- AnalysedElementRef
- Rubex::AST::Expression::RubyObjectElementRef
- Defined in:
- lib/rubex/ast/expression/analysed_element_ref/ruby_object_element_ref.rb
Direct Known Subclasses
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
- #analyse_types(local_scope) ⇒ Object
- #generate_assignment_code(rhs, code, local_scope) ⇒ Object
-
#generate_element_ref_code(expr, code, local_scope) ⇒ Object
Generate code for calls to array_ref inside structs.
- #generate_evaluation_code(code, local_scope) ⇒ Object
Methods inherited from AnalysedElementRef
Methods inherited from Base
#allocate_temp, #allocate_temps, #analyse_for_target_type, #c_code, #expression?, #from_ruby_object, #generate_and_dispose_subexprs, #generate_disposal_code, #has_temp, #possible_typecast, #release_temp, #release_temps, #to_ruby_object
Constructor Details
This class inherits a constructor from Rubex::AST::Expression::AnalysedElementRef
Instance Method Details
#analyse_types(local_scope) ⇒ Object
5 6 7 8 9 10 11 12 |
# File 'lib/rubex/ast/expression/analysed_element_ref/ruby_object_element_ref.rb', line 5 def analyse_types(local_scope) super @has_temp = true @pos.map! { |a| a.to_ruby_object } @pos.allocate_temps local_scope @pos.release_temps local_scope @subexprs << @pos end |
#generate_assignment_code(rhs, code, local_scope) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/rubex/ast/expression/analysed_element_ref/ruby_object_element_ref.rb', line 43 def generate_assignment_code(rhs, code, local_scope) raise "must specify atleast 1 arg in Object#[]=" if @pos.size < 1 generate_and_dispose_subexprs(code, local_scope) do @pos.each { |a| a.generate_evaluation_code(code, local_scope) } code << "rb_funcall(#{@entry.c_name}, rb_intern(\"[]=\")," code << "#{@pos.size + 1}" @pos.each do |p| code << ", #{p.c_code(local_scope)}" end code << ", #{rhs.c_code(local_scope)});" code.nl end end |
#generate_element_ref_code(expr, code, local_scope) ⇒ Object
Generate code for calls to array_ref inside structs.
29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/rubex/ast/expression/analysed_element_ref/ruby_object_element_ref.rb', line 29 def generate_element_ref_code(expr, code, local_scope) generate_and_dispose_subexprs(code, local_scope) do @pos.each { |a| a.generate_evaluation_code(code, local_scope) } code << "#{@c_code} = rb_funcall(#{expr.c_code(local_scope)}." code << "#{@entry.c_name}, rb_intern(\"[]\"), #{@pos.size}" @pos.each do |p| code << ", #{p.c_code(local_scope)}" end code << ", NULL" if @pos.empty? code << ");" code.nl end end |
#generate_evaluation_code(code, local_scope) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/rubex/ast/expression/analysed_element_ref/ruby_object_element_ref.rb', line 14 def generate_evaluation_code(code, local_scope) generate_and_dispose_subexprs(code, local_scope) do @pos.each { |a| a.generate_evaluation_code(code, local_scope) } code << "#{@c_code} = rb_funcall(#{@entry.c_name}, rb_intern(\"[]\"), " code << @pos.size.to_s @pos.each do |p| code << ", #{p.c_code(local_scope)}" end code << ", NULL" if @pos.empty? code << ");" code.nl end end |