Exemplo n.º 1
0
        // Arthmentic Simplification:

        /*
         * +/- zero to a column, or multiply/divide a column by 1
         */
        internal bool IsArithIdentity(ConstExpr lce, ConstExpr rce)
        {
            ConstExpr ve = lce != null ? lce : rce;
            ColExpr   ce = (children_[0] is ColExpr) ? (ColExpr)children_[0] : (children_[1] is ColExpr ? (ColExpr)children_[1] : null);

            if (ce == null)
            {
                return(false);
            }

            if (!(TypeBase.IsNumberType(ve.type_) && TypeBase.IsNumberType(ce.type_)))
            {
                return(false);
            }

            if ((op_ == "+" || op_ == "-") && ve.IsZero())
            {
                return(true);
            }

            if ((op_ == "*" || op_ == "/") && ve.IsOne())
            {
                return(true);
            }

            return(false);
        }
Exemplo n.º 2
0
        internal Expr SimplifyArithmetic(ConstExpr lve, ConstExpr rve)
        {
            // we know we have a BinExpr with numeric children
            ConstExpr ve = lve != null ? lve : rve;
            ColExpr   ce = (children_[0] is ColExpr) ? (ColExpr)children_[0] : (children_[1] is ColExpr ? (ColExpr)children_[1] : null);

            if (ce is null || ve is null)
            {
                return(this);
            }

            // Col + 0, or Col - 0 => return col
            if ((op_ == "+" || op_ == "-") && ve.IsZero())
            {
                return(ce);
            }

            if ((op_ == "*" || op_ == "/") && ve.IsOne())
            {
                return(ce);
            }

            return(this);
        }