Skip to content

Commit b7d5530

Browse files
committed
Add sort casting
For checking parameterised sorts.
1 parent 9e3edf7 commit b7d5530

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

src/solvers/smt2_incremental/smt_sorts.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,29 @@
1010
#include <solvers/smt2_incremental/smt_sorts.def>
1111
#undef SORT_ID
1212

13+
#define SORT_ID(the_id) \
14+
template <> \
15+
const smt_##the_id##_sortt *smt_sortt::cast<smt_##the_id##_sortt>() const \
16+
{ \
17+
return id() == ID_smt_##the_id##_sort \
18+
? static_cast<const smt_##the_id##_sortt *>(this) \
19+
: nullptr; \
20+
}
21+
#include <solvers/smt2_incremental/smt_sorts.def> // NOLINT(build/include)
22+
#undef SORT_ID
23+
24+
#define SORT_ID(the_id) \
25+
template <> \
26+
optionalt<smt_##the_id##_sortt> smt_sortt::cast<smt_##the_id##_sortt>() && \
27+
{ \
28+
if(id() == ID_smt_##the_id##_sort) \
29+
return {std::move(*static_cast<const smt_##the_id##_sortt *>(this))}; \
30+
else \
31+
return {}; \
32+
}
33+
#include <solvers/smt2_incremental/smt_sorts.def> // NOLINT(build/include)
34+
#undef SORT_ID
35+
1336
bool smt_sortt::operator==(const smt_sortt &other) const
1437
{
1538
return irept::operator==(other);

src/solvers/smt2_incremental/smt_sorts.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#define CPROVER_SOLVERS_SMT2_INCREMENTAL_SMT_SORTS_H
99

1010
#include <util/irep.h>
11+
#include <util/optional.h>
1112

1213
#include <type_traits>
1314

@@ -42,6 +43,12 @@ class smt_sortt : protected irept
4243
static const smt_sortt &downcast(const irept &);
4344
};
4445

46+
template <typename sub_classt>
47+
const sub_classt *cast() const;
48+
49+
template <typename sub_classt>
50+
optionalt<sub_classt> cast() &&;
51+
4552
protected:
4653
using irept::irept;
4754
};

0 commit comments

Comments
 (0)