Daily bump.
[official-gcc.git] / gcc / ada / restrict.ads
blob183973bbca92ad3b79f19a51c081d956d42956b0
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-2021, 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 (Simple_Barriers => True,
113 No_Calendar => True,
114 No_Default_Initialization => True,
115 No_Direct_Boolean_Operators => True,
116 No_Dispatching_Calls => True,
117 No_Dynamic_Accessibility_Checks => True,
118 No_Dynamic_Attachment => True,
119 No_Elaboration_Code => True,
120 No_Enumeration_Maps => True,
121 No_Entry_Calls_In_Elaboration_Code => True,
122 No_Entry_Queue => True,
123 No_Exception_Handlers => True,
124 No_Exception_Propagation => True,
125 No_Exception_Registration => True,
126 No_Finalization => True,
127 No_Fixed_IO => True,
128 No_Implementation_Attributes => True,
129 No_Implementation_Pragmas => True,
130 No_Implicit_Conditionals => True,
131 No_Implicit_Aliasing => True,
132 No_Implicit_Dynamic_Code => True,
133 No_Implicit_Loops => True,
134 No_Initialize_Scalars => True,
135 No_Local_Protected_Objects => True,
136 No_Long_Long_Integers => True,
137 No_Multiple_Elaboration => True,
138 No_Protected_Type_Allocators => True,
139 No_Relative_Delay => True,
140 No_Requeue_Statements => True,
141 No_Secondary_Stack => True,
142 No_Select_Statements => True,
143 No_Standard_Storage_Pools => True,
144 No_Stream_Optimizations => True,
145 No_Streams => True,
146 No_Task_Attributes_Package => True,
147 No_Task_Termination => True,
148 No_Tasking => True,
149 No_Wide_Characters => True,
150 Static_Priorities => True,
151 Static_Storage_Size => True,
152 Pure_Barriers => True,
153 SPARK_05 => True,
154 others => False);
156 --------------------------
157 -- No_Dependences Table --
158 --------------------------
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.
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.
171 type ND_Entry is record
172 Unit : Node_Id;
173 -- The unit parameter from the No_Dependence pragma
175 Warn : Boolean;
176 -- True if from Restriction_Warnings, False if from Restrictions
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.
181 end record;
183 package No_Dependences is new Table.Table (
184 Table_Component_Type => ND_Entry,
185 Table_Index_Type => Int,
186 Table_Low_Bound => 0,
187 Table_Initial => 200,
188 Table_Increment => 200,
189 Table_Name => "Name_No_Dependences");
191 ----------------------------
192 -- No_Use_Of_Entity Table --
193 ----------------------------
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.
199 -- Note: we have chosen to implement this restriction in the "syntactic"
200 -- form, where we allow arbitrary fully qualified names to be specified.
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.
208 Warn : Boolean;
209 -- True if from Restriction_Warnings, False if from Restrictions
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;
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");
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.
228 -----------------
229 -- Subprograms --
230 -----------------
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.
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.
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).
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).
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.
258 procedure Check_Restriction
259 (Msg_Issued : out Boolean;
260 R : Restriction_Id;
261 N : Node_Id;
262 V : Uint := Uint_Minus_1);
263 -- Checks that the given restriction is not set, and if it is set, an
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
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.
274 procedure Check_Restriction
275 (R : Restriction_Id;
276 N : Node_Id;
277 V : Uint := Uint_Minus_1);
278 -- Wrapper on Check_Restriction with Msg_Issued, with the out-parameter
279 -- being ignored here.
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
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.
286 procedure Check_Restriction_No_Specification_Of_Aspect (N : Node_Id);
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.
292 procedure Check_Restriction_No_Use_Of_Attribute (N : Node_Id);
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.
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)
299 -- will be issued if a restriction (warning) was previously set for this
300 -- entity name using Set_No_Use_Of_Entity.
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.
307 procedure Check_Elaboration_Code_Allowed (N : Node_Id);
308 -- Tests to see if elaboration code is allowed by the current restrictions
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
311 -- message is posted on the node given as argument.
313 -- WARNING: There is a matching C declaration of this subprogram in fe.h
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.
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.
329 -- WARNING: There is a matching C declaration of this subprogram in fe.h
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.
335 -- WARNING: There is a matching C declaration of this subprogram in fe.h
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.
342 -- WARNING: There is a matching C declaration of this subprogram in fe.h
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.
348 -- WARNING: There is a matching C declaration of this subprogram in fe.h
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.
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.
365 function Get_Restriction_Id
366 (N : Name_Id) return Restriction_Id;
367 -- Given an identifier name, determines if it is a valid restriction
368 -- identifier, and if so returns the corresponding Restriction_Id value,
369 -- otherwise returns Not_A_Restriction_Id.
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.
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.
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.
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).
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
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.
399 -- WARNING: There is a matching C declaration of this subprogram in fe.h
401 function No_Exception_Propagation_Active return Boolean;
402 -- Test to see if current restrictions settings specify that no
403 -- exception propagation is activated.
405 -- WARNING: There is a matching C declaration of this subprogram in fe.h
407 function Process_Restriction_Synonyms (N : Node_Id) return Name_Id;
408 -- Id is a node whose Chars field contains the name of a restriction.
409 -- If it is one of synonyms that we allow for historical purposes (for
410 -- list see System.Rident), then the proper official name is returned.
412 function Restriction_Active (R : All_Restrictions) return Boolean;
413 pragma Inline (Restriction_Active);
414 -- Determines if a given restriction is active. This call should only be
415 -- used where the compiled code depends on whether the restriction is
416 -- active. Always use Check_Restriction to record a violation. Note that
417 -- this returns False if we only have a Restriction_Warnings set, since
418 -- restriction warnings should never affect generated code. If you want
419 -- to know if a call to Check_Restriction is needed then use the function
420 -- Restriction_Check_Required instead.
422 function Restriction_Check_Required (R : All_Restrictions) return Boolean;
423 pragma Inline (Restriction_Check_Required);
424 -- Determines if either a Restriction_Warnings or Restrictions pragma has
425 -- been given for the specified restriction. If true, then a subsequent
426 -- call to Check_Restriction is required if the restriction is violated.
427 -- This must not be used to guard code generation that depends on whether
428 -- a restriction is active (see Restriction_Active above). Typically it
429 -- is used to avoid complex code to determine if a restriction is violated,
430 -- executing this code only if needed.
432 function Restricted_Profile return Boolean;
433 -- Tests if set of restrictions corresponding to Restricted_Tasking profile
434 -- is currently in effect (set by pragma Profile, or by an appropriate set
435 -- of individual Restrictions pragmas). Returns True only if all the
436 -- required restrictions are set.
438 procedure Set_Global_No_Tasking;
439 -- Used in call from Sem_Prag when restriction No_Tasking is set in the
440 -- run-time package System or in a configuration pragmas file.
442 procedure Set_Profile_Restrictions
443 (P : Profile_Name;
444 N : Node_Id;
445 Warn : Boolean);
446 -- Sets the set of restrictions associated with the given profile name. N
447 -- is the node of the construct to which error messages are to be attached
448 -- as required. Warn is set True for the case of Profile_Warnings where the
449 -- restrictions are set as warnings rather than legality requirements, and
450 -- is also True for Profile if the Treat_Restrictions_As_Warnings flag is
451 -- set. It is false for Profile if this flag is not set.
453 procedure Set_Restriction
454 (R : All_Boolean_Restrictions;
455 N : Node_Id);
456 -- N is a node (typically a pragma node) that has the effect of setting
457 -- Boolean restriction R. The restriction is set in Restrictions, and
458 -- also in Main_Restrictions if this is the main unit.
460 procedure Set_Restriction
461 (R : All_Parameter_Restrictions;
462 N : Node_Id;
463 V : Integer);
464 -- Similar to the above, except that this is used for the case of a
465 -- parameter restriction, and the corresponding value V is given.
467 procedure Set_Restriction
468 (R : All_Restrictions;
469 N : Node_Id;
470 Warn : Boolean;
471 V : Integer := Integer'First);
472 -- Same as above two, except also takes care of setting the
473 -- Restriction_Warnings flag. V is ignored for Boolean
474 -- restrictions.
476 -- If this is the first time we've seen this restriction, the warning flag
477 -- is set to Warn. If this is a second or subsequent time, Warn = False
478 -- wins; that is, errors always trump warnings. In that case, the warning
479 -- flag can be set to False, but never to True.
481 procedure Set_Restriction_No_Dependence
482 (Unit : Node_Id;
483 Warn : Boolean;
484 Profile : Profile_Name := No_Profile);
485 -- Sets given No_Dependence restriction in table if not there already. Warn
486 -- is True if from Restriction_Warnings, or for Restrictions if the flag
487 -- Treat_Restrictions_As_Warnings is set. False if from Restrictions and
488 -- this flag is not set. Profile is set to a non-default value if the
489 -- No_Dependence restriction comes from a Profile pragma.
491 procedure Set_Restriction_No_Specification_Of_Aspect
492 (N : Node_Id;
493 Warn : Boolean);
494 -- N is the node id for an identifier from a pragma Restrictions for the
495 -- No_Specification_Of_Aspect pragma. An error message will be issued if
496 -- the identifier is not a valid aspect name. Warning is set True for the
497 -- case of a Restriction_Warnings pragma specifying this restriction and
498 -- False for a Restrictions pragma specifying this restriction.
500 procedure Set_Restriction_No_Specification_Of_Aspect (A_Id : Aspect_Id);
501 -- Version used by Get_Target_Parameters (via Tbuild)
503 procedure Set_Restriction_No_Use_Of_Attribute
504 (N : Node_Id;
505 Warn : Boolean);
506 -- N is the node id for the identifier in a pragma Restrictions for
507 -- No_Use_Of_Attribute. Caller has verified that this is a valid attribute
508 -- designator.
510 procedure Set_Restriction_No_Use_Of_Attribute (A_Id : Attribute_Id);
511 -- Version used by Get_Target_Parameters (via Tbuild)
513 procedure Set_Restriction_No_Use_Of_Entity
514 (Entity : Node_Id;
515 Warn : Boolean;
516 Profile : Profile_Name := No_Profile);
517 -- Sets given No_Use_Of_Entity restriction in table if not there already.
518 -- Warn is True if from Restriction_Warnings, or for Restrictions if the
519 -- flag Treat_Restrictions_As_Warnings is set. False if from Restrictions
520 -- and this flag is not set. Profile is set to a non-default value if the
521 -- No_Dependence restriction comes from a Profile pragma. This procedure
522 -- also takes care of setting the Boolean2 flag of the simple name for
523 -- the entity (to optimize table searches).
525 procedure Set_Restriction_No_Use_Of_Pragma
526 (N : Node_Id;
527 Warn : Boolean);
528 -- N is the node id for the identifier in a pragma Restrictions for
529 -- No_Use_Of_Pragma. Caller has verified that this is a valid pragma id.
531 procedure Set_Restriction_No_Use_Of_Pragma (A_Id : Pragma_Id);
532 -- Version used in call from Get_Target_Parameters (via Tbuild).
534 function Tasking_Allowed return Boolean;
535 pragma Inline (Tasking_Allowed);
536 -- Tests if tasking operations are allowed by the current restrictions
537 -- settings. For tasking to be allowed Max_Tasks must be non-zero.
539 function Global_No_Tasking return Boolean;
540 -- Returns True if the restriction No_Tasking is set in the run-time
541 -- package System or in a configuration pragmas file.
543 ----------------------------------------------
544 -- Handling of Boolean Compilation Switches --
545 ----------------------------------------------
547 -- The following declarations are used for proper saving and restoring of
548 -- restrictions for separate compilation units. There are two cases:
550 -- For partition-wide restrictions, we just let the restrictions pragmas
551 -- pile up, and we never reset them. We might as well detect what we can
552 -- at compile time. If e.g. a with'ed unit has a restriction for one of
553 -- the partition-wide restrictions, then the binder will enforce it on
554 -- all units in the partition, including the unit with the WITH. Although
555 -- it would not be wrong to leave this till bind time, we might as well
556 -- flag it earlier at compile time.
558 -- For non-partition-wide restrictions, we have quite a different state
559 -- of affairs. Here it would be quite wrong to carry a restriction from
560 -- a with'ed unit to another with'ed unit, or from a package spec to the
561 -- package body. This means that we have to reset these non-partition
562 -- wide restrictions at the start of each separate compilation unit. For
563 -- units in the extended main program, we need to reset them all to the
564 -- values set by the configuration pragma file(s). For units not in the
565 -- extended main program, e.g. with'ed units, we might as well reset all
566 -- of these restrictions to off (False). The actual initial values will
567 -- be taken from the config files active when those units are compiled
568 -- as main units.
570 type Save_Cunit_Boolean_Restrictions is private;
571 -- Type used for saving and restoring compilation unit restrictions.
573 function Cunit_Boolean_Restrictions_Save
574 return Save_Cunit_Boolean_Restrictions;
575 -- This function saves the compilation unit restriction settings, leaving
576 -- them unchanged. This is used e.g. at the start of processing a context
577 -- clause, so that the main unit restrictions can be restored after all
578 -- the with'ed units have been processed.
580 procedure Cunit_Boolean_Restrictions_Restore
581 (R : Save_Cunit_Boolean_Restrictions);
582 -- This is the corresponding restore procedure to restore restrictions
583 -- previously saved by Cunit_Boolean_Restrictions_Save. However it does
584 -- not reset No_Elaboration_Code, this stays set if it was set before
585 -- the call, and also if it is set before the call, then the Config
586 -- setting is also updated to include this restriction. This is what
587 -- implements the special handling of No_Elaboration_Code.
589 procedure Save_Config_Cunit_Boolean_Restrictions;
590 -- This saves the current compilation unit restrictions in an internal
591 -- variable, and leaves them unchanged. This is called immediately after
592 -- processing the configuration file pragmas, to record the restrictions
593 -- set by these configuration file pragmas.
595 procedure Restore_Config_Cunit_Boolean_Restrictions;
596 -- This restores the value saved by the previous call to save config values
597 -- saved by Save_Config_Cunit_Boolean_Restrictions. It is called at the
598 -- start of processing a new unit that is part of the main sources (e.g.
599 -- a package spec when the main unit is a package body).
601 procedure Reset_Cunit_Boolean_Restrictions;
602 -- Turns off all non-partition-wide boolean restrictions
604 procedure Add_To_Config_Boolean_Restrictions (R : Restriction_Id);
605 -- Add specified restriction to stored configuration boolean restrictions.
606 -- This is used for handling the special case of No_Elaboration_Code.
608 private
609 type Save_Cunit_Boolean_Restrictions is
610 array (Cunit_Boolean_Restrictions) of Boolean;
611 -- Type used for saving and restoring compilation unit restrictions.
612 -- See Compilation_Unit_Restrictions_[Save|Restore] subprograms.
614 end Restrict;