public void RestrictedCall(RestrictedCall restrictedCall)
 {
     if (!RestrictedCalls.Contains(restrictedCall.CallType))
     {
         RestrictedCalls.Add(restrictedCall.CallType);
     }
 }
 public void Applied()
 {
     foreach (RestrictedCall restrictedCall in _macroVar.CallInfo.RestrictedCalls)
     {
         _callHandler.RestrictedCall(new RestrictedCall(
                                         restrictedCall.CallType,
                                         _callLocation,
                                         RestrictedCall.Message_Macro(_macroVar.Name, restrictedCall.CallType)
                                         ));
     }
 }
 public void Call(ParseInfo parseInfo, DocRange callRange)
 {
     if (Restricted != null)
     {
         // If there is a restricted call type, add it.
         parseInfo.RestrictedCallHandler.RestrictedCall(new RestrictedCall(
                                                            (RestrictedCallType)Restricted,
                                                            parseInfo.GetLocation(callRange),
                                                            RestrictedCall.Message_Element((RestrictedCallType)Restricted)
                                                            ));
     }
 }
Exemple #4
0
        /// <summary>Gets the restricted calls and recursion from a lambda invocation.</summary>
        public static void LambdaInvokeApply(ParseInfo parseInfo, LambdaAction source, DocRange callRange)
        {
            parseInfo.CurrentCallInfo?.Call(source.RecursiveCallHandler, callRange);

            // Add restricted calls.
            foreach (RestrictedCall call in source.CallInfo.RestrictedCalls)
            {
                parseInfo.RestrictedCallHandler.RestrictedCall(new RestrictedCall(
                                                                   call.CallType,
                                                                   parseInfo.GetLocation(callRange),
                                                                   RestrictedCall.Message_LambdaInvoke(source.GetLabel(false), call.CallType)
                                                                   ));
            }
        }
Exemple #5
0
        public CreateObjectAction(ParseInfo parseInfo, Scope scope, NewExpression context)
        {
            if (!context.Type.Valid)
            {
                CreatingObjectOf = parseInfo.Types.Any();
                return;
            }

            // Get the type. Syntax error if there is no type name.
            CreatingObjectOf = TypeFromContext.GetCodeTypeFromContext(parseInfo, scope, context.Type);

            DocRange nameRange = context.Type.GenericToken.Range;

            // Get the constructor to use.
            OverloadChooser = new OverloadChooser(
                CreatingObjectOf.Constructors.Select(c => new ConstructorOverload(c)).ToArray(),
                parseInfo,
                CreatingObjectOf.ReturningScope(),
                scope,
                nameRange,
                context.Range,
                context.Range,
                new OverloadError("type " + CreatingObjectOf.Name)
                );
            OverloadChooser.Apply(context.Parameters, false, null);

            Constructor = (Constructor)OverloadChooser.Overload;

            if (Constructor != null)
            {
                Constructor.Call(parseInfo, nameRange);
                parseInfo.Script.AddHover(context.Range, Constructor.GetLabel(parseInfo.TranslateInfo, LabelInfo.Hover));

                // Default restricted parameter values.
                OverloadChooser.Match.CheckOptionalsRestrictedCalls(parseInfo, nameRange);

                // Bridge other restricted values.
                if (Constructor.CallInfo != null)
                {
                    RestrictedCall.BridgeMethodCall(parseInfo, Constructor.CallInfo, nameRange, context.Type.GenericToken.Text, Constructor.RestrictedValuesAreFatal);
                }
            }
        }
 ///<summary>Gets the restricted calls from the unfilled optional parameters.</summary>
 public void CheckOptionalsRestrictedCalls(ParseInfo parseInfo, DocRange callRange)
 {
     // Iterate through each parameter.
     for (int i = 0; i < OrderedParameters.Length; i++)
     {
         // Check if the parameter is prefilled, which means the parameter is optional and not set.
         if (OrderedParameters[i].Prefilled)
         {
             // Add the restricted call.
             foreach (RestrictedCallType callType in Option.Parameters[i].RestrictedCalls)
             {
                 parseInfo.RestrictedCallHandler.RestrictedCall(new RestrictedCall(
                                                                    callType,
                                                                    parseInfo.GetLocation(callRange),
                                                                    RestrictedCall.Message_UnsetOptionalParameter(Option.Parameters[i].Name, Option.GetLabel(false), callType)
                                                                    ));
             }
         }
     }
 }
Exemple #7
0
        /// <summary>Gets the restricted calls and recursion from a lambda invocation.</summary>
        public static void LambdaInvokeApply(ParseInfo parseInfo, ILambdaApplier source, DocRange callRange)
        {
            if (!source.ResolvedSource)
            {
                return;
            }

            if (source.RecursiveCallHandler != null)
            {
                parseInfo.CurrentCallInfo.Call(source.RecursiveCallHandler, callRange);
            }

            // Add restricted calls.
            foreach (var callType in source.GetRestrictedCallTypes())
            {
                parseInfo.RestrictedCallHandler.AddRestrictedCall(new RestrictedCall(
                                                                      callType,
                                                                      parseInfo.GetLocation(callRange),
                                                                      RestrictedCall.Message_LambdaInvoke(source.GetLabel(parseInfo.TranslateInfo, LabelInfo.RecursionError), callType)
                                                                      ));
            }
        }
Exemple #8
0
        public void Applied()
        {
            if (UsedAsExpression && !CallingMethod.DoesReturnValue)
            {
                parseInfo.Script.Diagnostics.Error("The chosen overload for " + CallingMethod.Name + " does not return a value.", NameRange);
            }

            // Get optional parameter's restricted calls.
            OverloadChooser.Match?.CheckOptionalsRestrictedCalls(parseInfo, NameRange);

            // Check callinfo :)
            foreach (RestrictedCallType type in ((IApplyBlock)CallingMethod).CallInfo.GetRestrictedCallTypes())
            {
                parseInfo.RestrictedCallHandler.RestrictedCall(new RestrictedCall(type, parseInfo.GetLocation(NameRange), RestrictedCall.Message_FunctionCallsRestricted(CallingMethod.Name, type)));
            }
        }
Exemple #9
0
 protected virtual void EventPlayerRestrictedCall(RestrictedCall restrictedCall) => _parseInfo.RestrictedCallHandler.RestrictedCall(restrictedCall);
Exemple #10
0
        public IExpression Apply(IVariable variable, IExpression[] index, DocRange variableRange)
        {
            // Callable
            if (variable is ICallable callable)
            {
                Call(callable, variableRange);
            }

            // IIndexReferencers are wrapped by CallVariableActions.
            if (variable is IIndexReferencer referencer)
            {
                // If the type of the variable being called is Player, check if the variable is calling Event Player.
                // If the source expression is null, Event Player is used by default.
                // Otherwise, confirm that the source expression is returning the player variable scope.
                if (referencer.VariableType == VariableType.Player)
                {
                    EventPlayerRestrictedCall(new RestrictedCall(RestrictedCallType.EventPlayer, _parseInfo.GetLocation(variableRange), RestrictedCall.Message_EventPlayerDefault(referencer.Name)));
                }

                // If there is a local variable tracker and the variable requires capture.
                if (referencer.RequiresCapture)
                {
                    _parseInfo.LocalVariableAccessed(referencer);
                }

                return(new CallVariableAction(referencer, index));
            }

            // Check value in array.
            if (index != null && index.Length > 0)
            {
                if (!variable.CanBeIndexed)
                {
                    Error("This variable type cannot be indexed.", variableRange);
                }
                else
                {
                    return(new ValueInArrayAction(_parseInfo, (IExpression)variable, index));
                }
            }

            // Function group.
            if (variable is MethodGroup methodGroup)
            {
                return(new CallMethodGroup(_parseInfo, variableRange, methodGroup));
            }

            return((IExpression)variable);
        }
 public void AddRestrictedCall(RestrictedCall restrictedCall) => RestrictedCalls.Add(restrictedCall);
 void DefaultEventPlayerRestrictedCall() => _parseInfo.RestrictedCallHandler.AddRestrictedCall(
     new RestrictedCall(RestrictedCallType.EventPlayer, _parseInfo.GetLocation(CallRange), RestrictedCall.Message_EventPlayerDefault(_name))
     );
Exemple #13
0
        public IInvokeResult Invoke(InvokeData invokeInfo)
        {
            var parseInfo = invokeInfo.ParseInfo;

            if (invokeInfo.Target is CallMethodGroup == false)
            {
                parseInfo.Script.Diagnostics.Error("Method name expected", invokeInfo.TargetRange);
                CallMethodAction.DiscardParameters(parseInfo, invokeInfo.Getter, invokeInfo.Context.Parameters);
                return(null);
            }

            var groupCall = (CallMethodGroup)invokeInfo.Target;
            var group     = groupCall.Group;

            // Make an OverloadChooser to choose an Overload.
            var overloadChooser = new OverloadChooser(
                group.Functions.Select(f => new MethodOverload(f)).ToArray(),
                parseInfo,
                invokeInfo.Scope,
                invokeInfo.Getter,
                invokeInfo.TargetRange,
                invokeInfo.CallRange,
                invokeInfo.FullRange,
                new OverloadError("method '" + group.Name + "'")
                );

            // Apply the parameters.
            overloadChooser.Apply(invokeInfo.Context.Parameters, groupCall.TypeArgs.Length > 0, groupCall.TypeArgs);

            // Get the best function.
            var callingMethod = (IMethod)overloadChooser.Overload;
            var result        = new FunctionInvokeResult(parseInfo, invokeInfo.TargetRange, invokeInfo.UsedAsExpression, callingMethod, overloadChooser.AdditionalData, overloadChooser.ParameterResults, overloadChooser.Match);
            var typeArgLinker = overloadChooser.Match?.TypeArgLinker;

            // CallingMethod may be null if no good functions are found.
            if (callingMethod != null)
            {
                result.ReturnType = callingMethod.CodeType?.GetCodeType(parseInfo.TranslateInfo).GetRealType(typeArgLinker);

                // Do not track if any of the generics are null.
                if (overloadChooser.Match.TypeArgs.All(t => t != null))
                {
                    // Track the generics used in the function.
                    parseInfo.Script.Elements.AddTypeArgCall(new TypeArgCall(callingMethod.MethodInfo.Tracker, overloadChooser.Match.TypeArgs));
                }

                if (callingMethod.Attributes.CallInfo != null)
                {
                    // Restricted calls.
                    RestrictedCall.BridgeMethodCall(parseInfo, callingMethod.Attributes.CallInfo, invokeInfo.TargetRange, callingMethod.Name, overloadChooser.Match.Option.RestrictedValuesAreFatal);

                    // Apply
                    callingMethod.Attributes.CallInfo.OnCompleted.OnReady(result.Apply);
                }
                else
                {
                    result.Apply();
                }

                // Check if the function can be called in parallel.
                if (parseInfo.AsyncInfo != null)
                {
                    if (!callingMethod.Attributes.Parallelable)
                    {
                        parseInfo.AsyncInfo.Reject($"The method '{callingMethod.Name}' cannot be called in parallel");
                    }
                    else
                    {
                        parseInfo.AsyncInfo.Accept();
                    }
                }

                // Add the function hover.
                parseInfo.Script.AddHover(invokeInfo.Context.Range, callingMethod.GetLabel(parseInfo.TranslateInfo, new LabelInfo()
                {
                    IncludeDocumentation  = true,
                    IncludeParameterNames = true,
                    IncludeParameterTypes = true,
                    IncludeReturnType     = true,
                    AnonymousLabelInfo    = new AnonymousLabelInfo(typeArgLinker)
                }));
            }

            return(result);
        }
        public void Applied()
        {
            if (_usedAsExpression && !Function.DoesReturnValue)
            {
                _parseInfo.Script.Diagnostics.Error("The chosen overload for " + Function.Name + " does not return a value.", _targetRange);
            }

            // Get optional parameter's restricted calls.
            _match?.CheckOptionalsRestrictedCalls(_parseInfo, _targetRange);

            // Check callinfo :)
            foreach (RestrictedCallType type in ((IApplyBlock)Function).CallInfo.GetRestrictedCallTypes())
            {
                _parseInfo.RestrictedCallHandler.RestrictedCall(new RestrictedCall(type, _parseInfo.GetLocation(_targetRange), RestrictedCall.Message_FunctionCallsRestricted(Function.Name, type)));
            }
        }