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

Subversion Repositories openrisc

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

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
--                             E X P _ U T I L                              --
6
--                                                                          --
7
--                                 S p e c                                  --
8
--                                                                          --
9
--          Copyright (C) 1992-2012, 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
--  Package containing utility procedures used throughout the expander
27
 
28
with Exp_Tss; use Exp_Tss;
29
with Namet;   use Namet;
30
with Rtsfind; use Rtsfind;
31
with Sinfo;   use Sinfo;
32
with Types;   use Types;
33
with Uintp;   use Uintp;
34
 
35
package Exp_Util is
36
 
37
   -----------------------------------------------
38
   -- Handling of Actions Associated with Nodes --
39
   -----------------------------------------------
40
 
41
   --  The evaluation of certain expression nodes involves the elaboration
42
   --  of associated types and other declarations, and the execution of
43
   --  statement sequences. Expansion routines generating such actions must
44
   --  find an appropriate place in the tree to hang the actions so that
45
   --  they will be evaluated at the appropriate point.
46
 
47
   --  Some cases are simple:
48
 
49
   --    For an expression occurring in a simple statement that is in a list
50
   --    of statements, the actions are simply inserted into the list before
51
   --    the associated statement.
52
 
53
   --    For an expression occurring in a declaration (declarations always
54
   --    appear in lists), the actions are similarly inserted into the list
55
   --    just before the associated declaration.
56
 
57
   --  The following special cases arise:
58
 
59
   --    For actions associated with the right operand of a short circuit
60
   --    form, the actions are first stored in the short circuit form node
61
   --    in the Actions field. The expansion of these forms subsequently
62
   --    expands the short circuit forms into if statements which can then
63
   --    be moved as described above.
64
 
65
   --    For actions appearing in the Condition expression of a while loop,
66
   --    or an elsif clause, the actions are similarly temporarily stored in
67
   --    in the node (N_Elsif_Part or N_Iteration_Scheme) associated with
68
   --    the expression using the Condition_Actions field. Subsequently, the
69
   --    expansion of these nodes rewrites the control structures involved to
70
   --    reposition the actions in normal statement sequence.
71
 
72
   --    For actions appearing in the then or else expression of a conditional
73
   --    expression, these actions are similarly placed in the node, using the
74
   --    Then_Actions or Else_Actions field as appropriate. Once again the
75
   --    expansion of the N_Conditional_Expression node rewrites the node so
76
   --    that the actions can be normally positioned.
77
 
78
   --  Basically what we do is to climb up to the tree looking for the
79
   --  proper insertion point, as described by one of the above cases,
80
   --  and then insert the appropriate action or actions.
81
 
82
   --  Note if more than one insert call is made specifying the same
83
   --  Assoc_Node, then the actions are elaborated in the order of the
84
   --  calls, and this guarantee is preserved for the special cases above.
85
 
86
   procedure Insert_Action
87
     (Assoc_Node : Node_Id;
88
      Ins_Action : Node_Id);
89
   --  Insert the action Ins_Action at the appropriate point as described
90
   --  above. The action is analyzed using the default checks after it is
91
   --  inserted. Assoc_Node is the node with which the action is associated.
92
 
93
   procedure Insert_Action
94
     (Assoc_Node : Node_Id;
95
      Ins_Action : Node_Id;
96
      Suppress   : Check_Id);
97
   --  Insert the action Ins_Action at the appropriate point as described
98
   --  above. The action is analyzed using the default checks as modified
99
   --  by the given Suppress argument after it is inserted. Assoc_Node is
100
   --  the node with which the action is associated.
101
 
102
   procedure Insert_Actions
103
     (Assoc_Node  : Node_Id;
104
      Ins_Actions : List_Id);
105
   --  Insert the list of action Ins_Actions at the appropriate point as
106
   --  described above. The actions are analyzed using the default checks
107
   --  after they are inserted. Assoc_Node is the node with which the actions
108
   --  are associated. Ins_Actions may be No_List, in which case the call has
109
   --  no effect.
110
 
111
   procedure Insert_Actions
112
     (Assoc_Node  : Node_Id;
113
      Ins_Actions : List_Id;
114
      Suppress    : Check_Id);
115
   --  Insert the list of action Ins_Actions at the appropriate point as
116
   --  described above. The actions are analyzed using the default checks
117
   --  as modified by the given Suppress argument after they are inserted.
118
   --  Assoc_Node is the node with which the actions are associated.
119
   --  Ins_Actions may be No_List, in which case the call has no effect.
120
 
121
   procedure Insert_Action_After
122
     (Assoc_Node : Node_Id;
123
      Ins_Action : Node_Id);
124
   --  Assoc_Node must be a node in a list. Same as Insert_Action but the
125
   --  action will be inserted after N in a manner that is compatible with
126
   --  the transient scope mechanism.
127
 
128
   procedure Insert_Actions_After
129
     (Assoc_Node  : Node_Id;
130
      Ins_Actions : List_Id);
131
   --  Assoc_Node must be a node in a list. Same as Insert_Actions but
132
   --  actions will be inserted after N in a manner that is compatible with
133
   --  the transient scope mechanism. This procedure must be used instead
134
   --  of Insert_List_After if Assoc_Node may be in a transient scope.
135
   --
136
   --  Implementation limitation: Assoc_Node must be a statement. We can
137
   --  generalize to expressions if there is a need but this is tricky to
138
   --  implement because of short-circuits (among other things).???
139
 
140
   procedure Insert_Library_Level_Action (N : Node_Id);
141
   --  This procedure inserts and analyzes the node N as an action at the
142
   --  library level for the current unit (i.e. it is attached to the
143
   --  Actions field of the N_Compilation_Aux node for the main unit).
144
 
145
   procedure Insert_Library_Level_Actions (L : List_Id);
146
   --  Similar, but inserts a list of actions
147
 
148
   -----------------------
149
   -- Other Subprograms --
150
   -----------------------
151
 
152
   procedure Activate_Atomic_Synchronization (N : Node_Id);
153
   --  N is a node for which atomic synchronization may be required (it is
154
   --  either an identifier, expanded name, or selected/indexed component or
155
   --  an explicit dereference). The caller has checked the basic conditions
156
   --  (atomic variable appearing and Atomic_Sync not disabled). This function
157
   --  checks if atomic synchronization is required and if so sets the flag
158
   --  and if appropriate generates a warning (in -gnatw.n mode).
159
 
160
   procedure Adjust_Condition (N : Node_Id);
161
   --  The node N is an expression whose root-type is Boolean, and which
162
   --  represents a boolean value used as a condition (i.e. a True/False
163
   --  value). This routine handles the case of C and Fortran convention
164
   --  boolean types, which have zero/non-zero semantics rather than the normal
165
   --  0/1 semantics, and also the case of an enumeration rep clause that
166
   --  specifies a non-standard representation. On return, node N always has
167
   --  the type Standard.Boolean, with a value that is a standard Boolean
168
   --  values of 0/1 for False/True. This procedure is used in two situations.
169
   --  First, the processing for a condition field always calls
170
   --  Adjust_Condition, so that the boolean value presented to the backend is
171
   --  a standard value. Second, for the code for boolean operations such as
172
   --  AND, Adjust_Condition is called on both operands, and then the operation
173
   --  is done in the domain of Standard_Boolean, then Adjust_Result_Type is
174
   --  called on the result to possibly reset the original type. This procedure
175
   --  also takes care of validity checking if Validity_Checks = Tests.
176
 
177
   procedure Adjust_Result_Type (N : Node_Id; T : Entity_Id);
178
   --  The processing of boolean operations like AND uses the procedure
179
   --  Adjust_Condition so that it can operate on Standard.Boolean, which is
180
   --  the only boolean type on which the backend needs to be able to implement
181
   --  such operators. This means that the result is also of type
182
   --  Standard.Boolean. In general the type must be reset back to the original
183
   --  type to get proper semantics, and that is the purpose of this procedure.
184
   --  N is the node (of type Standard.Boolean), and T is the desired type. As
185
   --  an optimization, this procedure leaves the type as Standard.Boolean in
186
   --  contexts where this is permissible (in particular for Condition fields,
187
   --  and for operands of other logical operations higher up the tree). The
188
   --  call to this procedure is completely ignored if the argument N is not of
189
   --  type Boolean.
190
 
191
   procedure Append_Freeze_Action (T : Entity_Id; N : Node_Id);
192
   --  Add a new freeze action for the given type. The freeze action is
193
   --  attached to the freeze node for the type. Actions will be elaborated in
194
   --  the order in which they are added. Note that the added node is not
195
   --  analyzed. The analyze call is found in Exp_Ch13.Expand_N_Freeze_Entity.
196
 
197
   procedure Append_Freeze_Actions (T : Entity_Id; L : List_Id);
198
   --  Adds the given list of freeze actions (declarations or statements) for
199
   --  the given type. The freeze actions are attached to the freeze node for
200
   --  the type. Actions will be elaborated in the order in which they are
201
   --  added, and the actions within the list will be elaborated in list order.
202
   --  Note that the added nodes are not analyzed. The analyze call is found in
203
   --  Exp_Ch13.Expand_N_Freeze_Entity.
204
 
205
   procedure Build_Allocate_Deallocate_Proc
206
     (N           : Node_Id;
207
      Is_Allocate : Boolean);
208
   --  Create a custom Allocate/Deallocate to be associated with an allocation
209
   --  or deallocation:
210
   --
211
   --    1) controlled objects
212
   --    2) class-wide objects
213
   --    3) any kind of object on a subpool
214
   --
215
   --  N must be an allocator or the declaration of a temporary variable which
216
   --  represents the expression of the original allocator node, otherwise N
217
   --  must be a free statement. If flag Is_Allocate is set, the generated
218
   --  routine is allocate, deallocate otherwise.
219
 
220
   function Build_Runtime_Call (Loc : Source_Ptr; RE : RE_Id) return Node_Id;
221
   --  Build an N_Procedure_Call_Statement calling the given runtime entity.
222
   --  The call has no parameters. The first argument provides the location
223
   --  information for the tree and for error messages. The call node is not
224
   --  analyzed on return, the caller is responsible for analyzing it.
225
 
226
   function Build_Task_Image_Decls
227
     (Loc          : Source_Ptr;
228
      Id_Ref       : Node_Id;
229
      A_Type       : Entity_Id;
230
      In_Init_Proc : Boolean := False) return List_Id;
231
   --  Build declaration for a variable that holds an identifying string to be
232
   --  used as a task name. Id_Ref is an identifier if the task is a variable,
233
   --  and a selected or indexed component if the task is component of an
234
   --  object. If it is an indexed component, A_Type is the corresponding array
235
   --  type. Its index types are used to build the string as an image of the
236
   --  index values. For composite types, the result includes two declarations:
237
   --  one for a generated function that computes the image without using
238
   --  concatenation, and one for the variable that holds the result.
239
   --
240
   --  If In_Init_Proc is true, the call is part of the initialization of
241
   --  a component of a composite type, and the enclosing initialization
242
   --  procedure must be flagged as using the secondary stack. If In_Init_Proc
243
   --  is false, the call is for a stand-alone object, and the generated
244
   --  function itself must do its own cleanups.
245
 
246
   function Component_May_Be_Bit_Aligned (Comp : Entity_Id) return Boolean;
247
   --  This function is in charge of detecting record components that may
248
   --  cause trouble in the back end if an attempt is made to assign the
249
   --  component. The back end can handle such assignments with no problem if
250
   --  the components involved are small (64-bits or less) records or scalar
251
   --  items (including bit-packed arrays represented with modular types) or
252
   --  are both aligned on a byte boundary (starting on a byte boundary, and
253
   --  occupying an integral number of bytes).
254
   --
255
   --  However, problems arise for records larger than 64 bits, or for arrays
256
   --  (other than bit-packed arrays represented with a modular type) if the
257
   --  component starts on a non-byte boundary, or does not occupy an integral
258
   --  number of bytes (i.e. there are some bits possibly shared with fields
259
   --  at the start or beginning of the component). The back end cannot handle
260
   --  loading and storing such components in a single operation.
261
   --
262
   --  This function is used to detect the troublesome situation. it is
263
   --  conservative in the sense that it produces True unless it knows for
264
   --  sure that the component is safe (as outlined in the first paragraph
265
   --  above). The code generation for record and array assignment checks for
266
   --  trouble using this function, and if so the assignment is generated
267
   --  component-wise, which the back end is required to handle correctly.
268
   --
269
   --  Note that in GNAT 3, the back end will reject such components anyway,
270
   --  so the hard work in checking for this case is wasted in GNAT 3, but
271
   --  it is harmless, so it is easier to do it in all cases, rather than
272
   --  conditionalize it in GNAT 5 or beyond.
273
 
274
   procedure Convert_To_Actual_Subtype (Exp : Node_Id);
275
   --  The Etype of an expression is the nominal type of the expression,
276
   --  not the actual subtype. Often these are the same, but not always.
277
   --  For example, a reference to a formal of unconstrained type has the
278
   --  unconstrained type as its Etype, but the actual subtype is obtained by
279
   --  applying the actual bounds. This routine is given an expression, Exp,
280
   --  and (if necessary), replaces it using Rewrite, with a conversion to
281
   --  the actual subtype, building the actual subtype if necessary. If the
282
   --  expression is already of the requested type, then it is unchanged.
283
 
284
   function Corresponding_Runtime_Package (Typ : Entity_Id) return RTU_Id;
285
   --  Return the id of the runtime package that will provide support for
286
   --  concurrent type Typ. Currently only protected types are supported,
287
   --  and the returned value is one of the following:
288
   --    System_Tasking_Protected_Objects
289
   --    System_Tasking_Protected_Objects_Entries
290
   --    System_Tasking_Protected_Objects_Single_Entry
291
 
292
   function Current_Sem_Unit_Declarations return List_Id;
293
   --  Return the place where it is fine to insert declarations for the
294
   --  current semantic unit. If the unit is a package body, return the
295
   --  visible declarations of the corresponding spec. For RCI stubs, this
296
   --  is necessary because the point at which they are generated may not
297
   --  be the earliest point at which they are used.
298
 
299
   function Duplicate_Subexpr
300
     (Exp      : Node_Id;
301
      Name_Req : Boolean := False) return Node_Id;
302
   --  Given the node for a subexpression, this function makes a logical copy
303
   --  of the subexpression, and returns it. This is intended for use when the
304
   --  expansion of an expression needs to repeat part of it. For example,
305
   --  replacing a**2 by a*a requires two references to a which may be a
306
   --  complex subexpression. Duplicate_Subexpr guarantees not to duplicate
307
   --  side effects. If necessary, it generates actions to save the expression
308
   --  value in a temporary, inserting these actions into the tree using
309
   --  Insert_Actions with Exp as the insertion location. The original
310
   --  expression and the returned result then become references to this saved
311
   --  value. Exp must be analyzed on entry. On return, Exp is analyzed, but
312
   --  the caller is responsible for analyzing the returned copy after it is
313
   --  attached to the tree. The Name_Req flag is set to ensure that the result
314
   --  is suitable for use in a context requiring name (e.g. the prefix of an
315
   --  attribute reference).
316
   --
317
   --  Note that if there are any run time checks in Exp, these same checks
318
   --  will be duplicated in the returned duplicated expression. The two
319
   --  following functions allow this behavior to be modified.
320
 
321
   function Duplicate_Subexpr_No_Checks
322
     (Exp      : Node_Id;
323
      Name_Req : Boolean := False) return Node_Id;
324
   --  Identical in effect to Duplicate_Subexpr, except that Remove_Checks
325
   --  is called on the result, so that the duplicated expression does not
326
   --  include checks. This is appropriate for use when Exp, the original
327
   --  expression is unconditionally elaborated before the duplicated
328
   --  expression, so that there is no need to repeat any checks.
329
 
330
   function Duplicate_Subexpr_Move_Checks
331
     (Exp      : Node_Id;
332
      Name_Req : Boolean := False) return Node_Id;
333
   --  Identical in effect to Duplicate_Subexpr, except that Remove_Checks is
334
   --  called on Exp after the duplication is complete, so that the original
335
   --  expression does not include checks. In this case the result returned
336
   --  (the duplicated expression) will retain the original checks. This is
337
   --  appropriate for use when the duplicated expression is sure to be
338
   --  elaborated before the original expression Exp, so that there is no need
339
   --  to repeat the checks.
340
 
341
   procedure Ensure_Defined (Typ : Entity_Id; N : Node_Id);
342
   --  This procedure ensures that type referenced by Typ is defined. For the
343
   --  case of a type other than an Itype, nothing needs to be done, since
344
   --  all such types have declaration nodes. For Itypes, an N_Itype_Reference
345
   --  node is generated and inserted at the given node N. This is typically
346
   --  used to ensure that an Itype is properly defined outside a conditional
347
   --  construct when it is referenced in more than one branch.
348
 
349
   function Entry_Names_OK return Boolean;
350
   --  Determine whether it is appropriate to dynamically allocate strings
351
   --  which represent entry [family member] names. These strings are created
352
   --  by the compiler and used by GDB.
353
 
354
   procedure Evaluate_Name (Nam : Node_Id);
355
   --  Remove the all side effects from a name which appears as part of an
356
   --  object renaming declaration. More comments are needed here that explain
357
   --  how this differs from Force_Evaluation and Remove_Side_Effects ???
358
 
359
   procedure Evolve_And_Then (Cond : in out Node_Id; Cond1 : Node_Id);
360
   --  Rewrites Cond with the expression: Cond and then Cond1. If Cond is
361
   --  Empty, then simply returns Cond1 (this allows the use of Empty to
362
   --  initialize a series of checks evolved by this routine, with a final
363
   --  result of Empty indicating that no checks were required). The Sloc field
364
   --  of the constructed N_And_Then node is copied from Cond1.
365
 
366
   procedure Evolve_Or_Else (Cond : in out Node_Id; Cond1 : Node_Id);
367
   --  Rewrites Cond with the expression: Cond or else Cond1. If Cond is Empty,
368
   --  then simply returns Cond1 (this allows the use of Empty to initialize a
369
   --  series of checks evolved by this routine, with a final result of Empty
370
   --  indicating that no checks were required). The Sloc field of the
371
   --  constructed N_Or_Else node is copied from Cond1.
372
 
373
   procedure Expand_Subtype_From_Expr
374
     (N             : Node_Id;
375
      Unc_Type      : Entity_Id;
376
      Subtype_Indic : Node_Id;
377
      Exp           : Node_Id);
378
   --  Build a constrained subtype from the initial value in object
379
   --  declarations and/or allocations when the type is indefinite (including
380
   --  class-wide).
381
 
382
   function Find_Init_Call
383
     (Var        : Entity_Id;
384
      Rep_Clause : Node_Id) return Node_Id;
385
   --  Look for init_proc call for variable Var, either among declarations
386
   --  between that of Var and a subsequent Rep_Clause applying to Var, or
387
   --  in the list of freeze actions associated with Var, and if found, return
388
   --  that call node.
389
 
390
   function Find_Interface_ADT
391
     (T     : Entity_Id;
392
      Iface : Entity_Id) return Elmt_Id;
393
   --  Ada 2005 (AI-251): Given a type T implementing the interface Iface,
394
   --  return the element of Access_Disp_Table containing the tag of the
395
   --  interface.
396
 
397
   function Find_Interface_Tag
398
     (T     : Entity_Id;
399
      Iface : Entity_Id) return Entity_Id;
400
   --  Ada 2005 (AI-251): Given a type T implementing the interface Iface,
401
   --  return the record component containing the tag of Iface.
402
 
403
   function Find_Prim_Op (T : Entity_Id; Name : Name_Id) return Entity_Id;
404
   --  Find the first primitive operation of type T whose name is 'Name'.
405
   --  This function allows the use of a primitive operation which is not
406
   --  directly visible. If T is a class wide type, then the reference is
407
   --  to an operation of the corresponding root type. Raises Program_Error
408
   --  exception if no primitive operation is found. This is normally an
409
   --  internal error, but in some cases is an expected consequence of
410
   --  illegalities elsewhere.
411
 
412
   function Find_Prim_Op
413
     (T    : Entity_Id;
414
      Name : TSS_Name_Type) return Entity_Id;
415
   --  Find the first primitive operation of type T whose name has the form
416
   --  indicated by the name parameter (i.e. is a type support subprogram
417
   --  with the indicated suffix). This function allows use of a primitive
418
   --  operation which is not directly visible. If T is a class wide type,
419
   --  then the reference is to an operation of the corresponding root type.
420
   --  Raises Program_Error exception if no primitive operation is found.
421
   --  This is normally an internal error, but in some cases is an expected
422
   --  consequence of illegalities elsewhere.
423
 
424
   function Find_Protection_Object (Scop : Entity_Id) return Entity_Id;
425
   --  Traverse the scope stack starting from Scop and look for an entry,
426
   --  entry family, or a subprogram that has a Protection_Object and return
427
   --  it. Raises Program_Error if no such entity is found since the context
428
   --  in which this routine is invoked should always have a protection
429
   --  object.
430
 
431
   function Find_Protection_Type (Conc_Typ : Entity_Id) return Entity_Id;
432
   --  Given a protected type or its corresponding record, find the type of
433
   --  field _object.
434
 
435
   procedure Force_Evaluation
436
     (Exp      : Node_Id;
437
      Name_Req : Boolean := False);
438
   --  Force the evaluation of the expression right away. Similar behavior
439
   --  to Remove_Side_Effects when Variable_Ref is set to TRUE. That is to
440
   --  say, it removes the side-effects and captures the values of the
441
   --  variables. Remove_Side_Effects guarantees that multiple evaluations
442
   --  of the same expression won't generate multiple side effects, whereas
443
   --  Force_Evaluation further guarantees that all evaluations will yield
444
   --  the same result.
445
 
446
   function Fully_Qualified_Name_String (E : Entity_Id) return String_Id;
447
   --  Generates the string literal corresponding to the fully qualified name
448
   --  of entity E with an ASCII.NUL appended at the end of the name.
449
 
450
   procedure Generate_Poll_Call (N : Node_Id);
451
   --  If polling is active, then a call to the Poll routine is built,
452
   --  and then inserted before the given node N and analyzed.
453
 
454
   procedure Get_Current_Value_Condition
455
     (Var : Node_Id;
456
      Op  : out Node_Kind;
457
      Val : out Node_Id);
458
   --  This routine processes the Current_Value field of the variable Var. If
459
   --  the Current_Value field is null or if it represents a known value, then
460
   --  on return Cond is set to N_Empty, and Val is set to Empty.
461
   --
462
   --  The other case is when Current_Value points to an N_If_Statement or an
463
   --  N_Elsif_Part or a N_Iteration_Scheme node (see description in Einfo for
464
   --  exact details). In this case, Get_Current_Condition digs out the
465
   --  condition, and then checks if the condition is known false, known true,
466
   --  or not known at all. In the first two cases, Get_Current_Condition will
467
   --  return with Op set to the appropriate conditional operator (inverted if
468
   --  the condition is known false), and Val set to the constant value. If the
469
   --  condition is not known, then Op and Val are set for the empty case
470
   --  (N_Empty and Empty).
471
   --
472
   --  The check for whether the condition is true/false unknown depends
473
   --  on the case:
474
   --
475
   --     For an IF, the condition is known true in the THEN part, known false
476
   --     in any ELSIF or ELSE part, and not known outside the IF statement in
477
   --     question.
478
   --
479
   --     For an ELSIF, the condition is known true in the ELSIF part, known
480
   --     FALSE in any subsequent ELSIF, or ELSE part, and not known before the
481
   --     ELSIF, or after the end of the IF statement.
482
   --
483
   --  The caller can use this result to determine the value (for the case of
484
   --  N_Op_Eq), or to determine the result of some other test in other cases
485
   --  (e.g. no access check required if N_Op_Ne Null).
486
 
487
   function Get_Stream_Size (E : Entity_Id) return Uint;
488
   --  Return the stream size value of the subtype E
489
 
490
   function Has_Access_Constraint (E : Entity_Id) return Boolean;
491
   --  Given object or type E, determine if a discriminant is of an access type
492
 
493
   function Has_Following_Address_Clause (D : Node_Id) return Boolean;
494
   --  D is the node for an object declaration. This function searches the
495
   --  current declarative part to look for an address clause for the object
496
   --  being declared, and returns True if one is found.
497
 
498
   function Homonym_Number (Subp : Entity_Id) return Nat;
499
   --  Here subp is the entity for a subprogram. This routine returns the
500
   --  homonym number used to disambiguate overloaded subprograms in the same
501
   --  scope (the number is used as part of constructed names to make sure that
502
   --  they are unique). The number is the ordinal position on the Homonym
503
   --  chain, counting only entries in the current scope. If an entity is not
504
   --  overloaded, the returned number will be one.
505
 
506
   function Inside_Init_Proc return Boolean;
507
   --  Returns True if current scope is within an init proc
508
 
509
   function In_Library_Level_Package_Body (Id : Entity_Id) return Boolean;
510
   --  Given an arbitrary entity, determine whether it appears at the library
511
   --  level of a package body.
512
 
513
   function In_Unconditional_Context (Node : Node_Id) return Boolean;
514
   --  Node is the node for a statement or a component of a statement. This
515
   --  function determines if the statement appears in a context that is
516
   --  unconditionally executed, i.e. it is not within a loop or a conditional
517
   --  or a case statement etc.
518
 
519
   function Is_All_Null_Statements (L : List_Id) return Boolean;
520
   --  Return True if all the items of the list are N_Null_Statement nodes.
521
   --  False otherwise. True for an empty list. It is an error to call this
522
   --  routine with No_List as the argument.
523
 
524
   function Is_Displacement_Of_Ctrl_Function_Result
525
     (Obj_Id : Entity_Id) return Boolean;
526
   --  Determine whether Obj_Id is a source object that has been initialized by
527
   --  a controlled function call later rewritten as a class-wide conversion of
528
   --  Ada.Tags.Displace.
529
 
530
   function Is_Finalizable_Transient
531
     (Decl     : Node_Id;
532
      Rel_Node : Node_Id) return Boolean;
533
   --  Determine whether declaration Decl denotes a controlled transient which
534
   --  should be finalized. Rel_Node is the related context. Even though some
535
   --  transient are controlled, they may act as renamings of other objects or
536
   --  function calls.
537
 
538
   function Is_Fully_Repped_Tagged_Type (T : Entity_Id) return Boolean;
539
   --  Tests given type T, and returns True if T is a non-discriminated tagged
540
   --  type which has a record representation clause that specifies the layout
541
   --  of all the components, including recursively components in all parent
542
   --  types. We exclude discriminated types for convenience, it is extremely
543
   --  unlikely that the special processing associated with the use of this
544
   --  routine is useful for the case of a discriminated type, and testing for
545
   --  component overlap would be a pain.
546
 
547
   function Is_Library_Level_Tagged_Type (Typ : Entity_Id) return Boolean;
548
   --  Return True if Typ is a library level tagged type. Currently we use
549
   --  this information to build statically allocated dispatch tables.
550
 
551
   function Is_Null_Access_BIP_Func_Call (Expr : Node_Id) return Boolean;
552
   --  Determine whether node Expr denotes a build-in-place function call with
553
   --  a value of "null" for extra formal BIPaccess.
554
 
555
   function Is_Non_BIP_Func_Call (Expr : Node_Id) return Boolean;
556
   --  Determine whether node Expr denotes a non build-in-place function call
557
 
558
   function Is_Ref_To_Bit_Packed_Array (N : Node_Id) return Boolean;
559
   --  Determine whether the node P is a reference to a bit packed array, i.e.
560
   --  whether the designated object is a component of a bit packed array, or a
561
   --  subcomponent of such a component. If so, then all subscripts in P are
562
   --  evaluated with a call to Force_Evaluation, and True is returned.
563
   --  Otherwise False is returned, and P is not affected.
564
 
565
   function Is_Ref_To_Bit_Packed_Slice (N : Node_Id) return Boolean;
566
   --  Determine whether the node P is a reference to a bit packed slice, i.e.
567
   --  whether the designated object is bit packed slice or a component of a
568
   --  bit packed slice. Return True if so.
569
 
570
   function Is_Related_To_Func_Return (Id : Entity_Id) return Boolean;
571
   --  Determine whether object Id is related to an expanded return statement.
572
   --  The case concerned is "return Id.all;".
573
 
574
   function Is_Possibly_Unaligned_Slice (N : Node_Id) return Boolean;
575
   --  Determine whether the node P is a slice of an array where the slice
576
   --  result may cause alignment problems because it has an alignment that
577
   --  is not compatible with the type. Return True if so.
578
 
579
   function Is_Possibly_Unaligned_Object (N : Node_Id) return Boolean;
580
   --  Node N is an object reference. This function returns True if it is
581
   --  possible that the object may not be aligned according to the normal
582
   --  default alignment requirement for its type (e.g. if it appears in a
583
   --  packed record, or as part of a component that has a component clause.)
584
 
585
   function Is_Renamed_Object (N : Node_Id) return Boolean;
586
   --  Returns True if the node N is a renamed object. An expression is
587
   --  considered to be a renamed object if either it is the Name of an object
588
   --  renaming declaration, or is the prefix of a name which is a renamed
589
   --  object. For example, in:
590
   --
591
   --     x : r renames a (1 .. 2) (1);
592
   --
593
   --  We consider that a (1 .. 2) is a renamed object since it is the prefix
594
   --  of the name in the renaming declaration.
595
 
596
   function Is_Tag_To_Class_Wide_Conversion
597
     (Obj_Id : Entity_Id) return Boolean;
598
   --  Determine whether object Obj_Id is the result of a tag-to-class-wide
599
   --  type conversion.
600
 
601
   function Is_Untagged_Derivation (T : Entity_Id) return Boolean;
602
   --  Returns true if type T is not tagged and is a derived type,
603
   --  or is a private type whose completion is such a type.
604
 
605
   function Is_Volatile_Reference (N : Node_Id) return Boolean;
606
   --  Checks if the node N represents a volatile reference, which can be
607
   --  either a direct reference to a variable treated as volatile, or an
608
   --  indexed/selected component where the prefix is treated as volatile,
609
   --  or has Volatile_Components set. A slice of a volatile variable is
610
   --  also volatile.
611
 
612
   function Is_VM_By_Copy_Actual (N : Node_Id) return Boolean;
613
   --  Returns True if we are compiling on VM targets and N is a node that
614
   --  requires pass-by-copy in these targets.
615
 
616
   procedure Kill_Dead_Code (N : Node_Id; Warn : Boolean := False);
617
   --  N represents a node for a section of code that is known to be dead. Any
618
   --  exception handler references and warning messages relating to this code
619
   --  are removed. If Warn is True, a warning will be output at the start of N
620
   --  indicating the deletion of the code. Note that the tree for the deleted
621
   --  code is left intact so that e.g. cross-reference data is still valid.
622
 
623
   procedure Kill_Dead_Code (L : List_Id; Warn : Boolean := False);
624
   --  Like the above procedure, but applies to every element in the given
625
   --  list. If Warn is True, a warning will be output at the start of N
626
   --  indicating the deletion of the code.
627
 
628
   function Known_Non_Negative (Opnd : Node_Id) return Boolean;
629
   --  Given a node for a subexpression, determines if it represents a value
630
   --  that cannot possibly be negative, and if so returns True. A value of
631
   --  False means that it is not known if the value is positive or negative.
632
 
633
   function Known_Non_Null (N : Node_Id) return Boolean;
634
   --  Given a node N for a subexpression of an access type, determines if
635
   --  this subexpression yields a value that is known at compile time to
636
   --  be non-null and returns True if so. Returns False otherwise. It is
637
   --  an error to call this function if N is not of an access type.
638
 
639
   function Known_Null (N : Node_Id) return Boolean;
640
   --  Given a node N for a subexpression of an access type, determines if this
641
   --  subexpression yields a value that is known at compile time to be null
642
   --  and returns True if so. Returns False otherwise. It is an error to call
643
   --  this function if N is not of an access type.
644
 
645
   function Make_Invariant_Call (Expr : Node_Id) return Node_Id;
646
   --  Expr is an object of a type which Has_Invariants set (and which thus
647
   --  also has an Invariant_Procedure set). If invariants are enabled, this
648
   --  function returns a call to the Invariant procedure passing Expr as the
649
   --  argument, and returns it unanalyzed. If invariants are not enabled,
650
   --  returns a null statement.
651
 
652
   function Make_Predicate_Call
653
     (Typ  : Entity_Id;
654
      Expr : Node_Id) return Node_Id;
655
   --  Typ is a type with Predicate_Function set. This routine builds a call to
656
   --  this function passing Expr as the argument, and returns it unanalyzed.
657
 
658
   function Make_Predicate_Check
659
     (Typ  : Entity_Id;
660
      Expr : Node_Id) return Node_Id;
661
   --  Typ is a type with Predicate_Function set. This routine builds a Check
662
   --  pragma whose first argument is Predicate, and the second argument is a
663
   --  call to the this predicate function with Expr as the argument.
664
 
665
   function Make_Subtype_From_Expr
666
     (E       : Node_Id;
667
      Unc_Typ : Entity_Id) return Node_Id;
668
   --  Returns a subtype indication corresponding to the actual type of an
669
   --  expression E. Unc_Typ is an unconstrained array or record, or
670
   --  a classwide type.
671
 
672
   function May_Generate_Large_Temp (Typ : Entity_Id) return Boolean;
673
   --  Determines if the given type, Typ, may require a large temporary of the
674
   --  kind that causes back-end trouble if stack checking is enabled. The
675
   --  result is True only the size of the type is known at compile time and
676
   --  large, where large is defined heuristically by the body of this routine.
677
   --  The purpose of this routine is to help avoid generating troublesome
678
   --  temporaries that interfere with stack checking mechanism. Note that the
679
   --  caller has to check whether stack checking is actually enabled in order
680
   --  to guide the expansion (typically of a function call).
681
 
682
   function Needs_Constant_Address
683
     (Decl : Node_Id;
684
      Typ  : Entity_Id) return Boolean;
685
   --  Check whether the expression in an address clause is restricted to
686
   --  consist of constants, when the object has a non-trivial initialization
687
   --  or is controlled.
688
 
689
   function Needs_Finalization (T : Entity_Id) return Boolean;
690
   --  True if type T is controlled, or has controlled subcomponents. Also
691
   --  True if T is a class-wide type, because some type extension might add
692
   --  controlled subcomponents, except that if pragma Restrictions
693
   --  (No_Finalization) applies, this is False for class-wide types.
694
 
695
   function Non_Limited_Designated_Type (T : Entity_Id) return Entity_Id;
696
   --  An anonymous access type may designate a limited view. Check whether
697
   --  non-limited view is available during expansion, to examine components
698
   --  or other characteristics of the full type.
699
 
700
   function OK_To_Do_Constant_Replacement (E : Entity_Id) return Boolean;
701
   --  This function is used when testing whether or not to replace a reference
702
   --  to entity E by a known constant value. Such replacement must be done
703
   --  only in a scope known to be safe for such replacements. In particular,
704
   --  if we are within a subprogram and the entity E is declared outside the
705
   --  subprogram then we cannot do the replacement, since we do not attempt to
706
   --  trace subprogram call flow. It is also unsafe to replace statically
707
   --  allocated values (since they can be modified outside the scope), and we
708
   --  also inhibit replacement of Volatile or aliased objects since their
709
   --  address might be captured in a way we do not detect. A value of True is
710
   --  returned only if the replacement is safe.
711
 
712
   function Possible_Bit_Aligned_Component (N : Node_Id) return Boolean;
713
   --  This function is used during processing the assignment of a record or
714
   --  indexed component. The argument N is either the left hand or right hand
715
   --  side of an assignment, and this function determines if there is a record
716
   --  component reference where the record may be bit aligned in a manner that
717
   --  causes trouble for the back end (see Component_May_Be_Bit_Aligned for
718
   --  further details).
719
 
720
   procedure Process_Statements_For_Controlled_Objects (N : Node_Id);
721
   --  N is a node which contains a non-handled statement list. Inspect the
722
   --  statements looking for declarations of controlled objects. If at least
723
   --  one such object is found, wrap the statement list in a block.
724
 
725
   procedure Remove_Side_Effects
726
     (Exp          : Node_Id;
727
      Name_Req     : Boolean := False;
728
      Variable_Ref : Boolean := False);
729
   --  Given the node for a subexpression, this function replaces the node if
730
   --  necessary by an equivalent subexpression that is guaranteed to be side
731
   --  effect free. This is done by extracting any actions that could cause
732
   --  side effects, and inserting them using Insert_Actions into the tree to
733
   --  which Exp is attached. Exp must be analyzed and resolved before the call
734
   --  and is analyzed and resolved on return. The Name_Req may only be set to
735
   --  True if Exp has the form of a name, and the effect is to guarantee that
736
   --  any replacement maintains the form of name. If Variable_Ref is set to
737
   --  TRUE, a variable is considered as side effect (used in implementing
738
   --  Force_Evaluation). Note: after call to Remove_Side_Effects, it is safe
739
   --  to call New_Copy_Tree to obtain a copy of the resulting expression.
740
 
741
   function Represented_As_Scalar (T : Entity_Id) return Boolean;
742
   --  Returns True iff the implementation of this type in code generation
743
   --  terms is scalar. This is true for scalars in the Ada sense, and for
744
   --  packed arrays which are represented by a scalar (modular) type.
745
 
746
   function Requires_Cleanup_Actions (N : Node_Id) return Boolean;
747
   --  Given a node N, determine whether its declarative and/or statement list
748
   --  contains one of the following:
749
   --
750
   --    1) controlled objects
751
   --    2) library-level tagged types
752
   --
753
   --  The above cases require special actions on scope exit.
754
 
755
   function Safe_Unchecked_Type_Conversion (Exp : Node_Id) return Boolean;
756
   --  Given the node for an N_Unchecked_Type_Conversion, return True if this
757
   --  is an unchecked conversion that Gigi can handle directly. Otherwise
758
   --  return False if it is one for which the front end must provide a
759
   --  temporary. Note that the node need not be analyzed, and thus the Etype
760
   --  field may not be set, but in that case it must be the case that the
761
   --  Subtype_Mark field of the node is set/analyzed.
762
 
763
   procedure Set_Current_Value_Condition (Cnode : Node_Id);
764
   --  Cnode is N_If_Statement, N_Elsif_Part, or N_Iteration_Scheme (the latter
765
   --  when a WHILE condition is present). This call checks whether Condition
766
   --  (Cnode) has embedded expressions of a form that should result in setting
767
   --  the Current_Value field of one or more entities, and if so sets these
768
   --  fields to point to Cnode.
769
 
770
   procedure Set_Elaboration_Flag (N : Node_Id; Spec_Id : Entity_Id);
771
   --  N is the node for a subprogram or generic body, and Spec_Id is the
772
   --  entity for the corresponding spec. If an elaboration entity is defined,
773
   --  then this procedure generates an assignment statement to set it True,
774
   --  immediately after the body is elaborated. However, no assignment is
775
   --  generated in the case of library level procedures, since the setting of
776
   --  the flag in this case is generated in the binder. We do that so that we
777
   --  can detect cases where this is the only elaboration action that is
778
   --  required.
779
 
780
   procedure Set_Renamed_Subprogram (N : Node_Id; E : Entity_Id);
781
   --  N is an node which is an entity name that represents the name of a
782
   --  renamed subprogram. The node is rewritten to be an identifier that
783
   --  refers directly to the renamed subprogram, given by entity E.
784
 
785
   procedure Silly_Boolean_Array_Not_Test (N : Node_Id; T : Entity_Id);
786
   --  N is the node for a boolean array NOT operation, and T is the type of
787
   --  the array. This routine deals with the silly case where the subtype of
788
   --  the boolean array is False..False or True..True, where it is required
789
   --  that a Constraint_Error exception be raised (RM 4.5.6(6)).
790
 
791
   procedure Silly_Boolean_Array_Xor_Test (N : Node_Id; T : Entity_Id);
792
   --  N is the node for a boolean array XOR operation, and T is the type of
793
   --  the array. This routine deals with the silly case where the subtype of
794
   --  the boolean array is True..True, where a raise of a Constraint_Error
795
   --  exception is required (RM 4.5.6(6)).
796
 
797
   function Target_Has_Fixed_Ops
798
     (Left_Typ   : Entity_Id;
799
      Right_Typ  : Entity_Id;
800
      Result_Typ : Entity_Id) return Boolean;
801
   --  Returns True if and only if the target machine has direct support
802
   --  for fixed-by-fixed multiplications and divisions for the given
803
   --  operand and result types. This is called in package Exp_Fixd to
804
   --  determine whether to expand such operations.
805
 
806
   function Type_May_Have_Bit_Aligned_Components
807
     (Typ : Entity_Id) return Boolean;
808
   --  Determines if Typ is a composite type that has within it (looking down
809
   --  recursively at any subcomponents), a record type which has component
810
   --  that may be bit aligned (see Possible_Bit_Aligned_Component). The result
811
   --  is conservative, in that a result of False is decisive. A result of True
812
   --  means that such a component may or may not be present.
813
 
814
   procedure Wrap_Cleanup_Procedure (N : Node_Id);
815
   --  Given an N_Subprogram_Body node, this procedure adds an Abort_Defer call
816
   --  at the start of the statement sequence, and an Abort_Undefer call at the
817
   --  end of the statement sequence. All cleanup routines (i.e. those that are
818
   --  called from "at end" handlers) must defer abort on entry and undefer
819
   --  abort on exit. Note that it is assumed that the code for the procedure
820
   --  does not contain any return statements which would allow the flow of
821
   --  control to escape doing the undefer call.
822
 
823
private
824
   pragma Inline (Duplicate_Subexpr);
825
   pragma Inline (Force_Evaluation);
826
   pragma Inline (Is_Library_Level_Tagged_Type);
827
end Exp_Util;

powered by: WebSVN 2.1.0

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