Beispiel #1
0
        private static string PrintModule(ModuleInfo module)
        {
            var sb = new IndentingStringBuilder();

            sb.AppendLine(GetHeader());
            sb.AppendLine();

            if (module.NeedsAggressiveInlining)
            {
                sb.AppendLine("using System.Runtime.CompilerServices;");
                sb.AppendLine();
            }

            sb.AppendLine($"namespace {module.Namespace}");
            sb.AppendLineAndIncrease("{");

            sb.AppendLine($"public static class Result{module.Name}");
            sb.AppendLineAndIncrease("{");

            sb.AppendLine($"public const int Module{module.Name} = {module.Index};");
            sb.AppendLine();

            var  hierarchy    = new Stack <ResultInfo>();
            bool justIndented = false;

            foreach (ResultInfo result in module.Results)
            {
                while (hierarchy.Count > 0 && hierarchy.Peek().DescriptionEnd < result.DescriptionStart)
                {
                    hierarchy.Pop();
                    sb.DecreaseLevel();
                    sb.AppendSpacerLine();
                }

                if (!justIndented && result.IsRange)
                {
                    sb.AppendSpacerLine();
                }

                PrintResult(sb, module.Name, result);

                if (result.IsRange)
                {
                    hierarchy.Push(result);
                    sb.IncreaseLevel();
                }

                justIndented = result.IsRange;
            }

            while (hierarchy.Count > 0)
            {
                hierarchy.Pop();
                sb.DecreaseLevel();
            }

            sb.DecreaseAndAppendLine("}");
            sb.DecreaseAndAppendLine("}");

            return(sb.ToString());
        }