示例#1
0
 public Expression GetValue(Compiler compiler, List<Expression> exprs, List<ParameterExpression> temps)
 {
     Expression right = compiler.Compile(this.IndexExpressionAst.Target);
     this._targetExprTemp = Expression.Variable(right.Type);
     temps.Add(this._targetExprTemp);
     exprs.Add(Expression.Assign(this._targetExprTemp, right));
     ExpressionAst index = this.IndexExpressionAst.Index;
     ArrayLiteralAst ast2 = index as ArrayLiteralAst;
     PSMethodInvocationConstraints invocationConstraints = this.GetInvocationConstraints();
     if (ast2 != null)
     {
         return Expression.Dynamic(PSGetIndexBinder.Get(ast2.Elements.Count, invocationConstraints, true), typeof(object), ast2.Elements.Select<ExpressionAst, Expression>(new Func<ExpressionAst, Expression>(compiler.Compile)).Prepend<Expression>(this._targetExprTemp));
     }
     Expression expression3 = compiler.Compile(index);
     this._indexExprTemp = Expression.Variable(expression3.Type);
     temps.Add(this._indexExprTemp);
     exprs.Add(Expression.Assign(this._indexExprTemp, expression3));
     return Expression.Dynamic(PSGetIndexBinder.Get(1, invocationConstraints, true), typeof(object), this._targetExprTemp, this._indexExprTemp);
 }
示例#2
0
 public Expression GetValue(Compiler compiler, List<Expression> exprs, List<ParameterExpression> temps)
 {
     Expression targetExpr = this.GetTargetExpr(compiler);
     ParameterExpression item = Expression.Parameter(targetExpr.Type);
     temps.Add(item);
     this.CachedTarget = item;
     exprs.Add(Expression.Assign(item, targetExpr));
     StringConstantExpressionAst member = this.MemberExpression.Member as StringConstantExpressionAst;
     if (member != null)
     {
         return Expression.Dynamic(PSGetMemberBinder.Get(member.Value, this.MemberExpression.Static), typeof(object), item);
     }
     ParameterExpression expression4 = Expression.Parameter(this.GetPropertyExpr(compiler).Type);
     temps.Add(expression4);
     exprs.Add(Expression.Assign(expression4, compiler.Compile(this.MemberExpression.Member)));
     this.CachedPropertyExpr = expression4;
     return Expression.Dynamic(PSGetDynamicMemberBinder.Get(this.MemberExpression.Static), typeof(object), item, expression4);
 }
 private Expression GetTargetExpr(Compiler compiler)
 {
     return (this._targetExprTemp ?? compiler.Compile(this.InvokeMemberExpressionAst.Expression));
 }
示例#4
0
        private void ReallyCompile(bool optimize)
        {
            var sw = new Stopwatch();
            sw.Start();

            if (!IsProductCode && SecuritySupport.IsProductBinary(((Ast)_ast).Extent.File))
            {
                this.IsProductCode = true;
            }

            bool etwEnabled = ParserEventSource.Log.IsEnabled();
            if (etwEnabled)
            {
                var extent = _ast.Body.Extent;
                var text = extent.Text;
                ParserEventSource.Log.CompileStart(ParserEventSource.GetFileOrScript(extent.File, text), text.Length, optimize);
            }

            PerformSecurityChecks();

            Compiler compiler = new Compiler();
            compiler.Compile(this, optimize);

            if (!IsProductCode)
            {
                TelemetryAPI.ReportScriptTelemetry((Ast)_ast, !optimize, sw.ElapsedMilliseconds);
            }

            if (etwEnabled) ParserEventSource.Log.CompileStop();
        }
示例#5
0
        public Expression GetValue(Compiler compiler, List<Expression> exprs, List<ParameterExpression> temps)
        {
            var targetExpr = compiler.Compile(IndexExpressionAst.Target);
            _targetExprTemp = Expression.Variable(targetExpr.Type);
            temps.Add(_targetExprTemp);
            exprs.Add(Expression.Assign(_targetExprTemp, targetExpr));

            var index = IndexExpressionAst.Index;
            var arrayLiteral = (index as ArrayLiteralAst);
            var constraints = GetInvocationConstraints();
            Expression result;
            if (arrayLiteral != null)
            {
                // If assignment to slices were allowed, we'd need to save the elements in temps
                // like we do when doing normal assignment (below).  But it's not allowed, so it
                // doesn't matter.
                result = DynamicExpression.Dynamic(PSGetIndexBinder.Get(arrayLiteral.Elements.Count, constraints),
                                                   typeof(object),
                                                   arrayLiteral.Elements.Select(compiler.Compile).Prepend(_targetExprTemp));
            }
            else
            {
                var indexExpr = compiler.Compile(index);
                _indexExprTemp = Expression.Variable(indexExpr.Type);
                temps.Add(_indexExprTemp);
                exprs.Add(Expression.Assign(_indexExprTemp, indexExpr));
                result = DynamicExpression.Dynamic(PSGetIndexBinder.Get(1, constraints), typeof(object), _targetExprTemp,
                                                   _indexExprTemp);
            }
            return result;
        }
示例#6
0
 private Expression GetIndexExpr(Compiler compiler)
 {
     return _indexExprTemp ?? compiler.Compile(IndexExpressionAst.Index);
 }
示例#7
0
 private Expression GetTargetExpr(Compiler compiler)
 {
     return _targetExprTemp ?? compiler.Compile(IndexExpressionAst.Target);
 }
示例#8
0
 private Expression GetMemberNameExpr(Compiler compiler)
 {
     return _memberNameExprTemp ?? compiler.Compile(InvokeMemberExpressionAst.Member);
 }
示例#9
0
        public Expression GetValue(Compiler compiler, List<Expression> exprs, List<ParameterExpression> temps)
        {
            var target = GetTargetExpr(compiler);
            var targetTemp = Expression.Parameter(target.Type);
            temps.Add(targetTemp);
            CachedTarget = targetTemp;
            exprs.Add(Expression.Assign(targetTemp, target));
            var memberNameAst = MemberExpression.Member as StringConstantExpressionAst;
            if (memberNameAst != null)
            {
                string name = memberNameAst.Value;
                return DynamicExpression.Dynamic(PSGetMemberBinder.Get(name, compiler._memberFunctionType, MemberExpression.Static), typeof(object), targetTemp);
            }

            var propertyExpr = GetPropertyExpr(compiler);
            var propertyNameTemp = Expression.Parameter(propertyExpr.Type);
            temps.Add(propertyNameTemp);
            exprs.Add(Expression.Assign(propertyNameTemp, compiler.Compile(MemberExpression.Member)));
            CachedPropertyExpr = propertyNameTemp;
            return DynamicExpression.Dynamic(PSGetDynamicMemberBinder.Get(compiler._memberFunctionType, MemberExpression.Static), typeof(object), targetTemp, propertyNameTemp);
        }
示例#10
0
 private Expression GetPropertyExpr(Compiler compiler)
 {
     return compiler.Compile(MemberExpression.Member);
 }
示例#11
0
 private Expression GetTargetExpr(Compiler compiler)
 {
     return compiler.Compile(MemberExpression.Expression);
 }
示例#12
0
 private Expression GetIndexExpr(Compiler compiler)
 {
     return (this._indexExprTemp ?? compiler.Compile(this.IndexExpressionAst.Index));
 }