Esempio n. 1
0
        /// <summary>Gets a variable or type from a VariableContext.</summary>
        /// <param name="scope">The scope the variable was called in.</param>
        /// <param name="getter">The getter scope.</param>
        /// <param name="variableContext">The context of the variable.</param>
        /// <param name="selfContained">Wether the variable was not called in an expression tree.</param>
        /// <returns>An IExpression created from the context.</returns>
        public IExpression GetVariable(Scope scope, Scope getter, Identifier variableContext, bool selfContained)
        {
            // Get the variable name and range.
            string   variableName  = variableContext.Token.Text;
            DocRange variableRange = variableContext.Token.Range;

            // Get the variable.
            IVariable element = scope.GetVariable(variableName, getter, Script.Diagnostics, variableRange, ResolveInvokeInfo != null);

            if (element == null)
            {
                return(new MissingVariable(variableName));
            }

            // Additional syntax checking.
            var expression = new VariableApply(this).Apply(element, ExpressionIndexArray(getter, variableContext.Index), variableRange);

            // Accept the method group.
            if (expression is CallMethodGroup methodGroup)
            {
                methodGroup.Accept();
            }

            return(expression);
        }
        /// <summary>Gets a variable or type from a VariableContext.</summary>
        /// <param name="scope">The scope the variable was called in.</param>
        /// <param name="getter">The getter scope.</param>
        /// <param name="variableContext">The context of the variable.</param>
        /// <param name="selfContained">Whether the variable was not called in an expression tree.</param>
        /// <returns>An IExpression created from the context.</returns>
        public IExpression GetVariable(Scope scope, Scope getter, Identifier variableContext)
        {
            if (!variableContext.Token)
            {
                return(new MissingElementAction(TranslateInfo));
            }

            var name  = variableContext.Token.Text;
            var range = variableContext.Token.Range;

            // Get the variable.
            var variable = scope.GetAllVariables(name, ResolveInvokeInfo != null).FirstOrDefault();

            // Variable does not exist.
            if (variable == null)
            {
                Script.Diagnostics.Error(string.Format("The variable {0} does not exist in the {1}.", name, scope.ErrorName), range);
                variable = new MissingVariable(TranslateInfo, name);
            }

            // Check the access level.
            if (!SemanticsHelper.AccessLevelMatches(variable.AccessLevel, variable.Attributes.ContainingType, ThisType))
            {
                Script.Diagnostics.Error(string.Format("'{0}' is inaccessable due to its access level.", name), range);
            }

            var apply = new VariableApply(this, scope, getter, variable, variableContext);

            apply.Accept();
            return(apply.VariableCall);
        }