Skip to content

Commit c23e8ee

Browse files
committed
Use central is_constantt to identify constants for propagation
1 parent 9e4425a commit c23e8ee

File tree

2 files changed

+22
-40
lines changed

2 files changed

+22
-40
lines changed

src/analyses/constant_propagator.cpp

Lines changed: 22 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ Author: Peter Schrammel
1919
#include <util/arith_tools.h>
2020
#include <util/base_type.h>
2121
#include <util/cprover_prefix.h>
22+
#include <util/expr_util.h>
2223
#include <util/find_symbols.h>
2324
#include <util/ieee_float.h>
2425
#include <util/simplify_expr.h>
@@ -288,48 +289,31 @@ bool constant_propagator_domaint::ai_simplify(
288289

289290
bool constant_propagator_domaint::valuest::is_constant(const exprt &expr) const
290291
{
291-
if(expr.id()==ID_side_effect &&
292-
to_side_effect_expr(expr).get_statement()==ID_nondet)
293-
return false;
294-
295-
if(expr.id()==ID_side_effect &&
296-
to_side_effect_expr(expr).get_statement()==ID_allocate)
297-
return false;
298-
299-
if(expr.id()==ID_symbol)
300-
if(!replace_const.replaces_symbol(to_symbol_expr(expr).get_identifier()))
301-
return false;
302-
303-
if(expr.id()==ID_index)
304-
return false;
305-
306-
if(expr.id()==ID_address_of)
307-
return is_constant_address_of(to_address_of_expr(expr).object());
308-
309-
forall_operands(it, expr)
310-
if(!is_constant(*it))
311-
return false;
312-
313-
return true;
314-
}
315-
316-
bool constant_propagator_domaint::valuest::is_constant_address_of(
317-
const exprt &expr) const
318-
{
319-
if(expr.id()==ID_index)
320-
return is_constant_address_of(to_index_expr(expr).array()) &&
321-
is_constant(to_index_expr(expr).index());
292+
class constant_propagator_is_constantt : public is_constantt
293+
{
294+
public:
295+
explicit constant_propagator_is_constantt(
296+
const replace_symbolt &replace_const)
297+
: replace_const(replace_const)
298+
{
299+
}
322300

323-
if(expr.id()==ID_member)
324-
return is_constant_address_of(to_member_expr(expr).struct_op());
301+
protected:
302+
bool is_constant(const exprt &expr) const override
303+
{
304+
if(expr.id() == ID_symbol)
305+
{
306+
return replace_const.replaces_symbol(
307+
to_symbol_expr(expr).get_identifier());
308+
}
325309

326-
if(expr.id()==ID_dereference)
327-
return is_constant(to_dereference_expr(expr).pointer());
310+
return is_constantt::is_constant(expr);
311+
}
328312

329-
if(expr.id()==ID_string_constant)
330-
return true;
313+
const replace_symbolt &replace_const;
314+
};
331315

332-
return true;
316+
return constant_propagator_is_constantt(replace_const)(expr);
333317
}
334318

335319
/// Do not call this when iterating over replace_const.expr_map!

src/analyses/constant_propagator.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,6 @@ class constant_propagator_domaint:public ai_domain_baset
124124
void set_dirty_to_top(const dirtyt &dirty, const namespacet &ns);
125125

126126
bool is_constant(const exprt &expr) const;
127-
bool is_array_constant(const exprt &expr) const;
128-
bool is_constant_address_of(const exprt &expr) const;
129127

130128
bool is_empty() const
131129
{

0 commit comments

Comments
 (0)