Пример #1
0
        public override ScriptVariableType Process(ScriptParser parser, int level)
        {
            base.Process(parser, level);

            bool hadErrors = false;

            try { LType = LValue.Process(parser, level + 1); }
            catch (ScriptCriticalErrorException) { hadErrors = true; }

            try { RType = RValue.Process(parser, level + 1); }
            catch (ScriptCriticalErrorException) { hadErrors = true; }

            if (hadErrors)
            {
                throw new ScriptCriticalErrorException();                 // we are not going to try the operator because one of nodes had an error
            }
            dynamic a, b, c;

            a = LType.GetSampleValue();
            b = RType.GetSampleValue();
            try {
                c          = ApplyOperator(a, b);
                ResultType = ScriptVariableTypeExtension.GetScriptVariableType(c);
            }
            catch (UserFriendlyException) {
                throw;
            }
            catch {
                parser.Errors.Add(new ErrorInfo(ErrorLevel.CriticalError, ErrorCode.OperatorCannotBeApplied2, this, LType, RType));
                throw new ScriptCriticalErrorException();
            }

            return(ResultType);
        }
Пример #2
0
        public override ScriptVariableType Process(ScriptParser parser, int level)
        {
            base.Process(parser, level);

            ValueType = Value.Process(parser, level + 1);

            dynamic a, b;

            a = ValueType.GetSampleValue();
            try {
                b          = ApplyOperator(ref a);
                ResultType = ScriptVariableTypeExtension.GetScriptVariableType(b);
            }
            catch (UserFriendlyException) {
                throw;
            }
            catch {
                parser.Errors.Add(new ErrorInfo(ErrorLevel.CriticalError, ErrorCode.OperatorCannotBeApplied1, this, ValueType));
                throw new ScriptCriticalErrorException();
            }

            return(ValueType);
        }
Пример #3
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();
        }