@@ -42,22 +42,20 @@ class const_unique_depth_iteratort;
42
42
struct depth_iterator_expr_statet final
43
43
{
44
44
typedef exprt::operandst::const_iterator operands_iteratort;
45
- inline depth_iterator_expr_statet (
46
- const exprt & expr,
47
- operands_iteratort it,
48
- operands_iteratort end):
49
- expr(expr), it(it), end(end) { }
45
+ inline depth_iterator_expr_statet (const exprt &expr) :
46
+ expr(expr) ,
47
+ op_idx( 0 )
48
+ {
49
+ }
50
50
std::reference_wrapper<const exprt> expr;
51
- operands_iteratort it;
52
- operands_iteratort end;
51
+ std::size_t op_idx;
53
52
};
54
53
55
54
inline bool operator ==(
56
55
const depth_iterator_expr_statet &left,
57
56
const depth_iterator_expr_statet &right)
58
57
{
59
- return distance (left.it , left.end ) == distance (right.it , right.end ) &&
60
- left.expr .get () == right.expr .get ();
58
+ return left.op_idx == right.op_idx && left.expr .get () == right.expr .get ();
61
59
}
62
60
63
61
// / Depth first search iterator base - iterates over supplied expression
@@ -100,16 +98,21 @@ class depth_iterator_baset
100
98
PRECONDITION (!m_stack.empty ());
101
99
while (true )
102
100
{
103
- if (m_stack.back ().it ==m_stack.back ().end )
101
+
102
+ if (m_stack.back ().op_idx == m_stack.back ().expr .get ().operands ().size ())
104
103
{
105
104
m_stack.pop_back ();
106
105
if (m_stack.empty ())
107
106
break ;
108
107
}
109
108
// Check eg. if we haven't seen this node before
110
- else if (this ->downcast ().push_expr (*m_stack.back ().it ))
109
+ else if (
110
+ this ->downcast ().push_expr (
111
+ m_stack.back ().expr .get ().operands ()[m_stack.back ().op_idx ]))
112
+ {
111
113
break ;
112
- m_stack.back ().it ++;
114
+ }
115
+ ++m_stack.back ().op_idx ;
113
116
}
114
117
return this ->downcast ();
115
118
}
@@ -120,7 +123,7 @@ class depth_iterator_baset
120
123
m_stack.pop_back ();
121
124
if (!m_stack.empty ())
122
125
{
123
- ++m_stack.back ().it ;
126
+ ++m_stack.back ().op_idx ;
124
127
return ++(*this );
125
128
}
126
129
return this ->downcast ();
@@ -185,18 +188,11 @@ class depth_iterator_baset
185
188
for (auto &state : m_stack)
186
189
{
187
190
// This deliberately breaks sharing as expr is now non-const
188
- auto &operands = expr->operands ();
189
- // Get iterators into the operands of the new expr corresponding to the
190
- // ones into the operands of the old expr
191
- const auto it = operands.end () - (state.end - state.it );
191
+ (void )expr->operands ();
192
192
state.expr = *expr;
193
- state.it =it;
194
- state.end =operands.end ();
195
193
// Get the expr for the next level down to use in the next iteration
196
- if (!(state==m_stack.back ()))
197
- {
198
- expr = &*it;
199
- }
194
+ if (!(state == m_stack.back ()))
195
+ expr = &const_cast <exprt &>(state.expr .get ().operands ()[state.op_idx ]);
200
196
}
201
197
return *expr;
202
198
}
@@ -208,7 +204,7 @@ class depth_iterator_baset
208
204
// / false otherwise. If returning false, child will not be iterated over.
209
205
bool push_expr (const exprt &expr)
210
206
{
211
- m_stack.emplace_back (expr, expr. operands (). begin (), expr. operands (). end () );
207
+ m_stack.emplace_back (expr);
212
208
return true ;
213
209
}
214
210
0 commit comments