Skip to content

Commit f73547c

Browse files
committed
Add smt_command downcast visitor
1 parent d54376b commit f73547c

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
@@ -143,3 +143,26 @@ size_t smt_pop_commandt::levels() const
143143
{
144144
return get_size_t(ID_value);
145145
}
146+
147+
template <typename visitort>
148+
void accept(const smt_commandt &command, const irep_idt &id, visitort &&visitor)
149+
{
150+
#define COMMAND_ID(the_id) \
151+
if(id == ID_smt_##the_id##_command) \
152+
return visitor.visit(static_cast<const smt_##the_id##_commandt &>(command));
153+
// The include below is marked as nolint because including the same file
154+
// multiple times is required as part of the x macro pattern.
155+
#include <solvers/smt2_incremental/smt_commands.def> // NOLINT(build/include)
156+
#undef COMMAND_ID
157+
UNREACHABLE;
158+
}
159+
160+
void smt_commandt::accept(smt_command_const_downcast_visitort &visitor) const
161+
{
162+
::accept(*this, id(), visitor);
163+
}
164+
165+
void smt_commandt::accept(smt_command_const_downcast_visitort &&visitor) const
166+
{
167+
::accept(*this, id(), std::move(visitor));
168+
}

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
@@ -6,6 +6,8 @@
66
#include <solvers/smt2_incremental/smt_terms.h>
77
#include <util/irep.h>
88

9+
class smt_command_const_downcast_visitort;
10+
911
class smt_commandt : protected irept
1012
{
1113
public:
@@ -18,6 +20,9 @@ class smt_commandt : protected irept
1820
bool operator==(const smt_commandt &) const;
1921
bool operator!=(const smt_commandt &) const;
2022

23+
void accept(smt_command_const_downcast_visitort &) const;
24+
void accept(smt_command_const_downcast_visitort &&) const;
25+
2126
protected:
2227
using irept::irept;
2328
};
@@ -103,4 +108,13 @@ class smt_set_option_commandt : public smt_commandt
103108
public:
104109
};
105110

111+
class smt_command_const_downcast_visitort
112+
{
113+
public:
114+
#define COMMAND_ID(the_id) \
115+
virtual void visit(const smt_##the_id##_commandt &) = 0;
116+
#include "smt_commands.def"
117+
#undef COMMAND_ID
118+
};
119+
106120
#endif // CPROVER_SOLVERS_SMT2_INCREMENTAL_SMT_COMMANDS_H

0 commit comments

Comments
 (0)