Skip to content

Commit bbaf2b2

Browse files
committed
Add smt_command downcast visitor
1 parent 96f8b81 commit bbaf2b2

File tree

3 files changed

+39
-0
lines changed

3 files changed

+39
-0
lines changed

src/solvers/smt2_incremental/smt_commands.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,3 +171,26 @@ const smt_optiont &smt_set_option_commandt::option() const
171171
{
172172
return downcast(find(ID_value));
173173
}
174+
175+
template <typename visitort>
176+
void accept(const smt_commandt &command, const irep_idt &id, visitort &&visitor)
177+
{
178+
#define COMMAND_ID(the_id) \
179+
if(id == ID_smt_##the_id##_command) \
180+
return visitor.visit(static_cast<const smt_##the_id##_commandt &>(command));
181+
// The include below is marked as nolint because including the same file
182+
// multiple times is required as part of the x macro pattern.
183+
#include <solvers/smt2_incremental/smt_commands.def> // NOLINT(build/include)
184+
#undef COMMAND_ID
185+
UNREACHABLE;
186+
}
187+
188+
void smt_commandt::accept(smt_command_const_downcast_visitort &visitor) const
189+
{
190+
::accept(*this, id(), visitor);
191+
}
192+
193+
void smt_commandt::accept(smt_command_const_downcast_visitort &&visitor) const
194+
{
195+
::accept(*this, id(), std::move(visitor));
196+
}

src/solvers/smt2_incremental/smt_commands.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
/// set of commands which are implemented and it is used to automate repetitive
55
/// parts of the implementation. These include -
66
/// * The constant `irep_idt`s used to identify each of the command classes.
7+
/// * The member functions of the `smt_command_const_downcast_visitort` class.
8+
/// * The type of command checks required to implement `smt_commandt::accept`.
79
COMMAND_ID(assert)
810
COMMAND_ID(check_sat)
911
COMMAND_ID(declare_function)

src/solvers/smt2_incremental/smt_commands.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
#include <solvers/smt2_incremental/smt_terms.h>
99
#include <util/irep.h>
1010

11+
class smt_command_const_downcast_visitort;
12+
1113
class smt_commandt : protected irept
1214
{
1315
public:
@@ -20,6 +22,9 @@ class smt_commandt : protected irept
2022
bool operator==(const smt_commandt &) const;
2123
bool operator!=(const smt_commandt &) const;
2224

25+
void accept(smt_command_const_downcast_visitort &) const;
26+
void accept(smt_command_const_downcast_visitort &&) const;
27+
2328
protected:
2429
using irept::irept;
2530
};
@@ -118,4 +123,13 @@ class smt_set_option_commandt
118123
const smt_optiont &option() const;
119124
};
120125

126+
class smt_command_const_downcast_visitort
127+
{
128+
public:
129+
#define COMMAND_ID(the_id) \
130+
virtual void visit(const smt_##the_id##_commandt &) = 0;
131+
#include "smt_commands.def"
132+
#undef COMMAND_ID
133+
};
134+
121135
#endif // CPROVER_SOLVERS_SMT2_INCREMENTAL_SMT_COMMANDS_H

0 commit comments

Comments
 (0)