Skip to content

Commit a67014b

Browse files
author
Daniel Kroening
committed
introduce expr_protectedt
This will serve as the interface that we aspire exprt to offer; in particular, access to opX is protected.
1 parent 8ddf489 commit a67014b

File tree

4 files changed

+111
-89
lines changed

4 files changed

+111
-89
lines changed

src/util/expr.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,29 @@ class exprt:public irept
319319
const_unique_depth_iteratort unique_depth_cend() const;
320320
};
321321

322+
/// Class for expressions that offers a restriction of the API
323+
/// offered by exprt. Notably, access to non-type-safe methods such
324+
/// as opX() is protected.
325+
/// This API will eventually replace exprt.
326+
class expr_protectedt : public exprt
327+
{
328+
protected:
329+
// constructor
330+
expr_protectedt(const irep_idt &_id, const typet &_type) : exprt(_id, _type)
331+
{
332+
}
333+
334+
// protect these low-level methods
335+
using exprt::make_bool;
336+
using exprt::make_typecast;
337+
using exprt::op0;
338+
using exprt::op1;
339+
using exprt::op2;
340+
using exprt::op3;
341+
using exprt::add;
342+
using exprt::remove;
343+
};
344+
322345
class expr_visitort
323346
{
324347
public:

src/util/pointer_offset_size.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -593,8 +593,11 @@ exprt build_sizeof_expr(
593593
const constant_exprt &expr,
594594
const namespacet &ns)
595595
{
596-
const typet &type=
597-
static_cast<const typet &>(expr.find(ID_C_c_sizeof_type));
596+
// need to cast down to access 'find'
597+
const auto &expr_as_irep = static_cast<const irept &>(expr);
598+
599+
const typet &type =
600+
static_cast<const typet &>(expr_as_irep.find(ID_C_c_sizeof_type));
598601

599602
if(type.is_nil())
600603
return nil_exprt();

src/util/std_expr.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,8 @@ extractbits_exprt::extractbits_exprt(
150150
const exprt &_src,
151151
const std::size_t _upper,
152152
const std::size_t _lower,
153-
const typet &_type):
154-
exprt(ID_extractbits, _type)
153+
const typet &_type)
154+
: protected_exprt(ID_extractbits, _type)
155155
{
156156
PRECONDITION(_upper >= _lower);
157157
operands().resize(3);

0 commit comments

Comments
 (0)