cprover
replace_symbol.h
Go to the documentation of this file.
1 /*******************************************************************\
2 
3 Module:
4 
5 Author: Daniel Kroening, kroening@kroening.com
6 
7 \*******************************************************************/
8 
9 
10 #ifndef CPROVER_UTIL_REPLACE_SYMBOL_H
11 #define CPROVER_UTIL_REPLACE_SYMBOL_H
12 
13 //
14 // true: did nothing
15 // false: replaced something
16 //
17 
18 #include "expr.h"
19 
20 #include <unordered_map>
21 
23 {
24 public:
25  typedef std::unordered_map<irep_idt, exprt> expr_mapt;
26  typedef std::unordered_map<irep_idt, typet> type_mapt;
27 
28  void insert(const irep_idt &identifier,
29  const exprt &expr)
30  {
31  expr_map.insert(std::pair<irep_idt, exprt>(identifier, expr));
32  }
33 
34  void insert(const class symbol_exprt &old_expr,
35  const exprt &new_expr);
36 
37  void insert(const irep_idt &identifier,
38  const typet &type)
39  {
40  type_map.insert(std::pair<irep_idt, typet>(identifier, type));
41  }
42 
55  virtual bool replace(
56  exprt &dest,
57  const bool replace_with_const=true) const;
58 
59  virtual bool replace(typet &dest) const;
60 
61  void operator()(exprt &dest) const
62  {
63  replace(dest);
64  }
65 
66  void operator()(typet &dest) const
67  {
68  replace(dest);
69  }
70 
71  void clear()
72  {
73  expr_map.clear();
74  type_map.clear();
75  }
76 
77  bool empty() const
78  {
79  return expr_map.empty() && type_map.empty();
80  }
81 
83  virtual ~replace_symbolt();
84 
87 
88 protected:
89  bool have_to_replace(const exprt &dest) const;
90  bool have_to_replace(const typet &type) const;
91 };
92 
93 #endif // CPROVER_UTIL_REPLACE_SYMBOL_H
The type of an expression.
Definition: type.h:22
bool empty() const
void operator()(exprt &dest) const
std::unordered_map< irep_idt, typet > type_mapt
bool have_to_replace(const exprt &dest) const
dstringt has one field, an unsigned integer no which is an index into a static table of strings...
Definition: dstring.h:33
std::unordered_map< irep_idt, exprt > expr_mapt
virtual ~replace_symbolt()
virtual bool replace(exprt &dest, const bool replace_with_const=true) const
Replaces a symbol with a constant If you are replacing symbols with constants in an l-value...
Base class for all expressions.
Definition: expr.h:42
void insert(const irep_idt &identifier, const exprt &expr)
type_mapt type_map
Expression to hold a symbol (variable)
Definition: std_expr.h:90
void operator()(typet &dest) const
expr_mapt expr_map
void insert(const irep_idt &identifier, const typet &type)