Skip to content

Commit 13b2875

Browse files
committed
V721-009 Initial support for protected objects/types declarations.
1 parent 496a7ed commit 13b2875

File tree

6 files changed

+190
-11
lines changed

6 files changed

+190
-11
lines changed

share/gnatdoc/html/template/doc.xhtml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,15 @@
7070
</ul>
7171
</div>
7272

73+
<div tal:omit-tag="" tal:condition="gnatdoc/entity/protected_types">
74+
<h3>Protected Types and Protected Objects</h3>
75+
<ul>
76+
<li tal:repeat='item gnatdoc/entity/protected_types'>
77+
<a href='#' tal:attributes='href item/full_href' tal:content='item/name'/>
78+
</li>
79+
</ul>
80+
</div>
81+
7382
<div tal:omit-tag="" tal:condition="gnatdoc/entity/access_types">
7483
<h3>Access Types</h3>
7584
<ul>

source/backend/gnatdoc-backend-html.adb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,12 @@ package body GNATdoc.Backend.HTML is
169169
Entity_Information_Set_Proxy'
170170
(Index_Entities => Self.Entity.Task_Types'Unchecked_Access);
171171

172+
elsif Name = "protected_types" then
173+
return
174+
Entity_Information_Set_Proxy'
175+
(Index_Entities =>
176+
Self.Entity.Protected_Types'Unchecked_Access);
177+
172178
elsif Name = "constants" then
173179
return
174180
Entity_Information_Set_Proxy'
@@ -342,6 +348,12 @@ package body GNATdoc.Backend.HTML is
342348
end if;
343349
end loop;
344350

351+
for Item of Globals.Protected_Types loop
352+
if not Is_Private_Entity (Item) then
353+
Non_Index_Entities.Insert (Item);
354+
end if;
355+
end loop;
356+
345357
declare
346358
Input : Input_Sources.File.File_Input;
347359
Reader : VSS.XML.XmlAda_Readers.XmlAda_Reader;

source/frontend/gnatdoc-entities.ads

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ package GNATdoc.Entities is
7171
Interface_Types : aliased Entity_Information_Sets.Set;
7272
Tagged_Types : aliased Entity_Information_Sets.Set;
7373
Task_Types : aliased Entity_Information_Sets.Set;
74+
Protected_Types : aliased Entity_Information_Sets.Set;
7475
Access_Types : aliased Entity_Information_Sets.Set;
7576
Subtypes : aliased Entity_Information_Sets.Set;
7677
Constants : aliased Entity_Information_Sets.Set;
@@ -93,9 +94,9 @@ package GNATdoc.Entities is
9394
-- -- Generic subprograms instantiations.
9495
-- Tagged_Types : EInfo_List.Vector; +++
9596
-- Variables : EInfo_List.Vector; +++
96-
-- Tasks : EInfo_List.Vector;
97-
-- Protected_Objects : EInfo_List.Vector;
98-
-- Entries : EInfo_List.Vector;
97+
-- Tasks : EInfo_List.Vector; +++
98+
-- Protected_Objects : EInfo_List.Vector; +++
99+
-- Entries : EInfo_List.Vector; +++
99100

100101
end record;
101102

source/frontend/gnatdoc-frontend.adb

Lines changed: 65 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,14 @@ package body GNATdoc.Frontend is
125125
Enclosing : not null GNATdoc.Entities.Entity_Information_Access)
126126
with Pre => Node.Kind in Ada_Single_Task_Decl | Ada_Task_Type_Decl;
127127

128+
procedure Process_Protected_Decl
129+
(Node : Basic_Decl'Class;
130+
Name : Defining_Name'Class;
131+
Definition : Protected_Def'Class;
132+
Enclosing : not null GNATdoc.Entities.Entity_Information_Access)
133+
with
134+
Pre => Node.Kind in Ada_Single_Protected_Decl | Ada_Protected_Type_Decl;
135+
128136
procedure Process_Entry_Decl
129137
(Node : Entry_Decl'Class;
130138
Enclosing : not null GNATdoc.Entities.Entity_Information_Access);
@@ -411,16 +419,26 @@ package body GNATdoc.Frontend is
411419

412420
return Over;
413421

414-
when Ada_Entry_Decl =>
415-
Process_Entry_Decl (Node.As_Entry_Decl, Enclosing);
422+
when Ada_Single_Protected_Decl =>
423+
Process_Protected_Decl
424+
(Node.As_Single_Protected_Decl,
425+
Node.As_Single_Protected_Decl.F_Name,
426+
Node.As_Single_Protected_Decl.F_Definition,
427+
Enclosing);
416428

417429
return Over;
418430

419-
when Ada_Single_Protected_Decl
420-
| Ada_Protected_Type_Decl
421-
| Ada_Protected_Body
422-
=>
423-
Ada.Text_IO.Put_Line (Image (Node));
431+
when Ada_Protected_Type_Decl =>
432+
Process_Protected_Decl
433+
(Node.As_Protected_Type_Decl,
434+
Node.As_Protected_Type_Decl.F_Name,
435+
Node.As_Protected_Type_Decl.F_Definition,
436+
Enclosing);
437+
438+
return Over;
439+
440+
when Ada_Entry_Decl =>
441+
Process_Entry_Decl (Node.As_Entry_Decl, Enclosing);
424442

425443
return Over;
426444

@@ -930,6 +948,44 @@ package body GNATdoc.Frontend is
930948
end if;
931949
end Process_Private_Type_Def;
932950

951+
----------------------------
952+
-- Process_Protected_Decl --
953+
----------------------------
954+
955+
procedure Process_Protected_Decl
956+
(Node : Basic_Decl'Class;
957+
Name : Defining_Name'Class;
958+
Definition : Protected_Def'Class;
959+
Enclosing : not null GNATdoc.Entities.Entity_Information_Access)
960+
is
961+
Entity : constant not null GNATdoc.Entities.Entity_Information_Access :=
962+
new GNATdoc.Entities.Entity_Information'
963+
(Name => To_Virtual_String (Name.F_Name.Text),
964+
Qualified_Name => To_Virtual_String (Name.P_Fully_Qualified_Name),
965+
Signature => Signature (Name),
966+
Enclosing =>
967+
Signature (Node.P_Parent_Basic_Decl.P_Defining_Name),
968+
Is_Private =>
969+
(Node.Parent.Kind = Ada_Library_Item
970+
and then Node.Parent.As_Library_Item.F_Has_Private),
971+
Documentation => Extract (Node, GNATdoc.Options.Extractor_Options),
972+
others => <>);
973+
974+
begin
975+
Enclosing.Protected_Types.Insert (Entity);
976+
GNATdoc.Entities.To_Entity.Insert (Entity.Signature, Entity);
977+
978+
if GNATdoc.Entities.Globals'Access /= Enclosing then
979+
GNATdoc.Entities.Globals.Protected_Types.Insert (Entity);
980+
end if;
981+
982+
Process_Children (Definition.F_Public_Part, Entity);
983+
984+
if GNATdoc.Options.Frontend_Options.Generate_Private then
985+
Process_Children (Definition.F_Private_Part, Entity);
986+
end if;
987+
end Process_Protected_Decl;
988+
933989
-----------------------------
934990
-- Process_Record_Type_Def --
935991
-----------------------------
@@ -1066,8 +1122,9 @@ package body GNATdoc.Frontend is
10661122
| Ada_Subtype_Decl
10671123
| Ada_Exception_Decl
10681124
| Ada_Single_Task_Type_Decl | Ada_Task_Type_Decl
1125+
| Ada_Single_Protected_Decl | Ada_Protected_Type_Decl
10691126
| Ada_Entry_Decl
1070-
=>
1127+
=>
10711128
null;
10721129

10731130
when others =>

source/gnatdoc-comments-extractor.adb

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,13 @@ package body GNATdoc.Comments.Extractor is
142142
Documentation : in out Structured_Comment'Class);
143143
-- Extract documentation for single task declaration.
144144

145+
procedure Extract_Protected_Decl_Documentation
146+
(Node : Libadalang.Analysis.Basic_Decl'Class;
147+
Definition : Libadalang.Analysis.Protected_Def'Class;
148+
Options : GNATdoc.Comments.Options.Extractor_Options;
149+
Documentation : in out Structured_Comment'Class);
150+
-- Extract documentation for protected type declaration.
151+
145152
procedure Fill_Structured_Comment
146153
(Decl_Node : Basic_Decl'Class;
147154
Advanced_Groups : Boolean;
@@ -455,6 +462,20 @@ package body GNATdoc.Comments.Extractor is
455462
Options,
456463
Documentation);
457464

465+
when Ada_Single_Protected_Decl =>
466+
Extract_Protected_Decl_Documentation
467+
(Node.As_Single_Protected_Decl,
468+
Node.As_Single_Protected_Decl.F_Definition,
469+
Options,
470+
Documentation);
471+
472+
when Ada_Protected_Type_Decl =>
473+
Extract_Protected_Decl_Documentation
474+
(Node.As_Protected_Type_Decl,
475+
Node.As_Protected_Type_Decl.F_Definition,
476+
Options,
477+
Documentation);
478+
458479
when Ada_Entry_Decl =>
459480
Extract_Subprogram_Documentation
460481
(Decl_Node => Node,
@@ -1026,6 +1047,79 @@ package body GNATdoc.Comments.Extractor is
10261047
end;
10271048
end Extract_Leading_Section;
10281049

1050+
------------------------------------------
1051+
-- Extract_Protected_Decl_Documentation --
1052+
------------------------------------------
1053+
1054+
procedure Extract_Protected_Decl_Documentation
1055+
(Node : Libadalang.Analysis.Basic_Decl'Class;
1056+
Definition : Libadalang.Analysis.Protected_Def'Class;
1057+
Options : GNATdoc.Comments.Options.Extractor_Options;
1058+
Documentation : in out Structured_Comment'Class)
1059+
is
1060+
Is_Or_With_Token : Token_Reference;
1061+
Leading_Section : Section_Access;
1062+
Intermediate_Upper_Section : Section_Access;
1063+
1064+
begin
1065+
Extract_Leading_Section
1066+
(Node.Token_Start, Options, True, Documentation, Leading_Section);
1067+
1068+
-- Lookup for 'is' token that begins protected definition, or 'with'
1069+
-- token that ends interface part.
1070+
1071+
Is_Or_With_Token := Definition.Token_Start;
1072+
1073+
loop
1074+
Is_Or_With_Token := Previous (Is_Or_With_Token);
1075+
1076+
exit when Is_Or_With_Token = No_Token;
1077+
1078+
case Kind (Data (Is_Or_With_Token)) is
1079+
when Ada_Whitespace | Ada_Comment =>
1080+
null;
1081+
1082+
when Ada_Is | Ada_With =>
1083+
exit;
1084+
1085+
when others =>
1086+
raise Program_Error;
1087+
end case;
1088+
end loop;
1089+
1090+
Extract_Upper_Intermediate_Section
1091+
(Is_Or_With_Token,
1092+
Definition.Token_End,
1093+
Options,
1094+
Documentation,
1095+
Intermediate_Upper_Section);
1096+
1097+
Remove_Comment_Start_And_Indentation (Documentation, Options.Pattern);
1098+
1099+
declare
1100+
Raw_Section : Section_Access;
1101+
1102+
begin
1103+
-- Select most appropriate section.
1104+
1105+
if Intermediate_Upper_Section /= null
1106+
and then not Intermediate_Upper_Section.Text.Is_Empty
1107+
then
1108+
Raw_Section := Intermediate_Upper_Section;
1109+
1110+
elsif not Leading_Section.Text.Is_Empty then
1111+
Raw_Section := Leading_Section;
1112+
end if;
1113+
1114+
Parse_Raw_Section
1115+
(Raw_Section,
1116+
(Private_Tag => True,
1117+
Member_Tag => True,
1118+
others => False),
1119+
Documentation);
1120+
end;
1121+
end Extract_Protected_Decl_Documentation;
1122+
10291123
---------------------------------------
10301124
-- Extract_Record_Type_Documentation --
10311125
---------------------------------------

source/gnatdoc-comments-extractor.ads

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ package GNATdoc.Comments.Extractor is
4242
| Ada_Object_Decl
4343
| Ada_Package_Decl
4444
| Ada_Package_Renaming_Decl
45+
| Ada_Protected_Type_Decl
46+
| Ada_Single_Protected_Decl
4547
| Ada_Single_Task_Decl
4648
| Ada_Subp_Body
4749
| Ada_Subp_Decl
@@ -79,6 +81,8 @@ package GNATdoc.Comments.Extractor is
7981
| Ada_Object_Decl
8082
| Ada_Package_Decl
8183
| Ada_Package_Renaming_Decl
84+
| Ada_Protected_Type_Decl
85+
| Ada_Single_Protected_Decl
8286
| Ada_Single_Task_Decl
8387
| Ada_Subp_Body
8488
| Ada_Subp_Decl
@@ -116,6 +120,8 @@ package GNATdoc.Comments.Extractor is
116120
| Ada_Object_Decl
117121
| Ada_Package_Decl
118122
| Ada_Package_Renaming_Decl
123+
| Ada_Protected_Type_Decl
124+
| Ada_Single_Protected_Decl
119125
| Ada_Single_Task_Decl
120126
| Ada_Subp_Body
121127
| Ada_Subp_Decl

0 commit comments

Comments
 (0)