Skip to content

Commit c55c299

Browse files
author
Daniel Kroening
committed
extend the array_list_exprt API
The new API encourages maintaining the class invariants (type and even number of operands).
1 parent 8c3dac0 commit c55c299

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

src/util/std_expr.h

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1728,6 +1728,22 @@ class array_list_exprt : public multi_ary_exprt
17281728
: multi_ary_exprt(ID_array_list, std::move(_operands), _type)
17291729
{
17301730
}
1731+
1732+
const array_typet &type() const
1733+
{
1734+
return static_cast<const array_typet &>(multi_ary_exprt::type());
1735+
}
1736+
1737+
array_typet &type()
1738+
{
1739+
return static_cast<array_typet &>(multi_ary_exprt::type());
1740+
}
1741+
1742+
/// add an index/value pair
1743+
void add(exprt index, exprt value)
1744+
{
1745+
add_to_operands(std::move(index), std::move(value));
1746+
}
17311747
};
17321748

17331749
template <>
@@ -1741,6 +1757,22 @@ inline void validate_expr(const array_list_exprt &value)
17411757
PRECONDITION(value.operands().size() % 2 == 0);
17421758
}
17431759

1760+
inline const array_list_exprt &to_array_list_expr(const exprt &expr)
1761+
{
1762+
PRECONDITION(can_cast_expr<array_list_exprt>(expr));
1763+
auto &ret = static_cast<const array_list_exprt &>(expr);
1764+
validate_expr(ret);
1765+
return ret;
1766+
}
1767+
1768+
inline array_list_exprt &to_array_list_expr(exprt &expr)
1769+
{
1770+
PRECONDITION(can_cast_expr<array_list_exprt>(expr));
1771+
auto &ret = static_cast<array_list_exprt &>(expr);
1772+
validate_expr(ret);
1773+
return ret;
1774+
}
1775+
17441776
/// \brief Vector constructor from list of elements
17451777
class vector_exprt : public multi_ary_exprt
17461778
{

0 commit comments

Comments
 (0)