Skip to content

Commit c77b078

Browse files
committed
Adjust casting within quantifier handling
1 parent c6a8eef commit c77b078

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

src/goto-instrument/code_contracts.cpp

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ Date: February 2016
2727
#include <util/format_type.h>
2828
#include <util/fresh_symbol.h>
2929
#include <util/mathematical_types.h>
30+
#include <util/mathematical_expr.h>
3031
#include <util/message.h>
3132
#include <util/pointer_offset_size.h>
3233
#include <util/pointer_predicates.h>
@@ -169,41 +170,44 @@ void code_contractst::add_quantified_variable(
169170
irep_idt mode)
170171
{
171172
if(
172-
expression.id() == ID_not || expression.id() == ID_notequal ||
173-
expression.id() == ID_typecast)
173+
expression.id() == ID_not || expression.id() == ID_typecast)
174174
{
175175
// For unary connectives, recursively check for
176176
// nested quantified formulae in the term
177-
exprt term = expression.operands().at(0);
177+
unary_exprt unary_expression = to_unary_expr(expression);
178+
exprt term = unary_expression.operands().at(0);
178179
add_quantified_variable(term, replace, mode);
179180
}
180181
if(
181182
expression.id() == ID_and || expression.id() == ID_or ||
182-
expression.id() == ID_implies)
183+
expression.id() == ID_notequal || expression.id() == ID_implies)
183184
{
184185
// For binary connectives, recursively check for
185186
// nested quantified formulae in the left and right terms
186-
exprt left = expression.operands().at(0);
187+
binary_exprt binary_expression = to_binary_expr(expression);
188+
exprt left = binary_expression.operands().at(0);
187189
add_quantified_variable(left, replace, mode);
188-
exprt right = expression.operands().at(1);
190+
exprt right = binary_expression.operands().at(1);
189191
add_quantified_variable(right, replace, mode);
190192
}
191193
if(expression.id() == ID_if)
192194
{
193195
// For ternary connectives, recursively check for
194196
// nested quantified formulae in all three terms
195-
exprt condition = expression.operands().at(0);
197+
if_exprt if_expression = to_if_expr(expression);
198+
exprt condition = if_expression.operands().at(0);
196199
add_quantified_variable(condition, replace, mode);
197-
exprt first = expression.operands().at(1);
200+
exprt first = if_expression.operands().at(1);
198201
add_quantified_variable(first, replace, mode);
199-
exprt second = expression.operands().at(2);
202+
exprt second = if_expression.operands().at(2);
200203
add_quantified_variable(second, replace, mode);
201204
}
202205
else if(expression.id() == ID_exists || expression.id() == ID_forall)
203206
{
204-
// When a quantified expression is found,
207+
// When a quantifier expression is found,
205208
// 1. get quantified symbol
206-
exprt tuple = expression.operands().at(0);
209+
quantifier_exprt quantifier_expression = to_quantifier_expr(expression);
210+
exprt tuple = quantifier_expression.operands().at(0);
207211
exprt quantified_variable = tuple.operands().at(0);
208212
symbol_exprt quantified_symbol = to_symbol_expr(quantified_variable);
209213

@@ -222,7 +226,7 @@ void code_contractst::add_quantified_variable(
222226
replace.insert(q, new_symbol.symbol_expr());
223227

224228
// 4. recursively check for nested quantified formulae
225-
exprt quantified_expression = expression.operands().at(1);
229+
exprt quantified_expression = quantifier_expression.operands().at(1);
226230
add_quantified_variable(quantified_expression, replace, mode);
227231
}
228232
}

0 commit comments

Comments
 (0)