@@ -369,46 +369,13 @@ void add_quantified_variable(
369369 exprt &expression,
370370 const irep_idt &mode)
371371{
372- if (expression.id () == ID_not || expression.id () == ID_typecast)
373- {
374- // For unary connectives, recursively check for
375- // nested quantified formulae in the term
376- auto &unary_expression = to_unary_expr (expression);
377- add_quantified_variable (symbol_table, unary_expression.op (), mode);
378- }
379- if (expression.id () == ID_notequal || expression.id () == ID_implies)
380- {
381- // For binary connectives, recursively check for
382- // nested quantified formulae in the left and right terms
383- auto &binary_expression = to_binary_expr (expression);
384- add_quantified_variable (symbol_table, binary_expression.lhs (), mode);
385- add_quantified_variable (symbol_table, binary_expression.rhs (), mode);
386- }
387- if (expression.id () == ID_if)
388- {
389- // For ternary connectives, recursively check for
390- // nested quantified formulae in all three terms
391- auto &if_expression = to_if_expr (expression);
392- add_quantified_variable (symbol_table, if_expression.cond (), mode);
393- add_quantified_variable (symbol_table, if_expression.true_case (), mode);
394- add_quantified_variable (symbol_table, if_expression.false_case (), mode);
395- }
396- if (expression.id () == ID_and || expression.id () == ID_or)
397- {
398- // For multi-ary connectives, recursively check for
399- // nested quantified formulae in all terms
400- auto &multi_ary_expression = to_multi_ary_expr (expression);
401- for (auto &operand : multi_ary_expression.operands ())
402- {
403- add_quantified_variable (symbol_table, operand, mode);
404- }
405- }
406- else if (expression.id () == ID_exists || expression.id () == ID_forall)
407- {
372+ auto visitor = [&symbol_table, &mode](exprt &expr) {
373+ if (expr.id () != ID_exists && expr.id () != ID_forall)
374+ return ;
408375 // When a quantifier expression is found, create a fresh symbol for each
409376 // quantified variable and rewrite the expression to use those fresh
410377 // symbols.
411- auto &quantifier_expression = to_quantifier_expr (expression );
378+ auto &quantifier_expression = to_quantifier_expr (expr );
412379 std::vector<symbol_exprt> fresh_variables;
413380 fresh_variables.reserve (quantifier_expression.variables ().size ());
414381 for (const auto &quantified_variable : quantifier_expression.variables ())
@@ -435,7 +402,8 @@ void add_quantified_variable(
435402 // replace previous variables and body
436403 quantifier_expression.variables () = fresh_variables;
437404 quantifier_expression.where () = std::move (where);
438- }
405+ };
406+ expression.visit_pre (visitor);
439407}
440408
441409static void replace_history_parameter_rec (
0 commit comments