コード例 #1
0
ファイル: IfThenElseBlock.cs プロジェクト: Screeder/GameFiles
        public override void Print(Output output)
        {
            output.Print("if ");

            m_branch.AsExpression(m_r).Print(output);

            output.Print(" then");
            output.PrintLine();

            output.IncreaseIndent();

            //Handle the case where the "then" is empty in if-then-else.
            //The jump over the else block is falsely detected as a break.
            if (m_statements.Count == 1 && m_statements[0] is Break)
            {
                var b = m_statements[0] as Break;

                if (b.Target == m_loopback)
                {
                    output.DecreaseIndent();
                    return;
                }
            }

            Statement.PrintSequence(output, m_statements);

            output.DecreaseIndent();

            if (m_emptyElse)
            {
                output.PrintLine("else");
                output.PrintLine("end");
            }
        }
コード例 #2
0
ファイル: ElseEndBlock.cs プロジェクト: Screeder/GameFiles
        public override void Print(Output output)
        {
            output.Print("else");

            if (m_statements.Count == 1 && m_statements[0] is IfThenEndBlock)
            {    
                m_statements[0].Print(output);
            }
            else if (m_statements.Count == 2 && m_statements[0] is IfThenElseBlock && m_statements[1] is ElseEndBlock)
            {
                m_statements[0].Print(output);
                m_statements[1].Print(output);
            }
            else
            {
                output.PrintLine();

                output.IncreaseIndent();

                Statement.PrintSequence(output, m_statements);

                output.DecreaseIndent();
                
                output.Print("end");
            }
        }
コード例 #3
0
        private void PrintMain(Output output, Decompiler d, bool includeFirst)
        {
            output.Print("(");

            var start = includeFirst ? 0 : 1;

            if (m_function.NumParams > start)
            {
                new VariableTarget(d.DeclList[start]).Print(output);

                for (int i = start + 1; i < m_function.NumParams; i++)
                {
                    output.Print(", ");
                    new VariableTarget(d.DeclList[i]).Print(output);
                }
            }

            if ((m_function.VarArg & 1) == 1)
            {
                output.Print((m_function.NumParams > start) ? ", ..." : "...");
            }

            output.Print(")");
            output.PrintLine();

            output.IncreaseIndent();

            d.Decompile();
            d.Print(output);

            output.DecreaseIndent();
            output.Print("end");
            //output.PrintLine(); //This is an extra space for formatting
        }
コード例 #4
0
        public override void Print(Output output)
        {
            output.Print("for ");
            m_r.GetTarget(m_register + 3, Begin - 1).Print(output);
            output.Print(" = ");
            m_r.GetValue(m_register, Begin - 1).Print(output);
            output.Print(", ");
            m_r.GetValue(m_register + 1, Begin - 1).Print(output);

            var step = m_r.GetValue(m_register + 2, Begin - 1);

            if (!step.IsInteger || step.AsInteger() != 1)
            {
                output.Print(", ");
                step.Print(output);
            }

            output.Print(" do");
            output.PrintLine();

            output.IncreaseIndent();

            Statement.PrintSequence(output, m_statements);

            output.DecreaseIndent();

            output.Print("end");
        }
コード例 #5
0
        public override void Print(Output output)
        {
            output.PrintLine("while true do");
            output.IncreaseIndent();

            Statement.PrintSequence(output, m_statements);

            output.DecreaseIndent();
            output.Print("end");
        }
コード例 #6
0
ファイル: RepeatBlock.cs プロジェクト: Screeder/GameFiles
        public override void Print(Output output)
        {
            output.Print("repeat");
            output.PrintLine();

            output.IncreaseIndent();

            Statement.PrintSequence(output, m_statements);

            output.DecreaseIndent();

            output.Print("until ");
            m_branch.AsExpression(m_r).Print(output);
        }
コード例 #7
0
ファイル: TForBlock.cs プロジェクト: Screeder/GameFiles
        public override void Print(Output output)
        {
            output.Print("for ");

            m_r.GetTarget(m_register + 3, Begin - 1).Print(output);

            var n = m_register + 2 + m_length;

            for (int r1 = m_register + 4; r1 <= n; r1++)
            {
                output.Print(", ");
                m_r.GetTarget(r1, Begin - 1).Print(output);
            }

            output.Print(" in ");

            Expression value = null;

            value = m_r.GetValue(m_register, Begin - 1);
            value.Print(output);

            // TODO: Optimize code
            if (!value.IsMultiple)
            {
                output.Print(", ");

                value = m_r.GetValue(m_register + 1, Begin - 1);
                value.Print(output);

                if (!value.IsMultiple)
                {
                    output.Print(", ");

                    value = m_r.GetValue(m_register + 2, Begin - 1);
                    value.Print(output);
                }
            }

            output.Print(" do");
            output.PrintLine();

            output.IncreaseIndent();

            Statement.PrintSequence(output, m_statements);

            output.DecreaseIndent();
            output.Print("end");
        }
コード例 #8
0
ファイル: WhileBlock.cs プロジェクト: Screeder/GameFiles
        public override void Print(Output output)
        {
            output.Print("while ");

            m_branch.AsExpression(m_registers).Print(output);

            output.Print(" do");
            output.PrintLine();

            output.IncreaseIndent();

            Statement.PrintSequence(output, m_statements);

            output.DecreaseIndent();

            output.Print("end");
        }
コード例 #9
0
ファイル: TableLiteral.cs プロジェクト: Screeder/GameFiles
        public override void Print(Output output)
        {
            m_entries.Sort();
            m_listLength = 1;

            if (m_entries.Count == 0)
            {
                output.Print("{}");
            }
            else
            {
                var lineBreak = (m_isList && m_entries.Count > 5) ||
                                (m_isObject && m_entries.Count > 2) ||
                                (!m_isObject);

                if (!lineBreak)
                {
                    foreach (var entry in m_entries)
                    {
                        var value = entry.Value;

                        if (!value.IsBrief)
                        {
                            lineBreak = true;
                            break;
                        }
                    }
                }

                output.Print("{");

                if (lineBreak)
                {
                    output.PrintLine();
                    output.IncreaseIndent();
                }

                PrintEntry(0, output);

                if (!m_entries[0].Value.IsMultiple)
                {
                    for (int i = 1; i < m_entries.Count; i++)
                    {
                        output.Print(",");

                        if (lineBreak)
                        {
                            output.PrintLine();
                        }
                        else
                        {
                            output.Print(" ");
                        }

                        PrintEntry(i, output);

                        if (m_entries[i].Value.IsMultiple)
                        {
                            break;
                        }
                    }
                }

                if (lineBreak)
                {
                    output.PrintLine();
                    output.DecreaseIndent();
                }

                output.Print("}");
            }
        }