public UnaryComputationAssignment(IAssignableValue target, IReadableValue operand, UnaryOperatorType @operator, PrimitiveType operandType)
 {
     Target      = target;
     Operand     = operand;
     Operator    = @operator;
     OperandType = operandType;
 }
Ejemplo n.º 2
0
 public BinaryComputationAssignment(IAssignableValue target, IReadableValue lhs, IReadableValue rhs, BinaryOperatorType @operator, PrimitiveType operandType)
 {
     Target      = target;
     Lhs         = lhs;
     Rhs         = rhs;
     Operator    = @operator;
     OperandType = operandType;
 }
Ejemplo n.º 3
0
        public IEnumerable <IInstruction> TransformValue(IValue value, IAssignableValue target)
        {
            if (!(value.ReturnType is PrimitiveType type))
            {
                throw new InvalidOperationException("Internal Failure: Binder failed binding high-level locals to primitives");
            }

            yield return(DirectAssignment(target, RequestValue(value), type));
        }
Ejemplo n.º 4
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.º 5
0
        private IEnumerable <IInstruction> GetValue(IExpression expr, out IReadableValue location)
        {
            if (expr is IValue val)
            {
                location = RequestValue(val);
                return(Array.Empty <IInstruction>());
            }

            IAssignableValue target = RequestLocal();

            location = target;
            return(TransformExpression(expr, target));
        }
Ejemplo n.º 6
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);
            }
        }
Ejemplo n.º 8
0
 public CallInstruction(string name, IReadOnlyList <IReadableValue> parameters, IAssignableValue target)
 {
     Name       = name;
     Parameters = parameters;
     Target     = target;
 }
Ejemplo n.º 9
0
 public IEnumerable <IInstruction> TransformExpression(IExpression expression, IAssignableValue target) =>
 expression switch
 {
Ejemplo n.º 10
0
 public StoreInstruction(uint label, IAssignableValue result, IVariable operand)
     : base(label)
 {
     this.Result  = result;
     this.Operand = operand;
 }
 public ParameterQueryAssignment(int parameterIndex, IAssignableValue target)
 {
     ParameterIndex = parameterIndex;
     Target         = target;
 }
Ejemplo n.º 12
0
        public void VisitMethod(MethodBody mBody, ControlFlowGraph cfg)
        {
            VisitLocals(mBody);

            // Going through the instructions via cfg nodes instead of directly iterating over the instructions
            // of the methodBody becuase Phi instructions may not have been inserted in the insts of the methodBody.
            foreach (var node in cfg.Nodes)
            {
                foreach (var instruction in node.Instructions)
                {
                    // System.Console.WriteLine("{0}", instruction.ToString());
                    // System.Console.WriteLine("{0}", instruction.GetType().FullName());
                    // System.Console.WriteLine();

                    if (instruction is LoadInstruction)
                    {
                        LoadInstruction lInst      = instruction as LoadInstruction;
                        IValue          rhsOperand = lInst.Operand;
                        if (rhsOperand is StaticFieldAccess)
                        {
                            StaticFieldAccess rhsAcc  = rhsOperand as StaticFieldAccess;
                            IFieldReference   fld     = rhsAcc.Field;
                            ITypeDefinition   fldType = fld.ContainingType.ResolvedType;
                            Stubber.CheckAndAdd(fldType);
                        }
                        // Note: calls to static methods and instance methods appear as a StaticMethodReference
                        else if (rhsOperand is StaticMethodReference)
                        {
                            StaticMethodReference sMethAddr    = rhsOperand as StaticMethodReference;
                            IMethodDefinition     tgtMeth      = sMethAddr.Method.ResolvedMethod;
                            ITypeDefinition       containingTy = tgtMeth.ContainingTypeDefinition;
                            Stubber.CheckAndAdd(containingTy);
                            IMethodDefinition addedMeth = Stubber.CheckAndAdd(tgtMeth);
                            // addrTakenMethods do not contain templates.
                            if (addedMeth != null)
                            {
                                addrTakenMethods.Add(addedMeth);
                            }
                        }
                        //Note: calls to virtual, abstract or interface methods appear as VirtualMethodReference
                        else if (rhsOperand is VirtualMethodReference)
                        {
                            VirtualMethodReference sMethAddr    = rhsOperand as VirtualMethodReference;
                            IMethodDefinition      tgtMeth      = sMethAddr.Method.ResolvedMethod;
                            ITypeDefinition        containingTy = tgtMeth.ContainingTypeDefinition;
                            ITypeDefinition        addedTy      = Stubber.CheckAndAdd(containingTy);
                            IMethodDefinition      addedMeth    = Stubber.CheckAndAdd(tgtMeth);
                            if (addedTy != null && addedMeth != null)
                            {
                                // addrTakenMethods do not contain templates.
                                addrTakenMethods.Add(addedMeth);
                                ProcessVirtualInvoke(addedMeth, addedTy, true);
                            }
                        }
                        else if (rhsOperand is Reference)
                        {
                            Reference      rhsRef = rhsOperand as Reference;
                            IReferenceable refOf  = rhsRef.Value;
                            if (refOf is StaticFieldAccess)
                            {
                                StaticFieldAccess refAcc  = refOf as StaticFieldAccess;
                                IFieldDefinition  fld     = refAcc.Field.ResolvedField;
                                ITypeDefinition   fldType = fld.ContainingType.ResolvedType;
                                Stubber.CheckAndAdd(fldType);
                                addrTakenStatFlds.Add(fld);
                            }
                            else if (refOf is IVariable)
                            {
                                IVariable refVar = refOf as IVariable;
                                if (!refVar.Type.IsValueType || refVar.Type.ResolvedType.IsStruct)
                                {
                                    addrTakenLocals.Add(refVar);
                                }
                            }
                            else if (refOf is InstanceFieldAccess)
                            {
                                InstanceFieldAccess refAcc = refOf as InstanceFieldAccess;
                                IFieldDefinition    fld    = refAcc.Field.ResolvedField;
                                addrTakenInstFlds.Add(fld);
                            }
                            else if (refOf is ArrayElementAccess)
                            {
                                // All arrays will be added into domX as potential address taken.
                            }
                        }
                    }
                    else if (instruction is StoreInstruction)
                    {
                        StoreInstruction sInst = instruction as StoreInstruction;
                        IAssignableValue lhs   = sInst.Result;
                        if (lhs is StaticFieldAccess)
                        {
                            StaticFieldAccess lhsAcc  = lhs as StaticFieldAccess;
                            IFieldReference   fld     = lhsAcc.Field;
                            ITypeDefinition   fldType = fld.ContainingType.ResolvedType;
                            Stubber.CheckAndAdd(fldType);
                        }
                    }
                    else if (instruction is CreateObjectInstruction)
                    {
                        CreateObjectInstruction newObjInst = instruction as CreateObjectInstruction;
                        ITypeReference          objType    = newObjInst.AllocationType;
                        ITypeDefinition         objTypeDef = objType.ResolvedType;
                        if (objTypeDef is IGenericTypeInstance)
                        {
                            objTypeDef = objTypeDef.ResolvedType;
                        }
                        ITypeDefinition addedTy = Stubber.CheckAndAdd(objTypeDef);
                        if (addedTy != null && !allocClasses.Contains(addedTy))
                        {
                            allocClasses.Add(addedTy);
                        }
                    }
                    else if (instruction is CreateArrayInstruction)
                    {
                        CreateArrayInstruction newArrInst  = instruction as CreateArrayInstruction;
                        ITypeReference         elemType    = newArrInst.ElementType;
                        ITypeDefinition        elemTypeDef = elemType.ResolvedType;
                        ITypeDefinition        addedTy     = Stubber.CheckAndAdd(elemTypeDef);
                        if (addedTy != null && !allocClasses.Contains(addedTy))
                        {
                            allocClasses.Add(addedTy);
                        }
                    }
                    else if (instruction is MethodCallInstruction)
                    {
                        MethodCallInstruction invkInst       = instruction as MethodCallInstruction;
                        IMethodReference      callTgt        = invkInst.Method;
                        ITypeReference        containingType = callTgt.ContainingType;
                        ITypeDefinition       declType       = containingType.ResolvedType;
                        IMethodDefinition     callTgtDef     = callTgt.ResolvedMethod;
                        ITypeDefinition       addedType      = Stubber.CheckAndAdd(declType);
                        IMethodDefinition     addedMeth      = Stubber.CheckAndAdd(callTgtDef);
                        MethodCallOperation   callType       = invkInst.Operation;
                        if (callType == MethodCallOperation.Virtual && addedType != null && addedMeth != null)
                        {
                            ProcessVirtualInvoke(addedMeth, addedType, false);
                        }
                    }
                    else
                    {
                        // System.Console.WriteLine("{0}", instruction.ToString());
                        // System.Console.WriteLine("Not currently handled: {0}", instruction.GetType().ToString());
                        // System.Console.WriteLine();
                    }
                }
            }
        }