mirror of https://github.com/YosysHQ/yosys.git
Undo formatting changes in kernel/utils.h.
This commit is contained in:
parent
b9745f638b
commit
e38c9e01c9
|
@ -31,7 +31,9 @@ YOSYS_NAMESPACE_BEGIN
|
||||||
// A map-like container, but you can save and restore the state
|
// A map-like container, but you can save and restore the state
|
||||||
// ------------------------------------------------
|
// ------------------------------------------------
|
||||||
|
|
||||||
template <typename Key, typename T, typename OPS = hash_ops<Key>> struct stackmap {
|
template<typename Key, typename T, typename OPS = hash_ops<Key>>
|
||||||
|
struct stackmap
|
||||||
|
{
|
||||||
private:
|
private:
|
||||||
std::vector<dict<Key, T*, OPS>> backup_state;
|
std::vector<dict<Key, T*, OPS>> backup_state;
|
||||||
dict<Key, T, OPS> current_state;
|
dict<Key, T, OPS> current_state;
|
||||||
|
@ -41,20 +43,22 @@ template <typename Key, typename T, typename OPS = hash_ops<Key>> struct stackma
|
||||||
stackmap() { }
|
stackmap() { }
|
||||||
stackmap(const dict<Key, T, OPS> &other) : current_state(other) { }
|
stackmap(const dict<Key, T, OPS> &other) : current_state(other) { }
|
||||||
|
|
||||||
template <typename Other> stackmap &operator=(const Other &other)
|
template<typename Other>
|
||||||
|
void operator=(const Other &other)
|
||||||
{
|
{
|
||||||
for (const auto &it : current_state)
|
for (auto &it : current_state)
|
||||||
if (!backup_state.empty() && backup_state.back().count(it.first) == 0)
|
if (!backup_state.empty() && backup_state.back().count(it.first) == 0)
|
||||||
backup_state.back()[it.first] = new T(it.second);
|
backup_state.back()[it.first] = new T(it.second);
|
||||||
current_state.clear();
|
current_state.clear();
|
||||||
|
|
||||||
for (const auto &it : other)
|
for (auto &it : other)
|
||||||
set(it.first, it.second);
|
set(it.first, it.second);
|
||||||
|
|
||||||
return *this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool has(const Key &k) { return current_state.count(k) != 0; }
|
bool has(const Key &k)
|
||||||
|
{
|
||||||
|
return current_state.count(k) != 0;
|
||||||
|
}
|
||||||
|
|
||||||
void set(const Key &k, const T &v)
|
void set(const Key &k, const T &v)
|
||||||
{
|
{
|
||||||
|
@ -90,14 +94,20 @@ template <typename Key, typename T, typename OPS = hash_ops<Key>> struct stackma
|
||||||
current_state.erase(k);
|
current_state.erase(k);
|
||||||
}
|
}
|
||||||
|
|
||||||
const dict<Key, T, OPS> &stdmap() { return current_state; }
|
const dict<Key, T, OPS> &stdmap()
|
||||||
|
{
|
||||||
|
return current_state;
|
||||||
|
}
|
||||||
|
|
||||||
void save() { backup_state.resize(backup_state.size() + 1); }
|
void save()
|
||||||
|
{
|
||||||
|
backup_state.resize(backup_state.size()+1);
|
||||||
|
}
|
||||||
|
|
||||||
void restore()
|
void restore()
|
||||||
{
|
{
|
||||||
log_assert(!backup_state.empty());
|
log_assert(!backup_state.empty());
|
||||||
for (const auto &it : backup_state.back())
|
for (auto &it : backup_state.back())
|
||||||
if (it.second != nullptr) {
|
if (it.second != nullptr) {
|
||||||
current_state[it.first] = *it.second;
|
current_state[it.first] = *it.second;
|
||||||
delete it.second;
|
delete it.second;
|
||||||
|
|
Loading…
Reference in New Issue