Exemplo n.º 1
0
        /// <summary>
        /// Applies the rule.
        /// </summary>
        /// <param name="node">The node instance to modify.</param>
        /// <param name="data">Private data from CheckConsistency().</param>
        public override void Apply(IQueryExpression node, object data)
        {
            ILanguageConstant ExpressionConstant = NeutralLanguageConstant.NotConstant;

            Debug.Assert(node.ConstantSourceList.Count > 0);

            bool IsConstant = true;

            foreach (IExpression ConstantSource in node.ConstantSourceList)
            {
                IsConstant &= ConstantSource.ExpressionConstant.Item != NeutralLanguageConstant.NotConstant;
            }

            if (IsConstant)
            {
                ExpressionConstant = new ObjectLanguageConstant();

                if (node.ResolvedFinalDiscrete.IsAssigned)
                {
                    ExpressionConstant = new DiscreteLanguageConstant(node.ResolvedFinalDiscrete.Item);
                }
                else
                {
                    Debug.Assert(node.ResolvedFinalFeature.IsAssigned);
                    ICompiledFeature FinalFeature = node.ResolvedFinalFeature.Item;

                    if (FinalFeature is IConstantFeature AsConstantFeature)
                    {
                        Debug.Assert(node.ConstantSourceList.Count == 1);
                        Debug.Assert(node.ConstantSourceList[0].ExpressionConstant.IsAssigned);

                        ExpressionConstant = node.ConstantSourceList[0].ExpressionConstant.Item;
                    }
                    else
                    {
                        ExpressionConstant = Expression.GetDefaultConstant(node, node.ResolvedResult.Item);
                    }
                }
            }

            node.ExpressionConstant.Item = ExpressionConstant;
        }
        /// <summary>
        /// Applies the rule.
        /// </summary>
        /// <param name="node">The node instance to modify.</param>
        /// <param name="data">Private data from CheckConsistency().</param>
        public override void Apply(IClassConstantExpression node, object data)
        {
            ILanguageConstant ExpressionConstant = NeutralLanguageConstant.NotConstant;

            Debug.Assert(node.ConstantSourceList.Count == 1);
            IExpression ConstantSource = node.ConstantSourceList[0];

            Debug.Assert(ConstantSource.ExpressionConstant.IsAssigned);

            if (node.ResolvedFinalDiscrete.IsAssigned)
            {
                ExpressionConstant = new DiscreteLanguageConstant(node.ResolvedFinalDiscrete.Item);
            }
            else
            {
                ExpressionConstant = ConstantSource.ExpressionConstant.Item;
            }

            node.ExpressionConstant.Item = ExpressionConstant;
        }
Exemplo n.º 3
0
        private void AddValueToList(IConstantRange range)
        {
            if (LanguageConstant.TryParseInt(range.Minimum, out int IntMinimum) && LanguageConstant.TryParseInt(range.Maximum, out int IntMaximum))
            {
                ConstantList.Add(range.Minimum);

                if (IntMinimum < IntMaximum)
                {
                    for (int i = IntMinimum + 1; i < IntMaximum; i++)
                    {
                        ConstantList.Add(new NumberLanguageConstant(new Number(i)));
                    }

                    ConstantList.Add(range.Maximum);
                }
            }

            else if (range.Minimum is DiscreteLanguageConstant AsDiscreteMinimum && AsDiscreteMinimum.IsValueKnown && range.Maximum is DiscreteLanguageConstant AsDiscreteMaximum && AsDiscreteMaximum.IsValueKnown)
            {
                ConstantList.Add(AsDiscreteMinimum);

                if (AsDiscreteMaximum.IsConstantGreater(AsDiscreteMinimum))
                {
                    IClass EmbeddingClass = AsDiscreteMinimum.Discrete.EmbeddingClass;

                    int DiscreteMinimumIndex = EmbeddingClass.DiscreteList.IndexOf(AsDiscreteMinimum.Discrete);
                    int DiscreteMaximumIndex = EmbeddingClass.DiscreteList.IndexOf(AsDiscreteMaximum.Discrete);

                    if (DiscreteMinimumIndex >= 0 && DiscreteMaximumIndex >= 0)
                    {
                        for (int Index = DiscreteMinimumIndex + 1; Index < DiscreteMaximumIndex; Index++)
                        {
                            IDiscrete MiddleDiscrete = EmbeddingClass.DiscreteList[Index];
                            DiscreteLanguageConstant MiddleConstant = new DiscreteLanguageConstant(MiddleDiscrete);
                            ConstantList.Add(MiddleConstant);
                        }
                    }
                }
            }
        }