public VarArray(AstArrayTypeName type, VarLocation location) : base(type) { // Obtain our array size ArraySize = VarParser.ParseArrayTypeComponents(BaseType).arraySize; // Set our type name ArrayTypeName = type; // Set our element parser with the given array element/base type. ElementObject = VarParser.GetVariableObject(ArrayTypeName.BaseType, location); // Define our bounds variables int storageSlotCount = 1; if (ArraySize.HasValue) { // If an element doesn't fit in a single slot, we keep the storage format as is, and slot count = element count * element slot count. // If an element fits in a single slot, we try to compact multiple into a single slot. if (ElementObject.SizeBytes >= UInt256.SIZE) { storageSlotCount = ArraySize.Value * ElementObject.StorageEntryCount; } else { // Determine how many elements we can fit in a slot. int elementsPerSlot = UInt256.SIZE / ElementObject.SizeBytes; // Figure out how many slots we'll actually need to store the element count. storageSlotCount = (int)Math.Ceiling(ArraySize.Value / (double)elementsPerSlot); } } // Initialize our bounds. InitializeBounds(storageSlotCount, UInt256.SIZE, location); }