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
129117void 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}
0 commit comments