コード例 #1
0
        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));
        }
コード例 #2
0
ファイル: SourceMapper.cs プロジェクト: gpduck/ScriptMap
    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));
    }
コード例 #3
0
        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);
        }
コード例 #4
0
        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));
        }
コード例 #5
0
 public override AstVisitAction VisitIndexExpression(IndexExpressionAst ast)
 {
     return(Check(ast));
 }
コード例 #6
0
ファイル: AstVisitor.cs プロジェクト: JamesTryand/Pash2
 public virtual AstVisitAction VisitIndexExpression(IndexExpressionAst indexExpressionAst)
 {
     return AstVisitAction.Continue;
 }
コード例 #7
0
 /// <summary/>
 public virtual object VisitIndexExpression(IndexExpressionAst indexExpressionAst)
 {
     return _decorated.VisitIndexExpression(indexExpressionAst);
 }
コード例 #8
0
ファイル: VariableAnalysis.cs プロジェクト: nickchal/pash
 public object VisitIndexExpression(IndexExpressionAst indexExpressionAst)
 {
     indexExpressionAst.Target.Accept(this);
     indexExpressionAst.Index.Accept(this);
     return null;
 }
コード例 #9
0
ファイル: AstVisitor.cs プロジェクト: 40a/PowerShell
 public override AstVisitAction VisitIndexExpression(IndexExpressionAst ast) { return CheckParent(ast); }
コード例 #10
0
ファイル: ExecutionVisitor.cs プロジェクト: Ventero/Pash
 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);
     }
 }
コード例 #11
0
 /// <summary/>
 public virtual AstVisitAction VisitIndexExpression(IndexExpressionAst indexExpressionAst) => DefaultVisit(indexExpressionAst);
コード例 #12
0
ファイル: Compiler.cs プロジェクト: nickchal/pash
 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));
 }
コード例 #13
0
ファイル: SettableIndexExpression.cs プロジェクト: mauve/Pash
 internal SettableIndexExpression(IndexExpressionAst expressionAst, ExecutionVisitor currentExecution)
     : base (currentExecution)
 {
     _expressionAst = expressionAst;
 }
コード例 #14
0
ファイル: AstVisitor.cs プロジェクト: 40a/PowerShell
 /// <summary/>
 public virtual object VisitIndexExpression(IndexExpressionAst indexExpressionAst) { return null; }
コード例 #15
0
 public object VisitIndexExpression(IndexExpressionAst indexExpressionAst)
 {
     return((bool)indexExpressionAst.Index.Accept(this) && (bool)indexExpressionAst.Target.Accept(this));
 }
コード例 #16
0
ファイル: ExecutionVisitor.cs プロジェクト: Ventero/Pash
        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;
        }
コード例 #17
0
 public object VisitIndexExpression(IndexExpressionAst indexExpressionAst)
 {
     return(false);
 }
コード例 #18
0
ファイル: SemanticChecks.cs プロジェクト: dfinke/powershell
        public override AstVisitAction VisitIndexExpression(IndexExpressionAst indexExpressionAst)
        {
            // Array references are never allowed.  They could turn into function calls.
            ReportError(indexExpressionAst, () => ParserStrings.ArrayReferenceNotSupportedInDataSection);

            return AstVisitAction.Continue;
        }
コード例 #19
0
 public override AstVisitAction VisitIndexExpression(IndexExpressionAst indexExpressionAst)
 {
     this.ReportError(indexExpressionAst, () => ParserStrings.ArrayReferenceNotSupportedInDataSection, new object[0]);
     return AstVisitAction.Continue;
 }
コード例 #20
0
 public object VisitIndexExpression(IndexExpressionAst indexExpressionAst) { throw new UnexpectedElementException(); }
コード例 #21
0
        /// <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;
        }
コード例 #22
0
 public override AstVisitAction VisitIndexExpression(IndexExpressionAst indexExpressionAst)
 {
     this.ReportError(indexExpressionAst, () => ParserStrings.ArrayReferenceNotSupportedInDataSection, new object[0]);
     return(AstVisitAction.Continue);
 }
コード例 #23
0
ファイル: ExecutionVisitor.cs プロジェクト: mauve/Pash
 public override AstVisitAction VisitIndexExpression(IndexExpressionAst indexExpressionAst)
 {
     _pipelineCommandRuntime.WriteObject(new SettableIndexExpression(indexExpressionAst, this).GetValue(), false);
     return AstVisitAction.SkipChildren;
 }
コード例 #24
0
ファイル: AstSearcher.cs プロジェクト: nickchal/pash
 public override AstVisitAction VisitIndexExpression(IndexExpressionAst ast)
 {
     return this.Check(ast);
 }
コード例 #25
0
ファイル: ExecutionVisitor.cs プロジェクト: JayBazuzi/Pash
        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;
        }
コード例 #26
0
ファイル: SafeExprEvaluator.cs プロジェクト: nickchal/pash
 public object VisitIndexExpression(IndexExpressionAst indexExpressionAst)
 {
     return (!((bool) indexExpressionAst.Target.Accept(this)) ? ((object) 0) : ((object) ((bool) indexExpressionAst.Index.Accept(this))));
 }
コード例 #27
0
 public object VisitIndexExpression(IndexExpressionAst indexExpressionAst)
 {
     indexExpressionAst.Target.Accept(this);
     indexExpressionAst.Index.Accept(this);
     return(null);
 }
コード例 #28
0
ファイル: ConstantValues.cs プロジェクト: 40a/PowerShell
 public object VisitIndexExpression(IndexExpressionAst indexExpressionAst) { return AutomationNull.Value; }
コード例 #29
0
 /// <summary/>
 public virtual object VisitIndexExpression(IndexExpressionAst indexExpressionAst)
 {
     return(null);
 }
コード例 #30
0
ファイル: SafeValues.cs プロジェクト: 40a/PowerShell
 public object VisitIndexExpression(IndexExpressionAst indexExpressionAst)
 {
     return (bool)indexExpressionAst.Index.Accept(this) && (bool)indexExpressionAst.Target.Accept(this);
 }
コード例 #31
0
 public object VisitIndexExpression(IndexExpressionAst indexExpressionAst)
 {
     return false;
 }
コード例 #32
0
ファイル: SafeValues.cs プロジェクト: 40a/PowerShell
        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);
        }
コード例 #33
0
 /// <summary/>
 public virtual AstVisitAction VisitIndexExpression(IndexExpressionAst indexExpressionAst)
 {
     return(AstVisitAction.Continue);
 }
コード例 #34
0
ファイル: Compiler.cs プロジェクト: 40a/PowerShell
        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));
        }
コード例 #35
0
 public object VisitIndexExpression(IndexExpressionAst indexExpressionAst)
 {
     return(AutomationNull.Value);
 }
コード例 #36
0
 public object VisitIndexExpression(IndexExpressionAst indexExpressionAst)
 {
     throw new NotImplementedException();
 }