OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [gcc/] [ada/] [restrict.ads] - Blame information for rev 713

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 706 jeremybenn
------------------------------------------------------------------------------
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-2011, 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_Restriction 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
   --  The following declarations establish a mapping between restriction
75
   --  identifiers, and the names of corresponding restriction library units.
76
 
77
   type Unit_Entry is record
78
      Res_Id : Restriction_Id;
79
      Filenm : String (1 .. 8);
80
   end record;
81
 
82
   Unit_Array : constant array (Positive range <>) of Unit_Entry := (
83
     (No_Asynchronous_Control,     "a-astaco"),
84
     (No_Calendar,                 "a-calend"),
85
     (No_Calendar,                 "calendar"),
86
     (No_Delay,                    "a-calend"),
87
     (No_Delay,                    "calendar"),
88
     (No_Dynamic_Priorities,       "a-dynpri"),
89
     (No_Finalization,             "a-finali"),
90
     (No_IO,                       "a-direio"),
91
     (No_IO,                       "directio"),
92
     (No_IO,                       "a-sequio"),
93
     (No_IO,                       "sequenio"),
94
     (No_IO,                       "a-ststio"),
95
     (No_IO,                       "a-textio"),
96
     (No_IO,                       "text_io "),
97
     (No_IO,                       "a-witeio"),
98
     (No_Task_Attributes_Package,  "a-tasatt"),
99
     (No_Unchecked_Conversion,     "a-unccon"),
100
     (No_Unchecked_Conversion,     "unchconv"),
101
     (No_Unchecked_Deallocation,   "a-uncdea"),
102
     (No_Unchecked_Deallocation,   "unchdeal"));
103
 
104
   --  The following map has True for all GNAT pragmas. It is used to
105
   --  implement pragma Restrictions (No_Implementation_Restrictions)
106
   --  (which is why this restriction itself is excluded from the list).
107
 
108
   Implementation_Restriction : array (All_Restrictions) of Boolean :=
109
     (Simple_Barriers                    => True,
110
      No_Asynchronous_Control            => True,
111
      No_Calendar                        => True,
112
      No_Dispatching_Calls               => True,
113
      No_Dynamic_Attachment              => True,
114
      No_Elaboration_Code                => True,
115
      No_Enumeration_Maps                => True,
116
      No_Entry_Calls_In_Elaboration_Code => True,
117
      No_Entry_Queue                     => True,
118
      No_Exception_Handlers              => True,
119
      No_Exception_Registration          => True,
120
      No_Implementation_Attributes       => True,
121
      No_Implementation_Pragmas          => True,
122
      No_Implicit_Conditionals           => True,
123
      No_Implicit_Dynamic_Code           => True,
124
      No_Implicit_Loops                  => True,
125
      No_Local_Protected_Objects         => True,
126
      No_Protected_Type_Allocators       => True,
127
      No_Relative_Delay                  => True,
128
      No_Requeue_Statements              => True,
129
      No_Secondary_Stack                 => True,
130
      No_Select_Statements               => True,
131
      No_Standard_Storage_Pools          => True,
132
      No_Streams                         => True,
133
      No_Task_Attributes_Package         => True,
134
      No_Task_Termination                => True,
135
      No_Unchecked_Conversion            => True,
136
      No_Unchecked_Deallocation          => True,
137
      No_Wide_Characters                 => True,
138
      Static_Priorities                  => True,
139
      Static_Storage_Size                => True,
140
      others                             => False);
141
 
142
   --  The following table records entries made by Restrictions pragmas
143
   --  that specify a parameter for No_Dependence. Each such pragma makes
144
   --  an entry in this table.
145
 
146
   --  Note: we have chosen to implement this restriction in the "syntactic"
147
   --  form, where we do not check that the named package is a language defined
148
   --  package, but instead we allow arbitrary package names. The discussion of
149
   --  this issue is not complete in the ARG, but the sense seems to be leaning
150
   --  in this direction, which makes more sense to us, since it is much more
151
   --  useful, and much easier to implement.
152
 
153
   type ND_Entry is record
154
      Unit : Node_Id;
155
      --  The unit parameter from the No_Dependence pragma
156
 
157
      Warn : Boolean;
158
      --  True if from Restriction_Warnings, False if from Restrictions
159
 
160
      Profile : Profile_Name;
161
      --  Set to name of profile from which No_Dependence entry came, or to
162
      --  No_Profile if a pragma Restriction set the No_Dependence entry.
163
   end record;
164
 
165
   package No_Dependences is new Table.Table (
166
     Table_Component_Type => ND_Entry,
167
     Table_Index_Type     => Int,
168
     Table_Low_Bound      => 0,
169
     Table_Initial        => 200,
170
     Table_Increment      => 200,
171
     Table_Name           => "Name_No_Dependences");
172
 
173
   -------------------------------
174
   -- SPARK Restriction Control --
175
   -------------------------------
176
 
177
   --  SPARK HIDE directives allow the effect of the SPARK restriction to be
178
   --  turned off for a specified region of code, and the following tables are
179
   --  the data structures used to keep track of these regions.
180
 
181
   --  The table contains pairs of source locations, the first being the start
182
   --  location for hidden region, and the second being the end location.
183
 
184
   --  Note that the start location is included in the hidden region, while
185
   --  the end location is excluded from it. (It typically corresponds to the
186
   --  next token during scanning.)
187
 
188
   type SPARK_Hide_Entry is record
189
      Start : Source_Ptr;
190
      Stop  : Source_Ptr;
191
   end record;
192
 
193
   package SPARK_Hides is new Table.Table (
194
     Table_Component_Type => SPARK_Hide_Entry,
195
     Table_Index_Type     => Natural,
196
     Table_Low_Bound      => 1,
197
     Table_Initial        => 100,
198
     Table_Increment      => 200,
199
     Table_Name           => "SPARK Hides");
200
 
201
   -----------------
202
   -- Subprograms --
203
   -----------------
204
 
205
   --  Note: several of these subprograms can generate error messages (e.g.
206
   --  Check_Restriction). These routines should be called in the analyzer
207
   --  rather than the expander, so that the associated error messages are
208
   --  correctly generated in semantics only (-gnatc) mode.
209
 
210
   function Abort_Allowed return Boolean;
211
   pragma Inline (Abort_Allowed);
212
   --  Tests to see if abort is allowed by the current restrictions settings.
213
   --  For abort to be allowed, either No_Abort_Statements must be False,
214
   --  or Max_Asynchronous_Select_Nesting must be non-zero.
215
 
216
   procedure Check_Compiler_Unit (N : Node_Id);
217
   --  If unit N is in a unit that has a pragma Compiler_Unit, then a message
218
   --  is posted on node N noting use of a construct that is not permitted in
219
   --  the compiler.
220
 
221
   procedure Check_Restricted_Unit (U : Unit_Name_Type; N : Node_Id);
222
   --  Checks if loading of unit U is prohibited by the setting of some
223
   --  restriction (e.g. No_IO restricts the loading of unit Ada.Text_IO).
224
   --  If a restriction exists post error message at the given node.
225
 
226
   procedure Check_Restriction
227
     (Msg_Issued : out Boolean;
228
      R          : Restriction_Id;
229
      N          : Node_Id;
230
      V          : Uint := Uint_Minus_1);
231
   --  Checks that the given restriction is not set, and if it is set, an
232
   --  appropriate message is posted on the given node, in which case
233
   --  Msg_Issued is set to True (and False otherwise). Also records the
234
   --  violation in the appropriate internal arrays. Note that it is mandatory
235
   --  to always use this routine to check if a restriction is violated. Such
236
   --  checks must never be done directly by the caller, since otherwise
237
   --  violations in the absence of restrictions are not properly recorded. The
238
   --  value of V is relevant only for parameter restrictions, and in this case
239
   --  indicates the exact count for the violation. If the exact count is not
240
   --  known, V is left at its default of -1 which indicates an unknown count.
241
 
242
   procedure Check_Restriction
243
     (R : Restriction_Id;
244
      N : Node_Id;
245
      V : Uint := Uint_Minus_1);
246
   --  Wrapper on Check_Restriction with Msg_Issued, with the out-parameter
247
   --  being ignored here.
248
 
249
   procedure Check_Restriction_No_Dependence (U : Node_Id; Err : Node_Id);
250
   --  Called when a dependence on a unit is created (either implicitly, or by
251
   --  an explicit WITH clause). U is a node for the unit involved, and Err is
252
   --  the node to which an error will be attached if necessary.
253
 
254
   procedure Check_Restriction_No_Specification_Of_Aspect (N : Node_Id);
255
   --  N is the node id for an N_Aspect_Specification. An error message
256
   --  (warning) will be issued if a restriction (warning) was previous set
257
   --  for this aspect using Set_No_Specification_Of_Aspect.
258
 
259
   procedure Check_Elaboration_Code_Allowed (N : Node_Id);
260
   --  Tests to see if elaboration code is allowed by the current restrictions
261
   --  settings. This function is called by Gigi when it needs to define an
262
   --  elaboration routine. If elaboration code is not allowed, an error
263
   --  message is posted on the node given as argument.
264
 
265
   procedure Check_SPARK_Restriction
266
     (Msg   : String;
267
      N     : Node_Id;
268
      Force : Boolean := False);
269
   --  Node N represents a construct not allowed in formal mode. If this is a
270
   --  source node, or if the restriction is forced (Force = True), and the
271
   --  SPARK restriction is set, then an error is issued on N. Msg is appended
272
   --  to the restriction failure message.
273
 
274
   procedure Check_SPARK_Restriction (Msg1, Msg2 : String; N : Node_Id);
275
   --  Same as Check_SPARK_Restriction except there is a continuation message
276
   --  Msg2 following the initial message Msg1.
277
 
278
   procedure Check_No_Implicit_Aliasing (Obj : Node_Id);
279
   --  Obj is a node for which Is_Aliased_View is True, which is being used in
280
   --  a context (e.g. 'Access) where no implicit aliasing is allowed if the
281
   --  restriction No_Implicit_Aliasing is set. This procedure checks for the
282
   --  case where the restriction is active and Obj does not meet the required
283
   --  rules for avoiding implicit aliases, and issues a restriction message.
284
 
285
   procedure Check_Implicit_Dynamic_Code_Allowed (N : Node_Id);
286
   --  Tests to see if dynamic code generation (dynamically generated
287
   --  trampolines, in particular) is allowed by the current restrictions
288
   --  settings. This function is called by Gigi when it needs to generate code
289
   --  that generates a trampoline. If not allowed, an error message is posted
290
   --  on the node given as argument.
291
 
292
   procedure Check_No_Implicit_Heap_Alloc (N : Node_Id);
293
   --  Equivalent to Check_Restriction (No_Implicit_Heap_Allocations, N).
294
   --  Provided for easy use by back end, which has to check this restriction.
295
 
296
   procedure Check_Obsolescent_2005_Entity (E : Entity_Id; N : Node_Id);
297
   --  This routine checks if the entity E is one of the obsolescent entries
298
   --  in Ada.Characters.Handling in Ada 2005 and No_Obsolescent_Features
299
   --  restriction is active. If so an appropriate message is given. N is
300
   --  the node on which the message is to be placed. It's a bit kludgy to
301
   --  have this highly specialized routine rather than some wonderful general
302
   --  mechanism (e.g. a special pragma) to handle this case, but there are
303
   --  only six cases, and it is not worth the effort to do something general.
304
 
305
   procedure Check_Wide_Character_Restriction (E : Entity_Id; N : Node_Id);
306
   --  This procedure checks if the No_Wide_Character restriction is active,
307
   --  and if so, if N Comes_From_Source, and the root type of E is one of
308
   --  [Wide_]Wide_Character or [Wide_]Wide_String, then the restriction
309
   --  violation is recorded, and an appropriate message given.
310
 
311
   function Get_Restriction_Id
312
     (N : Name_Id) return Restriction_Id;
313
   --  Given an identifier name, determines if it is a valid restriction
314
   --  identifier, and if so returns the corresponding Restriction_Id value,
315
   --  otherwise returns Not_A_Restriction_Id.
316
 
317
   function Is_In_Hidden_Part_In_SPARK (Loc : Source_Ptr) return Boolean;
318
   --  Determine if given location is covered by a hidden region range in the
319
   --  SPARK hides table.
320
 
321
   function No_Exception_Handlers_Set return Boolean;
322
   --  Test to see if current restrictions settings specify that no exception
323
   --  handlers are present. This function is called by Gigi when it needs to
324
   --  expand an AT END clean up identifier with no exception handler. True
325
   --  will be returned if the configurable run-time is activated, and either
326
   --  of the restrictions No_Exception_Handlers or No_Exception_Propagation is
327
   --  set. In the latter case, the source may contain handlers but they either
328
   --  get converted using the local goto transformation or deleted.
329
 
330
   function No_Exception_Propagation_Active return Boolean;
331
   --  Test to see if current restrictions settings specify that no
332
   --  exception propagation is activated.
333
 
334
   function Process_Restriction_Synonyms (N : Node_Id) return Name_Id;
335
   --  Id is a node whose Chars field contains the name of a restriction.
336
   --  If it is one of synonyms that we allow for historical purposes (for
337
   --  list see System.Rident), then the proper official name is returned.
338
   --  Otherwise the Chars field of the argument is returned unchanged.
339
 
340
   function Restriction_Active (R : All_Restrictions) return Boolean;
341
   pragma Inline (Restriction_Active);
342
   --  Determines if a given restriction is active. This call should only be
343
   --  used where the compiled code depends on whether the restriction is
344
   --  active. Always use Check_Restriction to record a violation. Note that
345
   --  this returns False if we only have a Restriction_Warnings set, since
346
   --  restriction warnings should never affect generated code. If you want
347
   --  to know if a call to Check_Restriction is needed then use the function
348
   --  Restriction_Check_Required instead.
349
 
350
   function Restriction_Check_Required (R : All_Restrictions) return Boolean;
351
   pragma Inline (Restriction_Check_Required);
352
   --  Determines if either a Restriction_Warnings or Restrictions pragma has
353
   --  been given for the specified restriction. If true, then a subsequent
354
   --  call to Check_Restriction is required if the restriction is violated.
355
   --  This must not be used to guard code generation that depends on whether
356
   --  a restriction is active (see Restriction_Active above). Typically it
357
   --  is used to avoid complex code to determine if a restriction is violated,
358
   --  executing this code only if needed.
359
 
360
   function Restricted_Profile return Boolean;
361
   --  Tests if set of restrictions corresponding to Profile (Restricted) is
362
   --  currently in effect (set by pragma Profile, or by an appropriate set of
363
   --  individual Restrictions pragmas). Returns True only if all the required
364
   --  restrictions are set.
365
 
366
   procedure Set_Hidden_Part_In_SPARK (Loc1, Loc2 : Source_Ptr);
367
   --  Insert a new hidden region range in the SPARK hides table
368
 
369
   procedure Set_Profile_Restrictions
370
     (P    : Profile_Name;
371
      N    : Node_Id;
372
      Warn : Boolean);
373
   --  Sets the set of restrictions associated with the given profile name. N
374
   --  is the node of the construct to which error messages are to be attached
375
   --  as required. Warn is set True for the case of Profile_Warnings where the
376
   --  restrictions are set as warnings rather than legality requirements, and
377
   --  is also True for Profile if the Treat_Restrictions_As_Warnings flag is
378
   --  set. It is false for Profile if this flag is not set.
379
 
380
   procedure Set_Restriction
381
     (R : All_Boolean_Restrictions;
382
      N : Node_Id);
383
   --  N is a node (typically a pragma node) that has the effect of setting
384
   --  Boolean restriction R. The restriction is set in Restrictions, and
385
   --  also in Main_Restrictions if this is the main unit.
386
 
387
   procedure Set_Restriction
388
     (R : All_Parameter_Restrictions;
389
      N : Node_Id;
390
      V : Integer);
391
   --  Similar to the above, except that this is used for the case of a
392
   --  parameter restriction, and the corresponding value V is given.
393
 
394
   procedure Set_Restriction_No_Dependence
395
     (Unit    : Node_Id;
396
      Warn    : Boolean;
397
      Profile : Profile_Name := No_Profile);
398
   --  Sets given No_Dependence restriction in table if not there already. Warn
399
   --  is True if from Restriction_Warnings, or for Restrictions if the flag
400
   --  Treat_Restrictions_As_Warnings is set. False if from Restrictions and
401
   --  this flag is not set. Profile is set to a non-default value if the
402
   --  No_Dependence restriction comes from a Profile pragma.
403
 
404
   procedure Set_Restriction_No_Specification_Of_Aspect
405
     (N       : Node_Id;
406
      Warning : Boolean);
407
   --  N is the node id for an identifier from a pragma Restrictions for the
408
   --  No_Specification_Of_Aspect pragma. An error message will be issued if
409
   --  the identifier is not a valid aspect name. Warning is set True for the
410
   --  case of a Restriction_Warnings pragma specifying this restriction and
411
   --  False for a Restrictions pragma specifying this restriction.
412
 
413
   function Tasking_Allowed return Boolean;
414
   pragma Inline (Tasking_Allowed);
415
   --  Tests if tasking operations are allowed by the current restrictions
416
   --  settings. For tasking to be allowed Max_Tasks must be non-zero.
417
 
418
   ----------------------------------------------
419
   -- Handling of Boolean Compilation Switches --
420
   ----------------------------------------------
421
 
422
   --  The following declarations are used for proper saving and restoring of
423
   --  restrictions for separate compilation units. There are two cases:
424
 
425
   --    For partition-wide restrictions, we just let the restrictions pragmas
426
   --    pile up, and we never reset them. We might as well detect what we can
427
   --    at compile time. If e.g. a with'ed unit has a restriction for one of
428
   --    the partition-wide restrictions, then the binder will enforce it on
429
   --    all units in the partition, including the unit with the WITH. Although
430
   --    it would not be wrong to leave this till bind time, we might as well
431
   --    flag it earlier at compile time.
432
 
433
   --    For non-partition-wide restrictions, we have quite a different state
434
   --    of affairs. Here it would be quite wrong to carry a restriction from
435
   --    a with'ed unit to another with'ed unit, or from a package spec to the
436
   --    package body. This means that we have to reset these non-partition
437
   --    wide restrictions at the start of each separate compilation unit. For
438
   --    units in the extended main program, we need to reset them all to the
439
   --    values set by the configuration pragma file(s). For units not in the
440
   --    extended main program, e.g. with'ed units, we might as well reset all
441
   --    of these restrictions to off (False). The actual initial values will
442
   --    be taken from the config files active when those units are compiled
443
   --    as main units.
444
 
445
   type Save_Cunit_Boolean_Restrictions is private;
446
   --  Type used for saving and restoring compilation unit restrictions.
447
 
448
   function Cunit_Boolean_Restrictions_Save
449
     return Save_Cunit_Boolean_Restrictions;
450
   --  This function saves the compilation unit restriction settings, leaving
451
   --  then unchanged. This is used e.g. at the start of processing a context
452
   --  clause, so that the main unit restrictions can be restored after all
453
   --  the with'ed units have been processed.
454
 
455
   procedure Cunit_Boolean_Restrictions_Restore
456
     (R : Save_Cunit_Boolean_Restrictions);
457
   --  This is the corresponding restore procedure to restore restrictions
458
   --  previously saved by Cunit_Boolean_Restrictions_Save. However it does
459
   --  not reset No_Elaboration_Code, this stays set if it was set before
460
   --  the call, and also if it is set before the call, then the Config
461
   --  setting is also updated to include this restriction. This is what
462
   --  implements the special handling of No_Elaboration_Code.
463
 
464
   procedure Save_Config_Cunit_Boolean_Restrictions;
465
   --  This saves the current compilation unit restrictions in an internal
466
   --  variable, and leaves them unchanged. This is called immediately after
467
   --  processing the configuration file pragmas, to record the restrictions
468
   --  set by these configuration file pragmas.
469
 
470
   procedure Restore_Config_Cunit_Boolean_Restrictions;
471
   --  This restores the value saved by the previous call to save config values
472
   --  saved by Save_Config_Cunit_Boolean_Restrictions. It is called at the
473
   --  start of processing a new unit that is part of the main sources (e.g.
474
   --  a package spec when the main unit is a package body).
475
 
476
   procedure Reset_Cunit_Boolean_Restrictions;
477
   --  Turns off all non-partition-wide boolean restrictions
478
 
479
   procedure Add_To_Config_Boolean_Restrictions (R : Restriction_Id);
480
   --  Add specified restriction to stored configuration boolean restrictions.
481
   --  This is used for handling the special case of No_Elaboration_Code.
482
 
483
private
484
   type Save_Cunit_Boolean_Restrictions is
485
     array (Cunit_Boolean_Restrictions) of Boolean;
486
   --  Type used for saving and restoring compilation unit restrictions.
487
   --  See Compilation_Unit_Restrictions_[Save|Restore] subprograms.
488
 
489
end Restrict;

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.