Skip to content

Commit 8b10b25

Browse files
author
automatic-merge
committed
Merge remote branch 'origin/master' into edge
2 parents b619fc8 + 95d8c2b commit 8b10b25

File tree

3 files changed

+266
-50
lines changed

3 files changed

+266
-50
lines changed

source/gnatdoc-comments-helpers.adb

Lines changed: 253 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -35,22 +35,35 @@ package body GNATdoc.Comments.Helpers is
3535

3636
function Get_Plain_Text_Description
3737
(Documentation : Structured_Comment;
38-
Name : Defining_Name'Class)
38+
Symbol : VSS.Strings.Virtual_String)
3939
return VSS.String_Vectors.Virtual_String_Vector;
4040
-- Return description as plain text. Name is the defining name of the
4141
-- documented entity.
4242

4343
function Get_Plain_Text_Description
4444
(Documentation : Structured_Comment;
45-
Name : Defining_Name'Class;
46-
Subname : Defining_Name'Class)
45+
Symbol : VSS.Strings.Virtual_String;
46+
Subsymbol : VSS.Strings.Virtual_String)
4747
return VSS.String_Vectors.Virtual_String_Vector;
4848
-- Return description as plain text. Name and Subname are defining names
4949
-- of the documented entity. This hierarhy is used for generic declarations
5050
-- only (name is a name of the formal and subname is a name of the
5151
-- component depends from the kind of formal (name of parameter,
5252
-- discriminant, etc.)).
5353

54+
procedure Get_Plain_Text_Documentation
55+
(Name : Libadalang.Analysis.Defining_Name'Class;
56+
Options : GNATdoc.Comments.Options.Extractor_Options;
57+
Code_Snippet : out VSS.String_Vectors.Virtual_String_Vector;
58+
Comment : out GNATdoc.Comments.Structured_Comment;
59+
Symbol : out VSS.Strings.Virtual_String;
60+
Subsymbol : out VSS.Strings.Virtual_String);
61+
62+
procedure Merge
63+
(Documentation : in out Structured_Comment;
64+
Item : Structured_Comment);
65+
-- Appends all components of the `Item` into `Documentation`.
66+
5467
--------------------------
5568
-- Get_Ada_Code_Snippet --
5669
--------------------------
@@ -248,13 +261,11 @@ package body GNATdoc.Comments.Helpers is
248261

249262
function Get_Plain_Text_Description
250263
(Documentation : Structured_Comment;
251-
Name : Defining_Name'Class)
264+
Symbol : VSS.Strings.Virtual_String)
252265
return VSS.String_Vectors.Virtual_String_Vector is
253266
begin
254267
for Section of Documentation.Sections loop
255-
if Section.Kind in Component
256-
and then Section.Symbol = Utilities.To_Symbol (Name)
257-
then
268+
if Section.Kind in Component and then Section.Symbol = Symbol then
258269
return Get_Plain_Text_Description (Section);
259270
end if;
260271
end loop;
@@ -268,15 +279,9 @@ package body GNATdoc.Comments.Helpers is
268279

269280
function Get_Plain_Text_Description
270281
(Documentation : Structured_Comment;
271-
Name : Defining_Name'Class;
272-
Subname : Defining_Name'Class)
273-
return VSS.String_Vectors.Virtual_String_Vector
274-
is
275-
Symbol : constant VSS.Strings.Virtual_String :=
276-
GNATdoc.Comments.Utilities.To_Symbol (Name);
277-
Subsymbol : constant VSS.Strings.Virtual_String :=
278-
GNATdoc.Comments.Utilities.To_Symbol (Subname);
279-
282+
Symbol : VSS.Strings.Virtual_String;
283+
Subsymbol : VSS.Strings.Virtual_String)
284+
return VSS.String_Vectors.Virtual_String_Vector is
280285
begin
281286
for Section of Documentation.Sections loop
282287
if Section.Kind = Formal and then Section.Symbol = Symbol then
@@ -298,17 +303,18 @@ package body GNATdoc.Comments.Helpers is
298303
----------------------------------
299304

300305
procedure Get_Plain_Text_Documentation
301-
(Name : Libadalang.Analysis.Defining_Name'Class;
302-
Options : GNATdoc.Comments.Options.Extractor_Options;
303-
Code_Snippet : out VSS.String_Vectors.Virtual_String_Vector;
304-
Documentation : out VSS.String_Vectors.Virtual_String_Vector)
306+
(Name : Libadalang.Analysis.Defining_Name'Class;
307+
Options : GNATdoc.Comments.Options.Extractor_Options;
308+
Code_Snippet : out VSS.String_Vectors.Virtual_String_Vector;
309+
Comment : out GNATdoc.Comments.Structured_Comment;
310+
Symbol : out VSS.Strings.Virtual_String;
311+
Subsymbol : out VSS.Strings.Virtual_String)
305312
is
306313
Decl : constant Basic_Decl := Name.P_Basic_Decl;
307314
Parent_Basic_Decl : constant Basic_Decl := Decl.P_Parent_Basic_Decl;
308315
Decl_To_Extract : Basic_Decl;
309316
Name_To_Extract : Defining_Name;
310317
Subname_To_Extract : Defining_Name;
311-
Extracted : Structured_Comment;
312318
Messages : GNATdoc.Messages.Message_Container;
313319

314320
begin
@@ -364,6 +370,7 @@ package body GNATdoc.Comments.Helpers is
364370
| Ada_Single_Protected_Decl
365371
| Ada_Subp_Body
366372
| Ada_Subp_Decl
373+
| Ada_Subp_Renaming_Decl
367374
| Ada_Subtype_Decl
368375
| Ada_Task_Type_Decl
369376
or (Decl.Kind in Ada_Type_Decl
@@ -389,7 +396,8 @@ package body GNATdoc.Comments.Helpers is
389396

390397
elsif Decl.Kind in Ada_Param_Spec | Ada_Entry_Index_Spec
391398
and then Parent_Basic_Decl.Kind
392-
in Ada_Subp_Decl | Ada_Entry_Decl | Ada_Entry_Body
399+
in Ada_Subp_Decl | Ada_Subp_Body | Ada_Subp_Renaming_Decl
400+
| Ada_Entry_Decl | Ada_Entry_Body
393401
then
394402
-- Parameters of the subprograms and entries, family index of
395403
-- entries.
@@ -411,21 +419,6 @@ package body GNATdoc.Comments.Helpers is
411419
Decl.As_Enum_Literal_Decl.P_Enum_Type.As_Basic_Decl;
412420
Name_To_Extract := Name.As_Defining_Name;
413421

414-
elsif Decl.Kind = Ada_Incomplete_Type_Decl then
415-
-- We are looking at an incomplete type declaration. Check the
416-
-- complete part, and use it for doc if it's not private.
417-
declare
418-
Next_Part : constant Basic_Decl :=
419-
P_Next_Part_For_Decl (Decl);
420-
begin
421-
if not (Next_Part.Is_Null
422-
or else As_Type_Decl (Next_Part).P_Is_Private)
423-
then
424-
Decl_To_Extract := As_Basic_Decl (Next_Part);
425-
Name_To_Extract := Name.As_Defining_Name;
426-
end if;
427-
end;
428-
429422
elsif Decl.Kind in Ada_Discriminant_Spec | Ada_Component_Decl
430423
and then Parent_Basic_Decl.Kind
431424
in Ada_Type_Decl | Ada_Concrete_Type_Decl_Range
@@ -438,23 +431,235 @@ package body GNATdoc.Comments.Helpers is
438431

439432
if not Decl_To_Extract.Is_Null then
440433
GNATdoc.Comments.Extractor.Extract
441-
(Decl_To_Extract, Options, Extracted, Messages);
434+
(Decl_To_Extract, Options, Comment, Messages);
435+
436+
if not Name_To_Extract.Is_Null then
437+
Symbol := GNATdoc.Comments.Utilities.To_Symbol (Name_To_Extract);
438+
439+
if not Subname_To_Extract.Is_Null then
440+
Subsymbol :=
441+
GNATdoc.Comments.Utilities.To_Symbol (Subname_To_Extract);
442+
end if;
443+
end if;
444+
445+
Code_Snippet := Get_Ada_Code_Snippet (Comment);
446+
end if;
447+
end Get_Plain_Text_Documentation;
448+
449+
----------------------------------
450+
-- Get_Plain_Text_Documentation --
451+
----------------------------------
452+
453+
procedure Get_Plain_Text_Documentation
454+
(Name : Libadalang.Analysis.Defining_Name'Class;
455+
Origin : Libadalang.Analysis.Ada_Node'Class;
456+
Options : GNATdoc.Comments.Options.Extractor_Options;
457+
Code_Snippet : out VSS.String_Vectors.Virtual_String_Vector;
458+
Documentation : out VSS.String_Vectors.Virtual_String_Vector)
459+
is
460+
function Is_Callable
461+
(Name : Libadalang.Analysis.Defining_Name'Class) return Boolean;
462+
463+
-----------------
464+
-- Is_Callable --
465+
-----------------
466+
467+
function Is_Callable
468+
(Name : Libadalang.Analysis.Defining_Name'Class) return Boolean is
469+
begin
470+
case Name.P_Basic_Decl.Kind is
471+
when Ada_Entry_Decl
472+
| Ada_Expr_Function
473+
| Ada_Null_Subp_Decl
474+
| Ada_Subp_Body
475+
| Ada_Subp_Decl
476+
| Ada_Subp_Renaming_Decl
477+
=>
478+
return True;
479+
480+
when Ada_Generic_Subp_Instantiation
481+
=>
482+
return False;
483+
-- ???
484+
485+
when Ada_Component_Decl
486+
| Ada_Concrete_Type_Decl
487+
| Ada_Enum_Literal_Decl
488+
| Ada_For_Loop_Var_Decl
489+
| Ada_Generic_Package_Decl
490+
| Ada_Generic_Subp_Decl
491+
| Ada_Incomplete_Type_Decl
492+
| Ada_Object_Decl
493+
| Ada_Package_Body
494+
| Ada_Package_Decl
495+
| Ada_Param_Spec
496+
| Ada_Subtype_Decl
497+
=>
498+
return False;
499+
500+
when others =>
501+
raise Program_Error with Name.P_Basic_Decl.Kind'Img;
502+
end case;
503+
end Is_Callable;
504+
505+
All_Decls : constant Libadalang.Analysis.Defining_Name_Array :=
506+
Name.P_All_Parts;
507+
Most_Visible_Decl : constant Libadalang.Analysis.Defining_Name :=
508+
(if Origin.Is_Null
509+
then Name.As_Defining_Name else Name.P_Most_Visible_Part (Origin));
510+
Most_Visible_Index : Positive := All_Decls'First;
511+
All_Code_Snippet :
512+
array (All_Decls'Range) of VSS.String_Vectors.Virtual_String_Vector;
513+
All_Comment :
514+
array (All_Decls'Range) of GNATdoc.Comments.Structured_Comment;
515+
All_Symbol :
516+
array (All_Decls'Range) of VSS.Strings.Virtual_String;
517+
All_Subsymbol :
518+
array (All_Decls'Range) of VSS.Strings.Virtual_String;
519+
Comment : Structured_Comment;
520+
521+
begin
522+
-- Lookup for index of most visible declaration
523+
524+
for J in All_Decls'Range loop
525+
if All_Decls (J) = Most_Visible_Decl then
526+
Most_Visible_Index := J;
527+
528+
exit;
529+
end if;
530+
end loop;
531+
532+
-- Extract documentation for each declaration till most visible
533+
534+
for J in All_Decls'First .. Most_Visible_Index loop
535+
Get_Plain_Text_Documentation
536+
(Name => All_Decls (J),
537+
Options => Options,
538+
Code_Snippet => All_Code_Snippet (J),
539+
Comment => All_Comment (J),
540+
Symbol => All_Symbol (J),
541+
Subsymbol => All_Subsymbol (J));
542+
end loop;
543+
544+
-- Merge documentation
442545

443-
if Name_To_Extract.Is_Null then
444-
Documentation := Get_Plain_Text_Description (Extracted);
546+
Code_Snippet.Clear;
547+
Documentation.Clear;
445548

446-
elsif Subname_To_Extract.Is_Null then
447-
Documentation :=
448-
Get_Plain_Text_Description (Extracted, Name_To_Extract);
549+
if Is_Callable (Most_Visible_Decl) then
550+
-- For subprograms/entries use first declaration - subprogram/entry
551+
-- specification. When it is not available subprogram/entry body is
552+
-- used.
553+
554+
Code_Snippet := All_Code_Snippet (All_Code_Snippet'First);
555+
556+
else
557+
for J in All_Decls'First .. Most_Visible_Index loop
558+
if not All_Code_Snippet (J).Is_Empty then
559+
if not Code_Snippet.Is_Empty
560+
and then not Code_Snippet.Last_Element.Is_Empty
561+
then
562+
Code_Snippet.Append (Empty_Virtual_String);
563+
end if;
564+
565+
Code_Snippet.Append (All_Code_Snippet (J));
566+
end if;
567+
end loop;
568+
end if;
449569

450-
else
451-
Documentation :=
452-
Get_Plain_Text_Description
453-
(Extracted, Name_To_Extract, Subname_To_Extract);
570+
for J in All_Decls'First .. Most_Visible_Index loop
571+
if not All_Comment (J).Is_Empty then
572+
Merge (Comment, All_Comment (J));
454573
end if;
574+
end loop;
575+
576+
if not All_Subsymbol (Most_Visible_Index).Is_Empty then
577+
Documentation :=
578+
Get_Plain_Text_Description
579+
(Comment,
580+
All_Symbol (Most_Visible_Index),
581+
All_Subsymbol (Most_Visible_Index));
582+
583+
elsif not All_Symbol (Most_Visible_Index).Is_Empty then
584+
Documentation :=
585+
Get_Plain_Text_Description
586+
(Comment, All_Symbol (Most_Visible_Index));
455587

456-
Code_Snippet := Get_Ada_Code_Snippet (Extracted);
588+
else
589+
Documentation := Get_Plain_Text_Description (Comment);
457590
end if;
458591
end Get_Plain_Text_Documentation;
459592

593+
-----------
594+
-- Merge --
595+
-----------
596+
597+
procedure Merge
598+
(Documentation : in out Structured_Comment;
599+
Item : Structured_Comment)
600+
is
601+
procedure Merge
602+
(Target_Sections : in out Section_Vectors.Vector;
603+
Source_Sections : Section_Vectors.Vector);
604+
605+
-----------
606+
-- Merge --
607+
-----------
608+
609+
procedure Merge
610+
(Target_Sections : in out Section_Vectors.Vector;
611+
Source_Sections : Section_Vectors.Vector)
612+
is
613+
Target : Section_Access;
614+
615+
begin
616+
for Source of Source_Sections loop
617+
Target := null;
618+
619+
if Source.Kind /= Raw then
620+
-- Raw sections are not needed, skip them.
621+
622+
for Section of Target_Sections loop
623+
if Section.Kind = Source.Kind
624+
and Section.Symbol = Source.Symbol
625+
then
626+
Target := Section;
627+
628+
exit;
629+
end if;
630+
end loop;
631+
end if;
632+
633+
if Target = null then
634+
Target :=
635+
new Section'
636+
(Kind => Source.Kind,
637+
Name => Source.Name,
638+
Symbol => Source.Symbol,
639+
Text => Source.Text,
640+
Exact_Start_Line => 0,
641+
Exact_End_Line => 0,
642+
Group_Start_Line => 0,
643+
Group_End_Line => 0,
644+
Sections => <>);
645+
Target_Sections.Append (Target);
646+
647+
else
648+
if not Target.Text.Is_Empty
649+
and not Source.Text.Is_Empty
650+
then
651+
Target.Text.Append (VSS.Strings.Empty_Virtual_String);
652+
end if;
653+
654+
Target.Text.Append (Source.Text);
655+
end if;
656+
657+
Merge (Target.Sections, Source.Sections);
658+
end loop;
659+
end Merge;
660+
661+
begin
662+
Merge (Documentation.Sections, Item.Sections);
663+
end Merge;
664+
460665
end GNATdoc.Comments.Helpers;

0 commit comments

Comments
 (0)