ada: Further cleanup in finalization machinery
[official-gcc.git] / gcc / ada / restrict.ads
blob7d7771661b2ad5651ccfb376445d9b2c23994caf
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT COMPILER COMPONENTS --
4 -- --
5 -- R E S T R I C T --
6 -- --
7 -- S p e c --
8 -- --
9 -- Copyright (C) 1992-2023, Free Software Foundation, Inc. --
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- --
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. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
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. --
20 -- --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
23 -- --
24 ------------------------------------------------------------------------------
26 -- This package deals with the implementation of the Restrictions pragma
28 with Aspects; use Aspects;
29 with Namet; use Namet;
30 with Rident; use Rident;
31 with Snames; use Snames;
32 with Table;
33 with Types; use Types;
34 with Uintp; use Uintp;
36 package Restrict is
38 Restrictions : Restrictions_Info := No_Restrictions;
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
42 -- etc., since we may as well check as much as we can at compile time.
43 -- These variables should not be referenced directly by clients. Instead
44 -- use Check_Restriction to record a violation of a restriction, and
45 -- Restriction_Active to test if a given restriction is active.
47 Restrictions_Loc : array (All_Restrictions) of Source_Ptr :=
48 (others => No_Location);
49 -- Locations of Restrictions pragmas for error message purposes.
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.
55 Restriction_Profile_Name : array (All_Restrictions) of Profile_Name;
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
58 -- restriction was set by a Profile or Profile_Warnings pragma. The value
59 -- is No_Profile in all other cases.
61 Main_Restrictions : Restrictions_Info := No_Restrictions;
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.
67 Restriction_Warnings : Rident.Restriction_Flags := (others => False);
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.
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.
76 -- The following declarations establish a mapping between restriction
77 -- identifiers, and the names of corresponding restricted library units.
79 type Unit_Entry is record
80 Res_Id : Restriction_Id;
81 Filenm : String (1 .. 8);
82 end record;
84 Unit_Array : constant array (Positive range <>) of Unit_Entry := (
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"),
92 (No_IO, "a-direct"),
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"),
102 (No_Unchecked_Conversion, "a-unccon"),
103 (No_Unchecked_Conversion, "unchconv"),
104 (No_Unchecked_Deallocation, "a-uncdea"),
105 (No_Unchecked_Deallocation, "unchdeal"));
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).
111 Implementation_Restriction : constant array (All_Restrictions) of Boolean :=
112 (No_Calendar => True,
113 No_Default_Initialization => True,
114 No_Direct_Boolean_Operators => True,
115 No_Dispatching_Calls => True,
116 No_Dynamic_Accessibility_Checks => True,
117 No_Dynamic_Sized_Objects => True,
118 No_Elaboration_Code => True,
119 No_Entry_Calls_In_Elaboration_Code => True,
120 No_Entry_Queue => True,
121 No_Enumeration_Maps => True,
122 No_Exception_Handlers => True,
123 No_Exception_Propagation => True,
124 No_Exception_Registration => True,
125 No_Finalization => True,
126 No_Fixed_IO => True,
127 No_Implicit_Aliasing => True,
128 No_Implicit_Conditionals => True,
129 No_Implicit_Dynamic_Code => True,
130 No_Implicit_Loops => True,
131 No_Implicit_Protected_Object_Allocations => True,
132 No_Implicit_Task_Allocations => True,
133 No_Initialize_Scalars => True,
134 No_Local_Tagged_Types => True,
135 No_Long_Long_Integers => True,
136 No_Multiple_Elaboration => True,
137 No_Secondary_Stack => True,
138 No_Standard_Storage_Pools => True,
139 No_Stream_Optimizations => True,
140 No_Streams => True,
141 No_Tagged_Type_Registration => True,
142 No_Task_At_Interrupt_Priority => True,
143 No_Task_Attributes_Package => True,
144 No_Tasking => True,
145 No_Wide_Characters => True,
146 Static_Dispatch_Tables => True,
147 Static_Priorities => True,
148 Static_Storage_Size => True,
149 SPARK_05 => True,
150 others => False);
152 --------------------------
153 -- No_Dependences Table --
154 --------------------------
156 -- The following table records entries made by Restrictions pragmas
157 -- that specify a parameter for No_Dependence. Each such pragma makes
158 -- an entry in this table.
160 -- Note: we have chosen to implement this restriction in the "syntactic"
161 -- form, where we do not check that the named package is a language defined
162 -- package, but instead we allow arbitrary package names. The discussion of
163 -- this issue is not complete in the ARG, but the sense seems to be leaning
164 -- in this direction, which makes more sense to us, since it is much more
165 -- useful, and much easier to implement.
167 type ND_Entry is record
168 Unit : Node_Id;
169 -- The unit parameter from the No_Dependence pragma
171 System_Child : Name_Id;
172 -- The name if the unit is a child of System, or else No_Name
174 Warn : Boolean;
175 -- True if from Restriction_Warnings, False if from Restrictions
177 Profile : Profile_Name;
178 -- Set to name of profile from which No_Dependence entry came, or to
179 -- No_Profile if a pragma Restriction set the No_Dependence entry.
180 end record;
182 package No_Dependences is new Table.Table (
183 Table_Component_Type => ND_Entry,
184 Table_Index_Type => Int,
185 Table_Low_Bound => 0,
186 Table_Initial => 200,
187 Table_Increment => 200,
188 Table_Name => "Name_No_Dependences");
190 ----------------------------
191 -- No_Use_Of_Entity Table --
192 ----------------------------
194 -- The following table records entries made by Restrictions pragmas
195 -- that specify a parameter for No_Use_Of_Entity. Each such pragma makes
196 -- an entry in this table.
198 -- Note: we have chosen to implement this restriction in the "syntactic"
199 -- form, where we allow arbitrary fully qualified names to be specified.
201 type NE_Entry is record
202 Entity : Node_Id;
203 -- The entity parameter from the No_Use_Of_Entity pragma. This is in
204 -- the form of a selected component, since that is the way the parser
205 -- processes it, and we don't further analyze it.
207 Warn : Boolean;
208 -- True if from Restriction_Warnings, False if from Restrictions
210 Profile : Profile_Name;
211 -- Set to name of profile from which No_Use_Of_Entity entry came, or to
212 -- No_Profile if a pragma Restriction set the No_Use_Of_Entity entry.
213 end record;
215 package No_Use_Of_Entity is new Table.Table (
216 Table_Component_Type => NE_Entry,
217 Table_Index_Type => Int,
218 Table_Low_Bound => 0,
219 Table_Initial => 200,
220 Table_Increment => 200,
221 Table_Name => "Name_No_Use_Of_Entity");
223 -- Note that in addition to making an entry in this table, we also set the
224 -- Boolean2 flag of the Name_Table entry for the simple name of the entity.
225 -- This is used to avoid most useless searches of this table.
227 -----------------
228 -- Subprograms --
229 -----------------
231 -- Note: several of these subprograms can generate error messages (e.g.
232 -- Check_Restriction). These routines should be called in the analyzer
233 -- rather than the expander, so that the associated error messages are
234 -- correctly generated in semantics only (-gnatc) mode.
236 function Abort_Allowed return Boolean;
237 pragma Inline (Abort_Allowed);
238 -- Tests to see if abort is allowed by the current restrictions settings.
239 -- For abort to be allowed, either No_Abort_Statements must be False,
240 -- or Max_Asynchronous_Select_Nesting must be non-zero.
242 procedure Check_Restricted_Unit (U : Unit_Name_Type; N : Node_Id);
243 -- Checks if loading of unit U is prohibited by the setting of some
244 -- restriction (e.g. No_IO restricts the loading of unit Ada.Text_IO).
245 -- If a restriction exists post error message at the given node.
247 procedure Check_Restriction
248 (Msg_Issued : out Boolean;
249 R : Restriction_Id;
250 N : Node_Id;
251 V : Uint := Uint_Minus_1);
252 -- Checks that the given restriction is not set, and if it is set, an
253 -- appropriate message is posted on the given node, in which case
254 -- Msg_Issued is set to True (and False otherwise). Also records the
255 -- violation in the appropriate internal arrays. Note that it is mandatory
256 -- to always use this routine to check if a restriction is violated. Such
257 -- checks must never be done directly by the caller, since otherwise
258 -- violations in the absence of restrictions are not properly recorded. The
259 -- value of V is relevant only for parameter restrictions, and in this case
260 -- indicates the exact count for the violation. If the exact count is not
261 -- known, V is left at its default of -1 which indicates an unknown count.
263 procedure Check_Restriction
264 (R : Restriction_Id;
265 N : Node_Id;
266 V : Uint := Uint_Minus_1);
267 -- Wrapper on Check_Restriction with Msg_Issued, with the out-parameter
268 -- being ignored here.
270 procedure Check_Restriction_No_Dependence (U : Node_Id; Err : Node_Id);
271 -- Called when a dependence on a unit is created (either implicitly, or by
272 -- an explicit WITH clause). U is a node for the unit involved, and Err is
273 -- the node to which an error will be attached if necessary.
275 procedure Check_Restriction_No_Dependence_On_System
276 (U : Name_Id;
277 Err : Node_Id);
278 -- Likewise, but for the child units of System referenced by their name
280 -- WARNING: There is a matching C declaration of this subprogram in fe.h
282 procedure Check_Restriction_No_Specification_Of_Aspect (N : Node_Id);
283 -- N is the node id for an N_Aspect_Specification, an N_Pragma, or an
284 -- N_Attribute_Definition_Clause. An error message (warning) will be issued
285 -- if a restriction (warning) was previously set for this aspect using
286 -- Set_No_Specification_Of_Aspect.
288 procedure Check_Restriction_No_Use_Of_Attribute (N : Node_Id);
289 -- N denotes an attribute definition clause or an attribute reference. An
290 -- error message (warning) will be issued if a restriction (warning) was
291 -- previously set for this attribute using Set_No_Use_Of_Attribute.
293 procedure Check_Restriction_No_Use_Of_Entity (N : Node_Id);
294 -- N is the node id for an entity reference. An error message (warning)
295 -- will be issued if a restriction (warning) was previously set for this
296 -- entity name using Set_No_Use_Of_Entity.
298 procedure Check_Restriction_No_Use_Of_Pragma (N : Node_Id);
299 -- N is the node of a pragma. An error message (warning) will be issued
300 -- if a restriction (warning) was previously set for this pragma using
301 -- Set_No_Use_Of_Pragma.
303 procedure Check_Elaboration_Code_Allowed (N : Node_Id);
304 -- Tests to see if elaboration code is allowed by the current restrictions
305 -- settings. This function is called by Gigi when it needs to define an
306 -- elaboration routine. If elaboration code is not allowed, an error
307 -- message is posted on the node given as argument.
309 -- WARNING: There is a matching C declaration of this subprogram in fe.h
311 procedure Check_No_Implicit_Aliasing (Obj : Node_Id);
312 -- Obj is a node for which Is_Aliased_View is True, which is being used in
313 -- a context (e.g. 'Access) where no implicit aliasing is allowed if the
314 -- restriction No_Implicit_Aliasing is set. This procedure checks for the
315 -- case where the restriction is active and Obj does not meet the required
316 -- rules for avoiding implicit aliases, and issues a restriction message.
318 procedure Check_Implicit_Dynamic_Code_Allowed (N : Node_Id);
319 -- Tests to see if dynamic code generation (dynamically generated
320 -- trampolines, in particular) is allowed by the current restrictions
321 -- settings. This function is called by Gigi when it needs to generate code
322 -- that generates a trampoline. If not allowed, an error message is posted
323 -- on the node given as argument.
325 -- WARNING: There is a matching C declaration of this subprogram in fe.h
327 procedure Check_No_Implicit_Heap_Alloc (N : Node_Id);
328 -- Equivalent to Check_Restriction (No_Implicit_Heap_Allocations, N).
329 -- Provided for easy use by back end, which has to check this restriction.
331 -- WARNING: There is a matching C declaration of this subprogram in fe.h
333 procedure Check_No_Implicit_Protected_Alloc (N : Node_Id);
334 -- Equivalent to:
335 -- Check_Restriction (No_Implicit_Protected_Object_Allocations, N)
336 -- Provided for easy use by back end, which has to check this restriction.
338 -- WARNING: There is a matching C declaration of this subprogram in fe.h
340 procedure Check_No_Implicit_Task_Alloc (N : Node_Id);
341 -- Equivalent to Check_Restriction (No_Implicit_Task_Allocations, N).
342 -- Provided for easy use by back end, which has to check this restriction.
344 -- WARNING: There is a matching C declaration of this subprogram in fe.h
346 procedure Check_Obsolescent_2005_Entity (E : Entity_Id; N : Node_Id);
347 -- This routine checks if the entity E is one of the obsolescent entries
348 -- in Ada.Characters.Handling in Ada 2005 and No_Obsolescent_Features
349 -- restriction is active. If so an appropriate message is given. N is
350 -- the node on which the message is to be placed. It's a bit kludgy to
351 -- have this highly specialized routine rather than some wonderful general
352 -- mechanism (e.g. a special pragma) to handle this case, but there are
353 -- only six cases, and it is not worth the effort to do something general.
355 procedure Check_Wide_Character_Restriction (E : Entity_Id; N : Node_Id);
356 -- This procedure checks if the No_Wide_Character restriction is active,
357 -- and if so, if N Comes_From_Source, and the root type of E is one of
358 -- [Wide_]Wide_Character or [Wide_]Wide_String, then the restriction
359 -- violation is recorded, and an appropriate message given.
361 function Get_Restriction_Id
362 (N : Name_Id) return Restriction_Id;
363 -- Given an identifier name, determines if it is a valid restriction
364 -- identifier, and if so returns the corresponding Restriction_Id value,
365 -- otherwise returns Not_A_Restriction_Id.
367 function OK_No_Dependence_Unit_Name (N : Node_Id) return Boolean;
368 -- Used in checking No_Dependence argument of pragma Restrictions or
369 -- pragma Restrictions_Warning, or attribute Restriction_Set. Returns
370 -- True if N has the proper form for a unit name, False otherwise.
372 function OK_No_Use_Of_Entity_Name (N : Node_Id) return Boolean;
373 -- Used in checking No_Use_Of_Entity argument of pragma Restrictions or
374 -- pragma Restrictions_Warning, or attribute Restriction_Set. Returns
375 -- True if N has the proper form for an entity name, False otherwise.
377 function No_Dynamic_Accessibility_Checks_Enabled
378 (N : Node_Id) return Boolean;
379 -- Test to see if the current restrictions settings specify that
380 -- No_Dynamic_Accessibility_Checks is activated.
382 -- N is currently unused, but is reserved for future use and debugging
383 -- purposes to provide more context on a node for which an accessibility
384 -- check is being performed or generated (e.g. is N in a predefined unit).
386 function No_Exception_Handlers_Set return Boolean;
387 -- Test to see if current restrictions settings specify that no exception
388 -- handlers are present. This function is called by Gigi when it needs to
389 -- expand an AT END clean up identifier with no exception handler. True
390 -- will be returned if the configurable run-time is activated, and either
391 -- of the restrictions No_Exception_Handlers or No_Exception_Propagation is
392 -- set. In the latter case, the source may contain handlers but they either
393 -- get converted using the local goto transformation or deleted.
395 -- WARNING: There is a matching C declaration of this subprogram in fe.h
397 function No_Exception_Propagation_Active return Boolean;
398 -- Test to see if current restrictions settings specify that no
399 -- exception propagation is activated.
401 -- WARNING: There is a matching C declaration of this subprogram in fe.h
403 function Process_Restriction_Synonyms (N : Node_Id) return Name_Id;
404 -- Id is a node whose Chars field contains the name of a restriction.
405 -- If it is one of synonyms that we allow for historical purposes (for
406 -- list see System.Rident), then the proper official name is returned.
408 function Restriction_Active (R : All_Restrictions) return Boolean;
409 pragma Inline (Restriction_Active);
410 -- Determines if a given restriction is active. This call should only be
411 -- used where the compiled code depends on whether the restriction is
412 -- active. Always use Check_Restriction to record a violation. Note that
413 -- this returns False if we only have a Restriction_Warnings set, since
414 -- restriction warnings should never affect generated code. If you want
415 -- to know if a call to Check_Restriction is needed then use the function
416 -- Restriction_Check_Required instead.
418 function Restriction_Check_Required (R : All_Restrictions) return Boolean;
419 pragma Inline (Restriction_Check_Required);
420 -- Determines if either a Restriction_Warnings or Restrictions pragma has
421 -- been given for the specified restriction. If true, then a subsequent
422 -- call to Check_Restriction is required if the restriction is violated.
423 -- This must not be used to guard code generation that depends on whether
424 -- a restriction is active (see Restriction_Active above). Typically it
425 -- is used to avoid complex code to determine if a restriction is violated,
426 -- executing this code only if needed.
428 function Restricted_Profile return Boolean;
429 -- Tests if set of restrictions corresponding to Restricted_Tasking profile
430 -- is currently in effect (set by pragma Profile, or by an appropriate set
431 -- of individual Restrictions pragmas). Returns True only if all the
432 -- required restrictions are set.
434 procedure Set_Global_No_Tasking;
435 -- Used in call from Sem_Prag when restriction No_Tasking is set in the
436 -- run-time package System or in a configuration pragmas file.
438 procedure Set_Profile_Restrictions
439 (P : Profile_Name;
440 N : Node_Id;
441 Warn : Boolean);
442 -- Sets the set of restrictions associated with the given profile name. N
443 -- is the node of the construct to which error messages are to be attached
444 -- as required. Warn is set True for the case of Profile_Warnings where the
445 -- restrictions are set as warnings rather than legality requirements, and
446 -- is also True for Profile if the Treat_Restrictions_As_Warnings flag is
447 -- set. It is false for Profile if this flag is not set.
449 procedure Set_Restriction
450 (R : All_Boolean_Restrictions;
451 N : Node_Id);
452 -- N is a node (typically a pragma node) that has the effect of setting
453 -- Boolean restriction R. The restriction is set in Restrictions, and
454 -- also in Main_Restrictions if this is the main unit.
456 procedure Set_Restriction
457 (R : All_Parameter_Restrictions;
458 N : Node_Id;
459 V : Integer);
460 -- Similar to the above, except that this is used for the case of a
461 -- parameter restriction, and the corresponding value V is given.
463 procedure Set_Restriction
464 (R : All_Restrictions;
465 N : Node_Id;
466 Warn : Boolean;
467 V : Integer := Integer'First);
468 -- Same as above two, except also takes care of setting the
469 -- Restriction_Warnings flag. V is ignored for Boolean
470 -- restrictions.
472 -- If this is the first time we've seen this restriction, the warning flag
473 -- is set to Warn. If this is a second or subsequent time, Warn = False
474 -- wins; that is, errors always trump warnings. In that case, the warning
475 -- flag can be set to False, but never to True.
477 procedure Set_Restriction_No_Dependence
478 (Unit : Node_Id;
479 Warn : Boolean;
480 Profile : Profile_Name := No_Profile);
481 -- Sets given No_Dependence restriction in table if not there already. Warn
482 -- is True if from Restriction_Warnings, or for Restrictions if the flag
483 -- Treat_Restrictions_As_Warnings is set. False if from Restrictions and
484 -- this flag is not set. Profile is set to a non-default value if the
485 -- No_Dependence restriction comes from a Profile pragma.
487 procedure Set_Restriction_No_Specification_Of_Aspect
488 (N : Node_Id;
489 Warn : Boolean);
490 -- N is the node id for an identifier from a pragma Restrictions for the
491 -- No_Specification_Of_Aspect pragma. An error message will be issued if
492 -- the identifier is not a valid aspect name. Warning is set True for the
493 -- case of a Restriction_Warnings pragma specifying this restriction and
494 -- False for a Restrictions pragma specifying this restriction.
496 procedure Set_Restriction_No_Specification_Of_Aspect (A_Id : Aspect_Id);
497 -- Version used by Get_Target_Parameters (via Tbuild)
499 procedure Set_Restriction_No_Use_Of_Attribute
500 (N : Node_Id;
501 Warn : Boolean);
502 -- N is the node id for the identifier in a pragma Restrictions for
503 -- No_Use_Of_Attribute. Caller has verified that this is a valid attribute
504 -- designator.
506 procedure Set_Restriction_No_Use_Of_Attribute (A_Id : Attribute_Id);
507 -- Version used by Get_Target_Parameters (via Tbuild)
509 procedure Set_Restriction_No_Use_Of_Entity
510 (Entity : Node_Id;
511 Warn : Boolean;
512 Profile : Profile_Name := No_Profile);
513 -- Sets given No_Use_Of_Entity restriction in table if not there already.
514 -- Warn is True if from Restriction_Warnings, or for Restrictions if the
515 -- flag Treat_Restrictions_As_Warnings is set. False if from Restrictions
516 -- and this flag is not set. Profile is set to a non-default value if the
517 -- No_Dependence restriction comes from a Profile pragma. This procedure
518 -- also takes care of setting the Boolean2 flag of the simple name for
519 -- the entity (to optimize table searches).
521 procedure Set_Restriction_No_Use_Of_Pragma
522 (N : Node_Id;
523 Warn : Boolean);
524 -- N is the node id for the identifier in a pragma Restrictions for
525 -- No_Use_Of_Pragma. Caller has verified that this is a valid pragma id.
527 procedure Set_Restriction_No_Use_Of_Pragma (A_Id : Pragma_Id);
528 -- Version used in call from Get_Target_Parameters (via Tbuild).
530 function Tasking_Allowed return Boolean;
531 pragma Inline (Tasking_Allowed);
532 -- Tests if tasking operations are allowed by the current restrictions
533 -- settings. For tasking to be allowed Max_Tasks must be non-zero.
535 function Global_No_Tasking return Boolean;
536 -- Returns True if the restriction No_Tasking is set in the run-time
537 -- package System or in a configuration pragmas file.
539 ----------------------------------------------
540 -- Handling of Boolean Compilation Switches --
541 ----------------------------------------------
543 -- The following declarations are used for proper saving and restoring of
544 -- restrictions for separate compilation units. There are two cases:
546 -- For partition-wide restrictions, we just let the restrictions pragmas
547 -- pile up, and we never reset them. We might as well detect what we can
548 -- at compile time. If e.g. a with'ed unit has a restriction for one of
549 -- the partition-wide restrictions, then the binder will enforce it on
550 -- all units in the partition, including the unit with the WITH. Although
551 -- it would not be wrong to leave this till bind time, we might as well
552 -- flag it earlier at compile time.
554 -- For non-partition-wide restrictions, we have quite a different state
555 -- of affairs. Here it would be quite wrong to carry a restriction from
556 -- a with'ed unit to another with'ed unit, or from a package spec to the
557 -- package body. This means that we have to reset these non-partition
558 -- wide restrictions at the start of each separate compilation unit. For
559 -- units in the extended main program, we need to reset them all to the
560 -- values set by the configuration pragma file(s). For units not in the
561 -- extended main program, e.g. with'ed units, we might as well reset all
562 -- of these restrictions to off (False). The actual initial values will
563 -- be taken from the config files active when those units are compiled
564 -- as main units.
566 type Save_Cunit_Boolean_Restrictions is private;
567 -- Type used for saving and restoring compilation unit restrictions.
569 function Cunit_Boolean_Restrictions_Save
570 return Save_Cunit_Boolean_Restrictions;
571 -- This function saves the compilation unit restriction settings, leaving
572 -- them unchanged. This is used e.g. at the start of processing a context
573 -- clause, so that the main unit restrictions can be restored after all
574 -- the with'ed units have been processed.
576 procedure Cunit_Boolean_Restrictions_Restore
577 (R : Save_Cunit_Boolean_Restrictions);
578 -- This is the corresponding restore procedure to restore restrictions
579 -- previously saved by Cunit_Boolean_Restrictions_Save. However it does
580 -- not reset No_Elaboration_Code, this stays set if it was set before
581 -- the call, and also if it is set before the call, then the Config
582 -- setting is also updated to include this restriction. This is what
583 -- implements the special handling of No_Elaboration_Code.
585 procedure Save_Config_Cunit_Boolean_Restrictions;
586 -- This saves the current compilation unit restrictions in an internal
587 -- variable, and leaves them unchanged. This is called immediately after
588 -- processing the configuration file pragmas, to record the restrictions
589 -- set by these configuration file pragmas.
591 procedure Restore_Config_Cunit_Boolean_Restrictions;
592 -- This restores the value saved by the previous call to save config values
593 -- saved by Save_Config_Cunit_Boolean_Restrictions. It is called at the
594 -- start of processing a new unit that is part of the main sources (e.g.
595 -- a package spec when the main unit is a package body).
597 procedure Reset_Cunit_Boolean_Restrictions;
598 -- Turns off all non-partition-wide boolean restrictions
600 procedure Add_To_Config_Boolean_Restrictions (R : Restriction_Id);
601 -- Add specified restriction to stored configuration boolean restrictions.
602 -- This is used for handling the special case of No_Elaboration_Code.
604 package Local_Restrictions is
605 -- In the body of package Restrict, we want to call a subprogram
606 -- declared in package Local_Restrict. Doing this in the obvious
607 -- way introduces problems (by pulling the bulk of semantics into
608 -- the closure of package Restrict). So we declare an access-to-subp
609 -- object here and call through it later if it happens to be non-null;
610 -- it is initialized in the body of package Local_Restrict.
612 type Local_Restriction_Checking_Proc_Ref is access
613 procedure (R : All_Restrictions; N : Node_Id);
615 Local_Restriction_Checking_Hook : Local_Restriction_Checking_Proc_Ref;
616 end Local_Restrictions;
618 private
619 type Save_Cunit_Boolean_Restrictions is
620 array (Cunit_Boolean_Restrictions) of Boolean;
621 -- Type used for saving and restoring compilation unit restrictions.
622 -- See Compilation_Unit_Restrictions_[Save|Restore] subprograms.
624 end Restrict;