Skip to content

Commit 4ed382f

Browse files
committed
Protected body support
1 parent 73169bb commit 4ed382f

File tree

3 files changed

+125
-1
lines changed

3 files changed

+125
-1
lines changed

source/frontend/gnatdoc-frontend.adb

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,10 @@ package body GNATdoc.Frontend is
130130
with
131131
Pre => Node.Kind in Ada_Single_Protected_Decl | Ada_Protected_Type_Decl;
132132

133+
procedure Process_Protected_Body
134+
(Node : Protected_Body'Class;
135+
Enclosing : not null GNATdoc.Entities.Entity_Information_Access);
136+
133137
procedure Process_Entry_Decl
134138
(Node : Entry_Decl'Class;
135139
Enclosing : not null GNATdoc.Entities.Entity_Information_Access);
@@ -439,6 +443,11 @@ package body GNATdoc.Frontend is
439443

440444
return Over;
441445

446+
when Ada_Protected_Body =>
447+
Process_Protected_Body (Node.As_Protected_Body, Enclosing);
448+
449+
return Over;
450+
442451
when Ada_Ada_Node_List
443452
| Ada_Public_Part | Ada_Private_Part
444453
| Ada_Declarative_Part
@@ -951,6 +960,37 @@ package body GNATdoc.Frontend is
951960
end if;
952961
end Process_Private_Type_Def;
953962

963+
----------------------------
964+
-- Process_Protected_Body --
965+
----------------------------
966+
967+
procedure Process_Protected_Body
968+
(Node : Protected_Body'Class;
969+
Enclosing : not null GNATdoc.Entities.Entity_Information_Access)
970+
is
971+
Name : constant Defining_Name := Node.F_Name;
972+
Entity : constant not null
973+
GNATdoc.Entities.Entity_Information_Access :=
974+
new GNATdoc.Entities.Entity_Information'
975+
(Name => To_Virtual_String (Name.F_Name.Text),
976+
Qualified_Name => To_Virtual_String (Name.P_Fully_Qualified_Name),
977+
Signature => Signature (Name),
978+
Enclosing =>
979+
Signature (Node.P_Parent_Basic_Decl.P_Defining_Name),
980+
Documentation => Extract (Node, GNATdoc.Options.Extractor_Options),
981+
others => <>);
982+
983+
begin
984+
Enclosing.Protected_Types.Insert (Entity);
985+
GNATdoc.Entities.To_Entity.Insert (Entity.Signature, Entity);
986+
987+
if GNATdoc.Entities.Globals'Access /= Enclosing then
988+
GNATdoc.Entities.Globals.Packages.Insert (Entity);
989+
end if;
990+
991+
Process_Children (Node.F_Decls, Entity);
992+
end Process_Protected_Body;
993+
954994
----------------------------
955995
-- Process_Protected_Decl --
956996
----------------------------
@@ -1107,7 +1147,7 @@ package body GNATdoc.Frontend is
11071147
do
11081148
case Name.P_Basic_Decl.Kind is
11091149
when Ada_Package_Body | Ada_Subp_Body | Ada_Expr_Function
1110-
| Ada_Subp_Renaming_Decl
1150+
| Ada_Subp_Renaming_Decl | Ada_Protected_Body
11111151
=>
11121152
Result.Append ('$');
11131153

source/gnatdoc-comments-extractor.adb

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,12 @@ package body GNATdoc.Comments.Extractor is
151151
Documentation : in out Structured_Comment'Class);
152152
-- Extract documentation for protected type declaration.
153153

154+
procedure Extract_Protected_Body_Documentation
155+
(Node : Libadalang.Analysis.Protected_Body'Class;
156+
Options : GNATdoc.Comments.Options.Extractor_Options;
157+
Documentation : in out Structured_Comment'Class);
158+
-- Extract documentation for protected body.
159+
154160
procedure Extract_General_Trailing_Documentation
155161
(Decl_Node : Basic_Decl'Class;
156162
Pattern : VSS.Regular_Expressions.Regular_Expression;
@@ -430,6 +436,10 @@ package body GNATdoc.Comments.Extractor is
430436
Options,
431437
Documentation);
432438

439+
when Ada_Protected_Body =>
440+
Extract_Protected_Body_Documentation
441+
(Node.As_Protected_Body, Options, Documentation);
442+
433443
when Ada_Entry_Decl =>
434444
Extract_Subprogram_Documentation
435445
(Decl_Node => Node,
@@ -987,6 +997,77 @@ package body GNATdoc.Comments.Extractor is
987997
end;
988998
end Extract_Leading_Section;
989999

1000+
------------------------------------------
1001+
-- Extract_Protected_Body_Documentation --
1002+
------------------------------------------
1003+
1004+
procedure Extract_Protected_Body_Documentation
1005+
(Node : Libadalang.Analysis.Protected_Body'Class;
1006+
Options : GNATdoc.Comments.Options.Extractor_Options;
1007+
Documentation : in out Structured_Comment'Class)
1008+
is
1009+
Is_Token : Token_Reference :=
1010+
(if Node.F_Aspects.Is_Null
1011+
then Node.F_Name.Token_End else Node.F_Aspects.Token_End);
1012+
Leading_Section : Section_Access;
1013+
Intermediate_Upper_Section : Section_Access;
1014+
1015+
begin
1016+
Extract_Leading_Section
1017+
(Node.Token_Start, Options, True, Documentation, Leading_Section);
1018+
1019+
-- Lookup for 'is' token that begins protected body.
1020+
1021+
loop
1022+
Is_Token := Next (Is_Token);
1023+
1024+
exit when Is_Token = No_Token;
1025+
1026+
case Kind (Data (Is_Token)) is
1027+
when Ada_Whitespace | Ada_Comment =>
1028+
null;
1029+
1030+
when Ada_Is =>
1031+
exit;
1032+
1033+
when others =>
1034+
raise Program_Error;
1035+
end case;
1036+
end loop;
1037+
1038+
Extract_Upper_Intermediate_Section
1039+
(Is_Token,
1040+
Node.Token_End,
1041+
Options,
1042+
Documentation,
1043+
Intermediate_Upper_Section);
1044+
1045+
Remove_Comment_Start_And_Indentation (Documentation, Options.Pattern);
1046+
1047+
declare
1048+
Raw_Section : Section_Access;
1049+
1050+
begin
1051+
-- Select most appropriate section.
1052+
1053+
if Intermediate_Upper_Section /= null
1054+
and then not Intermediate_Upper_Section.Text.Is_Empty
1055+
then
1056+
Raw_Section := Intermediate_Upper_Section;
1057+
1058+
elsif not Leading_Section.Text.Is_Empty then
1059+
Raw_Section := Leading_Section;
1060+
end if;
1061+
1062+
Parse_Raw_Section
1063+
(Raw_Section,
1064+
(Private_Tag => True,
1065+
Member_Tag => True,
1066+
others => False),
1067+
Documentation);
1068+
end;
1069+
end Extract_Protected_Body_Documentation;
1070+
9901071
------------------------------------------
9911072
-- Extract_Protected_Decl_Documentation --
9921073
------------------------------------------

source/gnatdoc-comments-extractor.ads

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ package GNATdoc.Comments.Extractor is
4242
| Ada_Object_Decl
4343
| Ada_Package_Decl
4444
| Ada_Package_Renaming_Decl
45+
| Ada_Protected_Body
4546
| Ada_Protected_Type_Decl
4647
| Ada_Single_Protected_Decl
4748
| Ada_Single_Task_Decl
@@ -81,6 +82,7 @@ package GNATdoc.Comments.Extractor is
8182
| Ada_Object_Decl
8283
| Ada_Package_Decl
8384
| Ada_Package_Renaming_Decl
85+
| Ada_Protected_Body
8486
| Ada_Protected_Type_Decl
8587
| Ada_Single_Protected_Decl
8688
| Ada_Single_Task_Decl
@@ -120,6 +122,7 @@ package GNATdoc.Comments.Extractor is
120122
| Ada_Object_Decl
121123
| Ada_Package_Decl
122124
| Ada_Package_Renaming_Decl
125+
| Ada_Protected_Body
123126
| Ada_Protected_Type_Decl
124127
| Ada_Single_Protected_Decl
125128
| Ada_Single_Task_Decl

0 commit comments

Comments
 (0)