Skip to content

Commit 6947aaa

Browse files
author
Daniel Kroening
committed
introduce protected_exprt
This will serve as the interface that we aspire exprt to offer; in particular, access to opX is protected.
1 parent 46eadfa commit 6947aaa

File tree

9 files changed

+136
-108
lines changed

9 files changed

+136
-108
lines changed

src/ansi-c/expr2c.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1941,9 +1941,11 @@ std::string expr2ct::convert_constant(
19411941
if(src.operands().size()!=1)
19421942
return convert_norep(src, precedence);
19431943

1944-
if(src.op0().id()==ID_constant)
1944+
const auto &annotation = to_unary_expr(src).op();
1945+
1946+
if(annotation.id() == ID_constant)
19451947
{
1946-
const irep_idt &op_value=src.op0().get(ID_value);
1948+
const irep_idt &op_value = to_constant_expr(annotation).get_value();
19471949

19481950
if(op_value=="INVALID" ||
19491951
has_prefix(id2string(op_value), "INVALID-") ||
@@ -1953,7 +1955,7 @@ std::string expr2ct::convert_constant(
19531955
return convert_norep(src, precedence);
19541956
}
19551957
else
1956-
return convert_with_precedence(src.op0(), precedence);
1958+
return convert_with_precedence(annotation, precedence);
19571959
}
19581960
}
19591961
else if(type.id()==ID_string)

src/goto-programs/remove_function_pointers.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -392,13 +392,13 @@ void remove_function_pointerst::remove_function_pointer(
392392
t3->make_goto(t_final, true_exprt());
393393

394394
// goto to call
395-
address_of_exprt address_of(fun, pointer_type(fun.type()));
395+
const address_of_exprt address_of(fun, pointer_type(fun.type()));
396396

397-
if(address_of.type()!=pointer.type())
398-
address_of.make_typecast(pointer.type());
397+
const auto casted_address =
398+
typecast_exprt::conditional_cast(address_of, pointer.type());
399399

400400
goto_programt::targett t4=new_code_gotos.add_instruction();
401-
t4->make_goto(t1, equal_exprt(pointer, address_of));
401+
t4->make_goto(t1, equal_exprt(pointer, casted_address));
402402
}
403403

404404
// fall-through

src/pointer-analysis/value_set_fi.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -870,8 +870,8 @@ void value_set_fit::get_reference_set_sharing_rec(
870870
insert(dest, exprt(ID_unknown, expr.type()));
871871
else
872872
{
873-
index_exprt index_expr(
874-
object, from_integer(0, index_type()), expr.type());
873+
exprt index_expr =
874+
index_exprt(object, from_integer(0, index_type()), expr.type());
875875

876876
// adjust type?
877877
if(object.type().id() != "#REF#" && object.type() != array_type)

src/pointer-analysis/value_set_fivr.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -981,8 +981,8 @@ void value_set_fivrt::get_reference_set_sharing_rec(
981981
insert_from(dest, exprt(ID_unknown, expr.type()));
982982
else
983983
{
984-
index_exprt index_expr(
985-
object, from_integer(0, index_type()), expr.type());
984+
exprt index_expr =
985+
index_exprt(object, from_integer(0, index_type()), expr.type());
986986

987987
// adjust type?
988988
if(object.type().id() != "#REF#" && object.type() != array_type)

src/pointer-analysis/value_set_fivrns.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -674,8 +674,8 @@ void value_set_fivrnst::get_reference_set_rec(
674674
insert_from(dest, exprt(ID_unknown, expr.type()));
675675
else
676676
{
677-
index_exprt index_expr(
678-
object, from_integer(0, index_type()), expr.type());
677+
exprt index_expr =
678+
index_exprt(object, from_integer(0, index_type()), expr.type());
679679

680680
// adjust type?
681681
if(object.type() != array_type)

src/util/expr.h

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,40 @@ class exprt:public irept
318318
const_unique_depth_iteratort unique_depth_cend() const;
319319
};
320320

321+
/// Protected class for all expressions.
322+
/// This API will eventually replace exprt.
323+
class protected_exprt : public exprt
324+
{
325+
protected:
326+
// constructors
327+
DEPRECATED("use protected_exprt(id, type) instead")
328+
protected_exprt() : exprt()
329+
{
330+
}
331+
332+
DEPRECATED("use protected_exprt(id, type) instead")
333+
explicit protected_exprt(const irep_idt &_id) : exprt(_id)
334+
{
335+
}
336+
337+
protected_exprt(const irep_idt &_id, const typet &_type) : exprt(_id, _type)
338+
{
339+
}
340+
341+
// protect these low-level methods
342+
using exprt::make_bool;
343+
using exprt::make_typecast;
344+
using exprt::op0;
345+
using exprt::op1;
346+
using exprt::op2;
347+
using exprt::op3;
348+
// using exprt::find;
349+
// using exprt::get;
350+
// using exprt::set;
351+
using exprt::add;
352+
using exprt::remove;
353+
};
354+
321355
class expr_visitort
322356
{
323357
public:

src/util/pointer_offset_size.cpp

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

601604
if(type.is_nil())
602605
return nil_exprt();

src/util/std_expr.cpp

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

0 commit comments

Comments
 (0)