Esempio n. 1
0
        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);
        }
Esempio n. 2
0
        public VarEnum(AstUserDefinedTypeName type) : base(type)
        {
            // Set our enum definition
            EnumDefinition = AstParser.GetNode <AstEnumDefinition>(type.ReferencedDeclaration);

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