|
| 1 | +------------------------------------------------------------------------------ |
| 2 | +-- GNAT Documentation Generation Tool -- |
| 3 | +-- -- |
| 4 | +-- Copyright (C) 2022, AdaCore -- |
| 5 | +-- -- |
| 6 | +-- This is free software; you can redistribute it and/or modify it under -- |
| 7 | +-- terms of the GNU General Public License as published by the Free Soft- -- |
| 8 | +-- ware Foundation; either version 3, or (at your option) any later ver- -- |
| 9 | +-- sion. This software is distributed in the hope that it will be useful, -- |
| 10 | +-- but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN- -- |
| 11 | +-- TABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public -- |
| 12 | +-- License for more details. You should have received a copy of the GNU -- |
| 13 | +-- General Public License distributed with this software; see file -- |
| 14 | +-- COPYING3. If not, go to http://www.gnu.org/licenses for a complete copy -- |
| 15 | +-- of the license. -- |
| 16 | +------------------------------------------------------------------------------ |
| 17 | + |
| 18 | +package body GNATdoc.Comments.Builders.Protecteds is |
| 19 | + |
| 20 | + use Libadalang.Analysis; |
| 21 | + use Libadalang.Common; |
| 22 | + |
| 23 | + ----------- |
| 24 | + -- Build -- |
| 25 | + ----------- |
| 26 | + |
| 27 | + procedure Build |
| 28 | + (Self : in out Protected_Components_Builder; |
| 29 | + Documentation : not null GNATdoc.Comments.Structured_Comment_Access; |
| 30 | + Options : GNATdoc.Comments.Options.Extractor_Options; |
| 31 | + Node : Libadalang.Analysis.Basic_Decl'Class) |
| 32 | + is |
| 33 | + function Process (Node : Ada_Node'Class) return Visit_Status; |
| 34 | + |
| 35 | + ------------- |
| 36 | + -- Process -- |
| 37 | + ------------- |
| 38 | + |
| 39 | + function Process (Node : Ada_Node'Class) return Visit_Status is |
| 40 | + begin |
| 41 | + case Node.Kind is |
| 42 | + when Ada_Known_Discriminant_Part | Ada_Discriminant_Spec_List |
| 43 | + | Ada_Private_Part | Ada_Decl_List |
| 44 | + => |
| 45 | + -- Nodes that contains significant nodes inside thier |
| 46 | + -- subtrees. |
| 47 | + |
| 48 | + return Into; |
| 49 | + |
| 50 | + when Ada_Pragma_Node => |
| 51 | + -- Nodes that doesn't contains significant information. |
| 52 | + |
| 53 | + return Over; |
| 54 | + |
| 55 | + when Ada_Component_Decl => |
| 56 | + Self.Process_Component_Declaration (Node.As_Component_Decl); |
| 57 | + |
| 58 | + for Name of Node.As_Component_Decl.F_Ids loop |
| 59 | + Self.Process_Defining_Name (Field, Name); |
| 60 | + end loop; |
| 61 | + |
| 62 | + return Over; |
| 63 | + |
| 64 | + when Ada_Discriminant_Spec => |
| 65 | + Self.Process_Component_Declaration (Node.As_Discriminant_Spec); |
| 66 | + |
| 67 | + for Name of Node.As_Discriminant_Spec.F_Ids loop |
| 68 | + Self.Process_Defining_Name (Field, Name); |
| 69 | + end loop; |
| 70 | + |
| 71 | + return Over; |
| 72 | + |
| 73 | + when Ada_Subp_Decl | Ada_Entry_Decl => |
| 74 | + Self.Restart_Component_Group (Node.Sloc_Range.Start_Line); |
| 75 | + |
| 76 | + return Over; |
| 77 | + |
| 78 | + when others => |
| 79 | + raise Program_Error with Ada_Node_Kind_Type'Image (Node.Kind); |
| 80 | + end case; |
| 81 | + end Process; |
| 82 | + |
| 83 | + Discriminants : constant Discriminant_Part := |
| 84 | + (case Node.Kind is |
| 85 | + when Ada_Protected_Type_Decl => |
| 86 | + Node.As_Protected_Type_Decl.F_Discriminants, |
| 87 | + when others => No_Discriminant_Part); |
| 88 | + Definition : constant Protected_Def := |
| 89 | + (case Node.Kind is |
| 90 | + when Ada_Single_Protected_Decl => |
| 91 | + Node.As_Single_Protected_Decl.F_Definition, |
| 92 | + when Ada_Protected_Type_Decl => |
| 93 | + Node.As_Protected_Type_Decl.F_Definition, |
| 94 | + when others => No_Protected_Def); |
| 95 | + |
| 96 | + begin |
| 97 | + Self.Initialize (Documentation, Options, Node); |
| 98 | + |
| 99 | + -- Process discriminants of the protected type declaration. |
| 100 | + |
| 101 | + if not Discriminants.Is_Null then |
| 102 | + Discriminants.Traverse (Process'Access); |
| 103 | + |
| 104 | + -- Detect first line of the next declartion after discriminants part |
| 105 | + |
| 106 | + declare |
| 107 | + Token : Token_Reference := Discriminants.Token_End; |
| 108 | + |
| 109 | + begin |
| 110 | + loop |
| 111 | + Token := Next (Token); |
| 112 | + |
| 113 | + exit when Token = No_Token; |
| 114 | + |
| 115 | + case Kind (Data (Token)) is |
| 116 | + when Ada_Whitespace | Ada_Comment => |
| 117 | + -- Ignore whitespace separators and comments |
| 118 | + |
| 119 | + null; |
| 120 | + |
| 121 | + when Ada_Is | Ada_With => |
| 122 | + -- Ignore 'is' and 'with' keyword that starts aspects |
| 123 | + -- specification, interface list of public parts of |
| 124 | + -- protected specification: they may be left on the |
| 125 | + -- same line with last discriminant. |
| 126 | + |
| 127 | + null; |
| 128 | + |
| 129 | + when others => |
| 130 | + exit; |
| 131 | + end case; |
| 132 | + end loop; |
| 133 | + |
| 134 | + if Token /= No_Token then |
| 135 | + Self.Restart_Component_Group |
| 136 | + (Sloc_Range (Data (Token)).End_Line); |
| 137 | + end if; |
| 138 | + end; |
| 139 | + end if; |
| 140 | + |
| 141 | + -- Components of the private type can be declared in the private part |
| 142 | + -- only. Public part can contains subprograms/entries only, thus ignore |
| 143 | + -- hole public part. |
| 144 | + -- |
| 145 | + -- ??? Should it be controlled by the "generate private" option ??? |
| 146 | + |
| 147 | + if not Definition.F_Private_Part.Is_Null then |
| 148 | + Definition.F_Private_Part.Traverse (Process'Access); |
| 149 | + Self.Restart_Component_Group (Node.Sloc_Range.End_Line); |
| 150 | + end if; |
| 151 | + |
| 152 | + Self.Fill_Structured_Comment (Node, Options.Pattern); |
| 153 | + end Build; |
| 154 | + |
| 155 | +end GNATdoc.Comments.Builders.Protecteds; |
0 commit comments