Esempio 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(IUnaryNotExpression node, object data)
        {
            ILanguageConstant ExpressionConstant = NeutralLanguageConstant.NotConstant;

            Debug.Assert(node.ConstantSourceList.Count == 1);

            IExpression RightConstantSource = node.ConstantSourceList[0];
            Debug.Assert(RightConstantSource == node.RightExpression);

            Debug.Assert(RightConstantSource.ExpressionConstant.IsAssigned);
            ILanguageConstant RightExpressionConstant = RightConstantSource.ExpressionConstant.Item;

            if (RightExpressionConstant != NeutralLanguageConstant.NotConstant)
            {
                IBooleanLanguageConstant RightConstant = RightExpressionConstant as IBooleanLanguageConstant;
                Debug.Assert(RightConstant != null);

                bool? RightConstantValue = RightConstant.Value;

                if (RightConstantValue.HasValue)
                    ExpressionConstant = new BooleanLanguageConstant(!RightConstantValue.Value);
                else
                    ExpressionConstant = new BooleanLanguageConstant();
            }

            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(IEqualityExpression node, object data)
        {
            ILanguageConstant ExpressionConstant = NeutralLanguageConstant.NotConstant;

            Debug.Assert(node.ConstantSourceList.Count == 2);

            IExpression LeftConstantSource = node.ConstantSourceList[0];

            Debug.Assert(LeftConstantSource == node.LeftExpression);

            IExpression RightConstantSource = node.ConstantSourceList[1];

            Debug.Assert(RightConstantSource == node.RightExpression);

            Debug.Assert(LeftConstantSource.ExpressionConstant.IsAssigned);
            ILanguageConstant LeftExpressionConstant = LeftConstantSource.ExpressionConstant.Item;

            Debug.Assert(RightConstantSource.ExpressionConstant.IsAssigned);
            ILanguageConstant RightExpressionConstant = RightConstantSource.ExpressionConstant.Item;

            if (LeftExpressionConstant != NeutralLanguageConstant.NotConstant && RightExpressionConstant != NeutralLanguageConstant.NotConstant)
            {
                if (LeftExpressionConstant.IsCompatibleWith(RightExpressionConstant) && LeftExpressionConstant.IsValueKnown && RightExpressionConstant.IsValueKnown)
                {
                    switch (node.Comparison)
                    {
                    case BaseNode.ComparisonType.Equal:
                        ExpressionConstant = new BooleanLanguageConstant(LeftExpressionConstant.IsConstantEqual(RightExpressionConstant));
                        break;

                    case BaseNode.ComparisonType.Different:
                        ExpressionConstant = new BooleanLanguageConstant(!LeftExpressionConstant.IsConstantEqual(RightExpressionConstant));
                        break;
                    }

                    IBooleanLanguageConstant BooleanLanguageConstant = ExpressionConstant as IBooleanLanguageConstant;
                    Debug.Assert(BooleanLanguageConstant != null);
                    Debug.Assert(BooleanLanguageConstant.IsValueKnown);
                }
                else
                {
                    ExpressionConstant = new BooleanLanguageConstant();
                }
            }

            node.ExpressionConstant.Item = ExpressionConstant;
        }
Esempio n. 3
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(IBinaryConditionalExpression node, object data)
        {
            ILanguageConstant ExpressionConstant = NeutralLanguageConstant.NotConstant;

            Debug.Assert(node.ConstantSourceList.Count == 2);

            IExpression LeftConstantSource = node.ConstantSourceList[0];

            Debug.Assert(LeftConstantSource == node.LeftExpression);

            IExpression RightConstantSource = node.ConstantSourceList[1];

            Debug.Assert(RightConstantSource == node.RightExpression);

            Debug.Assert(LeftConstantSource.ExpressionConstant.IsAssigned);
            ILanguageConstant LeftExpressionConstant = LeftConstantSource.ExpressionConstant.Item;

            Debug.Assert(RightConstantSource.ExpressionConstant.IsAssigned);
            ILanguageConstant RightExpressionConstant = RightConstantSource.ExpressionConstant.Item;

            if (LeftExpressionConstant != NeutralLanguageConstant.NotConstant && RightExpressionConstant != NeutralLanguageConstant.NotConstant)
            {
                IBooleanLanguageConstant LeftConstant = LeftExpressionConstant as IBooleanLanguageConstant;
                Debug.Assert(LeftConstant != null);
                IBooleanLanguageConstant RightConstant = RightExpressionConstant as IBooleanLanguageConstant;
                Debug.Assert(RightConstant != null);

                bool?LeftConstantValue  = LeftConstant.Value;
                bool?RightConstantValue = RightConstant.Value;

                if (LeftConstantValue.HasValue && RightConstantValue.HasValue)
                {
                    switch (node.Conditional)
                    {
                    case BaseNode.ConditionalTypes.And:
                        ExpressionConstant = new BooleanLanguageConstant(LeftConstantValue.Value && RightConstantValue.Value);
                        break;

                    case BaseNode.ConditionalTypes.Or:
                        ExpressionConstant = new BooleanLanguageConstant(LeftConstantValue.Value || RightConstantValue.Value);
                        break;

                    case BaseNode.ConditionalTypes.Xor:
                        ExpressionConstant = new BooleanLanguageConstant(LeftConstantValue.Value ^ RightConstantValue.Value);
                        break;

                    case BaseNode.ConditionalTypes.Implies:
                        ExpressionConstant = new BooleanLanguageConstant(!LeftConstantValue.Value || RightConstantValue.Value);
                        break;
                    }

                    Debug.Assert(ExpressionConstant is IBooleanLanguageConstant);
                }
                else
                {
                    ExpressionConstant = new BooleanLanguageConstant();
                }
            }

            node.ExpressionConstant.Item = ExpressionConstant;
        }
Esempio n. 4
0
        /// <summary>
        /// Checks if another constant is equal to this instance.
        /// </summary>
        /// <param name="other">The other instance.</param>
        protected virtual bool IsConstantEqual(IBooleanLanguageConstant other)
        {
            Debug.Assert(other != null && Value.HasValue && other.Value.HasValue);

            return(Value.Value == other.Value.Value);
        }