Refactor storageSizeUpperBound.

This commit is contained in:
chriseth
2020-07-14 10:45:02 +02:00
parent 289fc7a9d0
commit f28bede34a
9 changed files with 63 additions and 59 deletions
+6 -1
View File
@@ -59,7 +59,6 @@ using BoolResult = util::Result<bool>;
namespace solidity::frontend
{
bigint storageSizeUpperBound(frontend::Type const& _type);
std::vector<frontend::Type const*> oversizedSubtypes(frontend::Type const& _type);
inline rational makeRational(bigint const& _numerator, bigint const& _denominator)
@@ -251,6 +250,10 @@ public:
/// @returns the number of storage slots required to hold this value in storage.
/// For dynamically "allocated" types, it returns the size of the statically allocated head,
virtual u256 storageSize() const { return 1; }
/// @returns an upper bound on the total storage size required by this type, descending
/// into structs and statically-sized arrays. This is mainly to ensure that the storage
/// slot allocation algorithm does not overflow, it is not a protection against collisions.
virtual bigint storageSizeUpperBound() const { return 1; }
/// Multiple small types can be packed into a single storage slot. If such a packing is possible
/// this function @returns the size in bytes smaller than 32. Data is moved to the next slot if
/// it does not fit.
@@ -788,6 +791,7 @@ public:
unsigned calldataEncodedTailSize() const override;
bool isDynamicallySized() const override { return m_hasDynamicLength; }
bool isDynamicallyEncoded() const override;
bigint storageSizeUpperBound() const override;
u256 storageSize() const override;
bool canLiveOutsideStorage() const override { return m_baseType->canLiveOutsideStorage(); }
bool nameable() const override { return true; }
@@ -952,6 +956,7 @@ public:
unsigned calldataEncodedTailSize() const override;
bool isDynamicallyEncoded() const override;
u256 memoryDataSize() const override;
bigint storageSizeUpperBound() const override;
u256 storageSize() const override;
bool canLiveOutsideStorage() const override { return true; }
bool nameable() const override { return true; }