Skip to content

Commit 9dd2ff4

Browse files
fixup! Class for smt2 asts and functions for creating ASTs
1 parent b9cb869 commit 9dd2ff4

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

src/solvers/smt2/smt2_ast.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,11 +133,14 @@ static void print_data(std::ostream &stream, const smt2_astt &ast)
133133
{
134134
if(ast.id() == ID_symbol || ast.id() == ID_constant)
135135
{
136-
stream << ast.read().named_sub.at(ID_value).id();
136+
INVARIANT(
137+
ast.read().named_sub.has_value(),
138+
"constant and symbols should have an non-empty `named_sub` field");
139+
stream << ast.read().named_sub.value();
137140
}
138141
else if(ast.id() == ID_string_constant)
139142
{
140-
stream << '\"' << ast.read().named_sub.at(ID_value).id() << '\"';
143+
stream << '\"' << ast.read().sub[0].id() << '\"';
141144
}
142145
else if(ast.id() == ID_tuple && ast.read().sub.empty())
143146
{

src/solvers/smt2/smt2_ast.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ Author: Romain Brenguier, [email protected]
1818
#include <util/invariant.h>
1919
#include <util/irep.h>
2020
#include <util/mp_arith.h>
21+
#include <util/optional.h>
2122

2223
/// Base class for Abstract Syntax Tree of SMT2 expressions.
2324
/// Instances of this class are:
@@ -39,7 +40,7 @@ Author: Romain Brenguier, [email protected]
3940
/// - \ref smt2_selector_declarationt, special case of \ref smt2_pairt
4041
/// - \ref smt2_constructor_declarationt with id \c ID_declaration
4142
/// - \ref smt2_datatype_declarationt with id \c ID_par
42-
class smt2_astt : public non_sharing_treet<smt2_astt>
43+
class smt2_astt : public non_sharing_treet<smt2_astt, optionalt<irep_idt>>
4344
{
4445
public:
4546
/// Empty constructor
@@ -69,9 +70,9 @@ class smt2_constantt : public smt2_astt
6970
}
7071

7172
protected:
72-
explicit smt2_constantt(irep_idt id) : smt2_astt(ID_constant)
73+
explicit smt2_constantt(irep_idt value) : smt2_astt(ID_constant)
7374
{
74-
write().named_sub[ID_value] = smt2_astt{std::move(id)};
75+
write().named_sub = std::move(value);
7576
}
7677
};
7778

@@ -96,7 +97,7 @@ class smt2_symbolt : public smt2_astt
9697
public:
9798
explicit smt2_symbolt(irep_idt symbol) : smt2_astt(ID_symbol)
9899
{
99-
write().named_sub[ID_value] = smt2_astt(std::move(symbol));
100+
write().named_sub = std::move(symbol);
100101
}
101102
};
102103

@@ -106,7 +107,7 @@ class smt2_string_literalt : public smt2_astt
106107
explicit smt2_string_literalt(irep_idt literal)
107108
: smt2_astt(ID_string_constant)
108109
{
109-
write().named_sub[ID_value] = smt2_astt(std::move(literal));
110+
write().sub.emplace_back(std::move(literal));
110111
}
111112
};
112113

0 commit comments

Comments
 (0)