Example #1
0
        private static List <CodeSection> GetSectionsByCode(List <List <FlatInfo> > sections)
        {
            List <CodeSection> codeSections = new List <CodeSection>();

            foreach (var sectionsInPlace in sections.OrderBy(x => x.Count))
            {
                CodeSection codeSection = new CodeSection();
                codeSection.CountFloors = sectionsInPlace[0].Floors;

                //Группировка по коду
                List <Code> codes = sectionsInPlace.OrderByDescending(x => x.CountFlats).GroupBy(g => g.Code).
                                    OrderBy(o => o.Key).
                                    Select(g =>
                {
                    var firstSect = g.First();
                    var code      = new Code(g.Key, g.ToList(),
                                             (codeSection.CountFloors - 1) * (firstSect.CountFlats - 1),
                                             firstSect.NumberInSpot, firstSect.SpotOwner, codeSection.CountFloors);
                    return(code);
                }).ToList();
                //Группировка  по кол-ву квартир в секции
                codeSection.SectionsByCountFlats = codes.GroupBy(g => g.CountFlats).OrderByDescending(o => o.Key).
                                                   Select(g =>
                {
                    var flatsInSection            = new FlatsInSection();
                    flatsInSection.CountFlats     = g.Key;
                    flatsInSection.SectionsByCode = g.ToList();
                    return(flatsInSection);
                }).ToList();

                codeSections.Add(codeSection);
            }
            return(codeSections);
        }
Example #2
0
        public override bool TryReadExpression(CodeReader reader, CodeSection code, out IExpression e)
        {
            Match m = Assignment.reader.Match(code.ToString());

            e = null;
            if (m.Success)
            {
                Group g = m.Groups[target];
                if (!reader.TryReadExpression(code.CreateSubsection(g.Index, g.Length), out IExpression target_expression))
                {
                    return(false);
                }

                g = m.Groups[value];
                if (!reader.TryReadExpression(code.CreateSubsection(g.Index, g.Length), out IExpression value_expression))
                {
                    return(false);
                }

                if (target_expression is IExpression <Variable> var_expression)
                {
                    e = new AssignmentExpression(var_expression, value_expression);
                    return(true);
                }
            }
            return(false);
        }
Example #3
0
 /// <summary>
 /// Initializes a new instance of the class.
 /// </summary>
 /// <param name="parent">The parent emitter.</param>
 /// <param name="outer">The outer code section.</param>
 /// <param name="sourceMap">The current source map.</param>
 private Emitter(Emitter parent, CodeSection outer, SourceMap sourceMap)
 {
     this.data      = parent.data;
     this.code      = parent.code;
     this.local     = new CodeSection();
     this.sourceMap = sourceMap;
     outer.Add(this.local);
 }
Example #4
0
 /// <summary>
 /// Initializes a new instance of the class.
 /// </summary>
 /// <param name="source">The source code, split into lines.</param>
 public Emitter(string[] source)
 {
     this.data      = new DataSection();
     this.code      = new CodeSection();
     this.local     = new CodeSection();
     this.sourceMap = new SourceMap(source);
     this.code.Add(this.local);
 }
        public MainScriptSCL(string name, string dsc, string authorName, Repository repo) : base(name, authorName, repo)
        {
            InitialComments.CommentStr = string.Format("Browser:IE5 \n" + "!Date:{0}\n", CreationDate);

            Sections.Add(new EnviromentSection(dsc));
            Header = new HeaderSection();
            Sections.Add(Header);
            Code = new CodeSection();
            Sections.Add(Code);

            AddVariable(new Variable(Name.Replace(".htp", ""), "Timer", VariablesScopes.Local));
            Sections.Add(new StartTimer(Name.Replace(".htp", "")));
        }
        /// <summary>
        /// Applies all known optimizations to the given code section.
        /// </summary>
        /// <param name="section">The code section to optimize.</param>
        public static void Optimize(this CodeSection section)
        {
            var optimizer = PeepholeOptimizer.DefaultOptimizer;

            foreach (var body in section.Bodies)
            {
                // Compress local entries.
                body.CompressLocalEntries();

                // Apply peephole optimizations.
                var optInstructions = optimizer.Optimize(body.BodyInstructions);
                body.BodyInstructions.Clear();
                body.BodyInstructions.AddRange(optInstructions);
            }
        }
Example #7
0
        /// <summary>
        /// Reads the non-custom section with the given header.
        /// </summary>
        /// <param name="Header">The section header.</param>
        /// <returns>The parsed section.</returns>
        protected Section ReadKnownSectionPayload(SectionHeader Header)
        {
            switch (Header.Name.Code)
            {
            case SectionCode.Type:
                return(TypeSection.ReadSectionPayload(Header, this));

            case SectionCode.Import:
                return(ImportSection.ReadSectionPayload(Header, this));

            case SectionCode.Function:
                return(FunctionSection.ReadSectionPayload(Header, this));

            case SectionCode.Table:
                return(TableSection.ReadSectionPayload(Header, this));

            case SectionCode.Memory:
                return(MemorySection.ReadSectionPayload(Header, this));

            case SectionCode.Global:
                return(GlobalSection.ReadSectionPayload(Header, this));

            case SectionCode.Export:
                return(ExportSection.ReadSectionPayload(Header, this));

            case SectionCode.Start:
                return(StartSection.ReadSectionPayload(Header, this));

            case SectionCode.Element:
                return(ElementSection.ReadSectionPayload(Header, this));

            case SectionCode.Code:
                return(CodeSection.ReadSectionPayload(Header, this));

            case SectionCode.Data:
                return(DataSection.ReadSectionPayload(Header, this));

            default:
                return(ReadUnknownSectionPayload(Header));
            }
        }
Example #8
0
        private void Write(CodeSection cs)
        {
            sb.AppendLine($"[Code section]");
            foreach (var c in cs.Operators)
            {
                if (c.XRefs.Count > 0)
                {
                    sb.AppendLine().AppendLine($"{c.Label}:");
                }

                sb.Append($"{c.Address:x4}: {c.Type:x2} {c.ArgsToHex(),-8}  {c.Name,-8} {c.ArgsToString()}");

                if (c.Name.Equals("lea"))
                {
                    sb.Append(";  ");
                    FillLeaDescription(c, sb);
                }

                sb.AppendLine();
            }
        }
Example #9
0
 public OpcodeWriter()
 {
     ApiSection  = new ApiSection();
     dataSection = new DataSection();
     codeSection = new CodeSection(dataSection, ApiSection);
 }
Example #10
0
        private void deleteSettingsSimpleButton_Click(object sender, EventArgs e)
        {
            bool removeSection = false;
            IQueryable <LotCodeFormatSections> laterSections = from LaterSection in m_LotCodeSession.Query <LotCodeFormatSections>()
                                                               where LaterSection.LotCodeFormat.Oid == m_CurrentLotCodeFormat.Oid && LaterSection.SectionPosition >= sectionPositionSpinEdit.Value
                                                               select LaterSection;

            if (MessageBox.Show("Are you sure you want to delete the settings for this Section?", "Delete Section Settings", MessageBoxButtons.YesNo, MessageBoxIcon.Hand) == DialogResult.No)
            {
                return;
            }
            else
            {
                if (deleteSettingsSimpleButton.Tag.ToString() != "RemoveSection")
                {
                    if (MessageBox.Show("Do you want to remove the section?", "Remove Section", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                    {
                        removeSection = true;
                    }
                }
                else
                {
                    removeSection = true;
                }
            }


            if (removeSection)
            {
                m_CurrentLotCodeSection.Delete();
                if (m_CurrentLotCodeSection.IsDeleted)
                {
                    foreach (LotCodeFormatSections CodeSection in laterSections)
                    {
                        CodeSection.SectionPosition -= 1;
                        CodeSection.Save();
                    }
                    if (laterSections.Count() > 0)
                    {
                        PrepareNewLotCodeSection((int?)sectionPositionSpinEdit.Value);
                    }
                    else if (sectionPositionSpinEdit.Value > 1M)
                    {
                        PrepareNewLotCodeSection((int?)(sectionPositionSpinEdit.Value - 1));
                    }
                    else
                    {
                        PrepareNewLotCodeSection(1);
                    }
                    MessageBox.Show("The section was successfully removed.");
                }
                else
                {
                    MessageBox.Show("The section was not deleted", "Error Encountered", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            else
            {
                PrepareNewLotCodeSection((int?)sectionPositionSpinEdit.Value);
            }

            lotCodeFormatSectionsGridControl.Enabled = true;
            Utilities.MakeFormReadOnly(sectionSettingsPanelControl, true);
            sectionPositionSpinEdit.ReadOnly = false;

            cancelSettingsChangesSimpleButton.Enabled = false;
            saveSettingsSimpleButton.Enabled          = false;
        }
Example #11
0
        private void ConvertToNaturalLanguage(CodeSection codeSection)
        {

            if (!string.IsNullOrEmpty(codeSection.Identifier)) // && codeSection.modifiers.Contains("public"))
            {
                if (codeSection.ReturnType != null && codeSection.ReturnType.Equals("class"))
                {
                    //Console.WriteLine("\t The " + codeSection.ReturnType + " " + codeSection.identifier + " ");
                    Console.WriteLine(Resources.String_tab + Resources.String__a_ + codeSection.Identifier);
                }
                if (codeSection.ReturnType != null && codeSection.ReturnType.Equals("namespace"))
                {
                    //Console.WriteLine("In " + codeSection.ReturnType + " " + codeSection.identifier + " ");
                    Console.WriteLine(Resources.String_In_ + codeSection.Identifier);
                }
            }
            foreach (CodeSection codeSectionChild in codeSection.CodeSections)
            {
                if (!string.IsNullOrEmpty(codeSectionChild.Identifier))
                {
                    // Only public methods
                    if (!codeSectionChild.Modifiers.Contains("public"))
                    {
                        // Console.WriteLine();
                        ConvertToNaturalLanguage(codeSectionChild);
                        continue;
                    }

                    if (codeSectionChild.Header.Contains("_"))
                    {
                        Console.Write(Resources.String_tab_arrow + Resources.String_react_to__ +
                                      codeSectionChild.Identifier);
                    }
                    else if (codeSectionChild.Header.Contains("("))
                    {
                        Console.Write(Resources.String_tab_arrow + Resources.String_can__ + codeSectionChild.Identifier);
                    }
                    else
                    {
                        if (codeSectionChild.ReturnType != null &&
                            (codeSectionChild.ReturnType.Equals("namespace") ||
                             codeSectionChild.ReturnType.Equals("class")))
                        {
                            Console.WriteLine();
                            ConvertToNaturalLanguage(codeSectionChild);
                            continue;
                        }
                        Console.Write(Resources.String_tab_arrow + Resources.String_ + codeSectionChild.Identifier);
                    }
                    if (codeSectionChild.ReturnType != null && !codeSectionChild.ReturnType.Equals("void"))
                    {
                        Console.Write(Resources.String__as_a_ + codeSectionChild.ReturnType);
                    }
                    string parameters = codeSectionChild.Parameters.Aggregate("",
                                                                              (current, parameter) =>
                                                                              current + parameter);

                    // has parameters but is not an event
                    if (!string.IsNullOrEmpty(parameters) && !codeSectionChild.Header.Contains("_"))
                    {
                        Console.Write(Resources.String__based_on_ + codeSectionChild.Parameters);
                    }
                    Console.WriteLine();
                }
                ConvertToNaturalLanguage(codeSectionChild);

            }
        }
Example #12
0
        public List<CodeSection> GetAllCodeElements(string filePath, string fileContent, int beginSection, int level)
        {
            string header = "";
            bool acceptBracket = false;
            bool branchContainExpression = false;
            int lastCodeEndedAt = beginSection;
            var ChildCodeSections = new List<CodeSection>();
            var codeSectionsChilds = new List<CodeSection>();
            for (int i = beginSection; i < fileContent.Length; i++)
            {
                if (IsNonExecutable(fileContent[i]))
                {
                    continue;
                }
                if (fileContent[i] == ';')
                {
                    branchContainExpression = true;
                    var codeSection = new CodeSection(filePath, fileContent, lastCodeEndedAt, i + 1, level);
                    ChildCodeSections.Add(codeSection);
                    lastCodeEndedAt = i + 1;
                }
                else if (fileContent[i] == '}')
                {

                    if (!acceptBracket)
                    {
                        //CodeSection codeSection = new CodeSection(filePath, fileContent, lastCodeEndedAt, i + 1, level);
                        //codeSections.Add(codeSection);
                        return ChildCodeSections;
                    }
                    if (branchContainExpression)
                    {
                        var codeSection = new CodeSection(filePath, fileContent, lastCodeEndedAt, i + 1, level)
                            {
                                Header = header.Trim()
                            };
                        if (codeSectionsChilds != null)
                        {
                            codeSection.CodeSections.AddRange(codeSectionsChilds);
                        }
                        ChildCodeSections.Add(codeSection);
                        lastCodeEndedAt = i + 1;
                    }
                    acceptBracket = false;
                }
                else if (fileContent[i] == '{')
                {
                    branchContainExpression = false;
                    //if (codeSectionsChilds.Count < 1 && !acceptBracket)
                    {
                        header = fileContent.Substring(lastCodeEndedAt, i - lastCodeEndedAt);
                    }
                    level++;
                    codeSectionsChilds = GetAllCodeElements(filePath, fileContent, i + 1, level);
                    if (codeSectionsChilds != null && codeSectionsChilds.Count > 0)
                    {
                        i = codeSectionsChilds[codeSectionsChilds.Count - 1].EndSection;
                        branchContainExpression = true;
                    }
                    acceptBracket = true;
                }
            }
            return ChildCodeSections;
        }
Example #13
0
        private void GetIdentifier(CodeSection codeSection)
        {
            var modifiers = new List<string>();
            var parameters = new List<string>();
            string modifiersString = string.Empty;
            string retutnType = "";
            string identifier = "";
            string parametersString = "";
            if (!string.IsNullOrEmpty(codeSection.Header))
            {
                string header = codeSection.Header;
                int roundBracketIndex = header.IndexOf('(');
                if (roundBracketIndex > -1)
                {
                    parametersString = header.Substring(roundBracketIndex);
                    int beginOfIdentifier = header.Substring(0, roundBracketIndex).Trim().LastIndexOf(' ');
                    if (beginOfIdentifier > -1)
                    {
                        identifier = header.Substring(beginOfIdentifier, roundBracketIndex - beginOfIdentifier);
                        retutnType = header.Substring(0, beginOfIdentifier);
                    }
                    else
                    {
                        identifier = header.Substring(0, roundBracketIndex);
                    }
                }
                else
                {
                    int beginOfIdentifier = header.LastIndexOf(' ');
                    if (beginOfIdentifier > -1)
                    {
                        identifier = header.Substring(beginOfIdentifier);
                        retutnType = header.Substring(0, beginOfIdentifier);
                    }
                }
                if (!string.IsNullOrEmpty(retutnType))
                {
                    string[] modifiersArray = retutnType.Trim().Split(' ');
                    modifiers = modifiersArray.ToList();

                    // Constructors have no return types
                    if (modifiersArray.Length != 1 || !modifiersArray[0].Equals("public"))
                    {
                        retutnType = modifiersArray[modifiersArray.Length - 1];
                        modifiers.RemoveAt(modifiers.Count - 1);
                    }
                    else
                    {
                        retutnType = "";
                    }
                    foreach (string modifier in modifiers)
                    {
                        modifiersString += modifier + " ";
                    }
                    if (parametersString.Length > 2)
                    {
                        parameters =
                            parametersString.Trim().Substring(1, parametersString.Length - 2).Split(',').ToList();
                        parametersString = "(.";
                        foreach (string parameter in parameters)
                        {
                            parametersString += parameters + ",";
                        }
                        parametersString += ".)";

                    }
                    if (modifiers.Contains("private"))
                    {
                        codeSection.Visibility = (int) CodeSection.Visible.Private;
                    }
                    if (modifiers.Contains("protected"))
                    {
                        codeSection.Visibility = (int) CodeSection.Visible.Protected;
                    }
                    if (modifiers.Contains("public"))
                    {
                        codeSection.Visibility = (int) CodeSection.Visible.Public;
                    }
                    codeSection.Identifier = identifier;
                    codeSection.Modifiers = modifiers;
                    codeSection.Parameters = parameters;
                    codeSection.ReturnType = retutnType;
                    //Console.WriteLine(modifiersString + " || R:" + retutnType + " || " + identifier + " || " + parametersString);
                    //Console.WriteLine(modifiersString + " || R:" + retutnType + " || " + identifier + " || " + parametersString);
                }
            }
            foreach (CodeSection codeSectionChild in codeSection.CodeSections)
            {
                GetIdentifier(codeSectionChild);
                if (!string.IsNullOrEmpty(identifier.Trim()) &&
                    !string.IsNullOrEmpty(codeSectionChild.Identifier.Trim()))
                {

                    string shape = "elipse";
                    switch (codeSectionChild.Visibility)
                    {
                        case 1:
                            shape = "diamond";
                            break;
                        case 2:
                            shape = "diamond";
                            break;
                        case 3:
                            shape = "diamond";
                            break;
                        case 4:
                            shape = "diamond";
                            break;
                        default:
                            shape = "elipse";
                            break;
                    }
                    string color = "white";
                    double complexity = (codeSectionChild.CodeSections.Count);
                    switch ((int) Math.Round(complexity))
                    {
                        case 0:
                            color = "yellow";
                            break;
                        case 1:
                            color = "yellow";
                            break;
                        case 2:
                            color = "orange";
                            break;
                        case 3:
                            color = "green";
                            break;
                        case 4:
                            color = "gray";
                            break;
                        case 5:
                            color = "magenta";
                            break;
                        default:
                            color = "red";
                            break;
                    }

                    string codeSectionChildIdentifier = codeSectionChild.Identifier.Replace('.', '_');
                    if (codeSectionChildIdentifier.Contains("[")) return;
                    if (codeSection.Identifier.Contains("[")) return;
                    if (codeSectionChildIdentifier.Contains("+")) return;
                    if (codeSection.Identifier.Contains("+")) return;
                    if (codeSectionChildIdentifier.Contains("~")) return;
                    if (codeSection.Identifier.Contains("~")) return;
                    if (string.IsNullOrEmpty(codeSection.Identifier.Trim()))
                    {
                        return;
                    }
                    Console.WriteLine(codeSectionChildIdentifier + "[fillcolor=" + color +
                                      ", style=\"rounded,filled\", shape=" + shape + "];");
                    Console.WriteLine(codeSection.Identifier.Replace('.', '_') + " -> " + codeSectionChildIdentifier +
                                      ";");
                }
            }
        }
Example #14
0
        private void OpenSection()
        {
            int nextRowNumber = Sections.Count > 0 ? Sections.Max(p => p.Number) + 1 : 1;
            CurrentSection = nextRowNumber;

            var section = new CodeSection
            {
                Number = nextRowNumber,
                Name = "##Hyperlink" + CurrentSection + "##",
                FirstChildRow = Row + 1
            };
            Sections.Add(section);
        }
        // strict parse means all sections must come in order
        public void ParseAsWASM(string filename, bool strict_parse = true)
        {
            if (!BitConverter.IsLittleEndian)
            {
                throw new NotImplementedException("LEB128 implementation only handles little endian systems");
            }

            using (FileStream fs = new FileStream(filename, FileMode.Open, FileAccess.Read))
            {
                BinaryReader reader = new BinaryReader(fs);
                uint         magic  = reader.ReadUInt32();
                if (magic != MAGIC)
                {
                    throw new Exception("Not a compiled Web Assembly file.");
                }

                uint version = reader.ReadUInt32();
                if (version > SUPPORTED_VERSION)
                {
                    throw new Exception($"Unsupported version. Expected version <= {SUPPORTED_VERSION}, received {version}.");
                }

                int last_parsed_module = int.MinValue;

                /* Read in each module */

                while (true)
                {
                    int id = reader.PeekChar();

                    // EOF
                    if (id == -1)
                    {
                        break;
                    }

                    if (strict_parse && id < last_parsed_module)
                    {
                        throw new Exception("File contains out of order sections.");
                    }
                    last_parsed_module = id;

                    switch (id)
                    {
                    case (int)WebAssemblyModuleID.Custom:
                        if (strict_parse && custom != null)
                        {
                            throw new Exception("File contains a duplicate custom section.");
                        }
                        custom = new CustomSection(reader);
                        break;

                    case (int)WebAssemblyModuleID.Type:
                        if (strict_parse && type != null)
                        {
                            throw new Exception("File contains a duplicate type section.");
                        }
                        type = new TypeSection(reader);
                        break;

                    case (int)WebAssemblyModuleID.Import:
                        if (strict_parse && import != null)
                        {
                            throw new Exception("File contains a duplicate import section.");
                        }
                        import = new ImportSection(reader);
                        break;

                    case (int)WebAssemblyModuleID.Function:
                        if (strict_parse && function != null)
                        {
                            throw new Exception("File contains a duplicate function section.");
                        }
                        function = new FunctionSection(reader);
                        break;

                    case (int)WebAssemblyModuleID.Table:
                        if (strict_parse && table != null)
                        {
                            throw new Exception("File contains a duplicate table section.");
                        }
                        table = new TableSection(reader);
                        break;

                    case (int)WebAssemblyModuleID.Memory:
                        if (strict_parse && memory != null)
                        {
                            throw new Exception("File contains a duplicate memory section.");
                        }
                        memory = new MemorySection(reader);
                        break;

                    case (int)WebAssemblyModuleID.Global:
                        if (strict_parse && global != null)
                        {
                            throw new Exception("File contains a duplicate global section.");
                        }
                        global = new GlobalSection(reader);
                        break;

                    case (int)WebAssemblyModuleID.Export:
                        if (strict_parse && export != null)
                        {
                            throw new Exception("File contains a duplicate export section.");
                        }
                        export = new ExportSection(reader);
                        break;

                    case (int)WebAssemblyModuleID.Start:
                        if (strict_parse && start != null)
                        {
                            throw new Exception("File contains a duplicate start section.");
                        }
                        start = new StartSection(reader);
                        break;

                    case (int)WebAssemblyModuleID.Element:
                        if (strict_parse && element != null)
                        {
                            throw new Exception("File contains a duplicate element section.");
                        }
                        element = new ElementSection(reader);
                        break;

                    case (int)WebAssemblyModuleID.Code:
                        if (strict_parse && code != null)
                        {
                            throw new Exception("File contains a duplicate code section.");
                        }
                        code = new CodeSection(reader);
                        break;

                    case (int)WebAssemblyModuleID.Data:
                        if (strict_parse && data != null)
                        {
                            throw new Exception("File contains a duplicate data section.");
                        }
                        data = new DataSection(reader);
                        break;

                    // Error
                    default:
                        throw new Exception($"Unknown section {id}.");
                    }
                }

                /* Additional validation */

                // The lengths of vectors produced by the (possibly empty) function and code section must match up.
                if ((function != null && code == null) || (function == null && code != null))
                {
                    throw new Exception("File corrupt. Must include both function and code sections.");
                }
                if (function.types.Length != code.bodies.Length)
                {
                    throw new Exception("File corrupt. Function and code sections do not match up.");
                }

                // TODO: I don't actually check if data overlaps

                // TODO: Validate everything in this list
                // https://webassembly.github.io/spec/core/valid/modules.html
            }
        }
Example #16
0
        private void EncodeInternal(TextWriter writer, Section[] sections)
        {
            Dictionary <HeadSection, string> headRefs = CreateTableOfContents(sections);

            for (int i = 0; i < sections.Length; i++)
            {
                Section section = sections[i];

                if (section is ParagraphSection)
                {
                    ParagraphSection s = (ParagraphSection)section;

                    writer.Write("<p>");
                    WriteText(writer, s.Text);
                    writer.WriteLine("</p>");
                }
                else if (section is HeadSection)
                {
                    HeadSection s = (HeadSection)section;

                    writer.Write("<a name=\"{0}\">", headRefs[s]);
                    writer.Write("<h{0}>", s.Level);
                    WriteText(writer, s.Text);
                    writer.Write("</h{0}>", s.Level);
                    writer.WriteLine("</a>");
                }
                else if (section is HorizonSection)
                {
                    HorizonSection s = (HorizonSection)section;

                    writer.Write("<hr/>");
                }
                else if (section is CodeSection)
                {
                    CodeSection s = (CodeSection)section;

                    writer.Write("<pre class=\"code\"><code>");
                    writer.Write(Escape(s.Text));
                    writer.WriteLine("</code></pre>");
                }
                else if (section is QuoteSection)
                {
                    QuoteSection s = (QuoteSection)section;

                    writer.Write("<blockquote>");
                    EncodeInternal(writer, s.Texts);
                    writer.WriteLine("</blockquote>");
                }
                else if (section is OrderListSection)
                {
                    OrderListSection s = (OrderListSection)section;

                    writer.WriteLine("<ol>");
                    foreach (ListItemSection j in s.Items)
                    {
                        writer.Write("<li>");
                        WriteText(writer, j.Text);
                        EncodeInternal(writer, j.ChildList.ToArray());
                        writer.WriteLine("</li>");
                    }
                    writer.WriteLine("</ol>");
                }
                else if (section is ListSection)
                {
                    ListSection s = (ListSection)section;

                    writer.WriteLine("<ul>");
                    foreach (ListItemSection j in s.Items)
                    {
                        writer.Write(String.Format("<li {0}>", GetListClass(j.Mark)));
                        WriteText(writer, j.Text);
                        EncodeInternal(writer, j.ChildList.ToArray());
                        writer.WriteLine("</li>");
                    }
                    writer.WriteLine("</ul>");
                }
                else if (section is DefinitionListSection)
                {
                    DefinitionListSection s = (DefinitionListSection)section;

                    writer.Write("<dl>");
                    foreach (DefinitionItemSection j in s.Items)
                    {
                        writer.Write("<dt>");
                        WriteText(writer, j.Caption);
                        writer.WriteLine("</dt>");
                        writer.Write("<dd>");
                        WriteText(writer, j.Data);
                        writer.WriteLine("</dd>");
                    }
                    writer.WriteLine("</dl>");
                }
                else if (section is ContentsSection)
                {
                    ContentsSection s = (ContentsSection)section;

                    List <ContentItem> contents
                        = ContentsTableGenerator.Generate(sections, i, s.LevelLower, s.LevelUpper);

                    WriteContents(writer, contents, headRefs);
                }
                else if (section is ContentsAllSection)
                {
                    ContentsAllSection s = (ContentsAllSection)section;

                    List <ContentItem> contents
                        = ContentsTableGenerator.GenerateAll(sections, s.LevelLower, s.LevelUpper);

                    WriteContents(writer, contents, headRefs);
                }
            }
        }