|
8 | 8 | #ifndef CPROVER_UTIL_SYMBOL_TABLE_BASE_H
|
9 | 9 | #define CPROVER_UTIL_SYMBOL_TABLE_BASE_H
|
10 | 10 |
|
| 11 | +#include <functional> |
11 | 12 | #include <iosfwd>
|
12 | 13 | #include <map>
|
13 | 14 | #include <unordered_map>
|
@@ -117,6 +118,78 @@ class symbol_table_baset
|
117 | 118 | virtual void clear() = 0;
|
118 | 119 |
|
119 | 120 | void show(std::ostream &out) const;
|
| 121 | + |
| 122 | + class iteratort |
| 123 | + { |
| 124 | + private: |
| 125 | + symbolst::iterator it; |
| 126 | + std::function<void(const irep_idt &id)> on_get_writeable; |
| 127 | + |
| 128 | + public: |
| 129 | + explicit iteratort(symbolst::iterator it) : it(std::move(it)) |
| 130 | + { |
| 131 | + } |
| 132 | + |
| 133 | + iteratort( |
| 134 | + const iteratort &it, |
| 135 | + std::function<void(const irep_idt &id)> on_get_writeable) |
| 136 | + : it(it.it), on_get_writeable(std::move(on_get_writeable)) |
| 137 | + { |
| 138 | + } |
| 139 | + |
| 140 | + // The following typedefs are NOLINT as they are needed by the STL |
| 141 | + typedef symbolst::iterator::difference_type difference_type; // NOLINT |
| 142 | + typedef symbolst::const_iterator::value_type value_type; // NOLINT |
| 143 | + typedef symbolst::const_iterator::pointer pointer; // NOLINT |
| 144 | + typedef symbolst::const_iterator::reference reference; // NOLINT |
| 145 | + typedef symbolst::iterator::iterator_category iterator_category; // NOLINT |
| 146 | + |
| 147 | + bool operator==(const iteratort &other) const |
| 148 | + { |
| 149 | + return it == other.it; |
| 150 | + } |
| 151 | + |
| 152 | + /// Preincrement operator |
| 153 | + /// Do not call on the end() iterator |
| 154 | + iteratort &operator++() |
| 155 | + { |
| 156 | + ++it; |
| 157 | + return *this; |
| 158 | + } |
| 159 | + |
| 160 | + /// Post-increment operator |
| 161 | + /// \remarks Expensive copy. Avoid if possible. |
| 162 | + iteratort operator++(int) |
| 163 | + { |
| 164 | + iteratort copy(*this); |
| 165 | + this->operator++(); |
| 166 | + return copy; |
| 167 | + } |
| 168 | + |
| 169 | + /// Dereference operator |
| 170 | + /// \remarks Dereferencing end() iterator is undefined behaviour |
| 171 | + reference operator*() const |
| 172 | + { |
| 173 | + return *it; |
| 174 | + } |
| 175 | + |
| 176 | + /// Dereference operator (member access) |
| 177 | + /// \remarks Dereferencing end() iterator is undefined behaviour |
| 178 | + pointer operator->() const |
| 179 | + { |
| 180 | + return &**this; |
| 181 | + } |
| 182 | + |
| 183 | + symbolt &get_writeable_symbol(const irep_idt &identifier) |
| 184 | + { |
| 185 | + if(on_get_writeable) |
| 186 | + on_get_writeable((*this)->first); |
| 187 | + return it->second; |
| 188 | + } |
| 189 | + }; |
| 190 | + |
| 191 | + virtual iteratort begin() = 0; |
| 192 | + virtual iteratort end() = 0; |
120 | 193 | };
|
121 | 194 |
|
122 | 195 | std::ostream &
|
|
0 commit comments