Skip to content

Commit 7273da2

Browse files
committed
smt2 parser: track a 'kind' for all identifiers
This commit adds a field to the idt data structure in the SMT-LIB2 parser. This enables distinguishing variables, parameters, and bound identifiers, primarily for the benefit of debugging.
1 parent e7fc79a commit 7273da2

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

src/solvers/smt2/smt2_parser.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,10 @@ exprt::operandst smt2_parsert::operands()
128128
return result;
129129
}
130130

131-
irep_idt smt2_parsert::add_fresh_id(const irep_idt &id, const exprt &expr)
131+
irep_idt smt2_parsert::add_fresh_id(
132+
const irep_idt &id,
133+
idt::kindt kind,
134+
const exprt &expr)
132135
{
133136
auto &count=renaming_counters[id];
134137
irep_idt new_id;
@@ -140,7 +143,7 @@ irep_idt smt2_parsert::add_fresh_id(const irep_idt &id, const exprt &expr)
140143
.emplace(
141144
std::piecewise_construct,
142145
std::forward_as_tuple(new_id),
143-
std::forward_as_tuple(expr))
146+
std::forward_as_tuple(kind, expr))
144147
.second);
145148

146149
// record renaming
@@ -155,7 +158,7 @@ void smt2_parsert::add_unique_id(const irep_idt &id, const exprt &expr)
155158
.emplace(
156159
std::piecewise_construct,
157160
std::forward_as_tuple(id),
158-
std::forward_as_tuple(expr))
161+
std::forward_as_tuple(idt::VARIABLE, expr))
159162
.second)
160163
{
161164
// id already used
@@ -209,7 +212,7 @@ exprt smt2_parsert::let_expression()
209212
for(auto &b : bindings)
210213
{
211214
// get a fresh id for it
212-
b.first = add_fresh_id(b.first, b.second);
215+
b.first = add_fresh_id(b.first, idt::BINDING, b.second);
213216
}
214217

215218
exprt where = expression();
@@ -269,7 +272,7 @@ exprt smt2_parsert::quantifier_expression(irep_idt id)
269272
for(auto &b : bindings)
270273
{
271274
const irep_idt id =
272-
add_fresh_id(b.get_identifier(), exprt(ID_nil, b.type()));
275+
add_fresh_id(b.get_identifier(), idt::BINDING, exprt(ID_nil, b.type()));
273276

274277
b.set_identifier(id);
275278
}
@@ -1181,7 +1184,8 @@ smt2_parsert::function_signature_definition()
11811184
irep_idt id = smt2_tokenizer.get_buffer();
11821185
domain.push_back(sort());
11831186

1184-
parameters.push_back(add_fresh_id(id, exprt(ID_nil, domain.back())));
1187+
parameters.push_back(
1188+
add_fresh_id(id, idt::PARAMETER, exprt(ID_nil, domain.back())));
11851189

11861190
if(next_token() != smt2_tokenizert::CLOSE)
11871191
throw error("expected ')' at end of parameter");

src/solvers/smt2/smt2_parser.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,14 @@ class smt2_parsert
3535

3636
struct idt
3737
{
38-
explicit idt(const exprt &expr) : type(expr.type()), definition(expr)
38+
using kindt = enum { VARIABLE, BINDING, PARAMETER };
39+
40+
idt(kindt _kind, const exprt &expr)
41+
: kind(_kind), type(expr.type()), definition(expr)
3942
{
4043
}
4144

45+
kindt kind;
4246
typet type;
4347
exprt definition;
4448
std::vector<irep_idt> parameters;
@@ -89,7 +93,7 @@ class smt2_parsert
8993
renaming_mapt renaming_map;
9094
using renaming_counterst=std::map<irep_idt, unsigned>;
9195
renaming_counterst renaming_counters;
92-
irep_idt add_fresh_id(const irep_idt &, const exprt &);
96+
irep_idt add_fresh_id(const irep_idt &, idt::kindt, const exprt &);
9397
void add_unique_id(const irep_idt &, const exprt &);
9498
irep_idt rename_id(const irep_idt &) const;
9599

0 commit comments

Comments
 (0)