public bool TryMatch(StatementCollection statements, out int startIndex, out Statement result, out int replacedStatementsCount)
 {
     replacedStatementsCount = 0;
     startIndex = -1;
     result     = null;
     V_0        = false;
     if (statements.get_Count() == 0)
     {
         return(false);
     }
     V_1 = new HashSet <VariableDefinition>();
     V_2 = this.GetStatementsToInline(statements);
     V_3 = V_2.get_Count() - 1;
     while (V_3 >= 0)
     {
         V_4 = V_2.get_Item(V_3);
         V_5 = statements.get_Item(V_4) as ExpressionStatement;
         V_6 = ((V_5.get_Expression() as BinaryExpression).get_Left() as VariableReferenceExpression).get_Variable().Resolve();
         if (V_4 == statements.get_Count() - 1 || !String.IsNullOrEmpty(V_5.get_Label()))
         {
             dummyVar0 = V_1.Add(V_6);
         }
         else
         {
             V_7 = new List <Instruction>(V_5.get_Expression().get_MappedInstructions());
             V_7.AddRange((V_5.get_Expression() as BinaryExpression).get_Left().get_UnderlyingSameMethodInstructions());
             V_8 = (V_5.get_Expression() as BinaryExpression).get_Right().CloneAndAttachInstructions(V_7);
             if (this.inliner.TryInlineVariable(V_6, V_8, statements.get_Item(V_4 + 1), this.ShouldInlineAggressively(V_6), out V_9))
             {
                 statements.RemoveAt(V_4);
                 V_0       = true;
                 dummyVar1 = V_1.Add(V_6);
                 this.methodContext.RemoveVariable(V_6);
                 statements.set_Item(V_4, (Statement)this.dereferencer.Visit(statements.get_Item(V_4)));
             }
         }
         V_3 = V_3 - 1;
     }
     V_10 = V_1.GetEnumerator();
     try
     {
         while (V_10.MoveNext())
         {
             V_11      = V_10.get_Current();
             dummyVar2 = this.patternsContext.get_VariableToSingleAssignmentMap().Remove(V_11);
             dummyVar3 = this.patternsContext.get_VariableToDefineUseCountContext().Remove(V_11);
         }
     }
     finally
     {
         ((IDisposable)V_10).Dispose();
     }
     return(V_0);
 }
 public override ICodeNode VisitObjectCreationExpression(ObjectCreationExpression node)
 {
     if (this.state != 2 || node.get_Arguments() == null || node.get_Arguments().get_Count() != 2 || node.get_Arguments().get_Item(0).get_CodeNodeType() != 26 || node.get_Arguments().get_Item(1).get_CodeNodeType() != 20 || !this.delegateCopies.Contains((node.get_Arguments().get_Item(0) as VariableReferenceExpression).get_Variable()))
     {
         return(this.VisitObjectCreationExpression(node));
     }
     V_0 = node.get_Constructor().get_DeclaringType().Resolve();
     if (V_0 == null || V_0.get_BaseType() == null || String.op_Inequality(V_0.get_BaseType().get_FullName(), "System.MulticastDelegate"))
     {
         return(this.VisitObjectCreationExpression(node));
     }
     V_1             = (node.get_Arguments().get_Item(1) as MethodReferenceExpression).get_Method();
     V_2             = (node.get_Arguments().get_Item(1) as MethodReferenceExpression).get_MethodDefinition();
     stackVariable62 = new MethodSpecificContext(V_2.get_Body());
     V_3             = new DecompilationContext(stackVariable62, this.context.get_TypeContext(), this.context.get_ModuleContext(), this.context.get_AssemblyContext(), this.context.get_Language());
     stackVariable62.set_FieldToExpression(this.fieldDefToAssignedValueMap);
     V_4 = V_2.get_Body().DecompileLambda(this.context.get_Language(), V_3);
     if (V_4.get_Statements().get_Count() == 1 && V_4.get_Statements().get_Item(0).get_CodeNodeType() == 5 && (V_4.get_Statements().get_Item(0) as ExpressionStatement).get_Expression().get_CodeNodeType() == 57)
     {
         V_8 = (V_4.get_Statements().get_Item(0) as ExpressionStatement).get_Expression() as ReturnExpression;
         V_9 = new ShortFormReturnExpression(V_8.get_Value(), V_8.get_MappedInstructions());
         V_4 = new BlockStatement();
         V_4.get_Statements().Add(new ExpressionStatement(V_9));
     }
     this.context.get_MethodContext().get_VariableDefinitionToNameMap().AddRange <VariableDefinition, string>(V_3.get_MethodContext().get_VariableDefinitionToNameMap());
     this.context.get_MethodContext().get_VariableNamesCollection().UnionWith(V_3.get_MethodContext().get_VariableNamesCollection());
     this.context.get_MethodContext().AddInnerMethodParametersToContext(V_3.get_MethodContext());
     this.context.get_MethodContext().get_GotoStatements().AddRange(V_3.get_MethodContext().get_GotoStatements());
     this.context.get_MethodContext().get_GotoLabels().AddRange <string, Statement>(V_3.get_MethodContext().get_GotoLabels());
     V_5  = new ExpressionCollection();
     V_6  = LambdaExpressionsHelper.HasAnonymousParameter(V_2.get_Parameters());
     V_10 = V_2.get_Parameters().GetEnumerator();
     try
     {
         while (V_10.MoveNext())
         {
             V_11 = V_10.get_Current();
             V_5.Add(new LambdaParameterExpression(V_11, !V_6, null));
         }
     }
     finally
     {
         V_10.Dispose();
     }
     this.delegatesFound.Add(V_4);
     stackVariable157 = new LambdaExpression(V_5, V_4, V_2.IsAsync(), V_2.IsFunction(), V_1.get_Parameters(), false, node.get_Arguments().get_Item(1).get_MappedInstructions());
     stackVariable157.set_ExpressionType(V_0);
     V_7 = stackVariable157;
     return(new DelegateCreationExpression(node.get_Constructor().get_DeclaringType(), V_7, node.get_Arguments().get_Item(0), node.get_MappedInstructions()));
 }
Ejemplo n.º 3
0
 private void Preprocess()
 {
     V_0 = 0;
     V_1 = new Dictionary <ParameterDefinition, string>();
     V_2 = this.methodContext.get_ParameterDefinitionToNameMap().GetEnumerator();
     try
     {
         while (V_2.MoveNext())
         {
             V_3 = V_2.get_Current();
             V_4 = V_3.get_Key();
             V_5 = V_3.get_Value();
             V_6 = V_5;
             V_7 = !V_6.IsValidIdentifier();
             while (V_7 || this.HasMethodParameterWithSameName(V_6))
             {
                 V_7             = false;
                 stackVariable22 = V_0;
                 V_0             = stackVariable22 + 1;
                 V_8             = stackVariable22;
                 V_6             = String.Concat("argument", V_8.ToString());
             }
             if (!String.op_Inequality(V_6, V_5))
             {
                 continue;
             }
             V_1.Add(V_4, V_6);
         }
     }
     finally
     {
         ((IDisposable)V_2).Dispose();
     }
     V_2 = V_1.GetEnumerator();
     try
     {
         while (V_2.MoveNext())
         {
             V_9 = V_2.get_Current();
             this.methodContext.get_ParameterDefinitionToNameMap().set_Item(V_9.get_Key(), V_9.get_Value());
         }
     }
     finally
     {
         ((IDisposable)V_2).Dispose();
     }
     V_10 = this.methodContext.get_Body().get_Method().get_Parameters().GetEnumerator();
     try
     {
         while (V_10.MoveNext())
         {
             V_11 = V_10.get_Current();
             V_12 = V_11.get_Name();
             if (String.IsNullOrEmpty(V_12))
             {
                 V_12 = this.GetNameByType(V_11.get_ParameterType());
             }
             this.methodContext.get_ParameterDefinitionToNameMap().Add(V_11, V_12);
         }
     }
     finally
     {
         V_10.Dispose();
     }
     if (this.methodContext.get_Method().get_IsSetter() && this.methodContext.get_Method().get_Parameters().get_Count() == 1)
     {
         V_13 = this.methodContext.get_Method().get_Parameters().get_Item(0);
         this.methodContext.get_ParameterDefinitionToNameMap().set_Item(V_13, "value");
     }
     V_14 = this.methodContext.get_Body().get_Variables().GetEnumerator();
     try
     {
         while (V_14.MoveNext())
         {
             V_15 = V_14.get_Current();
             if (!this.methodContext.get_ParameterDefinitionToNameMap().ContainsValue(V_15.get_Name()))
             {
                 continue;
             }
             dummyVar0 = this.methodContext.get_VariablesToRename().Add(V_15);
         }
     }
     finally
     {
         V_14.Dispose();
     }
     V_16 = this.methodContext.get_VariableDefinitionToNameMap().GetEnumerator();
     try
     {
         while (V_16.MoveNext())
         {
             V_17 = V_16.get_Current();
             if (!this.methodContext.get_ParameterDefinitionToNameMap().ContainsValue(V_17.get_Value()))
             {
                 continue;
             }
             dummyVar1 = this.methodContext.get_VariablesToRename().Add(V_17.get_Key());
         }
     }
     finally
     {
         ((IDisposable)V_16).Dispose();
     }
     return;
 }
Ejemplo n.º 4
0
		private ICodeNode FixBranchingExpression(Expression expression, Instruction branch)
		{
			if (branch.get_OpCode().get_Code() == 57)
			{
				stackVariable5 = true;
			}
			else
			{
				V_5 = branch.get_OpCode();
				stackVariable5 = V_5.get_Code() == 44;
			}
			V_0 = stackVariable5;
			V_1 = expression.get_ExpressionType();
			V_3 = 9;
			stackVariable10 = new Instruction[1];
			stackVariable10[0] = branch;
			V_4 = stackVariable10;
			if (V_0)
			{
				V_3 = 10;
			}
			if (String.op_Equality(V_1.get_Name(), "Boolean") || V_1.get_Name().Contains("Boolean "))
			{
				if (V_0)
				{
					V_6 = expression;
				}
				else
				{
					V_6 = Negator.Negate(expression, this.typeSystem);
				}
				if (expression as SafeCastExpression == null)
				{
					V_7 = new UnaryExpression(11, V_6, V_4);
				}
				else
				{
					V_7 = new BinaryExpression(V_3, expression, this.GetLiteralExpression(false, null), this.typeSystem, V_4, false);
				}
				return V_7;
			}
			if (String.op_Equality(V_1.get_Name(), "Char"))
			{
				V_2 = new BinaryExpression(V_3, expression, this.GetLiteralExpression('\0', null), this.typeSystem, V_4, false);
				V_2.set_ExpressionType(this.typeSystem.get_Boolean());
			}
			if (V_1.get_IsPrimitive())
			{
				V_2 = new BinaryExpression(V_3, expression, this.GetLiteralExpression(0, null), this.typeSystem, V_4, false);
				V_2.set_ExpressionType(this.typeSystem.get_Boolean());
			}
			else
			{
				V_8 = V_1.Resolve();
				if (V_8 == null || !V_8.get_IsEnum() || V_1.get_IsArray())
				{
					V_2 = new BinaryExpression(V_3, expression, this.GetLiteralExpression(null, null), this.typeSystem, V_4, false);
					V_2.set_ExpressionType(this.typeSystem.get_Boolean());
				}
				else
				{
					V_9 = null;
					V_10 = V_8.get_Fields().GetEnumerator();
					try
					{
						while (V_10.MoveNext())
						{
							V_11 = V_10.get_Current();
							if (V_11.get_Constant() == null || V_11.get_Constant().get_Value() == null || !V_11.get_Constant().get_Value().Equals(0))
							{
								continue;
							}
							V_9 = V_11;
							goto Label0;
						}
					}
					finally
					{
						V_10.Dispose();
					}
				Label0:
					if (V_9 != null)
					{
						V_2 = new BinaryExpression(V_3, expression, new EnumExpression(V_9, null), this.typeSystem, V_4, false);
						V_2.set_ExpressionType(this.typeSystem.get_Boolean());
					}
					else
					{
						V_2 = new BinaryExpression(V_3, expression, this.GetLiteralExpression(0, null), this.typeSystem, V_4, false);
						V_2.set_ExpressionType(this.typeSystem.get_Boolean());
					}
				}
			}
			return V_2;
		}