Class: Rubex::AST::Expression::Unary

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

Constant Summary collapse

OP_CLASS_MAP =
{
  '&' => Rubex::AST::Expression::Ampersand,
  '-' => Rubex::AST::Expression::UnarySub,
  '!' => Rubex::AST::Expression::UnaryNot,
  '~' => Rubex::AST::Expression::UnaryBitNot
}.freeze

Instance Attribute Summary

Attributes inherited from Base

#entry, #type, #typecast

Instance Method Summary collapse

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

#initialize(operator, expr) ⇒ Unary

Returns a new instance of Unary.



14
15
16
17
# File 'lib/rubex/ast/expression/unary.rb', line 14

def initialize(operator, expr)
  @operator = operator
  @expr = OP_CLASS_MAP[@operator].new(expr)
end

Instance Method Details

#analyse_for_target_type(target_type, local_scope) ⇒ Object



25
26
27
28
# File 'lib/rubex/ast/expression/unary.rb', line 25

def analyse_for_target_type(target_type, local_scope)
  @expr.analyse_for_target_type(target_type, local_scope)
  @type = @expr.type
end

#analyse_types(local_scope) ⇒ Object



19
20
21
22
23
# File 'lib/rubex/ast/expression/unary.rb', line 19

def analyse_types(local_scope)
  @expr.analyse_types local_scope
  @type = @expr.type
  super
end

#c_code(local_scope) ⇒ Object



34
35
36
37
# File 'lib/rubex/ast/expression/unary.rb', line 34

def c_code(local_scope)
  code = super
  code << @expr.c_code(local_scope)
end

#generate_evaluation_code(code, local_scope) ⇒ Object



30
31
32
# File 'lib/rubex/ast/expression/unary.rb', line 30

def generate_evaluation_code(code, local_scope)
  @expr.generate_evaluation_code code, local_scope
end