20
20
21
21
#include < util/c_types.h>
22
22
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)
26
24
{
27
25
if (expr.id ()==ID_member)
28
26
{
29
27
const exprt &op=to_member_expr (expr).struct_op ();
30
- const typet &op_type=ns.follow (op.type ());
31
28
32
- if (op_type. id ()== ID_union)
29
+ if (op. type (). id () == ID_union_tag || op. type (). id () == ID_union)
33
30
return true ;
34
31
}
35
32
else if (expr.id ()==ID_union)
36
33
return true ;
37
34
38
35
forall_operands (it, expr)
39
- if (have_to_rewrite_union (*it, ns ))
36
+ if (have_to_rewrite_union (*it))
40
37
return true ;
41
38
42
39
return false ;
43
40
}
44
41
45
42
// inside an address of (&x), unions can simply
46
43
// 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)
50
45
{
51
- if (!have_to_rewrite_union (expr, ns ))
46
+ if (!have_to_rewrite_union (expr))
52
47
return ;
53
48
54
49
if (expr.id ()==ID_index)
55
50
{
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 ());
58
53
}
59
54
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 ());
61
56
else if (expr.id ()==ID_symbol)
62
57
{
63
58
// done!
64
59
}
65
60
else if (expr.id ()==ID_dereference)
66
- rewrite_union (to_dereference_expr (expr).pointer (), ns );
61
+ rewrite_union (to_dereference_expr (expr).pointer ());
67
62
}
68
63
69
64
// / We rewrite u.c for unions u into byte_extract(u, 0), and { .c = v } into
70
65
// / byte_update(NIL, 0, v)
71
- void rewrite_union (
72
- exprt &expr,
73
- const namespacet &ns)
66
+ void rewrite_union (exprt &expr)
74
67
{
75
68
if (expr.id ()==ID_address_of)
76
69
{
77
- rewrite_union_address_of (to_address_of_expr (expr).object (), ns );
70
+ rewrite_union_address_of (to_address_of_expr (expr).object ());
78
71
return ;
79
72
}
80
73
81
- if (!have_to_rewrite_union (expr, ns ))
74
+ if (!have_to_rewrite_union (expr))
82
75
return ;
83
76
84
77
Forall_operands (it, expr)
85
- rewrite_union (*it, ns );
78
+ rewrite_union (*it);
86
79
87
80
if (expr.id ()==ID_member)
88
81
{
89
82
const exprt &op=to_member_expr (expr).struct_op ();
90
- const typet &op_type=ns.follow (op.type ());
91
83
92
- if (op_type. id ()== ID_union)
84
+ if (op. type (). id () == ID_union_tag || op. type (). id () == ID_union)
93
85
{
94
86
exprt offset=from_integer (0 , index_type ());
95
87
byte_extract_exprt tmp (byte_extract_id (), op, offset, expr.type ());
@@ -107,27 +99,22 @@ void rewrite_union(
107
99
}
108
100
}
109
101
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)
113
103
{
114
104
Forall_goto_program_instructions (it, goto_function.body )
115
105
{
116
- rewrite_union (it->code , ns );
117
- rewrite_union (it->guard , ns );
106
+ rewrite_union (it->code );
107
+ rewrite_union (it->guard );
118
108
}
119
109
}
120
110
121
- void rewrite_union (
122
- goto_functionst &goto_functions,
123
- const namespacet &ns)
111
+ void rewrite_union (goto_functionst &goto_functions)
124
112
{
125
113
Forall_goto_functions (it, goto_functions)
126
- rewrite_union (it->second , ns );
114
+ rewrite_union (it->second );
127
115
}
128
116
129
117
void rewrite_union (goto_modelt &goto_model)
130
118
{
131
- namespacet ns (goto_model.symbol_table );
132
- rewrite_union (goto_model.goto_functions , ns);
119
+ rewrite_union (goto_model.goto_functions );
133
120
}
0 commit comments