File tree Expand file tree Collapse file tree 3 files changed +39
-0
lines changed
src/solvers/smt2_incremental Expand file tree Collapse file tree 3 files changed +39
-0
lines changed Original file line number Diff line number Diff 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+ }
Original file line number Diff line number Diff line change 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`.
79COMMAND_ID(assert)
810COMMAND_ID(check_sat)
911COMMAND_ID(declare_function)
Original file line number Diff line number Diff line change 88#include < solvers/smt2_incremental/smt_terms.h>
99#include < util/irep.h>
1010
11+ class smt_command_const_downcast_visitort ;
12+
1113class smt_commandt : protected irept
1214{
1315public:
@@ -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+
2328protected:
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
You can’t perform that action at this time.
0 commit comments