コード例 #1
0
ファイル: ExprNodeLtr.cs プロジェクト: MoJoActive/MiniME
        public override object EvalConstLiteral()
        {
            // Eval left, quit if cant
            var lhs = Lhs.EvalConstLiteral();

            if (lhs == null)
            {
                return(null);
            }

            foreach (var t in Terms)
            {
                // Eval right, quit if cant
                var rhs = t.Rhs.EvalConstLiteral();
                if (rhs == null)
                {
                    return(null);
                }

                // We don't like strings
                if (lhs.GetType() == typeof(string) ||
                    rhs.GetType() == typeof(string))
                {
                    return(null);
                }

                // Double?
                if (lhs.GetType() == typeof(DoubleLiteral) &&
                    rhs.GetType() == typeof(DoubleLiteral))
                {
                    lhs = Eval(((DoubleLiteral)lhs).Value, ((DoubleLiteral)rhs).Value, t.Op);
                }

                // Long?
                if (lhs.GetType() == typeof(long) &&
                    rhs.GetType() == typeof(long))
                {
                    lhs = Eval((long)lhs, (long)rhs, t.Op);
                }

                // Bool
                if (lhs.GetType() == typeof(bool) &&
                    rhs.GetType() == typeof(bool))
                {
                    lhs = Eval((bool)lhs, (bool)rhs, t.Op);
                }

                if (lhs == null)
                {
                    return(null);
                }
            }

            return(lhs);
        }
コード例 #2
0
        public override object EvalConstLiteral()
        {
            // Eval right, quit if cant
            var rhs = Rhs.EvalConstLiteral();

            if (rhs == null)
            {
                return(null);
            }

            // Double?
            if (rhs.GetType() == typeof(DoubleLiteral))
            {
                return(Eval(((DoubleLiteral)rhs).Value, Op));
            }

            // Long?
            if (rhs.GetType() == typeof(long))
            {
                return(Eval((long)rhs, Op));
            }

            return(null);
        }