aboutsummaryrefslogtreecommitdiff
path: root/gcc/ada/libgnat/g-table.ads
blob: 68eb686c595c7d79727f33948547b0f0264cca1c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
------------------------------------------------------------------------------
--                                                                          --
--                         GNAT RUN-TIME COMPONENTS                         --
--                                                                          --
--                            G N A T . T A B L E                           --
--                                                                          --
--                                 S p e c                                  --
--                                                                          --
--                     Copyright (C) 1998-2024, AdaCore                     --
--                                                                          --
-- GNAT is free software;  you can  redistribute it  and/or modify it under --
-- terms of the  GNU General Public License as published  by the Free Soft- --
-- ware  Foundation;  either version 3,  or (at your option) any later ver- --
-- sion.  GNAT is distributed in the hope that it will be useful, but WITH- --
-- OUT ANY WARRANTY;  without even the  implied warranty of MERCHANTABILITY --
-- or FITNESS FOR A PARTICULAR PURPOSE.                                     --
--                                                                          --
-- As a special exception under Section 7 of GPL version 3, you are granted --
-- additional permissions described in the GCC Runtime Library Exception,   --
-- version 3.1, as published by the Free Software Foundation.               --
--                                                                          --
-- You should have received a copy of the GNU General Public License and    --
-- a copy of the GCC Runtime Library Exception along with this program;     --
-- see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see    --
-- <http://www.gnu.org/licenses/>.                                          --
--                                                                          --
-- GNAT was originally developed  by the GNAT team at  New York University. --
-- Extensive contributions were provided by Ada Core Technologies Inc.      --
--                                                                          --
------------------------------------------------------------------------------

--  This package provides a singleton version of GNAT.Dynamic_Tables
--  (g-dyntab.ads). See that package for documentation. This package just
--  declares a single instance of GNAT.Dynamic_Tables.Instance, and provides
--  wrappers for all the subprograms, passing that single instance.

--  Note that these three interfaces should remain synchronized to keep as much
--  coherency as possible among these related units:
--
--     GNAT.Dynamic_Tables
--     GNAT.Table
--     Table (the compiler unit)

with GNAT.Dynamic_Tables;

generic
   type Table_Component_Type is private;
   type Table_Index_Type     is range <>;

   Table_Low_Bound   : Table_Index_Type := Table_Index_Type'First;
   Table_Initial     : Positive := 8;
   Table_Increment   : Natural := 100;
   Table_Name        : String := ""; -- for debugging printouts
   pragma Unreferenced (Table_Name);
   Release_Threshold : Natural := 0;

package GNAT.Table is
   pragma Elaborate_Body;

   package Tab is new GNAT.Dynamic_Tables
     (Table_Component_Type,
      Table_Index_Type,
      Table_Low_Bound,
      Table_Initial,
      Table_Increment,
      Release_Threshold);

   subtype Valid_Table_Index_Type is Tab.Valid_Table_Index_Type;
   subtype Table_Last_Type is Tab.Table_Last_Type;
   subtype Table_Type is Tab.Table_Type;
   function "=" (X, Y : Table_Type) return Boolean renames Tab."=";

   subtype Table_Ptr is Tab.Table_Ptr;

   The_Instance : Tab.Instance;
   Table : Table_Ptr renames The_Instance.Table;
   Locked : Boolean renames The_Instance.Locked;

   function Is_Empty return Boolean;

   procedure Init;
   pragma Inline (Init);
   procedure Free;
   pragma Inline (Free);

   function First return Table_Index_Type;
   pragma Inline (First);

   function Last return Table_Last_Type;
   pragma Inline (Last);

   procedure Release;
   pragma Inline (Release);

   procedure Set_Last (New_Val : Table_Last_Type);
   pragma Inline (Set_Last);

   procedure Increment_Last;
   pragma Inline (Increment_Last);

   procedure Decrement_Last;
   pragma Inline (Decrement_Last);

   procedure Append (New_Val : Table_Component_Type);
   pragma Inline (Append);

   procedure Append_All (New_Vals : Table_Type);
   pragma Inline (Append_All);

   procedure Set_Item
     (Index : Valid_Table_Index_Type;
      Item  : Table_Component_Type);
   pragma Inline (Set_Item);

   subtype Saved_Table is Tab.Instance;
   --  Type used for Save/Restore subprograms

   function Save return Saved_Table;
   pragma Inline (Save);
   --  Resets table to empty, but saves old contents of table in returned
   --  value, for possible later restoration by a call to Restore.

   procedure Restore (T : in out Saved_Table);
   pragma Inline (Restore);
   --  Given a Saved_Table value returned by a prior call to Save, restores
   --  the table to the state it was in at the time of the Save call.

   procedure Allocate (Num : Integer := 1);
   function Allocate (Num : Integer := 1) return Valid_Table_Index_Type;
   pragma Inline (Allocate);
   --  Adds Num to Last. The function version also returns the old value of
   --  Last + 1. Note that this function has the possible side effect of
   --  reallocating the table. This means that a reference X.Table (X.Allocate)
   --  is incorrect, since the call to X.Allocate may modify the results of
   --  calling X.Table.

   generic
     with procedure Action
       (Index : Valid_Table_Index_Type;
        Item  : Table_Component_Type;
        Quit  : in out Boolean) is <>;
   procedure For_Each;
   pragma Inline (For_Each);

   generic
     with function Lt (Comp1, Comp2 : Table_Component_Type) return Boolean;
   procedure Sort_Table;
   pragma Inline (Sort_Table);

end GNAT.Table;