Beispiel #1
0
        public override SoqlExpression Simplify()
        {
            Left  = (SoqlBooleanExpression)Left.Simplify();
            Right = (SoqlBooleanExpression)Right.Simplify();

            ISoqlConstantExpression cp1 = Left as ISoqlConstantExpression;
            ISoqlConstantExpression cp2 = Right as ISoqlConstantExpression;

            // left subexpression is false - our node is false

            if (cp1 != null && (bool)cp1.GetConstantValue() == false)
            {
                return(new SoqlBooleanLiteralExpression(false));
            }

            // right subexpression is false - our node is false

            if (cp2 != null && (bool)cp2.GetConstantValue() == false)
            {
                return(new SoqlBooleanLiteralExpression(false));
            }

            // both are constant and not false - our node is true

            if (cp1 != null && cp2 != null)
            {
                return(new SoqlBooleanLiteralExpression(true));
            }

            // left subexpression is true - we return the right node

            if (cp1 != null && (bool)cp1.GetConstantValue() == true)
            {
                return(Right);
            }

            // right subexpression is true - we return the left node

            if (cp2 != null && (bool)cp2.GetConstantValue() == true)
            {
                return(Left);
            }

            // cannot simplify anymore
            return(this);
        }
        public override SoqlExpression Simplify()
        {
            par1 = (SoqlBooleanExpression)par1.Simplify();
            par2 = (SoqlBooleanExpression)par2.Simplify();

            ISoqlConstantExpression cp1 = par1 as ISoqlConstantExpression;
            ISoqlConstantExpression cp2 = par2 as ISoqlConstantExpression;

            // left subexpression is true - our node is true

            if (cp1 != null && (bool)cp1.GetConstantValue() == true)
            {
                return(new SoqlBooleanLiteralExpression(true));
            }

            // right subexpression is true - our node is true

            if (cp2 != null && (bool)cp2.GetConstantValue() == true)
            {
                return(new SoqlBooleanLiteralExpression(true));
            }

            // both are constant and false - our node is false

            if (cp1 != null && cp2 != null)
            {
                return(new SoqlBooleanLiteralExpression(false));
            }

            if (cp1 != null && (bool)cp1.GetConstantValue() == false)
            {
                return(par2);
            }

            if (cp2 != null && (bool)cp2.GetConstantValue() == false)
            {
                return(par1);
            }

            return(this);
        }
 public override SoqlExpression Simplify()
 {
     par = (SoqlBooleanExpression)par.Simplify();
     return(this);
 }