6
6
7
7
#include " goto_model.h"
8
8
9
- #include < ansi-c/expr2c.h>
10
-
11
- #include < util/expr_util.h>
12
9
#include < util/fresh_symbol.h>
13
10
#include < util/irep.h> // for id2string
14
11
#include < util/mathematical_expr.h>
15
12
13
+ // / Perform the first part of skolemisation, by identifying an existentially
14
+ // / quantified statement and substituting the variables with skolem constants.
15
+ // / \param condition The condition on which we search for quantifiers.
16
+ // / \param symbol_table The symbol_table new symbols are inserted into.
17
+ static void rename_variables_in_existential_quantifiers (
18
+ exprt &condition,
19
+ symbol_table_baset &symbol_table)
20
+ {
21
+ condition.visit_post ([&symbol_table](exprt &sub_expression) {
22
+ if (can_cast_expr<exists_exprt>(sub_expression))
23
+ {
24
+ quantifier_exprt &quantifier_expr = to_quantifier_expr (sub_expression);
25
+ const auto &quantifier_sym = quantifier_expr.symbol ();
26
+
27
+ const auto new_symbol = get_fresh_aux_symbol (
28
+ quantifier_sym.type (),
29
+ CPROVER_PREFIX,
30
+ id2string (
31
+ symbol_table.lookup (quantifier_sym.get_identifier ())->base_name ),
32
+ quantifier_expr.source_location (),
33
+ symbol_table.lookup (quantifier_sym.get_identifier ())->mode ,
34
+ symbol_table);
35
+ const auto symbol_expr = new_symbol.symbol_expr ();
36
+ const std::vector<exprt> new_sym_vec{symbol_expr};
37
+
38
+ sub_expression =
39
+ exists_exprt (symbol_expr, quantifier_expr.instantiate (new_sym_vec));
40
+ }
41
+ });
42
+ }
43
+
16
44
void rename_variables_in_existential_quantifiers (goto_modelt &goto_model)
17
45
{
18
46
for (auto &function : goto_model.goto_functions .function_map )
@@ -21,49 +49,9 @@ void rename_variables_in_existential_quantifiers(goto_modelt &goto_model)
21
49
{
22
50
if (instruction.has_condition ())
23
51
{
24
- auto &cond = instruction. condition_nonconst ();
25
- recurse_on_condition (cond , goto_model);
52
+ rename_variables_in_existential_quantifiers (
53
+ instruction. condition_nonconst () , goto_model. symbol_table );
26
54
}
27
55
}
28
56
}
29
57
}
30
-
31
- void recurse_on_condition (exprt &cond, goto_modelt &model)
32
- {
33
- // recurse on the condition's subexpressions first - that allows us
34
- // to correctly identify the nodes we care about in a compound
35
- // expression, for instance something like `1 == 1 && exists(i.i>=0 && i>1)`
36
- for (exprt &subexpr : cond.operands ())
37
- {
38
- recurse_on_condition (subexpr, model);
39
- }
40
-
41
- // if the expression we're in doesn't have any more operands,
42
- // it means it's a leaf node, so we go ahead and process it.
43
- rename_and_substitute (cond, model);
44
- }
45
-
46
- void rename_and_substitute (exprt &cond, goto_modelt &model)
47
- {
48
- // perform the first part of skolemisation, by identifying an existentially
49
- // quantified statement and substituting the variables with skolem constants.
50
- if (can_cast_expr<exists_exprt>(cond))
51
- {
52
- quantifier_exprt &quantifier_expr = to_quantifier_expr (cond);
53
- const auto &quantifier_sym = quantifier_expr.symbol ();
54
-
55
- const auto new_symbol = get_fresh_aux_symbol (
56
- quantifier_sym.type (),
57
- CPROVER_PREFIX,
58
- id2string (
59
- model.symbol_table .lookup (quantifier_sym.get_identifier ())->base_name ),
60
- quantifier_expr.source_location (),
61
- ID_C,
62
- model.symbol_table );
63
- const auto symbol_expr =
64
- symbol_exprt (new_symbol.name , quantifier_sym.type ());
65
- const std::vector<exprt> new_sym_vec{symbol_expr};
66
-
67
- cond = exists_exprt (symbol_expr, quantifier_expr.instantiate (new_sym_vec));
68
- }
69
- }
0 commit comments