public void Accept()
        {
            // Callable
            Variable.Call(_parseInfo, CallRange);

            // 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 (Variable.Provider.VariableType == VariableType.Player)
            {
                // No source expression, Event Player is used by default.
                if (_parseInfo.SourceExpression == null)
                {
                    DefaultEventPlayerRestrictedCall();
                }
                else // There is a source expression.
                {
                    _parseInfo.SourceExpression.OnResolve(expr => {
                        // An expression that is not targettable.
                        if (expr is RootAction)
                        {
                            DefaultEventPlayerRestrictedCall();
                        }
                    });
                }
            }

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

            VariableCall.Accept();
        }
Esempio n. 2
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);
        }