CBMC
symbol_table_base.cpp
Go to the documentation of this file.
1 
3 #include "symbol_table_base.h"
4 
5 #include <ostream>
6 #include <algorithm>
7 
10 {
11 }
12 
13 
18 bool symbol_table_baset::add(const symbolt &symbol)
19 {
20  return !insert(symbol).second;
21 }
22 
28 {
29  symbolst::const_iterator entry = symbols.find(name);
30  if(entry == symbols.end())
31  return true;
32  erase(entry);
33  return false;
34 }
35 
36 std::vector<irep_idt> symbol_table_baset::sorted_symbol_names() const
37 {
38  std::vector<irep_idt> sorted_names;
39  sorted_names.reserve(symbols.size());
40 
41  for(const auto &elem : symbols)
42  sorted_names.push_back(elem.first);
43 
44  std::sort(
45  sorted_names.begin(),
46  sorted_names.end(),
47  [](const irep_idt &a, const irep_idt &b) { return a.compare(b) < 0; });
48 
49  return sorted_names;
50 }
51 
54 void symbol_table_baset::show(std::ostream &out) const
55 {
56  out << "\n"
57  << "Symbols:"
58  << "\n";
59  for(const auto &name : sorted_symbol_names())
60  out << symbols.at(name);
61 }
62 
64 {
65  return symbols.end();
66 }
67 
69 {
70  return symbols.begin();
71 }
72 
76 std::ostream &
77 operator<<(std::ostream &out, const symbol_table_baset &symbol_table)
78 {
79  symbol_table.show(out);
80  return out;
81 }
dstringt has one field, an unsigned integer no which is an index into a static table of strings.
Definition: dstring.h:38
The symbol table base class interface.
std::vector< irep_idt > sorted_symbol_names() const
Build and return a lexicographically sorted vector of symbol names from all symbols stored in this sy...
bool remove(const irep_idt &name)
Remove a symbol from the symbol table.
virtual void erase(const symbolst::const_iterator &entry)=0
Remove a symbol from the symbol table.
virtual iteratort begin()=0
symbolst::const_iterator const_iteratort
void show(std::ostream &out) const
Print the contents of the symbol table.
const symbolst & symbols
Read-only field, used to look up symbols given their names.
virtual iteratort end()=0
bool add(const symbolt &symbol)
Add a new symbol to the symbol table.
virtual ~symbol_table_baset()
Author: Diffblue Ltd.
virtual std::pair< symbolt &, bool > insert(symbolt symbol)=0
Move or copy a new symbol to the symbol table.
Symbol table entry.
Definition: symbol.h:28
std::ostream & operator<<(std::ostream &out, const symbol_table_baset &symbol_table)
Print the contents of the symbol table.
Author: Diffblue Ltd.