Exemple #1
0
        private CompilerOptimizedSwitchByStringStatement ComposeSwitch(SwitchData data)
        {
            CompilerOptimizedSwitchByStringStatement @switch = new CompilerOptimizedSwitchByStringStatement(data.SwitchExpression, data.SwitchExpressionLoadInstructions);

            foreach (KeyValuePair <Expression, BlockStatement> pair in data.CaseConditionToBlockMap)
            {
                if (pair.Value != null && SwitchHelpers.BlockHasFallThroughSemantics(pair.Value))
                {
                    pair.Value.AddStatement(new BreakSwitchCaseStatement());
                }

                @switch.AddCase(new ConditionCase(pair.Key, pair.Value));
            }

            if (data.HaveDefaultCase)
            {
                if (SwitchHelpers.BlockHasFallThroughSemantics(data.DefaultCase))
                {
                    data.DefaultCase.AddStatement(new BreakSwitchCaseStatement());
                }

                @switch.AddCase(new DefaultCase(data.DefaultCase));
            }

            return(@switch);
        }
Exemple #2
0
 private CompilerOptimizedSwitchByStringStatement ComposeSwitch(CreateCompilerOptimizedSwitchByStringStatementsStep.SwitchData data)
 {
     V_0 = new CompilerOptimizedSwitchByStringStatement(data.get_SwitchExpression(), data.get_SwitchExpressionLoadInstructions());
     V_1 = data.get_CaseConditionToBlockMap().GetEnumerator();
     try
     {
         while (V_1.MoveNext())
         {
             V_2 = V_1.get_Current();
             if (V_2.get_Value() != null && SwitchHelpers.BlockHasFallThroughSemantics(V_2.get_Value()))
             {
                 V_2.get_Value().AddStatement(new BreakSwitchCaseStatement());
             }
             V_0.AddCase(new ConditionCase(V_2.get_Key(), V_2.get_Value()));
         }
     }
     finally
     {
         ((IDisposable)V_1).Dispose();
     }
     if (data.get_HaveDefaultCase())
     {
         if (SwitchHelpers.BlockHasFallThroughSemantics(data.get_DefaultCase()))
         {
             data.get_DefaultCase().AddStatement(new BreakSwitchCaseStatement());
         }
         V_0.AddCase(new DefaultCase(data.get_DefaultCase()));
     }
     return(V_0);
 }