Skip to content

Commit 93ea389

Browse files
committed
Merge branch 'topic/vadim/belongsto-master' into 'master'
Support of `@belongs-to` and `@private` for constants See merge request eng/ide/gnatdoc!168
2 parents d24621a + 333ba36 commit 93ea389

File tree

10 files changed

+283
-44
lines changed

10 files changed

+283
-44
lines changed

source/backend/gnatdoc-backend-test.adb

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,25 @@ package body GNATdoc.Backend.Test is
226226
Offset := @ - 2;
227227
end if;
228228

229+
if not Entity.Constants.Is_Empty then
230+
Offset := @ + 2;
231+
232+
Output.Put_Line
233+
(Section_Template.Format
234+
(VSS.Strings.Formatters.Strings.Image (Offset * ' '),
235+
VSS.Strings.Formatters.Strings.Image ("Constants")),
236+
Success);
237+
238+
Offset := @ + 2;
239+
240+
for E of Entity.Constants loop
241+
Dump (E.all);
242+
end loop;
243+
244+
Offset := @ - 2;
245+
Offset := @ - 2;
246+
end if;
247+
229248
if not Entity.Subprograms.Is_Empty then
230249
Offset := @ + 2;
231250

@@ -245,6 +264,30 @@ package body GNATdoc.Backend.Test is
245264
Offset := @ - 2;
246265
end if;
247266

267+
if not Entity.Belongs_Constants.Is_Empty then
268+
Offset := @ + 2;
269+
270+
Output.Put_Line
271+
(Section_Template.Format
272+
(VSS.Strings.Formatters.Strings.Image (Offset * ' '),
273+
VSS.Strings.Formatters.Strings.Image ("Belongs Constants")),
274+
Success);
275+
276+
Offset := @ + 2;
277+
278+
for E of Entity.Belongs_Constants loop
279+
if GNATdoc.Entities.To_Entity.Contains (E.Signature) then
280+
Dump (GNATdoc.Entities.To_Entity (E.Signature).all);
281+
282+
else
283+
Dump_Entity_Unknown (E, Success);
284+
end if;
285+
end loop;
286+
287+
Offset := @ - 2;
288+
Offset := @ - 2;
289+
end if;
290+
248291
if not Entity.Belongs_Subprograms.Is_Empty then
249292
Offset := @ + 2;
250293

source/backend/rst/gnatdoc-backend-rst.adb

Lines changed: 59 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,12 +144,53 @@ package body GNATdoc.Backend.RST is
144144
File : Streams.Output_Text_Stream;
145145
Success : Boolean := True;
146146

147+
procedure Generate_Constant_Documentation
148+
(Indent : VSS.Strings.Virtual_String;
149+
Entity : GNATdoc.Entities.Entity_Information;
150+
Package_Name : VSS.Strings.Virtual_String);
151+
-- Generate documentation for the given constant.
152+
147153
procedure Generate_Subprogram_Documentation
148154
(Indent : VSS.Strings.Virtual_String;
149155
Entity : GNATdoc.Entities.Entity_Information;
150156
Package_Name : VSS.Strings.Virtual_String);
151157
-- Generate documentation for the given subprogram.
152158

159+
-------------------------------------
160+
-- Generate_Constant_Documentation --
161+
-------------------------------------
162+
163+
procedure Generate_Constant_Documentation
164+
(Indent : VSS.Strings.Virtual_String;
165+
Entity : GNATdoc.Entities.Entity_Information;
166+
Package_Name : VSS.Strings.Virtual_String)
167+
is
168+
use type VSS.Strings.Virtual_String;
169+
170+
begin
171+
File.New_Line (Success);
172+
173+
File.Put (Indent, Success);
174+
File.Put (".. ada:object:: ", Success);
175+
176+
File.Put (Entity.RST_Profile, Success);
177+
File.New_Line (Success);
178+
File.Put (Indent, Success);
179+
File.Put (" :package: ", Success);
180+
File.Put (Package_Name, Success);
181+
File.New_Line (Success);
182+
File.New_Line (Success);
183+
184+
File.Put_Lines
185+
(GNATdoc.Comments.RST_Helpers.Get_RST_Documentation
186+
(Indent => Indent & " ",
187+
Documentation => Entity.Documentation,
188+
Pass_Through => Self.Pass_Through,
189+
Code_Snippet => False),
190+
Success);
191+
File.New_Line (Success);
192+
end Generate_Constant_Documentation;
193+
153194
---------------------------------------
154195
-- Generate_Subprogram_Documentation --
155196
---------------------------------------
@@ -346,8 +387,9 @@ package body GNATdoc.Backend.RST is
346387
end loop;
347388
end Union;
348389

349-
Types : Entity_Information_Sets.Set;
350-
Methods : Entity_Information_Sets.Set;
390+
Types : Entity_Information_Sets.Set;
391+
Constants : Entity_Information_Sets.Set;
392+
Methods : Entity_Information_Sets.Set;
351393

352394
begin
353395
Union (Types, Entity.Simple_Types);
@@ -389,8 +431,23 @@ package body GNATdoc.Backend.RST is
389431
if Self.OOP_Mode
390432
and then Item.Kind in Ada_Interface_Type | Ada_Tagged_Type
391433
then
434+
Constants.Clear;
392435
Methods.Clear;
393436

437+
for Object of Item.Belongs_Constants loop
438+
if not Is_Private_Entity
439+
(GNATdoc.Entities.To_Entity (Object.Signature))
440+
then
441+
Constants.Insert
442+
(GNATdoc.Entities.To_Entity (Object.Signature));
443+
end if;
444+
end loop;
445+
446+
for Object of Constants loop
447+
Generate_Constant_Documentation
448+
(" ", Object.all, Entity.Qualified_Name);
449+
end loop;
450+
394451
for Method of Item.Belongs_Subprograms loop
395452
if not Is_Private_Entity
396453
(GNATdoc.Entities.To_Entity (Method.Signature))

source/frontend/gnatdoc-entities.ads

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,11 @@ package GNATdoc.Entities is
8686
Enclosing : Entity_Signature;
8787
-- Structural enclosing entity (package/task/protected object).
8888
Belongs : Entity_Reference;
89-
-- Reference to the entity it belongs. It is set then subprogram is:
90-
-- * explicitly `@belongs-to` type
89+
-- Reference to the entity it belongs. It is set to refer to type when
90+
-- entity `@belongs-to` explicitly (for constants/subprogram), or then
91+
-- subprogram:
9192
-- * can be called with prefix notation
92-
-- * primitive operations of the tagged type
93+
-- * is a primitive operations of the tagged type
9394

9495
Is_Private : Boolean := False;
9596
-- Private entities are excluded from the documentartion.
@@ -129,6 +130,9 @@ package GNATdoc.Entities is
129130
Access_Types : aliased Entity_Information_Sets.Set;
130131
Subtypes : aliased Entity_Information_Sets.Set;
131132
Constants : aliased Entity_Information_Sets.Set;
133+
Belongs_Constants : aliased Entity_Reference_Sets.Set;
134+
-- Constants that belongs to the entity (to interface/tagged type,
135+
-- otherwise to the package)
132136
Variables : aliased Entity_Information_Sets.Set;
133137
Exceptions : aliased Entity_Information_Sets.Set;
134138

source/frontend/gnatdoc-frontend.adb

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1764,11 +1764,15 @@ package body GNATdoc.Frontend is
17641764

17651765
procedure Process_Object_Decl
17661766
(Node : Object_Decl'Class;
1767-
Enclosing : not null GNATdoc.Entities.Entity_Information_Access) is
1767+
Enclosing : not null GNATdoc.Entities.Entity_Information_Access)
1768+
is
1769+
Template : constant VSS.Strings.Templates.Virtual_String_Template :=
1770+
"{} : constant {}";
1771+
17681772
begin
17691773
for Name of Node.F_Ids loop
17701774
declare
1771-
Entity : constant not null
1775+
Entity : constant not null
17721776
GNATdoc.Entities.Entity_Information_Access :=
17731777
new GNATdoc.Entities.Entity_Information'
17741778
(Location => GNATdoc.Utilities.Location (Name),
@@ -1777,17 +1781,36 @@ package body GNATdoc.Frontend is
17771781
To_Virtual_String (Name.P_Fully_Qualified_Name),
17781782
Signature => Signature (Name),
17791783
others => <>);
1784+
Belongs : GNATdoc.Entities.Entity_Information_Access;
17801785

17811786
begin
17821787
Extract
17831788
(Node => Node,
17841789
Options => GNATdoc.Options.Extractor_Options,
17851790
Documentation => Entity.Documentation,
17861791
Messages => Entity.Messages);
1792+
GNATdoc.Entities.To_Entity.Insert (Entity.Signature, Entity);
17871793

17881794
if Node.F_Has_Constant then
17891795
Enclosing.Constants.Insert (Entity);
17901796

1797+
Resolve_Belongs_To
1798+
(Enclosing => Enclosing,
1799+
Belongs => Belongs,
1800+
Entity => Entity);
1801+
1802+
if Belongs = null then
1803+
Enclosing.Belongs_Constants.Insert (Entity.Reference);
1804+
1805+
else
1806+
Entity.RST_Profile :=
1807+
Template.Format
1808+
(VSS.Strings.Formatters.Strings.Image (Entity.Name),
1809+
VSS.Strings.Formatters.Strings.Image (Belongs.Name));
1810+
Belongs.Belongs_Constants.Insert (Entity.Reference);
1811+
Entity.Belongs := Belongs.Reference;
1812+
end if;
1813+
17911814
else
17921815
Enclosing.Variables.Insert (Entity);
17931816
end if;

source/gnatdoc-comments-extractor.adb

Lines changed: 83 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,16 @@ package body GNATdoc.Comments.Extractor is
154154
= Ada_Private_Type_Def);
155155
-- Extract documentation for private type declaration.
156156

157+
procedure Extract_Object_Declaration_Documentation
158+
(Node : Libadalang.Analysis.Basic_Decl'Class;
159+
Options : GNATdoc.Comments.Options.Extractor_Options;
160+
Sections : in out Section_Vectors.Vector;
161+
Messages : in out GNATdoc.Messages.Message_Container;
162+
Belongs_To : out VSS.Strings.Virtual_String;
163+
Is_Private : out Boolean)
164+
with Pre => Node.Kind in Ada_Object_Decl;
165+
-- Extractdocumentation for object declaration
166+
157167
procedure Extract_Simple_Declaration_Documentation
158168
(Node : Libadalang.Analysis.Basic_Decl'Class;
159169
Options : GNATdoc.Comments.Options.Extractor_Options;
@@ -644,11 +654,13 @@ package body GNATdoc.Comments.Extractor is
644654
Messages);
645655

646656
when Ada_Object_Decl =>
647-
Extract_Simple_Declaration_Documentation
657+
Extract_Object_Declaration_Documentation
648658
(Node.As_Object_Decl,
649659
Options,
650660
Documentation.Sections,
651-
Messages);
661+
Messages,
662+
Documentation.Belongs_To,
663+
Documentation.Is_Private);
652664

653665
when Ada_Number_Decl =>
654666
Extract_Simple_Declaration_Documentation
@@ -1855,6 +1867,75 @@ package body GNATdoc.Comments.Extractor is
18551867
end if;
18561868
end Extract_Leading_Section;
18571869

1870+
----------------------------------------------
1871+
-- Extract_Object_Declaration_Documentation --
1872+
----------------------------------------------
1873+
1874+
procedure Extract_Object_Declaration_Documentation
1875+
(Node : Libadalang.Analysis.Basic_Decl'Class;
1876+
Options : GNATdoc.Comments.Options.Extractor_Options;
1877+
Sections : in out Section_Vectors.Vector;
1878+
Messages : in out GNATdoc.Messages.Message_Container;
1879+
Belongs_To : out VSS.Strings.Virtual_String;
1880+
Is_Private : out Boolean)
1881+
is
1882+
Leading_Section : Section_Access;
1883+
Trailing_Section : Section_Access;
1884+
1885+
begin
1886+
Extract_General_Leading_Trailing_Documentation
1887+
(Decl_Node => Node,
1888+
Options => Options,
1889+
Last_Section => null,
1890+
Minimum_Indent => 0,
1891+
Sections => Sections,
1892+
Leading_Section => Leading_Section,
1893+
Trailing_Section => Trailing_Section);
1894+
1895+
Fill_Code_Snippet (Node, Node.Token_Start, Node.Token_End, Sections);
1896+
Remove_Comment_Start_And_Indentation (Sections, Options.Pattern);
1897+
1898+
declare
1899+
Raw_Section : Section_Access;
1900+
1901+
begin
1902+
-- Select most appropriate section depending from the style and
1903+
-- fallback.
1904+
1905+
case Options.Style is
1906+
when GNAT =>
1907+
if not Trailing_Section.Text.Is_Empty then
1908+
Raw_Section := Trailing_Section;
1909+
1910+
elsif Options.Fallback
1911+
and not Leading_Section.Text.Is_Empty
1912+
then
1913+
Raw_Section := Leading_Section;
1914+
end if;
1915+
1916+
when Leading =>
1917+
if not Leading_Section.Text.Is_Empty then
1918+
Raw_Section := Leading_Section;
1919+
1920+
elsif Options.Fallback
1921+
and not Trailing_Section.Text.Is_Empty
1922+
then
1923+
Raw_Section := Trailing_Section;
1924+
end if;
1925+
end case;
1926+
1927+
Parse_Raw_Section
1928+
(Location => GNATdoc.Utilities.Location (Node),
1929+
Raw_Section => Raw_Section,
1930+
Allowed_Tags =>
1931+
[Private_Tag | Belongs_To_Tag => True, others => False],
1932+
Sections => Sections,
1933+
Belongs_To => Belongs_To,
1934+
Is_Private => Is_Private,
1935+
Messages => Messages);
1936+
end;
1937+
end Extract_Object_Declaration_Documentation;
1938+
18581939
----------------------------------------
18591940
-- Extract_Private_Type_Documentation --
18601941
----------------------------------------
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
2+
package Constants is
3+
4+
type T is tagged limited null record;
5+
6+
C : constant T := (others => <>);
7+
8+
B : constant T := (others => <>);
9+
-- @belongs-to T
10+
11+
end Constants;

testsuite/executable/belongs_to_tags/belongs_to.ads renamed to testsuite/executable/belongs_to_tags/subprograms.ads

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
package Belongs_To is
2+
package Subprograms is
33

44
type T1 is tagged null record;
55

@@ -29,4 +29,4 @@ package Belongs_To is
2929
function PI2 (Self : I1) return I2'Class is abstract;
3030
-- @belongs-to I2
3131

32-
end Belongs_To;
32+
end Subprograms;

0 commit comments

Comments
 (0)