예제 #1
0
 private bool TryRemoveOuterTryCatch(StatementCollection statements)
 {
     V_0 = 0;
     while (V_0 < statements.get_Count())
     {
         V_3 = statements.get_Item(V_0);
         if (V_3.get_CodeNodeType() == 17 && (V_3 as TryStatement).get_CatchClauses().get_Count() == 1)
         {
             break;
         }
         V_0 = V_0 + 1;
     }
     if (V_0 == statements.get_Count())
     {
         return(false);
     }
     V_1 = statements.get_Item(V_0) as TryStatement;
     V_2 = V_1.get_Try().get_Statements();
     if (this.asyncData.get_StateField() == null && !this.TryGetStateField(V_1.get_CatchClauses().get_Item(0).get_Body()))
     {
         return(false);
     }
     statements.RemoveAt(V_0);
     V_4 = 0;
     while (V_4 < V_2.get_Count())
     {
         statements.Insert(V_0 + V_4, V_2.get_Item(V_4));
         V_4 = V_4 + 1;
     }
     return(true);
 }
예제 #2
0
        private bool TryRemoveOuterTryCatch(StatementCollection statements)
        {
            int index = 0;

            for (; index < statements.Count; index++)
            {
                Statement currentStatement = statements[index];
                if (currentStatement.CodeNodeType == CodeNodeType.TryStatement && (currentStatement as TryStatement).CatchClauses.Count == 1)
                {
                    break;
                }
            }

            if (index == statements.Count)
            {
                return(false);
            }

            TryStatement        theTry        = statements[index] as TryStatement;
            StatementCollection tryStatements = theTry.Try.Statements;

            if (asyncData.StateField == null && !TryGetStateField(theTry.CatchClauses[0].Body))
            {
                return(false);
            }

            statements.RemoveAt(index);
            for (int i = 0; i < tryStatements.Count; i++)
            {
                statements.Insert(index + i, tryStatements[i]);
            }

            return(true);
        }
예제 #3
0
 private void RemoveLastIfYieldBreak(StatementCollection collection)
 {
     V_0 = collection.get_Count() - 1;
     V_1 = collection.get_Item(V_0);
     if (V_1.get_CodeNodeType() == 5 && (V_1 as ExpressionStatement).get_Expression().get_CodeNodeType() == 55 && String.IsNullOrEmpty(V_1.get_Label()) && this.yieldData.get_YieldBreaks().get_Count() != 1 || this.yieldData.get_YieldReturns().get_Count() != 0)
     {
         collection.RemoveAt(V_0);
     }
     return;
 }
 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);
 }
        private void RemoveFirstStatements(StatementCollection statements, int count)
        {
            for (int i = 0; i + count < statements.Count; i++)
            {
                statements[i] = statements[i + count];
            }

            while (count-- > 0)
            {
                statements.RemoveAt(statements.Count - 1);
            }
        }
        public bool TryMatch(StatementCollection statements, out int startIndex, out Statement result, out int replacedStatementsCount)
        {
            replacedStatementsCount = 0;
            startIndex = -1;
            result     = null;
            bool inlinedSuccessfully = false;

            if (statements.Count == 0)
            {
                return(false);
            }

            HashSet <VariableDefinition> markedForRemoval = new HashSet <VariableDefinition>();

            List <int> positionsToInline = GetStatementsToInline(statements);

            for (int i = positionsToInline.Count - 1; i >= 0; i--)
            {
                int index = positionsToInline[i];

                ExpressionStatement defineExpression = statements[index] as ExpressionStatement;
                VariableDefinition  variable         = ((defineExpression.Expression as BinaryExpression).Left as VariableReferenceExpression).Variable.Resolve();

                if (index == statements.Count - 1 || !string.IsNullOrEmpty(defineExpression.Label))
                {
                    markedForRemoval.Add(variable);
                    continue;
                }

                List <Instruction> instructions = new List <Instruction>(defineExpression.Expression.MappedInstructions);
                instructions.AddRange((defineExpression.Expression as BinaryExpression).Left.UnderlyingSameMethodInstructions);
                Expression value = (defineExpression.Expression as BinaryExpression).Right.CloneAndAttachInstructions(instructions);

                ICodeNode resultNode;
                if (inliner.TryInlineVariable(variable, value, statements[index + 1], ShouldInlineAggressively(variable), out resultNode))
                {
                    statements.RemoveAt(index);
                    inlinedSuccessfully = true;
                    markedForRemoval.Add(variable);
                    methodContext.RemoveVariable(variable);
                    // the statement containing the inlined variable is not at index, since we removed the variable declaration statement
                    statements[index] = (Statement)this.dereferencer.Visit(statements[index]);
                }
            }

            foreach (VariableDefinition variable in markedForRemoval)
            {
                patternsContext.VariableToSingleAssignmentMap.Remove(variable);
                patternsContext.VariableToDefineUseCountContext.Remove(variable);
            }

            return(inlinedSuccessfully);
        }
        private void RemoveLastIfYieldBreak(StatementCollection collection)
        {
            int       lastIndex   = collection.Count - 1;
            Statement lastElement = collection[lastIndex];

            if ((lastElement.CodeNodeType == CodeNodeType.ExpressionStatement &&
                 (lastElement as ExpressionStatement).Expression.CodeNodeType == CodeNodeType.YieldBreakExpression &&
                 string.IsNullOrEmpty(lastElement.Label) && (yieldData.YieldBreaks.Count != 1 || yieldData.YieldReturns.Count != 0)))
            {
                collection.RemoveAt(lastIndex);
            }
        }
        public bool TryMatch(StatementCollection statements, out int startIndex, out Statement result, out int replacedStatementsCount)
        {
            replacedStatementsCount = 0;
            startIndex = -1;
            result = null;
            bool inlinedSuccessfully = false;

            if(statements.Count == 0)
            {
                return false;
            }

            HashSet<VariableDefinition> markedForRemoval = new HashSet<VariableDefinition>();

            List<int> positionsToInline = GetStatementsToInline(statements);

            for (int i = positionsToInline.Count - 1; i >= 0; i--)
            {
                int index = positionsToInline[i];

                ExpressionStatement defineExpression = statements[index] as ExpressionStatement;
                VariableDefinition variable = ((defineExpression.Expression as BinaryExpression).Left as VariableReferenceExpression).Variable.Resolve();

                if (index == statements.Count - 1 || !string.IsNullOrEmpty(defineExpression.Label))
                {
                    markedForRemoval.Add(variable);
                    continue;
                }

                List<Instruction> instructions = new List<Instruction>(defineExpression.Expression.MappedInstructions);
                instructions.AddRange((defineExpression.Expression as BinaryExpression).Left.UnderlyingSameMethodInstructions);
                Expression value = (defineExpression.Expression as BinaryExpression).Right.CloneAndAttachInstructions(instructions);

                ICodeNode resultNode;
                if (inliner.TryInlineVariable(variable, value, statements[index + 1], ShouldInlineAggressively(variable), out resultNode))
                {
                    statements.RemoveAt(index);
                    inlinedSuccessfully = true;
                    markedForRemoval.Add(variable);
                    methodContext.RemoveVariable(variable);
                }
            }

            foreach (VariableDefinition variable in markedForRemoval)
            {
                patternsContext.VariableToSingleAssignmentMap.Remove(variable);
                patternsContext.VariableToDefineUseCountContext.Remove(variable);
            }

            return inlinedSuccessfully;
        }
            private void RemoveRange(StatementCollection theCollection, int from, int to)
            {
                for (; to < theCollection.Count; from++, to++)
                {
                    theCollection[from] = theCollection[to];
                }

                int count = theCollection.Count;

                while (from < count)
                {
                    theCollection.RemoveAt(--count);
                }
            }
 private void RemoveRange(StatementCollection theCollection, int from, int to)
 {
     while (to < theCollection.get_Count())
     {
         theCollection.set_Item(from, theCollection.get_Item(to));
         from = from + 1;
         to   = to + 1;
     }
     V_0 = theCollection.get_Count();
     while (from < V_0)
     {
         stackVariable21 = V_0 - 1;
         V_0             = stackVariable21;
         theCollection.RemoveAt(stackVariable21);
     }
     return;
 }
예제 #11
0
        private void RemoveRange(StatementCollection statements, int startIndex, int length)
        {
            if (length == 0)
            {
                return;
            }
            int count = statements.Count;

            for (int i = startIndex; i + length < count; i++)
            {
                statements[i] = statements[i + length];
            }

            while (length > 0)
            {
                statements.RemoveAt(--count);
                length--;
            }
        }
 private void RemoveRange(StatementCollection statements, int startIndex, int length)
 {
     if (length == 0)
     {
         return;
     }
     V_0 = statements.get_Count();
     V_1 = startIndex;
     while (V_1 + length < V_0)
     {
         statements.set_Item(V_1, statements.get_Item(V_1 + length));
         V_1 = V_1 + 1;
     }
     while (length > 0)
     {
         stackVariable23 = V_0 - 1;
         V_0             = stackVariable23;
         statements.RemoveAt(stackVariable23);
         length = length - 1;
     }
     return;
 }
            private void RemoveRange(StatementCollection theCollection, int from, int to)
            {
                for (; to < theCollection.Count; from++, to++)
                {
                    theCollection[from] = theCollection[to];
                }

                int count = theCollection.Count;
                while (from < count)
                {
                    theCollection.RemoveAt(--count);
                }
            }
        private void RemoveRange(StatementCollection statements, int startIndex, int length)
        {
            if (length == 0)
            {
                return;
            }
            int count = statements.Count;
            for (int i = startIndex; i + length < count; i++)
            {
                statements[i] = statements[i + length];
            }

            while (length > 0)
            {
                statements.RemoveAt(--count);
                length--;
            }
        }
        private void RemoveLastIfYieldBreak(StatementCollection collection)
        {
            int lastIndex = collection.Count - 1;
            Statement lastElement = collection[lastIndex];

            if ((lastElement.CodeNodeType == CodeNodeType.ExpressionStatement &&
                (lastElement as ExpressionStatement).Expression.CodeNodeType == CodeNodeType.YieldBreakExpression &&
                string.IsNullOrEmpty(lastElement.Label) && (yieldData.YieldBreaks.Count != 1 || yieldData.YieldReturns.Count != 0)))
            {
                collection.RemoveAt(lastIndex);
            }
        }
        private bool TryRemoveOuterTryCatch(StatementCollection statements)
        {
            int index = 0;
            for (; index < statements.Count; index++)
            {
                Statement currentStatement = statements[index];
                if (currentStatement.CodeNodeType == CodeNodeType.TryStatement && (currentStatement as TryStatement).CatchClauses.Count == 1)
                {
                    break;
                }
            }

            if (index == statements.Count)
            {
                return false;
            }

            TryStatement theTry = statements[index] as TryStatement;
            StatementCollection tryStatements = theTry.Try.Statements;

            if (asyncData.StateField == null && !TryGetStateField(theTry.CatchClauses[0].Body))
            {
                return false;
            }

            statements.RemoveAt(index);
            for (int i = 0; i < tryStatements.Count; i++)
            {
                statements.Insert(index + i, tryStatements[i]);
            }

            return true;
        }
        private void RemoveFirstStatements(StatementCollection statements, int count)
        {
            for (int i = 0; i + count < statements.Count; i++)
            {
                statements[i] = statements[i + count];
            }

            while (count-- > 0)
            {
                statements.RemoveAt(statements.Count - 1);
            }
        }