Skip to content

Commit 430d402

Browse files
committed
Use exprt::depth_iterator in rename_symbolt
1 parent 54e5b85 commit 430d402

File tree

1 file changed

+39
-31
lines changed

1 file changed

+39
-31
lines changed

src/util/rename_symbol.cpp

Lines changed: 39 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Author: Daniel Kroening, [email protected]
88

99
#include "rename_symbol.h"
1010

11+
#include "expr_iterator.h"
1112
#include "std_types.h"
1213
#include "std_expr.h"
1314

@@ -30,45 +31,52 @@ bool rename_symbolt::rename(exprt &dest) const
3031
{
3132
bool result=true;
3233

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)
4635
{
47-
expr_mapt::const_iterator it=
48-
expr_map.find(to_symbol_expr(dest).get_identifier());
36+
exprt * modifiable_expr = nullptr;
4937

50-
if(it!=expr_map.end())
38+
// first look at type
39+
if(have_to_rename(it->type()))
5140
{
52-
to_symbol_expr(dest).set_identifier(it->second);
53-
return false;
41+
modifiable_expr = &it.mutate();
42+
result &= rename(modifiable_expr->type());
5443
}
55-
}
56-
57-
Forall_operands(it, dest)
58-
if(!rename(*it))
59-
result=false;
6044

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());
6250

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+
}
6659

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+
}
6869

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+
}
7280

7381
return result;
7482
}

0 commit comments

Comments
 (0)