コード例 #1
0
 private void Parse_SwitchStmt()
 {
     int label = base.NewLabel();
     int num2 = base.NewLabel();
     IntegerList list = new IntegerList(true);
     IntegerList list2 = new IntegerList(true);
     IntegerStack stack = new IntegerStack();
     int num3 = base.NewVar();
     this.Gen(base.code.OP_ASSIGN, num3, base.TRUE_id, num3);
     base.BreakStack.Push(label);
     this.Match("switch");
     base.BeginBlock();
     this.Match('(');
     int num4 = this.Parse_Expression();
     this.Match(')');
     this.Match('{');
     Label_008D:
     if (base.IsCurrText("case"))
     {
         this.Match("case");
         stack.Push(base.NewLabel());
         int avalue = this.Parse_Expression();
         list.AddObject(avalue, stack.Peek());
         this.Gen(base.code.OP_EQ, num4, avalue, num3);
         this.Gen(base.code.OP_GO_TRUE, stack.Peek(), num3, 0);
     }
     else
     {
         if (!base.IsCurrText("default"))
         {
             while (stack.Count > 0)
             {
                 base.SetLabelHere(stack.Peek());
                 stack.Pop();
             }
             int num6 = base.NewLabel();
             this.Gen(base.code.OP_GO_FALSE, num6, num3, 0);
             while ((!base.IsCurrText("case") && !base.IsCurrText("default")) && !base.IsCurrText('}'))
             {
                 if (base.IsCurrText("goto"))
                 {
                     this.Match("goto");
                     if (base.IsCurrText("case"))
                     {
                         this.Match("case");
                         int num7 = this.Parse_Expression();
                         this.Gen(base.code.OP_GOTO_START, 0, 0, 0);
                         list2.AddObject(num7, base.CodeCard);
                         this.Match(';');
                     }
                     else if (base.IsCurrText("default"))
                     {
                         this.Match("default");
                         this.Gen(base.code.OP_GOTO_START, num2, 0, 0);
                         this.Match(';');
                     }
                     else
                     {
                         int num8 = this.Parse_Ident();
                         this.Gen(base.code.OP_GOTO_START, num8, 0, 0);
                         this.Match(';');
                     }
                 }
                 else
                 {
                     this.Parse_Stmt();
                 }
             }
             base.SetLabelHere(num6);
             if (base.IsCurrText('}'))
             {
                 base.BreakStack.Pop();
                 base.SetLabelHere(label);
                 base.EndBlock();
                 this.Match('}');
                 for (int i = 0; i < list2.Count; i++)
                 {
                     int id = list2[i];
                     int n = (int) list2.Objects[i];
                     object val = base.GetVal(id);
                     bool flag = false;
                     for (int j = 0; j < list.Count; j++)
                     {
                         int num13 = list[j];
                         int num14 = (int) list.Objects[j];
                         object obj3 = base.GetVal(num13);
                         if ((val.GetType() == obj3.GetType()) && (val == obj3))
                         {
                             flag = true;
                             base.GenAt(n, base.code.OP_GOTO_START, num14, 0, 0);
                             break;
                         }
                     }
                     if (!flag)
                     {
                         base.CodeCard = n;
                         base.RaiseErrorEx(true, "CS0159. No such label '{0}' within the scope of the goto statement.", new object[] { val.ToString() });
                     }
                 }
                 return;
             }
             goto Label_008D;
         }
         this.Match("default");
         base.SetLabelHere(num2);
         this.Gen(base.code.OP_ASSIGN, num3, base.TRUE_id, num3);
     }
     this.Match(':');
     goto Label_008D;
 }
コード例 #2
0
ファイル: Code.cs プロジェクト: RainsSoft/CSLiteScript
 public IntegerStack RecreateLevelStack(int init_n)
 {
     Module module = this.GetModule(init_n);
     if (module == null)
     {
         return null;
     }
     IntegerStack stack = new IntegerStack();
     for (int i = module.P1; i <= module.P2; i++)
     {
         if (this[i].op == this.OP_CREATE_METHOD)
         {
             stack.Push(this[i].arg1);
         }
         else if (this[i].op == this.OP_END_METHOD)
         {
             stack.Pop();
         }
         else if (this[i].op == this.OP_BEGIN_USING)
         {
             stack.Push(this[i].arg1);
         }
         else if (this[i].op == this.OP_END_USING)
         {
             stack.Pop();
         }
         if (i == init_n)
         {
             return stack;
         }
     }
     return stack;
 }