Ejemplo n.º 1
0
        Expression IAssignableValue.SetValue(Compiler compiler, Expression rhs)
        {
            List <AttributeBaseAst> attributes      = this.GetAttributes();
            IAssignableValue        assignableValue = this.GetActualAssignableAst().GetAssignableValue();
            VariableExpressionAst   ast             = assignableValue as VariableExpressionAst;

            if (ast == null)
            {
                return(assignableValue.SetValue(compiler, Compiler.ConvertValue(rhs, attributes)));
            }
            return(Compiler.CallSetVariable(Expression.Constant(ast.VariablePath), rhs, Expression.Constant(attributes.ToArray())));
        }
Ejemplo n.º 2
0
        private object ExecutePrefixPostFix(Array input, Pipe outputPipe, ExecutionContext context)
        {
            if (this._prefix == null && this._postfix == null)
            {
                return((object)null);
            }
            Token errToken = this._prefix != null ? this._prefix : this._postfix;

            if (!(this._expression is IAssignableParseTreeNode expression))
            {
                throw InterpreterError.NewInterpreterException((object)errToken.TokenText, typeof(RuntimeException), errToken, "OperatorRequiresVariableOrProperty", (object)errToken.TokenText);
            }
            IAssignableValue assignableValue = expression.GetAssignableValue(input, context);
            object           obj1            = PSObject.Base(assignableValue.GetValue(context)) ?? (object)0;
            Type             type            = obj1.GetType();
            TypeCode         typeCode        = LanguagePrimitives.GetTypeCode(type);

            if (!LanguagePrimitives.IsNumeric(typeCode))
            {
                throw InterpreterError.NewInterpreterException(obj1, typeof(RuntimeException), errToken, "OperatorRequiresNumber", (object)errToken, (object)type);
            }
            object obj2;

            if (typeCode == TypeCode.Int32)
            {
                try
                {
                    obj2 = (object)checked ((int)obj1 + this.valueToAdd);
                }
                catch
                {
                    obj2 = ParserOps.PolyAdd(context, this.NodeToken, obj1, (object)this.valueToAdd);
                }
            }
            else
            {
                obj2 = ParserOps.PolyAdd(context, this.NodeToken, obj1, (object)this.valueToAdd);
            }
            assignableValue.SetValue(obj2, context);
            return(this._prefix != null ? obj2 : obj1);
        }
        internal override object Execute(Array input, Pipe outputPipe, ExecutionContext context)
        {
            this.CheckForInterrupts(context);
            object obj1 = (object)null;

            try
            {
                obj1 = this._rightHandSide.Execute(input, (Pipe)null, context);
                if (obj1 == AutomationNull.Value)
                {
                    obj1 = (object)null;
                }
                IAssignableValue assignableValue = this._left.GetAssignableValue(input, context);
                object           obj2            = this._operationDelegate == null ? obj1 : this._operationDelegate(context, this.NodeToken, assignableValue.GetValue(context), obj1);
                assignableValue.SetValue(obj2, context);
                return(obj2);
            }
            catch (ScriptCallDepthException ex)
            {
                throw;
            }
            catch (FlowControlException ex)
            {
                throw;
            }
            catch (RuntimeException ex)
            {
                if (ex.ErrorRecord != null && ex.ErrorRecord.InvocationInfo == null)
                {
                    ex.ErrorRecord.SetInvocationInfo(new InvocationInfo((CommandInfo)null, this.NodeToken, context));
                }
                throw;
            }
            catch (Exception ex)
            {
                CommandProcessorBase.CheckForSevereException(ex);
                throw InterpreterError.NewInterpreterException(obj1, typeof(RuntimeException), this.NodeToken, "OperatorFailed", (object)this.NodeToken.TokenText, (object)ex.Message);
            }
        }