Skip to content

Commit 96a64b9

Browse files
committed
Code refactoing.
Builders are responsible to create sections and to fill them.
1 parent 11be345 commit 96a64b9

13 files changed

+227
-206
lines changed

source/gnatdoc-comments-builders-enumerations.adb

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,22 +22,23 @@ package body GNATdoc.Comments.Builders.Enumerations is
2222
-----------
2323

2424
procedure Build
25-
(Self : in out Enumeration_Components_Builder;
26-
Documentation : not null GNATdoc.Comments.Structured_Comment_Access;
27-
Options : GNATdoc.Comments.Options.Extractor_Options;
28-
Node : Libadalang.Analysis.Enum_Type_Def'Class;
29-
Advanced_Groups : out Boolean;
30-
Last_Section : out GNATdoc.Comments.Section_Access;
31-
Minimum_Indent : out Langkit_Support.Slocs.Column_Number) is
25+
(Self : in out Enumeration_Components_Builder;
26+
Documentation : not null GNATdoc.Comments.Structured_Comment_Access;
27+
Options : GNATdoc.Comments.Options.Extractor_Options;
28+
Node : Libadalang.Analysis.Type_Decl'Class;
29+
Def_Node : Libadalang.Analysis.Enum_Type_Def'Class;
30+
Last_Section : out GNATdoc.Comments.Section_Access;
31+
Minimum_Indent : out Langkit_Support.Slocs.Column_Number) is
3232
begin
33-
Self.Initialize (Documentation, Options, Node);
33+
Self.Initialize (Documentation, Options, Def_Node);
3434

35-
for Literal of Node.F_Enum_Literals loop
35+
for Literal of Def_Node.F_Enum_Literals loop
3636
Self.Process_Component_Declaration (Literal);
3737
Self.Process_Defining_Name (Enumeration_Literal, Literal.F_Name);
3838
end loop;
3939

40-
Advanced_Groups := Self.Advanced_Groups;
40+
Self.Fill_Structured_Comment (Node, Options.Pattern);
41+
4142
Last_Section := Self.Last_Section;
4243
Minimum_Indent := Self.Minimum_Indent;
4344
end Build;

source/gnatdoc-comments-builders-enumerations.ads

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
-- of the license. --
1616
------------------------------------------------------------------------------
1717

18+
-- Structured comment builder for enumeration types. It creates sections for
19+
-- enumeration literals and fill them.
20+
1821
with Libadalang.Analysis;
1922

2023
package GNATdoc.Comments.Builders.Enumerations is
@@ -23,13 +26,13 @@ package GNATdoc.Comments.Builders.Enumerations is
2326
new Abstract_Components_Builder with private;
2427

2528
procedure Build
26-
(Self : in out Enumeration_Components_Builder;
27-
Documentation : not null GNATdoc.Comments.Structured_Comment_Access;
28-
Options : GNATdoc.Comments.Options.Extractor_Options;
29-
Node : Libadalang.Analysis.Enum_Type_Def'Class;
30-
Advanced_Groups : out Boolean;
31-
Last_Section : out GNATdoc.Comments.Section_Access;
32-
Minimum_Indent : out Langkit_Support.Slocs.Column_Number);
29+
(Self : in out Enumeration_Components_Builder;
30+
Documentation : not null GNATdoc.Comments.Structured_Comment_Access;
31+
Options : GNATdoc.Comments.Options.Extractor_Options;
32+
Node : Libadalang.Analysis.Type_Decl'Class;
33+
Def_Node : Libadalang.Analysis.Enum_Type_Def'Class;
34+
Last_Section : out GNATdoc.Comments.Section_Access;
35+
Minimum_Indent : out Langkit_Support.Slocs.Column_Number);
3336

3437
private
3538

source/gnatdoc-comments-builders-generics.adb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ package body GNATdoc.Comments.Builders.Generics is
3232
(Self : in out Generic_Components_Builder;
3333
Documentation : not null GNATdoc.Comments.Structured_Comment_Access;
3434
Options : GNATdoc.Comments.Options.Extractor_Options;
35+
Node : Libadalang.Analysis.Generic_Package_Decl'Class;
3536
Formal_Part_Node : Libadalang.Analysis.Generic_Formal_Part'Class;
3637
Basic_Decl_Node : Libadalang.Analysis.Basic_Decl'Class) is
3738
begin
@@ -71,6 +72,8 @@ package body GNATdoc.Comments.Builders.Generics is
7172
end loop;
7273

7374
Self.Restart_Component_Group (Basic_Decl_Node.Sloc_Range.Start_Line);
75+
76+
Self.Fill_Structured_Comment (Node, Options.Pattern);
7477
end Build;
7578

7679
end GNATdoc.Comments.Builders.Generics;

source/gnatdoc-comments-builders-generics.ads

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ package GNATdoc.Comments.Builders.Generics is
2626
(Self : in out Generic_Components_Builder;
2727
Documentation : not null GNATdoc.Comments.Structured_Comment_Access;
2828
Options : GNATdoc.Comments.Options.Extractor_Options;
29+
Node : Libadalang.Analysis.Generic_Package_Decl'Class;
2930
Formal_Part_Node : Libadalang.Analysis.Generic_Formal_Part'Class;
3031
Basic_Decl_Node : Libadalang.Analysis.Basic_Decl'Class);
3132

source/gnatdoc-comments-builders-records.adb

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,12 @@ package body GNATdoc.Comments.Builders.Records is
2929
-----------
3030

3131
procedure Build
32-
(Self : in out Record_Components_Builder;
33-
Documentation : not null GNATdoc.Comments.Structured_Comment_Access;
34-
Options : GNATdoc.Comments.Options.Extractor_Options;
35-
Node : Libadalang.Analysis.Type_Decl'Class;
36-
Advanced_Groups : out Boolean;
37-
Last_Section : out GNATdoc.Comments.Section_Access;
38-
Minimum_Indent : out Langkit_Support.Slocs.Column_Number)
32+
(Self : in out Record_Components_Builder;
33+
Documentation : not null GNATdoc.Comments.Structured_Comment_Access;
34+
Options : GNATdoc.Comments.Options.Extractor_Options;
35+
Node : Libadalang.Analysis.Type_Decl'Class;
36+
Last_Section : out GNATdoc.Comments.Section_Access;
37+
Minimum_Indent : out Langkit_Support.Slocs.Column_Number)
3938
is
4039
function Process (Node : Ada_Node'Class) return Visit_Status;
4140

@@ -114,7 +113,8 @@ package body GNATdoc.Comments.Builders.Records is
114113
Components.Traverse (Process'Access);
115114
Self.Restart_Component_Group (Node.Sloc_Range.End_Line);
116115

117-
Advanced_Groups := Self.Advanced_Groups;
116+
Self.Fill_Structured_Comment (Node, Options.Pattern);
117+
118118
Last_Section := Self.Last_Section;
119119
Minimum_Indent := Self.Minimum_Indent;
120120
end Build;

source/gnatdoc-comments-builders-records.ads

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,12 @@ package GNATdoc.Comments.Builders.Records is
2323
new Abstract_Components_Builder with private;
2424

2525
procedure Build
26-
(Self : in out Record_Components_Builder;
27-
Documentation : not null GNATdoc.Comments.Structured_Comment_Access;
28-
Options : GNATdoc.Comments.Options.Extractor_Options;
29-
Node : Libadalang.Analysis.Type_Decl'Class;
30-
Advanced_Groups : out Boolean;
31-
Last_Section : out GNATdoc.Comments.Section_Access;
32-
Minimum_Indent : out Langkit_Support.Slocs.Column_Number);
26+
(Self : in out Record_Components_Builder;
27+
Documentation : not null GNATdoc.Comments.Structured_Comment_Access;
28+
Options : GNATdoc.Comments.Options.Extractor_Options;
29+
Node : Libadalang.Analysis.Type_Decl'Class;
30+
Last_Section : out GNATdoc.Comments.Section_Access;
31+
Minimum_Indent : out Langkit_Support.Slocs.Column_Number);
3332

3433
private
3534

source/gnatdoc-comments-builders-subprograms.adb

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,16 @@ package body GNATdoc.Comments.Builders.Subprograms is
2727
-----------
2828

2929
procedure Build
30-
(Self : in out Subprogram_Components_Builder;
31-
Documentation : not null GNATdoc.Comments.Structured_Comment_Access;
32-
Options : GNATdoc.Comments.Options.Extractor_Options;
33-
Spec_Node : Libadalang.Analysis.Base_Subp_Spec'Class;
34-
Name_Node : Libadalang.Analysis.Defining_Name'Class;
35-
Params_Node : Libadalang.Analysis.Params'Class;
36-
Returns_Node : Libadalang.Analysis.Type_Expr'Class;
37-
Advanced_Groups : out Boolean;
38-
Last_Section : out GNATdoc.Comments.Section_Access;
39-
Minimum_Indent : out Langkit_Support.Slocs.Column_Number)
30+
(Self : in out Subprogram_Components_Builder;
31+
Documentation : not null GNATdoc.Comments.Structured_Comment_Access;
32+
Options : GNATdoc.Comments.Options.Extractor_Options;
33+
Node : Libadalang.Analysis.Basic_Decl'Class;
34+
Spec_Node : Libadalang.Analysis.Base_Subp_Spec'Class;
35+
Name_Node : Libadalang.Analysis.Defining_Name'Class;
36+
Params_Node : Libadalang.Analysis.Params'Class;
37+
Returns_Node : Libadalang.Analysis.Type_Expr'Class;
38+
Last_Section : out GNATdoc.Comments.Section_Access;
39+
Minimum_Indent : out Langkit_Support.Slocs.Column_Number)
4040
is
4141
use all type GNATdoc.Comments.Options.Documentation_Style;
4242
use type Langkit_Support.Slocs.Line_Number;
@@ -128,7 +128,8 @@ package body GNATdoc.Comments.Builders.Subprograms is
128128
end;
129129
end if;
130130

131-
Advanced_Groups := Self.Advanced_Groups;
131+
Self.Fill_Structured_Comment (Node, Options.Pattern);
132+
132133
Last_Section := Self.Last_Section;
133134
Minimum_Indent := Self.Minimum_Indent;
134135
end Build;

source/gnatdoc-comments-builders-subprograms.ads

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,16 @@ package GNATdoc.Comments.Builders.Subprograms is
2626
new Abstract_Components_Builder with private;
2727

2828
procedure Build
29-
(Self : in out Subprogram_Components_Builder;
30-
Documentation : not null GNATdoc.Comments.Structured_Comment_Access;
31-
Options : GNATdoc.Comments.Options.Extractor_Options;
32-
Spec_Node : Libadalang.Analysis.Base_Subp_Spec'Class;
33-
Name_Node : Libadalang.Analysis.Defining_Name'Class;
34-
Params_Node : Libadalang.Analysis.Params'Class;
35-
Returns_Node : Libadalang.Analysis.Type_Expr'Class;
36-
Advanced_Groups : out Boolean;
37-
Last_Section : out GNATdoc.Comments.Section_Access;
38-
Minimum_Indent : out Langkit_Support.Slocs.Column_Number)
29+
(Self : in out Subprogram_Components_Builder;
30+
Documentation : not null GNATdoc.Comments.Structured_Comment_Access;
31+
Options : GNATdoc.Comments.Options.Extractor_Options;
32+
Node : Libadalang.Analysis.Basic_Decl'Class;
33+
Spec_Node : Libadalang.Analysis.Base_Subp_Spec'Class;
34+
Name_Node : Libadalang.Analysis.Defining_Name'Class;
35+
Params_Node : Libadalang.Analysis.Params'Class;
36+
Returns_Node : Libadalang.Analysis.Type_Expr'Class;
37+
Last_Section : out GNATdoc.Comments.Section_Access;
38+
Minimum_Indent : out Langkit_Support.Slocs.Column_Number)
3939
with Pre =>
4040
Spec_Node.Kind in Libadalang.Common.Ada_Entry_Spec
4141
| Libadalang.Common.Ada_Subp_Spec;

source/gnatdoc-comments-builders.adb

Lines changed: 63 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,75 @@
1515
-- of the license. --
1616
------------------------------------------------------------------------------
1717

18-
with VSS.Strings; use VSS.Strings;
19-
with VSS.Strings.Conversions; use VSS.Strings.Conversions;
18+
with VSS.Strings; use VSS.Strings;
19+
with VSS.Strings.Conversions; use VSS.Strings.Conversions;
2020

21-
with Langkit_Support.Slocs; use Langkit_Support.Slocs;
22-
with Langkit_Support.Text; use Langkit_Support.Text;
23-
with Libadalang.Analysis; use Libadalang.Analysis;
24-
with Libadalang.Common; use Libadalang.Common;
21+
with Langkit_Support.Slocs; use Langkit_Support.Slocs;
22+
with Langkit_Support.Text; use Langkit_Support.Text;
23+
with Libadalang.Analysis; use Libadalang.Analysis;
24+
with Libadalang.Common; use Libadalang.Common;
25+
26+
with GNATdoc.Comments.Utilities; use GNATdoc.Comments.Utilities;
2527

2628
package body GNATdoc.Comments.Builders is
2729

2830
use all type GNATdoc.Comments.Options.Documentation_Style;
2931

32+
-----------------------------
33+
-- Fill_Structured_Comment --
34+
-----------------------------
35+
36+
procedure Fill_Structured_Comment
37+
(Self : in out Abstract_Components_Builder'Class;
38+
Node : Basic_Decl'Class;
39+
Pattern : VSS.Regular_Expressions.Regular_Expression)
40+
is
41+
Node_Location : constant Source_Location_Range := Node.Sloc_Range;
42+
Location : Source_Location_Range;
43+
44+
begin
45+
-- Extract comments inside the declaration and fill text of raw,
46+
-- parameters, returns, and literals sections.
47+
48+
declare
49+
Token : Token_Reference := Node.Token_Start;
50+
51+
begin
52+
while Token /= No_Token and Token /= Node.Token_End loop
53+
Location := Sloc_Range (Data (Token));
54+
55+
if Kind (Data (Token)) = Ada_Comment then
56+
for Section of Self.Documentation.Sections loop
57+
if Section.Kind
58+
in Raw | Enumeration_Literal | Field
59+
| Parameter | Returns | Formal
60+
and then
61+
(Location.Start_Line
62+
in Section.Exact_Start_Line
63+
.. Section.Exact_End_Line
64+
or Location.Start_Line
65+
in Section.Group_Start_Line
66+
.. Section.Group_End_Line)
67+
68+
then
69+
if Self.Advanced_Groups
70+
and Location.Start_Line = Section.Group_Start_Line
71+
and not Section.Text.Is_Empty
72+
then
73+
Section.Text.Append (Empty_Virtual_String);
74+
end if;
75+
76+
Append_Documentation_Line
77+
(Section.Text, Text (Token), Pattern);
78+
end if;
79+
end loop;
80+
end if;
81+
82+
Token := Next (Token);
83+
end loop;
84+
end;
85+
end Fill_Structured_Comment;
86+
3087
----------------
3188
-- Initialize --
3289
----------------

source/gnatdoc-comments-builders.ads

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,15 @@
1616
------------------------------------------------------------------------------
1717

1818
-- This packages provides base tagged type to construct set of sections of
19-
-- structured comment.
19+
-- structured comment and to fill them by documentation extracted from inside
20+
-- of the declaration. Builders doesn't process documentation above and below
21+
-- declaration.
2022

2123
private with Langkit_Support.Slocs;
2224
private with Libadalang.Analysis;
2325

26+
private with VSS.Regular_Expressions;
27+
2428
private with GNATdoc.Comments.Options;
2529

2630
private package GNATdoc.Comments.Builders is
@@ -85,4 +89,16 @@ private
8589
-- breaks group, for instance, t shpuld be called after processing of the
8690
-- discriminants of the record type, and before processing of the fields.
8791

92+
procedure Fill_Structured_Comment
93+
(Self : in out Abstract_Components_Builder'Class;
94+
Node : Libadalang.Analysis.Basic_Decl'Class;
95+
Pattern : VSS.Regular_Expressions.Regular_Expression);
96+
-- Extract comments' text from the given declaration and fill sections
97+
-- of the provided structured comment. Also, creates raw sections for
98+
-- the leading and trailing comments and extract them into these sections.
99+
--
100+
-- @param Decl_Node Whole declaration.
101+
-- @param Pattern Regular expression to detect documentation lines.
102+
-- @param Documentation Structured comment to fill.
103+
88104
end GNATdoc.Comments.Builders;

0 commit comments

Comments
 (0)