Skip to content

Commit 4a75080

Browse files
committed
extract smt2_parsert::binding(...)
This is a refactoring that enables re-use of the code for parsing a binding.
1 parent b9fffb3 commit 4a75080

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

src/solvers/smt2/smt2_parser.cpp

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ exprt smt2_parsert::let_expression()
215215
return let_exprt(variables, values, where);
216216
}
217217

218-
exprt smt2_parsert::quantifier_expression(irep_idt id)
218+
std::pair<binding_exprt::variablest, exprt> smt2_parsert::binding(irep_idt id)
219219
{
220220
if(next_token() != smt2_tokenizert::OPEN)
221221
throw error() << "expected bindings after " << id;
@@ -264,8 +264,6 @@ exprt smt2_parsert::quantifier_expression(irep_idt id)
264264
if(next_token() != smt2_tokenizert::CLOSE)
265265
throw error() << "expected ')' after " << id;
266266

267-
exprt result=expr;
268-
269267
// remove bindings from id_map
270268
for(const auto &b : bindings)
271269
id_map.erase(b.get_identifier());
@@ -274,14 +272,17 @@ exprt smt2_parsert::quantifier_expression(irep_idt id)
274272
for(auto &saved_id : saved_ids)
275273
id_map.insert(std::move(saved_id));
276274

277-
// go backwards, build quantified expression
278-
for(auto r_it=bindings.rbegin(); r_it!=bindings.rend(); r_it++)
279-
{
280-
quantifier_exprt quantifier(id, *r_it, result);
281-
result=quantifier;
282-
}
275+
return {std::move(bindings), std::move(expr)};
276+
}
283277

284-
return result;
278+
exprt smt2_parsert::quantifier_expression(irep_idt id)
279+
{
280+
auto binding = this->binding(id);
281+
282+
if(binding.second.type().id() != ID_bool)
283+
throw error() << id << " expects a boolean term";
284+
285+
return quantifier_exprt(id, binding.first, binding.second);
285286
}
286287

287288
exprt smt2_parsert::function_application(

src/solvers/smt2/smt2_parser.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ class smt2_parsert
163163
exprt binary(irep_idt, const exprt::operandst &);
164164
exprt unary(irep_idt, const exprt::operandst &);
165165

166+
std::pair<binding_exprt::variablest, exprt> binding(irep_idt);
166167
exprt let_expression();
167168
exprt quantifier_expression(irep_idt);
168169
exprt function_application(

0 commit comments

Comments
 (0)