protected void SetupParameters(DeltinScriptParser.SetParametersContext context) { var parameterInfo = CodeParameter.GetParameters(parseInfo, methodScope, context); Parameters = parameterInfo.Parameters; ParameterVars = parameterInfo.Variables; }
public Constructor(CodeType type, LanguageServer.Location definedAt, AccessLevel accessLevel) { Type = type; DefinedAt = definedAt; AccessLevel = accessLevel; Parameters = new CodeParameter[0]; }
protected void SetupParameters(List <VariableDeclaration> context, bool subroutineParameter) { var parameterInfo = CodeParameter.GetParameters(parseInfo, methodScope, context, subroutineParameter); Parameters = parameterInfo.Parameters; ParameterVars = parameterInfo.Variables; }
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 void SetupParameters() { var parameterInfo = CodeParameter.GetParameters(parseInfo, ConstructorScope, context.setParameters(), false); Parameters = parameterInfo.Parameters; ParameterVars = parameterInfo.Variables; parseInfo.Script.AddHover(DocRange.GetRange(context.name), GetLabel(true)); }
public void SetupParameters() { var parameterInfo = CodeParameter.GetParameters(parseInfo, ConstructorScope, context.Parameters, false); Parameters = parameterInfo.Parameters; ParameterVars = parameterInfo.Variables; parseInfo.Script.AddHover(context.LocationToken.Range, GetLabel(true)); }
public void SetupBlock() { var parameterInfo = CodeParameter.GetParameters(parseInfo, ConstructorScope, context.setParameters()); Parameters = parameterInfo.Parameters; ParameterVars = parameterInfo.Variables; Block = new BlockAction(parseInfo.SetCallInfo(CallInfo), ConstructorScope, context.block()); parseInfo.Script.AddHover(DocRange.GetRange(context.name), GetLabel(true)); }
public MarkupBuilder GetLabel(DeltinScript deltinScript, LabelInfo labelInfo) { var builder = new MarkupBuilder().StartCodeLine().Add("new " + Type.GetName()); builder.Add(CodeParameter.GetLabels(deltinScript, labelInfo.AnonymousLabelInfo, Parameters)).EndCodeLine(); if (labelInfo.IncludeDocumentation) { builder.NewSection().Add(Documentation); } return(builder); }
private IExpression MissingParameter(CodeParameter parameter) { if (parameter.DefaultValue != null) { return(parameter.DefaultValue); } // Parameter is missing. parseInfo.Script.Diagnostics.Error( string.Format(ErrorMessages.MissingParameter, parameter.Name), genericErrorRange ); return(null); }
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)); }
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)); }
public DefinedMethodInstance(DefinedMethodProvider provider, InstanceAnonymousTypeLinker instanceInfo, CodeType definedIn) { Provider = provider; CodeType = provider.ReturnType?.GetRealType(instanceInfo); InstanceInfo = instanceInfo; DefinedInType = Attributes.ContainingType = definedIn; Attributes.Parallelable = provider.IsSubroutine; Attributes.Recursive = provider.Recursive; Parameters = new CodeParameter[provider.ParameterProviders.Length]; ParameterVars = new IVariableInstance[Parameters.Length]; for (int i = 0; i < Parameters.Length; i++) { var parameterInstance = provider.ParameterProviders[i].GetInstance(instanceInfo); ParameterVars[i] = parameterInstance.Variable; Parameters[i] = parameterInstance.Parameter; } Attributes.CallInfo = Provider.CallInfo; Attributes.GetRestrictedCallTypes = Provider.CallInfo; }
// String Format function FuncMethod FormatFunction(ITypeSupplier supplier) => new FuncMethodBuilder() { Name = "Format", Documentation = "Inserts an array of objects into a string.", ReturnType = supplier.String(), Parameters = new CodeParameter[] { new StringFormatArrayParameter(supplier) }, OnCall = (parseInfo, range) => { // Resolve the source usage with StringFormat. // This will tell the source string to not add an error for incorrect formats. parseInfo.SourceUsageResolver?.Resolve(UsageType.StringFormat); // The source string will be resolved after this function returns. var sourceResolver = new StringFormatSourceResolver(); parseInfo.SourceExpression.OnResolve(expr => ConstantExpressionResolver.Resolve(expr, expr => { // Make sure the resolved source expression is a string. if (expr is StringAction stringAction) { // Resolve the sourceResolver with the obtained string. sourceResolver.ResolveString(stringAction); } else // Expression is not a constant string, add an error. { parseInfo.Script.Diagnostics.Error("Source expression must be a string constant", range); } })); return(sourceResolver); }, Action = (actionSet, methodCall) => { // This will get the source resolver instance that was initialized above. var sourceResolver = (StringFormatSourceResolver)methodCall.AdditionalData; // Create and return the string. return(sourceResolver.ParseString(actionSet)); } }; }
public bool ParameterOrdered(CodeParameter parameter) => !Picky || parameter.Name == Name;
public ParameterInstance(CodeParameter parameter, IVariableInstance variableInstance) { Parameter = parameter; Variable = variableInstance; }