@@ -20,12 +20,16 @@ class recording_symbol_tablet:public symbol_tablet
20
20
typedef std::unordered_set<irep_idt, irep_id_hash> changesett;
21
21
private:
22
22
symbol_tablet &base_symbol_table;
23
+ // Symbols originally in the table will never be marked inserted
24
+ changesett inserted;
25
+ // get_writeable marks an existing symbol updated
26
+ // Inserted symbols are marked updated, removed ones aren't
23
27
changesett updated;
28
+ // Symbols not originally in the table will never be marked removed
24
29
changesett removed;
25
30
26
- public:
27
- // NOLINTNEXTLINE(runtime/explicit) - No information is lost in conversion
28
- recording_symbol_tablet (symbol_tablet &base_symbol_table)
31
+ private:
32
+ explicit recording_symbol_tablet (symbol_tablet &base_symbol_table)
29
33
: symbol_tablet(
30
34
base_symbol_table.symbols,
31
35
base_symbol_table.symbol_base_map,
@@ -34,6 +38,7 @@ class recording_symbol_tablet:public symbol_tablet
34
38
{
35
39
}
36
40
41
+ public:
37
42
recording_symbol_tablet (const recording_symbol_tablet &other)
38
43
: symbol_tablet(
39
44
other.base_symbol_table.symbols,
@@ -43,6 +48,11 @@ class recording_symbol_tablet:public symbol_tablet
43
48
{
44
49
}
45
50
51
+ static recording_symbol_tablet wrap (symbol_tablet &base_symbol_table)
52
+ {
53
+ return recording_symbol_tablet (base_symbol_table);
54
+ }
55
+
46
56
virtual opt_symbol_reft get_writeable (const irep_idt &identifier) override
47
57
{
48
58
opt_symbol_reft result=base_symbol_table.get_writeable (identifier);
@@ -56,7 +66,7 @@ class recording_symbol_tablet:public symbol_tablet
56
66
std::pair<symbolt &, bool > result=
57
67
base_symbol_table.insert (std::move (symbol));
58
68
if (result.second )
59
- on_update (result.first .name );
69
+ on_insert (result.first .name );
60
70
return result;
61
71
}
62
72
@@ -73,19 +83,27 @@ class recording_symbol_tablet:public symbol_tablet
73
83
base_symbol_table.clear ();
74
84
}
75
85
86
+ const changesett &get_inserted () const { return inserted; }
76
87
const changesett &get_updated () const { return updated; }
77
88
const changesett &get_removed () const { return removed; }
78
89
79
90
private:
91
+ void on_insert (const irep_idt &id)
92
+ {
93
+ if (removed.erase (id)==0 )
94
+ inserted.insert (id);
95
+ updated.insert (id);
96
+ }
97
+
80
98
void on_update (const irep_idt &id)
81
99
{
82
100
updated.insert (id);
83
- removed.erase (id);
84
101
}
85
102
86
103
void on_remove (const irep_idt &id)
87
104
{
88
- removed.insert (id);
105
+ if (inserted.erase (id)==0 )
106
+ removed.insert (id);
89
107
updated.erase (id);
90
108
}
91
109
};
0 commit comments