Class: Rubex::AST::Expression::Literal::Char

Inherits:
Base
  • Object
show all
Defined in:
lib/rubex/ast/expression/literal/char.rb

Instance Attribute Summary

Attributes inherited from Base

#entry, #type, #typecast

Instance Method Summary collapse

Methods inherited from Base

#==, #c_name, #initialize, #literal?

Methods inherited from Base

#allocate_temp, #allocate_temps, #expression?, #from_ruby_object, #generate_and_dispose_subexprs, #generate_assignment_code, #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::Literal::Base

Instance Method Details

#analyse_for_target_type(target_type, local_scope) ⇒ Object



6
7
8
9
10
11
12
13
14
15
# File 'lib/rubex/ast/expression/literal/char.rb', line 6

def analyse_for_target_type(target_type, local_scope)
  if target_type.char?
    @type = Rubex::DataType::Char.new
  elsif target_type.object?
    @type = Rubex::DataType::RubyString.new
    analyse_types local_scope
  else
    raise Rubex::TypeError, "Cannot assign #{target_type} to string."
  end
end

#analyse_types(_local_scope) ⇒ Object



17
18
19
# File 'lib/rubex/ast/expression/literal/char.rb', line 17

def analyse_types(_local_scope)
  @type ||= Rubex::DataType::RubyString.new
end

#c_code(_local_scope) ⇒ Object



29
30
31
# File 'lib/rubex/ast/expression/literal/char.rb', line 29

def c_code(_local_scope)
  @c_code
end

#generate_evaluation_code(_code, _local_scope) ⇒ Object



21
22
23
24
25
26
27
# File 'lib/rubex/ast/expression/literal/char.rb', line 21

def generate_evaluation_code(_code, _local_scope)
  @c_code = if @type.char?
              @name
            else
              "rb_str_new2(\"#{@name[1]}\")"
            end
end