Skip to content

Commit 21eccc9

Browse files
committed
Prepare for strict type checking in replace_symbolt
The derived class unchecked_replace_symbolt will not do any such type checking and is to be used in all cases where types are expected to change or no type checking can be performed.
1 parent e1fc49f commit 21eccc9

File tree

9 files changed

+53
-10
lines changed

9 files changed

+53
-10
lines changed

src/analyses/constant_propagator.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ class constant_propagator_domaint:public ai_domain_baset
7171
struct valuest
7272
{
7373
// maps variables to constants
74-
replace_symbolt replace_const;
74+
unchecked_replace_symbolt replace_const;
7575
bool is_bottom = true;
7676

7777
bool merge(const valuest &src);

src/goto-instrument/code_contracts.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ void code_contractst::apply_contract(
185185
return;
186186

187187
// replace formal parameters by arguments, replace return
188-
replace_symbolt replace;
188+
unchecked_replace_symbolt replace;
189189

190190
// TODO: return value could be nil
191191
if(type.return_type()!=empty_typet())
@@ -303,7 +303,7 @@ void code_contractst::add_contract_check(
303303
// prepare function call including all declarations
304304
code_function_callt call;
305305
call.function()=ns.lookup(function).symbol_expr();
306-
replace_symbolt replace;
306+
unchecked_replace_symbolt replace;
307307

308308
// decl ret
309309
if(gf.type.return_type()!=empty_typet())

src/goto-instrument/dump_c.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -908,7 +908,7 @@ void dump_ct::convert_global_variable(
908908
/// \param b: Code block to be cleaned
909909
void dump_ct::cleanup_harness(code_blockt &b)
910910
{
911-
replace_symbolt replace;
911+
unchecked_replace_symbolt replace;
912912
code_blockt decls;
913913

914914
const symbolt *argc_sym=nullptr;

src/goto-instrument/model_argc_argv.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ bool model_argc_argv(
125125
{
126126
value = symbol_pair.second.value;
127127

128-
replace_symbolt replace;
128+
unchecked_replace_symbolt replace;
129129
replace.insert("ARGC", ns.lookup("argc'").symbol_expr());
130130
replace.insert("ARGV", ns.lookup("argv'").symbol_expr());
131131
replace(value);

src/linking/linking_class.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class linkingt:public typecheckt
3535
virtual void typecheck();
3636

3737
rename_symbolt rename_symbol;
38-
replace_symbolt object_type_updates;
38+
unchecked_replace_symbolt object_type_updates;
3939

4040
protected:
4141
bool needs_renaming_type(

src/solvers/smt2/smt2_solver.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ void smt2_solvert::expand_function_applications(exprt &expr)
101101
app.arguments().size(),
102102
"number of function parameters");
103103

104-
replace_symbolt replace_symbol;
104+
unchecked_replace_symbolt replace_symbol;
105105

106106
std::map<irep_idt, exprt> parameter_map;
107107
for(std::size_t i=0; i<f_type.domain().size(); i++)

src/util/replace_symbol.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,3 +261,33 @@ bool replace_symbolt::have_to_replace(const typet &dest) const
261261

262262
return false;
263263
}
264+
265+
unchecked_replace_symbolt &unchecked_replace_symbolt::operator=(
266+
const unchecked_replace_symbolt &other)
267+
{
268+
expr_map = other.expr_map;
269+
type_map = other.type_map;
270+
271+
return *this;
272+
}
273+
274+
void unchecked_replace_symbolt::insert(
275+
const irep_idt &identifier,
276+
const exprt &new_expr)
277+
{
278+
expr_map.emplace(identifier, new_expr);
279+
}
280+
281+
void unchecked_replace_symbolt::insert(
282+
const symbol_exprt &old_expr,
283+
const exprt &new_expr)
284+
{
285+
insert(old_expr.get_identifier(), new_expr);
286+
}
287+
288+
void unchecked_replace_symbolt::insert(
289+
const irep_idt &identifier,
290+
const typet &new_type)
291+
{
292+
type_map.emplace(identifier, new_type);
293+
}

src/util/replace_symbol.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,4 +113,18 @@ class replace_symbolt
113113
bool have_to_replace(const typet &type) const;
114114
};
115115

116+
class unchecked_replace_symbolt : public replace_symbolt
117+
{
118+
public:
119+
unchecked_replace_symbolt()
120+
{
121+
}
122+
123+
unchecked_replace_symbolt &operator=(const unchecked_replace_symbolt &other);
124+
125+
void insert(const irep_idt &identifier, const exprt &new_expr);
126+
void insert(const symbol_exprt &old_expr, const exprt &new_expr);
127+
void insert(const irep_idt &identifier, const typet &new_type);
128+
};
129+
116130
#endif // CPROVER_UTIL_REPLACE_SYMBOL_H

unit/util/replace_symbol.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,8 @@ TEST_CASE("Replace all symbols in expression", "[core][util][replace_symbol]")
2525

2626
exprt other_expr("other");
2727

28-
replace_symbolt r;
28+
unchecked_replace_symbolt r;
2929
REQUIRE(r.empty());
30-
3130
r.insert("a", other_expr);
3231
REQUIRE(r.replaces_symbol("a"));
3332
REQUIRE(r.get_expr_map().size() == 1);
@@ -62,7 +61,7 @@ TEST_CASE("Lvalue only", "[core][util][replace_symbol]")
6261

6362
constant_exprt c("some_value", typet("some_type"));
6463

65-
replace_symbolt r;
64+
unchecked_replace_symbolt r;
6665
r.insert("a", c);
6766

6867
REQUIRE(r.replace(binary) == false);

0 commit comments

Comments
 (0)