Class: IDL::Expression::Operation

Inherits:
IDL::Expression show all
Defined in:
lib/ridl/expression.rb

Direct Known Subclasses

Integer2, Unary

Defined Under Namespace

Classes: Add, And, Boolean2, Div, Float2, Integer2, LShift, Minus, Mod, Mult, Or, RShift, Shift, Unary, UnaryMinus, UnaryNot, UnaryPlus, Xor

Constant Summary collapse

NUMBER_OF_OPERANDS =
nil

Instance Attribute Summary collapse

Attributes inherited from IDL::Expression

#idltype, #value

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from IDL::Expression

#typename

Constructor Details

#initialize(*_operands) ⇒ Operation

Returns a new instance of Operation.



87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/ridl/expression.rb', line 87

def initialize(*_operands)
  n = self.class::NUMBER_OF_OPERANDS

  if _operands.size != n
    raise RuntimeError,
      format("%s must receive %d operand%s.",
      self.typename, n, if (n>1) then "s" else "" end)
  end

  unless _operands.any? { |o| o.is_template? }
    @idltype = self.class.suite_type(*(_operands.collect{|o| o.idltype.resolved_type}))
    @value = calculate(*(_operands.collect{|o| o.value}))
  else
    @idltype = nil
    @value = nil
  end
  @operands = _operands
  self.set_type
end

Instance Attribute Details

#operandsObject (readonly)

Returns the value of attribute operands.



86
87
88
# File 'lib/ridl/expression.rb', line 86

def operands
  @operands
end

Class Method Details

.suite_type(*types) ⇒ Object



115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# File 'lib/ridl/expression.rb', line 115

def Operation.suite_type(*types)
  types.each do |t|
    if not self::Applicable.include? t.class
      raise RuntimeError,
        "#{self.name} cannot be applicable for #{t.typename}"
    end
  end

  ret = nil
  types = types.collect {|t| t.class }
  self::Applicable.each do |t|
    if types.include? t
      ret = t
      break
    end
  end
  ret
end

Instance Method Details

#instantiate(_context) ⇒ Object



111
112
113
# File 'lib/ridl/expression.rb', line 111

def instantiate(_context)
  self.is_template? ? self.class.new(*@operands.collect { |o| o.instantiate(_context) }) : self
end

#is_template?Boolean

Returns:

  • (Boolean)


107
108
109
# File 'lib/ridl/expression.rb', line 107

def is_template?
  @operands.any? { |o| o.is_template? }
end

#set_typeObject



133
134
# File 'lib/ridl/expression.rb', line 133

def set_type
end