]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/ada/restrict.ads
Correct a function pre/postcondition [PR102403].
[thirdparty/gcc.git] / gcc / ada / restrict.ads
CommitLineData
19235870
RK
1------------------------------------------------------------------------------
2-- --
3-- GNAT COMPILER COMPONENTS --
4-- --
5-- R E S T R I C T --
6-- --
7-- S p e c --
8-- --
8d0d46f4 9-- Copyright (C) 1992-2021, Free Software Foundation, Inc. --
19235870
RK
10-- --
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- --
b5c84c3c 13-- ware Foundation; either version 3, or (at your option) any later ver- --
19235870
RK
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. See the GNU General Public License --
17-- for more details. You should have received a copy of the GNU General --
b5c84c3c
RD
18-- Public License distributed with GNAT; see file COPYING3. If not, go to --
19-- http://www.gnu.org/licenses for a complete copy of the license. --
19235870
RK
20-- --
21-- GNAT was originally developed by the GNAT team at New York University. --
71ff80dc 22-- Extensive contributions were provided by Ada Core Technologies Inc. --
19235870
RK
23-- --
24------------------------------------------------------------------------------
25
26-- This package deals with the implementation of the Restrictions pragma
27
596b25f9
AC
28with Aspects; use Aspects;
29with Namet; use Namet;
30with Rident; use Rident;
31with Snames; use Snames;
5f3ab6fb 32with Table;
596b25f9
AC
33with Types; use Types;
34with Uintp; use Uintp;
19235870
RK
35
36package Restrict is
37
de397a3d 38 Restrictions : Restrictions_Info := No_Restrictions;
6e937c1c
AC
39 -- This variable records restrictions found in any units in the main
40 -- extended unit, and in the case of restrictions checked for partition
41 -- consistency, restrictions found in any with'ed units, parent specs
276e95ca 42 -- etc., since we may as well check as much as we can at compile time.
6e937c1c 43 -- These variables should not be referenced directly by clients. Instead
646e2823 44 -- use Check_Restriction to record a violation of a restriction, and
6e937c1c
AC
45 -- Restriction_Active to test if a given restriction is active.
46
47 Restrictions_Loc : array (All_Restrictions) of Source_Ptr :=
fbf5a39b 48 (others => No_Location);
19235870 49 -- Locations of Restrictions pragmas for error message purposes.
fbf5a39b
AC
50 -- Valid only if corresponding entry in Restrictions is set. A value
51 -- of No_Location is used for implicit restrictions set by another
52 -- pragma, and a value of System_Location is used for restrictions
53 -- set from package Standard by the processing in Targparm.
19235870 54
9b7c38af 55 Restriction_Profile_Name : array (All_Restrictions) of Profile_Name;
db761fee
AC
56 -- Entries in this array are valid only if the corresponding restriction in
57 -- Restrictions is set. The value is the corresponding profile name if the
9b7c38af
RD
58 -- restriction was set by a Profile or Profile_Warnings pragma. The value
59 -- is No_Profile in all other cases.
60
de397a3d 61 Main_Restrictions : Restrictions_Info := No_Restrictions;
6e937c1c
AC
62 -- This variable records only restrictions found in any units of the
63 -- main extended unit. These are the variables used for ali file output,
64 -- since we want the binder to be able to accurately diagnose inter-unit
65 -- restriction violations.
19235870 66
f1c80977 67 Restriction_Warnings : Rident.Restriction_Flags := (others => False);
fbf5a39b
AC
68 -- If one of these flags is set, then it means that violation of the
69 -- corresponding restriction results only in a warning message, not
70 -- in an error message, and the restriction is not otherwise enforced.
6e937c1c
AC
71 -- Note that the flags in Restrictions are set to indicate that the
72 -- restriction is set in this case, but Main_Restrictions is never
73 -- set if Restriction_Warnings is set, so this does not look like a
74 -- restriction to the binder.
fbf5a39b 75
6e937c1c 76 -- The following declarations establish a mapping between restriction
ee10c0ec 77 -- identifiers, and the names of corresponding restricted library units.
19235870
RK
78
79 type Unit_Entry is record
80 Res_Id : Restriction_Id;
81 Filenm : String (1 .. 8);
82 end record;
83
6e937c1c 84 Unit_Array : constant array (Positive range <>) of Unit_Entry := (
06effe87
AC
85 (No_Asynchronous_Control, "a-astaco"),
86 (No_Calendar, "a-calend"),
87 (No_Calendar, "calendar"),
88 (No_Delay, "a-calend"),
89 (No_Delay, "calendar"),
90 (No_Dynamic_Priorities, "a-dynpri"),
91 (No_Finalization, "a-finali"),
79d09a49 92 (No_IO, "a-direct"),
06effe87
AC
93 (No_IO, "a-direio"),
94 (No_IO, "directio"),
95 (No_IO, "a-sequio"),
96 (No_IO, "sequenio"),
97 (No_IO, "a-ststio"),
98 (No_IO, "a-textio"),
99 (No_IO, "text_io "),
100 (No_IO, "a-witeio"),
101 (No_Task_Attributes_Package, "a-tasatt"),
06effe87
AC
102 (No_Unchecked_Conversion, "a-unccon"),
103 (No_Unchecked_Conversion, "unchconv"),
104 (No_Unchecked_Deallocation, "a-uncdea"),
105 (No_Unchecked_Deallocation, "unchdeal"));
19235870 106
bbf1aec2
RD
107 -- The following map has True for all GNAT-defined Restrictions. It is used
108 -- to implement pragma Restrictions (No_Implementation_Restrictions) (which
109 -- is why this restriction itself is excluded from the list).
07fc65c4 110
aff557c7 111 Implementation_Restriction : constant array (All_Restrictions) of Boolean :=
9f4fd324 112 (Simple_Barriers => True,
07fc65c4 113 No_Calendar => True,
be4c5193
AC
114 No_Default_Initialization => True,
115 No_Direct_Boolean_Operators => True,
3bcd6930 116 No_Dispatching_Calls => True,
bcb8c3bb 117 No_Dynamic_Accessibility_Checks => True,
9f4fd324 118 No_Dynamic_Attachment => True,
5b2217f8 119 No_Elaboration_Code => True,
07fc65c4
GB
120 No_Enumeration_Maps => True,
121 No_Entry_Calls_In_Elaboration_Code => True,
122 No_Entry_Queue => True,
123 No_Exception_Handlers => True,
be4c5193 124 No_Exception_Propagation => True,
fbf5a39b 125 No_Exception_Registration => True,
be4c5193 126 No_Finalization => True,
0688dac8 127 No_Fixed_IO => True,
5b2217f8
RD
128 No_Implementation_Attributes => True,
129 No_Implementation_Pragmas => True,
07fc65c4 130 No_Implicit_Conditionals => True,
be4c5193 131 No_Implicit_Aliasing => True,
07fc65c4
GB
132 No_Implicit_Dynamic_Code => True,
133 No_Implicit_Loops => True,
be4c5193 134 No_Initialize_Scalars => True,
07fc65c4 135 No_Local_Protected_Objects => True,
bb012790 136 No_Long_Long_Integers => True,
d8941160 137 No_Multiple_Elaboration => True,
07fc65c4
GB
138 No_Protected_Type_Allocators => True,
139 No_Relative_Delay => True,
6e937c1c 140 No_Requeue_Statements => True,
07fc65c4
GB
141 No_Secondary_Stack => True,
142 No_Select_Statements => True,
143 No_Standard_Storage_Pools => True,
be4c5193 144 No_Stream_Optimizations => True,
07fc65c4 145 No_Streams => True,
06effe87 146 No_Task_Attributes_Package => True,
07fc65c4 147 No_Task_Termination => True,
be4c5193 148 No_Tasking => True,
07fc65c4
GB
149 No_Wide_Characters => True,
150 Static_Priorities => True,
151 Static_Storage_Size => True,
b8c9f7af 152 Pure_Barriers => True,
aa0dfa7e 153 SPARK_05 => True,
07fc65c4
GB
154 others => False);
155
db761fee
AC
156 --------------------------
157 -- No_Dependences Table --
158 --------------------------
159
5f3ab6fb
AC
160 -- The following table records entries made by Restrictions pragmas
161 -- that specify a parameter for No_Dependence. Each such pragma makes
162 -- an entry in this table.
163
164 -- Note: we have chosen to implement this restriction in the "syntactic"
165 -- form, where we do not check that the named package is a language defined
166 -- package, but instead we allow arbitrary package names. The discussion of
167 -- this issue is not complete in the ARG, but the sense seems to be leaning
168 -- in this direction, which makes more sense to us, since it is much more
169 -- useful, and much easier to implement.
170
171 type ND_Entry is record
172 Unit : Node_Id;
173 -- The unit parameter from the No_Dependence pragma
174
175 Warn : Boolean;
176 -- True if from Restriction_Warnings, False if from Restrictions
9b7c38af
RD
177
178 Profile : Profile_Name;
179 -- Set to name of profile from which No_Dependence entry came, or to
180 -- No_Profile if a pragma Restriction set the No_Dependence entry.
5f3ab6fb
AC
181 end record;
182
e7fceebc 183 package No_Dependences is new Table.Table (
5f3ab6fb
AC
184 Table_Component_Type => ND_Entry,
185 Table_Index_Type => Int,
186 Table_Low_Bound => 0,
187 Table_Initial => 200,
188 Table_Increment => 200,
e7fceebc 189 Table_Name => "Name_No_Dependences");
5f3ab6fb 190
db761fee
AC
191 ----------------------------
192 -- No_Use_Of_Entity Table --
193 ----------------------------
194
195 -- The following table records entries made by Restrictions pragmas
196 -- that specify a parameter for No_Use_Of_Entity. Each such pragma makes
197 -- an entry in this table.
198
199 -- Note: we have chosen to implement this restriction in the "syntactic"
200 -- form, where we allow arbitrary fully qualified names to be specified.
201
202 type NE_Entry is record
203 Entity : Node_Id;
204 -- The entity parameter from the No_Use_Of_Entity pragma. This is in
205 -- the form of a selected component, since that is the way the parser
206 -- processes it, and we don't further analyze it.
207
208 Warn : Boolean;
209 -- True if from Restriction_Warnings, False if from Restrictions
210
211 Profile : Profile_Name;
212 -- Set to name of profile from which No_Use_Of_Entity entry came, or to
213 -- No_Profile if a pragma Restriction set the No_Use_Of_Entity entry.
214 end record;
215
216 package No_Use_Of_Entity is new Table.Table (
217 Table_Component_Type => NE_Entry,
218 Table_Index_Type => Int,
219 Table_Low_Bound => 0,
220 Table_Initial => 200,
221 Table_Increment => 200,
222 Table_Name => "Name_No_Use_Of_Entity");
223
224 -- Note that in addition to making an entry in this table, we also set the
225 -- Boolean2 flag of the Name_Table entry for the simple name of the entity.
226 -- This is used to avoid most useless searches of this table.
227
19235870
RK
228 -----------------
229 -- Subprograms --
230 -----------------
231
9aff36e9
RD
232 -- Note: several of these subprograms can generate error messages (e.g.
233 -- Check_Restriction). These routines should be called in the analyzer
234 -- rather than the expander, so that the associated error messages are
235 -- correctly generated in semantics only (-gnatc) mode.
236
fbf5a39b
AC
237 function Abort_Allowed return Boolean;
238 pragma Inline (Abort_Allowed);
239 -- Tests to see if abort is allowed by the current restrictions settings.
240 -- For abort to be allowed, either No_Abort_Statements must be False,
241 -- or Max_Asynchronous_Select_Nesting must be non-zero.
242
c86cf714
RD
243 procedure Check_Compiler_Unit (Feature : String; N : Node_Id);
244 -- If unit N is in a unit that has a pragma Compiler_Unit_Warning, then
245 -- a message is posted on node N noting use of the given feature is not
246 -- permitted in the compiler (bootstrap considerations).
247
248 procedure Check_Compiler_Unit (Feature : String; Loc : Source_Ptr);
249 -- If unit N is in a unit that has a pragma Compiler_Unit_Warning, then a
250 -- message is posted at location Loc noting use of the given feature is not
251 -- permitted in the compiler (bootstrap considerations).
2d9ea47f 252
19235870
RK
253 procedure Check_Restricted_Unit (U : Unit_Name_Type; N : Node_Id);
254 -- Checks if loading of unit U is prohibited by the setting of some
255 -- restriction (e.g. No_IO restricts the loading of unit Ada.Text_IO).
256 -- If a restriction exists post error message at the given node.
257
6e937c1c 258 procedure Check_Restriction
23685ae6
AC
259 (Msg_Issued : out Boolean;
260 R : Restriction_Id;
261 N : Node_Id;
262 V : Uint := Uint_Minus_1);
19235870 263 -- Checks that the given restriction is not set, and if it is set, an
23685ae6
AC
264 -- appropriate message is posted on the given node, in which case
265 -- Msg_Issued is set to True (and False otherwise). Also records the
9b7c38af
RD
266 -- violation in the appropriate internal arrays. Note that it is mandatory
267 -- to always use this routine to check if a restriction is violated. Such
268 -- checks must never be done directly by the caller, since otherwise
269 -- violations in the absence of restrictions are not properly recorded. The
270 -- value of V is relevant only for parameter restrictions, and in this case
271 -- indicates the exact count for the violation. If the exact count is not
272 -- known, V is left at its default of -1 which indicates an unknown count.
19235870 273
23685ae6 274 procedure Check_Restriction
e917aec2
RD
275 (R : Restriction_Id;
276 N : Node_Id;
277 V : Uint := Uint_Minus_1);
23685ae6
AC
278 -- Wrapper on Check_Restriction with Msg_Issued, with the out-parameter
279 -- being ignored here.
280
5f3ab6fb
AC
281 procedure Check_Restriction_No_Dependence (U : Node_Id; Err : Node_Id);
282 -- Called when a dependence on a unit is created (either implicitly, or by
e917aec2
RD
283 -- an explicit WITH clause). U is a node for the unit involved, and Err is
284 -- the node to which an error will be attached if necessary.
5f3ab6fb 285
e7fceebc 286 procedure Check_Restriction_No_Specification_Of_Aspect (N : Node_Id);
d4175ef4
GL
287 -- N is the node id for an N_Aspect_Specification, an N_Pragma, or an
288 -- N_Attribute_Definition_Clause. An error message (warning) will be issued
289 -- if a restriction (warning) was previously set for this aspect using
290 -- Set_No_Specification_Of_Aspect.
e7fceebc 291
18dae814 292 procedure Check_Restriction_No_Use_Of_Attribute (N : Node_Id);
58ba2415
HK
293 -- N denotes an attribute definition clause or an attribute reference. An
294 -- error message (warning) will be issued if a restriction (warning) was
295 -- previously set for this attribute using Set_No_Use_Of_Attribute.
18dae814
RD
296
297 procedure Check_Restriction_No_Use_Of_Entity (N : Node_Id);
298 -- N is the node id for an entity reference. An error message (warning)
07fbef62 299 -- will be issued if a restriction (warning) was previously set for this
18dae814
RD
300 -- entity name using Set_No_Use_Of_Entity.
301
302 procedure Check_Restriction_No_Use_Of_Pragma (N : Node_Id);
303 -- N is the node of a pragma. An error message (warning) will be issued
304 -- if a restriction (warning) was previously set for this pragma using
305 -- Set_No_Use_Of_Pragma.
306
19235870
RK
307 procedure Check_Elaboration_Code_Allowed (N : Node_Id);
308 -- Tests to see if elaboration code is allowed by the current restrictions
e917aec2
RD
309 -- settings. This function is called by Gigi when it needs to define an
310 -- elaboration routine. If elaboration code is not allowed, an error
19235870
RK
311 -- message is posted on the node given as argument.
312
c7732bbe
EB
313 -- WARNING: There is a matching C declaration of this subprogram in fe.h
314
a4901c08
AC
315 procedure Check_No_Implicit_Aliasing (Obj : Node_Id);
316 -- Obj is a node for which Is_Aliased_View is True, which is being used in
317 -- a context (e.g. 'Access) where no implicit aliasing is allowed if the
318 -- restriction No_Implicit_Aliasing is set. This procedure checks for the
319 -- case where the restriction is active and Obj does not meet the required
320 -- rules for avoiding implicit aliases, and issues a restriction message.
321
cadf64d1
BD
322 procedure Check_Implicit_Dynamic_Code_Allowed (N : Node_Id);
323 -- Tests to see if dynamic code generation (dynamically generated
324 -- trampolines, in particular) is allowed by the current restrictions
325 -- settings. This function is called by Gigi when it needs to generate code
326 -- that generates a trampoline. If not allowed, an error message is posted
327 -- on the node given as argument.
328
c7732bbe
EB
329 -- WARNING: There is a matching C declaration of this subprogram in fe.h
330
fbf5a39b
AC
331 procedure Check_No_Implicit_Heap_Alloc (N : Node_Id);
332 -- Equivalent to Check_Restriction (No_Implicit_Heap_Allocations, N).
333 -- Provided for easy use by back end, which has to check this restriction.
19235870 334
c7732bbe 335 -- WARNING: There is a matching C declaration of this subprogram in fe.h
c96c518f
AC
336
337 procedure Check_No_Implicit_Protected_Alloc (N : Node_Id);
338 -- Equivalent to:
339 -- Check_Restriction (No_Implicit_Protected_Object_Allocations, N)
340 -- Provided for easy use by back end, which has to check this restriction.
341
c7732bbe
EB
342 -- WARNING: There is a matching C declaration of this subprogram in fe.h
343
344 procedure Check_No_Implicit_Task_Alloc (N : Node_Id);
345 -- Equivalent to Check_Restriction (No_Implicit_Task_Allocations, N).
346 -- Provided for easy use by back end, which has to check this restriction.
347
348 -- WARNING: There is a matching C declaration of this subprogram in fe.h
349
b5c739f9
RD
350 procedure Check_Obsolescent_2005_Entity (E : Entity_Id; N : Node_Id);
351 -- This routine checks if the entity E is one of the obsolescent entries
352 -- in Ada.Characters.Handling in Ada 2005 and No_Obsolescent_Features
353 -- restriction is active. If so an appropriate message is given. N is
354 -- the node on which the message is to be placed. It's a bit kludgy to
355 -- have this highly specialized routine rather than some wonderful general
356 -- mechanism (e.g. a special pragma) to handle this case, but there are
357 -- only six cases, and it is not worth the effort to do something general.
358
30196a76
RD
359 procedure Check_Wide_Character_Restriction (E : Entity_Id; N : Node_Id);
360 -- This procedure checks if the No_Wide_Character restriction is active,
361 -- and if so, if N Comes_From_Source, and the root type of E is one of
362 -- [Wide_]Wide_Character or [Wide_]Wide_String, then the restriction
363 -- violation is recorded, and an appropriate message given.
364
19235870 365 function Get_Restriction_Id
6e937c1c 366 (N : Name_Id) return Restriction_Id;
19235870 367 -- Given an identifier name, determines if it is a valid restriction
052e0603
AC
368 -- identifier, and if so returns the corresponding Restriction_Id value,
369 -- otherwise returns Not_A_Restriction_Id.
19235870 370
2cbac6c6
AC
371 function OK_No_Dependence_Unit_Name (N : Node_Id) return Boolean;
372 -- Used in checking No_Dependence argument of pragma Restrictions or
373 -- pragma Restrictions_Warning, or attribute Restriction_Set. Returns
374 -- True if N has the proper form for a unit name, False otherwise.
375
18dae814
RD
376 function OK_No_Use_Of_Entity_Name (N : Node_Id) return Boolean;
377 -- Used in checking No_Use_Of_Entity argument of pragma Restrictions or
378 -- pragma Restrictions_Warning, or attribute Restriction_Set. Returns
379 -- True if N has the proper form for an entity name, False otherwise.
380
bcb8c3bb
JS
381 function No_Dynamic_Accessibility_Checks_Enabled
382 (N : Node_Id) return Boolean;
383 -- Test to see if the current restrictions settings specify that
384 -- No_Dynamic_Accessibility_Checks is activated.
385
386 -- N is currently unused, but is reserved for future use and debugging
387 -- purposes to provide more context on a node for which an accessibility
388 -- check is being performed or generated (e.g. is N in a predefined unit).
389
fbf5a39b
AC
390 function No_Exception_Handlers_Set return Boolean;
391 -- Test to see if current restrictions settings specify that no exception
392 -- handlers are present. This function is called by Gigi when it needs to
6790c865
AC
393 -- expand an AT END clean up identifier with no exception handler. True
394 -- will be returned if the configurable run-time is activated, and either
395 -- of the restrictions No_Exception_Handlers or No_Exception_Propagation is
396 -- set. In the latter case, the source may contain handlers but they either
397 -- get converted using the local goto transformation or deleted.
19235870 398
c7732bbe
EB
399 -- WARNING: There is a matching C declaration of this subprogram in fe.h
400
06eab6a7
RD
401 function No_Exception_Propagation_Active return Boolean;
402 -- Test to see if current restrictions settings specify that no
403 -- exception propagation is activated.
404
cc335f43 405 function Process_Restriction_Synonyms (N : Node_Id) return Name_Id;
727e7b1a
AC
406 -- Id is a node whose Chars field contains the name of a restriction.
407 -- If it is one of synonyms that we allow for historical purposes (for
408 -- list see System.Rident), then the proper official name is returned.
b5e792e2 409
6e937c1c
AC
410 function Restriction_Active (R : All_Restrictions) return Boolean;
411 pragma Inline (Restriction_Active);
412 -- Determines if a given restriction is active. This call should only be
413 -- used where the compiled code depends on whether the restriction is
de397a3d
AC
414 -- active. Always use Check_Restriction to record a violation. Note that
415 -- this returns False if we only have a Restriction_Warnings set, since
7a963087
RD
416 -- restriction warnings should never affect generated code. If you want
417 -- to know if a call to Check_Restriction is needed then use the function
418 -- Restriction_Check_Required instead.
419
420 function Restriction_Check_Required (R : All_Restrictions) return Boolean;
421 pragma Inline (Restriction_Check_Required);
422 -- Determines if either a Restriction_Warnings or Restrictions pragma has
423 -- been given for the specified restriction. If true, then a subsequent
424 -- call to Check_Restriction is required if the restriction is violated.
425 -- This must not be used to guard code generation that depends on whether
426 -- a restriction is active (see Restriction_Active above). Typically it
427 -- is used to avoid complex code to determine if a restriction is violated,
428 -- executing this code only if needed.
6e937c1c 429
19235870 430 function Restricted_Profile return Boolean;
393525af
AC
431 -- Tests if set of restrictions corresponding to Restricted_Tasking profile
432 -- is currently in effect (set by pragma Profile, or by an appropriate set
433 -- of individual Restrictions pragmas). Returns True only if all the
434 -- required restrictions are set.
cc335f43 435
a7837c08
JM
436 procedure Set_Global_No_Tasking;
437 -- Used in call from Sem_Prag when restriction No_Tasking is set in the
438 -- run-time package System or in a configuration pragmas file.
439
cc335f43
AC
440 procedure Set_Profile_Restrictions
441 (P : Profile_Name;
442 N : Node_Id;
443 Warn : Boolean);
23e6615e
RD
444 -- Sets the set of restrictions associated with the given profile name. N
445 -- is the node of the construct to which error messages are to be attached
446 -- as required. Warn is set True for the case of Profile_Warnings where the
447 -- restrictions are set as warnings rather than legality requirements, and
448 -- is also True for Profile if the Treat_Restrictions_As_Warnings flag is
449 -- set. It is false for Profile if this flag is not set.
19235870 450
6e937c1c
AC
451 procedure Set_Restriction
452 (R : All_Boolean_Restrictions;
453 N : Node_Id);
454 -- N is a node (typically a pragma node) that has the effect of setting
455 -- Boolean restriction R. The restriction is set in Restrictions, and
456 -- also in Main_Restrictions if this is the main unit.
457
458 procedure Set_Restriction
459 (R : All_Parameter_Restrictions;
460 N : Node_Id;
461 V : Integer);
462 -- Similar to the above, except that this is used for the case of a
463 -- parameter restriction, and the corresponding value V is given.
464
47484baa
BD
465 procedure Set_Restriction
466 (R : All_Restrictions;
467 N : Node_Id;
468 Warn : Boolean;
469 V : Integer := Integer'First);
470 -- Same as above two, except also takes care of setting the
471 -- Restriction_Warnings flag. V is ignored for Boolean
472 -- restrictions.
473 --
474 -- If this is the first time we've seen this restriction, the warning flag
475 -- is set to Warn. If this is a second or subsequent time, Warn = False
476 -- wins; that is, errors always trump warnings. In that case, the warning
477 -- flag can be set to False, but never to True.
478
5f3ab6fb 479 procedure Set_Restriction_No_Dependence
9b7c38af
RD
480 (Unit : Node_Id;
481 Warn : Boolean;
482 Profile : Profile_Name := No_Profile);
052e0603
AC
483 -- Sets given No_Dependence restriction in table if not there already. Warn
484 -- is True if from Restriction_Warnings, or for Restrictions if the flag
23e6615e 485 -- Treat_Restrictions_As_Warnings is set. False if from Restrictions and
9b7c38af
RD
486 -- this flag is not set. Profile is set to a non-default value if the
487 -- No_Dependence restriction comes from a Profile pragma.
5f3ab6fb 488
e7fceebc 489 procedure Set_Restriction_No_Specification_Of_Aspect
47484baa
BD
490 (N : Node_Id;
491 Warn : Boolean);
e7fceebc
AC
492 -- N is the node id for an identifier from a pragma Restrictions for the
493 -- No_Specification_Of_Aspect pragma. An error message will be issued if
494 -- the identifier is not a valid aspect name. Warning is set True for the
495 -- case of a Restriction_Warnings pragma specifying this restriction and
496 -- False for a Restrictions pragma specifying this restriction.
497
596b25f9
AC
498 procedure Set_Restriction_No_Specification_Of_Aspect (A_Id : Aspect_Id);
499 -- Version used by Get_Target_Parameters (via Tbuild)
500
57f4c288 501 procedure Set_Restriction_No_Use_Of_Attribute
47484baa
BD
502 (N : Node_Id;
503 Warn : Boolean);
57f4c288
ES
504 -- N is the node id for the identifier in a pragma Restrictions for
505 -- No_Use_Of_Attribute. Caller has verified that this is a valid attribute
506 -- designator.
507
596b25f9
AC
508 procedure Set_Restriction_No_Use_Of_Attribute (A_Id : Attribute_Id);
509 -- Version used by Get_Target_Parameters (via Tbuild)
510
18dae814
RD
511 procedure Set_Restriction_No_Use_Of_Entity
512 (Entity : Node_Id;
47484baa 513 Warn : Boolean;
18dae814
RD
514 Profile : Profile_Name := No_Profile);
515 -- Sets given No_Use_Of_Entity restriction in table if not there already.
516 -- Warn is True if from Restriction_Warnings, or for Restrictions if the
517 -- flag Treat_Restrictions_As_Warnings is set. False if from Restrictions
518 -- and this flag is not set. Profile is set to a non-default value if the
519 -- No_Dependence restriction comes from a Profile pragma. This procedure
520 -- also takes care of setting the Boolean2 flag of the simple name for
14f73211 521 -- the entity (to optimize table searches).
18dae814 522
57f4c288 523 procedure Set_Restriction_No_Use_Of_Pragma
47484baa
BD
524 (N : Node_Id;
525 Warn : Boolean);
57f4c288
ES
526 -- N is the node id for the identifier in a pragma Restrictions for
527 -- No_Use_Of_Pragma. Caller has verified that this is a valid pragma id.
528
596b25f9
AC
529 procedure Set_Restriction_No_Use_Of_Pragma (A_Id : Pragma_Id);
530 -- Version used in call from Get_Target_Parameters (via Tbuild).
531
19235870
RK
532 function Tasking_Allowed return Boolean;
533 pragma Inline (Tasking_Allowed);
9b7c38af
RD
534 -- Tests if tasking operations are allowed by the current restrictions
535 -- settings. For tasking to be allowed Max_Tasks must be non-zero.
19235870 536
a7837c08
JM
537 function Global_No_Tasking return Boolean;
538 -- Returns True if the restriction No_Tasking is set in the run-time
539 -- package System or in a configuration pragmas file.
540
51fb9b73
RD
541 ----------------------------------------------
542 -- Handling of Boolean Compilation Switches --
543 ----------------------------------------------
544
545 -- The following declarations are used for proper saving and restoring of
546 -- restrictions for separate compilation units. There are two cases:
547
548 -- For partition-wide restrictions, we just let the restrictions pragmas
549 -- pile up, and we never reset them. We might as well detect what we can
550 -- at compile time. If e.g. a with'ed unit has a restriction for one of
551 -- the partition-wide restrictions, then the binder will enforce it on
552 -- all units in the partition, including the unit with the WITH. Although
553 -- it would not be wrong to leave this till bind time, we might as well
554 -- flag it earlier at compile time.
555
556 -- For non-partition-wide restrictions, we have quite a different state
557 -- of affairs. Here it would be quite wrong to carry a restriction from
558 -- a with'ed unit to another with'ed unit, or from a package spec to the
559 -- package body. This means that we have to reset these non-partition
560 -- wide restrictions at the start of each separate compilation unit. For
561 -- units in the extended main program, we need to reset them all to the
562 -- values set by the configuration pragma file(s). For units not in the
563 -- extended main program, e.g. with'ed units, we might as well reset all
564 -- of these restrictions to off (False). The actual initial values will
565 -- be taken from the config files active when those units are compiled
566 -- as main units.
567
568 type Save_Cunit_Boolean_Restrictions is private;
569 -- Type used for saving and restoring compilation unit restrictions.
570
571 function Cunit_Boolean_Restrictions_Save
572 return Save_Cunit_Boolean_Restrictions;
573 -- This function saves the compilation unit restriction settings, leaving
a2667f14 574 -- them unchanged. This is used e.g. at the start of processing a context
51fb9b73
RD
575 -- clause, so that the main unit restrictions can be restored after all
576 -- the with'ed units have been processed.
577
578 procedure Cunit_Boolean_Restrictions_Restore
579 (R : Save_Cunit_Boolean_Restrictions);
580 -- This is the corresponding restore procedure to restore restrictions
581 -- previously saved by Cunit_Boolean_Restrictions_Save. However it does
582 -- not reset No_Elaboration_Code, this stays set if it was set before
583 -- the call, and also if it is set before the call, then the Config
584 -- setting is also updated to include this restriction. This is what
585 -- implements the special handling of No_Elaboration_Code.
586
587 procedure Save_Config_Cunit_Boolean_Restrictions;
588 -- This saves the current compilation unit restrictions in an internal
589 -- variable, and leaves them unchanged. This is called immediately after
590 -- processing the configuration file pragmas, to record the restrictions
591 -- set by these configuration file pragmas.
592
593 procedure Restore_Config_Cunit_Boolean_Restrictions;
594 -- This restores the value saved by the previous call to save config values
595 -- saved by Save_Config_Cunit_Boolean_Restrictions. It is called at the
596 -- start of processing a new unit that is part of the main sources (e.g.
597 -- a package spec when the main unit is a package body).
598
599 procedure Reset_Cunit_Boolean_Restrictions;
600 -- Turns off all non-partition-wide boolean restrictions
601
602 procedure Add_To_Config_Boolean_Restrictions (R : Restriction_Id);
603 -- Add specified restriction to stored configuration boolean restrictions.
604 -- This is used for handling the special case of No_Elaboration_Code.
605
19235870 606private
6e937c1c
AC
607 type Save_Cunit_Boolean_Restrictions is
608 array (Cunit_Boolean_Restrictions) of Boolean;
19235870
RK
609 -- Type used for saving and restoring compilation unit restrictions.
610 -- See Compilation_Unit_Restrictions_[Save|Restore] subprograms.
611
612end Restrict;