cprover
Loading...
Searching...
No Matches
replace_expr.cpp
Go to the documentation of this file.
1/*******************************************************************\
2
3Module:
4
5Author: Daniel Kroening, kroening@kroening.com
6
7\*******************************************************************/
8
9#include "replace_expr.h"
10#include "expr_iterator.h"
11
12bool replace_expr(const exprt &what, const exprt &by, exprt &dest)
13{
14 bool no_change = true;
15
16 for(auto it = dest.depth_begin(), itend = dest.depth_end();
17 it != itend;) // no ++it
18 {
19 if(*it == what)
20 {
21 it.mutate() = by;
22 no_change = false;
23 it.next_sibling_or_parent();
24 }
25 else
26 ++it;
27 }
28
29 return no_change;
30}
31
32bool replace_expr(const replace_mapt &what, exprt &dest)
33{
34 bool no_change = true;
35
36 for(auto it = dest.depth_begin(), itend = dest.depth_end();
37 it != itend;) // No ++it
38 {
39 replace_mapt::const_iterator findit = what.find(*it);
40 if(findit != what.end())
41 {
42 it.mutate() = findit->second;
43 no_change = false;
44 it.next_sibling_or_parent();
45 }
46 else
47 ++it;
48 }
49
50 return no_change;
51}
Base class for all expressions.
Definition expr.h:54
depth_iteratort depth_end()
Definition expr.cpp:267
depth_iteratort depth_begin()
Definition expr.cpp:265
Forward depth-first search iterators These iterators' copy operations are expensive,...
bool replace_expr(const exprt &what, const exprt &by, exprt &dest)
std::unordered_map< exprt, exprt, irep_hash > replace_mapt