Class: Rubex::AST::Expression::Raise

Inherits:
CommandCall show all
Defined in:
lib/rubex/ast/expression/command_call/raise.rb

Instance Attribute Summary

Attributes inherited from Base

#entry, #type, #typecast

Instance Method Summary collapse

Methods inherited from CommandCall

#generate_assignment_code

Methods inherited from Base

#allocate_temp, #allocate_temps, #analyse_for_target_type, #expression?, #from_ruby_object, #generate_and_dispose_subexprs, #generate_assignment_code, #has_temp, #possible_typecast, #release_temp, #release_temps, #to_ruby_object

Constructor Details

#initialize(args) ⇒ Raise

Returns a new instance of Raise.



5
6
7
# File 'lib/rubex/ast/expression/command_call/raise.rb', line 5

def initialize(args)
  @args = args
end

Instance Method Details

#analyse_types(local_scope) ⇒ Object



9
10
11
12
13
14
15
16
17
18
# File 'lib/rubex/ast/expression/command_call/raise.rb', line 9

def analyse_types(local_scope)
  @args.analyse_types local_scope
  @args.allocate_temps local_scope
  unless @args.empty? || @args[0].is_a?(AST::Expression::Name) ||
         @args[0].is_a?(AST::Expression::Literal::StringLit)
    raise Rubex::TypeMismatchError, "Wrong argument list #{@args.inspect} for raise."
  end
  @subexprs = [@args]
  @args.release_temps local_scope
end

#c_code(_local_scope) ⇒ Object



45
46
47
# File 'lib/rubex/ast/expression/command_call/raise.rb', line 45

def c_code(_local_scope)
  super + @c_code
end

#generate_disposal_code(code) ⇒ Object



43
# File 'lib/rubex/ast/expression/command_call/raise.rb', line 43

def generate_disposal_code(code); end

#generate_evaluation_code(code, local_scope) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/rubex/ast/expression/command_call/raise.rb', line 20

def generate_evaluation_code(code, local_scope)
  generate_and_dispose_subexprs(code, local_scope) do
    @c_code = ''
    @c_code << 'rb_raise('

    if @args[0].is_a?(AST::Expression::Name)
      @c_code << @args[0].c_code(local_scope) + ','
      args = @args[1..-1]
    else
      @c_code << Rubex::DEFAULT_CLASS_MAPPINGS['RuntimeError'] + ','
      args = @args
    end

    unless args.empty?
      @c_code << "\"#{prepare_format_string(args)}\" ,"
      @c_code << args.map { |arg| (inspected_expr(arg, local_scope)).to_s }.join(',')
    else
      @c_code << '""'
    end
    @c_code << ');'
  end
end