Esempio n. 1
0
        public CBinaryLambdaFuncASTNode(E_OPERATION_TYPE type) :
            base(E_NODE_TYPE.NT_BINARY_LAMBDA_FUNC)
        {
            mOpType = type;

            mAttributes = E_NODE_ATTRIBUTES.NA_IS_LEAF_NODE;
        }
Esempio n. 2
0
        protected string _constructOperationStr(E_OPERATION_TYPE type)
        {
            switch (type)
            {
            case E_OPERATION_TYPE.OT_ADD:
                return("+");

            case E_OPERATION_TYPE.OT_SUB:
                return("-");

            case E_OPERATION_TYPE.OT_MUL:
                return("*");

            case E_OPERATION_TYPE.OT_DIV:
                return("/");

            case E_OPERATION_TYPE.OT_MOD:
                return("%");

            //case E_OPERATION_TYPE.OT_POW:
            //    return "**";

            case E_OPERATION_TYPE.OT_MAX:
                return("MAX");

            case E_OPERATION_TYPE.OT_MIN:
                return("MIN");
            }

            return(string.Empty);
        }
        public CUnaryLambdaFuncASTNode(E_OPERATION_TYPE type, IASTNode body) :
            base(E_NODE_TYPE.NT_UNARY_LAMBDA_FUNC)
        {
            mOpType = type;

            body.Parent = this;

            body.NodeId = 0;

            mChildren.Add(body);
        }
Esempio n. 4
0
        protected Expression _createExpressionByOpType(E_OPERATION_TYPE type, Expression left, Expression right)
        {
            switch (type)
            {
            case E_OPERATION_TYPE.OT_ADD:
                return(Expression.Add(left, right));

            case E_OPERATION_TYPE.OT_SUB:
                return(Expression.Subtract(left, right));

            case E_OPERATION_TYPE.OT_MUL:
                return(Expression.Multiply(left, right));

            case E_OPERATION_TYPE.OT_DIV:

                if ((mAttributes & E_INTERPRETER_ATTRIBUTES.IA_IS_SAFE_DIVISION_ENABLED) == E_INTERPRETER_ATTRIBUTES.IA_IS_SAFE_DIVISION_ENABLED)
                {
                    return(_createSafeDivisionOperator(left, right));
                }

                return(Expression.Divide(left, right));

            case E_OPERATION_TYPE.OT_MOD:

                if ((mAttributes & E_INTERPRETER_ATTRIBUTES.IA_IS_SAFE_DIVISION_ENABLED) == E_INTERPRETER_ATTRIBUTES.IA_IS_SAFE_DIVISION_ENABLED)
                {
                    return(_createSafeModuloOperator(left, right));
                }

                return(Expression.Modulo(left, right));

            case E_OPERATION_TYPE.OT_MAX:
                return(Expression.Call(typeof(Math).GetMethod("Max", new Type[] { typeof(Int32), typeof(Int32) }), left, right));

            case E_OPERATION_TYPE.OT_MIN:
                return(Expression.Call(typeof(Math).GetMethod("Min", new Type[] { typeof(Int32), typeof(Int32) }), left, right));
            }

            return(Expression.Empty());
        }
Esempio n. 5
0
        public void TestVisitUnaryLambdaFuncNode_CheckSimpleLambdaPredicateGeneration_ReturnsLambdaPredicate(E_OPERATION_TYPE type, int x, int value, int res)
        {
            IVisitor <Object> interpreter = new CInterpreter();

            Func <int, int> lambdaFunctor = null;

            Assert.DoesNotThrow(() => {
                lambdaFunctor = (Func <int, int>)interpreter.VisitUnaryLambdaFuncNode(
                    new CUnaryLambdaFuncASTNode(type, new CValueASTNode(new int[] { value })));
            });

            Assert.AreEqual(res, lambdaFunctor(x));
        }
Esempio n. 6
0
        //[TestCase(E_OPERATION_TYPE.OT_POW, 3, 2, 9)] works only for double, need to find some trick to implement it
        public void TestVisitBinaryLambdaFuncNode_CheckLambdaFunctorGeneration_ReturnsLambdaFunctor(E_OPERATION_TYPE type, int x, int y, int res)
        {
            IVisitor <Object> interpreter = new CInterpreter();

            Func <int, int, int> lambdaFunctor = null;

            Assert.DoesNotThrow(() => {
                lambdaFunctor = (Func <int, int, int>)interpreter.VisitBinaryLambdaFuncNode(new CBinaryLambdaFuncASTNode(type));
            });

            Assert.AreEqual(res, lambdaFunctor(x, y));
        }