Create a state struct.

This commit is contained in:
chriseth
2022-03-14 19:32:33 +01:00
parent eab4ca906c
commit afdf22f5c7
2 changed files with 49 additions and 47 deletions
+15 -9
View File
@@ -101,9 +101,9 @@ public:
void operator()(Block& _block) override;
/// @returns the current value of the given variable, if known - always movable.
AssignedValue const* variableValue(YulString _variable) const { return util::valueOrNullptr(m_value, _variable); }
std::set<YulString> const* references(YulString _variable) const { return util::valueOrNullptr(m_references, _variable); }
std::map<YulString, AssignedValue> const& allValues() const { return m_value; }
AssignedValue const* variableValue(YulString _variable) const { return util::valueOrNullptr(m_state.value, _variable); }
std::set<YulString> const* references(YulString _variable) const { return util::valueOrNullptr(m_state.references, _variable); }
std::map<YulString, AssignedValue> const& allValues() const { return m_state.value; }
std::optional<YulString> storageValue(YulString _key) const;
std::optional<YulString> memoryValue(YulString _key) const;
@@ -173,14 +173,20 @@ protected:
/// if this is not provided or the function is not found.
std::map<YulString, SideEffects> m_functionSideEffects;
/// Current values of variables, always movable.
std::map<YulString, AssignedValue> m_value;
/// m_references[a].contains(b) <=> the current expression assigned to a references b
std::unordered_map<YulString, std::set<YulString>> m_references;
private:
struct State
{
/// Current values of variables, always movable.
std::map<YulString, AssignedValue> value;
/// m_references[a].contains(b) <=> the current expression assigned to a references b
std::unordered_map<YulString, std::set<YulString>> references;
std::unordered_map<YulString, YulString> m_storage;
std::unordered_map<YulString, YulString> m_memory;
std::unordered_map<YulString, YulString> storage;
std::unordered_map<YulString, YulString> memory;
};
State m_state;
protected:
KnowledgeBase m_knowledgeBase;
YulString m_storeFunctionName[static_cast<unsigned>(StoreLoadLocation::Last) + 1];