Skip to content

Commit 6dbf798

Browse files
committed
Add an identifier-based lookup to constant_propagator_is_constantt
This avoid the workaround of constructing a symbol_exprt without proper type just for the sake of a lookup.
1 parent bafd7e7 commit 6dbf798

File tree

2 files changed

+31
-23
lines changed

2 files changed

+31
-23
lines changed

src/analyses/constant_propagator.cpp

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -416,35 +416,42 @@ bool constant_propagator_domaint::ai_simplify(
416416
}
417417

418418

419-
bool constant_propagator_domaint::valuest::is_constant(const exprt &expr) const
419+
class constant_propagator_is_constantt : public is_constantt
420420
{
421-
class constant_propagator_is_constantt : public is_constantt
421+
public:
422+
explicit constant_propagator_is_constantt(
423+
const replace_symbolt &replace_const)
424+
: replace_const(replace_const)
422425
{
423-
public:
424-
explicit constant_propagator_is_constantt(
425-
const replace_symbolt &replace_const)
426-
: replace_const(replace_const)
427-
{
428-
}
426+
}
429427

430-
protected:
431-
bool is_constant(const exprt &expr) const override
432-
{
433-
if(expr.id() == ID_symbol)
434-
{
435-
return replace_const.replaces_symbol(
436-
to_symbol_expr(expr).get_identifier());
437-
}
428+
bool is_constantt(const irep_idt &id) const
429+
{
430+
return replace_const.replaces_symbol(id);
431+
}
438432

439-
return is_constantt::is_constant(expr);
440-
}
433+
protected:
434+
bool is_constant(const exprt &expr) const override
435+
{
436+
if(expr.id() == ID_symbol)
437+
return is_constant(to_symbol_expr(expr).get_identifier());
441438

442-
const replace_symbolt &replace_const;
443-
};
439+
return is_constantt::is_constant(expr);
440+
}
441+
442+
const replace_symbolt &replace_const;
443+
};
444444

445+
bool constant_propagator_domaint::valuest::is_constant(const exprt &expr) const
446+
{
445447
return constant_propagator_is_constantt(replace_const)(expr);
446448
}
447449

450+
bool constant_propagator_domaint::valuest::is_constant(const irep_idt &id) const
451+
{
452+
return constant_propagator_is_constantt(replace_const)(id);
453+
}
454+
448455
/// Do not call this when iterating over replace_const.expr_map!
449456
bool constant_propagator_domaint::valuest::set_to_top(
450457
const symbol_exprt &symbol_expr)
@@ -649,10 +656,9 @@ bool constant_propagator_domaint::partial_evaluate(
649656
// if the current rounding mode is top we can
650657
// still get a non-top result by trying all rounding
651658
// modes and checking if the results are all the same
652-
if(!known_values.is_constant(symbol_exprt(ID_cprover_rounding_mode_str)))
653-
{
659+
if(!known_values.is_constant(ID_cprover_rounding_mode_str))
654660
return partial_evaluate_with_all_rounding_modes(known_values, expr, ns);
655-
}
661+
656662
return replace_constants_and_simplify(known_values, expr, ns);
657663
}
658664

src/analyses/constant_propagator.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,8 @@ class constant_propagator_domaint:public ai_domain_baset
125125

126126
bool is_constant(const exprt &expr) const;
127127

128+
bool is_constant(const irep_idt &id) const;
129+
128130
bool is_empty() const
129131
{
130132
return replace_const.empty();

0 commit comments

Comments
 (0)