OSDN Git Service

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