mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Merge pull request #11247 from ethereum/setValueForCurrentScopeHelper
Add SetValueForCurrentScope helper.
This commit is contained in:
commit
f9b23ca845
@ -133,4 +133,26 @@ private:
|
|||||||
std::function<void(void)> m_f;
|
std::function<void(void)> m_f;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/// RAII utility class that sets the value of a variable for the current scope and restores it to its old value
|
||||||
|
/// during its destructor.
|
||||||
|
template<typename V>
|
||||||
|
class ScopedSaveAndRestore
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
explicit ScopedSaveAndRestore(V& _variable, V&& _value): m_variable(_variable), m_oldValue(std::move(_value))
|
||||||
|
{
|
||||||
|
std::swap(m_variable, m_oldValue);
|
||||||
|
}
|
||||||
|
ScopedSaveAndRestore(ScopedSaveAndRestore const&) = delete;
|
||||||
|
~ScopedSaveAndRestore() { std::swap(m_variable, m_oldValue); }
|
||||||
|
ScopedSaveAndRestore& operator=(ScopedSaveAndRestore const&) = delete;
|
||||||
|
|
||||||
|
private:
|
||||||
|
V& m_variable;
|
||||||
|
V m_oldValue;
|
||||||
|
};
|
||||||
|
|
||||||
|
template<typename V, typename... Args>
|
||||||
|
ScopedSaveAndRestore(V, Args...) -> ScopedSaveAndRestore<V>;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -156,16 +156,11 @@ void DataFlowAnalyzer::operator()(FunctionDefinition& _fun)
|
|||||||
{
|
{
|
||||||
// Save all information. We might rather reinstantiate this class,
|
// Save all information. We might rather reinstantiate this class,
|
||||||
// but this could be difficult if it is subclassed.
|
// but this could be difficult if it is subclassed.
|
||||||
map<YulString, AssignedValue> value;
|
ScopedSaveAndRestore valueResetter(m_value, {});
|
||||||
size_t loopDepth{0};
|
ScopedSaveAndRestore loopDepthResetter(m_loopDepth, 0u);
|
||||||
unordered_map<YulString, set<YulString>> references;
|
ScopedSaveAndRestore referencesResetter(m_references, {});
|
||||||
unordered_map<YulString, YulString> storage;
|
ScopedSaveAndRestore storageResetter(m_storage, {});
|
||||||
unordered_map<YulString, YulString> memory;
|
ScopedSaveAndRestore memoryResetter(m_memory, {});
|
||||||
swap(m_value, value);
|
|
||||||
swap(m_loopDepth, loopDepth);
|
|
||||||
swap(m_references, references);
|
|
||||||
swap(m_storage, storage);
|
|
||||||
swap(m_memory, memory);
|
|
||||||
pushScope(true);
|
pushScope(true);
|
||||||
|
|
||||||
for (auto const& parameter: _fun.parameters)
|
for (auto const& parameter: _fun.parameters)
|
||||||
@ -182,11 +177,6 @@ void DataFlowAnalyzer::operator()(FunctionDefinition& _fun)
|
|||||||
// statement.
|
// statement.
|
||||||
|
|
||||||
popScope();
|
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)
|
void DataFlowAnalyzer::operator()(ForLoop& _for)
|
||||||
|
Loading…
Reference in New Issue
Block a user