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); }