8
8
9
9
#include " rename_symbol.h"
10
10
11
+ #include " expr_iterator.h"
11
12
#include " std_types.h"
12
13
#include " std_expr.h"
13
14
@@ -30,45 +31,52 @@ bool rename_symbolt::rename(exprt &dest) const
30
31
{
31
32
bool result=true ;
32
33
33
- // first look at type
34
-
35
- const exprt &const_dest (dest);
36
- if (have_to_rename (const_dest.type ()))
37
- if (!rename (dest.type ()))
38
- result=false ;
39
-
40
- // now do expression itself
41
-
42
- if (!have_to_rename (dest))
43
- return result;
44
-
45
- if (dest.id ()==ID_symbol)
34
+ for (auto it = dest.depth_begin (), end = dest.depth_end (); it != end; ++it)
46
35
{
47
- expr_mapt::const_iterator it=
48
- expr_map.find (to_symbol_expr (dest).get_identifier ());
36
+ exprt * modifiable_expr = nullptr ;
49
37
50
- if (it!=expr_map.end ())
38
+ // first look at type
39
+ if (have_to_rename (it->type ()))
51
40
{
52
- to_symbol_expr (dest). set_identifier (it-> second );
53
- return false ;
41
+ modifiable_expr = &it. mutate ( );
42
+ result &= rename (modifiable_expr-> type ()) ;
54
43
}
55
- }
56
-
57
- Forall_operands (it, dest)
58
- if (!rename (*it))
59
- result=false ;
60
44
61
- const irept &c_sizeof_type=dest.find (ID_C_c_sizeof_type);
45
+ // now do expression itself
46
+ if (it->id ()==ID_symbol)
47
+ {
48
+ expr_mapt::const_iterator entry =
49
+ expr_map.find (to_symbol_expr (*it).get_identifier ());
62
50
63
- if (c_sizeof_type.is_not_nil () &&
64
- !rename (static_cast <typet&>(dest.add (ID_C_c_sizeof_type))))
65
- result=false ;
51
+ if (entry != expr_map.end ())
52
+ {
53
+ if (!modifiable_expr)
54
+ modifiable_expr = &it.mutate ();
55
+ to_symbol_expr (*modifiable_expr).set_identifier (entry->second );
56
+ result = false ;
57
+ }
58
+ }
66
59
67
- const irept &va_arg_type=dest.find (ID_C_va_arg_type);
60
+ const typet &c_sizeof_type =
61
+ static_cast <const typet&>(it->find (ID_C_c_sizeof_type));
62
+ if (c_sizeof_type.is_not_nil () && have_to_rename (c_sizeof_type))
63
+ {
64
+ if (!modifiable_expr)
65
+ modifiable_expr = &it.mutate ();
66
+ result &=
67
+ rename (static_cast <typet&>(modifiable_expr->add (ID_C_c_sizeof_type)));
68
+ }
68
69
69
- if (va_arg_type.is_not_nil () &&
70
- !rename (static_cast <typet&>(dest.add (ID_C_va_arg_type))))
71
- result=false ;
70
+ const typet &va_arg_type =
71
+ static_cast <const typet&>(it->find (ID_C_va_arg_type));
72
+ if (va_arg_type.is_not_nil () && have_to_rename (va_arg_type))
73
+ {
74
+ if (!modifiable_expr)
75
+ modifiable_expr = &it.mutate ();
76
+ result &=
77
+ rename (static_cast <typet&>(modifiable_expr->add (ID_C_va_arg_type)));
78
+ }
79
+ }
72
80
73
81
return result;
74
82
}
0 commit comments