1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2004 Free Software Foundation, Inc. --
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 2, 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 COPYING. If not, write --
19 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
20 -- MA 02111-1307, USA. --
22 -- GNAT was originally developed by the GNAT team at New York University. --
23 -- Extensive contributions were provided by Ada Core Technologies Inc. --
25 ------------------------------------------------------------------------------
27 -- This package deals with the implementation of the Restrictions pragma
29 with Rident; use Rident;
30 with Types; use Types;
31 with Uintp; use Uintp;
35 Restrictions : Restrictions_Info;
36 -- This variable records restrictions found in any units in the main
37 -- extended unit, and in the case of restrictions checked for partition
38 -- consistency, restrictions found in any with'ed units, parent specs
39 -- etc, since we may as well check as much as we can at compile time.
40 -- These variables should not be referenced directly by clients. Instead
41 -- use Check_Restrictions to record a violation of a restriction, and
42 -- Restriction_Active to test if a given restriction is active.
44 Restrictions_Loc : array (All_Restrictions) of Source_Ptr :=
45 (others => No_Location);
46 -- Locations of Restrictions pragmas for error message purposes.
47 -- Valid only if corresponding entry in Restrictions is set. A value
48 -- of No_Location is used for implicit restrictions set by another
49 -- pragma, and a value of System_Location is used for restrictions
50 -- set from package Standard by the processing in Targparm.
52 Main_Restrictions : Restrictions_Info;
53 -- This variable records only restrictions found in any units of the
54 -- main extended unit. These are the variables used for ali file output,
55 -- since we want the binder to be able to accurately diagnose inter-unit
56 -- restriction violations.
58 Restriction_Warnings : Rident.Restriction_Flags;
59 -- If one of these flags is set, then it means that violation of the
60 -- corresponding restriction results only in a warning message, not
61 -- in an error message, and the restriction is not otherwise enforced.
62 -- Note that the flags in Restrictions are set to indicate that the
63 -- restriction is set in this case, but Main_Restrictions is never
64 -- set if Restriction_Warnings is set, so this does not look like a
65 -- restriction to the binder.
67 type Save_Cunit_Boolean_Restrictions is private;
68 -- Type used for saving and restoring compilation unit restrictions.
69 -- See Cunit_Boolean_Restrictions_[Save|Restore] subprograms.
71 -- The following declarations establish a mapping between restriction
72 -- identifiers, and the names of corresponding restriction library units.
74 type Unit_Entry is record
75 Res_Id : Restriction_Id;
76 Filenm : String (1 .. 8);
79 Unit_Array : constant array (Positive range <>) of Unit_Entry := (
80 (No_Asynchronous_Control, "a-astaco"),
81 (No_Calendar, "a-calend"),
82 (No_Calendar, "calendar"),
83 (No_Delay, "a-calend"),
84 (No_Delay, "calendar"),
85 (No_Dynamic_Priorities, "a-dynpri"),
86 (No_Finalization, "a-finali"),
95 (No_Task_Attributes_Package, "a-tasatt"),
96 (No_Streams, "a-stream"),
97 (No_Unchecked_Conversion, "a-unccon"),
98 (No_Unchecked_Conversion, "unchconv"),
99 (No_Unchecked_Deallocation, "a-uncdea"),
100 (No_Unchecked_Deallocation, "unchdeal"));
102 -- The following map has True for all GNAT pragmas. It is used to
103 -- implement pragma Restrictions (No_Implementation_Restrictions)
104 -- (which is why this restriction itself is excluded from the list).
106 Implementation_Restriction : array (All_Restrictions) of Boolean :=
107 (Boolean_Entry_Barriers => True,
109 No_Dynamic_Interrupts => True,
110 No_Enumeration_Maps => True,
111 No_Entry_Calls_In_Elaboration_Code => True,
112 No_Entry_Queue => True,
113 No_Exception_Handlers => True,
114 No_Exception_Registration => True,
115 No_Implicit_Conditionals => True,
116 No_Implicit_Dynamic_Code => True,
117 No_Implicit_Loops => True,
118 No_Local_Protected_Objects => True,
119 No_Protected_Type_Allocators => True,
120 No_Relative_Delay => True,
121 No_Requeue_Statements => True,
122 No_Secondary_Stack => True,
123 No_Select_Statements => True,
124 No_Standard_Storage_Pools => True,
126 No_Task_Attributes_Package => True,
127 No_Task_Termination => True,
128 No_Wide_Characters => True,
129 Static_Priorities => True,
130 Static_Storage_Size => True,
131 No_Implementation_Attributes => True,
132 No_Implementation_Pragmas => True,
133 No_Elaboration_Code => True,
140 function Abort_Allowed return Boolean;
141 pragma Inline (Abort_Allowed);
142 -- Tests to see if abort is allowed by the current restrictions settings.
143 -- For abort to be allowed, either No_Abort_Statements must be False,
144 -- or Max_Asynchronous_Select_Nesting must be non-zero.
146 procedure Check_Restricted_Unit (U : Unit_Name_Type; N : Node_Id);
147 -- Checks if loading of unit U is prohibited by the setting of some
148 -- restriction (e.g. No_IO restricts the loading of unit Ada.Text_IO).
149 -- If a restriction exists post error message at the given node.
151 procedure Check_Restriction
154 V : Uint := Uint_Minus_1);
155 -- Checks that the given restriction is not set, and if it is set, an
156 -- appropriate message is posted on the given node. Also records the
157 -- violation in the appropriate internal arrays. Note that it is
158 -- mandatory to always use this routine to check if a restriction
159 -- is violated. Such checks must never be done directly by the caller,
160 -- since otherwise violations in the absence of restrictions are not
161 -- properly recorded. The value of V is relevant only for parameter
162 -- restrictions, and in this case indicates the exact count for the
163 -- violation. If the exact count is not known, V is left at its
164 -- default value of -1 which indicates an unknown count.
166 procedure Check_Elaboration_Code_Allowed (N : Node_Id);
167 -- Tests to see if elaboration code is allowed by the current restrictions
168 -- settings. This function is called by Gigi when it needs to define
169 -- an elaboration routine. If elaboration code is not allowed, an error
170 -- message is posted on the node given as argument.
172 procedure Check_No_Implicit_Heap_Alloc (N : Node_Id);
173 -- Equivalent to Check_Restriction (No_Implicit_Heap_Allocations, N).
174 -- Provided for easy use by back end, which has to check this restriction.
176 function Cunit_Boolean_Restrictions_Save
177 return Save_Cunit_Boolean_Restrictions;
178 -- This function saves the compilation unit restriction settings, and
179 -- resets them to False. This is used e.g. when compiling a with'ed
180 -- unit to avoid incorrectly propagating restrictions. Note that it
181 -- would not be wrong to also save and reset the partition restrictions,
182 -- since the binder would catch inconsistencies, but actually it is a
183 -- good thing to acquire restrictions from with'ed units if they are
184 -- required to be partition wide, because it allows the restriction
185 -- violation message to be given at compile time instead of link time.
187 procedure Cunit_Boolean_Restrictions_Restore
188 (R : Save_Cunit_Boolean_Restrictions);
189 -- This is the corresponding restore procedure to restore restrictions
190 -- previously saved by Cunit_Boolean_Restrictions_Save.
192 function Get_Restriction_Id
193 (N : Name_Id) return Restriction_Id;
194 -- Given an identifier name, determines if it is a valid restriction
195 -- identifier, and if so returns the corresponding Restriction_Id
196 -- value, otherwise returns Not_A_Restriction_Id.
198 function No_Exception_Handlers_Set return Boolean;
199 -- Test to see if current restrictions settings specify that no exception
200 -- handlers are present. This function is called by Gigi when it needs to
201 -- expand an AT END clean up identifier with no exception handler.
203 function Restriction_Active (R : All_Restrictions) return Boolean;
204 pragma Inline (Restriction_Active);
205 -- Determines if a given restriction is active. This call should only be
206 -- used where the compiled code depends on whether the restriction is
207 -- active. Always use Check_Restriction to record a violation.
209 function Restricted_Profile return Boolean;
210 -- Tests to see if tasking operations follow the GNAT restricted run time
213 procedure Set_Ravenscar (N : Node_Id);
214 -- Enables the set of restrictions for Ravenscar. N is the corresponding
215 -- pragma node, which is used for error messages on any constructs that
216 -- violate the profile.
218 procedure Set_Restriction
219 (R : All_Boolean_Restrictions;
221 -- N is a node (typically a pragma node) that has the effect of setting
222 -- Boolean restriction R. The restriction is set in Restrictions, and
223 -- also in Main_Restrictions if this is the main unit.
225 procedure Set_Restriction
226 (R : All_Parameter_Restrictions;
229 -- Similar to the above, except that this is used for the case of a
230 -- parameter restriction, and the corresponding value V is given.
232 procedure Set_Restricted_Profile (N : Node_Id);
233 -- Enables the set of restrictions for pragma Restricted_Run_Time. N is
234 -- the corresponding pragma node, which is used for error messages on
235 -- constructs that violate the profile.
237 function Tasking_Allowed return Boolean;
238 pragma Inline (Tasking_Allowed);
239 -- Tests to see if tasking operations are allowed by the current
240 -- restrictions settings. For tasking to be allowed Max_Tasks must
244 type Save_Cunit_Boolean_Restrictions is
245 array (Cunit_Boolean_Restrictions) of Boolean;
246 -- Type used for saving and restoring compilation unit restrictions.
247 -- See Compilation_Unit_Restrictions_[Save|Restore] subprograms.