示例#1
0
        /// <summary>
        ///
        /// check the parameters, according to the definition.
        /// </summary>
        /// <param name="exprExecResult"></param>
        /// <param name="functionToCallMapper"></param>
        /// <param name="listExprExecParam"></param>
        /// <returns></returns>
        public bool CheckParams(ExecResult exprExecResult, FunctionToCallMapper functionToCallMapper, List <ExpressionExecBase> listExprExecParam)
        {
            bool res;

            // check param1
            res = CheckParam(exprExecResult, functionToCallMapper, listExprExecParam, 1, functionToCallMapper.Param1Type);
            if (functionToCallMapper.Param1Type == DataType.NotDefined)
            {
                return(res);
            }

            // check param2
            res &= CheckParam(exprExecResult, functionToCallMapper, listExprExecParam, 2, functionToCallMapper.Param2Type);
            if (functionToCallMapper.Param2Type == DataType.NotDefined)
            {
                return(res);
            }

            // check param3
            res &= CheckParam(exprExecResult, functionToCallMapper, listExprExecParam, 3, functionToCallMapper.Param3Type);
            //if (functionToCallMapper.Param2Type == DataType.NotDefined) return res;

            // check others params
            // todo:
            return(res);
        }
示例#2
0
        /// <summary>
        /// Execute a functionCall.
        /// First execute parameters and then execute the function code attached/linked.
        /// </summary>
        /// <param name="exprExecResult"></param>
        /// <param name="exprFunctionCall"></param>
        /// <param name="exprExecBase"></param>
        /// <returns></returns>
        private bool ExecExpressionFunctionCall(ExecResult exprExecResult, ExprFunctionCall exprFunctionCall, out ExpressionExecBase exprExecBase)
        {
            ExpressionExecBase        exprExecParamBase;
            List <ExpressionExecBase> listExprExecParam = new List <ExpressionExecBase>();
            bool res = true;

            exprExecBase = null;

            // get the function code
            FunctionToCallMapper functionToCallMapper = _exprEvalConfig.ListFunctionToCallMapper.Find(f => f.FunctionCallName.Equals(exprFunctionCall.FunctionName, StringComparison.InvariantCultureIgnoreCase));

            if (functionToCallMapper == null)
            {
                // error
                exprExecResult.AddErrorExec(ErrorCode.FunctionCallNotLinked, "FunctionCallName", exprFunctionCall.FunctionName);
                return(false);
            }

            // execute params of the function
            foreach (ExpressionBase exprParam in exprFunctionCall.ListExprParameters)
            {
                res &= ExecExpression(exprExecResult, exprParam, out exprExecParamBase);
                listExprExecParam.Add(exprExecParamBase);
            }

            // a param execution failed
            if (!res)
            {
                return(false);
            }

            // execute the function code attached to the functionCall, provide executed params
            return(_exprExecutorFunctionCall.ExecExpressionFunctionCall(exprExecResult, exprFunctionCall, functionToCallMapper, listExprExecParam, out exprExecBase));
        }
示例#3
0
        /// <summary>
        /// Check that all found functionCall in the expression are linked with a function body.
        /// </summary>
        /// <returns></returns>
        private bool CheckFunctionCalls()
        {
            // set to no error
            bool functionCallMappedRes = true;

            // scan each defined var by the parser
            foreach (ExprFunctionCallUsed functionCallUsed in _expressionData.ExprParseResult.ListExprFunctionCallUsed)
            {
                // is a functionToCall mapped to the functionCall found in the expression?
                FunctionToCallMapper functionToCall = _exprEvalConfig.ListFunctionToCallMapper.Find(f => f.FunctionCallName.Equals(functionCallUsed.Name, StringComparison.InvariantCultureIgnoreCase));
                if (functionToCall == null)
                {
                    // any function code matching the functionCall name is found!
                    _expressionData.ExprExecResult.AddErrorExec(ErrorCode.FunctionCallNotLinked, "FunctionCallName", functionCallUsed.Name);
                    functionCallMappedRes = false;
                    // check the next functionCall used/present in the expression
                    continue;
                }

                // ok the functionCall is attached to a functionCode, check the params count (the type will be checked later at execution)
                if (!CheckParamsCountMatching(functionCallUsed, functionToCall))
                {
                    // the error is set inside the function
                    functionCallMappedRes = false;
                }
            }

            return(functionCallMappedRes);
        }
示例#4
0
        /// <summary>
        /// Check the match of parameters between the functionCall and the attached function code.
        /// the matching of the type of each parameter will be checked later at the execution stage.
        /// </summary>
        /// <param name="functionCallUsed"></param>
        /// <param name="functionToCall"></param>
        /// <returns></returns>
        private bool CheckParamsCountMatching(ExprFunctionCallUsed functionCallUsed, FunctionToCallMapper functionToCall)
        {
            // the function code has any parameter
            if (functionToCall.Param1Type == DataType.NotDefined)
            {
                if (functionCallUsed.ParameterCount != 0)
                {
                    // error, the parameter count mismatch between the function call and the function code
                    _expressionData.ExprExecResult.AddErrorExec(ErrorCode.FunctionCallParamCountWrong, "FunctionCallName", functionCallUsed.Name);
                    return(false);
                }
                // ok, the parameter count match
                return(true);
            }

            // one parameter at least is present
            if (functionToCall.Param2Type == DataType.NotDefined)
            {
                if (functionCallUsed.ParameterCount != 1)
                {
                    // error, the parameter count mismatch between the function call and the function code
                    _expressionData.ExprExecResult.AddErrorExec(ErrorCode.FunctionCallParamCountWrong, "FunctionCallName", functionCallUsed.Name);
                    return(false);
                }
                // ok, the parameter count match
                return(true);
            }

            // one parameter at least is present
            if (functionToCall.Param3Type == DataType.NotDefined)
            {
                if (functionCallUsed.ParameterCount != 2)
                {
                    // error, the parameter count mismatch between the function call and the function code
                    _expressionData.ExprExecResult.AddErrorExec(ErrorCode.FunctionCallParamCountWrong, "FunctionCallName", functionCallUsed.Name);
                    return(false);
                }
                // ok, the parameter count match
                return(true);
            }

            // the function call has three parameters
            if (functionCallUsed.ParameterCount != 3)
            {
                // error, the parameter count mismatch between the function call and the function code
                _expressionData.ExprExecResult.AddErrorExec(ErrorCode.FunctionCallParamCountWrong, "FunctionCallName", functionCallUsed.Name);
                return(false);
            }

            // ok, the parameter count match
            return(true);

            // todo: enlever code de check count param dans la methode ExprExecutorFunctionCallRetBase.CheckParam()
        }
示例#5
0
        /// <summary>
        /// Check one parameter of a function call.
        /// </summary>
        /// <param name="exprExecResult"></param>
        /// <param name="functionToCallMapper"></param>
        /// <param name="listExprExecParam"></param>
        /// <param name="paramNum"></param>
        /// <param name="dataType"></param>
        /// <returns></returns>
        private bool CheckParam(ExecResult exprExecResult, FunctionToCallMapper functionToCallMapper, List <ExpressionExecBase> listExprExecParam, int paramNum, DataType dataType)
        {
            // check param
            //if (dataType == DataType.NotDefined)
            //{
            //    ici();

            //    // any parameter
            //    if (listExprExecParam.Count > paramNum)
            //    {
            //        // error! too many parameters provided
            //        exprExecResult.AddError(ExecErrorCode.ExprFunctionCallParamCountWrong, "ParamExpectedCount", (paramNum).ToString(), "ParamFoundCount", listExprExecParam.Count.ToString());
            //        return false;
            //    }

            //    // the param type is set to NotDefined
            //    return true;
            //}

            //// at least one parameter is expected
            //if (listExprExecParam.Count < paramNum)
            //{
            //    // errror! not enought provided parameters
            //    exprExecResult.AddError(ExecErrorCode.ExprFunctionCallParamCountWrong, "ParamExpectedCount", (paramNum).ToString(), "ParamFoundCount", listExprExecParam.Count.ToString());
            //    return false;
            //}

            if (dataType == DataType.NotDefined)
            {
                return(true);
            }

            // check param, should be a bool
            if (dataType == DataType.Bool)
            {
                // check the type of the param
                ExprExecValueBool exprParamBool;
                if (!GetCheckParamBool(exprExecResult, functionToCallMapper.FunctionCallName, listExprExecParam[paramNum - 1], out exprParamBool))
                {
                    return(false);
                }

                // the param1 is ok
                return(true);
            }

            // check param, should be an int
            if (dataType == DataType.Int)
            {
                // check the type of the param
                ExprExecValueInt exprParamInt;
                if (!GetCheckParamInt(exprExecResult, functionToCallMapper.FunctionCallName, listExprExecParam[paramNum - 1], out exprParamInt))
                {
                    return(false);
                }

                // the param1 is ok
                return(true);
            }

            // string
            if (dataType == DataType.String)
            {
                // check the type of the param
                ExprExecValueString exprParamString;
                if (!GetCheckParamString(exprExecResult, functionToCallMapper.FunctionCallName, listExprExecParam[paramNum - 1], out exprParamString))
                {
                    return(false);
                }

                // the param is ok
                return(true);
            }


            // check param, should be a double
            // check the type of the param
            ExprExecValueDouble exprParamDouble;

            if (!GetCheckParamDouble(exprExecResult, functionToCallMapper.FunctionCallName, listExprExecParam[paramNum - 1], out exprParamDouble))
            {
                return(false);
            }

            // the param is ok
            return(true);
        }