Class: IDL::Expression::Operation
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
#idltype, #value
Class Method Summary
collapse
Instance Method Summary
collapse
#typename
Constructor Details
#initialize(*_operands) ⇒ Operation
Returns a new instance of Operation.
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
|
# File 'lib/ridl/expression.rb', line 93
def initialize(*_operands)
n = self.class::NUMBER_OF_OPERANDS
if _operands.size != n
raise 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
#operands ⇒ Object
Returns the value of attribute operands.
91
92
93
|
# File 'lib/ridl/expression.rb', line 91
def operands
@operands
end
|
Class Method Details
.suite_type(*types) ⇒ Object
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
|
# File 'lib/ridl/expression.rb', line 120
def Operation.suite_type(*types)
types.each do |t|
unless self::Applicable.include? t.class
raise "#{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(instantiation_context) ⇒ Object
116
117
118
|
# File 'lib/ridl/expression.rb', line 116
def instantiate(instantiation_context)
self.is_template? ? self.class.new(*@operands.collect { |o| o.instantiate(instantiation_context) }) : self
end
|
#is_template? ⇒ Boolean
112
113
114
|
# File 'lib/ridl/expression.rb', line 112
def is_template?
@operands.any? { |o| o.is_template? }
end
|
#set_type ⇒ Object
138
|
# File 'lib/ridl/expression.rb', line 138
def set_type; end
|