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); }
public VarStruct(string typeString, VarLocation location) : base(typeString) { // Set our struct definition string canonicalName = VarParser.GetEnumOrStructCanonicalName(typeString); if (!AstParser._structsByCanonicalName.TryGetValue(canonicalName, out var structDefinition)) { throw new ArgumentException("Could not find struct definition for parsed canonical name."); } // Set our obtained struct definition. StructDefinition = structDefinition; // Obtain our struct members. Members = StructDefinition.Members.Select(x => new StateVariable(x)).ToArray(); // Resolve all of the storage locations for these state variables. StorageLocation endLocation = StorageManager.ResolveStorageSlots(Members); // Obtain our next free slot based off of our end location. int nextFreeSlot = (int)endLocation.SlotKeyInteger; if (endLocation.DataOffset > 0) { nextFreeSlot++; } // Our next free slot signifies our used storage entry count to that point. // Initialize our bounds InitializeBounds(nextFreeSlot, UInt256.SIZE, location); }
public void InitializeBounds(int storageEntryCount, int storageSizeBytes, VarLocation variableLocation) { // Set our variables bounds. InitializeBounds(storageEntryCount, storageSizeBytes); // Set our extra properties VariableLocation = variableLocation; }
public VarStruct(AstUserDefinedTypeName type, VarLocation location) : base(type) { // Set our struct definition StructDefinition = AstParser.GetNode <AstStructDefinition>(type.ReferencedDeclaration); // Obtain our struct members. Members = StructDefinition.Members.Select(x => new StateVariable(x)).ToArray(); // Resolve all of the storage locations for these state variables. StorageLocation endLocation = StorageManager.ResolveStorageSlots(Members); // Obtain our next free slot based off of our end location. int nextFreeSlot = (int)endLocation.SlotKeyInteger; if (endLocation.DataOffset > 0) { nextFreeSlot++; } // Our next free slot signifies our used storage entry count to that point. // Initialize our bounds InitializeBounds(nextFreeSlot, UInt256.SIZE, location); }
public VarString(AstElementaryTypeName type, VarLocation location) : base(type, location) { }
public VarDynamicBytes(AstElementaryTypeName type, VarLocation location) : base(type) { // Initialize our bounds. InitializeBounds(1, UInt256.SIZE, location); }
public VarString(string typeString, VarLocation location) : base(typeString, location) { }
public VarDynamicBytes(string typeString, VarLocation location) : base(typeString) { // Initialize our bounds. InitializeBounds(1, UInt256.SIZE, location); }