Skip to content

Commit c9a3de1

Browse files
committed
Add smt_command downcast visitor
1 parent fabc43a commit c9a3de1

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

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)