CBMC
journalling_symbol_table.h
Go to the documentation of this file.
1 
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 {
38 public:
39  typedef std::unordered_set<irep_idt> changesett;
40 
41 private:
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 
51 private:
58  {
59  }
60 
61 public:
63 
66  other.symbols,
67  other.symbol_base_map,
68  other.symbol_module_map),
70  inserted(std::move(other.inserted)),
71  updated(std::move(other.updated)),
72  removed(std::move(other.removed))
73  {
74  }
75 
76  virtual const symbol_tablet &get_symbol_table() const override
77  {
79  }
80 
82  {
84  }
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  {
106  return base_symbol_table.next_unused_suffix(prefix);
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;
122  base_symbol_table.erase(entry);
123  on_remove(entry_name);
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 
147  void validate(
148  const validation_modet vm = validation_modet::INVARIANT) const override
149  {
151  }
152 
153  const changesett &get_inserted() const
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 
166 private:
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
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
const changesett & get_updated() const
static journalling_symbol_tablet wrap(symbol_table_baset &base_symbol_table)
virtual std::pair< symbolt &, bool > insert(symbolt symbol) override
Move or copy a new symbol to the symbol table.
journalling_symbol_tablet(const journalling_symbol_tablet &other)=delete
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
void validate(const validation_modet vm=validation_modet::INVARIANT) const override
journalling_symbol_tablet(journalling_symbol_tablet &&other)
void on_insert(const irep_idt &id)
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)
const changesett & get_removed() const
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.
virtual bool move(symbolt &symbol, symbolt *&new_symbol) override
const changesett & get_inserted() const
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 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 const symbol_tablet & get_symbol_table() const =0
virtual iteratort end()=0
virtual symbolt * get_writeable(const irep_idt &name)=0
Find a symbol in the symbol table for read-write access.
virtual std::pair< symbolt &, bool > insert(symbolt symbol)=0
Move or copy a new symbol to the symbol table.
The symbol table.
Definition: symbol_table.h:14
Symbol table entry.
Definition: symbol.h:28
irep_idt name
The unique identifier.
Definition: symbol.h:40
Author: Diffblue Ltd.
validation_modet