Class: OCL::Implies

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

Overview

Paren

Instance Method Summary collapse

Methods inherited from Block

check_condition, result, #to_s

Constructor Details

#initialize(condition, implication) ⇒ Implies

Returns a new instance of Implies.


126
127
128
129
# File 'lib/dbc/ocl.rb', line 126

def initialize(condition, implication)
	@condition = condition
	@implication = implication
end

Instance Method Details

#cexp?Boolean

Returns:

  • (Boolean)

151
152
153
# File 'lib/dbc/ocl.rb', line 151

def cexp?
	@condition.cexp? and @implication.cexp?
end

#to_cexpObject


155
156
157
# File 'lib/dbc/ocl.rb', line 155

def to_cexp
	"#{@condition.to_cexp} ? #{@implication.to_cexp} : 1"
end

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


131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
# File 'lib/dbc/ocl.rb', line 131

def to_exp(result, indent_str = '')
	str = ''
	# implies statements are true by default
	str << indent_str << "#{result} = 1;\n"
	if @condition.cexp?
		expression = @condition.to_cexp
	else
		expression = Block.result
		str << @condition.to_exp(expression, indent_str)
	end
	# if the expression is true then that implies the condition
	str << indent_str << "if (#{expression}) {\n"
	if @implication.cexp?
		str << check_condition(@implication.to_cexp, result, "\t" << indent_str)
	else
		str << @implication.to_exp(result, "\t" << indent_str)
	end
	str << indent_str << "}\n"
end