示例#1
0
 public virtual void typeswitch_section(typeswitch_section ast, SymbolTable bindings, ref bool hasdefault)
 {
     foreach (switch_label x in ast.labels)
     {
         if (x is typeswitch_label)
         {
             typeswitch_label((typeswitch_label)x, bindings);
         }
         else if (x is switch_default)
         {
             if (hasdefault)
             {
                 msg.Error(ast.begin, "duplicate default label");
             }
             hasdefault = true;
         }
     }
     if (ast.id != null)
     {
         ast.sym      = ast.block.AddLocal(ast.id, msg);
         ast.sym.Type = ((typeswitch_label)ast.labels[0]).typelabel.sym;
     }
     foreach (statement x in ast.stmts)
     {
         statement(x, ast.block.locals);
     }
 }
示例#2
0
 public virtual void typeswitch_section(typeswitch_section ast, int indent)
 {
     if (ast.labels[0] is switch_default)
     {
         defaultStmts = ast.stmts;
         return;
     }
     Write("if (", indent);
     for (int i = 0; i < ast.labels.Count; i++)
     {
         if (i > 0)
         {
             Write(" || ");
         }
         Write("{0} is ", id);
         visit(ast.labels[i], 0);
     }
     WriteLine(") {{");
     if (ast.id != null)
     {
         visit(ast.labels[0], indent + 1);
         Write(" {0} = (", ast.id.str);
         visit(ast.labels[0]);
         WriteLine("){0};", id);
     }
     foreach (statement x in ast.stmts)
     {
         visit(x, indent + 1);
     }
     WriteLine("}}", indent);
 }
示例#3
0
 void typeswitch_section(typeswitch_section ast)
 {
     foreach (statement s in ast.stmts)
     {
         statement(s);
     }
 }
 public virtual void typeswitch_section(typeswitch_section ast)
 {
     foreach (switch_label x in ast.labels)
     {
         if (x is typeswitch_label)
         {
             typeswitch_label((typeswitch_label)x);
         }
     }
     foreach (statement x in ast.stmts)
     {
         statement(x);
     }
 }
示例#5
0
    public virtual void typeswitch_section(typeswitch_section ast, SymbolTable bindings)
    {
        ast.block = new Block(bindings);
        statement s = null;

        foreach (statement x in ast.stmts)
        {
            statement(s = x, ast.block.locals);
        }
        if (!(s is return_statement || s is break_statement ||
              s is continue_statement || s is goto_statement ||
              s is goto_case_statement || s is goto_default_statement ||
              s is throw_statement))
        {
            msg.Error(s.begin, "missing break or other control flow statement in typeswitch case");
        }
    }
        void typeswitch_section(typeswitch_section ast, typeswitch_statement sw, ref typeswitch_section default_section)
        {
            if (ast.labels.Count == 1 && ast.labels[0] is switch_default)
            {
                default_section = ast;
                return;
            }
            int lab = genLabel(2);

            if (ast.id != null)
            {
                parent.comment(ast, "case {0} ({1}):", ast.sym.Type.Name, ast.id.str);
                EmitLoad(sw.var);
                Emit(OpCodes.Isinst, ast.sym.Type);
                int temp = newLocal(ast.sym.Type);
                EmitStore(temp);
                EmitLoad(temp);
                gotoLabel(OpCodes.Brfalse, lab + 1);
                EmitLoad(temp);
                EmitStore(ast.sym);
            }
            else
            {
                foreach (switch_label s in ast.labels)
                {
                    parent.comment(s, "case {0}:", ((typeswitch_label)s).typelabel.sym.Name);
                    EmitLoad(sw.var);
                    Emit(OpCodes.Isinst, ((typeswitch_label)s).typelabel.sym);
                    if (s == ast.labels[ast.labels.Count - 1])
                    {
                        gotoLabel(OpCodes.Brfalse, lab + 1);
                    }
                    else
                    {
                        gotoLabel(OpCodes.Brtrue, lab);
                    }
                }
                defLabel(lab);
            }
            foreach (statement s in ast.stmts)
            {
                statement(s);
            }
            defLabel(lab + 1);
        }
        public virtual void typeswitch_statement(typeswitch_statement ast)
        {
            parent.comment(ast, "typeswitch ({0})", source.ToString(ast.expr));
            ast.lab = genLabel(3);
            ast.var = newLocal(ast.expr.typ);
            expression(ast.expr);
            EmitStore(ast.var);
            typeswitch_section default_section = null;

            foreach (typeswitch_section s in ast.sections)
            {
                typeswitch_section(s, ast, ref default_section);
            }
            defLabel(ast.lab);
            if (default_section != null)
            {
                parent.comment(default_section, "default:");
                foreach (statement s in default_section.stmts)
                {
                    statement(s);
                }
            }
            defLabel(ast.lab + 2);
        }