@@ -42,22 +42,18 @@ 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
+ explicit depth_iterator_expr_statet (const exprt &expr) : expr(expr), op_idx(0 )
46
+ {
47
+ }
50
48
std::reference_wrapper<const exprt> expr;
51
- operands_iteratort it;
52
- operands_iteratort end;
49
+ std::size_t op_idx;
53
50
};
54
51
55
52
inline bool operator ==(
56
53
const depth_iterator_expr_statet &left,
57
54
const depth_iterator_expr_statet &right)
58
55
{
59
- return distance (left.it , left.end ) == distance (right.it , right.end ) &&
60
- left.expr .get () == right.expr .get ();
56
+ return left.op_idx == right.op_idx && left.expr .get () == right.expr .get ();
61
57
}
62
58
63
59
// / Depth first search iterator base - iterates over supplied expression
@@ -100,16 +96,19 @@ class depth_iterator_baset
100
96
PRECONDITION (!m_stack.empty ());
101
97
while (true )
102
98
{
103
- if (m_stack.back ().it == m_stack.back ().end )
99
+ if (m_stack.back ().op_idx == m_stack.back ().expr . get (). operands (). size () )
104
100
{
105
101
m_stack.pop_back ();
106
102
if (m_stack.empty ())
107
103
break ;
108
104
}
109
105
// Check eg. if we haven't seen this node before
110
- else if (this ->downcast ().push_expr (*m_stack.back ().it ))
106
+ else if (this ->downcast ().push_expr (
107
+ m_stack.back ().expr .get ().operands ()[m_stack.back ().op_idx ]))
108
+ {
111
109
break ;
112
- m_stack.back ().it ++;
110
+ }
111
+ ++m_stack.back ().op_idx ;
113
112
}
114
113
return this ->downcast ();
115
114
}
@@ -120,7 +119,7 @@ class depth_iterator_baset
120
119
m_stack.pop_back ();
121
120
if (!m_stack.empty ())
122
121
{
123
- ++m_stack.back ().it ;
122
+ ++m_stack.back ().op_idx ;
124
123
return ++(*this );
125
124
}
126
125
return this ->downcast ();
@@ -185,18 +184,11 @@ class depth_iterator_baset
185
184
for (auto &state : m_stack)
186
185
{
187
186
// 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 );
187
+ (void )expr->write ();
192
188
state.expr = *expr;
193
- state.it =it;
194
- state.end =operands.end ();
195
189
// 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
- }
190
+ if (!(state == m_stack.back ()))
191
+ expr = &expr->operands ()[state.op_idx ];
200
192
}
201
193
return *expr;
202
194
}
@@ -208,7 +200,7 @@ class depth_iterator_baset
208
200
// / false otherwise. If returning false, child will not be iterated over.
209
201
bool push_expr (const exprt &expr)
210
202
{
211
- m_stack.emplace_back (expr, expr. operands (). begin (), expr. operands (). end () );
203
+ m_stack.emplace_back (expr);
212
204
return true ;
213
205
}
214
206
0 commit comments