public void TransformExpressions(BaseCodeTransformer transformer) { V_0 = this.context.get_MethodContext().get_Expressions().get_BlockExpressions().get_Values().GetEnumerator(); try { while (V_0.MoveNext()) { V_1 = V_0.get_Current(); V_2 = 0; V_3 = 0; while (V_3 < V_1.get_Count()) { V_4 = (Expression)transformer.Visit(V_1.get_Item(V_3)); if (V_4 != null) { stackVariable27 = V_2; V_2 = stackVariable27 + 1; V_1.set_Item(stackVariable27, V_4); } V_3 = V_3 + 1; } V_5 = V_1.get_Count() - V_2; while (V_5 > 0) { V_1.RemoveAt(V_2 + V_5 - 1); V_5 = V_5 - 1; } } } finally { ((IDisposable)V_0).Dispose(); } return; }
public ICodeNode VisitMethodInvocationExpression(MethodInvocationExpression node) { MethodReferenceExpression methodReference = node.MethodExpression; if ((methodReference == null) || (methodReference.Method.CallingConvention == MethodCallingConvention.StdCall)) { return(null); } MethodReference method = methodReference.Method; BinaryOperator binaryOperator; if (binaryOperators.TryGetValue(method.Name, out binaryOperator)) { return(BuildBinaryExpression(binaryOperator, node.Arguments[0], node.Arguments[1], method.FixedReturnType, node.InvocationInstructions)); } UnaryOperator unaryOperator; if (unaryOperators.TryGetValue(method.Name, out unaryOperator)) { return(BuildUnaryExpression(unaryOperator, node.Arguments[0], node.InvocationInstructions)); } if (method.Name == "op_True") { return((Expression)codeTransformer.Visit(node.Arguments[0])); } else if (method.Name == "op_False") { //TODO: Must consider better representation return(new ConditionExpression((Expression)codeTransformer.Visit(node.Arguments[0]), new LiteralExpression(false, typeSystem, null), new LiteralExpression(true, typeSystem, null), node.InvocationInstructions)); } if (method.Name == "op_Explicit") { return(new ExplicitCastExpression((Expression)codeTransformer.Visit(node.Arguments[0]), node.ExpressionType, node.InvocationInstructions)); } if (method.Name == "op_Implicit") { return(new ImplicitCastExpression((Expression)codeTransformer.Visit(node.Arguments[0]), node.ExpressionType, node.InvocationInstructions)); } if (method.Name == "get_Chars" && node.MethodExpression.Target.ExpressionType.FullName == "System.String") { ArrayIndexerExpression stringIndexing = new ArrayIndexerExpression(node.MethodExpression.Target, node.InvocationInstructions); foreach (Expression arg in node.Arguments) { stringIndexing.Indices.Add(arg); } return(stringIndexing); } return(null); }
public ICodeNode VisitMethodInvocationExpression(MethodInvocationExpression node) { if (node.MethodExpression.CodeNodeType == CodeNodeType.MethodReferenceExpression) { MethodReferenceExpression methodReferenceExpression = node.MethodExpression; MethodReference methodReference = methodReferenceExpression.Method; if (IsDelegateInvokeMethod(methodReference)) { ExpressionCollection visitedArguments = (ExpressionCollection)codeTransformer.Visit(node.Arguments); return(new DelegateInvokeExpression(methodReferenceExpression.Target, visitedArguments, methodReference, node.InvocationInstructions)); } } return(null); }
private CanCastExpression CreateCanCastExpression(Pattern.MatchContext matchContext, BinaryExpression node) { SafeCastExpression safeCast = (SafeCastExpression)matchContext[SafeCastKey]; List <Instruction> instructions = new List <Instruction>(); instructions.AddRange(safeCast.MappedInstructions); instructions.AddRange(node.MappedInstructions); instructions.AddRange(node.Right.UnderlyingSameMethodInstructions); return(new CanCastExpression( (Expression)codeTransformer.Visit(safeCast.Expression), safeCast.TargetType, instructions)); }
public void TransformExpressions(BaseCodeTransformer transformer) { foreach (IList <Expression> expressionList in this.context.MethodContext.Expressions.BlockExpressions.Values) { int current_index = 0; for (int iterator_index = 0; iterator_index < expressionList.Count; iterator_index++) { Expression result = (Expression)transformer.Visit(expressionList[iterator_index]); if (result != null) { expressionList[current_index++] = result; } } for (int i = expressionList.Count - current_index; i > 0; i--) { expressionList.RemoveAt(current_index + i - 1); } } }
public void TransformExpressions(BaseCodeTransformer transformer) { foreach (IList<Expression> expressionList in this.context.MethodContext.Expressions.BlockExpressions.Values) { int current_index = 0; for (int iterator_index = 0; iterator_index < expressionList.Count; iterator_index++) { Expression result = (Expression)transformer.Visit(expressionList[iterator_index]); if(result != null) { expressionList[current_index++] = result; } } for (int i = expressionList.Count - current_index; i > 0; i--) { expressionList.RemoveAt(current_index + i - 1); } } }
private void ProcessAnonymousType(TypeDefinition anonymousTypeDefinition, GenericInstanceType anonymousInstanceType, MethodDefinition constructorDefinition, ExpressionCollection constructorArguments) { for (int i = 0; i < constructorDefinition.Parameters.Count; i++) { ParameterDefinition currentParameter = constructorDefinition.Parameters[i]; int genericParameterIndex = anonymousTypeDefinition.GenericParameters.IndexOf(currentParameter.ParameterType as GenericParameter); PropertyDefinition property = FindPropertyOfType(anonymousTypeDefinition, currentParameter.ParameterType); TypeReference propertyType = anonymousInstanceType.GenericArguments[genericParameterIndex]; if (anonymousInstanceType.PostionToArgument.ContainsKey(genericParameterIndex)) { propertyType = anonymousInstanceType.PostionToArgument[genericParameterIndex]; } Expression parameterExpression = new AnonymousPropertyInitializerExpression(property, propertyType); int argumentIndex = GetParameterIndexWithType(constructorDefinition, currentParameter.ParameterType); Expression argumentExpression = transformer.Visit(constructorArguments[argumentIndex].Clone()) as Expression; initializerExpressions.Expressions.Add( new BinaryExpression(BinaryOperator.Assign, parameterExpression, argumentExpression, this.typeSystem, null)); } }