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-2020, 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------------------------------------------------------------------------------
25
26--  This package deals with the implementation of the Restrictions pragma
27
28with Aspects; use Aspects;
29with Namet;   use Namet;
30with Rident;  use Rident;
31with Snames;  use Snames;
32with Table;
33with Types;   use Types;
34with Uintp;   use Uintp;
35
36package Restrict is
37
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.
46
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.
54
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.
60
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.
66
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.
75
76   --  The following declarations establish a mapping between restriction
77   --  identifiers, and the names of corresponding restricted library units.
78
79   type Unit_Entry is record
80      Res_Id : Restriction_Id;
81      Filenm : String (1 .. 8);
82   end record;
83
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"));
106
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).
110
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_Attachment              => True,
118      No_Elaboration_Code                => True,
119      No_Enumeration_Maps                => True,
120      No_Entry_Calls_In_Elaboration_Code => True,
121      No_Entry_Queue                     => 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_Implementation_Attributes       => True,
128      No_Implementation_Pragmas          => True,
129      No_Implicit_Conditionals           => True,
130      No_Implicit_Aliasing               => True,
131      No_Implicit_Dynamic_Code           => True,
132      No_Implicit_Loops                  => True,
133      No_Initialize_Scalars              => True,
134      No_Local_Protected_Objects         => True,
135      No_Long_Long_Integers              => True,
136      No_Multiple_Elaboration            => True,
137      No_Protected_Type_Allocators       => True,
138      No_Relative_Delay                  => True,
139      No_Requeue_Statements              => True,
140      No_Secondary_Stack                 => True,
141      No_Select_Statements               => True,
142      No_Standard_Storage_Pools          => True,
143      No_Stream_Optimizations            => True,
144      No_Streams                         => True,
145      No_Task_Attributes_Package         => True,
146      No_Task_Termination                => True,
147      No_Tasking                         => True,
148      No_Wide_Characters                 => True,
149      Static_Priorities                  => True,
150      Static_Storage_Size                => True,
151      Pure_Barriers                      => True,
152      SPARK_05                           => True,
153      others                             => False);
154
155   --------------------------
156   -- No_Dependences Table --
157   --------------------------
158
159   --  The following table records entries made by Restrictions pragmas
160   --  that specify a parameter for No_Dependence. Each such pragma makes
161   --  an entry in this table.
162
163   --  Note: we have chosen to implement this restriction in the "syntactic"
164   --  form, where we do not check that the named package is a language defined
165   --  package, but instead we allow arbitrary package names. The discussion of
166   --  this issue is not complete in the ARG, but the sense seems to be leaning
167   --  in this direction, which makes more sense to us, since it is much more
168   --  useful, and much easier to implement.
169
170   type ND_Entry is record
171      Unit : Node_Id;
172      --  The unit parameter from the No_Dependence pragma
173
174      Warn : Boolean;
175      --  True if from Restriction_Warnings, False if from Restrictions
176
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;
181
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");
189
190   ----------------------------
191   -- No_Use_Of_Entity Table --
192   ----------------------------
193
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.
197
198   --  Note: we have chosen to implement this restriction in the "syntactic"
199   --  form, where we allow arbitrary fully qualified names to be specified.
200
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.
206
207      Warn : Boolean;
208      --  True if from Restriction_Warnings, False if from Restrictions
209
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;
214
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");
222
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.
226
227   -----------------
228   -- Subprograms --
229   -----------------
230
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.
235
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.
241
242   procedure Check_Compiler_Unit (Feature : String; N : Node_Id);
243   --  If unit N is in a unit that has a pragma Compiler_Unit_Warning, then
244   --  a message is posted on node N noting use of the given feature is not
245   --  permitted in the compiler (bootstrap considerations).
246
247   procedure Check_Compiler_Unit (Feature : String; Loc : Source_Ptr);
248   --  If unit N is in a unit that has a pragma Compiler_Unit_Warning, then a
249   --  message is posted at location Loc noting use of the given feature is not
250   --  permitted in the compiler (bootstrap considerations).
251
252   procedure Check_Restricted_Unit (U : Unit_Name_Type; N : Node_Id);
253   --  Checks if loading of unit U is prohibited by the setting of some
254   --  restriction (e.g. No_IO restricts the loading of unit Ada.Text_IO).
255   --  If a restriction exists post error message at the given node.
256
257   procedure Check_Restriction
258     (Msg_Issued : out Boolean;
259      R          : Restriction_Id;
260      N          : Node_Id;
261      V          : Uint := Uint_Minus_1);
262   --  Checks that the given restriction is not set, and if it is set, an
263   --  appropriate message is posted on the given node, in which case
264   --  Msg_Issued is set to True (and False otherwise). Also records the
265   --  violation in the appropriate internal arrays. Note that it is mandatory
266   --  to always use this routine to check if a restriction is violated. Such
267   --  checks must never be done directly by the caller, since otherwise
268   --  violations in the absence of restrictions are not properly recorded. The
269   --  value of V is relevant only for parameter restrictions, and in this case
270   --  indicates the exact count for the violation. If the exact count is not
271   --  known, V is left at its default of -1 which indicates an unknown count.
272
273   procedure Check_Restriction
274     (R : Restriction_Id;
275      N : Node_Id;
276      V : Uint := Uint_Minus_1);
277   --  Wrapper on Check_Restriction with Msg_Issued, with the out-parameter
278   --  being ignored here.
279
280   procedure Check_Restriction_No_Dependence (U : Node_Id; Err : Node_Id);
281   --  Called when a dependence on a unit is created (either implicitly, or by
282   --  an explicit WITH clause). U is a node for the unit involved, and Err is
283   --  the node to which an error will be attached if necessary.
284
285   procedure Check_Restriction_No_Specification_Of_Aspect (N : Node_Id);
286   --  N is the node id for an N_Aspect_Specification, an N_Pragma, or an
287   --  N_Attribute_Definition_Clause. An error message (warning) will be issued
288   --  if a restriction (warning) was previously set for this aspect using
289   --  Set_No_Specification_Of_Aspect.
290
291   procedure Check_Restriction_No_Use_Of_Attribute (N : Node_Id);
292   --  N denotes an attribute definition clause or an attribute reference. An
293   --  error message (warning) will be issued if a restriction (warning) was
294   --  previously set for this attribute using Set_No_Use_Of_Attribute.
295
296   procedure Check_Restriction_No_Use_Of_Entity (N : Node_Id);
297   --  N is the node id for an entity reference. An error message (warning)
298   --  will be issued if a restriction (warning) was previously set for this
299   --  entity name using Set_No_Use_Of_Entity.
300
301   procedure Check_Restriction_No_Use_Of_Pragma (N : Node_Id);
302   --  N is the node of a pragma. An error message (warning) will be issued
303   --  if a restriction (warning) was previously set for this pragma using
304   --  Set_No_Use_Of_Pragma.
305
306   procedure Check_Elaboration_Code_Allowed (N : Node_Id);
307   --  Tests to see if elaboration code is allowed by the current restrictions
308   --  settings. This function is called by Gigi when it needs to define an
309   --  elaboration routine. If elaboration code is not allowed, an error
310   --  message is posted on the node given as argument.
311
312   --  WARNING: There is a matching C declaration of this subprogram in fe.h
313
314   procedure Check_No_Implicit_Aliasing (Obj : Node_Id);
315   --  Obj is a node for which Is_Aliased_View is True, which is being used in
316   --  a context (e.g. 'Access) where no implicit aliasing is allowed if the
317   --  restriction No_Implicit_Aliasing is set. This procedure checks for the
318   --  case where the restriction is active and Obj does not meet the required
319   --  rules for avoiding implicit aliases, and issues a restriction message.
320
321   procedure Check_Implicit_Dynamic_Code_Allowed (N : Node_Id);
322   --  Tests to see if dynamic code generation (dynamically generated
323   --  trampolines, in particular) is allowed by the current restrictions
324   --  settings. This function is called by Gigi when it needs to generate code
325   --  that generates a trampoline. If not allowed, an error message is posted
326   --  on the node given as argument.
327
328   --  WARNING: There is a matching C declaration of this subprogram in fe.h
329
330   procedure Check_No_Implicit_Heap_Alloc (N : Node_Id);
331   --  Equivalent to Check_Restriction (No_Implicit_Heap_Allocations, N).
332   --  Provided for easy use by back end, which has to check this restriction.
333
334   --  WARNING: There is a matching C declaration of this subprogram in fe.h
335
336   procedure Check_No_Implicit_Protected_Alloc (N : Node_Id);
337   --  Equivalent to:
338   --    Check_Restriction (No_Implicit_Protected_Object_Allocations, N)
339   --  Provided for easy use by back end, which has to check this restriction.
340
341   --  WARNING: There is a matching C declaration of this subprogram in fe.h
342
343   procedure Check_No_Implicit_Task_Alloc (N : Node_Id);
344   --  Equivalent to Check_Restriction (No_Implicit_Task_Allocations, N).
345   --  Provided for easy use by back end, which has to check this restriction.
346
347   --  WARNING: There is a matching C declaration of this subprogram in fe.h
348
349   procedure Check_Obsolescent_2005_Entity (E : Entity_Id; N : Node_Id);
350   --  This routine checks if the entity E is one of the obsolescent entries
351   --  in Ada.Characters.Handling in Ada 2005 and No_Obsolescent_Features
352   --  restriction is active. If so an appropriate message is given. N is
353   --  the node on which the message is to be placed. It's a bit kludgy to
354   --  have this highly specialized routine rather than some wonderful general
355   --  mechanism (e.g. a special pragma) to handle this case, but there are
356   --  only six cases, and it is not worth the effort to do something general.
357
358   procedure Check_Wide_Character_Restriction (E : Entity_Id; N : Node_Id);
359   --  This procedure checks if the No_Wide_Character restriction is active,
360   --  and if so, if N Comes_From_Source, and the root type of E is one of
361   --  [Wide_]Wide_Character or [Wide_]Wide_String, then the restriction
362   --  violation is recorded, and an appropriate message given.
363
364   function Get_Restriction_Id
365     (N : Name_Id) return Restriction_Id;
366   --  Given an identifier name, determines if it is a valid restriction
367   --  identifier, and if so returns the corresponding Restriction_Id value,
368   --  otherwise returns Not_A_Restriction_Id.
369
370   function OK_No_Dependence_Unit_Name (N : Node_Id) return Boolean;
371   --  Used in checking No_Dependence argument of pragma Restrictions or
372   --  pragma Restrictions_Warning, or attribute Restriction_Set. Returns
373   --  True if N has the proper form for a unit name, False otherwise.
374
375   function OK_No_Use_Of_Entity_Name (N : Node_Id) return Boolean;
376   --  Used in checking No_Use_Of_Entity argument of pragma Restrictions or
377   --  pragma Restrictions_Warning, or attribute Restriction_Set. Returns
378   --  True if N has the proper form for an entity name, False otherwise.
379
380   function No_Exception_Handlers_Set return Boolean;
381   --  Test to see if current restrictions settings specify that no exception
382   --  handlers are present. This function is called by Gigi when it needs to
383   --  expand an AT END clean up identifier with no exception handler. True
384   --  will be returned if the configurable run-time is activated, and either
385   --  of the restrictions No_Exception_Handlers or No_Exception_Propagation is
386   --  set. In the latter case, the source may contain handlers but they either
387   --  get converted using the local goto transformation or deleted.
388
389   --  WARNING: There is a matching C declaration of this subprogram in fe.h
390
391   function No_Exception_Propagation_Active return Boolean;
392   --  Test to see if current restrictions settings specify that no
393   --  exception propagation is activated.
394
395   function Process_Restriction_Synonyms (N : Node_Id) return Name_Id;
396   --  Id is a node whose Chars field contains the name of a restriction.
397   --  If it is one of synonyms that we allow for historical purposes (for
398   --  list see System.Rident), then the proper official name is returned.
399
400   function Restriction_Active (R : All_Restrictions) return Boolean;
401   pragma Inline (Restriction_Active);
402   --  Determines if a given restriction is active. This call should only be
403   --  used where the compiled code depends on whether the restriction is
404   --  active. Always use Check_Restriction to record a violation. Note that
405   --  this returns False if we only have a Restriction_Warnings set, since
406   --  restriction warnings should never affect generated code. If you want
407   --  to know if a call to Check_Restriction is needed then use the function
408   --  Restriction_Check_Required instead.
409
410   function Restriction_Check_Required (R : All_Restrictions) return Boolean;
411   pragma Inline (Restriction_Check_Required);
412   --  Determines if either a Restriction_Warnings or Restrictions pragma has
413   --  been given for the specified restriction. If true, then a subsequent
414   --  call to Check_Restriction is required if the restriction is violated.
415   --  This must not be used to guard code generation that depends on whether
416   --  a restriction is active (see Restriction_Active above). Typically it
417   --  is used to avoid complex code to determine if a restriction is violated,
418   --  executing this code only if needed.
419
420   function Restricted_Profile return Boolean;
421   --  Tests if set of restrictions corresponding to Restricted_Tasking profile
422   --  is currently in effect (set by pragma Profile, or by an appropriate set
423   --  of individual Restrictions pragmas). Returns True only if all the
424   --  required restrictions are set.
425
426   procedure Set_Global_No_Tasking;
427   --  Used in call from Sem_Prag when restriction No_Tasking is set in the
428   --  run-time package System or in a configuration pragmas file.
429
430   procedure Set_Profile_Restrictions
431     (P    : Profile_Name;
432      N    : Node_Id;
433      Warn : Boolean);
434   --  Sets the set of restrictions associated with the given profile name. N
435   --  is the node of the construct to which error messages are to be attached
436   --  as required. Warn is set True for the case of Profile_Warnings where the
437   --  restrictions are set as warnings rather than legality requirements, and
438   --  is also True for Profile if the Treat_Restrictions_As_Warnings flag is
439   --  set. It is false for Profile if this flag is not set.
440
441   procedure Set_Restriction
442     (R : All_Boolean_Restrictions;
443      N : Node_Id);
444   --  N is a node (typically a pragma node) that has the effect of setting
445   --  Boolean restriction R. The restriction is set in Restrictions, and
446   --  also in Main_Restrictions if this is the main unit.
447
448   procedure Set_Restriction
449     (R : All_Parameter_Restrictions;
450      N : Node_Id;
451      V : Integer);
452   --  Similar to the above, except that this is used for the case of a
453   --  parameter restriction, and the corresponding value V is given.
454
455   procedure Set_Restriction
456     (R    : All_Restrictions;
457      N    : Node_Id;
458      Warn : Boolean;
459      V    : Integer := Integer'First);
460   --  Same as above two, except also takes care of setting the
461   --  Restriction_Warnings flag. V is ignored for Boolean
462   --  restrictions.
463   --
464   --  If this is the first time we've seen this restriction, the warning flag
465   --  is set to Warn. If this is a second or subsequent time, Warn = False
466   --  wins; that is, errors always trump warnings. In that case, the warning
467   --  flag can be set to False, but never to True.
468
469   procedure Set_Restriction_No_Dependence
470     (Unit    : Node_Id;
471      Warn    : Boolean;
472      Profile : Profile_Name := No_Profile);
473   --  Sets given No_Dependence restriction in table if not there already. Warn
474   --  is True if from Restriction_Warnings, or for Restrictions if the flag
475   --  Treat_Restrictions_As_Warnings is set. False if from Restrictions and
476   --  this flag is not set. Profile is set to a non-default value if the
477   --  No_Dependence restriction comes from a Profile pragma.
478
479   procedure Set_Restriction_No_Specification_Of_Aspect
480     (N    : Node_Id;
481      Warn : Boolean);
482   --  N is the node id for an identifier from a pragma Restrictions for the
483   --  No_Specification_Of_Aspect pragma. An error message will be issued if
484   --  the identifier is not a valid aspect name. Warning is set True for the
485   --  case of a Restriction_Warnings pragma specifying this restriction and
486   --  False for a Restrictions pragma specifying this restriction.
487
488   procedure Set_Restriction_No_Specification_Of_Aspect (A_Id : Aspect_Id);
489   --  Version used by Get_Target_Parameters (via Tbuild)
490
491   procedure Set_Restriction_No_Use_Of_Attribute
492     (N    : Node_Id;
493      Warn : Boolean);
494   --  N is the node id for the identifier in a pragma Restrictions for
495   --  No_Use_Of_Attribute. Caller has verified that this is a valid attribute
496   --  designator.
497
498   procedure Set_Restriction_No_Use_Of_Attribute (A_Id : Attribute_Id);
499   --  Version used by Get_Target_Parameters (via Tbuild)
500
501   procedure Set_Restriction_No_Use_Of_Entity
502     (Entity  : Node_Id;
503      Warn    : Boolean;
504      Profile : Profile_Name := No_Profile);
505   --  Sets given No_Use_Of_Entity restriction in table if not there already.
506   --  Warn is True if from Restriction_Warnings, or for Restrictions if the
507   --  flag Treat_Restrictions_As_Warnings is set. False if from Restrictions
508   --  and this flag is not set. Profile is set to a non-default value if the
509   --  No_Dependence restriction comes from a Profile pragma. This procedure
510   --  also takes care of setting the Boolean2 flag of the simple name for
511   --  the entity (to optimize table searches).
512
513   procedure Set_Restriction_No_Use_Of_Pragma
514     (N    : Node_Id;
515      Warn : Boolean);
516   --  N is the node id for the identifier in a pragma Restrictions for
517   --  No_Use_Of_Pragma. Caller has verified that this is a valid pragma id.
518
519   procedure Set_Restriction_No_Use_Of_Pragma (A_Id : Pragma_Id);
520   --  Version used in call from Get_Target_Parameters (via Tbuild).
521
522   function Tasking_Allowed return Boolean;
523   pragma Inline (Tasking_Allowed);
524   --  Tests if tasking operations are allowed by the current restrictions
525   --  settings. For tasking to be allowed Max_Tasks must be non-zero.
526
527   function Global_No_Tasking return Boolean;
528   --  Returns True if the restriction No_Tasking is set in the run-time
529   --  package System or in a configuration pragmas file.
530
531   ----------------------------------------------
532   -- Handling of Boolean Compilation Switches --
533   ----------------------------------------------
534
535   --  The following declarations are used for proper saving and restoring of
536   --  restrictions for separate compilation units. There are two cases:
537
538   --    For partition-wide restrictions, we just let the restrictions pragmas
539   --    pile up, and we never reset them. We might as well detect what we can
540   --    at compile time. If e.g. a with'ed unit has a restriction for one of
541   --    the partition-wide restrictions, then the binder will enforce it on
542   --    all units in the partition, including the unit with the WITH. Although
543   --    it would not be wrong to leave this till bind time, we might as well
544   --    flag it earlier at compile time.
545
546   --    For non-partition-wide restrictions, we have quite a different state
547   --    of affairs. Here it would be quite wrong to carry a restriction from
548   --    a with'ed unit to another with'ed unit, or from a package spec to the
549   --    package body. This means that we have to reset these non-partition
550   --    wide restrictions at the start of each separate compilation unit. For
551   --    units in the extended main program, we need to reset them all to the
552   --    values set by the configuration pragma file(s). For units not in the
553   --    extended main program, e.g. with'ed units, we might as well reset all
554   --    of these restrictions to off (False). The actual initial values will
555   --    be taken from the config files active when those units are compiled
556   --    as main units.
557
558   type Save_Cunit_Boolean_Restrictions is private;
559   --  Type used for saving and restoring compilation unit restrictions.
560
561   function Cunit_Boolean_Restrictions_Save
562     return Save_Cunit_Boolean_Restrictions;
563   --  This function saves the compilation unit restriction settings, leaving
564   --  them unchanged. This is used e.g. at the start of processing a context
565   --  clause, so that the main unit restrictions can be restored after all
566   --  the with'ed units have been processed.
567
568   procedure Cunit_Boolean_Restrictions_Restore
569     (R : Save_Cunit_Boolean_Restrictions);
570   --  This is the corresponding restore procedure to restore restrictions
571   --  previously saved by Cunit_Boolean_Restrictions_Save. However it does
572   --  not reset No_Elaboration_Code, this stays set if it was set before
573   --  the call, and also if it is set before the call, then the Config
574   --  setting is also updated to include this restriction. This is what
575   --  implements the special handling of No_Elaboration_Code.
576
577   procedure Save_Config_Cunit_Boolean_Restrictions;
578   --  This saves the current compilation unit restrictions in an internal
579   --  variable, and leaves them unchanged. This is called immediately after
580   --  processing the configuration file pragmas, to record the restrictions
581   --  set by these configuration file pragmas.
582
583   procedure Restore_Config_Cunit_Boolean_Restrictions;
584   --  This restores the value saved by the previous call to save config values
585   --  saved by Save_Config_Cunit_Boolean_Restrictions. It is called at the
586   --  start of processing a new unit that is part of the main sources (e.g.
587   --  a package spec when the main unit is a package body).
588
589   procedure Reset_Cunit_Boolean_Restrictions;
590   --  Turns off all non-partition-wide boolean restrictions
591
592   procedure Add_To_Config_Boolean_Restrictions (R : Restriction_Id);
593   --  Add specified restriction to stored configuration boolean restrictions.
594   --  This is used for handling the special case of No_Elaboration_Code.
595
596private
597   type Save_Cunit_Boolean_Restrictions is
598     array (Cunit_Boolean_Restrictions) of Boolean;
599   --  Type used for saving and restoring compilation unit restrictions.
600   --  See Compilation_Unit_Restrictions_[Save|Restore] subprograms.
601
602end Restrict;
603