cprover
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 
38 void symbol_table_baset::show(std::ostream &out) const
39 {
40  std::vector<irep_idt> sorted_names;
41  sorted_names.reserve(symbols.size());
42  for(const auto &elem : symbols)
43  sorted_names.push_back(elem.first);
44  std::sort(
45  sorted_names.begin(),
46  sorted_names.end(),
47  [](const irep_idt &a, const irep_idt &b) { return a.compare(b); });
48  out << "\n"
49  << "Symbols:"
50  << "\n";
51  for(const auto &name : sorted_names)
52  out << symbols.at(name);
53 }
54 
58 std::ostream &
59 operator<<(std::ostream &out, const symbol_table_baset &symbol_table)
60 {
61  symbol_table.show(out);
62  return out;
63 }
std::ostream & operator<<(std::ostream &out, const symbol_table_baset &symbol_table)
Print the contents of the symbol table.
virtual void erase(const symbolst::const_iterator &entry)=0
Remove a symbol from the symbol table.
void show(std::ostream &out) const
Print the contents of the symbol table.
Symbol table entry.This is a symbol in the symbol table, stored in an object of type symbol_tablet...
Definition: symbol.h:30
dstringt has one field, an unsigned integer no which is an index into a static table of strings...
Definition: dstring.h:33
const symbolst & symbols
bool remove(const irep_idt &name)
Remove a symbol from the symbol table.
virtual ~symbol_table_baset()
Author: Diffblue Ltd.
Author: Diffblue Ltd.
The symbol table base class interface.
int compare(const dstringt &b) const
Definition: dstring.h:118
virtual std::pair< symbolt &, bool > insert(symbolt symbol)=0
Move or copy a new symbol to the symbol table.
bool add(const symbolt &symbol)
Add a new symbol to the symbol table.