コード例 #1
0
ファイル: DepthFirstVisitor.cs プロジェクト: reshadi2/mcjs
 public override void Visit(SwitchStatement node)
 {
   VisitNode(node.Expression);
   VisitNodes(node.CaseClauses);
   Visit((Statement)node);
 }
コード例 #2
0
ファイル: CodeGenerator.cs プロジェクト: reshadi2/mcjs
      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();
      }
コード例 #3
0
      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();
      }
コード例 #4
0
 public override void Visit(SwitchStatement node) { Visit((Statement)node); }
コード例 #5
0
 public override void Visit(SwitchStatement node)
 {
     Visit((Statement)node);
 }
コード例 #6
0
ファイル: NodeFactory.cs プロジェクト: reshadi2/mcjs
 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;
 }
コード例 #7
0
ファイル: INodeVisitor.cs プロジェクト: vrajeshbhavsar/mcjs
 public abstract void Visit(SwitchStatement node);
コード例 #8
0
ファイル: CodeGeneratorBase.cs プロジェクト: reshadi2/mcjs
 public override void Visit(SwitchStatement node)
 {
   throw new NotImplementedException();
 }
コード例 #9
0
 public override void Visit(SwitchStatement node) { VisitNodes(node.CaseClauses); }