Пример #1
0
        static Boolean ProcessFile(CompilerFrontEnd cfe, FileInfo file, int total, int current, Boolean basic = true)
        {
            SyntaxBuilder sb        = null;
            Boolean       OscarKilo = false;
            ConsoleKey    ck;

            while (!OscarKilo)
            {
                sb = new SyntaxBuilder(cfe, file.FullName);
                WriteLine(file.Name);
                SyntaxBuilder.Stages last = (SyntaxBuilder.Stages)(-1);
                while (sb.Step())
                {
                    if (last != sb.Stage)
                    {
                        Write(ConCol.Info, "\r({0}/{1}): {2}", current + 1, total, (last = sb.Stage).ToString());
                    }
                }
                WriteLine();


                if (!sb.OscarKilo)
                {
                    if (!sb.Success)
                    {
                        WriteLine(ConCol.Error, "Unable to process [{0}]:", file.Name);
                    }
                    if (sb.Warns.Count > 0)
                    {
                        WriteLine(ConCol.Warning, "Warnings:");
                        foreach (var m in sb.Warns.AsIndexable())
                        {
                            WriteLine(ConCol.Warning, "{0}) {1}", m.Index + 1, m.Value);
                        }
                        WriteLine();
                    }
                    if (sb.Errors.Count > 0)
                    {
                        WriteLine(ConCol.Error, "Errors:");
                        foreach (var m in sb.Errors.AsIndexable())
                        {
                            WriteLine(ConCol.Error, "{0}) {1}", m.Index + 1, m.Value);
                        }
                        if (sb.Errors.Count > 0)
                        {
                            ExecuteOnError(file.FullName, sb.Errors[0].Location.Value);
                        }
                    }
                    WriteLine("Press anything...");
                    Console.ReadKey(true);

                    ck = CharQuestion("Do you want to (c)ontinue or (t)ry again?", ConsoleKey.C, ConsoleKey.T, ConsoleKey.F);
                    if (ck == ConsoleKey.C)
                    {
                        break;
                    }
                }
                else
                {
                    OscarKilo = true;
                }
            }

            if (sb.Success)
            {
                cfe.UserDefinedDOM = sb.GetFinalDOM(ValidationBuilder.GetExtlessName(file.Name));
            }

            if (sb.Success && !basic)
            {
                String targetName   = paramCopyName == null ? file.Name : paramCopyName;
                String finalTarget  = Path.Combine(paramOutputFolder, targetName);
                String targetPacked = "{0}.packed{1}".Fmt(ValidationBuilder.GetExtlessName(targetName),
                                                          (new FileInfo(targetName)).Extension), finalTargetPacked = null;


                if (paramCopyName != null || paramCrossCheck)
                {
                    CheckOutputFolder();
                    WriteLine(ConCol.Info, "Outputing generated source.");
                    using (var sw = new StreamWriter(finalTarget))
                        sw.Write(cfe.UserDefinedDOM.Express(0));
                    WriteLine(ConCol.Info, "Emitted generated file [{0}].".Fmt(targetName));
                }

                if (paramEmitPacked)
                {
                    finalTargetPacked = Path.Combine(paramOutputFolder, targetPacked);
                    try
                    {
                        using (StreamWriter sw = new StreamWriter(finalTargetPacked))
                            sb.SavePacked(sw);
                        WriteLine(ConCol.Success, "Emitted packed source [{0}].", finalTargetPacked);
                    }
                    catch (Exception e)
                    {
                        WriteLine(ConCol.Error, "Unable to emit packed source of [{0}]: {1}", targetPacked, e.Message);
                        e.BreakException();
                        return(false);
                    }
                }

                if (paramCrossCheck)
                {
                    try
                    {
                        CodeDOMModule A, B;
                        CheckOutputFolder();
                        A = cfe.UserDefinedDOM;

                        if (!ProcessFile(cfe, new FileInfo(finalTarget), total, current))
                        {
                            WriteLine(ConCol.Error, "Cross check failed! Please contact Chaz pronto!");
                            throw new Exception("Cross check failed. Compiler isn't up to standard.");
                        }

                        B = cfe.UserDefinedDOM;

                        var d = CodeDOMComparer.CompareDOM(A, B);

                        if (d.Count == 0)
                        {
                            WriteLine(ConCol.Success, "Crosscheck Original To Copy Success!");
                        }
                        else
                        {
                            WriteLine(ConCol.Warning, "Crosscheck returned differences:");
                            foreach (var item in d.AsIndexable())
                            {
                                WriteLine(ConCol.Warning, "{0}> {1}", item.Index + 1, item.Value.ToString());
                            }
                            throw new Exception("Cross check failed. Compiler isn't up to standard.");
                        }

                        if (paramEmitPacked)
                        {
                            WriteLine(ConCol.Info, "Now cross checking with packed [{0}].", finalTargetPacked);
                            if (!ProcessFile(cfe, new FileInfo(finalTargetPacked), total, current))
                            {
                                WriteLine(ConCol.Error, "Packed cross check failed! Please contact Chaz pronto!");
                                throw new Exception("Packed cross check failed. Compiler isn't up to standard.");
                            }

                            B = cfe.UserDefinedDOM;

                            d = CodeDOMComparer.CompareDOM(A, B);

                            if (d.Count == 0)
                            {
                                WriteLine(ConCol.Success, "Crosscheck Original To Packed Success!");
                            }
                            else
                            {
                                WriteLine(ConCol.Warning, "Packed crosscheck returned differences:");
                                foreach (var item in d.AsIndexable())
                                {
                                    WriteLine(ConCol.Warning, "{0}> {1}", item.Index + 1, item.Value.ToString());
                                }
                                throw new Exception("Packed Cross check failed. Compiler isn't up to standard.");
                            }
                        }

                        cfe.UserDefinedDOM = A;
                    }
                    catch (Exception e)
                    {
                        WriteLine(ConCol.Error, "Crosscheck of file [{0}] failed: {1}".Fmt(targetName, e.Message));
                        e.BreakException();
                        return(false);
                    }
                }
            }
            return(sb.Success);
        }