Skip to content

Commit c97323b

Browse files
author
Daniel Kroening
committed
rewrite_union no longer needs a namespace
1 parent 338042e commit c97323b

File tree

2 files changed

+24
-45
lines changed

2 files changed

+24
-45
lines changed

src/goto-symex/rewrite_union.cpp

+20-33
Original file line numberDiff line numberDiff line change
@@ -20,76 +20,68 @@ Author: Daniel Kroening, [email protected]
2020

2121
#include <util/c_types.h>
2222

23-
static bool have_to_rewrite_union(
24-
const exprt &expr,
25-
const namespacet &ns)
23+
static bool have_to_rewrite_union(const exprt &expr)
2624
{
2725
if(expr.id()==ID_member)
2826
{
2927
const exprt &op=to_member_expr(expr).struct_op();
30-
const typet &op_type=ns.follow(op.type());
3128

32-
if(op_type.id()==ID_union)
29+
if(op.type().id() == ID_union_tag || op.type().id() == ID_union)
3330
return true;
3431
}
3532
else if(expr.id()==ID_union)
3633
return true;
3734

3835
forall_operands(it, expr)
39-
if(have_to_rewrite_union(*it, ns))
36+
if(have_to_rewrite_union(*it))
4037
return true;
4138

4239
return false;
4340
}
4441

4542
// inside an address of (&x), unions can simply
4643
// be type casts and don't have to be re-written!
47-
void rewrite_union_address_of(
48-
exprt &expr,
49-
const namespacet &ns)
44+
void rewrite_union_address_of(exprt &expr)
5045
{
51-
if(!have_to_rewrite_union(expr, ns))
46+
if(!have_to_rewrite_union(expr))
5247
return;
5348

5449
if(expr.id()==ID_index)
5550
{
56-
rewrite_union_address_of(to_index_expr(expr).array(), ns);
57-
rewrite_union(to_index_expr(expr).index(), ns);
51+
rewrite_union_address_of(to_index_expr(expr).array());
52+
rewrite_union(to_index_expr(expr).index());
5853
}
5954
else if(expr.id()==ID_member)
60-
rewrite_union_address_of(to_member_expr(expr).struct_op(), ns);
55+
rewrite_union_address_of(to_member_expr(expr).struct_op());
6156
else if(expr.id()==ID_symbol)
6257
{
6358
// done!
6459
}
6560
else if(expr.id()==ID_dereference)
66-
rewrite_union(to_dereference_expr(expr).pointer(), ns);
61+
rewrite_union(to_dereference_expr(expr).pointer());
6762
}
6863

6964
/// We rewrite u.c for unions u into byte_extract(u, 0), and { .c = v } into
7065
/// byte_update(NIL, 0, v)
71-
void rewrite_union(
72-
exprt &expr,
73-
const namespacet &ns)
66+
void rewrite_union(exprt &expr)
7467
{
7568
if(expr.id()==ID_address_of)
7669
{
77-
rewrite_union_address_of(to_address_of_expr(expr).object(), ns);
70+
rewrite_union_address_of(to_address_of_expr(expr).object());
7871
return;
7972
}
8073

81-
if(!have_to_rewrite_union(expr, ns))
74+
if(!have_to_rewrite_union(expr))
8275
return;
8376

8477
Forall_operands(it, expr)
85-
rewrite_union(*it, ns);
78+
rewrite_union(*it);
8679

8780
if(expr.id()==ID_member)
8881
{
8982
const exprt &op=to_member_expr(expr).struct_op();
90-
const typet &op_type=ns.follow(op.type());
9183

92-
if(op_type.id()==ID_union)
84+
if(op.type().id() == ID_union_tag || op.type().id() == ID_union)
9385
{
9486
exprt offset=from_integer(0, index_type());
9587
byte_extract_exprt tmp(byte_extract_id(), op, offset, expr.type());
@@ -107,27 +99,22 @@ void rewrite_union(
10799
}
108100
}
109101

110-
void rewrite_union(
111-
goto_functionst::goto_functiont &goto_function,
112-
const namespacet &ns)
102+
void rewrite_union(goto_functionst::goto_functiont &goto_function)
113103
{
114104
Forall_goto_program_instructions(it, goto_function.body)
115105
{
116-
rewrite_union(it->code, ns);
117-
rewrite_union(it->guard, ns);
106+
rewrite_union(it->code);
107+
rewrite_union(it->guard);
118108
}
119109
}
120110

121-
void rewrite_union(
122-
goto_functionst &goto_functions,
123-
const namespacet &ns)
111+
void rewrite_union(goto_functionst &goto_functions)
124112
{
125113
Forall_goto_functions(it, goto_functions)
126-
rewrite_union(it->second, ns);
114+
rewrite_union(it->second);
127115
}
128116

129117
void rewrite_union(goto_modelt &goto_model)
130118
{
131-
namespacet ns(goto_model.symbol_table);
132-
rewrite_union(goto_model.goto_functions, ns);
119+
rewrite_union(goto_model.goto_functions);
133120
}

src/goto-symex/rewrite_union.h

+4-12
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,9 @@ class namespacet;
1919
class goto_functionst;
2020
class goto_modelt;
2121

22-
void rewrite_union(
23-
exprt &expr,
24-
const namespacet &ns);
25-
26-
void rewrite_union(
27-
goto_functionst::goto_functiont &goto_function,
28-
const namespacet &ns);
29-
30-
void rewrite_union(
31-
goto_functionst &goto_functions,
32-
const namespacet &ns);
33-
void rewrite_union(goto_modelt &goto_model);
22+
void rewrite_union(exprt &);
23+
void rewrite_union(goto_functionst::goto_functiont &);
24+
void rewrite_union(goto_functionst &);
25+
void rewrite_union(goto_modelt &);
3426

3527
#endif // CPROVER_GOTO_SYMEX_REWRITE_UNION_H

0 commit comments

Comments
 (0)