Daily bump.
[official-gcc.git] / gcc / ada / restrict.ads
blob0a81324e2ba26c139574e6d9ad0828d8c1f95068
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT COMPILER COMPONENTS --
4 -- --
5 -- R E S T R I C T --
6 -- --
7 -- S p e c --
8 -- --
9 -- $Revision: 1.1 $
10 -- --
11 -- Copyright (C) 1992-2001 Free Software Foundation, Inc. --
12 -- --
13 -- GNAT is free software; you can redistribute it and/or modify it under --
14 -- terms of the GNU General Public License as published by the Free Soft- --
15 -- ware Foundation; either version 2, or (at your option) any later ver- --
16 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
17 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
18 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
19 -- for more details. You should have received a copy of the GNU General --
20 -- Public License distributed with GNAT; see file COPYING. If not, write --
21 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
22 -- MA 02111-1307, USA. --
23 -- --
24 -- GNAT was originally developed by the GNAT team at New York University. --
25 -- Extensive contributions were provided by Ada Core Technologies Inc. --
26 -- --
27 ------------------------------------------------------------------------------
29 -- This package deals with the implementation of the Restrictions pragma
31 with Rident;
32 with Types; use Types;
33 with Uintp; use Uintp;
35 package Restrict is
37 type Restriction_Id is new Rident.Restriction_Id;
38 -- The type Restriction_Id defines the set of restriction identifiers,
39 -- which take no parameter (i.e. they are either present or not present).
40 -- The actual definition is in the separate package Rident, so that it
41 -- can easily be accessed by the binder without dragging in lots of stuff.
43 subtype Partition_Restrictions is
44 Restriction_Id range
45 Restriction_Id (Rident.Partition_Restrictions'First) ..
46 Restriction_Id (Rident.Partition_Restrictions'Last);
47 -- Range of restriction identifiers that are checked by the binder
49 subtype Compilation_Unit_Restrictions is
50 Restriction_Id range
51 Restriction_Id (Rident.Compilation_Unit_Restrictions'First) ..
52 Restriction_Id (Rident.Compilation_Unit_Restrictions'Last);
53 -- Range of restriction identifiers not checked by binder
55 type Restriction_Parameter_Id is new Rident.Restriction_Parameter_Id;
56 -- The type Restriction_Parameter_Id records cases where a parameter is
57 -- present in the corresponding pragma. These cases are not checked for
58 -- consistency by the binder. The actual definition is in the separate
59 -- package Rident for consistency.
61 type Restrictions_Flags is array (Restriction_Id) of Boolean;
62 -- Type used for arrays indexed by Restriction_Id.
64 Restrictions : Restrictions_Flags := (others => False);
65 -- Corresponding entry is False if restriction is not active, and
66 -- True if the restriction is active, i.e. if a pragma Restrictions
67 -- has been seen anywhere. Note that we are happy to pick up any
68 -- restrictions pragmas in with'ed units, since we are required to
69 -- be consistent at link time, and we might as well find the error
70 -- at compile time. Clients must NOT use this array for checking to
71 -- see if a restriction is violated, instead it is required that the
72 -- Check_Restrictions subprograms be used for this purpose. The only
73 -- legitimate direct use of this array is when the code is modified
74 -- as a result of the restriction in some way.
76 Restrictions_Loc : array (Restriction_Id) of Source_Ptr;
77 -- Locations of Restrictions pragmas for error message purposes.
78 -- Valid only if corresponding entry in Restrictions is set.
80 Main_Restrictions : Restrictions_Flags := (others => False);
81 -- This variable saves the cumulative restrictions in effect compiling
82 -- any unit that is part of the extended main unit (i.e. the compiled
83 -- unit, its spec if any, and its subunits if any). The reason we keep
84 -- track of this is for the information that goes to the binder about
85 -- restrictions that are set. The binder will identify a unit that has
86 -- a restrictions pragma for error message purposes, and we do not want
87 -- to pick up a restrictions pragma in a with'ed unit for this purpose.
89 Violations : Restrictions_Flags := (others => False);
90 -- Corresponding entry is False if the restriction has not been
91 -- violated in the current main unit, and True if it has been violated.
93 Restriction_Parameters :
94 array (Restriction_Parameter_Id) of Uint := (others => No_Uint);
95 -- This array indicates the setting of restriction parameter identifier
96 -- values. All values are initially set to No_Uint indicating that the
97 -- parameter is not set, and are set to the appropriate non-negative
98 -- value if a Restrictions pragma specifies the corresponding
99 -- restriction parameter identifier with an appropriate value.
101 Restriction_Parameters_Loc :
102 array (Restriction_Parameter_Id) of Source_Ptr;
103 -- Locations of Restrictions pragmas for error message purposes.
104 -- Valid only if corresponding entry in Restriction_Parameters is
105 -- set to a value other than No_Uint.
107 type Unit_Entry is record
108 Res_Id : Restriction_Id;
109 Filenm : String (1 .. 8);
110 end record;
112 type Unit_Array_Type is array (Positive range <>) of Unit_Entry;
114 Unit_Array : constant Unit_Array_Type := (
115 (No_Asynchronous_Control, "a-astaco"),
116 (No_Calendar, "a-calend"),
117 (No_Calendar, "calendar"),
118 (No_Delay, "a-calend"),
119 (No_Delay, "calendar"),
120 (No_Dynamic_Priorities, "a-dynpri"),
121 (No_IO, "a-direio"),
122 (No_IO, "directio"),
123 (No_IO, "a-sequio"),
124 (No_IO, "sequenio"),
125 (No_IO, "a-ststio"),
126 (No_IO, "a-textio"),
127 (No_IO, "text_io "),
128 (No_IO, "a-witeio"),
129 (No_Task_Attributes, "a-tasatt"),
130 (No_Streams, "a-stream"),
131 (No_Unchecked_Conversion, "a-unccon"),
132 (No_Unchecked_Conversion, "unchconv"),
133 (No_Unchecked_Deallocation, "a-uncdea"),
134 (No_Unchecked_Deallocation, "unchdeal"));
135 -- This array defines the mapping between restriction identifiers and
136 -- predefined language files containing units for which the identifier
137 -- forbids semantic dependence.
139 type Save_Compilation_Unit_Restrictions is private;
140 -- Type used for saving and restoring compilation unit restrictions.
141 -- See Compilation_Unit_Restrictions_[Save|Restore] subprograms.
143 -----------------
144 -- Subprograms --
145 -----------------
147 procedure Check_Restricted_Unit (U : Unit_Name_Type; N : Node_Id);
148 -- Checks if loading of unit U is prohibited by the setting of some
149 -- restriction (e.g. No_IO restricts the loading of unit Ada.Text_IO).
150 -- If a restriction exists post error message at the given node.
152 procedure Check_Restriction (R : Restriction_Id; N : Node_Id);
153 -- Checks that the given restriction is not set, and if it is set, an
154 -- appropriate message is posted on the given node. Also records the
155 -- violation in the violations array. Note that it is mandatory to
156 -- always use this routine to check if a restriction is violated. Such
157 -- checks must never be done directly by the caller, since otherwise
158 -- they are not properly recorded in the violations array.
160 procedure Check_Restriction
161 (R : Restriction_Parameter_Id;
162 N : Node_Id);
163 -- Checks that the given restriction parameter identifier is not set to
164 -- zero. If it is set to zero, then the node N is replaced by a node
165 -- that raises Storage_Error, and a warning is issued.
167 procedure Check_Restriction
168 (R : Restriction_Parameter_Id;
169 V : Uint;
170 N : Node_Id);
171 -- Checks that the count in V does not exceed the maximum value of the
172 -- restriction parameter value corresponding to the given restriction
173 -- parameter identifier (if it has been set). If the count in V exceeds
174 -- the maximum, then post an error message on node N.
176 procedure Check_Elaboration_Code_Allowed (N : Node_Id);
177 -- Tests to see if elaboration code is allowed by the current restrictions
178 -- settings. This function is called by Gigi when it needs to define
179 -- an elaboration routine. If elaboration code is not allowed, an error
180 -- message is posted on the node given as argument.
182 function No_Exception_Handlers_Set return Boolean;
183 -- Test to see if current restrictions settings specify that no exception
184 -- handlers are present. This function is called by Gigi when it needs to
185 -- expand an AT END clean up identifier with no exception handler.
187 function Compilation_Unit_Restrictions_Save
188 return Save_Compilation_Unit_Restrictions;
189 -- This function saves the compilation unit restriction settings, and
190 -- resets them to False. This is used e.g. when compiling a with'ed
191 -- unit to avoid incorrectly propagating restrictions. Note that it
192 -- would not be wrong to also save and reset the partition restrictions,
193 -- since the binder would catch inconsistencies, but actually it is a
194 -- good thing to acquire restrictions from with'ed units if they are
195 -- required to be partition wide, because it allows the restriction
196 -- violation message to be given at compile time instead of link time.
198 procedure Compilation_Unit_Restrictions_Restore
199 (R : Save_Compilation_Unit_Restrictions);
200 -- This is the corresponding restore procedure to restore restrictions
201 -- previously saved by Compilation_Unit_Restrictions_Save.
203 procedure Disallow_In_No_Run_Time_Mode (Enode : Node_Id);
204 -- If in No_Run_Time mode, then the construct represented by Enode is
205 -- not permitted, and will be appropriately flagged.
207 procedure Set_No_Run_Time_Mode;
208 -- Set the no run time mode, and associated restriction pragmas.
210 function Get_Restriction_Id
211 (N : Name_Id)
212 return Restriction_Id;
213 -- Given an identifier name, determines if it is a valid restriction
214 -- identifier, and if so returns the corresponding Restriction_Id
215 -- value, otherwise returns Not_A_Restriction_Id.
217 function Get_Restriction_Parameter_Id
218 (N : Name_Id)
219 return Restriction_Parameter_Id;
220 -- Given an identifier name, determines if it is a valid restriction
221 -- parameter identifier, and if so returns the corresponding
222 -- Restriction_Parameter_Id value, otherwise returns
223 -- Not_A_Restriction_Parameter_Id.
225 function Abort_Allowed return Boolean;
226 pragma Inline (Abort_Allowed);
227 -- Tests to see if abort is allowed by the current restrictions settings.
228 -- For abort to be allowed, either No_Abort_Statements must be False,
229 -- or Max_Asynchronous_Select_Nesting must be non-zero.
231 function Restricted_Profile return Boolean;
232 -- Tests to see if tasking operations follow the GNAT restricted run time
233 -- profile.
235 procedure Set_Ravenscar;
236 -- Sets the set of rerstrictions fro Ravenscar
238 procedure Set_Restricted_Profile;
239 -- Sets the set of restrictions for pragma Restricted_Run_Time
241 function Tasking_Allowed return Boolean;
242 pragma Inline (Tasking_Allowed);
243 -- Tests to see if tasking operations are allowed by the current
244 -- restrictions settings. For tasking to be allowed Max_Tasks must
245 -- be non-zero.
247 private
248 type Save_Compilation_Unit_Restrictions is
249 array (Compilation_Unit_Restrictions) of Boolean;
250 -- Type used for saving and restoring compilation unit restrictions.
251 -- See Compilation_Unit_Restrictions_[Save|Restore] subprograms.
253 end Restrict;