Skip to content

Commit 8033ac4

Browse files
committed
smt2 id_map: Do not use nil_typet when we mean "optional"
Use optionalt<typet> instead. nil_typet is deprecated.
1 parent 4eb7d04 commit 8033ac4

File tree

3 files changed

+16
-20
lines changed

3 files changed

+16
-20
lines changed

src/solvers/smt2/smt2_parser.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ exprt::operandst smt2_parsert::operands()
120120

121121
irep_idt smt2_parsert::get_fresh_id(const irep_idt &id)
122122
{
123-
if(id_map[id].type.is_nil())
123+
if(!id_map[id].type.has_value())
124124
return id; // id not yet used
125125

126126
auto &count=renaming_counters[id];
@@ -754,16 +754,15 @@ exprt smt2_parsert::function_application()
754754
auto id_it=id_map.find(final_id);
755755
if(id_it!=id_map.end())
756756
{
757-
if(id_it->second.type.id()==ID_mathematical_function)
757+
if(id_it->second.type->id() == ID_mathematical_function)
758758
{
759759
return function_application_exprt(
760-
symbol_exprt(final_id, id_it->second.type),
760+
symbol_exprt(final_id, *(id_it->second.type)),
761761
op,
762-
to_mathematical_function_type(
763-
id_it->second.type).codomain());
762+
to_mathematical_function_type(*(id_it->second.type)).codomain());
764763
}
765764
else
766-
return symbol_exprt(final_id, id_it->second.type);
765+
return symbol_exprt(final_id, *(id_it->second.type));
767766
}
768767

769768
throw error() << "unknown function symbol `" << id << '\'';
@@ -964,7 +963,7 @@ exprt smt2_parsert::expression()
964963
auto id_it = id_map.find(final_id);
965964
if(id_it != id_map.end())
966965
{
967-
symbol_exprt symbol_expr(final_id, id_it->second.type);
966+
symbol_exprt symbol_expr(final_id, *(id_it->second.type));
968967
if(smt2_tokenizer.token_is_quoted_symbol())
969968
symbol_expr.set(ID_C_quoted, true);
970969
return std::move(symbol_expr);

src/solvers/smt2/smt2_parser.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ Author: Daniel Kroening, [email protected]
1212
#include <map>
1313

1414
#include <util/mathematical_types.h>
15+
#include <util/optional.h>
1516
#include <util/std_expr.h>
1617

1718
#include "smt2_tokenizer.h"
@@ -33,11 +34,7 @@ class smt2_parsert
3334

3435
struct idt
3536
{
36-
idt():type(nil_typet())
37-
{
38-
}
39-
40-
typet type;
37+
optionalt<typet> type;
4138
exprt definition;
4239
std::vector<irep_idt> parameters;
4340
};

src/solvers/smt2/smt2_solver.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ void smt2_solvert::define_constants()
5151
{
5252
for(const auto &id : id_map)
5353
{
54-
if(id.second.type.id() == ID_mathematical_function)
54+
if(id.second.type->id() == ID_mathematical_function)
5555
continue;
5656

5757
if(id.second.definition.is_nil())
@@ -68,7 +68,7 @@ void smt2_solvert::define_constants()
6868
exprt def = id.second.definition;
6969
expand_function_applications(def);
7070
solver.set_to_true(
71-
equal_exprt(symbol_exprt(identifier, id.second.type), def));
71+
equal_exprt(symbol_exprt(identifier, *id.second.type), def));
7272
}
7373
}
7474

@@ -89,11 +89,11 @@ void smt2_solvert::expand_function_applications(exprt &expr)
8989
{
9090
const auto &f=f_it->second;
9191

92-
DATA_INVARIANT(f.type.id()==ID_mathematical_function,
92+
DATA_INVARIANT(
93+
f.type->id() == ID_mathematical_function,
9394
"type of function symbol must be mathematical_function_type");
9495

95-
const auto f_type=
96-
to_mathematical_function_type(f.type);
96+
const auto f_type = to_mathematical_function_type(*f.type);
9797

9898
const auto &domain = f_type.domain();
9999

@@ -272,7 +272,7 @@ void smt2_solvert::command(const std::string &c)
272272
std::cout << '(';
273273
for(const auto &id : id_map)
274274
{
275-
const symbol_exprt name(id.first, id.second.type);
275+
const symbol_exprt name(id.first, *id.second.type);
276276
const auto value = simplify_expr(solver.get(name), ns);
277277

278278
if(value.is_not_nil())
@@ -284,10 +284,10 @@ void smt2_solvert::command(const std::string &c)
284284

285285
std::cout << "(define-fun " << smt2_format(name) << ' ';
286286

287-
if(id.second.type.id() == ID_mathematical_function)
287+
if(id.second.type->id() == ID_mathematical_function)
288288
throw error("models for functions unimplemented");
289289
else
290-
std::cout << "() " << smt2_format(id.second.type);
290+
std::cout << "() " << smt2_format(*id.second.type);
291291

292292
std::cout << ' ' << smt2_format(value) << ')';
293293
}

0 commit comments

Comments
 (0)