Class: OCL::IterBlock

Inherits:
Block
  • Object
show all
Defined in:
lib/dbc/ocl.rb

Direct Known Subclasses

Exists, Forall

Instance Method Summary collapse

Methods inherited from Block

check_condition, result, #to_s

Constructor Details

#initialize(iterator, expression) ⇒ IterBlock

Returns a new instance of IterBlock.



290
291
292
293
# File 'lib/dbc/ocl.rb', line 290

def initialize(iterator, expression)
	@iterator = iterator
	@expression = expression
end

Instance Method Details

#cexp?Boolean

Returns:

  • (Boolean)


294
295
296
# File 'lib/dbc/ocl.rb', line 294

def cexp?
	false
end

#to_cexpObject



297
298
299
# File 'lib/dbc/ocl.rb', line 297

def to_cexp
	raise "cannot convert #{self.class} to C expression"
end

#to_exp(result, indent_str = '') ⇒ Object



300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
# File 'lib/dbc/ocl.rb', line 300

def to_exp(result, indent_str = '')
	# if the condition is true for a single element then we mark result
	# as true and break (since the condition must be true for only one element).
	str = ''
	str << self.initialize_iterator(result, indent_str)
	str << indent_str << "{\n"
	indent = "\t" << indent_str # increase indent
	if @expression.cexp?
		check_exp = @expression.to_cexp
		inside_iterator = ''
	else
		check_exp = Block.result
		str << indent << "int #{check_exp} = 0;\n"
		inside_iterator = @expression.to_exp(check_exp, "\t" << indent)
	end
	str << @iterator.declare(indent)
	str << @iterator.open(indent)
	# inside_iterator does checks / calcs necessary for check_exp to be valid
	str << inside_iterator
	str << self.check_iteration(check_exp, result, indent)
	str << @iterator.close(indent)
	str << indent_str << "}\n"
end