File tree 2 files changed +61
-0
lines changed
2 files changed +61
-0
lines changed Original file line number Diff line number Diff line change @@ -287,6 +287,65 @@ void exprt::visit_post(std::function<void(const exprt &)> visitor) const
287
287
visit_post_template (visitor, this );
288
288
}
289
289
290
+ optionalt<exprt>
291
+ exprt::transform_pre (std::function<optionalt<exprt>(exprt)> visitor) const
292
+ {
293
+ auto visitor_result = visitor (*this );
294
+
295
+ exprt tmp;
296
+
297
+ if (visitor_result.has_value ())
298
+ tmp = visitor_result.value ();
299
+ else
300
+ tmp = *this ;
301
+
302
+ bool op_changed = false ;
303
+
304
+ for (auto &op : tmp.operands ()) // this breaks sharing
305
+ {
306
+ auto op_result = op.transform_pre (visitor);
307
+ if (op_result.has_value ())
308
+ {
309
+ op = std::move (op_result.value ());
310
+ op_changed = true ;
311
+ }
312
+ }
313
+
314
+ if (op_changed)
315
+ return std::move (tmp);
316
+ else
317
+ return visitor_result;
318
+ }
319
+
320
+ optionalt<exprt>
321
+ exprt::transform_post (std::function<optionalt<exprt>(exprt)> visitor) const
322
+ {
323
+ exprt tmp = *this ;
324
+ bool op_changed = false ;
325
+
326
+ for (auto &op : tmp.operands ()) // this breaks sharing
327
+ {
328
+ auto op_result = op.transform_post (visitor);
329
+ if (op_result.has_value ())
330
+ {
331
+ op = std::move (op_result.value ());
332
+ op_changed = true ;
333
+ }
334
+ }
335
+
336
+ if (op_changed)
337
+ {
338
+ auto visitor_result = visitor (tmp);
339
+
340
+ if (visitor_result.has_value ())
341
+ return std::move (visitor_result.value ());
342
+ else
343
+ return std::move (tmp);
344
+ }
345
+ else
346
+ return visitor (*this );
347
+ }
348
+
290
349
template <typename T>
291
350
static void visit_pre_template (std::function<void (T &)> visitor, T *_expr)
292
351
{
Original file line number Diff line number Diff line change @@ -332,12 +332,14 @@ class exprt:public irept
332
332
void visit (class const_expr_visitort &visitor) const ;
333
333
void visit_pre (std::function<void (exprt &)>);
334
334
void visit_pre (std::function<void (const exprt &)>) const ;
335
+ optionalt<exprt> transform_pre (std::function<optionalt<exprt>(exprt)>) const ;
335
336
336
337
// / These are post-order traversal visitors, i.e.,
337
338
// / the visitor is executed on a node _after_ its children
338
339
// / have been visited.
339
340
void visit_post (std::function<void (exprt &)>);
340
341
void visit_post (std::function<void (const exprt &)>) const ;
342
+ optionalt<exprt> transform_post (std::function<optionalt<exprt>(exprt)>) const ;
341
343
342
344
depth_iteratort depth_begin ();
343
345
depth_iteratort depth_end ();
You can’t perform that action at this time.
0 commit comments