@@ -46,26 +46,29 @@ void letifyt::collect_bindings(
46
46
let_order.push_back (expr);
47
47
}
48
48
49
- exprt letifyt::letify_rec (
49
+ exprt letifyt::letify (
50
50
const exprt &expr,
51
- std::vector<exprt> &let_order,
52
- const seen_expressionst &map,
53
- std::size_t i)
51
+ const std::vector<exprt> &let_order,
52
+ const seen_expressionst &map)
54
53
{
55
- if (i >= let_order.size ())
56
- return substitute_let (expr, map);
54
+ exprt result = substitute_let (expr, map);
57
55
58
- exprt current = let_order[i];
59
- INVARIANT (
60
- map.find (current) != map.end (), " expression should have been seen already" );
56
+ // go backwards in let order
57
+ for (auto r_it = let_order.rbegin (); r_it != let_order.rend (); r_it++)
58
+ {
59
+ const exprt ¤t = *r_it;
61
60
62
- if (map.find (current)->second .count < LET_COUNT)
63
- return letify_rec (expr, let_order, map, i + 1 );
61
+ auto m_it = map.find (current);
62
+ INVARIANT (m_it != map.end (), " expression should have been seen already" );
63
+
64
+ if (m_it->second .count >= LET_COUNT)
65
+ {
66
+ result = let_exprt (
67
+ m_it->second .let_symbol , substitute_let (current, map), result);
68
+ }
69
+ }
64
70
65
- return let_exprt (
66
- map.find (current)->second .let_symbol ,
67
- substitute_let (current, map),
68
- letify_rec (expr, let_order, map, i + 1 ));
71
+ return result;
69
72
}
70
73
71
74
exprt letifyt::operator ()(const exprt &expr)
@@ -75,7 +78,7 @@ exprt letifyt::operator()(const exprt &expr)
75
78
76
79
collect_bindings (expr, map, let_order);
77
80
78
- return letify_rec (expr, let_order, map, 0 );
81
+ return letify (expr, let_order, map);
79
82
}
80
83
81
84
exprt letifyt::substitute_let (const exprt &expr, const seen_expressionst &map)
0 commit comments