Skip to content

Commit b497f6b

Browse files
committed
Make constant_exprt a nullary_exprt
It should always have been one, and the introduction of annotated_pointer_constant_exprt makes it possible to implement this. This highlighted to pieces of dead code: there are not `constant_exprt` of type `ID_array` for such constant are `array_exprt`; `goto_trace_constant_pointer_exprt` was never used (though meant to be what annotated_pointer_constant_exprt now actually is).
1 parent 112f1d0 commit b497f6b

File tree

3 files changed

+8
-53
lines changed

3 files changed

+8
-53
lines changed

src/goto-programs/goto_trace.h

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -296,32 +296,4 @@ void show_goto_trace(
296296
if(cmdline.isset("stack-trace")) \
297297
options.set_option("stack-trace", true);
298298

299-
/// Variety of constant expression only used in the context of a GOTO trace, to
300-
/// give both the numeric value and the symbolic value of a pointer,
301-
/// e.g. numeric value "0xabcd0004" but symbolic value "&some_object + 4". The
302-
/// numeric value is stored in the `constant_exprt`'s usual value slot (see
303-
/// \ref constant_exprt::get_value) and the symbolic value is accessed using the
304-
/// `symbolic_pointer` method introduced by this class.
305-
class goto_trace_constant_pointer_exprt : public constant_exprt
306-
{
307-
public:
308-
const exprt &symbolic_pointer() const
309-
{
310-
return static_cast<const exprt &>(operands()[0]);
311-
}
312-
};
313-
314-
template <>
315-
inline bool can_cast_expr<goto_trace_constant_pointer_exprt>(const exprt &base)
316-
{
317-
return can_cast_expr<constant_exprt>(base) && base.operands().size() == 1;
318-
}
319-
320-
inline const goto_trace_constant_pointer_exprt &
321-
to_goto_trace_constant_pointer_expr(const exprt &expr)
322-
{
323-
PRECONDITION(can_cast_expr<goto_trace_constant_pointer_exprt>(expr));
324-
return static_cast<const goto_trace_constant_pointer_exprt &>(expr);
325-
}
326-
327299
#endif // CPROVER_GOTO_PROGRAMS_GOTO_TRACE_H

src/solvers/flattening/boolbv_constant.cpp

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -22,29 +22,7 @@ bvt boolbvt::convert_constant(const constant_exprt &expr)
2222

2323
const typet &expr_type=expr.type();
2424

25-
if(expr_type.id()==ID_array)
26-
{
27-
std::size_t op_width=width/expr.operands().size();
28-
std::size_t offset=0;
29-
30-
forall_operands(it, expr)
31-
{
32-
const bvt &tmp=convert_bv(*it);
33-
34-
DATA_INVARIANT_WITH_DIAGNOSTICS(
35-
tmp.size() == op_width,
36-
"convert_constant: unexpected operand width",
37-
irep_pretty_diagnosticst{expr});
38-
39-
for(std::size_t j=0; j<op_width; j++)
40-
bv[offset+j]=tmp[j];
41-
42-
offset+=op_width;
43-
}
44-
45-
return bv;
46-
}
47-
else if(expr_type.id()==ID_string)
25+
if(expr_type.id() == ID_string)
4826
{
4927
// we use the numbering for strings
5028
std::size_t number = string_numbering.number(expr.get_value());

src/util/std_expr.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2799,11 +2799,11 @@ inline type_exprt &to_type_expr(exprt &expr)
27992799
}
28002800

28012801
/// \brief A constant literal expression
2802-
class constant_exprt : public expr_protectedt
2802+
class constant_exprt : public nullary_exprt
28032803
{
28042804
public:
28052805
constant_exprt(const irep_idt &_value, typet _type)
2806-
: expr_protectedt(ID_constant, std::move(_type))
2806+
: nullary_exprt(ID_constant, std::move(_type))
28072807
{
28082808
set_value(_value);
28092809
}
@@ -2827,6 +2827,11 @@ inline bool can_cast_expr<constant_exprt>(const exprt &base)
28272827
return base.id() == ID_constant;
28282828
}
28292829

2830+
inline void validate_expr(const constant_exprt &value)
2831+
{
2832+
validate_operands(value, 0, "Constants must not have operands");
2833+
}
2834+
28302835
/// \brief Cast an exprt to a \ref constant_exprt
28312836
///
28322837
/// \a expr must be known to be \ref constant_exprt.

0 commit comments

Comments
 (0)