Skip to content

Commit abff630

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 fbffc09 commit abff630

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
@@ -29,10 +29,45 @@ class smt_termt : protected irept, private smt_sortt::storert<smt_termt>
2929
void accept(smt_term_const_downcast_visitort &) const;
3030
void accept(smt_term_const_downcast_visitort &&) const;
3131

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

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

0 commit comments

Comments
 (0)