CBMC
symbol_table_builder.h
Go to the documentation of this file.
1 
3 // \file Contains a symbol table wrapper that keeps track of suffixes
4 // that have been used for their prefix
5 
6 #ifndef CPROVER_UTIL_SYMBOL_TABLE_BUILDER_H
7 #define CPROVER_UTIL_SYMBOL_TABLE_BUILDER_H
8 
9 #include "symbol_table_base.h"
10 
14 {
15 private:
17  mutable std::map<std::string, std::size_t> next_free_suffix_for_prefix;
18 
19 public:
26  {
27  }
28 
31  other.symbols,
32  other.symbol_base_map,
33  other.symbol_module_map),
35  {
36  }
37 
41 
43  {
45  }
46 
47  const symbol_tablet &get_symbol_table() const override
48  {
50  }
51 
52  void erase(const symbolst::const_iterator &entry) override
53  {
54  base_symbol_table.erase(entry);
55  }
56 
57  void clear() override
58  {
61  }
62 
63  bool move(symbolt &symbol, symbolt *&new_symbol) override
64  {
65  return base_symbol_table.move(symbol, new_symbol);
66  }
67 
68  symbolt *get_writeable(const irep_idt &identifier) override
69  {
70  return base_symbol_table.get_writeable(identifier);
71  }
72 
73  std::pair<symbolt &, bool> insert(symbolt symbol) override
74  {
75  return base_symbol_table.insert(std::move(symbol));
76  }
77 
78  iteratort begin() override
79  {
80  return base_symbol_table.begin();
81  }
82 
83  iteratort end() override
84  {
85  return base_symbol_table.end();
86  }
87 
90 
101  std::size_t next_unused_suffix(const std::string &prefix) const override
102  {
103  // Check if we have an entry for this particular suffix, if not,
104  // create baseline.
105  auto suffix_iter = next_free_suffix_for_prefix.insert({prefix, 0}).first;
106  std::size_t free_suffix =
107  base_symbol_table.next_unused_suffix(prefix, suffix_iter->second);
108  suffix_iter->second = free_suffix + 1;
109  return free_suffix;
110  }
111 };
112 
113 #endif // CPROVER_UTIL_SYMBOL_TABLE_BUILDER_H
dstringt
dstringt has one field, an unsigned integer no which is an index into a static table of strings.
Definition: dstring.h:36
symbol_table_buildert::base_symbol_table
symbol_table_baset & base_symbol_table
Definition: symbol_table_builder.h:16
symbol_tablet
The symbol table.
Definition: symbol_table.h:13
symbol_table_baset::get_writeable
virtual symbolt * get_writeable(const irep_idt &name)=0
Find a symbol in the symbol table for read-write access.
symbol_table_buildert::operator=
symbol_table_buildert & operator=(const symbol_table_buildert &)=delete
symbol_table_baset::symbol_base_map
const symbol_base_mapt & symbol_base_map
Read-only field, used to look up symbol names given their base names.
Definition: symbol_table_base.h:33
symbol_table_buildert::next_unused_suffix
std::size_t next_unused_suffix(const std::string &prefix) const override
Try to find the next free identity for the passed-in prefix in this symbol table.
Definition: symbol_table_builder.h:101
symbol_table_baset::clear
virtual void clear()=0
symbol_table_buildert::get_writeable
symbolt * get_writeable(const irep_idt &identifier) override
Find a symbol in the symbol table for read-write access.
Definition: symbol_table_builder.h:68
symbol_table_buildert::move
bool move(symbolt &symbol, symbolt *&new_symbol) override
Definition: symbol_table_builder.h:63
symbol_table_baset::symbol_module_map
const symbol_module_mapt & symbol_module_map
Read-only field, used to look up symbol names given their modules.
Definition: symbol_table_base.h:38
symbol_table_buildert::symbol_table_buildert
symbol_table_buildert(symbol_table_buildert &&other)
Definition: symbol_table_builder.h:29
symbol_table_baset::erase
virtual void erase(const symbolst::const_iterator &entry)=0
Remove a symbol from the symbol table.
symbol_table_baset::begin
virtual iteratort begin()=0
Definition: symbol_table_base.cpp:68
symbol_table_baset
The symbol table base class interface.
Definition: symbol_table_base.h:21
symbol_table_buildert::symbol_table_buildert
symbol_table_buildert(symbol_table_baset &base_symbol_table)
Definition: symbol_table_builder.h:20
symbol_table_buildert::erase
void erase(const symbolst::const_iterator &entry) override
Remove a symbol from the symbol table.
Definition: symbol_table_builder.h:52
symbol_table_baset::end
virtual iteratort end()=0
Definition: symbol_table_base.cpp:63
symbol_table_baset::iteratort
Definition: symbol_table_base.h:154
symbol_table_buildert::end
iteratort end() override
Definition: symbol_table_builder.h:83
symbolt
Symbol table entry.
Definition: symbol.h:27
symbol_table_buildert::wrap
static symbol_table_buildert wrap(symbol_table_baset &base_symbol_table)
Definition: symbol_table_builder.h:42
symbol_table_buildert
Author: Diffblue Ltd.
Definition: symbol_table_builder.h:13
symbol_table_baset::symbols
const symbolst & symbols
Read-only field, used to look up symbols given their names.
Definition: symbol_table_base.h:30
symbol_table_buildert::clear
void clear() override
Definition: symbol_table_builder.h:57
symbol_table_buildert::get_symbol_table
const symbol_tablet & get_symbol_table() const override
Definition: symbol_table_builder.h:47
symbol_table_buildert::next_free_suffix_for_prefix
std::map< std::string, std::size_t > next_free_suffix_for_prefix
Definition: symbol_table_builder.h:17
symbol_table_baset::insert
virtual std::pair< symbolt &, bool > insert(symbolt symbol)=0
Move or copy a new symbol to the symbol table.
symbol_table_baset::move
virtual bool move(symbolt &symbol, symbolt *&new_symbol)=0
symbol_table_base.h
Author: Diffblue Ltd.
symbol_table_baset::next_unused_suffix
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.
Definition: symbol_table_base.h:63
symbol_table_buildert::insert
std::pair< symbolt &, bool > insert(symbolt symbol) override
Move or copy a new symbol to the symbol table.
Definition: symbol_table_builder.h:73
symbol_table_buildert::begin
iteratort begin() override
Definition: symbol_table_builder.h:78
symbol_table_baset::get_symbol_table
virtual const symbol_tablet & get_symbol_table() const =0