/// <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); }