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));
        }
Exemple #2
0
        public static ParameterParseResult GetParameters(ParseInfo parseInfo, Scope methodScope, List <VariableDeclaration> context, bool subroutineParameter)
        {
            if (context == null)
            {
                return(new ParameterParseResult(new CodeParameter[0], new Var[0]));
            }

            var parameters = new CodeParameter[context.Count];
            var vars       = new Var[parameters.Length];

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

                CodeParameter parameter = new CodeParameter(context[i].Identifier.GetText());

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

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

                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));
        }