|
| 1 | +------------------------------------------------------------------------------ |
| 2 | +-- GNAT Documentation Generation Tool -- |
| 3 | +-- -- |
| 4 | +-- Copyright (C) 2025, AdaCore -- |
| 5 | +-- -- |
| 6 | +-- This is free software; you can redistribute it and/or modify it under -- |
| 7 | +-- terms of the GNU General Public License as published by the Free Soft- -- |
| 8 | +-- ware Foundation; either version 3, or (at your option) any later ver- -- |
| 9 | +-- sion. This software is distributed in the hope that it will be useful, -- |
| 10 | +-- but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN- -- |
| 11 | +-- TABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public -- |
| 12 | +-- License for more details. You should have received a copy of the GNU -- |
| 13 | +-- General Public License distributed with this software; see file -- |
| 14 | +-- COPYING3. If not, go to http://www.gnu.org/licenses for a complete copy -- |
| 15 | +-- of the license. -- |
| 16 | +------------------------------------------------------------------------------ |
| 17 | + |
| 18 | +with VSS.IRIs; |
| 19 | +with VSS.Strings.Formatters.Generic_Integers; |
| 20 | +with VSS.Strings.Formatters.Strings; |
| 21 | +with VSS.Strings.Templates; |
| 22 | +with VSS.XML.Attributes.Containers; |
| 23 | +with VSS.XML.Writers.Pretty; |
| 24 | + |
| 25 | +with GNATdoc.Backend.XML_Namespaces; |
| 26 | +with GNATdoc.Comments.XML_Helpers; |
| 27 | +with Streams; |
| 28 | + |
| 29 | +package body GNATdoc.Backend.XML is |
| 30 | + |
| 31 | + use GNATdoc.Backend.XML_Namespaces; |
| 32 | + |
| 33 | + package Character_Count_Formatters is |
| 34 | + new VSS.Strings.Formatters.Generic_Integers (VSS.Strings.Character_Count); |
| 35 | + use Character_Count_Formatters; |
| 36 | + -- XXX VSS 20251204+ provides it as |
| 37 | + -- `VSS.Strings.Formatters.Character_Offsets`. |
| 38 | + |
| 39 | + package Line_Count_Formatters is |
| 40 | + new VSS.Strings.Formatters.Generic_Integers (VSS.Strings.Line_Count); |
| 41 | + use Line_Count_Formatters; |
| 42 | + -- XXX VSS 20251204+ provides it as `VSS.Strings.Formatters.Line_Offsets`. |
| 43 | + |
| 44 | + GNATdoc_Element : constant VSS.Strings.Virtual_String := "gnatdoc"; |
| 45 | + |
| 46 | + -------------- |
| 47 | + -- Generate -- |
| 48 | + -------------- |
| 49 | + |
| 50 | + overriding procedure Generate (Self : in out XML_Backend) is |
| 51 | + |
| 52 | + procedure Generate |
| 53 | + (Writer : in out VSS.XML.Writers.XML_Writer'Class; |
| 54 | + Entity : not null GNATdoc.Entities.Entity_Information_Access; |
| 55 | + Success : in out Boolean); |
| 56 | + |
| 57 | + -------------- |
| 58 | + -- Generate -- |
| 59 | + -------------- |
| 60 | + |
| 61 | + procedure Generate |
| 62 | + (Writer : in out VSS.XML.Writers.XML_Writer'Class; |
| 63 | + Entity : not null GNATdoc.Entities.Entity_Information_Access; |
| 64 | + Success : in out Boolean) |
| 65 | + is |
| 66 | + Attributes : VSS.XML.Attributes.Containers.Attributes; |
| 67 | + Signatures : VSS.String_Vectors.Virtual_String_Vector; |
| 68 | + Location_Template : VSS.Strings.Templates.Virtual_String_Template := |
| 69 | + "{}:{}:{}"; |
| 70 | + |
| 71 | + begin |
| 72 | + Attributes.Clear; |
| 73 | + Attributes.Insert |
| 74 | + (VSS.IRIs.Empty_IRI, |
| 75 | + "kind", |
| 76 | + VSS.Strings.To_Virtual_String |
| 77 | + (GNATdoc.Entities.Entity_Kind'Wide_Wide_Image (Entity.Kind))); |
| 78 | + Attributes.Insert |
| 79 | + (VSS.IRIs.Empty_IRI, |
| 80 | + "location", |
| 81 | + Location_Template.Format |
| 82 | + (VSS.Strings.Formatters.Strings.Image (Entity.Location.File), |
| 83 | + Image (Entity.Location.Line), |
| 84 | + Image (Entity.Location.Column))); |
| 85 | + Attributes.Insert |
| 86 | + (VSS.IRIs.Empty_IRI, "signature", Entity.Signature.Image); |
| 87 | + Attributes.Insert (VSS.IRIs.Empty_IRI, "name", Entity.Name); |
| 88 | + Attributes.Insert |
| 89 | + (VSS.IRIs.Empty_IRI, "qualified_name", Entity.Qualified_Name); |
| 90 | + |
| 91 | + if not GNATdoc.Entities.Is_Undefined (Entity.Parent_Type) then |
| 92 | + Attributes.Insert |
| 93 | + (VSS.IRIs.Empty_IRI, |
| 94 | + "parent_type", |
| 95 | + Entity.Parent_Type.Signature.Image); |
| 96 | + end if; |
| 97 | + |
| 98 | + for Progenitor of Entity.Progenitor_Types loop |
| 99 | + Signatures.Append (Progenitor.Signature.Image); |
| 100 | + end loop; |
| 101 | + |
| 102 | + if not Signatures.Is_Empty then |
| 103 | + Attributes.Insert |
| 104 | + (VSS.IRIs.Empty_IRI, "progenitor_types", Signatures.Join (' ')); |
| 105 | + end if; |
| 106 | + |
| 107 | + Writer.Start_Element |
| 108 | + (GNATdoc_Namespace, "entity", Attributes, Success); |
| 109 | + |
| 110 | + GNATdoc.Comments.XML_Helpers.Generate |
| 111 | + (Entity.Documentation, Writer, Success); |
| 112 | + |
| 113 | + for E of Entity.Entities loop |
| 114 | + Generate (Writer, E, Success); |
| 115 | + end loop; |
| 116 | + |
| 117 | + Writer.End_Element (GNATdoc_Namespace, "entity", Success); |
| 118 | + end Generate; |
| 119 | + |
| 120 | + Writer : aliased VSS.XML.Writers.Pretty.Pretty_XML_Writer; |
| 121 | + Output : aliased Streams.Output_Text_Stream; |
| 122 | + Success : Boolean := True; |
| 123 | + Attributes : VSS.XML.Attributes.Containers.Attributes; |
| 124 | + |
| 125 | + begin |
| 126 | + -- Open output file. |
| 127 | + |
| 128 | + Output.Open |
| 129 | + (GNATCOLL.VFS.Create_From_Dir |
| 130 | + (Self.Output_Root, "documentation.xml")); |
| 131 | + |
| 132 | + -- Connect components |
| 133 | + |
| 134 | + Writer.Set_Output_Stream (Output'Unchecked_Access); |
| 135 | + Writer.Set_Indent (2); |
| 136 | + |
| 137 | + -- Generate XML document |
| 138 | + |
| 139 | + Writer.Start_Document (Success); |
| 140 | + Writer.Start_Prefix_Mapping ("", GNATdoc_Namespace, Success); |
| 141 | + |
| 142 | + Attributes.Clear; |
| 143 | + Writer.Start_Element |
| 144 | + (GNATdoc_Namespace, GNATdoc_Element, Attributes, Success); |
| 145 | + |
| 146 | + for E of GNATdoc.Entities.Globals.Entities loop |
| 147 | + Generate (Writer, E, Success); |
| 148 | + end loop; |
| 149 | + |
| 150 | + Writer.End_Element (GNATdoc_Namespace, GNATdoc_Element, Success); |
| 151 | + |
| 152 | + -- Close output file. |
| 153 | + |
| 154 | + Output.Close; |
| 155 | + end Generate; |
| 156 | + |
| 157 | +end GNATdoc.Backend.XML; |
0 commit comments