annotate gcc/ada/libgnat/a-conhel.ads @ 131:84e7813d76e9

gcc-8.2
author mir3636
date Thu, 25 Oct 2018 07:37:49 +0900
parents 04ced10e8804
children 1830386684a0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 ------------------------------------------------------------------------------
kono
parents:
diff changeset
2 -- --
kono
parents:
diff changeset
3 -- GNAT LIBRARY COMPONENTS --
kono
parents:
diff changeset
4 -- --
kono
parents:
diff changeset
5 -- A D A . C O N T A I N E R S . H E L P E R S --
kono
parents:
diff changeset
6 -- --
kono
parents:
diff changeset
7 -- S p e c --
kono
parents:
diff changeset
8 -- --
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
9 -- Copyright (C) 2015-2018, Free Software Foundation, Inc. --
111
kono
parents:
diff changeset
10 -- --
kono
parents:
diff changeset
11 -- GNAT is free software; you can redistribute it and/or modify it under --
kono
parents:
diff changeset
12 -- terms of the GNU General Public License as published by the Free Soft- --
kono
parents:
diff changeset
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
kono
parents:
diff changeset
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
kono
parents:
diff changeset
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
kono
parents:
diff changeset
16 -- or FITNESS FOR A PARTICULAR PURPOSE. --
kono
parents:
diff changeset
17 -- --
kono
parents:
diff changeset
18 -- As a special exception under Section 7 of GPL version 3, you are granted --
kono
parents:
diff changeset
19 -- additional permissions described in the GCC Runtime Library Exception, --
kono
parents:
diff changeset
20 -- version 3.1, as published by the Free Software Foundation. --
kono
parents:
diff changeset
21 -- --
kono
parents:
diff changeset
22 -- You should have received a copy of the GNU General Public License and --
kono
parents:
diff changeset
23 -- a copy of the GCC Runtime Library Exception along with this program; --
kono
parents:
diff changeset
24 -- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
kono
parents:
diff changeset
25 -- <http://www.gnu.org/licenses/>. --
kono
parents:
diff changeset
26 ------------------------------------------------------------------------------
kono
parents:
diff changeset
27
kono
parents:
diff changeset
28 with Ada.Finalization;
kono
parents:
diff changeset
29 with System.Atomic_Counters;
kono
parents:
diff changeset
30
kono
parents:
diff changeset
31 package Ada.Containers.Helpers is
kono
parents:
diff changeset
32 pragma Annotate (CodePeer, Skip_Analysis);
kono
parents:
diff changeset
33 pragma Pure;
kono
parents:
diff changeset
34
kono
parents:
diff changeset
35 -- Miscellaneous helpers shared among various containers
kono
parents:
diff changeset
36
kono
parents:
diff changeset
37 package SAC renames System.Atomic_Counters;
kono
parents:
diff changeset
38
kono
parents:
diff changeset
39 Count_Type_Last : constant := Count_Type'Last;
kono
parents:
diff changeset
40 -- Count_Type'Last as a universal_integer, so we can compare Index_Type
kono
parents:
diff changeset
41 -- values against this without type conversions that might overflow.
kono
parents:
diff changeset
42
kono
parents:
diff changeset
43 type Tamper_Counts is record
kono
parents:
diff changeset
44 Busy : aliased SAC.Atomic_Unsigned := 0;
kono
parents:
diff changeset
45 Lock : aliased SAC.Atomic_Unsigned := 0;
kono
parents:
diff changeset
46 end record;
kono
parents:
diff changeset
47
kono
parents:
diff changeset
48 -- Busy is positive when tampering with cursors is prohibited. Busy and
kono
parents:
diff changeset
49 -- Lock are both positive when tampering with elements is prohibited.
kono
parents:
diff changeset
50
kono
parents:
diff changeset
51 type Tamper_Counts_Access is access all Tamper_Counts;
kono
parents:
diff changeset
52 for Tamper_Counts_Access'Storage_Size use 0;
kono
parents:
diff changeset
53
kono
parents:
diff changeset
54 generic
kono
parents:
diff changeset
55 package Generic_Implementation is
kono
parents:
diff changeset
56
kono
parents:
diff changeset
57 -- Generic package used in the implementation of containers.
kono
parents:
diff changeset
58
kono
parents:
diff changeset
59 -- This needs to be generic so that the 'Enabled attribute will return
kono
parents:
diff changeset
60 -- the value that is relevant at the point where a container generic is
kono
parents:
diff changeset
61 -- instantiated. For example:
kono
parents:
diff changeset
62 --
kono
parents:
diff changeset
63 -- pragma Suppress (Container_Checks);
kono
parents:
diff changeset
64 -- package My_Vectors is new Ada.Containers.Vectors (...);
kono
parents:
diff changeset
65 --
kono
parents:
diff changeset
66 -- should suppress all container-related checks within the instance
kono
parents:
diff changeset
67 -- My_Vectors.
kono
parents:
diff changeset
68
kono
parents:
diff changeset
69 -- Shorthands for "checks enabled" and "tampering checks enabled". Note
kono
parents:
diff changeset
70 -- that suppressing either Container_Checks or Tampering_Check disables
kono
parents:
diff changeset
71 -- tampering checks. Note that this code needs to be in a generic
kono
parents:
diff changeset
72 -- package, because we want to take account of check suppressions at the
kono
parents:
diff changeset
73 -- instance. We use these flags, along with pragma Inline, to ensure
kono
parents:
diff changeset
74 -- that the compiler can optimize away the checks, as well as the
kono
parents:
diff changeset
75 -- tampering check machinery, when checks are suppressed.
kono
parents:
diff changeset
76
kono
parents:
diff changeset
77 Checks : constant Boolean := Container_Checks'Enabled;
kono
parents:
diff changeset
78 T_Check : constant Boolean :=
kono
parents:
diff changeset
79 Container_Checks'Enabled and Tampering_Check'Enabled;
kono
parents:
diff changeset
80
kono
parents:
diff changeset
81 -- Reference_Control_Type is used as a component of reference types, to
kono
parents:
diff changeset
82 -- prohibit tampering with elements so long as references exist.
kono
parents:
diff changeset
83
kono
parents:
diff changeset
84 type Reference_Control_Type is
kono
parents:
diff changeset
85 new Finalization.Controlled with record
kono
parents:
diff changeset
86 T_Counts : Tamper_Counts_Access;
kono
parents:
diff changeset
87 end record
kono
parents:
diff changeset
88 with Disable_Controlled => not T_Check;
kono
parents:
diff changeset
89
kono
parents:
diff changeset
90 overriding procedure Adjust (Control : in out Reference_Control_Type);
kono
parents:
diff changeset
91 pragma Inline (Adjust);
kono
parents:
diff changeset
92
kono
parents:
diff changeset
93 overriding procedure Finalize (Control : in out Reference_Control_Type);
kono
parents:
diff changeset
94 pragma Inline (Finalize);
kono
parents:
diff changeset
95
kono
parents:
diff changeset
96 procedure Zero_Counts (T_Counts : out Tamper_Counts);
kono
parents:
diff changeset
97 pragma Inline (Zero_Counts);
kono
parents:
diff changeset
98 -- Set Busy and Lock to zero
kono
parents:
diff changeset
99
kono
parents:
diff changeset
100 procedure Busy (T_Counts : in out Tamper_Counts);
kono
parents:
diff changeset
101 pragma Inline (Busy);
kono
parents:
diff changeset
102 -- Prohibit tampering with cursors
kono
parents:
diff changeset
103
kono
parents:
diff changeset
104 procedure Unbusy (T_Counts : in out Tamper_Counts);
kono
parents:
diff changeset
105 pragma Inline (Unbusy);
kono
parents:
diff changeset
106 -- Allow tampering with cursors
kono
parents:
diff changeset
107
kono
parents:
diff changeset
108 procedure Lock (T_Counts : in out Tamper_Counts);
kono
parents:
diff changeset
109 pragma Inline (Lock);
kono
parents:
diff changeset
110 -- Prohibit tampering with elements
kono
parents:
diff changeset
111
kono
parents:
diff changeset
112 procedure Unlock (T_Counts : in out Tamper_Counts);
kono
parents:
diff changeset
113 pragma Inline (Unlock);
kono
parents:
diff changeset
114 -- Allow tampering with elements
kono
parents:
diff changeset
115
kono
parents:
diff changeset
116 procedure TC_Check (T_Counts : Tamper_Counts);
kono
parents:
diff changeset
117 pragma Inline (TC_Check);
kono
parents:
diff changeset
118 -- Tampering-with-cursors check
kono
parents:
diff changeset
119
kono
parents:
diff changeset
120 procedure TE_Check (T_Counts : Tamper_Counts);
kono
parents:
diff changeset
121 pragma Inline (TE_Check);
kono
parents:
diff changeset
122 -- Tampering-with-elements check
kono
parents:
diff changeset
123
kono
parents:
diff changeset
124 -----------------
kono
parents:
diff changeset
125 -- RAII Types --
kono
parents:
diff changeset
126 -----------------
kono
parents:
diff changeset
127
kono
parents:
diff changeset
128 -- Initialize of With_Busy increments the Busy count, and Finalize
kono
parents:
diff changeset
129 -- decrements it. Thus, to prohibit tampering with elements within a
kono
parents:
diff changeset
130 -- given scope, declare an object of type With_Busy. The Busy count
kono
parents:
diff changeset
131 -- will be correctly decremented in case of exception or abort.
kono
parents:
diff changeset
132
kono
parents:
diff changeset
133 -- With_Lock is the same as With_Busy, except it increments/decrements
kono
parents:
diff changeset
134 -- BOTH Busy and Lock, thus prohibiting tampering with cursors.
kono
parents:
diff changeset
135
kono
parents:
diff changeset
136 type With_Busy (T_Counts : not null access Tamper_Counts) is
kono
parents:
diff changeset
137 new Finalization.Limited_Controlled with null record
kono
parents:
diff changeset
138 with Disable_Controlled => not T_Check;
kono
parents:
diff changeset
139 overriding procedure Initialize (Busy : in out With_Busy);
kono
parents:
diff changeset
140 overriding procedure Finalize (Busy : in out With_Busy);
kono
parents:
diff changeset
141
kono
parents:
diff changeset
142 type With_Lock (T_Counts : not null access Tamper_Counts) is
kono
parents:
diff changeset
143 new Finalization.Limited_Controlled with null record
kono
parents:
diff changeset
144 with Disable_Controlled => not T_Check;
kono
parents:
diff changeset
145 overriding procedure Initialize (Lock : in out With_Lock);
kono
parents:
diff changeset
146 overriding procedure Finalize (Lock : in out With_Lock);
kono
parents:
diff changeset
147
kono
parents:
diff changeset
148 -- Variables of type With_Busy and With_Lock are declared only for the
kono
parents:
diff changeset
149 -- effects of Initialize and Finalize, so they are not referenced;
kono
parents:
diff changeset
150 -- disable warnings about that. Note that all variables of these types
kono
parents:
diff changeset
151 -- have names starting with "Busy" or "Lock". These pragmas need to be
kono
parents:
diff changeset
152 -- present wherever these types are used.
kono
parents:
diff changeset
153
kono
parents:
diff changeset
154 pragma Warnings (Off, "variable ""Busy*"" is not referenced");
kono
parents:
diff changeset
155 pragma Warnings (Off, "variable ""Lock*"" is not referenced");
kono
parents:
diff changeset
156
kono
parents:
diff changeset
157 end Generic_Implementation;
kono
parents:
diff changeset
158
kono
parents:
diff changeset
159 end Ada.Containers.Helpers;