private ExpressionAst CheckUsingExpression(ExpressionAst exprAst) { RuntimeHelpers.EnsureSufficientExecutionStack(); if (exprAst is VariableExpressionAst) { return(null); } MemberExpressionAst ast = exprAst as MemberExpressionAst; if (((ast != null) && !(ast is InvokeMemberExpressionAst)) && (ast.Member is StringConstantExpressionAst)) { return(this.CheckUsingExpression(ast.Expression)); } IndexExpressionAst ast2 = exprAst as IndexExpressionAst; if (ast2 == null) { return(exprAst); } if (!this.IsValidAttributeArgument(ast2.Index)) { return(ast2.Index); } return(this.CheckUsingExpression(ast2.Target)); }
public System.Object VisitIndexExpression(System.Management.Automation.Language.IndexExpressionAst indexExpressionAst) { IScriptExtent mappedExtent = MapExtent(indexExpressionAst.Extent); ExpressionAst mappedTarget = _VisitExpression(indexExpressionAst.Target); ExpressionAst mappedIndex = _VisitExpression(indexExpressionAst.Index); return(new IndexExpressionAst(mappedExtent, mappedTarget, mappedIndex)); }
public object VisitIndexExpression(IndexExpressionAst indexExpressionAst) { // Get the value of the index and value and call the compiler var index = indexExpressionAst.Index.Accept(this); var target = indexExpressionAst.Target.Accept(this); if (index == null || target == null) { throw new ArgumentNullException("indexExpressionAst"); } return GetIndexedValueFromTarget(target, index); }
private static VariableExpressionAst ExtractUsingVariableImpl(ExpressionAst expression) { VariableExpressionAst subExpression; UsingExpressionAst ast = expression as UsingExpressionAst; if (ast != null) { subExpression = ast.SubExpression as VariableExpressionAst; if (subExpression != null) { return(subExpression); } return(ExtractUsingVariableImpl(ast.SubExpression)); } IndexExpressionAst ast3 = expression as IndexExpressionAst; if (ast3 != null) { subExpression = ast3.Target as VariableExpressionAst; if (subExpression != null) { return(subExpression); } return(ExtractUsingVariableImpl(ast3.Target)); } MemberExpressionAst ast4 = expression as MemberExpressionAst; if (ast4 == null) { return(null); } subExpression = ast4.Expression as VariableExpressionAst; if (subExpression != null) { return(subExpression); } return(ExtractUsingVariableImpl(ast4.Expression)); }
public override AstVisitAction VisitIndexExpression(IndexExpressionAst ast) { return(Check(ast)); }
public virtual AstVisitAction VisitIndexExpression(IndexExpressionAst indexExpressionAst) { return AstVisitAction.Continue; }
/// <summary/> public virtual object VisitIndexExpression(IndexExpressionAst indexExpressionAst) { return _decorated.VisitIndexExpression(indexExpressionAst); }
public object VisitIndexExpression(IndexExpressionAst indexExpressionAst) { indexExpressionAst.Target.Accept(this); indexExpressionAst.Index.Accept(this); return null; }
public override AstVisitAction VisitIndexExpression(IndexExpressionAst ast) { return CheckParent(ast); }
private void SetIndexExpressionValue(IndexExpressionAst indexExpressionAst, object value) { var target = PSObject.Unwrap(EvaluateAst(indexExpressionAst.Target)); var index = PSObject.Unwrap(EvaluateAst(indexExpressionAst.Index, false)); var arrayTarget = target as Array; if (arrayTarget != null && arrayTarget.Rank > 1) { var rawIndices = (int[])LanguagePrimitives.ConvertTo(index, typeof(int[])); var indices = ConvertNegativeIndicesForMultidimensionalArray(arrayTarget, rawIndices); var convertedValue = LanguagePrimitives.ConvertTo(value, arrayTarget.GetType().GetElementType()); arrayTarget.SetValue(convertedValue, indices); return; } // we don't support assignment to slices (, yet?), so throw an error if (index is Array && ((Array)index).Length > 1) { throw new PSInvalidOperationException("Assignment to slices is not supported"); } // otherwise do assignments var iListTarget = target as IList; if (iListTarget != null) // covers also arrays { var intIdx = (int)LanguagePrimitives.ConvertTo(index, typeof(int)); intIdx = intIdx < 0 ? intIdx + iListTarget.Count : intIdx; iListTarget[intIdx] = value; } else if (target is IDictionary) { ((IDictionary)target)[index] = value; } else { var msg = String.Format("Cannot set index for type '{0}'", target.GetType().FullName); throw new PSInvalidOperationException(msg); } }
/// <summary/> public virtual AstVisitAction VisitIndexExpression(IndexExpressionAst indexExpressionAst) => DefaultVisit(indexExpressionAst);
public object VisitIndexExpression(IndexExpressionAst indexExpressionAst) { Expression element = this.CompileExpressionOperand(indexExpressionAst.Target); ExpressionAst index = indexExpressionAst.Index; ArrayLiteralAst ast2 = index as ArrayLiteralAst; PSMethodInvocationConstraints constraints = CombineTypeConstraintForMethodResolution(GetTypeConstraintForMethodResolution(indexExpressionAst.Target), GetTypeConstraintForMethodResolution(index)); if ((ast2 != null) && (ast2.Elements.Count > 1)) { return Expression.Dynamic(PSGetIndexBinder.Get(ast2.Elements.Count, constraints, true), typeof(object), ast2.Elements.Select<ExpressionAst, Expression>(new Func<ExpressionAst, Expression>(this.CompileExpressionOperand)).Prepend<Expression>(element)); } return Expression.Dynamic(PSGetIndexBinder.Get(1, constraints, true), typeof(object), element, this.CompileExpressionOperand(index)); }
internal SettableIndexExpression(IndexExpressionAst expressionAst, ExecutionVisitor currentExecution) : base (currentExecution) { _expressionAst = expressionAst; }
/// <summary/> public virtual object VisitIndexExpression(IndexExpressionAst indexExpressionAst) { return null; }
public object VisitIndexExpression(IndexExpressionAst indexExpressionAst) { return((bool)indexExpressionAst.Index.Accept(this) && (bool)indexExpressionAst.Target.Accept(this)); }
public override AstVisitAction VisitIndexExpression(IndexExpressionAst indexExpressionAst) { var targetValue = PSObject.Unwrap(EvaluateAst(indexExpressionAst.Target, true)); object index = PSObject.Unwrap(EvaluateAst(indexExpressionAst.Index)); if (targetValue is PSObject) targetValue = ((PSObject)targetValue).BaseObject; // Check dicts/hashtables first var dictTarget = targetValue as IDictionary; if (dictTarget != null) { var idxobjects = index is object[] ? (object[])index : new object[] { index }; foreach (var idxobj in idxobjects) { var res = dictTarget[PSObject.Unwrap(idxobj)]; _pipelineCommandRuntime.WriteObject(res); } return AstVisitAction.SkipChildren; } // otherwise we need int indexing var indices = (int[]) LanguagePrimitives.ConvertTo(index, typeof(int[])); // check for real multidimensional array access first var arrayTarget = targetValue as Array; if (arrayTarget != null && arrayTarget.Rank > 1) { int[] convIndices = ConvertNegativeIndicesForMultidimensionalArray(arrayTarget, indices); object arrayValue = null; try { arrayValue = arrayTarget.GetValue(convIndices); } catch (IndexOutOfRangeException) // just write nothing to pipeline { } this._pipelineCommandRuntime.WriteObject(arrayValue); return AstVisitAction.SkipChildren; } // if we have a string, we need to access it as an char[] if (targetValue is string) { targetValue = ((string)targetValue).ToCharArray(); } // now we can access arrays, list, and string (charArrays) all the same by using the IList interface var iListTarget = targetValue as IList; if (iListTarget == null) { var msg = String.Format("Cannot index an object of type '{0}'.", targetValue.GetType().FullName); throw new PSInvalidOperationException(msg); } var numItems = iListTarget.Count; // now get all elements from the index list bool writtenFromList = false; foreach (int curIdx in indices) { // support negative indices var idx = curIdx < 0 ? curIdx + numItems : curIdx; // check if it's a valid index, otherwise ignore if (idx >= 0 && idx < numItems) { _pipelineCommandRuntime.WriteObject(iListTarget[idx]); writtenFromList = true; } } if (!writtenFromList) { _pipelineCommandRuntime.WriteObject(null); } return AstVisitAction.SkipChildren; }
public object VisitIndexExpression(IndexExpressionAst indexExpressionAst) { return(false); }
public override AstVisitAction VisitIndexExpression(IndexExpressionAst indexExpressionAst) { // Array references are never allowed. They could turn into function calls. ReportError(indexExpressionAst, () => ParserStrings.ArrayReferenceNotSupportedInDataSection); return AstVisitAction.Continue; }
public override AstVisitAction VisitIndexExpression(IndexExpressionAst indexExpressionAst) { this.ReportError(indexExpressionAst, () => ParserStrings.ArrayReferenceNotSupportedInDataSection, new object[0]); return AstVisitAction.Continue; }
public object VisitIndexExpression(IndexExpressionAst indexExpressionAst) { throw new UnexpectedElementException(); }
/// <summary> /// Visit Index Expression /// </summary> /// <param name="indexExpressionAst"></param> /// <returns></returns> public object VisitIndexExpression(IndexExpressionAst indexExpressionAst) { if (indexExpressionAst == null) return null; indexExpressionAst.Target.Visit(this.Decorator); indexExpressionAst.Index.Visit(this.Decorator); return null; }
public override AstVisitAction VisitIndexExpression(IndexExpressionAst indexExpressionAst) { this.ReportError(indexExpressionAst, () => ParserStrings.ArrayReferenceNotSupportedInDataSection, new object[0]); return(AstVisitAction.Continue); }
public override AstVisitAction VisitIndexExpression(IndexExpressionAst indexExpressionAst) { _pipelineCommandRuntime.WriteObject(new SettableIndexExpression(indexExpressionAst, this).GetValue(), false); return AstVisitAction.SkipChildren; }
public override AstVisitAction VisitIndexExpression(IndexExpressionAst ast) { return this.Check(ast); }
public override AstVisitAction VisitIndexExpression(IndexExpressionAst indexExpressionAst) { var targetValue = EvaluateAst(indexExpressionAst.Target); int index = (int)EvaluateAst(indexExpressionAst.Index); var stringTargetValue = targetValue as string; if (stringTargetValue != null) { var result = stringTargetValue[index]; this._pipelineCommandRuntime.WriteObject(result); } else if (targetValue is IList) { var result = (targetValue as IList)[index]; this._pipelineCommandRuntime.WriteObject(result); } else throw new NotImplementedException(indexExpressionAst.ToString() + " " + targetValue.GetType()); return AstVisitAction.SkipChildren; }
public object VisitIndexExpression(IndexExpressionAst indexExpressionAst) { return (!((bool) indexExpressionAst.Target.Accept(this)) ? ((object) 0) : ((object) ((bool) indexExpressionAst.Index.Accept(this)))); }
public object VisitIndexExpression(IndexExpressionAst indexExpressionAst) { indexExpressionAst.Target.Accept(this); indexExpressionAst.Index.Accept(this); return(null); }
public object VisitIndexExpression(IndexExpressionAst indexExpressionAst) { return AutomationNull.Value; }
/// <summary/> public virtual object VisitIndexExpression(IndexExpressionAst indexExpressionAst) { return(null); }
public object VisitIndexExpression(IndexExpressionAst indexExpressionAst) { return (bool)indexExpressionAst.Index.Accept(this) && (bool)indexExpressionAst.Target.Accept(this); }
public object VisitIndexExpression(IndexExpressionAst indexExpressionAst) { return false; }
/// <summary/> public virtual AstVisitAction VisitIndexExpression(IndexExpressionAst indexExpressionAst) { return(AstVisitAction.Continue); }
public object VisitIndexExpression(IndexExpressionAst indexExpressionAst) { var targetExpr = CompileExpressionOperand(indexExpressionAst.Target); var index = indexExpressionAst.Index; var arrayLiteral = (index as ArrayLiteralAst); var constraints = CombineTypeConstraintForMethodResolution(GetTypeConstraintForMethodResolution(indexExpressionAst.Target), GetTypeConstraintForMethodResolution(index)); // An array literal is either: // $x[1,2] // or // $x[,1] // In the former case, the user is requesting an array slice. In the latter case, they index expression is likely // an array (dynamically determined) and they don't want an array slice, they want to use the array as the index // expression. if (arrayLiteral != null && arrayLiteral.Elements.Count > 1) { return DynamicExpression.Dynamic(PSGetIndexBinder.Get(arrayLiteral.Elements.Count, constraints), typeof(object), arrayLiteral.Elements.Select(CompileExpressionOperand).Prepend(targetExpr)); } return DynamicExpression.Dynamic(PSGetIndexBinder.Get(1, constraints), typeof(object), targetExpr, CompileExpressionOperand(index)); }
public object VisitIndexExpression(IndexExpressionAst indexExpressionAst) { return(AutomationNull.Value); }
public object VisitIndexExpression(IndexExpressionAst indexExpressionAst) { throw new NotImplementedException(); }