OSDN Git Service

* targhooks.c (default_stack_protect_guard): Avoid sharing RTL
[pf3gnuchains/gcc-fork.git] / gcc / ada / restrict.ads
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-2008, 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
28 with Namet;  use Namet;
29 with Rident; use Rident;
30 with Table;
31 with Types;  use Types;
32 with Uintp;  use Uintp;
33
34 package Restrict is
35
36    Restrictions : Restrictions_Info := No_Restrictions;
37    --  This variable records restrictions found in any units in the main
38    --  extended unit, and in the case of restrictions checked for partition
39    --  consistency, restrictions found in any with'ed units, parent specs
40    --  etc., since we may as well check as much as we can at compile time.
41    --  These variables should not be referenced directly by clients. Instead
42    --  use Check_Restrictions to record a violation of a restriction, and
43    --  Restriction_Active to test if a given restriction is active.
44
45    Restrictions_Loc : array (All_Restrictions) of Source_Ptr :=
46                        (others => No_Location);
47    --  Locations of Restrictions pragmas for error message purposes.
48    --  Valid only if corresponding entry in Restrictions is set. A value
49    --  of No_Location is used for implicit restrictions set by another
50    --  pragma, and a value of System_Location is used for restrictions
51    --  set from package Standard by the processing in Targparm.
52
53    Restriction_Profile_Name : array (All_Restrictions) of Profile_Name;
54    --  Entries in this array are valid only if the corresponding restriction
55    --  in Restrictions set. The value is the corresponding profile name if the
56    --  restriction was set by a Profile or Profile_Warnings pragma. The value
57    --  is No_Profile in all other cases.
58
59    Main_Restrictions : Restrictions_Info := No_Restrictions;
60    --  This variable records only restrictions found in any units of the
61    --  main extended unit. These are the variables used for ali file output,
62    --  since we want the binder to be able to accurately diagnose inter-unit
63    --  restriction violations.
64
65    Restriction_Warnings : Rident.Restriction_Flags;
66    --  If one of these flags is set, then it means that violation of the
67    --  corresponding restriction results only in a warning message, not
68    --  in an error message, and the restriction is not otherwise enforced.
69    --  Note that the flags in Restrictions are set to indicate that the
70    --  restriction is set in this case, but Main_Restrictions is never
71    --  set if Restriction_Warnings is set, so this does not look like a
72    --  restriction to the binder.
73
74    type Save_Cunit_Boolean_Restrictions is private;
75    --  Type used for saving and restoring compilation unit restrictions.
76    --  See Cunit_Boolean_Restrictions_[Save|Restore] subprograms.
77
78    --  The following declarations establish a mapping between restriction
79    --  identifiers, and the names of corresponding restriction library units.
80
81    type Unit_Entry is record
82       Res_Id : Restriction_Id;
83       Filenm : String (1 .. 8);
84    end record;
85
86    Unit_Array : constant array (Positive range <>) of Unit_Entry := (
87      (No_Asynchronous_Control,     "a-astaco"),
88      (No_Calendar,                 "a-calend"),
89      (No_Calendar,                 "calendar"),
90      (No_Delay,                    "a-calend"),
91      (No_Delay,                    "calendar"),
92      (No_Dynamic_Priorities,       "a-dynpri"),
93      (No_Finalization,             "a-finali"),
94      (No_IO,                       "a-direio"),
95      (No_IO,                       "directio"),
96      (No_IO,                       "a-sequio"),
97      (No_IO,                       "sequenio"),
98      (No_IO,                       "a-ststio"),
99      (No_IO,                       "a-textio"),
100      (No_IO,                       "text_io "),
101      (No_IO,                       "a-witeio"),
102      (No_Task_Attributes_Package,  "a-tasatt"),
103      (No_Unchecked_Conversion,     "a-unccon"),
104      (No_Unchecked_Conversion,     "unchconv"),
105      (No_Unchecked_Deallocation,   "a-uncdea"),
106      (No_Unchecked_Deallocation,   "unchdeal"));
107
108    --  The following map has True for all GNAT pragmas. It is used to
109    --  implement pragma Restrictions (No_Implementation_Restrictions)
110    --  (which is why this restriction itself is excluded from the list).
111
112    Implementation_Restriction : array (All_Restrictions) of Boolean :=
113      (Simple_Barriers                    => True,
114       No_Asynchronous_Control            => True,
115       No_Calendar                        => 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_Registration          => True,
124       No_Implementation_Attributes       => True,
125       No_Implementation_Pragmas          => True,
126       No_Implicit_Conditionals           => True,
127       No_Implicit_Dynamic_Code           => True,
128       No_Implicit_Loops                  => True,
129       No_Local_Protected_Objects         => True,
130       No_Protected_Type_Allocators       => True,
131       No_Relative_Delay                  => True,
132       No_Requeue_Statements              => True,
133       No_Secondary_Stack                 => True,
134       No_Select_Statements               => True,
135       No_Standard_Storage_Pools          => True,
136       No_Streams                         => True,
137       No_Task_Attributes_Package         => True,
138       No_Task_Termination                => True,
139       No_Unchecked_Conversion            => True,
140       No_Unchecked_Deallocation          => True,
141       No_Wide_Characters                 => True,
142       Static_Priorities                  => True,
143       Static_Storage_Size                => True,
144       others                             => False);
145
146    --  The following table records entries made by Restrictions pragmas
147    --  that specify a parameter for No_Dependence. Each such pragma makes
148    --  an entry in this table.
149
150    --  Note: we have chosen to implement this restriction in the "syntactic"
151    --  form, where we do not check that the named package is a language defined
152    --  package, but instead we allow arbitrary package names. The discussion of
153    --  this issue is not complete in the ARG, but the sense seems to be leaning
154    --  in this direction, which makes more sense to us, since it is much more
155    --  useful, and much easier to implement.
156
157    type ND_Entry is record
158       Unit : Node_Id;
159       --  The unit parameter from the No_Dependence pragma
160
161       Warn : Boolean;
162       --  True if from Restriction_Warnings, False if from Restrictions
163
164       Profile : Profile_Name;
165       --  Set to name of profile from which No_Dependence entry came, or to
166       --  No_Profile if a pragma Restriction set the No_Dependence entry.
167    end record;
168
169    package No_Dependence is new Table.Table (
170      Table_Component_Type => ND_Entry,
171      Table_Index_Type     => Int,
172      Table_Low_Bound      => 0,
173      Table_Initial        => 200,
174      Table_Increment      => 200,
175      Table_Name           => "Name_No_Dependence");
176
177    -----------------
178    -- Subprograms --
179    -----------------
180
181    function Abort_Allowed return Boolean;
182    pragma Inline (Abort_Allowed);
183    --  Tests to see if abort is allowed by the current restrictions settings.
184    --  For abort to be allowed, either No_Abort_Statements must be False,
185    --  or Max_Asynchronous_Select_Nesting must be non-zero.
186
187    procedure Check_Compiler_Unit (N : Node_Id);
188    --  If unit N is in a unit that has a pragma Compiler_Unit, then a message
189    --  is posted on node N noting use of a construct that is not permitted in
190    --  the compiler.
191
192    procedure Check_Restricted_Unit (U : Unit_Name_Type; N : Node_Id);
193    --  Checks if loading of unit U is prohibited by the setting of some
194    --  restriction (e.g. No_IO restricts the loading of unit Ada.Text_IO).
195    --  If a restriction exists post error message at the given node.
196
197    procedure Check_Restriction
198      (R : Restriction_Id;
199       N : Node_Id;
200       V : Uint := Uint_Minus_1);
201    --  Checks that the given restriction is not set, and if it is set, an
202    --  appropriate message is posted on the given node. Also records the
203    --  violation in the appropriate internal arrays. Note that it is mandatory
204    --  to always use this routine to check if a restriction is violated. Such
205    --  checks must never be done directly by the caller, since otherwise
206    --  violations in the absence of restrictions are not properly recorded. The
207    --  value of V is relevant only for parameter restrictions, and in this case
208    --  indicates the exact count for the violation. If the exact count is not
209    --  known, V is left at its default of -1 which indicates an unknown count.
210
211    procedure Check_Restriction_No_Dependence (U : Node_Id; Err : Node_Id);
212    --  Called when a dependence on a unit is created (either implicitly, or by
213    --  an explicit WITH clause). U is a node for the unit involved, and Err
214    --  is the node to which an error will be attached if necessary.
215
216    procedure Check_Elaboration_Code_Allowed (N : Node_Id);
217    --  Tests to see if elaboration code is allowed by the current restrictions
218    --  settings. This function is called by Gigi when it needs to define
219    --  an elaboration routine. If elaboration code is not allowed, an error
220    --  message is posted on the node given as argument.
221
222    procedure Check_Implicit_Dynamic_Code_Allowed (N : Node_Id);
223    --  Tests to see if dynamic code generation (dynamically generated
224    --  trampolines, in particular) is allowed by the current restrictions
225    --  settings. This function is called by Gigi when it needs to generate code
226    --  that generates a trampoline. If not allowed, an error message is posted
227    --  on the node given as argument.
228
229    procedure Check_No_Implicit_Heap_Alloc (N : Node_Id);
230    --  Equivalent to Check_Restriction (No_Implicit_Heap_Allocations, N).
231    --  Provided for easy use by back end, which has to check this restriction.
232
233    function Cunit_Boolean_Restrictions_Save
234      return Save_Cunit_Boolean_Restrictions;
235    --  This function saves the compilation unit restriction settings, and
236    --  resets them to False. This is used e.g. when compiling a with'ed
237    --  unit to avoid incorrectly propagating restrictions. Note that it
238    --  would not be wrong to also save and reset the partition restrictions,
239    --  since the binder would catch inconsistencies, but actually it is a
240    --  good thing to acquire restrictions from with'ed units if they are
241    --  required to be partition wide, because it allows the restriction
242    --  violation message to be given at compile time instead of link time.
243
244    procedure Cunit_Boolean_Restrictions_Restore
245      (R : Save_Cunit_Boolean_Restrictions);
246    --  This is the corresponding restore procedure to restore restrictions
247    --  previously saved by Cunit_Boolean_Restrictions_Save.
248
249    function Get_Restriction_Id
250      (N : Name_Id) return Restriction_Id;
251    --  Given an identifier name, determines if it is a valid restriction
252    --  identifier, and if so returns the corresponding Restriction_Id
253    --  value, otherwise returns Not_A_Restriction_Id.
254
255    function No_Exception_Handlers_Set return Boolean;
256    --  Test to see if current restrictions settings specify that no exception
257    --  handlers are present. This function is called by Gigi when it needs to
258    --  expand an AT END clean up identifier with no exception handler. True
259    --  will be returned if the configurable run-time is activated, and either
260    --  of the restrictions No_Exception_Handlers or No_Exception_Propagation is
261    --  set. In the latter case, the source may contain handlers but they either
262    --  get converted using the local goto transformation or deleted.
263
264    function No_Exception_Propagation_Active return Boolean;
265    --  Test to see if current restrictions settings specify that no
266    --  exception propagation is activated.
267
268    function Process_Restriction_Synonyms (N : Node_Id) return Name_Id;
269    --  Id is a node whose Chars field contains the name of a restriction.
270    --  If it is one of synonyms that we allow for historical purposes (for
271    --  list see System.Rident), then the proper official name is returned.
272    --  Otherwise the Chars field of the argument is returned unchanged.
273
274    function Restriction_Active (R : All_Restrictions) return Boolean;
275    pragma Inline (Restriction_Active);
276    --  Determines if a given restriction is active. This call should only be
277    --  used where the compiled code depends on whether the restriction is
278    --  active. Always use Check_Restriction to record a violation. Note that
279    --  this returns False if we only have a Restriction_Warnings set, since
280    --  restriction warnings should never affect generated code.
281
282    function Restricted_Profile return Boolean;
283    --  Tests if set of restrictions corresponding to Profile (Restricted) is
284    --  currently in effect (set by pragma Profile, or by an appropriate set
285    --  of individual Restrictions pragmas). Returns True only if all the
286    --  required restrictions are set.
287
288    procedure Set_Profile_Restrictions
289      (P    : Profile_Name;
290       N    : Node_Id;
291       Warn : Boolean);
292    --  Sets the set of restrictions associated with the given profile name. N
293    --  is the node of the construct to which error messages are to be attached
294    --  as required. Warn is set True for the case of Profile_Warnings where the
295    --  restrictions are set as warnings rather than legality requirements, and
296    --  is also True for Profile if the Treat_Restrictions_As_Warnings flag is
297    --  set. It is false for Profile if this flag is not set.
298
299    procedure Set_Restriction
300      (R : All_Boolean_Restrictions;
301       N : Node_Id);
302    --  N is a node (typically a pragma node) that has the effect of setting
303    --  Boolean restriction R. The restriction is set in Restrictions, and
304    --  also in Main_Restrictions if this is the main unit.
305
306    procedure Set_Restriction
307      (R : All_Parameter_Restrictions;
308       N : Node_Id;
309       V : Integer);
310    --  Similar to the above, except that this is used for the case of a
311    --  parameter restriction, and the corresponding value V is given.
312
313    procedure Set_Restriction_No_Dependence
314      (Unit    : Node_Id;
315       Warn    : Boolean;
316       Profile : Profile_Name := No_Profile);
317    --  Sets given No_Dependence restriction in table if not there already.
318    --  Warn is True if from Restriction_Warnings, or for Restrictions if flag
319    --  Treat_Restrictions_As_Warnings is set. False if from Restrictions and
320    --  this flag is not set. Profile is set to a non-default value if the
321    --  No_Dependence restriction comes from a Profile pragma.
322
323    function Tasking_Allowed return Boolean;
324    pragma Inline (Tasking_Allowed);
325    --  Tests if tasking operations are allowed by the current restrictions
326    --  settings. For tasking to be allowed Max_Tasks must be non-zero.
327
328 private
329    type Save_Cunit_Boolean_Restrictions is
330      array (Cunit_Boolean_Restrictions) of Boolean;
331    --  Type used for saving and restoring compilation unit restrictions.
332    --  See Compilation_Unit_Restrictions_[Save|Restore] subprograms.
333
334 end Restrict;