|
1 | | -// Copyright 2016-2017 DiffBlue Limited. All Rights Reserved. |
| 1 | +// Copyright 2016-2017 Diffblue Limited. All Rights Reserved. |
2 | 2 |
|
3 | 3 | /// \file |
4 | 4 | /// Symbol table |
@@ -52,6 +52,7 @@ class symbol_tablet |
52 | 52 | const symbol_base_mapt &symbol_base_map; |
53 | 53 | const symbol_module_mapt &symbol_module_map; |
54 | 54 |
|
| 55 | +public: |
55 | 56 | symbol_tablet() |
56 | 57 | : symbols(internal_symbols), |
57 | 58 | symbol_base_map(internal_symbol_base_map), |
@@ -93,79 +94,88 @@ class symbol_tablet |
93 | 94 | return *this; |
94 | 95 | } |
95 | 96 |
|
| 97 | + void swap(symbol_tablet &other) |
| 98 | + { |
| 99 | + internal_symbols.swap(other.internal_symbols); |
| 100 | + internal_symbol_base_map.swap(other.internal_symbol_base_map); |
| 101 | + internal_symbol_module_map.swap(other.internal_symbol_module_map); |
| 102 | + } |
| 103 | + |
| 104 | +public: |
96 | 105 | bool has_symbol(const irep_idt &name) const |
97 | 106 | { |
98 | 107 | return symbols.find(name)!=symbols.end(); |
99 | 108 | } |
100 | 109 |
|
101 | 110 | /// Find a symbol in the symbol table for read-only access. |
102 | | - /// \param id: The name of the symbol to look for |
103 | | - /// \return an optional reference, set if found, nullptr otherwise. |
104 | | - const symbolt *lookup(const irep_idt &id) const { return lookup_impl(id); } |
105 | | - |
106 | | - /// Find a symbol in the symbol table for read-write access. |
107 | | - /// \param id: The name of the symbol to look for |
108 | | - /// \return an optional reference, set if found, unset otherwise. |
109 | | - symbolt *get_writeable(const irep_idt &id) { return lookup_impl(id); } |
| 111 | + /// \param name: The name of the symbol to look for |
| 112 | + /// \return a pointer to the found symbol if it exists, nullptr otherwise. |
| 113 | + const symbolt *lookup(const irep_idt &name) const |
| 114 | + { |
| 115 | + return lookup_impl(name); |
| 116 | + } |
110 | 117 |
|
111 | 118 | /// Find a symbol in the symbol table for read-only access. |
112 | | - /// \param id: The name of the symbol to look for |
| 119 | + /// \param name: The name of the symbol to look for |
113 | 120 | /// \return A reference to the symbol |
114 | 121 | /// \throw `std::out_of_range` if no such symbol exists |
115 | | - const symbolt &lookup_ref(const irep_idt &id) const |
116 | | - { return internal_symbols.at(id); } |
| 122 | + const symbolt &lookup_ref(const irep_idt &name) const |
| 123 | + { |
| 124 | + return symbols.at(name); |
| 125 | + } |
| 126 | + |
| 127 | + /// Find a symbol in the symbol table for read-write access. |
| 128 | + /// \param name: The name of the symbol to look for |
| 129 | + /// \return a pointer to the found symbol if it exists, nullptr otherwise. |
| 130 | + symbolt *get_writeable(const irep_idt &name) |
| 131 | + { |
| 132 | + return lookup_impl(name); |
| 133 | + } |
117 | 134 |
|
118 | 135 | /// Find a symbol in the symbol table for read-write access. |
119 | | - /// \param id: The name of the symbol to look for |
| 136 | + /// \param name: The name of the symbol to look for |
120 | 137 | /// \return A reference to the symbol |
121 | 138 | /// \throw `std::out_of_range` if no such symbol exists |
122 | | - symbolt &get_writeable_ref(const irep_idt &id) |
123 | | - { return internal_symbols.at(id); } |
| 139 | + symbolt &get_writeable_ref(const irep_idt &name) |
| 140 | + { |
| 141 | + return internal_symbols.at(name); |
| 142 | + } |
124 | 143 |
|
125 | 144 | bool add(const symbolt &symbol); |
126 | | - |
127 | 145 | std::pair<symbolt &, bool> insert(symbolt symbol); |
128 | | - |
129 | 146 | bool move(symbolt &symbol, symbolt *&new_symbol); |
130 | 147 |
|
| 148 | + bool remove(const irep_idt &name); |
| 149 | + void erase(const symbolst::const_iterator &entry); |
131 | 150 | void clear() |
132 | 151 | { |
133 | 152 | internal_symbols.clear(); |
134 | 153 | internal_symbol_base_map.clear(); |
135 | 154 | internal_symbol_module_map.clear(); |
136 | 155 | } |
137 | 156 |
|
138 | | - bool remove(const irep_idt &name); |
139 | | - |
140 | | - void erase(const symbolst::const_iterator &entry); |
141 | | - |
142 | 157 | void show(std::ostream &out) const; |
143 | 158 |
|
144 | | - void swap(symbol_tablet &other) |
| 159 | +private: |
| 160 | + const symbolt *lookup_impl(const irep_idt &name) const |
145 | 161 | { |
146 | | - internal_symbols.swap(other.internal_symbols); |
147 | | - internal_symbol_base_map.swap(other.internal_symbol_base_map); |
148 | | - internal_symbol_module_map.swap(other.internal_symbol_module_map); |
| 162 | + return lookup_impl(*this, name); |
149 | 163 | } |
150 | 164 |
|
151 | | -private: |
152 | | - const symbolt *lookup_impl(const irep_idt &id) const |
153 | | - { return lookup_impl(*this, id); } |
154 | | - |
155 | | - symbolt *lookup_impl(const irep_idt &id) |
156 | | - { return lookup_impl(*this, id); } |
| 165 | + symbolt *lookup_impl(const irep_idt &name) |
| 166 | + { |
| 167 | + return lookup_impl(*this, name); |
| 168 | + } |
157 | 169 |
|
158 | | - template<typename T> |
159 | | - static auto lookup_impl(T &t, const irep_idt &id) |
160 | | - -> decltype(std::declval<T>().lookup_impl(id)) |
| 170 | + template <typename T> |
| 171 | + static auto lookup_impl(T &t, const irep_idt &name) |
| 172 | + -> decltype(std::declval<T>().lookup_impl(name)) |
161 | 173 | { |
162 | | - const auto it=t.internal_symbols.find(id); |
| 174 | + const auto it = t.internal_symbols.find(name); |
163 | 175 | return it==t.internal_symbols.end()?nullptr:&it->second; |
164 | 176 | } |
165 | 177 | }; |
166 | 178 |
|
167 | | -std::ostream &operator << ( |
168 | | - std::ostream &out, |
169 | | - const symbol_tablet &symbol_table); |
| 179 | +std::ostream &operator<<(std::ostream &out, const symbol_tablet &symbol_table); |
170 | 180 |
|
171 | 181 | #endif // CPROVER_UTIL_SYMBOL_TABLE_H |
0 commit comments