Skip to content

Commit b03077b

Browse files
committed
Expose check_renaming utility function
In the process it is moved (without change) to renaming_level.h/cpp, alongside the similarly-structured get_original_name functions.
1 parent 3ad2a27 commit b03077b

File tree

3 files changed

+92
-84
lines changed

3 files changed

+92
-84
lines changed

src/goto-symex/goto_symex_state.cpp

Lines changed: 0 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -48,90 +48,6 @@ goto_symex_statet::goto_symex_statet(
4848

4949
goto_symex_statet::~goto_symex_statet()=default;
5050

51-
/// Check that \p expr is correctly renamed to level 2 and return true in case
52-
/// an error is detected.
53-
static bool check_renaming(const exprt &expr);
54-
55-
static bool check_renaming(const typet &type)
56-
{
57-
if(type.id()==ID_array)
58-
return check_renaming(to_array_type(type).size());
59-
else if(type.id() == ID_struct || type.id() == ID_union)
60-
{
61-
for(const auto &c : to_struct_union_type(type).components())
62-
if(check_renaming(c.type()))
63-
return true;
64-
}
65-
else if(type.has_subtype())
66-
return check_renaming(to_type_with_subtype(type).subtype());
67-
68-
return false;
69-
}
70-
71-
static bool check_renaming_l1(const exprt &expr)
72-
{
73-
if(check_renaming(expr.type()))
74-
return true;
75-
76-
if(expr.id()==ID_symbol)
77-
{
78-
const auto &type = expr.type();
79-
if(!expr.get_bool(ID_C_SSA_symbol))
80-
return type.id() != ID_code && type.id() != ID_mathematical_function;
81-
if(!to_ssa_expr(expr).get_level_2().empty())
82-
return true;
83-
if(to_ssa_expr(expr).get_original_expr().type() != type)
84-
return true;
85-
}
86-
else
87-
{
88-
forall_operands(it, expr)
89-
if(check_renaming_l1(*it))
90-
return true;
91-
}
92-
93-
return false;
94-
}
95-
96-
static bool check_renaming(const exprt &expr)
97-
{
98-
if(check_renaming(expr.type()))
99-
return true;
100-
101-
if(
102-
expr.id() == ID_address_of &&
103-
to_address_of_expr(expr).object().id() == ID_symbol)
104-
{
105-
return check_renaming_l1(to_address_of_expr(expr).object());
106-
}
107-
else if(
108-
expr.id() == ID_address_of &&
109-
to_address_of_expr(expr).object().id() == ID_index)
110-
{
111-
const auto index_expr = to_index_expr(to_address_of_expr(expr).object());
112-
return check_renaming_l1(index_expr.array()) ||
113-
check_renaming(index_expr.index());
114-
}
115-
else if(expr.id()==ID_symbol)
116-
{
117-
const auto &type = expr.type();
118-
if(!expr.get_bool(ID_C_SSA_symbol))
119-
return type.id() != ID_code && type.id() != ID_mathematical_function;
120-
if(to_ssa_expr(expr).get_level_2().empty())
121-
return true;
122-
if(to_ssa_expr(expr).get_original_expr().type() != type)
123-
return true;
124-
}
125-
else
126-
{
127-
forall_operands(it, expr)
128-
if(check_renaming(*it))
129-
return true;
130-
}
131-
132-
return false;
133-
}
134-
13551
template <>
13652
renamedt<ssa_exprt, L0>
13753
goto_symex_statet::set_indices<L0>(ssa_exprt ssa_expr, const namespacet &ns)

src/goto-symex/renaming_level.cpp

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,3 +205,83 @@ typet get_original_name(typet type)
205205
}
206206
return type;
207207
}
208+
209+
bool check_renaming(const typet &type)
210+
{
211+
if(type.id() == ID_array)
212+
return check_renaming(to_array_type(type).size());
213+
else if(type.id() == ID_struct || type.id() == ID_union)
214+
{
215+
for(const auto &c : to_struct_union_type(type).components())
216+
if(check_renaming(c.type()))
217+
return true;
218+
}
219+
else if(type.has_subtype())
220+
return check_renaming(to_type_with_subtype(type).subtype());
221+
222+
return false;
223+
}
224+
225+
bool check_renaming_l1(const exprt &expr)
226+
{
227+
if(check_renaming(expr.type()))
228+
return true;
229+
230+
if(expr.id() == ID_symbol)
231+
{
232+
const auto &type = expr.type();
233+
if(!expr.get_bool(ID_C_SSA_symbol))
234+
return type.id() != ID_code && type.id() != ID_mathematical_function;
235+
if(!to_ssa_expr(expr).get_level_2().empty())
236+
return true;
237+
if(to_ssa_expr(expr).get_original_expr().type() != type)
238+
return true;
239+
}
240+
else
241+
{
242+
forall_operands(it, expr)
243+
if(check_renaming_l1(*it))
244+
return true;
245+
}
246+
247+
return false;
248+
}
249+
250+
bool check_renaming(const exprt &expr)
251+
{
252+
if(check_renaming(expr.type()))
253+
return true;
254+
255+
if(
256+
expr.id() == ID_address_of &&
257+
to_address_of_expr(expr).object().id() == ID_symbol)
258+
{
259+
return check_renaming_l1(to_address_of_expr(expr).object());
260+
}
261+
else if(
262+
expr.id() == ID_address_of &&
263+
to_address_of_expr(expr).object().id() == ID_index)
264+
{
265+
const auto index_expr = to_index_expr(to_address_of_expr(expr).object());
266+
return check_renaming_l1(index_expr.array()) ||
267+
check_renaming(index_expr.index());
268+
}
269+
else if(expr.id() == ID_symbol)
270+
{
271+
const auto &type = expr.type();
272+
if(!expr.get_bool(ID_C_SSA_symbol))
273+
return type.id() != ID_code && type.id() != ID_mathematical_function;
274+
if(to_ssa_expr(expr).get_level_2().empty())
275+
return true;
276+
if(to_ssa_expr(expr).get_original_expr().type() != type)
277+
return true;
278+
}
279+
else
280+
{
281+
forall_operands(it, expr)
282+
if(check_renaming(*it))
283+
return true;
284+
}
285+
286+
return false;
287+
}

src/goto-symex/renaming_level.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,4 +103,16 @@ exprt get_original_name(exprt expr);
103103
/// Undo all levels of renaming
104104
typet get_original_name(typet type);
105105

106+
/// Check that \p expr is correctly renamed to level 2 and return true in case
107+
/// an error is detected.
108+
bool check_renaming(const exprt &expr);
109+
110+
/// Check that \p expr is correctly renamed to level 1 and return true in case
111+
/// an error is detected.
112+
bool check_renaming_l1(const exprt &expr);
113+
114+
/// Check that \p type is correctly renamed to level 2 and return true in case
115+
/// an error is detected.
116+
bool check_renaming(const typet &type);
117+
106118
#endif // CPROVER_GOTO_SYMEX_RENAMING_LEVEL_H

0 commit comments

Comments
 (0)