Skip to content

Commit 3aa0eee

Browse files
committed
Rename is_constantt (and it's children) to can_forward_propagatet
There is too much ambiguity in what could be called a "constant," and we really mean "this expression can be forward propagated."
1 parent 3bdc70f commit 3aa0eee

13 files changed

+44
-38
lines changed

src/analyses/constant_propagator.cpp

+7-6
Original file line numberDiff line numberDiff line change
@@ -416,13 +416,13 @@ bool constant_propagator_domaint::ai_simplify(
416416
return partial_evaluate(values, condition, ns);
417417
}
418418

419-
class constant_propagator_is_constantt : public is_constantt
419+
class constant_propagator_can_forward_propagatet : public can_forward_propagatet
420420
{
421421
public:
422-
constant_propagator_is_constantt(
422+
constant_propagator_can_forward_propagatet(
423423
const replace_symbolt &replace_const,
424424
const namespacet &ns)
425-
: is_constantt(ns), replace_const(replace_const)
425+
: can_forward_propagatet(ns), replace_const(replace_const)
426426
{
427427
}
428428

@@ -437,7 +437,7 @@ class constant_propagator_is_constantt : public is_constantt
437437
if(expr.id() == ID_symbol)
438438
return is_constant(to_symbol_expr(expr).get_identifier());
439439

440-
return is_constantt::is_constant(expr);
440+
return can_forward_propagatet::is_constant(expr);
441441
}
442442

443443
const replace_symbolt &replace_const;
@@ -447,14 +447,15 @@ bool constant_propagator_domaint::valuest::is_constant(
447447
const exprt &expr,
448448
const namespacet &ns) const
449449
{
450-
return constant_propagator_is_constantt(replace_const, ns)(expr);
450+
return constant_propagator_can_forward_propagatet(replace_const, ns)(expr);
451451
}
452452

453453
bool constant_propagator_domaint::valuest::is_constant(
454454
const irep_idt &id,
455455
const namespacet &ns) const
456456
{
457-
return constant_propagator_is_constantt(replace_const, ns).is_constant(id);
457+
return constant_propagator_can_forward_propagatet(replace_const, ns)
458+
.is_constant(id);
458459
}
459460

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

src/goto-instrument/contracts/dynamic-frames/dfcc_infer_loop_assigns.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ assignst dfcc_infer_loop_assigns(
6666
// widen or drop targets that depend on loop-locals or are non-constant,
6767
// ie. depend on other locations assigned by the loop.
6868
// e.g: if the loop assigns {i, a[i]}, then a[i] is non-constant.
69-
havoc_utils_is_constantt is_constant(assigns, ns);
69+
havoc_utils_can_forward_propagatet is_constant(assigns, ns);
7070
assignst result;
7171
for(const auto &expr : assigns)
7272
{

src/goto-instrument/contracts/utils.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ void widen_assigns(assignst &assigns, const namespacet &ns)
341341
{
342342
assignst result;
343343

344-
havoc_utils_is_constantt is_constant(assigns, ns);
344+
havoc_utils_can_forward_propagatet is_constant(assigns, ns);
345345

346346
for(const auto &e : assigns)
347347
{

src/goto-instrument/havoc_utils.h

+10-7
Original file line numberDiff line numberDiff line change
@@ -24,22 +24,25 @@ class goto_programt;
2424
typedef std::set<exprt> assignst;
2525

2626
/// \brief A class containing utility functions for havocing expressions.
27-
class havoc_utils_is_constantt : public is_constantt
27+
class havoc_utils_can_forward_propagatet : public can_forward_propagatet
2828
{
2929
public:
30-
explicit havoc_utils_is_constantt(const assignst &mod, const namespacet &ns)
31-
: is_constantt(ns), assigns(mod)
30+
explicit havoc_utils_can_forward_propagatet(
31+
const assignst &mod,
32+
const namespacet &ns)
33+
: can_forward_propagatet(ns), assigns(mod)
3234
{
3335
}
3436

3537
bool is_constant(const exprt &expr) const override
3638
{
37-
// Besides the "usual" constants (checked in is_constantt::is_constant),
38-
// we also treat unmodified symbols as constants
39+
// Besides the "usual" constants (checked in
40+
// can_forward_propagatet::is_constant), we also treat unmodified symbols as
41+
// constants
3942
if(expr.id() == ID_symbol && assigns.find(expr) == assigns.end())
4043
return true;
4144

42-
return is_constantt::is_constant(expr);
45+
return can_forward_propagatet::is_constant(expr);
4346
}
4447

4548
protected:
@@ -102,7 +105,7 @@ class havoc_utilst
102105

103106
protected:
104107
const assignst &assigns;
105-
const havoc_utils_is_constantt is_constant;
108+
const havoc_utils_can_forward_propagatet is_constant;
106109
};
107110

108111
#endif // CPROVER_GOTO_INSTRUMENT_HAVOC_UTILS_H

src/goto-symex/goto_state.cpp

+5-4
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@ Author: Romain Brenguier, [email protected]
77
\*******************************************************************/
88

99
#include "goto_state.h"
10-
#include "goto_symex_is_constant.h"
11-
#include "goto_symex_state.h"
1210

1311
#include <util/format_expr.h>
1412

13+
#include "goto_symex_can_forward_propagate.h"
14+
#include "goto_symex_state.h"
15+
1516
/// Print the constant propagation map in a human-friendly format.
1617
/// This is primarily for use from the debugger; please don't delete me just
1718
/// because there aren't any current callers.
@@ -91,7 +92,7 @@ void goto_statet::apply_condition(
9192
if(is_ssa_expr(rhs))
9293
std::swap(lhs, rhs);
9394

94-
if(is_ssa_expr(lhs) && goto_symex_is_constantt(ns)(rhs))
95+
if(is_ssa_expr(lhs) && goto_symex_can_forward_propagatet(ns)(rhs))
9596
{
9697
const ssa_exprt &ssa_lhs = to_ssa_expr(lhs);
9798
INVARIANT(
@@ -141,7 +142,7 @@ void goto_statet::apply_condition(
141142
if(is_ssa_expr(rhs))
142143
std::swap(lhs, rhs);
143144

144-
if(!is_ssa_expr(lhs) || !goto_symex_is_constantt(ns)(rhs))
145+
if(!is_ssa_expr(lhs) || !goto_symex_can_forward_propagatet(ns)(rhs))
145146
return;
146147

147148
if(rhs.is_true())

src/goto-symex/goto_symex_is_constant.h renamed to src/goto-symex/goto_symex_can_forward_propagate.h

+7-6
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,17 @@ Author: Michael Tautschig, [email protected]
99
/// \file
1010
/// GOTO Symex constant propagation
1111

12-
#ifndef CPROVER_GOTO_SYMEX_GOTO_SYMEX_IS_CONSTANT_H
13-
#define CPROVER_GOTO_SYMEX_GOTO_SYMEX_IS_CONSTANT_H
12+
#ifndef CPROVER_GOTO_SYMEX_GOTO_SYMEX_CAN_FORWARD_PROPAGATE_H
13+
#define CPROVER_GOTO_SYMEX_GOTO_SYMEX_CAN_FORWARD_PROPAGATE_H
1414

1515
#include <util/expr.h>
1616
#include <util/expr_util.h>
1717

18-
class goto_symex_is_constantt : public is_constantt
18+
class goto_symex_can_forward_propagatet : public can_forward_propagatet
1919
{
2020
public:
21-
explicit goto_symex_is_constantt(const namespacet &ns) : is_constantt(ns)
21+
explicit goto_symex_can_forward_propagatet(const namespacet &ns)
22+
: can_forward_propagatet(ns)
2223
{
2324
}
2425

@@ -56,8 +57,8 @@ class goto_symex_is_constantt : public is_constantt
5657
#endif
5758
}
5859

59-
return is_constantt::is_constant(expr);
60+
return can_forward_propagatet::is_constant(expr);
6061
}
6162
};
6263

63-
#endif // CPROVER_GOTO_SYMEX_GOTO_SYMEX_IS_CONSTANT_H
64+
#endif // CPROVER_GOTO_SYMEX_GOTO_SYMEX_CAN_FORWARD_PROPAGATE_H

src/goto-symex/goto_symex_state.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Author: Daniel Kroening, [email protected]
2323
#include <analyses/dirty.h>
2424
#include <pointer-analysis/add_failed_symbols.h>
2525

26-
#include "goto_symex_is_constant.h"
26+
#include "goto_symex_can_forward_propagate.h"
2727
#include "symex_target_equation.h"
2828

2929
static void get_l1_name(exprt &expr);
@@ -112,7 +112,7 @@ renamedt<ssa_exprt, L2> goto_symex_statet::assignment(
112112
"pointer handling for concurrency is unsound");
113113

114114
// Update constant propagation map -- the RHS is L2
115-
if(!is_shared && record_value && goto_symex_is_constantt(ns)(rhs))
115+
if(!is_shared && record_value && goto_symex_can_forward_propagatet(ns)(rhs))
116116
{
117117
const auto propagation_entry = propagation.find(l1_identifier);
118118
if(!propagation_entry.has_value())

src/goto-symex/symex_goto.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ Author: Daniel Kroening, [email protected]
2222
#include <pointer-analysis/value_set_dereference.h>
2323

2424
#include "goto_symex.h"
25-
#include "goto_symex_is_constant.h"
25+
#include "goto_symex_can_forward_propagate.h"
2626
#include "path_storage.h"
2727

2828
#include <algorithm>
@@ -204,7 +204,7 @@ static optionalt<renamedt<exprt, L2>> try_evaluate_pointer_comparison(
204204
if(!symbol_expr_lhs)
205205
return {};
206206

207-
if(!goto_symex_is_constantt(ns)(rhs))
207+
if(!goto_symex_can_forward_propagatet(ns)(rhs))
208208
return {};
209209

210210
return try_evaluate_pointer_comparison(

src/goto-synthesizer/enumerative_loop_contracts_synthesizer.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ void enumerative_loop_contracts_synthesizert::synthesize_assigns(
160160
if(new_assign.id() == ID_index || new_assign.id() == ID_dereference)
161161
{
162162
address_of_exprt address_of_new_assigns(new_assign);
163-
havoc_utils_is_constantt is_constant(assigns_map[loop_id], ns);
163+
havoc_utils_can_forward_propagatet is_constant(assigns_map[loop_id], ns);
164164
if(!is_constant(address_of_new_assigns))
165165
{
166166
new_assign = pointer_object(address_of_new_assigns);

src/util/expr_util.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ const exprt &skip_typecast(const exprt &expr)
226226

227227
/// This function determines what expressions are to be propagated as
228228
/// "constants"
229-
bool is_constantt::is_constant(const exprt &expr) const
229+
bool can_forward_propagatet::is_constant(const exprt &expr) const
230230
{
231231
if(
232232
expr.id() == ID_symbol || expr.id() == ID_nondet_symbol ||
@@ -306,7 +306,7 @@ bool is_constantt::is_constant(const exprt &expr) const
306306
}
307307

308308
/// this function determines which reference-typed expressions are constant
309-
bool is_constantt::is_constant_address_of(const exprt &expr) const
309+
bool can_forward_propagatet::is_constant_address_of(const exprt &expr) const
310310
{
311311
if(expr.id() == ID_symbol)
312312
{

src/util/expr_util.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,10 @@ const exprt &skip_typecast(const exprt &expr);
8585
/// An implementation may derive from this class to refine what it considers
8686
/// constant in a particular context by overriding is_constant and/or
8787
/// is_constant_address_of.
88-
class is_constantt
88+
class can_forward_propagatet
8989
{
9090
public:
91-
explicit is_constantt(const namespacet &ns) : ns(ns)
91+
explicit can_forward_propagatet(const namespacet &ns) : ns(ns)
9292
{
9393
}
9494

src/util/simplify_expr.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1986,7 +1986,7 @@ simplify_exprt::simplify_byte_extract(const byte_extract_exprt &expr)
19861986
if(subexpr.has_value() && subexpr.value() != expr)
19871987
return changed(simplify_rec(subexpr.value())); // recursive call
19881988

1989-
if(is_constantt(ns)(expr))
1989+
if(can_forward_propagatet(ns)(expr))
19901990
return changed(simplify_rec(lower_byte_extract(expr, ns)));
19911991

19921992
return unchanged(expr);

unit/goto-symex/is_constant.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*******************************************************************\
22
3-
Module: Unit tests for goto_symex_is_constantt
3+
Module: Unit tests for goto_symex_can_forward_propagatet
44
55
Author: Diffblue Ltd.
66
@@ -11,7 +11,7 @@ Author: Diffblue Ltd.
1111
#include <util/std_expr.h>
1212
#include <util/symbol_table.h>
1313

14-
#include <goto-symex/goto_symex_is_constant.h>
14+
#include <goto-symex/goto_symex_can_forward_propagate.h>
1515
#include <testing-utils/use_catch.h>
1616

1717
SCENARIO("goto-symex-is-constant", "[core][goto-symex][is_constant]")
@@ -24,7 +24,7 @@ SCENARIO("goto-symex-is-constant", "[core][goto-symex][is_constant]")
2424
sizeof_constant.set(ID_C_c_sizeof_type, int_type);
2525
symbol_exprt non_constant("x", int_type);
2626

27-
goto_symex_is_constantt is_constant(ns);
27+
goto_symex_can_forward_propagatet is_constant(ns);
2828

2929
GIVEN("Sizeof expression multiplied by a non-constant")
3030
{

0 commit comments

Comments
 (0)