コード例 #1
0
        public override ScriptVariableType Process(ScriptParser parser, int level)
        {
            base.Process(parser, level);

            // check script if it has a function we can execute
            if (parser.GetFunction(Name.Value, out ScriptFunction))
            {
                if (ScriptFunction.Parameters.Count < Parameters.Count)
                {
                    parser.Errors.Add(new ErrorInfo(ErrorLevel.Error, ErrorCode.TooManyParameters, this));
                }
                else
                {
                    ParamDefault = new bool[ScriptFunction.Parameters.Count];

                    for (int i = 0; i < ScriptFunction.Parameters.Count; i++)
                    {
                        if (Parameters.Count <= i || Parameters[i] == null)
                        {
                            if (ScriptFunction.Parameters[i].HasDefaultValue)
                            {
                                ParamDefault[i] = true;
                            }
                            else
                            {
                                parser.Errors.Add(new ErrorInfo(ErrorLevel.Error, ErrorCode.ParameterIsRequired, this, i, Name.Value));
                            }
                        }
                        else
                        {
                            ParamDefault[i] = false;
                            Parameters[i]   = TypeCastExecutionNode.ImplicitCast(parser, level, ScriptFunction.Parameters[i].ParamType, Parameters[i]);
                        }
                    }
                }
                ResultType = (ScriptFunction.ReturnType == ScriptVariableType.Void) ? ScriptVariableType.Undefined : ScriptFunction.ReturnType;

                return(ResultType);
            }

            // check environment if it has a function we can execute
            if (parser.Script.Environment.GetFunction(Name.Value, out EnvironmentFunction))
            {
                ResultType = EnvironmentFunction.ReturnType;

                ParameterInfo[] envFuncParams = EnvironmentFunction.Function.GetParameters();
                FuncParamCount = envFuncParams.Length;
                if (envFuncParams.Length < Parameters.Count)
                {
                    parser.Errors.Add(new ErrorInfo(ErrorLevel.Error, ErrorCode.TooManyParameters, this));
                }
                else
                {
                    for (int i = 1, j = 0; i < envFuncParams.Length; i++, j++)
                    {
                        if (Parameters.Count <= j || Parameters[j] == null)
                        {
                            parser.Errors.Add(new ErrorInfo(ErrorLevel.Error, ErrorCode.ParameterIsRequired, this, j, Name.Value));
                        }
                        else
                        {
                            if (!envFuncParams[i].ParameterType.Equals(typeof(object)))
                            {
                                Parameters[j] = TypeCastExecutionNode.ImplicitCast(parser, level, ScriptVariableTypeExtension.GetScriptVariableTypeFromType(envFuncParams[i].ParameterType), Parameters[j]);
                            }
                            else
                            {
                                Parameters[j].Process(parser, level);
                            }
                        }
                    }
                }

                return(ResultType);
            }

            parser.Errors.Add(new ErrorInfo(ErrorLevel.CriticalError, ErrorCode.FunctionNotFound, this, Name.Value));
            throw new ScriptCriticalErrorException();
        }