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 VarEnum(string typeString) : base(typeString) { // Set our enum definition string canonicalName = VarParser.GetEnumOrStructCanonicalName(typeString); if (!AstParser._enumsByCanonicalName.TryGetValue(canonicalName, out var enumDefinition)) { throw new ArgumentException("Could not find enum definition for parsed canonical name."); } // Set our obtained struct definition. EnumDefinition = enumDefinition; // Determine how many bytes is needed to address the enum. The enum size is // dependent on the amount of bytes needed to index all enum options. int enumSize = 0; int highestMemberIndex = EnumDefinition.Members.Length - 1; while (highestMemberIndex > 0) { // Add one to our byte count, and shift over. highestMemberIndex >>= 8; enumSize++; } // Initialize our bounds InitializeBounds(1, enumSize); }
public VarUInt(AstElementaryTypeName type) : base(type) { // Obtain our size in bytes int sizeBytes = VarParser.GetIntegerSizeInBytes(BaseType, GenericType); // Initialize our bounds InitializeBounds(1, sizeBytes); }
public VarFixedBytes(string typeString) : base(typeString) { // Determine the size of our fixed array. int sizeBytes = VarParser.GetFixedArraySizeInBytes(BaseType); // Initialize our bounds InitializeBounds(1, sizeBytes); }
public VarMapping(string typeString) : base(typeString) { // Initialize our bounds. (Mappings are Storage-only objects). InitializeBounds(1, UInt256.SIZE, VarLocation.Storage); // Parse the key/value type strings. (KeyTypeString, ValueTypeString) = VarParser.GetMappingKeyValueTypeStrings(typeString); }
public VarFixedBytes(AstElementaryTypeName type) : base(type) { // Determine the size of our fixed array. int sizeBytes = VarParser.GetFixedArraySizeInBytes(BaseType); // Initialize our bounds InitializeBounds(1, sizeBytes); }
public VarInt(string typeString) : base(typeString) { // Obtain our size in bytes int sizeBytes = VarParser.GetIntegerSizeInBytes(BaseType, GenericType); // Initialize our bounds InitializeBounds(1, sizeBytes); }
public VarBase(AstElementaryTypeName type) { // Set our type Type = type; // Obtain the components of our type and set them. BaseType = VarParser.ParseTypeComponents(type.TypeDescriptions.TypeString).baseType; // Obtain our generic type. GenericType = VarParser.GetGenericType(BaseType); }
public VarBase(string typeString) { // Set our type TypeString = typeString; // Obtain the components of our type and set them. BaseType = VarParser.ParseTypeComponents(TypeString).baseType; // Obtain our generic type. GenericType = VarParser.GetGenericType(BaseType); }