cprover
symbol_table.h
Go to the documentation of this file.
1 /*******************************************************************\
2 
3 Module:
4 
5 Author: Daniel Kroening, kroening@kroening.com
6 
7 \*******************************************************************/
8 
9 
10 #ifndef CPROVER_UTIL_SYMBOL_TABLE_H
11 #define CPROVER_UTIL_SYMBOL_TABLE_H
12 
22 #include <iosfwd>
23 #include <map>
24 #include <unordered_map>
25 
26 #include "symbol.h"
27 
28 #define forall_symbols(it, expr) \
29  for(symbol_tablet::symbolst::const_iterator it=(expr).begin(); \
30  it!=(expr).end(); ++it)
31 
32 #define Forall_symbols(it, expr) \
33  for(symbol_tablet::symbolst::iterator it=(expr).begin(); \
34  it!=(expr).end(); ++it)
35 
36 typedef std::multimap<irep_idt, irep_idt> symbol_base_mapt;
37 typedef std::multimap<irep_idt, irep_idt> symbol_module_mapt;
38 
39 #define forall_symbol_base_map(it, expr, base_name) \
40  for(symbol_base_mapt::const_iterator it=(expr).lower_bound(base_name), \
41  it_end=(expr).upper_bound(base_name); \
42  it!=it_end; ++it)
43 
44 #define forall_symbol_module_map(it, expr, module) \
45  for(symbol_module_mapt::const_iterator it=(expr).lower_bound(module), \
46  it_end=(expr).upper_bound(module); \
47  it!=it_end; ++it)
48 
53 {
54 public:
55  typedef std::unordered_map<irep_idt, symbolt, irep_id_hash> symbolst;
56 
57  symbolst symbols;
60 
61  bool add(const symbolt &symbol);
62 
63  bool move(symbolt &symbol, symbolt *&new_symbol);
64 
65  // this will go away, use add instead
66  bool move(symbolt &symbol)
67  { symbolt *new_symbol; return move(symbol, new_symbol); }
68 
69  void clear()
70  {
71  symbols.clear();
72  symbol_base_map.clear();
73  symbol_module_map.clear();
74  }
75 
76  bool remove(const irep_idt &name);
77 
78  void show(std::ostream &out) const;
79 
80  void swap(symbol_tablet &other)
81  {
82  symbols.swap(other.symbols);
83  symbol_base_map.swap(other.symbol_base_map);
84  symbol_module_map.swap(other.symbol_module_map);
85  }
86 
87  bool has_symbol(const irep_idt &name) const
88  {
89  return symbols.find(name)!=symbols.end();
90  }
91 
92  symbolt &lookup(const irep_idt &identifier);
93  const symbolt &lookup(const irep_idt &identifier) const;
94 };
95 
96 std::ostream &operator << (
97  std::ostream &out,
98  const symbol_tablet &symbol_table);
99 
100 #endif // CPROVER_UTIL_SYMBOL_TABLE_H
symbolt & lookup(const irep_idt &identifier)
Find a symbol in the symbol table.
Symbol table entry.
Symbol table entry.This is a symbol in the symbol table, stored in an object of type symbol_tablet...
Definition: symbol.h:33
symbol_base_mapt symbol_base_map
Definition: symbol_table.h:58
symbol_module_mapt symbol_module_map
Definition: symbol_table.h:59
symbolst symbols
Definition: symbol_table.h:57
std::multimap< irep_idt, irep_idt > symbol_base_mapt
Definition: symbol_table.h:36
The symbol table.
Definition: symbol_table.h:52
std::unordered_map< irep_idt, symbolt, irep_id_hash > symbolst
Definition: symbol_table.h:55
bool add(const symbolt &symbol)
Add a new symbol to the symbol table.
bool move(symbolt &symbol, symbolt *&new_symbol)
Move a symbol into the symbol table.
bool move(symbolt &symbol)
Definition: symbol_table.h:66
void show(std::ostream &out) const
Print the contents of the symbol table.
std::ostream & operator<<(std::ostream &out, const symbol_tablet &symbol_table)
Print the contents of the symbol table.
bool has_symbol(const irep_idt &name) const
Definition: symbol_table.h:87
void swap(symbol_tablet &other)
Definition: symbol_table.h:80
std::multimap< irep_idt, irep_idt > symbol_module_mapt
Definition: symbol_table.h:37