public override void TraverseChildren(IMethodDefinition method) { this.methodTraversed = method; if (method.IsConstructor && PhoneTypeHelper.isPhoneApplicationClass(typeTraversed, host)) { navigationCallers.Add(method); string mainPageUri = PhoneCodeHelper.instance().PhonePlugin.getMainPageXAML(); SourceMethodBody sourceBody = method.Body as SourceMethodBody; if (sourceBody != null) { BlockStatement bodyBlock = sourceBody.Block as BlockStatement; if (bodyBlock != null) { Assignment uriInitAssign = new Assignment() { Source = new CompileTimeConstant() { Type = host.PlatformType.SystemString, Value = UriHelper.getURIBase(mainPageUri), }, Type = host.PlatformType.SystemString, Target = new TargetExpression() { Type = host.PlatformType.SystemString, // TODO unify code for current uri fieldreference Definition = new FieldReference() { ContainingType = PhoneCodeHelper.instance().getMainAppTypeReference(), IsStatic=true, Type=host.PlatformType.SystemString, Name=host.NameTable.GetNameFor(PhoneCodeHelper.IL_CURRENT_NAVIGATION_URI_VARIABLE), InternFactory= host.InternFactory, }, }, }; Statement uriInitStmt= new ExpressionStatement() { Expression= uriInitAssign, }; bodyBlock.Statements.Insert(0, uriInitStmt); } } } base.TraverseChildren(method); }
private Statement ParseArraySet(IOperation currentOperation) { Contract.Requires(currentOperation != null); ExpressionStatement result = new ExpressionStatement(); Assignment assignment = new Assignment(); result.Expression = assignment; assignment.Source = this.PopOperandStack(); TargetExpression targetExpression = new TargetExpression(); assignment.Target = targetExpression; Contract.Assume(currentOperation.Value is IArrayTypeReference); ArrayIndexer indexer = this.ParseArrayIndexer(currentOperation, ((IArrayTypeReference)currentOperation.Value).ElementType); targetExpression.Definition = indexer; targetExpression.Instance = indexer.IndexedObject; targetExpression.Type = indexer.Type; assignment.Source = TypeInferencer.Convert(assignment.Source, indexer.Type); assignment.Type = indexer.Type; return result; }
private Statement ParseInitObject(IOperation currentOperation) { Contract.Requires(currentOperation != null); Contract.Assume(currentOperation.Value is ITypeReference); var objectType = (ITypeReference)currentOperation.Value; Assignment assignment = new Assignment(); var addressDeref = new AddressDereference() { Address = this.PopOperandStack(), Type = objectType }; assignment.Target = new TargetExpression() { Definition = addressDeref, Type = objectType }; assignment.Source = new DefaultValue() { DefaultValueType = (ITypeReference)currentOperation.Value, Type = objectType }; assignment.Type = objectType; return new ExpressionStatement() { Expression = assignment }; }
public override void BuildMethod() { AddStatement.DeclareInterceptedType(field.ContainingType.ResolvedType); Context.Log.WriteTrace(" Adding: var interceptedField = interceptedType.GetField('{0}');", field.Name.Value); Context.Block.Statements.Add( Declare.Variable<FieldInfo>("interceptedField").As( Call.VirtualMethod("GetField", typeof (string)).ThatReturns<FieldInfo>().WithArguments( Constant.Of(field.Name.Value)).On("interceptedType")) ); AddStatement.DeclareArgumentsList(); AddStatement.AddArgumentToList(Params["assignedValue"]); var actionT = SharpMockTypes.Actions[1]; var actionActualT = new GenericTypeInstanceReference(); actionActualT.GenericType = actionT; actionActualT.GenericArguments.Add(field.Type); var assignment = new AnonymousDelegate(); assignment.Type = actionActualT; assignment.ReturnType = Context.Host.PlatformType.SystemVoid; assignment.CallingConvention = CallingConvention.HasThis; var parameterDefinition = new ParameterDefinition(); parameterDefinition.Index = 0; parameterDefinition.Type = field.Type; parameterDefinition.Name = Context.Host.NameTable.GetNameFor("alteredValue"); parameterDefinition.ContainingSignature = assignment; assignment.Parameters.Add(parameterDefinition); var assignmentBody = new BlockStatement(); var assignActualField = new ExpressionStatement(); var actualField = new TargetExpression(); actualField.Type = field.Type; actualField.Definition = field; var value = new BoundExpression(); value.Type = field.Type; value.Definition = parameterDefinition; var assignValueToField = new Assignment(); assignValueToField.Source = value; assignValueToField.Target = actualField; assignValueToField.Type = field.Type; assignActualField.Expression = assignValueToField; actualField.Type = field.Type; actualField.Definition = field; assignmentBody.Statements.Add(assignActualField); assignmentBody.Statements.Add(new ReturnStatement()); assignment.Body = assignmentBody; Context.Block.Statements.Add( Declare.Variable("local_0", actionActualT).As(assignment) ); AddStatement.DeclareRegistryInterceptor(); AddStatement.DeclareInvocation(); AddStatement.SetArgumentsOnInvocation(); AddStatement.SetOriginalCallOnInvocation(); AddStatement.SetTargetOnInvocationToNull(); Context.Block.Statements.Add( Do(Call.PropertySetter<MemberInfo>("OriginalCallInfo").WithArguments("interceptedField").On("invocation")) ); AddStatement.CallShouldInterceptOnInterceptor(); AddStatement.CallInterceptOnInterceptor(); Context.Block.Statements.Add(Return.Void()); }
private Statement ParseArraySet(IOperation currentOperation) { ExpressionStatement result = new ExpressionStatement(); Assignment assignment = new Assignment(); result.Expression = assignment; assignment.Source = this.PopOperandStack(); TargetExpression targetExpression = new TargetExpression(); assignment.Target = targetExpression; ArrayIndexer indexer = this.ParseArrayIndexer(currentOperation); targetExpression.Definition = indexer; targetExpression.Instance = indexer.IndexedObject; return result; }
/// <summary> /// Visits the specified assignment. /// </summary> /// <param name="assignment">The assignment.</param> public override void Visit(IAssignment assignment) { Assignment mutableAssignment = assignment as Assignment; if (alwaysMakeACopy || mutableAssignment == null) mutableAssignment = new Assignment(assignment); this.resultExpression = this.myCodeMutator.Visit(mutableAssignment); }
/// <summary> /// Visits the specified assignment. /// </summary> /// <param name="assignment">The assignment.</param> public override void Visit(IAssignment assignment) { Assignment mutableAssignment = new Assignment(assignment); this.resultExpression = this.myCodeCopier.DeepCopy(mutableAssignment); }
private Expression ParseCopyObject() { AddressDereference source = new AddressDereference(); source.Address = this.PopOperandStack(); AddressDereference addressDeref = new AddressDereference(); addressDeref.Address = this.PopOperandStack(); TargetExpression target = new TargetExpression(); target.Definition = addressDeref; Assignment result = new Assignment(); result.Source = source; result.Target = target; return result; }
public override IExpression Visit(Assignment assignment) { var ld = assignment.Target.Definition as ILocalDefinition; if (ld != null && this.currentClosureLocals.ContainsKey(ld)) return CodeDummy.Expression; return base.Visit(assignment); }
private IExpression CollapseOpAssign(Assignment assignment) { Contract.Requires(assignment != null); Contract.Ensures(Contract.Result<IExpression>() != null); var sourceAssignment = assignment.Source as Assignment; if (sourceAssignment != null) { assignment.Source = this.CollapseOpAssign(sourceAssignment); return assignment; } var binOp = assignment.Source as BinaryOperation; if (binOp != null) { var addressDeref = binOp.LeftOperand as IAddressDereference; if (addressDeref != null) { var dupValue = addressDeref.Address as IDupValue; if (dupValue != null) { if (binOp is IAddition || binOp is IBitwiseAnd || binOp is IBitwiseOr || binOp is IDivision || binOp is IExclusiveOr || binOp is ILeftShift || binOp is IModulus || binOp is IMultiplication || binOp is IRightShift || binOp is ISubtraction) { binOp.LeftOperand = assignment.Target; return binOp; } } } else { var boundExpr = binOp.LeftOperand as IBoundExpression; if (boundExpr != null && boundExpr.Definition == assignment.Target.Definition && boundExpr.Instance is IDupValue) { if (binOp is IAddition || binOp is IBitwiseAnd || binOp is IBitwiseOr || binOp is IDivision || binOp is IExclusiveOr || binOp is ILeftShift || binOp is IModulus || binOp is IMultiplication || binOp is IRightShift || binOp is ISubtraction) { binOp.LeftOperand = assignment.Target; return binOp; } } } } return assignment; }
private static List<IStatement> InitializeFieldsInConstructor(IMethodDefinition method) { Contract.Ensures(Contract.Result<List<IStatement>>() != null); var inits = new List<IStatement>(); if (method.IsConstructor || method.IsStaticConstructor) { var smb = method.Body as ISourceMethodBody; if (method.IsStaticConstructor || (smb != null && !FindCtorCall.IsDeferringCtor(method, smb.Block))) { var thisExp = new ThisReference() { Type = method.ContainingTypeDefinition, }; foreach (var f in method.ContainingTypeDefinition.Fields) { if (f.IsStatic == method.IsStatic) { var a = new Assignment() { Source = new DefaultValue() { DefaultValueType = f.Type, Type = f.Type, }, Target = new TargetExpression() { Definition = f, Instance = method.IsConstructor ? thisExp : null, Type = f.Type }, Type = f.Type, }; inits.Add(new ExpressionStatement() { Expression = a, }); } } } } return inits; }
/// <summary> /// Create the new body of the iterator method. /// </summary> /// <remarks> /// Pseudo code: /// iteratorClosureLocal = new Closure(0); /// iteratorClosureLocal.field = parameter; // for each parameter including this. /// return iteratorClosureLocal; /// </remarks> private BlockStatement CreateNewIteratorMethodBody(IteratorClosureInformation iteratorClosure) { BlockStatement result = new BlockStatement(); // iteratorClosureLocal = new IteratorClosure(0); LocalDefinition localDefinition = new LocalDefinition() { Name = this.host.NameTable.GetNameFor("iteratorClosureLocal"), Type = GetClosureTypeReferenceFromIterator(iteratorClosure), }; CreateObjectInstance createObjectInstance = new CreateObjectInstance() { MethodToCall = GetMethodReference(iteratorClosure, iteratorClosure.Constructor), Type = localDefinition.Type }; // the start state depends on whether the iterator is an IEnumerable or an IEnumerator. For the former, // it must be created in state -2. Then it is the GetEnumerator method that puts it into its // "start" state, i.e., state 0. var startState = this.isEnumerable ? -2 : 0; createObjectInstance.Arguments.Add(new CompileTimeConstant() { Value = startState, Type = this.host.PlatformType.SystemInt32 }); LocalDeclarationStatement localDeclarationStatement = new LocalDeclarationStatement() { InitialValue = createObjectInstance, LocalVariable = localDefinition }; result.Statements.Add(localDeclarationStatement); // Generate assignments to closure instance's fields for each of the parameters captured by the closure. foreach (object capturedLocalOrParameter in FieldForCapturedLocalOrParameter.Keys) { BoundField boundField = FieldForCapturedLocalOrParameter[capturedLocalOrParameter]; Assignment assignment; ITypeReference localOrParameterType = GetLocalOrParameterType(capturedLocalOrParameter); if (capturedLocalOrParameter is ILocalDefinition) continue; if (capturedLocalOrParameter is IThisReference) { var thisR = new ThisReference(); IExpression thisValue = thisR; if (!this.method.ContainingTypeDefinition.IsClass) { thisValue = new AddressDereference() { Address = thisR, Type = this.method.ContainingTypeDefinition.IsGeneric ? (ITypeReference)this.method.ContainingTypeDefinition.InstanceType : (ITypeReference)this.method.ContainingTypeDefinition }; } assignment = new Assignment { Source = thisValue, Type = this.method.ContainingType, Target = new TargetExpression() { Definition = GetFieldReference(iteratorClosure, boundField.Field), Type = this.method.ContainingType, Instance = new BoundExpression() { Type = localDefinition.Type, Instance = null, Definition = localDefinition, IsVolatile = false } }, }; } else { assignment = new Assignment { Source = new BoundExpression() { Definition = capturedLocalOrParameter, Instance = null, IsVolatile = false, Type = localOrParameterType }, Type = localOrParameterType, Target = new TargetExpression() { Definition = GetFieldReference(iteratorClosure, boundField.Field), Type = localOrParameterType, Instance = new BoundExpression() { Type = localDefinition.Type, Instance = null, Definition = localDefinition, IsVolatile = false } }, }; } ExpressionStatement expressionStatement = new ExpressionStatement() { Expression = assignment }; result.Statements.Add(expressionStatement); } // Generate: return iteratorClosureLocal; result.Statements.Add(new ReturnStatement() { Expression = new BoundExpression() { Definition = localDeclarationStatement.LocalVariable, Instance = null, Type = localDeclarationStatement.LocalVariable.Type } }); return result; }
/// <summary> /// Rewrites the children of the given assignment expression. /// </summary> /// <param name="assignment"></param> public virtual void RewriteChildren(Assignment assignment) { this.RewriteChildren((Expression)assignment); assignment.Target = this.Rewrite(assignment.Target); assignment.Source = this.Rewrite(assignment.Source); }
private Statement ParseAssignment(IOperation currentOperation) { Contract.Requires(currentOperation != null); TargetExpression target = new TargetExpression(); ITypeReference/*?*/ elementType = null; if (this.alignment > 0) { Contract.Assume(this.alignment == 1 || this.alignment == 2 || this.alignment == 4); target.Alignment = this.alignment; } target.IsVolatile = this.sawVolatile; Assignment assignment = new Assignment(); assignment.Target = target; assignment.Source = this.PopOperandStack(); ExpressionStatement result = new ExpressionStatement(); result.Expression = assignment; switch (currentOperation.OperationCode) { case OperationCode.Starg: case OperationCode.Starg_S: { var definition = currentOperation.Value; if (definition == null) { target.Definition = new ThisReference(); var typeForThis = (INamedTypeDefinition)this.MethodDefinition.ContainingTypeDefinition; if (typeForThis.IsValueType) target.Type = Immutable.ManagedPointerType.GetManagedPointerType(Microsoft.Cci.MutableCodeModel.NamedTypeDefinition.SelfInstance(typeForThis, this.host.InternFactory), this.host.InternFactory); else target.Type = NamedTypeDefinition.SelfInstance(typeForThis, this.host.InternFactory); } else { var par = definition as IParameterDefinition; Contract.Assume(par != null); target.Definition = definition; target.Type = par.Type; } break; } case OperationCode.Stfld: target.Instance = this.PopOperandStack(); goto case OperationCode.Stsfld; case OperationCode.Stsfld: Contract.Assume(currentOperation.Value is IFieldReference); var field = (IFieldReference)currentOperation.Value; target.Definition = field; target.Type = field.Type; break; case OperationCode.Stelem: elementType = (ITypeReference)currentOperation.Value; goto case OperationCode.Stelem_Ref; case OperationCode.Stelem_I: elementType = this.platformType.SystemIntPtr; goto case OperationCode.Stelem_Ref; case OperationCode.Stelem_I1: elementType = this.platformType.SystemInt8; goto case OperationCode.Stelem_Ref; case OperationCode.Stelem_I2: elementType = this.platformType.SystemInt16; goto case OperationCode.Stelem_Ref; case OperationCode.Stelem_I4: elementType = this.platformType.SystemInt32; goto case OperationCode.Stelem_Ref; case OperationCode.Stelem_I8: elementType = this.platformType.SystemInt64; goto case OperationCode.Stelem_Ref; case OperationCode.Stelem_R4: elementType = this.platformType.SystemFloat32; goto case OperationCode.Stelem_Ref; case OperationCode.Stelem_R8: elementType = this.platformType.SystemFloat64; goto case OperationCode.Stelem_Ref; case OperationCode.Stelem_Ref: ArrayIndexer indexer = this.ParseArrayIndexer(currentOperation, elementType??this.platformType.SystemObject, treatArrayAsSingleDimensioned: true); target.Definition = indexer; target.Instance = indexer.IndexedObject; target.Type = indexer.Type; break; case OperationCode.Stind_I: elementType = this.platformType.SystemIntPtr; goto case OperationCode.Stind_Ref; case OperationCode.Stind_I1: elementType = this.platformType.SystemInt8; goto case OperationCode.Stind_Ref; case OperationCode.Stind_I2: elementType = this.platformType.SystemInt16; goto case OperationCode.Stind_Ref; case OperationCode.Stind_I4: elementType = this.platformType.SystemInt32; goto case OperationCode.Stind_Ref; case OperationCode.Stind_I8: elementType = this.platformType.SystemInt64; goto case OperationCode.Stind_Ref; case OperationCode.Stind_R4: elementType = this.platformType.SystemFloat32; goto case OperationCode.Stind_Ref; case OperationCode.Stind_R8: elementType = this.platformType.SystemFloat64; goto case OperationCode.Stind_Ref; case OperationCode.Stobj: elementType = (ITypeReference)currentOperation.Value; goto case OperationCode.Stind_Ref; case OperationCode.Stind_Ref: AddressDereference addressDereference = new AddressDereference(); addressDereference.Address = this.PopOperandStack(); addressDereference.Alignment = this.alignment; addressDereference.IsVolatile = this.sawVolatile; target.Definition = addressDereference; var pointerType = addressDereference.Address.Type as IPointerTypeReference; if (pointerType != null) addressDereference.Type = pointerType.TargetType; else { var managedPointerType = addressDereference.Address.Type as IManagedPointerTypeReference; if (managedPointerType != null) addressDereference.Type = managedPointerType.TargetType; else { //The pointer itself is untyped, so the instruction must have specified the element type addressDereference.Type = elementType??this.platformType.SystemObject; } } target.Type = addressDereference.Type; break; case OperationCode.Stloc: case OperationCode.Stloc_0: case OperationCode.Stloc_1: case OperationCode.Stloc_2: case OperationCode.Stloc_3: case OperationCode.Stloc_S: Contract.Assume(currentOperation.Value is ILocalDefinition); var local = this.GetLocalWithSourceName((ILocalDefinition)currentOperation.Value); target.Definition = local; this.numberOfAssignmentsToLocal[local] = this.numberOfAssignmentsToLocal.ContainsKey(local) ? this.numberOfAssignmentsToLocal[local] + 1 : 1; target.Type = local.Type; break; default: { var definition = currentOperation.Value; Contract.Assume(definition is ILocalDefinition || definition is IParameterDefinition || definition is IFieldReference || definition is IArrayIndexer || definition is IAddressDereference || definition is IPropertyDefinition); target.Definition = definition; break; } } assignment.Source = TypeInferencer.Convert(assignment.Source, target.Type); //mainly to convert (u)ints to bools, chars and pointers. assignment.Type = target.Type; Contract.Assume(assignment.Target.Type.TypeCode != PrimitiveTypeCode.Boolean || assignment.Source.Type.TypeCode == PrimitiveTypeCode.Boolean || IsByRef(assignment.Target.Definition)); this.alignment = 0; this.sawVolatile = false; return result; }
/// <summary> /// Visits the specified assignment. /// </summary> /// <param name="assignment">The assignment.</param> /// <returns></returns> protected virtual IExpression DeepCopy(Assignment assignment) { assignment.Target = (ITargetExpression)this.Substitute(assignment.Target); assignment.Source = this.Substitute(assignment.Source); assignment.Type = this.Substitute(assignment.Type); return assignment; }
public override IExpression Rewrite(IAssignment assignment) { // _log.Info("Rewriting IAssignment: " + assignment + " Pass: " + MutationTarget.PassInfo); var targetType = assignment.Target.Type; IMethodDefinition currentMethod = CurrentMethod; var field = currentMethod.ContainingTypeDefinition.Fields .Where(f => f.IsStatic == currentMethod.IsStatic) .First(f => isCompatibile(targetType, f.Type.ResolvedType)); var assignmentNew = new Assignment(assignment); assignmentNew.Source = new BoundExpression { Instance = new ThisReference(){Type = CurrentMethod.ContainingTypeDefinition}, Definition = field, Type = field.Type, }; return assignmentNew; }
public override IStatement Rewrite(IPushStatement pushStatement) { var depth = this.locals.Count; var t = pushStatement.ValueToPush.Type; var local = this.GetOrCreateLocal(depth, t); this.locals.Push(local); var assignment = new Assignment() { Source = pushStatement.ValueToPush, Target = new TargetExpression(){ Definition = local, Instance = null, Type = t, }, Type = t, }; if (this.inThenBranch) { if (this.thenBranchPushes != null && (t.TypeCode == PrimitiveTypeCode.Int32 || t.TypeCode == PrimitiveTypeCode.Boolean)) { this.thenBranchPushes.Add(depth, assignment); } } else if (this.inElseBranch) { if (this.thenBranchPushes != null) { if (t.TypeCode == PrimitiveTypeCode.Int32) { Contract.Assume(this.thenBranchPushes.ContainsKey(depth)); var a = this.thenBranchPushes[depth]; if (a.Type.TypeCode == PrimitiveTypeCode.Boolean) { // then this should be a push of a boolean, not an int Contract.Assume(pushStatement.ValueToPush is ICompileTimeConstant); var ctc = (ICompileTimeConstant) pushStatement.ValueToPush; var boolLocal = a.Target.Definition as ILocalDefinition; assignment.Target = new TargetExpression() { Definition = boolLocal, Instance = null, Type = this.systemBool, }; assignment.Source = new CompileTimeConstant() { Type = this.systemBool, Value = ((int)ctc.Value) == 0 ? false : true, }; this.locals.Pop(); this.locals.Push(boolLocal); } } else if (t.TypeCode == PrimitiveTypeCode.Boolean) { Contract.Assume(this.thenBranchPushes.ContainsKey(depth)); var a = this.thenBranchPushes[depth]; if (a.Type.TypeCode == PrimitiveTypeCode.Int32) { // then this should have been a push of a boolean, not an int Contract.Assume(a.Source is ICompileTimeConstant); var ctc = (ICompileTimeConstant)a.Source; var boolLocal = a.Target.Definition as ILocalDefinition; Contract.Assume(boolLocal != null); a.Target = new TargetExpression() { Definition = boolLocal, Instance = null, Type = this.systemBool, }; a.Source = new CompileTimeConstant() { Type = this.systemBool, Value = ((int)ctc.Value) == 0 ? false : true, }; } } } } var expressionStatment = new ExpressionStatement() { Expression = assignment, }; return expressionStatment; }
private Statement ParseInitObject(IOperation currentOperation) { Assignment assignment = new Assignment(); assignment.Target = new TargetExpression() { Definition = new AddressDereference() { Address = this.PopOperandStack() } }; assignment.Source = new DefaultValue() { DefaultValueType = (ITypeReference)currentOperation.Value }; return new ExpressionStatement() { Expression = assignment }; }
private void injectNavigationUpdateCode(IBlockStatement block, IEnumerable<Tuple<IStatement,StaticURIMode, string>> staticStmts, IEnumerable<IStatement> nonStaticStmts) { // TODO Here there is the STRONG assumption that a given method will only navigate at most once per method call // TODO (or at most will re-navigate to the same page). Quick "page flipping" on the same method // TODO would not be captured correctly Microsoft.Cci.MutableCodeModel.BlockStatement mutableBlock = block as Microsoft.Cci.MutableCodeModel.BlockStatement; foreach (IStatement stmt in nonStaticStmts) { int ndx = mutableBlock.Statements.ToList().IndexOf(stmt); if (ndx == -1) { // can't be throw new IndexOutOfRangeException("Statement must exist in original block"); } Assignment currentURIAssign = new Assignment() { Source = new CompileTimeConstant() { Type = host.PlatformType.SystemString, Value = PhoneCodeHelper.BOOGIE_DO_HAVOC_CURRENTURI, }, Type = host.PlatformType.SystemString, Target = new TargetExpression() { Type = host.PlatformType.SystemString, // TODO unify code for current uri fieldreference Definition = new FieldReference() { ContainingType = PhoneCodeHelper.instance().getMainAppTypeReference(), IsStatic= true, Type = host.PlatformType.SystemString, Name = host.NameTable.GetNameFor(PhoneCodeHelper.IL_CURRENT_NAVIGATION_URI_VARIABLE), InternFactory=host.InternFactory, }, }, }; Statement uriInitStmt = new ExpressionStatement() { Expression = currentURIAssign, }; mutableBlock.Statements.Insert(ndx + 1, uriInitStmt); } foreach (Tuple<IStatement, StaticURIMode, string> entry in staticStmts) { int ndx= mutableBlock.Statements.ToList().IndexOf(entry.Item1); if (ndx == -1) { // can't be throw new IndexOutOfRangeException("Statement must exist in original block"); } Assignment currentURIAssign = new Assignment() { Source = new CompileTimeConstant() { Type = host.PlatformType.SystemString, Value = UriHelper.getURIBase(entry.Item3).ToLower(), }, Type = host.PlatformType.SystemString, Target = new TargetExpression() { Type = host.PlatformType.SystemString, // TODO unify code for current uri fieldreference Definition = new FieldReference() { ContainingType = PhoneCodeHelper.instance().getMainAppTypeReference(), IsStatic= true, Type = host.PlatformType.SystemString, Name = host.NameTable.GetNameFor(PhoneCodeHelper.IL_CURRENT_NAVIGATION_URI_VARIABLE), InternFactory=host.InternFactory, }, }, }; Statement uriInitStmt = new ExpressionStatement() { Expression = currentURIAssign, }; mutableBlock.Statements.Insert(ndx+1, uriInitStmt); } }
private Statement ParseAssignment(IOperation currentOperation) { TargetExpression target = new TargetExpression(); ITypeReference/*?*/ elementType = null; target.Alignment = this.alignment; target.Definition = currentOperation.Value; target.IsVolatile = this.sawVolatile; Assignment assignment = new Assignment(); assignment.Target = target; assignment.Source = this.PopOperandStack(); ExpressionStatement result = new ExpressionStatement(); result.Expression = assignment; switch (currentOperation.OperationCode) { case OperationCode.Stfld: target.Instance = this.PopOperandStack(); break; case OperationCode.Stelem: case OperationCode.Stelem_I: case OperationCode.Stelem_I1: case OperationCode.Stelem_I2: case OperationCode.Stelem_I4: case OperationCode.Stelem_I8: case OperationCode.Stelem_R4: case OperationCode.Stelem_R8: case OperationCode.Stelem_Ref: ArrayIndexer indexer = this.ParseArrayIndexer(currentOperation); target.Definition = indexer; target.Instance = indexer.IndexedObject; break; case OperationCode.Stind_I: elementType = this.platformType.SystemIntPtr; goto case OperationCode.Stind_Ref; case OperationCode.Stind_I1: elementType = this.platformType.SystemInt8; goto case OperationCode.Stind_Ref; case OperationCode.Stind_I2: elementType = this.platformType.SystemInt16; goto case OperationCode.Stind_Ref; case OperationCode.Stind_I4: elementType = this.platformType.SystemInt32; goto case OperationCode.Stind_Ref; case OperationCode.Stind_I8: elementType = this.platformType.SystemInt64; goto case OperationCode.Stind_Ref; case OperationCode.Stind_R4: elementType = this.platformType.SystemFloat32; goto case OperationCode.Stind_Ref; case OperationCode.Stind_R8: elementType = this.platformType.SystemFloat64; goto case OperationCode.Stind_Ref; case OperationCode.Stind_Ref: case OperationCode.Stobj: AddressDereference addressDereference = new AddressDereference(); addressDereference.Address = this.PopOperandStack(); addressDereference.Alignment = this.alignment; addressDereference.IsVolatile = this.sawVolatile; //capture the element type. The pointer might be untyped, in which case the instruction is the only point where the element type is known. if (elementType != null) addressDereference.Type = elementType; //else: The type inferencer will fill in the type once the pointer type is known. target.Definition = addressDereference; break; case OperationCode.Stloc: case OperationCode.Stloc_0: case OperationCode.Stloc_1: case OperationCode.Stloc_2: case OperationCode.Stloc_3: case OperationCode.Stloc_S: var local = this.GetLocalWithSourceName((ILocalDefinition)target.Definition); target.Definition = local; this.numberOfAssignments[local] = this.numberOfAssignments.ContainsKey(local) ? this.numberOfAssignments[local] + 1 : 1; break; } this.alignment = 0; this.sawVolatile = false; return result; }
/// <summary> /// Visits the specified assignment. /// </summary> /// <param name="assignment">The assignment.</param> /// <returns></returns> public virtual IExpression Visit(Assignment assignment) { assignment.Target = this.Visit(assignment.Target); assignment.Source = this.Visit(assignment.Source); assignment.Type = this.Visit(assignment.Type); return assignment; }