Skip to content

Commit af27fcc

Browse files
committed
Add controlled upcasting of smt_termt for storage implementions
So that instaces of smt_termt can be stored inside other non-term ireps.
1 parent cd8e888 commit af27fcc

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

src/solvers/smt2_incremental/smt_terms.h

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,45 @@ class smt_termt : protected irept, private smt_sortt::storert<smt_termt>
3131
void accept(smt_term_const_downcast_visitort &) const;
3232
void accept(smt_term_const_downcast_visitort &&) const;
3333

34+
/// \brief Class for adding the ability to up and down cast smt_termt to and
35+
/// from irept. These casts are required by other irept derived classes in
36+
/// order to store instances of smt_termt inside them.
37+
/// \tparam derivedt The type of class which derives from this class and from
38+
/// irept.
39+
template <typename derivedt>
40+
class storert
41+
{
42+
protected:
43+
storert();
44+
static irept upcast(smt_termt term);
45+
static const smt_termt &downcast(const irept &);
46+
};
47+
3448
protected:
3549
smt_termt(irep_idt id, smt_sortt sort);
3650
};
3751

52+
template <typename derivedt>
53+
smt_termt::storert<derivedt>::storert()
54+
{
55+
static_assert(
56+
std::is_base_of<irept, derivedt>::value &&
57+
std::is_base_of<storert<derivedt>, derivedt>::value,
58+
"Only irept based classes need to upcast smt_termt to store it.");
59+
}
60+
61+
template <typename derivedt>
62+
irept smt_termt::storert<derivedt>::upcast(smt_termt term)
63+
{
64+
return static_cast<irept &&>(std::move(term));
65+
}
66+
67+
template <typename derivedt>
68+
const smt_termt &smt_termt::storert<derivedt>::downcast(const irept &irep)
69+
{
70+
return static_cast<const smt_termt &>(irep);
71+
}
72+
3873
class smt_bool_literal_termt : public smt_termt
3974
{
4075
public:

0 commit comments

Comments
 (0)