protected override bool ProcessCFG()
        {
            StateMachineDisposeAnalyzer disposeAnalyzer = new StateMachineDisposeAnalyzer(moveNextMethodContext.Method);
            StateControllerRemover      controllerRemover;
            YieldStateMachineVersion    machineVersion = disposeAnalyzer.ProcessDisposeMethod();

            if (machineVersion == YieldStateMachineVersion.V1)
            {
                controllerRemover = new StateControllerRemover(moveNextMethodContext);
            }
            else if (machineVersion == YieldStateMachineVersion.V2)
            {
                controllerRemover = new DisposingStateControllerRemover(moveNextMethodContext, disposeAnalyzer.StateField, disposeAnalyzer.DisposingField);
                StateMachineDoFinallyCheckRemover doFinallyCheckRemover = new StateMachineDoFinallyCheckRemover(moveNextMethodContext);
                if (!doFinallyCheckRemover.MarkFinallyConditionsForRemoval())
                {
                    return(false);
                }
                toBeRemoved.UnionWith(doFinallyCheckRemover.BlocksMarkedForRemoval);
            }
            else
            {
                return(false);
            }

            if (!controllerRemover.RemoveStateMachineController())
            {
                return(false);
            }

            toBeRemoved.UnionWith(controllerRemover.BlocksMarkedForRemoval);

            SwitchData switchData = controllerRemover.SwitchData;
            YieldStateMachineControlFlowRebuilder controlFlowRebuilder =
                new YieldStateMachineControlFlowRebuilder(moveNextMethodContext, switchData, controllerRemover.StateField);

            if (!controlFlowRebuilder.ProcessEndBlocks())
            {
                return(false);
            }

            toBeRemoved.UnionWith(controlFlowRebuilder.BlocksMarkedForRemoval);
            StateMachineCFGCleaner cfgCleaner = new StateMachineCFGCleaner(theCFG, switchData, switchData.OrderedCasesArray[0]);

            if (!cfgCleaner.CleanUpTheCFG(toBeRemoved))
            {
                return(false);
            }

            YieldFieldsInformation fieldsInfo = new YieldFieldsInformation(controllerRemover.StateField,
                                                                           controlFlowRebuilder.CurrentItemField, controlFlowRebuilder.ReturnFlagVariable);

            this.moveNextMethodContext.YieldData =
                new YieldData(machineVersion, controlFlowRebuilder.YieldReturnBlocks,
                              controlFlowRebuilder.YieldBreakBlocks, fieldsInfo, disposeAnalyzer.YieldsExceptionData);
            return(true);
        }
예제 #2
0
        protected override bool ProcessCFG()
        {
            if (!GetStateField() || !RemoveStateSavingBlocks())
            {
                return(false);
            }

            AsyncMoveNextMethodAnalyzer         analyzer = new AsyncMoveNextMethodAnalyzer(this.moveNextMethodContext, this.stateField);
            StateMachineFinallyCheckRemoverBase finallyCheckRemover;

            if (analyzer.StateMachineVersion == AsyncStateMachineVersion.V1)
            {
                finallyCheckRemover = new StateMachineDoFinallyCheckRemover(this.moveNextMethodContext);
                finallyCheckRemover.MarkFinallyConditionsForRemoval(analyzer.DoFinallyVariable);
            }
            else
            {
                finallyCheckRemover = new StateMachineFinallyStateCheckRemover(this.moveNextMethodContext);
                finallyCheckRemover.MarkFinallyConditionsForRemoval(analyzer.StateVariable);
            }

            toBeRemoved.UnionWith(finallyCheckRemover.BlocksMarkedForRemoval);

            AsyncStateControllerRemover asyncControllerRemover =
                new AsyncStateControllerRemover(this.moveNextMethodContext, this.stateField, analyzer.DoFinallyVariable, analyzer.StateMachineVersion);

            if (!asyncControllerRemover.RemoveStateMachineController() && asyncControllerRemover.FoundControllerBlocks)
            {
                return(false);
            }
            toBeRemoved.UnionWith(asyncControllerRemover.BlocksMarkedForRemoval);

            SwitchData controllerSwitchData;

            if (asyncControllerRemover.SwitchData != null)
            {
                controllerSwitchData = asyncControllerRemover.SwitchData;
            }
            else if (!CreateFakeSwitchData(out controllerSwitchData))
            {
                return(false);
            }

            StateMachineCFGCleaner cfgCleaner = new StateMachineCFGCleaner(this.theCFG, controllerSwitchData, controllerSwitchData.DefaultCase);

            if (!cfgCleaner.CleanUpTheCFG(toBeRemoved))
            {
                return(false);
            }

            this.moveNextMethodContext.AsyncData = new Decompiler.AsyncData(stateField, awaiterVariables, analyzer.variableToFieldMap);
            return(true);
        }
 protected override bool ProcessCFG()
 {
     V_0 = new StateMachineDisposeAnalyzer(this.moveNextMethodContext.get_Method());
     V_2 = V_0.ProcessDisposeMethod();
     if (V_2 != 1)
     {
         if (V_2 != 2)
         {
             return(false);
         }
         V_1 = new DisposingStateControllerRemover(this.moveNextMethodContext, V_0.get_StateField(), V_0.get_DisposingField());
         V_6 = new StateMachineDoFinallyCheckRemover(this.moveNextMethodContext);
         if (!V_6.MarkFinallyConditionsForRemoval())
         {
             return(false);
         }
         this.toBeRemoved.UnionWith(V_6.get_BlocksMarkedForRemoval());
     }
     else
     {
         V_1 = new StateControllerRemover(this.moveNextMethodContext, null);
     }
     if (!V_1.RemoveStateMachineController())
     {
         return(false);
     }
     this.toBeRemoved.UnionWith(V_1.get_BlocksMarkedForRemoval());
     V_3 = V_1.get_SwitchData();
     V_4 = new YieldStateMachineControlFlowRebuilder(this.moveNextMethodContext, V_3, V_1.get_StateField());
     if (!V_4.ProcessEndBlocks())
     {
         return(false);
     }
     this.toBeRemoved.UnionWith(V_4.get_BlocksMarkedForRemoval());
     if (!(new StateMachineCFGCleaner(this.theCFG, V_3, V_3.get_OrderedCasesArray()[0])).CleanUpTheCFG(this.toBeRemoved))
     {
         return(false);
     }
     V_5 = new YieldFieldsInformation(V_1.get_StateField(), V_4.get_CurrentItemField(), V_4.get_ReturnFlagVariable());
     this.moveNextMethodContext.set_YieldData(new YieldData(V_2, V_4.get_YieldReturnBlocks(), V_4.get_YieldBreakBlocks(), V_5, V_0.get_YieldsExceptionData()));
     return(true);
 }
 protected override bool ProcessCFG()
 {
     if (!this.GetStateField() || !this.RemoveStateSavingBlocks())
     {
         return(false);
     }
     V_0 = new AsyncMoveNextMethodAnalyzer(this.moveNextMethodContext, this.stateField);
     if (V_0.get_StateMachineVersion() != AsyncStateMachineVersion.V1)
     {
         V_1 = new StateMachineFinallyStateCheckRemover(this.moveNextMethodContext);
         V_1.MarkFinallyConditionsForRemoval(V_0.get_StateVariable());
     }
     else
     {
         V_1 = new StateMachineDoFinallyCheckRemover(this.moveNextMethodContext);
         V_1.MarkFinallyConditionsForRemoval(V_0.get_DoFinallyVariable());
     }
     this.toBeRemoved.UnionWith(V_1.get_BlocksMarkedForRemoval());
     V_2 = new AsyncStateControllerRemover(this.moveNextMethodContext, this.stateField, V_0.get_DoFinallyVariable(), V_0.get_StateMachineVersion());
     if (!V_2.RemoveStateMachineController() && V_2.get_FoundControllerBlocks())
     {
         return(false);
     }
     this.toBeRemoved.UnionWith(V_2.get_BlocksMarkedForRemoval());
     if (V_2.get_SwitchData() == null)
     {
         if (!this.CreateFakeSwitchData(out V_3))
         {
             return(false);
         }
     }
     else
     {
         V_3 = V_2.get_SwitchData();
     }
     if (!(new StateMachineCFGCleaner(this.theCFG, V_3, V_3.get_DefaultCase())).CleanUpTheCFG(this.toBeRemoved))
     {
         return(false);
     }
     this.moveNextMethodContext.set_AsyncData(new AsyncData(this.stateField, this.awaiterVariables, V_0.variableToFieldMap));
     return(true);
 }