Esempio n. 1
0
        private Assignment(bool nonAmbiguousIgnored, Expression target, AType nullableTypeDeclaration, Token assignmentOpToken, Ops op, Expression assignedValue, Node owner)
            : base(target.FirstToken, owner)
        {
            this.Target  = target;
            this.OpToken = assignmentOpToken;
            this.Op      = op;
            this.Value   = assignedValue;
            this.NullableTypeDeclaration = nullableTypeDeclaration;

            if (this.NullableTypeDeclaration != null)
            {
                this.type = AssignmentType.TYPED_VARIABLE_DECLARATION;

                if (this.Value == null)
                {
                    Expression defaultValue;
                    switch (this.NullableTypeDeclaration.RootType)
                    {
                    case "bool": defaultValue = new BooleanConstant(this.FirstToken, false, this.Owner); break;

                    case "int": defaultValue = new IntegerConstant(this.FirstToken, 0, this.Owner); break;

                    case "float": defaultValue = new FloatConstant(this.FirstToken, 0.0, this.Owner); break;

                    default: defaultValue = new NullConstant(this.FirstToken, this.Owner); break;
                    }
                    this.Value = defaultValue;
                }
            }
            else if (this.Target is Variable)
            {
                this.type = AssignmentType.VARIABLE;
            }
            else if (this.Target is BracketIndex)
            {
                this.type = AssignmentType.KEYED_ASSIGNMENT;
            }
            else if (this.Target is DotField || this.Target is FieldReference)
            {
                this.type = AssignmentType.FIELD_ASSIGNMENT;
            }
            else
            {
                throw new ParserException(this, "Cannot assign to this type of expression.");
            }
        }
Esempio n. 2
0
        private bool DetermineContinuousness()
        {
            HashSet <int> integersUsed = new HashSet <int>();
            bool          first        = true;
            int           min          = 0;
            int           max          = 0;

            foreach (Chunk chunk in this.chunks)
            {
                if (chunk.Cases.Length != 1)
                {
                    throw new Exception("This should have been filtered out by the largestSpane check earlier.");
                }
                IntegerConstant c = chunk.Cases[0] as IntegerConstant;
                if (c == null)
                {
                    throw new Exception("How did this happen?");
                }
                int num = c.Value;
                integersUsed.Add(num);
                if (first)
                {
                    first = false;
                    min   = num;
                    max   = num;
                }
                else
                {
                    if (num < min)
                    {
                        min = num;
                    }
                    if (num > max)
                    {
                        max = num;
                    }
                }
            }

            int expectedTotal = max - min + 1;

            return(expectedTotal == integersUsed.Count);
        }
Esempio n. 3
0
        public ListSlice(Expression root, List <Expression> items, Token bracketToken, Node owner)
            : base(root.FirstToken, owner)
        {
            this.Root         = root;
            this.BracketToken = bracketToken;
            if (items.Count == 2)
            {
                items.Add(new IntegerConstant(null, 1, owner));
            }

            if (items.Count != 3)
            {
                throw new Exception("Slices must have 2 or 3 components before passed into the constructor.");
            }

            if (items[2] == null)
            {
                items[2] = new IntegerConstant(null, 1, owner);
            }

            this.Items = items.ToArray();
        }
Esempio n. 4
0
        internal override void Resolve(ParserContext parser)
        {
            ConstantResolutionState resolutionState = parser.ConstantAndEnumResolutionState[this];

            if (resolutionState == ConstantResolutionState.RESOLVED)
            {
                return;
            }
            if (resolutionState == ConstantResolutionState.RESOLVING)
            {
                throw new ParserException(this, "The resolution of this enum creates a cycle.");
            }
            parser.ConstantAndEnumResolutionState[this] = ConstantResolutionState.RESOLVING;

            HashSet <int> consumed = new HashSet <int>();

            for (int i = 0; i < this.Items.Length; ++i)
            {
                string itemName = this.Items[i].Value;

                if (itemName == "length")
                {
                    throw new ParserException(this.Items[i], "The name 'length' is not allowed as an enum value as it is a reserved field. In general, enum members should be in ALL CAPS anyway.");
                }

                if (this.IntValue.ContainsKey(itemName))
                {
                    throw new ParserException(this.Items[i], "Duplicate item in same enum. ");
                }

                this.IntValue[itemName] = -1;

                if (this.Values[i] != null)
                {
                    IntegerConstant ic = this.Values[i].Resolve(parser) as IntegerConstant;
                    if (ic == null)
                    {
                        throw new ParserException(this.Values[i], "Enum values must be integers or left blank.");
                    }
                    this.Values[i] = ic;
                    if (consumed.Contains(ic.Value))
                    {
                        throw new ParserException(this.Values[i], "This integer value has already been used in the same enum.");
                    }

                    consumed.Add(ic.Value);
                    this.IntValue[itemName] = ic.Value;
                }
            }
            parser.ConstantAndEnumResolutionState[this] = ConstantResolutionState.RESOLVED;

            int next = 0;

            for (int i = 0; i < this.Items.Length; ++i)
            {
                if (this.Values[i] == null)
                {
                    while (consumed.Contains(next))
                    {
                        ++next;
                    }

                    this.IntValue[this.Items[i].Value] = next;
                    consumed.Add(next);
                }
            }
        }