15
15
// false: replaced something
16
16
//
17
17
18
+ #include < unordered_map>
19
+
18
20
#include " expr.h"
21
+ #include " namespace.h"
22
+ #include " symbol_table.h"
19
23
20
- # include < unordered_map >
24
+ class symbol_exprt ;
21
25
22
26
// / Replace expression or type symbols by an expression or type, respectively.
27
+ // / The resolved type of the symbol must match the type of the replacement.
23
28
class replace_symbolt
24
29
{
25
30
public:
26
31
typedef std::unordered_map<irep_idt, exprt> expr_mapt;
27
32
typedef std::unordered_map<irep_idt, typet> type_mapt;
28
33
29
- void insert (const irep_idt &identifier,
30
- const exprt &expr)
31
- {
32
- expr_map.insert (std::pair<irep_idt, exprt>(identifier, expr));
33
- }
34
-
35
- void insert (const class symbol_exprt &old_expr,
36
- const exprt &new_expr);
37
-
38
- void insert (const irep_idt &identifier,
39
- const typet &type)
40
- {
41
- type_map.insert (std::pair<irep_idt, typet>(identifier, type));
42
- }
43
-
34
+ void insert (const irep_idt &identifier, const exprt &new_expr);
35
+ void insert (const symbol_exprt &old_expr, const exprt &new_expr);
36
+ void insert (const irep_idt &identifier, const typet &new_type);
44
37
45
38
virtual bool replace (exprt &dest) const ;
46
39
virtual bool replace (typet &dest) const ;
@@ -77,7 +70,11 @@ class replace_symbolt
77
70
type_map.find (id) != type_map.end ();
78
71
}
79
72
80
- replace_symbolt ();
73
+ explicit replace_symbolt (const namespacet &ns)
74
+ : ns(ns)
75
+ {
76
+ }
77
+
81
78
virtual ~replace_symbolt ();
82
79
83
80
const expr_mapt &get_expr_map () const
@@ -90,7 +87,10 @@ class replace_symbolt
90
87
return expr_map;
91
88
}
92
89
90
+ replace_symbolt &operator =(const replace_symbolt &other);
91
+
93
92
protected:
93
+ const namespacet &ns;
94
94
expr_mapt expr_map;
95
95
type_mapt type_map;
96
96
@@ -104,6 +104,7 @@ class unchecked_replace_symbolt : public replace_symbolt
104
104
{
105
105
public:
106
106
unchecked_replace_symbolt ()
107
+ : replace_symbolt(dummy_ns), dummy_ns(symbol_table)
107
108
{
108
109
}
109
110
@@ -112,6 +113,12 @@ class unchecked_replace_symbolt : public replace_symbolt
112
113
void insert (const irep_idt &identifier, const exprt &new_expr);
113
114
void insert (const symbol_exprt &old_expr, const exprt &new_expr);
114
115
void insert (const irep_idt &identifier, const typet &new_type);
116
+
117
+ private:
118
+ const symbol_tablet symbol_table;
119
+ const namespacet dummy_ns;
120
+
121
+ bool replace_symbol_expr (symbol_exprt &dest) const override ;
115
122
};
116
123
117
124
// / Replace symbols with constants while maintaining syntactically valid
0 commit comments