Example #1
0
 public override void Visit(SwitchStatement node)
 {
   VisitNode(node.Expression);
   VisitNodes(node.CaseClauses);
   Visit((Statement)node);
 }
Example #2
0
      public override void Visit(SwitchStatement node)
      {
        PushLocation(node);

        var switchDone = _ilGen.DefineLabel();
        _labelInfos.PushLabel(null, switchDone);

        var labels = new System.Reflection.Emit.Label[node.CaseClauses.Count];
        var defaultTargetIndex = -1;


        for (var caseIndex = 0; caseIndex < node.CaseClauses.Count; ++caseIndex)
        {
          var c = node.CaseClauses[caseIndex];
          var caseTarget = _ilGen.DefineLabel();
          labels[caseIndex] = caseTarget;
          if (!c.IsDefault)
          {
            var stackState = _localVars.GetTemporaryStackState();
            VisitNode(c.Comparison);
            AsBoolean();
            _ilGen.Brtrue(caseTarget);
            _localVars.PopTemporariesAfter(stackState);
          }
          else
            defaultTargetIndex = caseIndex;
        }
        if (defaultTargetIndex != -1)
          _ilGen.Br(labels[defaultTargetIndex]);

        for (var caseIndex = 0; caseIndex < node.CaseClauses.Count; ++caseIndex)
        {
          var c = node.CaseClauses[caseIndex];
          _ilGen.MarkLabel(labels[caseIndex]);
          VisitNodes(c.Body.Statements);
        }

        _ilGen.MarkLabel(switchDone);
        _labelInfos.PopLabel(null);

        PopLocation();
      }
      public override void Visit(SwitchStatement node)
      {
        PushLocation(node);

        var breakIndexes = new LinkedList<int>();
        _labelInfos.PushLabel(null, breakIndexes);

        ///We know all case.Compare expressions should only generate one boolean value, except the the default: case
        var comparisionResultPointer = _stackModel.StackPointer;

        var caseCompareIndexes = new int[node.CaseClauses.Count]; // We will fill those slots after we know the begining index of blocks
        var defaultTargetIndex = -1;


        for (var caseIndex = 0; caseIndex < node.CaseClauses.Count; ++caseIndex)
        {
          var c = node.CaseClauses[caseIndex];

          if (!c.IsDefault)
          {
            VisitNode(c.Comparison);
            Debug.Assert(_stackModel.StackPointer == comparisionResultPointer + 1, "Invalid situation, stack state did not change correctly in switch statement");

            ///We will later generate the BrTrue IC here which will Pop the comparision result
            ///but now we should set the StackPointer correctly for the next CaseClause to visit
            _stackModel.Pop(1);
          }
          else
          {
            defaultTargetIndex = caseIndex;
          }
          caseCompareIndexes[caseIndex] = ReserveNewICIndex();
        }
        Debug.Assert(_stackModel.StackPointer == comparisionResultPointer, "Invalid stack pointer value! Expected {0} instead of {1}", comparisionResultPointer, _stackModel.StackPointer);


        for (var caseIndex = 0; caseIndex < node.CaseClauses.Count; ++caseIndex)
        {
          var c = node.CaseClauses[caseIndex];
          BeginICMethod(c);
          if (c.IsDefault)
          {
            Debug.Assert(caseIndex == defaultTargetIndex, "Invalid situation");
            Br(GetCurrentICIndex() + 1);
          }
          else
            Brtrue(comparisionResultPointer, GetCurrentICIndex() + 1);
          EndICMethod(caseCompareIndexes[caseIndex]);

          VisitNodes(c.Body.Statements);
        }

        UpdateJumps(GetCurrentICIndex() + 1, breakIndexes);

        _labelInfos.PopLabel(null);

        PopLocation();
      }
Example #4
0
 public override void Visit(SwitchStatement node) { Visit((Statement)node); }
Example #5
0
 public override void Visit(SwitchStatement node)
 {
     Visit((Statement)node);
 }
Example #6
0
 public SwitchStatement MakeSwitchStatement(Scope scope, IExpression expression, ICaseClauseList caseClauses)
 {
   var expr = (Expression)expression;
   foreach (var c in caseClauses)
   {
     if (!c.IsDefault)
     {
       c.Comparison = MakeSameExpressionInternal(expr, c.Expression);
       c.Comparison.AddUser(c);
     }
   }
   var n = new SwitchStatement(expr, caseClauses);
   return n;
 }
Example #7
0
 public abstract void Visit(SwitchStatement node);
Example #8
0
 public override void Visit(SwitchStatement node)
 {
   throw new NotImplementedException();
 }
Example #9
0
 public override void Visit(SwitchStatement node) { VisitNodes(node.CaseClauses); }