1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
5 -- S Y S T E M . R I D E N T --
9 -- Copyright (C) 1992-2011, Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. --
18 -- As a special exception under Section 7 of GPL version 3, you are granted --
19 -- additional permissions described in the GCC Runtime Library Exception, --
20 -- version 3.1, as published by the Free Software Foundation. --
22 -- You should have received a copy of the GNU General Public License and --
23 -- a copy of the GCC Runtime Library Exception along with this program; --
24 -- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
25 -- <http://www.gnu.org/licenses/>. --
27 -- GNAT was originally developed by the GNAT team at New York University. --
28 -- Extensive contributions were provided by Ada Core Technologies Inc. --
30 ------------------------------------------------------------------------------
32 -- This package defines the set of restriction identifiers. It is a generic
33 -- package that is instantiated by the compiler/binder in package Rident, and
34 -- is instantiated in package System.Restrictions for use at run-time.
36 -- The reason that we make this a generic package is so that in the case of
37 -- the instantiation in Rident for use at compile time and bind time, we can
38 -- generate normal image tables for the enumeration types, which are needed
39 -- for diagnostic and informational messages. At run-time we really do not
40 -- want to waste the space for these image tables, and they are not needed,
41 -- so we can do the instantiation under control of Discard_Names to remove
45 package System.Rident is
48 -- The following enumeration type defines the set of restriction
49 -- identifiers that are implemented in GNAT.
51 -- To add a new restriction identifier, add an entry with the name to be
52 -- used in the pragma, and add calls to the Restrict.Check_Restriction
53 -- routine as appropriate.
55 type Restriction_Id is
57 -- The following cases are checked for consistency in the binder. The
58 -- binder will check that every unit either has the restriction set, or
59 -- does not violate the restriction.
61 (Simple_Barriers, -- GNAT (Ravenscar)
62 No_Abort_Statements, -- (RM D.7(5), H.4(3))
63 No_Access_Subprograms, -- (RM H.4(17))
64 No_Allocators, -- (RM H.4(7))
65 No_Allocators_After_Elaboration, -- Ada 2012 (RM D.7(19.1/2))
66 No_Anonymous_Allocators, -- Ada 2012 (RM H.4(8/1))
67 No_Asynchronous_Control, -- (RM D.7(10))
69 No_Default_Stream_Attributes, -- Ada 2012 (RM 13.12.1(4/2))
70 No_Delay, -- (RM H.4(21))
71 No_Direct_Boolean_Operators, -- GNAT
72 No_Dispatch, -- (RM H.4(19))
73 No_Dispatching_Calls, -- GNAT
74 No_Dynamic_Attachment, -- GNAT
75 No_Dynamic_Priorities, -- (RM D.9(9))
76 No_Enumeration_Maps, -- GNAT
77 No_Entry_Calls_In_Elaboration_Code, -- GNAT
78 No_Entry_Queue, -- GNAT (Ravenscar)
79 No_Exception_Handlers, -- GNAT
80 No_Exception_Propagation, -- GNAT
81 No_Exception_Registration, -- GNAT
82 No_Exceptions, -- (RM H.4(12))
83 No_Finalization, -- GNAT
84 No_Fixed_Point, -- (RM H.4(15))
85 No_Floating_Point, -- (RM H.4(14))
86 No_IO, -- (RM H.4(20))
87 No_Implicit_Conditionals, -- GNAT
88 No_Implicit_Dynamic_Code, -- GNAT
89 No_Implicit_Heap_Allocations, -- (RM D.8(8), H.4(3))
90 No_Implicit_Loops, -- GNAT
91 No_Initialize_Scalars, -- GNAT
92 No_Local_Allocators, -- (RM H.4(8))
93 No_Local_Timing_Events, -- (RM D.7(10.2/2))
94 No_Local_Protected_Objects, -- GNAT
95 No_Nested_Finalization, -- (RM D.7(4))
96 No_Protected_Type_Allocators, -- GNAT
97 No_Protected_Types, -- (RM H.4(5))
98 No_Recursion, -- (RM H.4(22))
99 No_Reentrancy, -- (RM H.4(23))
100 No_Relative_Delay, -- GNAT (Ravenscar)
101 No_Requeue_Statements, -- GNAT
102 No_Secondary_Stack, -- GNAT
103 No_Select_Statements, -- GNAT (Ravenscar)
104 No_Specific_Termination_Handlers, -- (RM D.7(10.7/2))
105 No_Standard_Storage_Pools, -- GNAT
106 No_Stream_Optimizations, -- GNAT
108 No_Task_Allocators, -- (RM D.7(7))
109 No_Task_Attributes_Package, -- GNAT
110 No_Task_Hierarchy, -- (RM D.7(3), H.4(3))
111 No_Task_Termination, -- GNAT (Ravenscar)
113 No_Terminate_Alternatives, -- (RM D.7(6))
114 No_Unchecked_Access, -- (RM H.4(18))
115 No_Unchecked_Conversion, -- (RM H.4(16))
116 No_Unchecked_Deallocation, -- (RM H.4(9))
117 Static_Priorities, -- GNAT
118 Static_Storage_Size, -- GNAT
120 -- The following require consistency checking with special rules. See
121 -- individual routines in unit Bcheck for details of what is required.
123 No_Default_Initialization, -- GNAT
125 -- The following cases do not require consistency checking
127 Immediate_Reclamation, -- (RM H.4(10))
128 No_Implementation_Aspect_Specifications, -- Ada 2012 AI-241
129 No_Implementation_Attributes, -- Ada 2005 AI-257
130 No_Implementation_Identifiers, -- Ada 2012 AI-246
131 No_Implementation_Pragmas, -- Ada 2005 AI-257
132 No_Implementation_Restrictions, -- GNAT
133 No_Implementation_Units, -- Ada 2012 AI-242
134 No_Implicit_Aliasing, -- GNAT
135 No_Elaboration_Code, -- GNAT
136 No_Obsolescent_Features, -- Ada 2005 AI-368
137 No_Wide_Characters, -- GNAT
140 -- The following cases require a parameter value
142 -- The following entries are fully checked at compile/bind time, which
143 -- means that the compiler can in general tell the minimum value which
144 -- could be used with a restrictions pragma. The binder can deduce the
145 -- appropriate minimum value for the partition by taking the maximum
146 -- value required by any unit.
148 Max_Protected_Entries, -- (RM D.7(14))
149 Max_Select_Alternatives, -- (RM D.7(12))
150 Max_Task_Entries, -- (RM D.7(13), H.4(3))
152 -- The following entries are also fully checked at compile/bind time,
153 -- and the compiler can also at least in some cases tell the minimum
154 -- value which could be used with a restriction pragma. The difference
155 -- is that the contributions are additive, so the binder deduces this
156 -- value by adding the unit contributions.
158 Max_Tasks, -- (RM D.7(19), H.4(3))
160 -- The following entries are checked at compile time only for zero/
161 -- nonzero entries. This means that the compiler can tell at compile
162 -- time if a restriction value of zero is (would be) violated, but that
163 -- the compiler cannot distinguish between different non-zero values.
165 Max_Asynchronous_Select_Nesting, -- (RM D.7(18), H.4(3))
166 Max_Entry_Queue_Length, -- GNAT
168 -- The remaining entries are not checked at compile/bind time
170 Max_Storage_At_Blocking, -- (RM D.7(17))
172 Not_A_Restriction_Id);
174 -- Synonyms permitted for historical purposes of compatibility.
175 -- Must be coordinated with Restrict.Process_Restriction_Synonym.
177 Boolean_Entry_Barriers : Restriction_Id renames Simple_Barriers;
178 Max_Entry_Queue_Depth : Restriction_Id renames Max_Entry_Queue_Length;
179 No_Dynamic_Interrupts : Restriction_Id renames No_Dynamic_Attachment;
180 No_Requeue : Restriction_Id renames No_Requeue_Statements;
181 No_Task_Attributes : Restriction_Id renames No_Task_Attributes_Package;
183 subtype All_Restrictions is Restriction_Id range
184 Simple_Barriers .. Max_Storage_At_Blocking;
185 -- All restrictions (excluding only Not_A_Restriction_Id)
187 subtype All_Boolean_Restrictions is Restriction_Id range
188 Simple_Barriers .. SPARK;
189 -- All restrictions which do not take a parameter
191 subtype Partition_Boolean_Restrictions is All_Boolean_Restrictions range
192 Simple_Barriers .. Static_Storage_Size;
193 -- Boolean restrictions that are checked for partition consistency.
194 -- Note that all parameter restrictions are checked for partition
195 -- consistency by default, so this distinction is only needed in the
196 -- case of Boolean restrictions.
198 subtype Cunit_Boolean_Restrictions is All_Boolean_Restrictions range
199 Immediate_Reclamation .. SPARK;
200 -- Boolean restrictions that are not checked for partition consistency
201 -- and that thus apply only to the current unit. Note that for these
202 -- restrictions, the compiler does not apply restrictions found in
203 -- with'ed units, parent specs etc. to the main unit.
205 subtype All_Parameter_Restrictions is
207 Max_Protected_Entries .. Max_Storage_At_Blocking;
208 -- All restrictions that take a parameter
210 subtype Checked_Parameter_Restrictions is
211 All_Parameter_Restrictions range
212 Max_Protected_Entries .. Max_Entry_Queue_Length;
213 -- These are the parameter restrictions that can be at least partially
214 -- checked at compile/binder time. Minimally, the compiler can detect
215 -- violations of a restriction pragma with a value of zero reliably.
217 subtype Checked_Max_Parameter_Restrictions is
218 Checked_Parameter_Restrictions range
219 Max_Protected_Entries .. Max_Task_Entries;
220 -- Restrictions with parameters that can be checked in some cases by
221 -- maximizing among statically detected instances where the compiler
222 -- can determine the count.
224 subtype Checked_Add_Parameter_Restrictions is
225 Checked_Parameter_Restrictions range
226 Max_Tasks .. Max_Tasks;
227 -- Restrictions with parameters that can be checked in some cases by
228 -- summing the statically detected instances where the compiler can
229 -- determine the count.
231 subtype Checked_Val_Parameter_Restrictions is
232 Checked_Parameter_Restrictions range
233 Max_Protected_Entries .. Max_Tasks;
234 -- Restrictions with parameter where the count is known at least in some
235 -- cases by the compiler/binder.
237 subtype Checked_Zero_Parameter_Restrictions is
238 Checked_Parameter_Restrictions range
239 Max_Asynchronous_Select_Nesting .. Max_Entry_Queue_Length;
240 -- Restrictions with parameters where the compiler can detect the use of
241 -- the feature, and hence violations of a restriction specifying a value
242 -- of zero, but cannot detect specific values other than zero/nonzero.
244 subtype Unchecked_Parameter_Restrictions is
245 All_Parameter_Restrictions range
246 Max_Storage_At_Blocking .. Max_Storage_At_Blocking;
247 -- Restrictions with parameters where the compiler cannot ever detect
248 -- corresponding compile time usage, so the binder and compiler never
249 -- detect violations of any restriction.
251 -------------------------------------
252 -- Restriction Status Declarations --
253 -------------------------------------
255 -- The following declarations are used to record the current status or
256 -- restrictions (for the current unit, or related units, at compile time,
257 -- and for all units in a partition at bind time or run time).
259 type Restriction_Flags is array (All_Restrictions) of Boolean;
260 type Restriction_Values is array (All_Parameter_Restrictions) of Natural;
261 type Parameter_Flags is array (All_Parameter_Restrictions) of Boolean;
263 type Restrictions_Info is record
264 Set : Restriction_Flags;
265 -- An entry is True in the Set array if a restrictions pragma has been
266 -- encountered for the given restriction. If the value is True for a
267 -- parameter restriction, then the corresponding entry in the Value
268 -- array gives the minimum value encountered for any such restriction.
270 Value : Restriction_Values;
271 -- If the entry for a parameter restriction in Set is True (i.e. a
272 -- restrictions pragma for the restriction has been encountered), then
273 -- the corresponding entry in the Value array is the minimum value
274 -- specified by any such restrictions pragma. Note that a restrictions
275 -- pragma specifying a value greater than Int'Last is simply ignored.
277 Violated : Restriction_Flags;
278 -- An entry is True in the violations array if the compiler has detected
279 -- a violation of the restriction. For a parameter restriction, the
280 -- Count and Unknown arrays have additional information.
282 Count : Restriction_Values;
283 -- If an entry for a parameter restriction is True in Violated, the
284 -- corresponding entry in the Count array may record additional
285 -- information. If the actual minimum count is known (by taking
286 -- maximums, or sums, depending on the restriction), it will be
287 -- recorded in this array. If not, then the value will remain zero.
288 -- The value is also zero for a non-violated restriction.
290 Unknown : Parameter_Flags;
291 -- If an entry for a parameter restriction is True in Violated, the
292 -- corresponding entry in the Unknown array may record additional
293 -- information. If the actual count is not known by the compiler (but
294 -- is known to be non-zero), then the entry in Unknown will be True.
295 -- This indicates that the value in Count is not known to be exact,
296 -- and the actual violation count may be higher.
298 -- Note: If Violated (K) is True, then either Count (K) > 0 or
299 -- Unknown (K) = True. It is possible for both these to be set.
300 -- For example, if Count (K) = 3 and Unknown (K) is True, it means
301 -- that the actual violation count is at least 3 but might be higher.
304 No_Restrictions : constant Restrictions_Info :=
305 (Set => (others => False),
306 Value => (others => 0),
307 Violated => (others => False),
308 Count => (others => 0),
309 Unknown => (others => False));
310 -- Used to initialize Restrictions_Info variables
312 ----------------------------------
313 -- Profile Definitions and Data --
314 ----------------------------------
316 -- Note: to add a profile, modify the following declarations appropriately,
317 -- add Name_xxx to Snames, and add a branch to the conditions for pragmas
318 -- Profile and Profile_Warnings in the body of Sem_Prag.
322 No_Implementation_Extensions,
325 -- Names of recognized profiles. No_Profile is used to indicate that a
326 -- restriction came from pragma Restrictions[_Warning], as opposed to
327 -- pragma Profile[_Warning].
329 subtype Profile_Name_Actual is Profile_Name
330 range No_Implementation_Extensions .. Restricted;
331 -- Actual used profile names
333 type Profile_Data is record
334 Set : Restriction_Flags;
335 -- Set to True if given restriction must be set for the profile, and
336 -- False if it need not be set (False does not mean that it must not be
337 -- set, just that it need not be set). If the flag is True for a
338 -- parameter restriction, then the Value array gives the maximum value
339 -- permitted by the profile.
341 Value : Restriction_Values;
342 -- An entry in this array is meaningful only if the corresponding flag
343 -- in Set is True. In that case, the value in this array is the maximum
344 -- value of the parameter permitted by the profile.
347 Profile_Info : constant array (Profile_Name_Actual) of Profile_Data :=
349 (No_Implementation_Extensions =>
350 -- Restrictions for Restricted profile
353 (No_Implementation_Aspect_Specifications => True,
354 No_Implementation_Attributes => True,
355 No_Implementation_Identifiers => True,
356 No_Implementation_Pragmas => True,
357 No_Implementation_Units => True,
360 -- Value settings for Restricted profile (none
365 -- Restricted Profile
369 -- Restrictions for Restricted profile
372 (No_Abort_Statements => True,
373 No_Asynchronous_Control => True,
374 No_Dynamic_Attachment => True,
375 No_Dynamic_Priorities => True,
376 No_Entry_Queue => True,
377 No_Local_Protected_Objects => True,
378 No_Protected_Type_Allocators => True,
379 No_Requeue_Statements => True,
380 No_Task_Allocators => True,
381 No_Task_Attributes_Package => True,
382 No_Task_Hierarchy => True,
383 No_Terminate_Alternatives => True,
384 Max_Asynchronous_Select_Nesting => True,
385 Max_Protected_Entries => True,
386 Max_Select_Alternatives => True,
387 Max_Task_Entries => True,
390 -- Value settings for Restricted profile
393 (Max_Asynchronous_Select_Nesting => 0,
394 Max_Protected_Entries => 1,
395 Max_Select_Alternatives => 0,
396 Max_Task_Entries => 0,
401 -- Note: the table entries here only represent the
402 -- required restriction profile for Ravenscar. The
403 -- full Ravenscar profile also requires:
405 -- pragma Dispatching_Policy (FIFO_Within_Priorities);
406 -- pragma Locking_Policy (Ceiling_Locking);
407 -- pragma Detect_Blocking
411 -- Restrictions for Ravenscar = Restricted profile ..
414 (No_Abort_Statements => True,
415 No_Asynchronous_Control => True,
416 No_Dynamic_Attachment => True,
417 No_Dynamic_Priorities => True,
418 No_Entry_Queue => True,
419 No_Local_Protected_Objects => True,
420 No_Protected_Type_Allocators => True,
421 No_Requeue_Statements => True,
422 No_Task_Allocators => True,
423 No_Task_Attributes_Package => True,
424 No_Task_Hierarchy => True,
425 No_Terminate_Alternatives => True,
426 Max_Asynchronous_Select_Nesting => True,
427 Max_Protected_Entries => True,
428 Max_Select_Alternatives => True,
429 Max_Task_Entries => True,
431 -- plus these additional restrictions:
434 No_Implicit_Heap_Allocations => True,
435 No_Relative_Delay => True,
436 No_Select_Statements => True,
437 No_Task_Termination => True,
438 Simple_Barriers => True,
441 -- Value settings for Ravenscar (same as Restricted)
444 (Max_Asynchronous_Select_Nesting => 0,
445 Max_Protected_Entries => 1,
446 Max_Select_Alternatives => 0,
447 Max_Task_Entries => 0,