Add ScopedSaveAndRestore helper.

This commit is contained in:
Daniel Kirchner
2021-04-16 10:56:56 +02:00
parent 0289994da5
commit afae46dcb5
2 changed files with 27 additions and 15 deletions
+5 -15
View File
@@ -156,16 +156,11 @@ void DataFlowAnalyzer::operator()(FunctionDefinition& _fun)
{
// Save all information. We might rather reinstantiate this class,
// but this could be difficult if it is subclassed.
map<YulString, AssignedValue> value;
size_t loopDepth{0};
unordered_map<YulString, set<YulString>> references;
unordered_map<YulString, YulString> storage;
unordered_map<YulString, YulString> memory;
swap(m_value, value);
swap(m_loopDepth, loopDepth);
swap(m_references, references);
swap(m_storage, storage);
swap(m_memory, memory);
ScopedSaveAndRestore valueResetter(m_value, {});
ScopedSaveAndRestore loopDepthResetter(m_loopDepth, 0u);
ScopedSaveAndRestore referencesResetter(m_references, {});
ScopedSaveAndRestore storageResetter(m_storage, {});
ScopedSaveAndRestore memoryResetter(m_memory, {});
pushScope(true);
for (auto const& parameter: _fun.parameters)
@@ -182,11 +177,6 @@ void DataFlowAnalyzer::operator()(FunctionDefinition& _fun)
// statement.
popScope();
swap(m_value, value);
swap(m_loopDepth, loopDepth);
swap(m_references, references);
swap(m_storage, storage);
swap(m_memory, memory);
}
void DataFlowAnalyzer::operator()(ForLoop& _for)