Esempio n. 1
0
        public static ParameterParseResult GetParameters(ParseInfo parseInfo, Scope methodScope, DeltinScriptParser.SetParametersContext context)
        {
            if (context == null)
            {
                return(new ParameterParseResult(new CodeParameter[0], new Var[0]));
            }

            var parameters = new CodeParameter[context.define().Length];
            var vars       = new Var[parameters.Length];

            for (int i = 0; i < context.define().Length; i++)
            {
                var newVar = Var.CreateVarFromContext(VariableDefineType.Parameter, parseInfo, context.define(i));
                newVar.Finalize(methodScope);
                vars[i] = newVar;

                ExpressionOrWorkshopValue initialValue = null;
                if (newVar.InitialValue != null)
                {
                    initialValue = new ExpressionOrWorkshopValue(newVar.InitialValue);
                }

                parameters[i] = new CodeParameter(context.define(i).name.Text, newVar.CodeType, initialValue);
            }

            return(new ParameterParseResult(parameters, vars));
        }
        public static ParameterParseResult GetParameters(ParseInfo parseInfo, Scope methodScope, DeltinScriptParser.SetParametersContext context, bool subroutineParameter)
        {
            if (context == null)
            {
                return(new ParameterParseResult(new CodeParameter[0], new Var[0]));
            }

            var parameters = new CodeParameter[context.define().Length];
            var vars       = new Var[parameters.Length];

            for (int i = 0; i < context.define().Length; i++)
            {
                Var newVar;

                CodeParameter parameter = new CodeParameter(context.define(i).name.Text);

                // Set up the context handler.
                IVarContextHandler contextHandler = new DefineContextHandler(parseInfo.SetRestrictedCallHandler(parameter), context.define(i));

                // Normal parameter
                if (!subroutineParameter)
                {
                    newVar = new ParameterVariable(methodScope, contextHandler, parameter.Invoked);
                }
                // Subroutine parameter.
                else
                {
                    newVar = new SubroutineParameterVariable(methodScope, contextHandler);
                }

                vars[i]        = newVar;
                parameter.Type = newVar.CodeType;

                if (newVar.InitialValue != null)
                {
                    parameter.DefaultValue = new ExpressionOrWorkshopValue(newVar.InitialValue);
                }

                parameters[i] = parameter;
            }

            return(new ParameterParseResult(parameters, vars));
        }