@@ -168,23 +168,29 @@ void code_contractst::add_quantified_variable(
168168 replace_symbolt &replace,
169169 irep_idt mode)
170170{
171- // If the expression is a quantified expression, this function adds
172- // the quantified variable to the symbol table and to the expression map
173-
174- // TODO Currently only works if the contract contains only a single
175- // quantified formula
176- // i.e. (1) the top-level element is a quantifier formula
177- // and (2) there are no inner quantifier formulae
178- // This TODO is handled in PR #5968
179-
180- if (expression.id () == ID_exists || expression.id () == ID_forall)
181- {
182- // get quantified symbol
183- exprt tuple = expression.operands ().front ();
184- exprt quantified_variable = tuple.operands ().front ();
171+ // This function recursively searches the expression to find nested or
172+ // non-nested quantified expressions. When a quantified expression is found,
173+ // the quantified variable is added to the symbol table and to the expression map.
174+ if (
175+ expression.id () == ID_and || expression.id () == ID_or ||
176+ expression.id () == ID_implies)
177+ {
178+ // For binary connectives, recursively check for
179+ // nested quantified formulae in the left and right terms
180+ exprt left = expression.operands ().at (0 );
181+ add_quantified_variable (left, replace, mode);
182+ exprt right = expression.operands ().at (1 );
183+ add_quantified_variable (right, replace, mode);
184+ }
185+ else if (expression.id () == ID_exists || expression.id () == ID_forall)
186+ {
187+ // When a quantified expression is found,
188+ // 1. get quantified symbol
189+ exprt tuple = expression.operands ().at (0 );
190+ exprt quantified_variable = tuple.operands ().at (0 );
185191 symbol_exprt quantified_symbol = to_symbol_expr (quantified_variable);
186192
187- // create fresh symbol
193+ // 2. create fresh symbol
188194 symbolt new_symbol = get_fresh_aux_symbol (
189195 quantified_symbol.type (),
190196 id2string (quantified_symbol.get_identifier ()),
@@ -193,10 +199,14 @@ void code_contractst::add_quantified_variable(
193199 mode,
194200 symbol_table);
195201
196- // add created fresh symbol to expression map
202+ // 3. add created fresh symbol to expression map
197203 symbol_exprt q (
198204 quantified_symbol.get_identifier (), quantified_symbol.type ());
199205 replace.insert (q, new_symbol.symbol_expr ());
206+
207+ // 4. recursively check for nested quantified formulae
208+ exprt quantified_expression = expression.operands ().at (1 );
209+ add_quantified_variable (quantified_expression, replace, mode);
200210 }
201211}
202212
0 commit comments