Ejemplo n.º 1
0
 public VariableParameter(string name, string documentation, VariableType variableType, VariableResolveOptions options = null) : base(name, documentation)
 {
     if (variableType == VariableType.ElementReference)
     {
         throw new Exception("Only the variable types Dynamic, Global, and Player is valid.");
     }
     VariableType = variableType;
     Options      = options ?? new VariableResolveOptions();
 }
        public VariableResolve(VariableResolveOptions options, IExpression expression, DocRange expressionRange, FileDiagnostics diagnostics)
        {
            // The expression is a variable.
            if (expression is CallVariableAction)
            {
                // Get the variable being set and the range.
                SetVariable   = (CallVariableAction)expression;
                VariableRange = expressionRange;
            }
            // The expression is an expression tree.
            else if (expression is ExpressionTree tree)
            {
                Tree = tree;
                if (tree.Completed)
                {
                    // If the resulting expression in the tree is not a variable.
                    if (tree.Result is CallVariableAction == false)
                    {
                        NotAVariableRange = tree.ExprContextTree.Last().GetRange();
                    }
                    else
                    {
                        // Get the variable and the range.
                        SetVariable   = (CallVariableAction)tree.Result;
                        VariableRange = tree.ExprContextTree.Last().GetRange();
                    }
                }
            }
            // The expression is not a variable.
            else if (expression != null)
            {
                NotAVariableRange = expressionRange;
            }

            // NotAVariableRange will not be null if the resulting expression is a variable.
            if (NotAVariableRange != null)
            {
                diagnostics.Error("Expected a variable.", NotAVariableRange);
            }

            // Make sure the variable can be set to.
            if (SetVariable != null)
            {
                // Check if the variable is settable.
                if (options.ShouldBeSettable && !SetVariable.Calling.Settable())
                {
                    diagnostics.Error($"The variable '{SetVariable.Calling.Name}' cannot be set to.", VariableRange);
                }

                // Check if the variable is a whole workshop variable.
                if (options.FullVariable)
                {
                    Var asVar = SetVariable.Calling as Var;
                    if (asVar == null || asVar.StoreType != StoreType.FullVariable)
                    {
                        diagnostics.Error($"The variable '{SetVariable.Calling.Name}' cannot be indexed.", VariableRange);
                    }
                }

                // Check for indexers.
                if (!options.CanBeIndexed && SetVariable.Index.Length != 0)
                {
                    diagnostics.Error($"The variable '{SetVariable.Calling.Name}' cannot be indexed.", VariableRange);
                }
            }

            DoesResolveToVariable = SetVariable != null;
        }
Ejemplo n.º 3
0
        public VariableResolve(ParseInfo parseInfo, VariableResolveOptions options, IExpression expression, DocRange expressionRange, IVariableResolveErrorHandler errorHandler)
        {
            bool treeSettable = true;

            // The expression is a variable.
            if (expression is CallVariableAction)
            {
                // Get the variable being set and the range.
                SetVariable   = (CallVariableAction)expression;
                VariableRange = expressionRange;
            }
            // The expression is an expression tree.
            else if (expression is ExpressionTree tree)
            {
                Tree = tree;
                if (tree.Completed)
                {
                    // If the resulting expression in the tree is not a variable.
                    if (tree.Result is CallVariableAction == false)
                    {
                        NotAVariableRange = tree.ExprContextTree.Last().GetRange();
                    }
                    else
                    {
                        // Get the variable and the range.
                        SetVariable   = (CallVariableAction)tree.Result;
                        VariableRange = tree.ExprContextTree.Last().GetRange();
                        treeSettable  = tree.TargetCanBeSet();
                    }
                }
            }
            // The expression is not a variable.
            else if (expression != null)
            {
                NotAVariableRange = expressionRange;
            }

            // NotAVariableRange will not be null if the resulting expression is a variable.
            if (NotAVariableRange != null)
            {
                errorHandler.Error("Expected a variable.", NotAVariableRange);
            }

            // Make sure the variable can be set to.
            if (SetVariable != null)
            {
                // Check if the variable is settable.
                if (options.ShouldBeSettable)
                {
                    // The variable can never be set.
                    if (!SetVariable.Calling.Attributes.CanBeSet)
                    {
                        errorHandler.Error($"The variable '{SetVariable.Calling.Name}' cannot be set", VariableRange);
                    }

                    // The variable is normally settable, but not in the current context.
                    else if (!treeSettable || (parseInfo.ContextualVariableModifiers != null && !parseInfo.ContextualVariableModifiers.IsSettable(SetVariable.Calling)))
                    {
                        errorHandler.Error($"The variable '{SetVariable.Calling.Name}' cannot be set in the current context", VariableRange);
                    }
                }

                // Check if the variable is a whole workshop variable.
                else if ((options.FullVariable && SetVariable.Calling.Attributes.StoreType != StoreType.FullVariable) || (!options.CanBeIndexed && SetVariable.Index.Length != 0))
                {
                    errorHandler.Error($"The variable '{SetVariable.Calling.Name}' cannot be indexed", VariableRange);
                }
            }

            DoesResolveToVariable = SetVariable != null;
        }
Ejemplo n.º 4
0
 public VariableParameter(string name, string documentation, VariableResolveOptions options = null) : base(name, documentation)
 {
     VariableType = VariableType.Dynamic;
     Options      = options ?? new VariableResolveOptions();
 }
Ejemplo n.º 5
0
 public VariableResolve(ParseInfo parseInfo, VariableResolveOptions options, IExpression expression, DocRange expressionRange)
     : this(parseInfo, options, expression, expressionRange, new VariableResolveErrorHandler(parseInfo.Script.Diagnostics))
 {
 }