CBMC
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
journalling_symbol_table.h
Go to the documentation of this file.
1
2
5
6#ifndef CPROVER_UTIL_JOURNALLING_SYMBOL_TABLE_H
7#define CPROVER_UTIL_JOURNALLING_SYMBOL_TABLE_H
8
9#include "irep.h"
10#include "symbol_table_base.h"
11
12#include <unordered_set>
13#include <utility>
14
37{
38public:
39 typedef std::unordered_set<irep_idt> changesett;
40
41private:
43 // Symbols originally in the table will never be marked inserted
45 // get_writeable marks an existing symbol updated
46 // Inserted symbols are marked updated, removed ones aren't
48 // Symbols not originally in the table will never be marked removed
50
51private:
60
61public:
63
75
76 virtual const symbol_tablet &get_symbol_table() const override
77 {
79 }
80
85
86 virtual bool move(symbolt &symbol, symbolt *&new_symbol) override
87 {
88 bool ret = base_symbol_table.move(symbol, new_symbol);
89 if(!ret)
90 on_insert(symbol.name);
91 else
92 on_update(symbol.name);
93 return ret;
94 }
95
96 virtual symbolt *get_writeable(const irep_idt &identifier) override
97 {
98 symbolt *result = base_symbol_table.get_writeable(identifier);
99 if(result)
100 on_update(identifier);
101 return result;
102 }
103
104 std::size_t next_unused_suffix(const std::string &prefix) const override
105 {
107 }
108
109 virtual std::pair<symbolt &, bool> insert(symbolt symbol) override
110 {
111 std::pair<symbolt &, bool> result =
112 base_symbol_table.insert(std::move(symbol));
113 if(result.second)
114 on_insert(result.first.name);
115 return result;
116 }
117
118 virtual void
119 erase(const symbol_table_baset::symbolst::const_iterator &entry) override
120 {
121 const irep_idt entry_name = entry->first;
124 }
125
126 virtual void clear() override
127 {
128 for(const auto &named_symbol : base_symbol_table.symbols)
129 on_remove(named_symbol.first);
131 }
132
133 virtual iteratort begin() override
134 {
135 return iteratort(
136 base_symbol_table.begin(), [this](const irep_idt &id) { on_update(id); });
137 }
138 virtual iteratort end() override
139 {
140 return iteratort(
141 base_symbol_table.end(), [this](const irep_idt &id) { on_update(id); });
142 }
143
146
148 const validation_modet vm = validation_modet::INVARIANT) const override
149 {
151 }
152
154 {
155 return inserted;
156 }
157 const changesett &get_updated() const
158 {
159 return updated;
160 }
161 const changesett &get_removed() const
162 {
163 return removed;
164 }
165
166private:
167 void on_insert(const irep_idt &id)
168 {
169 if(removed.erase(id) == 0)
170 inserted.insert(id);
171 updated.insert(id);
172 }
173
174 void on_update(const irep_idt &id)
175 {
176 updated.insert(id);
177 }
178
179 void on_remove(const irep_idt &id)
180 {
181 if(inserted.erase(id) == 0)
182 removed.insert(id);
183 updated.erase(id);
184 }
185};
186
187#endif // CPROVER_UTIL_JOURNALLING_SYMBOL_TABLE_H
ait supplies three of the four components needed: an abstract interpreter (in this case handling func...
Definition ai.h:562
dstringt has one field, an unsigned integer no which is an index into a static table of strings.
Definition dstring.h:38
A symbol table wrapper that records which entries have been updated/removedA caller can pass a journa...
virtual iteratort begin() override
virtual symbolt * get_writeable(const irep_idt &identifier) override
Find a symbol in the symbol table for read-write access.
virtual const symbol_tablet & get_symbol_table() const override
static journalling_symbol_tablet wrap(symbol_table_baset &base_symbol_table)
journalling_symbol_tablet(const journalling_symbol_tablet &other)=delete
void validate(const validation_modet vm=validation_modet::INVARIANT) const override
journalling_symbol_tablet(journalling_symbol_tablet &&other)
const changesett & get_inserted() const
void on_insert(const irep_idt &id)
const changesett & get_removed() const
virtual iteratort end() override
void on_remove(const irep_idt &id)
std::unordered_set< irep_idt > changesett
journalling_symbol_tablet(symbol_table_baset &base_symbol_table)
symbol_table_baset & base_symbol_table
std::size_t next_unused_suffix(const std::string &prefix) const override
virtual void erase(const symbol_table_baset::symbolst::const_iterator &entry) override
Remove a symbol from the symbol table.
const changesett & get_updated() const
virtual std::pair< symbolt &, bool > insert(symbolt symbol) override
Move or copy a new symbol to the symbol table.
virtual bool move(symbolt &symbol, symbolt *&new_symbol) override
void on_update(const irep_idt &id)
The symbol table base class interface.
const symbol_base_mapt & symbol_base_map
Read-only field, used to look up symbol names given their base names.
virtual void clear()=0
virtual void validate(const validation_modet vm=validation_modet::INVARIANT) const =0
virtual bool move(symbolt &symbol, symbolt *&new_symbol)=0
virtual std::pair< symbolt &, bool > insert(symbolt symbol)=0
Move or copy a new symbol to the symbol table.
virtual symbolt * get_writeable(const irep_idt &name)=0
Find a symbol in the symbol table for read-write access.
virtual void erase(const symbolst::const_iterator &entry)=0
Remove a symbol from the symbol table.
const symbol_module_mapt & symbol_module_map
Read-only field, used to look up symbol names given their modules.
virtual iteratort begin()=0
std::size_t next_unused_suffix(const std::string &prefix, std::size_t start_number) const
Find smallest unused integer i so that prefix + std::to_string(i) does not exist in the list symbols.
const symbolst & symbols
Read-only field, used to look up symbols given their names.
virtual iteratort end()=0
virtual const symbol_tablet & get_symbol_table() const =0
The symbol table.
Symbol table entry.
Definition symbol.h:28
irep_idt name
The unique identifier.
Definition symbol.h:40
STL namespace.
Author: Diffblue Ltd.
validation_modet