aboutsummaryrefslogtreecommitdiffstats
path: root/Types.h
diff options
context:
space:
mode:
authorchriseth <c@ethdev.com>2015-03-14 02:48:24 +0800
committerchriseth <c@ethdev.com>2015-03-17 01:07:14 +0800
commit02595abf6ac1c30c7c0125c5a705cd2c85974838 (patch)
treeb824309b77c9be95bd81b50e6e4cc6b457b3b9a9 /Types.h
parent7f64584b7fb151459500ade84612d3cd48f13f18 (diff)
downloaddexon-solidity-02595abf6ac1c30c7c0125c5a705cd2c85974838.tar.gz
dexon-solidity-02595abf6ac1c30c7c0125c5a705cd2c85974838.tar.zst
dexon-solidity-02595abf6ac1c30c7c0125c5a705cd2c85974838.zip
Fetch and store packed values.
Diffstat (limited to 'Types.h')
-rw-r--r--Types.h25
1 files changed, 22 insertions, 3 deletions
diff --git a/Types.h b/Types.h
index 5e497078..cc7a0e24 100644
--- a/Types.h
+++ b/Types.h
@@ -43,6 +43,26 @@ using TypePointer = std::shared_ptr<Type const>;
using FunctionTypePointer = std::shared_ptr<FunctionType const>;
using TypePointers = std::vector<TypePointer>;
+
+/**
+ * Helper class to compute storage offsets of members of structs and contracts.
+ */
+class StorageOffsets
+{
+public:
+ /// Resets the StorageOffsets objects and determines the position in storage for each
+ /// of the elements of @a _types.
+ void computeOffsets(TypePointers const& _types);
+ /// @returns the offset of the given member, might be null if the member is not part of storage.
+ std::pair<u256, unsigned> const* getOffset(size_t _index) const;
+ /// @returns the total number of slots occupied by all members.
+ u256 const& getStorageSize() const { return m_storageSize; }
+
+private:
+ u256 m_storageSize;
+ std::map<size_t, std::pair<u256, unsigned>> m_offsets;
+};
+
/**
* List of members of a type.
*/
@@ -71,8 +91,7 @@ public:
private:
MemberMap m_memberTypes;
- mutable u256 m_storageSize = 0;
- mutable std::unique_ptr<std::map<std::string, std::pair<u256, unsigned>>> m_storageOffsets;
+ mutable std::unique_ptr<StorageOffsets> m_storageOffsets;
};
/**
@@ -411,7 +430,7 @@ public:
virtual MemberList const& getMembers() const override;
- u256 getStorageOffsetOfMember(std::string const& _name) const;
+ std::pair<u256, unsigned> const& getStorageOffsetsOfMember(std::string const& _name) const;
private:
StructDefinition const& m_struct;