Class: OCL::Condition
- Inherits:
-
Object
- Object
- OCL::Condition
- Defined in:
- lib/dbc/ocl.rb
Overview
Needs to be able to deal with old values!
Constant Summary collapse
- DEFAULT_ERROR_FUNCTION =
'dbc_error'.freeze
- @@mappings =
{ 'pre' => 'precondition', 'post' => 'postcondition', 'inv' => 'invariant' }.freeze
Instance Attribute Summary collapse
-
#error_function ⇒ Object
Returns the value of attribute error_function.
-
#label ⇒ Object
readonly
Returns the value of attribute label.
-
#old_values ⇒ Object
readonly
Returns the value of attribute old_values.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
- #abort_condition(error_info, result, indent_str = '') ⇒ Object
- #condition=(expression) ⇒ Object
-
#initialize(type, label) ⇒ Condition
constructor
A new instance of Condition.
- #long_type ⇒ Object
- #to_cexp(indent = '', context = nil) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(type, label) ⇒ Condition
Returns a new instance of Condition.
362 363 364 365 366 367 368 |
# File 'lib/dbc/ocl.rb', line 362 def initialize(type, label) @old_values = nil @type = type raise "invalid condition type #{type}" unless @type @label = label @error_function = DEFAULT_ERROR_FUNCTION end |
Instance Attribute Details
#error_function ⇒ Object
Returns the value of attribute error_function.
375 376 377 |
# File 'lib/dbc/ocl.rb', line 375 def error_function @error_function end |
#label ⇒ Object (readonly)
Returns the value of attribute label.
376 377 378 |
# File 'lib/dbc/ocl.rb', line 376 def label @label end |
#old_values ⇒ Object (readonly)
Returns the value of attribute old_values.
376 377 378 |
# File 'lib/dbc/ocl.rb', line 376 def old_values @old_values end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
376 377 378 |
# File 'lib/dbc/ocl.rb', line 376 def type @type end |
Instance Method Details
#abort_condition(error_info, result, indent_str = '') ⇒ Object
400 401 402 403 404 405 |
# File 'lib/dbc/ocl.rb', line 400 def abort_condition(error_info, result, indent_str='') str = '' str << indent_str << "if (!(#{result})) {\n" str << indent_str << "\t#{@error_function}(#{error_info});\n" str << indent_str << "}\n" end |
#condition=(expression) ⇒ Object
370 371 372 373 |
# File 'lib/dbc/ocl.rb', line 370 def condition=(expression) raise "condition already set" if @condition @condition = expression end |
#long_type ⇒ Object
378 379 380 |
# File 'lib/dbc/ocl.rb', line 378 def long_type @@mappings[@type] end |
#to_cexp(indent = '', context = nil) ⇒ Object
382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 |
# File 'lib/dbc/ocl.rb', line 382 def to_cexp(indent='', context=nil) raise "condition not set" unless @condition error_tag = "#{@label.to_s(context)} \"#{long_type} failed\"" str = '' str << indent << "{\n" if @condition.cexp? result = @condition.to_cexp else result = "__ocl_result_" str << indent << "\tint #{result};\n" str << @condition.to_exp(result, "\t" << indent) end str << abort_condition(error_tag, result, "\t" << indent) str << indent << "}\n" end |
#to_s ⇒ Object
407 408 409 |
# File 'lib/dbc/ocl.rb', line 407 def to_s "#{@type}:" end |