コード例 #1
0
        public override TextBuffer ToJava(int indent, BytecodeMappingTracer tracer)
        {
            SwitchHelper.Simplify(this);
            TextBuffer buf = new TextBuffer();

            buf.Append(ExprProcessor.ListToJava(varDefinitions, indent, tracer));
            buf.Append(first.ToJava(indent, tracer));
            if (IsLabeled())
            {
                buf.AppendIndent(indent).Append("label").Append(this.id.ToString()).Append(":").AppendLineSeparator
                    ();
                tracer.IncrementCurrentSourceLine();
            }
            buf.AppendIndent(indent).Append(headexprent[0].ToJava(indent, tracer)).Append(" {"
                                                                                          ).AppendLineSeparator();
            tracer.IncrementCurrentSourceLine();
            VarType switch_type = headexprent[0].GetExprType();

            for (int i = 0; i < caseStatements.Count; i++)
            {
                Statement       stat   = caseStatements[i];
                List <StatEdge> edges  = caseEdges[i];
                List <Exprent>  values = caseValues[i];
                for (int j = 0; j < edges.Count; j++)
                {
                    if (edges[j] == default_edge)
                    {
                        buf.AppendIndent(indent).Append("default:").AppendLineSeparator();
                    }
                    else
                    {
                        buf.AppendIndent(indent).Append("case ");
                        Exprent value = values[j];
                        if (value is ConstExprent)
                        {
                            value = value.Copy();
                            ((ConstExprent)value).SetConstType(switch_type);
                        }
                        if (value is FieldExprent && ((FieldExprent)value).IsStatic())
                        {
                            // enum values
                            buf.Append(((FieldExprent)value).GetName());
                        }
                        else
                        {
                            buf.Append(value.ToJava(indent, tracer));
                        }
                        buf.Append(":").AppendLineSeparator();
                    }
                    tracer.IncrementCurrentSourceLine();
                }
                buf.Append(ExprProcessor.JmpWrapper(stat, indent + 1, false, tracer));
            }
            buf.AppendIndent(indent).Append("}").AppendLineSeparator();
            tracer.IncrementCurrentSourceLine();
            return(buf);
        }