public override SoqlExpression Simplify()
        {
            par1 = par1.Simplify();
            par2 = par2.Simplify();

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

            if (cp1 != null && cp2 != null)
            {
                object v1 = cp1.GetConstantValue();
                object v2 = cp2.GetConstantValue();

                object result = Compare(v1, v2, op);
                if (result == null)
                {
                    return(new SoqlNullLiteral());
                }
                else
                {
                    return(new SoqlBooleanLiteralExpression((bool)result));
                }
            }
            return(this);
        }
        public override SoqlExpression Simplify()
        {
            par1 = par1.Simplify();
            par2 = par2.Simplify();

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

            if (cp1 != null && cp2 != null)
            {
                object v1 = cp1.GetConstantValue();
                object v2 = cp2.GetConstantValue();

                object newValue = CalcValue(op, v1, v2);
                if (newValue != null)
                {
                    return(new SoqlLiteralExpression(newValue));
                }
                else
                {
                    return(new SoqlNullLiteral());
                }
            }

            return(this);
        }
Beispiel #3
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);
        }