Debian Codegraph @

gcc/ada/exp_util.ads

raw
1 ------------------------------------------------------------------------------
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-2025, 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 Einfo.Utils; use Einfo.Utils;
29 with Exp_Tss; use Exp_Tss;
30 with Namet; use Namet;
31 with Rtsfind; use Rtsfind;
32 with Sinfo; use Sinfo;
33 with Sinfo.Nodes; use Sinfo.Nodes;
34 with Snames; use Snames;
35 with Types; use Types;
36 with Uintp; use Uintp;
37
38 package Exp_Util is
39
40 -----------------------------------------------
41 -- Handling of Actions Associated with Nodes --
42 -----------------------------------------------
43
44 -- The evaluation of certain expression nodes involves the elaboration
45 -- of associated types and other declarations, and the execution of
46 -- statement sequences. Expansion routines generating such actions must
47 -- find an appropriate place in the tree to hang the actions so that
48 -- they will be evaluated at the appropriate point.
49
50 -- Some cases are simple:
51
52 -- For an expression occurring in a simple statement that is in a list
53 -- of statements, the actions are simply inserted into the list before
54 -- the associated statement.
55
56 -- For an expression occurring in a declaration the actions are similarly
57 -- inserted into the list just before the associated declaration. (But
58 -- note that although declarations usually appear in lists, they don't
59 -- always; in particular, a library unit declaration does not appear in
60 -- a list, and Insert_Action will crash in that case.)
61
62 -- The following special cases arise:
63
64 -- For actions associated with the right operand of a short circuit
65 -- form, the actions are first stored in the short circuit form node
66 -- in the Actions field. The expansion of these forms subsequently
67 -- expands the short circuit forms into if statements which can then
68 -- be moved as described above.
69
70 -- For actions appearing in the Condition expression of a while loop,
71 -- or an elsif clause, the actions are similarly temporarily stored in
72 -- in the node (N_Elsif_Part or N_Iteration_Scheme) associated with
73 -- the expression using the Condition_Actions field. Subsequently, the
74 -- expansion of these nodes rewrites the control structures involved to
75 -- reposition the actions in normal statement sequence.
76
77 -- For actions appearing in the then or else expression of a conditional
78 -- expression, these actions are similarly placed in the node, using the
79 -- Then_Actions or Else_Actions field as appropriate. Once again the
80 -- expansion of the N_If_Expression node rewrites the node so that the
81 -- actions can be positioned normally.
82
83 -- For actions coming from expansion of the expression in an expression
84 -- with actions node, the action is appended to the list of actions.
85
86 -- Basically what we do is to climb up to the tree looking for the
87 -- proper insertion point, as described by one of the above cases,
88 -- and then insert the appropriate action or actions.
89
90 -- Note if more than one insert call is made specifying the same
91 -- Assoc_Node, then the actions are elaborated in the order of the
92 -- calls, and this guarantee is preserved for the special cases above.
93
94 procedure Insert_Action
95 (Assoc_Node : Node_Id;
96 Ins_Action : Node_Id;
97 Spec_Expr_OK : Boolean := False);
98 -- Insert the action Ins_Action at the appropriate point as described
99 -- above. The action is analyzed using the default checks after it is
100 -- inserted. Assoc_Node is the node with which the action is associated.
101 -- When flag Spec_Expr_OK is set, insertions triggered in the context of
102 -- spec expressions are honored, even though they contradict "Handling
103 -- of Default and Per-Object Expressions".
104
105 procedure Insert_Action
106 (Assoc_Node : Node_Id;
107 Ins_Action : Node_Id;
108 Suppress : Check_Id;
109 Spec_Expr_OK : Boolean := False);
110 -- Insert the action Ins_Action at the appropriate point as described
111 -- above. The action is analyzed using the default checks as modified
112 -- by the given Suppress argument after it is inserted. Assoc_Node is
113 -- the node with which the action is associated. When flag Spec_Expr_OK
114 -- is set, insertions triggered in the context of spec expressions are
115 -- honored, even though they contradict "Handling of Default and Per-
116 -- Object Expressions".
117
118 procedure Insert_Actions
119 (Assoc_Node : Node_Id;
120 Ins_Actions : List_Id;
121 Spec_Expr_OK : Boolean := False);
122 -- Insert the list of action Ins_Actions at the appropriate point as
123 -- described above. The actions are analyzed using the default checks
124 -- after they are inserted. Assoc_Node is the node with which the actions
125 -- are associated. Ins_Actions may be No_List, in which case the call has
126 -- no effect. When flag Spec_Expr_OK is set, insertions triggered in the
127 -- context of spec expressions are honored, even though they contradict
128 -- "Handling of Default and Per-Object Expressions".
129
130 procedure Insert_Actions
131 (Assoc_Node : Node_Id;
132 Ins_Actions : List_Id;
133 Suppress : Check_Id;
134 Spec_Expr_OK : Boolean := False);
135 -- Insert the list of action Ins_Actions at the appropriate point as
136 -- described above. The actions are analyzed using the default checks
137 -- as modified by the given Suppress argument after they are inserted.
138 -- Assoc_Node is the node with which the actions are associated. List
139 -- Ins_Actions may be No_List, in which case the call has no effect.
140 -- When flag Spec_Expr_OK is set, insertions triggered in the context of
141 -- spec expressions are honored, even though they contradict "Handling
142 -- of Default and Per-Object Expressions".
143
144 procedure Insert_Action_After
145 (Assoc_Node : Node_Id;
146 Ins_Action : Node_Id);
147 -- Assoc_Node must be a node in a list. Same as Insert_Action but the
148 -- action will be inserted after N in a manner that is compatible with
149 -- the transient scope mechanism.
150 --
151 -- Note: If several successive calls to Insert_Action_After are made for
152 -- the same node, they will each in turn be inserted just after the node.
153 -- This means they will end up being executed in reverse order. Use the
154 -- call to Insert_Actions_After to insert a list of actions to be executed
155 -- in the sequence in which they are given in the list.
156
157 procedure Insert_Actions_After
158 (Assoc_Node : Node_Id;
159 Ins_Actions : List_Id);
160 -- Assoc_Node must be a node in a list. Same as Insert_Actions but
161 -- actions will be inserted after N in a manner that is compatible with
162 -- the transient scope mechanism. This procedure must be used instead
163 -- of Insert_List_After if Assoc_Node may be in a transient scope.
164 --
165 -- Implementation limitation: Assoc_Node must be a statement. We can
166 -- generalize to expressions if there is a need but this is tricky to
167 -- implement because of short-circuits (among other things).
168
169 procedure Insert_Library_Level_Action (N : Node_Id);
170 -- This procedure inserts and analyzes the node N as an action at the
171 -- library level for the current unit (i.e. it is attached to the
172 -- Actions field of the N_Compilation_Aux node for the main unit).
173
174 procedure Insert_Library_Level_Actions (L : List_Id);
175 -- Similar, but inserts a list of actions
176
177 ------------------------
178 -- Delayed Expansion --
179 ------------------------
180
181 -- The default, bottom-up expansion of expressions is not appropriate for
182 -- some specific situations, either because it would generate problematic
183 -- constructs in the expanded code, for example temporaries of a limited
184 -- type, or because it would generate superfluous copy operations. These
185 -- situations involve either aggregates or conditional expressions (or a
186 -- combination of them) of composite types:
187
188 -- 1. For aggregates, the default expansion model is to instantiate the
189 -- anonymous object where elaboration is performed, in other words to
190 -- create a temporary. This can be directly avoided if the aggregate
191 -- is the initialization expression of an object, but cannot be if the
192 -- aggregate is nested in another aggregate, or else is the dependent
193 -- expression of a conditional expression.
194
195 -- 2. For (most) conditional expressions of composite types, the default
196 -- expansion model is to take 'Unrestricted_Access of their dependent
197 -- expressions and to replace them with the dereference of the access
198 -- value designating the dependent expression chosen by the condition.
199 -- Now taking 'Unrestricted_Access of an expression, for example again
200 -- an aggregate or a function call, forces the creation of a temporary
201 -- to hold the value of the expression.
202
203 -- In these specific situations, it is desirable, if not required, to delay
204 -- the expansion of the expression until after that of the parent construct
205 -- has started or has completed, so that it can drive this expansion in the
206 -- first case or completely rewrite the expression in the second case.
207
208 -- This is achieved by means of the Expansion_Delayed flag that may be set
209 -- on aggregates and conditional expressions: when the above situations are
210 -- recognized, expansion is blocked, the flag is set, and Expand returns
211 -- after setting the Analyzed flag on the expression as usual, which means
212 -- that it is up to the parent construct either to perform the expansion of
213 -- the expression directly (case of nested aggregates), or to reset the
214 -- Analyzed flag on the expression so that Expand can give it another try
215 -- in a modified context (case of conditional expressions).
216
217 procedure Delay_Conditional_Expressions_Between (From, To : Node_Id);
218 -- Mark all the conditional expressions in the tree between From and To
219 -- as having their expansion delayed (From included, To excluded).
220
221 function Is_Delayed_Conditional_Expression (N : Node_Id) return Boolean;
222 -- Returns True if N is a conditional expression whose Expansion_Delayed
223 -- flag is set.
224
225 procedure Unanalyze_Delayed_Conditional_Expression (N : Node_Id);
226 -- Schedule the reanalysis of the delayed conditional expression N
227
228 -----------------------
229 -- Other Subprograms --
230 -----------------------
231
232 procedure Activate_Atomic_Synchronization (N : Node_Id);
233 -- N is a node for which atomic synchronization may be required (it is
234 -- either an identifier, expanded name, or selected/indexed component or
235 -- an explicit dereference). The caller has checked the basic conditions
236 -- (atomic variable appearing and Atomic_Synchronization enabled). This
237 -- function checks if atomic synchronization is required and if so sets
238 -- the flag and (in -gnatw.n mode) generates a warning.
239
240 procedure Adjust_Condition (N : Node_Id);
241 -- The node N is an expression whose root-type is Boolean, and which
242 -- represents a boolean value used as a condition (i.e. a True/False
243 -- value). This routine handles the case of C and Fortran convention
244 -- boolean types, which have zero/non-zero semantics rather than the normal
245 -- 0/1 semantics, and also the case of an enumeration rep clause that
246 -- specifies a non-standard representation. On return, node N always has
247 -- the type Standard.Boolean, with a value that is a standard Boolean
248 -- values of 0/1 for False/True. This procedure is used in two situations.
249 -- First, the processing for a condition field always calls
250 -- Adjust_Condition, so that the boolean value presented to the backend is
251 -- a standard value. Second, for the code for boolean operations such as
252 -- AND, Adjust_Condition is called on both operands, and then the operation
253 -- is done in the domain of Standard_Boolean, then Adjust_Result_Type is
254 -- called on the result to possibly reset the original type. This procedure
255 -- also takes care of validity checking if Validity_Checks = Tests.
256
257 procedure Adjust_Result_Type (N : Node_Id; T : Entity_Id);
258 -- The processing of boolean operations like AND uses the procedure
259 -- Adjust_Condition so that it can operate on Standard.Boolean, which is
260 -- the only boolean type on which the backend needs to be able to implement
261 -- such operators. This means that the result is also of type
262 -- Standard.Boolean. In general the type must be reset back to the original
263 -- type to get proper semantics, and that is the purpose of this procedure.
264 -- N is the node (of type Standard.Boolean), and T is the desired type. As
265 -- an optimization, this procedure leaves the type as Standard.Boolean in
266 -- contexts where this is permissible (in particular for Condition fields,
267 -- and for operands of other logical operations higher up the tree). The
268 -- call to this procedure is completely ignored if the argument N is not of
269 -- type Boolean.
270
271 procedure Append_Freeze_Action (T : Entity_Id; N : Node_Id);
272 -- Add a new freeze action for the given type. The freeze action is
273 -- attached to the freeze node for the type. Actions will be elaborated in
274 -- the order in which they are added. Note that the added node is not
275 -- analyzed. The analyze call is found in Exp_Ch13.Expand_N_Freeze_Entity.
276
277 procedure Append_Freeze_Actions (T : Entity_Id; L : List_Id);
278 -- Adds the given list of freeze actions (declarations or statements) for
279 -- the given type. The freeze actions are attached to the freeze node for
280 -- the type. Actions will be elaborated in the order in which they are
281 -- added, and the actions within the list will be elaborated in list order.
282 -- Note that the added nodes are not analyzed. The analyze call is found in
283 -- Exp_Ch13.Expand_N_Freeze_Entity.
284
285 function Attribute_Constrained_Static_Value (Pref : Node_Id) return Boolean;
286 -- Return the static value of a statically known attribute reference
287 -- Pref'Constrained.
288
289 procedure Build_Allocate_Deallocate_Proc
290 (N : Node_Id;
291 Mark : Node_Id := Empty);
292 -- Create a custom Allocate/Deallocate to be associated with an allocation
293 -- or deallocation for:
294 --
295 -- 1) controlled objects
296 -- 2) class-wide objects
297 -- 3) any kind of objects on a subpool
298 --
299 -- Moreover, for objects that need finalization, generate the attachment
300 -- actions to resp. detachment actions from the appropriate collection.
301 --
302 -- N must be an allocator or the declaration of a temporary initialized by
303 -- an allocator or an assignment of an allocator to a temporary, otherwise
304 -- N must be a free statement of a temporary.
305 --
306 -- Mark must be set to a mark past the initialization of the allocator if
307 -- it is initialized (the allocator itself is OK) or left empty otherwise.
308 -- It is used to determine the place where objects that need finalization
309 -- can be attached to the appropriate collection.
310
311 function Build_Abort_Undefer_Block
312 (Loc : Source_Ptr;
313 Stmts : List_Id;
314 Context : Node_Id) return Node_Id;
315 -- Wrap statements Stmts in a block where the AT END handler contains a
316 -- call to Abort_Undefer_Direct. Context is the node which prompted the
317 -- inlining of the abort undefer routine. Note that this routine does
318 -- not install a call to Abort_Defer.
319
320 procedure Build_Class_Wide_Expression
321 (Pragma_Or_Expr : Node_Id;
322 Subp : Entity_Id;
323 Par_Subp : Entity_Id;
324 Adjust_Sloc : Boolean);
325 -- Build the expression for an inherited class-wide condition. Pragma_Or_
326 -- _Expr is either the pragma constructed from the corresponding aspect of
327 -- the parent subprogram or the class-wide pre/postcondition built from the
328 -- parent, Subp is the overriding operation, and Par_Subp is the overridden
329 -- operation that has the condition. Adjust_Sloc is True when the sloc of
330 -- nodes traversed should be adjusted for the inherited pragma.
331
332 function Build_DIC_Call
333 (Loc : Source_Ptr;
334 Obj_Name : Node_Id;
335 Typ : Entity_Id) return Node_Id;
336 -- Build a call to the DIC procedure for Typ with Obj_Name as the actual
337 -- parameter.
338
339 procedure Build_DIC_Procedure_Body
340 (Typ : Entity_Id;
341 Partial_DIC : Boolean := False);
342 -- Create the body of the procedure which verifies the assertion expression
343 -- of pragma Default_Initial_Condition at run time. Partial_DIC indicates
344 -- that a partial DIC-checking procedure body should be built, for checking
345 -- a DIC associated with the type's partial view, and which will be called
346 -- by the main DIC procedure.
347
348 procedure Build_DIC_Procedure_Declaration
349 (Typ : Entity_Id;
350 Partial_DIC : Boolean := False);
351 -- Create the declaration of the procedure which verifies the assertion
352 -- expression of pragma Default_Initial_Condition at run time. Partial_DIC
353 -- indicates that a partial DIC-checking procedure should be declared,
354 -- for checking a DIC associated with the type's partial view, and which
355 -- will be called by the main DIC procedure.
356
357 procedure Build_Invariant_Procedure_Body
358 (Typ : Entity_Id;
359 Partial_Invariant : Boolean := False);
360 -- Create the body of the procedure which verifies the invariants of type
361 -- Typ at runtime. Flag Partial_Invariant should be set when Typ denotes a
362 -- private type, otherwise it is assumed that Typ denotes the full view of
363 -- a private type.
364
365 procedure Build_Invariant_Procedure_Declaration
366 (Typ : Entity_Id;
367 Partial_Invariant : Boolean := False);
368 -- Create the declaration of the procedure which verifies the invariants of
369 -- type Typ at runtime. Flag Partial_Invariant should be set when building
370 -- the invariant procedure for a private type.
371
372 function Build_Runtime_Call (Loc : Source_Ptr; RE : RE_Id) return Node_Id;
373 -- Build an N_Procedure_Call_Statement calling the given runtime entity.
374 -- The call has no parameters. The first argument provides the location
375 -- information for the tree and for error messages. The call node is not
376 -- analyzed on return, the caller is responsible for analyzing it.
377
378 function Build_SS_Mark_Call
379 (Loc : Source_Ptr;
380 Mark : Entity_Id) return Node_Id;
381 -- Build a call to routine System.Secondary_Stack.Mark. Mark denotes the
382 -- entity of the secondary stack mark.
383
384 function Build_SS_Release_Call
385 (Loc : Source_Ptr;
386 Mark : Entity_Id) return Node_Id;
387 -- Build a call to routine System.Secondary_Stack.Release. Mark denotes the
388 -- entity of the secondary stack mark.
389
390 function Build_Task_Image_Decls
391 (Loc : Source_Ptr;
392 Id_Ref : Node_Id;
393 A_Type : Entity_Id;
394 In_Init_Proc : Boolean := False) return List_Id;
395 -- Build declaration for a variable that holds an identifying string to be
396 -- used as a task name. Id_Ref is an identifier if the task is a variable,
397 -- and a selected or indexed component if the task is component of an
398 -- object. If it is an indexed component, A_Type is the corresponding array
399 -- type. Its index types are used to build the string as an image of the
400 -- index values. For composite types, the result includes two declarations:
401 -- one for a generated function that computes the image without using
402 -- concatenation, and one for the variable that holds the result.
403 --
404 -- If In_Init_Proc is true, the call is part of the initialization of
405 -- a component of a composite type, and the enclosing initialization
406 -- procedure must be flagged as using the secondary stack. If In_Init_Proc
407 -- is false, the call is for a stand-alone object, and the generated
408 -- function itself must do its own cleanups.
409
410 function Build_Temporary_On_Secondary_Stack
411 (Loc : Source_Ptr;
412 Typ : Entity_Id;
413 Code : List_Id) return Entity_Id;
414 -- Build a temporary of type Typ on the secondary stack, appending the
415 -- necessary actions to Code, and return a constant holding the access
416 -- value designating this temporary, under the assumption that Typ does
417 -- not need finalization.
418
419 -- This should be used when Typ can potentially be large, to avoid putting
420 -- too much pressure on the primary stack, for example with storage models.
421
422 procedure Check_Float_Op_Overflow (N : Node_Id);
423 -- Called where we could have a floating-point binary operator where we
424 -- must check for infinities if we are operating in Check_Float_Overflow
425 -- mode. Note that we don't need to worry about unary operator cases,
426 -- since for floating-point, abs, unary "-", and unary "+" can never
427 -- case overflow.
428
429 function Component_May_Be_Bit_Aligned
430 (Comp : Entity_Id;
431 For_Slice : Boolean := False) return Boolean;
432 -- This function is in charge of detecting record components that may cause
433 -- trouble for the back end if an attempt is made to access the component,
434 -- either as a whole if For_Slice is False, or through an array slice if
435 -- For_Slice is True. The back end can handle such accesses only if the
436 -- components involved are small (64/128 bits or less) records or scalars
437 -- (including bit-packed arrays represented with a modular type), or else
438 -- if they are aligned on byte boundaries (i.e. starting on a byte boundary
439 -- and occupying an integral number of bytes).
440 --
441 -- However problems arise for records larger than 64/128 bits or for arrays
442 -- (other than bit-packed arrays represented with a modular type) if the
443 -- component either does not start on a byte boundary or does not occupy an
444 -- integral number of bytes (i.e. there are some bits possibly shared with
445 -- other components at the start or the end of the component). The back end
446 -- cannot handle loading from or storing to such components as a whole.
447 --
448 -- This function is used to detect the troublesome situation. It is meant
449 -- to be conservative in the sense that it produces True unless it knows
450 -- for sure that the component is safe (as outlined in the first paragraph
451 -- above). The processing for record and array assignment indirectly checks
452 -- for trouble using this function and, if so, the assignment is expanded
453 -- component-wise, which the back end is required to handle correctly.
454
455 procedure Convert_To_Actual_Subtype (Exp : Node_Id);
456 -- The Etype of an expression is the nominal type of the expression,
457 -- not the actual subtype. Often these are the same, but not always.
458 -- For example, a reference to a formal of unconstrained type has the
459 -- unconstrained type as its Etype, but the actual subtype is obtained by
460 -- applying the actual bounds. This routine is given an expression, Exp,
461 -- and (if necessary), replaces it using Rewrite, with a conversion to
462 -- the actual subtype, building the actual subtype if necessary. If the
463 -- expression is already of the requested type, then it is unchanged.
464
465 function Corresponding_Runtime_Package (Typ : Entity_Id) return RTU_Id;
466 -- Return the id of the runtime package that will provide support for
467 -- concurrent type Typ. Currently only protected types are supported,
468 -- and the returned value is one of the following:
469 -- System_Tasking_Protected_Objects
470 -- System_Tasking_Protected_Objects_Entries
471 -- System_Tasking_Protected_Objects_Single_Entry
472
473 function Current_Sem_Unit_Declarations return List_Id;
474 -- Return the place where it is fine to insert declarations for the
475 -- current semantic unit. If the unit is a package body, return the
476 -- visible declarations of the corresponding spec. For RCI stubs, this
477 -- is necessary because the point at which they are generated may not
478 -- be the earliest point at which they are used.
479
480 function Duplicate_Subexpr
481 (Exp : Node_Id;
482 New_Scope : Entity_Id := Empty;
483 Name_Req : Boolean := False;
484 Renaming_Req : Boolean := False) return Node_Id;
485 -- Given the node for a subexpression, this function makes a logical copy
486 -- of the subexpression, and returns it. This is intended for use when the
487 -- expansion of an expression needs to repeat part of it. For example,
488 -- replacing a**2 by a*a requires two references to a which may be a
489 -- complex subexpression. Duplicate_Subexpr guarantees not to duplicate
490 -- side effects. If necessary, it generates actions to save the expression
491 -- value in a temporary, inserting these actions into the tree using
492 -- Insert_Actions with Exp as the insertion location. The original
493 -- expression and the returned result then become references to this saved
494 -- value. Exp must be analyzed on entry. On return, Exp is analyzed, but
495 -- the caller is responsible for analyzing the returned copy after it is
496 -- attached to the tree.
497 --
498 -- The New_Scope entity may be used to specify a new scope for all copied
499 -- entities and itypes.
500 --
501 -- The Name_Req flag is set to ensure that the result is suitable for use
502 -- in a context requiring a name (for example, the prefix of an attribute
503 -- reference).
504 --
505 -- The Renaming_Req flag is set to produce an object renaming declaration
506 -- rather than an object declaration. This is valid only if the expression
507 -- Exp designates a renamable object. This is used for example in the case
508 -- of an unchecked deallocation, to make sure the object gets set to null.
509 --
510 -- Note that if there are any run time checks in Exp, these same checks
511 -- will be duplicated in the returned duplicated expression. The two
512 -- following functions allow this behavior to be modified.
513
514 function Duplicate_Subexpr_No_Checks
515 (Exp : Node_Id;
516 New_Scope : Entity_Id := Empty;
517 Name_Req : Boolean := False;
518 Renaming_Req : Boolean := False) return Node_Id;
519 -- Identical in effect to Duplicate_Subexpr, except that Remove_Checks is
520 -- called on the result, so that the duplicated expression does not include
521 -- checks. This is appropriate for use when Exp, the original expression is
522 -- unconditionally elaborated before the duplicated expression, so that
523 -- there is no need to repeat any checks.
524
525 function Duplicate_Subexpr_Move_Checks
526 (Exp : Node_Id;
527 New_Scope : Entity_Id := Empty;
528 Name_Req : Boolean := False;
529 Renaming_Req : Boolean := False) return Node_Id;
530 -- Identical in effect to Duplicate_Subexpr, except that Remove_Checks is
531 -- called on Exp after the duplication is complete, so that the original
532 -- expression does not include checks. In this case the result returned
533 -- (the duplicated expression) will retain the original checks. This is
534 -- appropriate for use when the duplicated expression is sure to be
535 -- elaborated before the original expression Exp, so that there is no need
536 -- to repeat the checks.
537
538 function Enclosing_Init_Proc return Entity_Id;
539 -- Obtain the entity of the type initialization procedure which encloses
540 -- the current scope. Return Empty if no such procedure exists.
541
542 procedure Ensure_Defined (Typ : Entity_Id; N : Node_Id);
543 -- This procedure ensures that type referenced by Typ is defined. For the
544 -- case of a type other than an Itype, nothing needs to be done, since
545 -- all such types have declaration nodes. For Itypes, an N_Itype_Reference
546 -- node is generated and inserted as an action on node N. This is typically
547 -- used to ensure that an Itype is properly defined outside a conditional
548 -- construct when it is referenced in more than one branch.
549
550 procedure Evaluate_Name (Nam : Node_Id);
551 -- Remove all side effects from a name which appears as part of an object
552 -- renaming declaration. Similarly to Force_Evaluation, it removes the
553 -- side effects and captures the values of the variables, except for the
554 -- variable being renamed. Hence this differs from Force_Evaluation and
555 -- Remove_Side_Effects (but it calls Force_Evaluation on subexpressions
556 -- whose value needs to be fixed).
557
558 procedure Evolve_And_Then (Cond : in out Node_Id; Cond1 : Node_Id);
559 -- Rewrites Cond with the expression: Cond and then Cond1. If Cond is
560 -- Empty, then simply returns Cond1 (this allows the use of Empty to
561 -- initialize a series of checks evolved by this routine, with a final
562 -- result of Empty indicating that no checks were required). The Sloc field
563 -- of the constructed N_And_Then node is copied from Cond1.
564
565 procedure Evolve_Or_Else (Cond : in out Node_Id; Cond1 : Node_Id);
566 -- Rewrites Cond with the expression: Cond or else Cond1. If Cond is Empty,
567 -- then simply returns Cond1 (this allows the use of Empty to initialize a
568 -- series of checks evolved by this routine, with a final result of Empty
569 -- indicating that no checks were required). The Sloc field of the
570 -- constructed N_Or_Else node is copied from Cond1.
571
572 procedure Expand_Sliding_Conversion (N : Node_Id; Arr_Typ : Entity_Id);
573 -- When sliding is needed for an array object N in the context of an
574 -- unconstrained array type Arr_Typ with fixed lower bound (FLB), create
575 -- a subtype with appropriate index constraint (FLB .. N'Length + FLB - 1)
576 -- and apply a conversion from N to that subtype.
577
578 procedure Expand_Static_Predicates_In_Choices (N : Node_Id);
579 -- N is either a case alternative or a variant. The Discrete_Choices field
580 -- of N points to a list of choices. If any of these choices is the name
581 -- of a (statically) predicated subtype, then it is rewritten as the series
582 -- of choices that correspond to the values allowed for the subtype.
583
584 procedure Expand_Subtype_From_Expr
585 (N : Node_Id;
586 Unc_Type : Entity_Id;
587 Subtype_Indic : Node_Id;
588 Exp : Node_Id;
589 Related_Id : Entity_Id := Empty);
590 -- Build a constrained subtype from the initial value in object
591 -- declarations and/or allocations when the type is indefinite (including
592 -- class-wide). Set Related_Id to request an external name for the subtype
593 -- rather than an internal temporary.
594
595 function Expression_Contains_Primitives_Calls_Of
596 (Expr : Node_Id;
597 Typ : Entity_Id) return Boolean;
598 -- Return True if the expression Expr contains a nondispatching call to a
599 -- function which is a primitive of the tagged type Typ.
600
601 function Finalize_Address (Typ : Entity_Id) return Entity_Id;
602 -- Locate TSS primitive Finalize_Address in type Typ. Return Empty if the
603 -- subprogram is not available.
604
605 function Find_Interface_ADT
606 (T : Entity_Id;
607 Iface : Entity_Id) return Elmt_Id;
608 -- Ada 2005 (AI-251): Given a type T implementing the interface Iface,
609 -- return the element of Access_Disp_Table containing the tag of the
610 -- interface.
611
612 function Find_Interface_Tag
613 (T : Entity_Id;
614 Iface : Entity_Id) return Entity_Id;
615 -- Ada 2005 (AI-251): Given a type T and an interface Iface, return the
616 -- record component containing the tag of Iface if T implements Iface or
617 -- Empty if it does not.
618
619 -- WARNING: There is a matching C declaration of this subprogram in fe.h
620
621 function Find_Last_Init (Decl : Node_Id) return Node_Id;
622 -- Find the last initialization call related to object declaration Decl
623
624 function Find_Prim_Op (T : Entity_Id; Name : Name_Id) return Entity_Id
625 with Pre => Name not in Name_Adjust | Name_Finalize | Name_Initialize;
626 -- Find the first primitive operation of type T with the specified Name,
627 -- disregarding any visibility considerations. If T is a class-wide type,
628 -- then examine the primitive operations of its corresponding root type.
629 -- This function should not be called for the three controlled primitive
630 -- operations, and, instead, Find_Controlled_Prim_Op must be called for
631 -- those. Raise Program_Error if no primitive operation with the given
632 -- Name is found.
633
634 function Find_Prim_Op
635 (T : Entity_Id;
636 Name : TSS_Name_Type) return Entity_Id;
637 -- Same as Find_Prim_Op above, except we're searching for an op that has
638 -- the form indicated by Name (i.e. is a type support subprogram with the
639 -- indicated suffix).
640
641 function Find_Controlled_Prim_Op
642 (T : Entity_Id; Name : Name_Id) return Entity_Id
643 with Pre => Name in Name_Adjust | Name_Finalize | Name_Initialize;
644 -- Same as Find_Prim_Op but for the three controlled primitive operations,
645 -- and returns Empty if not found.
646
647 function Find_Optional_Prim_Op
648 (T : Entity_Id; Name : Name_Id) return Entity_Id;
649 function Find_Optional_Prim_Op
650 (T : Entity_Id;
651 Name : TSS_Name_Type) return Entity_Id;
652 -- Same as Find_Prim_Op, except returns Empty if not found
653
654 function Find_Protection_Object (Scop : Entity_Id) return Entity_Id;
655 -- Traverse the scope stack starting from Scop and look for an entry, entry
656 -- family, or a subprogram that has a Protection_Object and return it. Must
657 -- always return a value since the context in which this routine is invoked
658 -- should always have a protection object.
659
660 function Find_Protection_Type (Conc_Typ : Entity_Id) return Entity_Id;
661 -- Given a protected type or its corresponding record, find the type of
662 -- field _object.
663
664 function Find_Storage_Op
665 (Typ : Entity_Id;
666 Nam : Name_Id) return Entity_Id;
667 -- Given type Typ that's either a descendant of Root_Storage_Pool or else
668 -- specifies aspect Storage_Model_Type, returns the Entity_Id of the
669 -- subprogram associated with Nam, which must either be a primitive op of
670 -- the type in the case of a storage pool, or the operation corresponding
671 -- to Nam as specified in the aspect Storage_Model_Type. In the case of
672 -- aspect Storage_Model_Type, returns Empty when no operation is found,
673 -- indicating that the operation is defaulted in the aspect (can occur in
674 -- the case where the storage-model address type is System.Address).
675
676 function Find_Hook_Context (N : Node_Id) return Node_Id;
677 -- Determine a suitable node on which to attach actions related to N that
678 -- need to be elaborated unconditionally. In general this is the topmost
679 -- expression of which N is a subexpression, which in turn may or may not
680 -- be evaluated, for example if N is the right operand of a short circuit
681 -- operator.
682
683 function Following_Address_Clause (D : Node_Id) return Node_Id;
684 -- D is the node for an object declaration. This function searches the
685 -- current declarative part to look for an address clause for the object
686 -- being declared, and returns the clause if one is found, returns
687 -- Empty otherwise.
688
689 type Force_Evaluation_Mode is (Relaxed, Strict);
690
691 procedure Force_Evaluation
692 (Exp : Node_Id;
693 Name_Req : Boolean := False;
694 Related_Id : Entity_Id := Empty;
695 Is_Low_Bound : Boolean := False;
696 Is_High_Bound : Boolean := False;
697 Discr_Number : Int := 0;
698 Mode : Force_Evaluation_Mode := Relaxed);
699 -- Force the evaluation of the expression right away. Similar behavior
700 -- to Remove_Side_Effects when Variable_Ref is set to TRUE. That is to
701 -- say, it removes the side effects and captures the values of the
702 -- variables. Remove_Side_Effects guarantees that multiple evaluations
703 -- of the same expression won't generate multiple side effects, whereas
704 -- Force_Evaluation further guarantees that all evaluations will yield
705 -- the same result. If Mode is Relaxed then calls to this subprogram have
706 -- no effect if Exp is side-effect-free; if Mode is Strict and Exp is not
707 -- a static expression then no side-effect check is performed on Exp and
708 -- temporaries are unconditionally generated.
709 --
710 -- Related_Id denotes the entity of the context where Expr appears. Flags
711 -- Is_Low_Bound and Is_High_Bound specify whether the expression to check
712 -- is the low or the high bound of a range. These three optional arguments
713 -- signal Remove_Side_Effects to create an external symbol of the form
714 -- Chars (Related_Id)_FIRST/_LAST. If Related_Id is set, then exactly one
715 -- of the Is_xxx_Bound flags must be set. For use of these parameters see
716 -- the warning in the body of Sem_Ch3.Process_Range_Expr_In_Decl.
717
718 -- Discr_Number is positive when the expression is a discriminant value
719 -- in an object or component declaration. In that case Discr_Number is
720 -- the position of the corresponding discriminant in the corresponding
721 -- type declaration, and the name for the evaluated expression is built
722 -- out of the Related_Id and the Discr_Number.
723
724 function Fully_Qualified_Name_String
725 (E : Entity_Id;
726 Append_NUL : Boolean := True) return String_Id;
727 -- Generates the string literal corresponding to the fully qualified name
728 -- of entity E, in all upper case, with an ASCII.NUL appended at the end
729 -- of the name if Append_NUL is True.
730
731 procedure Get_Current_Value_Condition
732 (Var : Node_Id;
733 Op : out Node_Kind;
734 Val : out Node_Id) with Post => Val /= Var;
735 -- This routine processes the Current_Value field of the variable Var. If
736 -- the Current_Value field is null or if it represents a known value, then
737 -- on return Cond is set to N_Empty, and Val is set to Empty.
738 --
739 -- The other case is when Current_Value points to an N_If_Statement or an
740 -- N_Elsif_Part or a N_Iteration_Scheme node (see description in Einfo for
741 -- exact details). In this case, Get_Current_Condition digs out the
742 -- condition, and then checks if the condition is known false, known true,
743 -- or not known at all. In the first two cases, Get_Current_Condition will
744 -- return with Op set to the appropriate conditional operator (inverted if
745 -- the condition is known false), and Val set to the constant value. If the
746 -- condition is not known, then Op and Val are set for the empty case
747 -- (N_Empty and Empty).
748 --
749 -- The check for whether the condition is true/false unknown depends
750 -- on the case:
751 --
752 -- For an IF, the condition is known true in the THEN part, known false
753 -- in any ELSIF or ELSE part, and not known outside the IF statement in
754 -- question.
755 --
756 -- For an ELSIF, the condition is known true in the ELSIF part, known
757 -- FALSE in any subsequent ELSIF, or ELSE part, and not known before the
758 -- ELSIF, or after the end of the IF statement.
759 --
760 -- The caller can use this result to determine the value (for the case of
761 -- N_Op_Eq), or to determine the result of some other test in other cases
762 -- (e.g. no access check required if N_Op_Ne Null).
763
764 function Get_Index_Subtype (N : Node_Id) return Entity_Id;
765 -- Used for First, Last, and Length, when the prefix is an array type.
766 -- Obtains the corresponding index subtype.
767
768 function Get_Mapped_Entity (E : Entity_Id) return Entity_Id;
769 -- Return the mapped entity of E; used to check inherited class-wide
770 -- pre/postconditions.
771
772 function Get_Stream_Size (E : Entity_Id) return Uint;
773 -- Return the stream size value of the subtype E
774
775 function Has_Access_Constraint (E : Entity_Id) return Boolean;
776 -- Given object or type E, determine if a discriminant is of an access type
777
778 function Has_Tag_Of_Type (Exp : Node_Id) return Boolean;
779 -- Return True if expression Exp of a tagged type is known to statically
780 -- have the tag of this tagged type as specified by RM 3.9(19-25).
781
782 function Homonym_Number (Subp : Entity_Id) return Pos;
783 -- Here subp is the entity for a subprogram. This routine returns the
784 -- homonym number used to disambiguate overloaded subprograms in the same
785 -- scope (the number is used as part of constructed names to make sure that
786 -- they are unique). The number is the ordinal position on the Homonym
787 -- chain, counting only entries in the current scope. If an entity is not
788 -- overloaded, the returned number will be one.
789
790 function In_Library_Level_Package_Body (Id : Entity_Id) return Boolean;
791 -- Given an arbitrary entity, determine whether it appears at the library
792 -- level of a package body.
793
794 function In_Unconditional_Context (Node : Node_Id) return Boolean;
795 -- Node is the node for a statement or a component of a statement. This
796 -- function determines if the statement appears in a context that is
797 -- unconditionally executed, i.e. it is not within a loop or a conditional
798 -- or a case statement etc.
799
800 function Init_Proc_Level_Formal (Proc : Entity_Id) return Entity_Id;
801 -- Return the extra formal of an initialization procedure corresponding to
802 -- the level of the object being initialized, or Empty if none is present.
803
804 function Inside_Init_Proc return Boolean;
805 -- Return True if current scope is within an init proc
806
807 function Integer_Type_For (S : Uint; Uns : Boolean) return Entity_Id;
808 -- Return a suitable standard integer type containing at least S bits and
809 -- of the signedness given by Uns. See also Small_Integer_Type_For.
810
811 function Is_Captured_Function_Call (N : Node_Id) return Boolean;
812 -- Return True if N is a captured function call, i.e. the result of calling
813 -- Remove_Side_Effects on an N_Function_Call node:
814
815 -- type Ann is access all Typ;
816 -- Rnn : constant Ann := Func (...)'reference;
817 -- Rnn.all
818
819 function Is_Constr_Array_Subt_Of_Unc_With_Controlled (Typ : Entity_Id)
820 return Boolean;
821 -- Return True if Typ is a constrained subtype of an array type with an
822 -- unconstrained first subtype and a controlled component type.
823
824 function Is_Conversion_Or_Reference_To_Formal (N : Node_Id) return Boolean;
825 -- Return True if N is a type conversion, or a dereference thereof, or a
826 -- reference to a formal parameter.
827
828 function Is_Expanded_Class_Wide_Interface_Object_Decl
829 (N : Node_Id) return Boolean;
830 -- Determine if N is the expanded code for a class-wide interface type
831 -- object declaration.
832
833 function Is_Finalizable_Access (Decl : Node_Id) return Boolean;
834 -- Determine whether declaration Decl denotes an access-to-controlled
835 -- object that must be finalized, i.e. both that the designated object
836 -- is controlled and that it must be finalized through this access, in
837 -- particular that it will not be also finalized directly. That is the
838 -- case only for objects initialized by a reference to a function call
839 -- that meet specific conditions.
840
841 function Is_Finalizable_Transient
842 (Decl : Node_Id;
843 N : Node_Id) return Boolean;
844 -- Determine whether declaration Decl denotes a controlled transient object
845 -- that must be finalized. N is the node serviced by the transient context.
846
847 function Is_Fully_Repped_Tagged_Type (T : Entity_Id) return Boolean;
848 -- Tests given type T, and returns True if T is a non-discriminated tagged
849 -- type which has a record representation clause that specifies the layout
850 -- of all the components, including recursively components in all parent
851 -- types. We exclude discriminated types for convenience, it is extremely
852 -- unlikely that the special processing associated with the use of this
853 -- routine is useful for the case of a discriminated type, and testing for
854 -- component overlap would be a pain.
855
856 -- WARNING: There is a matching C declaration of this subprogram in fe.h
857
858 function Is_Library_Level_Tagged_Type (Typ : Entity_Id) return Boolean;
859 -- Return True if Typ is a library level tagged type. Currently we use
860 -- this information to build statically allocated dispatch tables.
861
862 function Is_LSP_Wrapper (E : Entity_Id) return Boolean;
863 -- Return True if E is a wrapper built when a subprogram has class-wide
864 -- preconditions or postconditions affected by overriding (AI12-0195).
865 -- LSP stands for Liskov Substitution Principle.
866
867 function Is_Possibly_Unaligned_Object (N : Node_Id) return Boolean;
868 -- Node N is an object reference. This function returns True if it is
869 -- possible that the object may not be aligned according to the normal
870 -- default alignment requirement for its type (e.g. if it appears in a
871 -- packed record, or as part of a component that has a component clause.)
872
873 function Is_Possibly_Unaligned_Slice (N : Node_Id) return Boolean;
874 -- Determine whether the node P is a slice of an array where the slice
875 -- result may cause alignment problems because it has an alignment that
876 -- is not compatible with the type. Return True if so.
877
878 function Is_Ref_To_Bit_Packed_Array (N : Node_Id) return Boolean;
879 -- Determine whether the node P is a reference to a bit packed array, i.e.
880 -- whether the designated object is a component of a bit packed array, or a
881 -- subcomponent of such a component. If so, then all subscripts in P are
882 -- evaluated with a call to Force_Evaluation, and True is returned.
883 -- Otherwise False is returned, and P is not affected.
884
885 function Is_Ref_To_Bit_Packed_Slice (N : Node_Id) return Boolean;
886 -- Determine whether the node P is a reference to a bit packed slice, i.e.
887 -- whether the designated object is bit packed slice or a component of a
888 -- bit packed slice. Return True if so.
889
890 function Is_Related_To_Func_Return (Id : Entity_Id) return Boolean;
891 -- Determine whether object Id is related to an expanded return statement.
892 -- The case concerned is "return Id.all;".
893
894 -- This is effectively used to determine which temporaries generated for
895 -- return statements must be finalized because they are regular temporaries
896 -- and which ones must not be since they are allocated on the return stack.
897
898 -- WARNING: There is a matching C declaration of this subprogram in fe.h
899
900 function Is_Renamed_Object (N : Node_Id) return Boolean;
901 -- Returns True if the node N is a renamed object. An expression is
902 -- considered to be a renamed object if either it is the Name of an object
903 -- renaming declaration, or is the prefix of a name which is a renamed
904 -- object. For example, in:
905 --
906 -- x : r renames a (1 .. 2) (1);
907 --
908 -- We consider that a (1 .. 2) is a renamed object since it is the prefix
909 -- of the name in the renaming declaration.
910
911 function Is_Secondary_Stack_Thunk (Id : Entity_Id) return Boolean;
912 -- Determine whether Id denotes a secondary stack thunk
913
914 -- WARNING: There is a matching C declaration of this subprogram in fe.h
915
916 function Is_Statically_Disabled
917 (N : Node_Id;
918 Value : Boolean;
919 Include_Valid : Boolean)
920 return Boolean
921 with Pre => Nkind (N) in N_Subexpr and then Is_Boolean_Type (Etype (N));
922 -- Returns whether N is a "statically disabled" condition which evaluates
923 -- to Value, as described in section 7.3.2 of SPARK User's Guide.
924 --
925 -- If Include_Valid is True, a reference to 'Valid or 'Valid_Scalar is
926 -- considered as disabled for Value=True, which is useful in GNATprove, as
927 -- proof considers that these attributes always return the value True. In
928 -- general, Include_Valid is set to True in the proof phase of GNATprove,
929 -- as 'Valid is assumed to always evaluate to True, but not in the flow
930 -- analysis phase of GNATprove, which does not make this assumption.
931
932 function Is_Untagged_Derivation (T : Entity_Id) return Boolean;
933 -- Returns true if type T is not tagged and is a derived type,
934 -- or is a private type whose completion is such a type.
935
936 function Is_Untagged_Private_Derivation
937 (Priv_Typ : Entity_Id;
938 Full_Typ : Entity_Id) return Boolean;
939 -- Determine whether private type Priv_Typ and its full view Full_Typ
940 -- represent an untagged derivation from a private parent.
941
942 function Is_Volatile_Reference (N : Node_Id) return Boolean;
943 -- Checks if the node N represents a volatile reference, which can be
944 -- either a direct reference to a variable treated as volatile, or an
945 -- indexed/selected component where the prefix is treated as volatile,
946 -- or has Volatile_Components set. A slice of a volatile variable is
947 -- also volatile.
948
949 procedure Kill_Dead_Code (N : Node_Id; Warn : Boolean := False);
950 -- N represents a node for a section of code that is known to be dead. Any
951 -- exception handler references and warning messages relating to this code
952 -- are removed. If Warn is True, a warning will be output at the start of N
953 -- indicating the deletion of the code. Note that the tree for the deleted
954 -- code is left intact so that e.g. cross-reference data is still valid.
955
956 procedure Kill_Dead_Code (L : List_Id; Warn : Boolean := False);
957 -- Like the above procedure, but applies to every element in the given
958 -- list. If Warn is True, a warning will be output at the start of N
959 -- indicating the deletion of the code.
960
961 function Make_CW_Equivalent_Type
962 (T : Entity_Id;
963 E : Node_Id;
964 List_Def : out List_Id) return Entity_Id;
965 -- T is a class-wide type entity, and E is the initial expression node that
966 -- constrains T in cases such as: " X: T := E" or "new T'(E)". When there
967 -- is no E present then it is assumed that T is an unconstrained mutably
968 -- tagged class-wide type.
969 --
970 -- This function returns the entity of the Equivalent type and inserts
971 -- on the fly the necessary declaration into List_Def such as:
972 --
973 -- type anon is record
974 -- _parent : Root_Type (T); constrained with E discriminants (if any)
975 -- Extension : String (1 .. expr to match size of E);
976 -- end record;
977 --
978 -- This record is compatible with any object of the class of T thanks to
979 -- the first field and has the same size as E thanks to the second.
980
981 function Make_Invariant_Call (Expr : Node_Id) return Node_Id;
982 -- Generate a call to the Invariant_Procedure associated with the type of
983 -- expression Expr. Expr is passed as an actual parameter in the call.
984
985 function Make_Predicate_Call
986 (Typ : Entity_Id;
987 Expr : Node_Id;
988 Static_Mem : Boolean := False;
989 Dynamic_Mem : Node_Id := Empty) return Node_Id;
990 -- Typ is a type with Predicate_Function set. This routine builds a call to
991 -- this function passing Expr as the argument, and returns it unanalyzed.
992 -- If the callee takes a second parameter (as determined by
993 -- Sem_Util.Predicate_Function_Needs_Membership_Parameter), then the
994 -- actual parameter is determined by the two Mem parameters.
995 -- If Dynamic_Mem is nonempty, then Dynamic_Mem is the actual parameter.
996 -- Otherwise, the value of the Static_Mem parameter is passed in as
997 -- a Boolean literal. It is an error if Dynamic_Mem is nonempty but
998 -- the callee does not take a second parameter.
999
1000 function Make_Predicate_Check
1001 (Typ : Entity_Id;
1002 Expr : Node_Id) return Node_Id;
1003 -- Typ is a type with Predicate_Function set. This routine builds a Check
1004 -- pragma whose first argument is Predicate, and the second argument is
1005 -- a call to the predicate function of Typ with Expr as the argument. If
1006 -- Predicate_Check is suppressed then a null statement is returned instead.
1007
1008 function Make_Subtype_From_Expr
1009 (E : Node_Id;
1010 Unc_Typ : Entity_Id;
1011 Related_Id : Entity_Id := Empty) return Node_Id;
1012 -- Returns a subtype indication corresponding to the actual type of an
1013 -- expression E. Unc_Typ is an unconstrained array or record, or a class-
1014 -- wide type. Set Related_Id to request an external name for the subtype
1015 -- rather than an internal temporary.
1016
1017 function Make_Tag_Assignment_From_Type
1018 (Loc : Source_Ptr;
1019 Target : Node_Id;
1020 Typ : Entity_Id) return Node_Id
1021 with
1022 Pre => (not Is_Concurrent_Type (Typ));
1023 -- Return an assignment of the tag of tagged type Typ to prefix Target,
1024 -- which must be a record object of a descendant of Typ. Typ cannot be a
1025 -- concurrent type; for concurrent types, the corresponding record types
1026 -- should be passed to this function instead.
1027
1028 function Make_Variant_Comparison
1029 (Loc : Source_Ptr;
1030 Typ : Entity_Id;
1031 Mode : Name_Id;
1032 Curr_Val : Node_Id;
1033 Old_Val : Node_Id) return Node_Id;
1034 -- Subsidiary to the expansion of pragmas Loop_Variant and
1035 -- Subprogram_Variant. Generate a comparison between Curr_Val and Old_Val
1036 -- depending on the variant mode (Increases / Decreases) using less or
1037 -- greater operator for Typ.
1038
1039 procedure Map_Formals
1040 (Parent_Subp : Entity_Id;
1041 Derived_Subp : Entity_Id;
1042 Force_Update : Boolean := False);
1043 -- Establish the mapping from the formals of Parent_Subp to the formals
1044 -- of Derived_Subp; if Force_Update is True then mapping of Parent_Subp to
1045 -- Derived_Subp is also updated; used to update mapping of late-overriding
1046 -- primitives of a tagged type.
1047
1048 procedure Map_Types (Parent_Type : Entity_Id; Derived_Type : Entity_Id);
1049 -- Establish the following mapping between the attributes of tagged parent
1050 -- type Parent_Type and tagged derived type Derived_Type.
1051 --
1052 -- * Map each discriminant of Parent_Type to either the corresponding
1053 -- discriminant of Derived_Type or come constraint.
1054
1055 -- * Map each primitive operation of Parent_Type to the corresponding
1056 -- primitive of Derived_Type.
1057 --
1058 -- The mapping Parent_Type -> Derived_Type is also added to the table in
1059 -- order to prevent subsequent attempts of the same mapping.
1060
1061 function Matching_Standard_Type (Typ : Entity_Id) return Entity_Id;
1062 -- Given a scalar subtype Typ, returns a matching type in standard that
1063 -- has the same object size value. For example, a 16 bit signed type will
1064 -- typically return Standard_Short_Integer. For fixed-point types, this
1065 -- will return integer types of the corresponding size.
1066
1067 procedure Move_To_Initialization_Statements (Decl, Stop : Node_Id);
1068 -- Decl is an N_Object_Declaration node and Stop is a node past Decl in
1069 -- the same list. Move all the nodes on the list between Decl and Stop
1070 -- (excluded) into a compound statement inserted between Decl and Stop
1071 -- and attached to the object by means of Initialization_Statements.
1072
1073 function Needs_Initialization_Statements (Decl : Node_Id) return Boolean;
1074 -- Decl is the N_Object_Declaration node of an object initialized with an
1075 -- aggregate or a call expanded in place. Return True if the statements
1076 -- created by expansion need to be moved to the Initialization_Statements
1077 -- of the object.
1078
1079 function Name_Of_Controlled_Prim_Op
1080 (Typ : Entity_Id;
1081 Nam : Name_Id) return Name_Id
1082 with Pre => Nam in Name_Adjust | Name_Finalize | Name_Initialize;
1083 -- Return the name of the Adjust, Finalize, or Initialize primitive of
1084 -- controlled type Typ, if it exists, and No_Name if it does not.
1085
1086 function Needs_Conditional_Null_Excluding_Check
1087 (Typ : Entity_Id) return Boolean;
1088 -- Check if a type meets certain properties that require it to have a
1089 -- conditional null-excluding check within its Init_Proc.
1090
1091 function Needs_Constant_Address
1092 (Decl : Node_Id;
1093 Typ : Entity_Id) return Boolean;
1094 -- Check whether the expression in an address clause is restricted to
1095 -- consist of constants, when the object has a nontrivial initialization
1096 -- or is controlled.
1097
1098 function OK_To_Do_Constant_Replacement (E : Entity_Id) return Boolean;
1099 -- This function is used when testing whether or not to replace a reference
1100 -- to entity E by a known constant value. Such replacement must be done
1101 -- only in a scope known to be safe for such replacements. In particular,
1102 -- if we are within a subprogram and the entity E is declared outside the
1103 -- subprogram then we cannot do the replacement, since we do not attempt to
1104 -- trace subprogram call flow. It is also unsafe to replace statically
1105 -- allocated values (since they can be modified outside the scope), and we
1106 -- also inhibit replacement of Volatile or aliased objects since their
1107 -- address might be captured in a way we do not detect. A value of True is
1108 -- returned only if the replacement is safe.
1109
1110 function Possible_Bit_Aligned_Component
1111 (N : Node_Id;
1112 For_Slice : Boolean := False) return Boolean;
1113 -- This function is used during processing the assignment of a record or an
1114 -- array, or the construction of an aggregate. The argument N is either the
1115 -- left or the right hand side of an assignment and the function determines
1116 -- whether there is a record component reference where the component may be
1117 -- bit aligned in a manner that causes trouble for the back end (see also
1118 -- Component_May_Be_Bit_Aligned for further details).
1119
1120 function Power_Of_Two (N : Node_Id) return Nat;
1121 -- Determines if N is a known at compile time value which is of the form
1122 -- 2**K, where K is in the range 1 .. M, where the Esize of N is 2**(M+1).
1123 -- If so, returns the value K, otherwise returns zero. The caller checks
1124 -- that N is of an integer type.
1125
1126 function Predicate_Check_In_Scope (N : Node_Id) return Boolean;
1127 -- Return True if predicate checks should be generated in the current
1128 -- scope on the given node. Will return False for example when the current
1129 -- scope is a predefined primitive operation.
1130
1131 procedure Process_Statements_For_Controlled_Objects (N : Node_Id);
1132 -- N is a node which contains a non-handled statement list. Inspect the
1133 -- statements looking for declarations of controlled objects. If at least
1134 -- one such object is found, wrap the statement list in a block.
1135
1136 function Remove_Init_Call
1137 (Var : Entity_Id;
1138 Rep_Clause : Node_Id) return Node_Id;
1139 -- Look for init_proc call or aggregate initialization statements for
1140 -- variable Var, either among declarations between that of Var and a
1141 -- subsequent Rep_Clause applying to Var, or in the list of freeze actions
1142 -- associated with Var, and if found, remove and return that call node.
1143
1144 procedure Remove_Side_Effects
1145 (Exp : Node_Id;
1146 Name_Req : Boolean := False;
1147 Renaming_Req : Boolean := False;
1148 Variable_Ref : Boolean := False;
1149 Related_Id : Entity_Id := Empty;
1150 Is_Low_Bound : Boolean := False;
1151 Is_High_Bound : Boolean := False;
1152 Discr_Number : Int := 0;
1153 Check_Side_Effects : Boolean := True);
1154 -- Given the node for a subexpression, this function replaces the node if
1155 -- necessary by an equivalent subexpression that is guaranteed to be side
1156 -- effect free. This is done by extracting any actions that could cause
1157 -- side effects, and inserting them using Insert_Actions into the tree
1158 -- to which Exp is attached. Exp must be analyzed and resolved before the
1159 -- call and is analyzed and resolved on return. Name_Req may only be set to
1160 -- True if Exp has the form of a name, and the effect is to guarantee that
1161 -- any replacement maintains the form of name. If Renaming_Req is set to
1162 -- True, the routine produces an object renaming declaration capturing the
1163 -- expression. If Variable_Ref is set to True, a variable is considered as
1164 -- side effect (used in implementing Force_Evaluation). Note: after call to
1165 -- Remove_Side_Effects, it is safe to call New_Copy_Tree to obtain a copy
1166 -- of the resulting expression. If Check_Side_Effects is set to True then
1167 -- no action is performed if Exp is known to be side-effect-free.
1168 --
1169 -- Related_Id denotes the entity of the context where Expr appears. Flags
1170 -- Is_Low_Bound and Is_High_Bound specify whether the expression to check
1171 -- is the low or the high bound of a range. These three optional arguments
1172 -- signal Remove_Side_Effects to create an external symbol of the form
1173 -- Chars (Related_Id)_FIRST/_LAST. If Related_Id is set, then exactly one
1174 -- of the Is_xxx_Bound flags must be set. For use of these parameters see
1175 -- the warning in the body of Sem_Ch3.Process_Range_Expr_In_Decl.
1176 --
1177 -- If Discr_Number is positive, the expression denotes a discrimant value
1178 -- in a constraint, the suffix DISCR is used to create the external name.
1179
1180 -- The side effects are captured using one of the following methods:
1181 --
1182 -- 1) a constant initialized with the value of the subexpression
1183 -- 2) a renaming of the subexpression
1184 -- 3) a reference to the subexpression
1185 --
1186 -- For elementary types, methods 1) and 2) are used; for composite types,
1187 -- methods 2) and 3) are used. The renaming (method 2) is used only when
1188 -- the subexpression denotes a name, so that it can be elaborated by gigi
1189 -- without evaluating the subexpression.
1190 --
1191 -- Historical note: the reference (method 3) used to be the common fallback
1192 -- method but it gives rise to aliasing issues if the subexpression denotes
1193 -- a name that is not aliased, since it is equivalent to taking the address
1194 -- in this case. The renaming (method 2) used to be applied to any objects
1195 -- in the RM sense, that is to say to the cases where a renaming is legal
1196 -- in Ada. But for some of these cases, most notably functions calls, the
1197 -- renaming cannot be elaborated without evaluating the subexpression, so
1198 -- gigi would resort to method 1) or 3) under the hood for them.
1199
1200 procedure Replace_References
1201 (Expr : Node_Id;
1202 Par_Typ : Entity_Id;
1203 Deriv_Typ : Entity_Id;
1204 Par_Obj : Entity_Id := Empty;
1205 Deriv_Obj : Entity_Id := Empty);
1206 -- Expr denotes an arbitrary expression. Par_Typ is a tagged parent type
1207 -- in a type hierarchy. Deriv_Typ is a tagged type derived from Par_Typ
1208 -- with optional ancestors in between. Par_Obj is a formal parameter
1209 -- which emulates the current instance of Par_Typ. Deriv_Obj is a formal
1210 -- parameter which emulates the current instance of Deriv_Typ. Perform the
1211 -- following substitutions in Expr:
1212 --
1213 -- * Replace a reference to Par_Obj with a reference to Deriv_Obj
1214 --
1215 -- * Replace a reference to a discriminant of Par_Typ with a suitable
1216 -- value from the point of view of Deriv_Typ.
1217 --
1218 -- * Replace a call to an overridden primitive of Par_Typ with a call to
1219 -- an overriding primitive of Deriv_Typ.
1220 --
1221 -- * Replace a call to an inherited primitive of Par_Type with a call to
1222 -- the internally-generated inherited primitive of Deriv_Typ.
1223
1224 procedure Replace_Type_References
1225 (Expr : Node_Id;
1226 Typ : Entity_Id;
1227 Obj_Id : Entity_Id);
1228 -- Substitute all references of the current instance of type Typ with
1229 -- references to formal parameter Obj_Id within expression Expr.
1230
1231 function Represented_As_Scalar (T : Entity_Id) return Boolean;
1232 -- Returns True iff the implementation of this type in code generation
1233 -- terms is scalar. This is true for scalars in the Ada sense, and for
1234 -- packed arrays which are represented by a scalar (modular) type.
1235
1236 function Requires_Cleanup_Actions
1237 (N : Node_Id;
1238 Lib_Level : Boolean) return Boolean;
1239 -- Given a node N, determine whether its declarative and/or statement list
1240 -- contains one of the following:
1241 --
1242 -- 1) controlled objects
1243 -- 2) library-level tagged types
1244 --
1245 -- These cases require special actions on scope exit. Lib_Level is True if
1246 -- the construct is at library level, and False otherwise.
1247
1248 procedure Rewrite_Object_Declaration_As_Renaming (N, Nam : Node_Id);
1249 -- Rewrite object declaration N as an object renaming declaration of Nam
1250
1251 function Safe_Unchecked_Type_Conversion (Exp : Node_Id) return Boolean;
1252 -- Given the node for an N_Unchecked_Type_Conversion, return True if this
1253 -- is an unchecked conversion that Gigi can handle directly. Otherwise
1254 -- return False if it is one for which the front end must provide a
1255 -- temporary. Note that the node need not be analyzed, and thus the Etype
1256 -- field may not be set, but in that case it must be the case that the
1257 -- Subtype_Mark field of the node is set/analyzed.
1258
1259 procedure Set_Current_Value_Condition (Cnode : Node_Id);
1260 -- Cnode is N_If_Statement, N_Elsif_Part, or N_Iteration_Scheme (the latter
1261 -- when a WHILE condition is present). This call checks whether Condition
1262 -- (Cnode) has embedded expressions of a form that should result in setting
1263 -- the Current_Value field of one or more entities, and if so sets these
1264 -- fields to point to Cnode.
1265
1266 procedure Set_Elaboration_Flag (N : Node_Id; Spec_Id : Entity_Id);
1267 -- N is the node for a subprogram or generic body, and Spec_Id is the
1268 -- entity for the corresponding spec. If an elaboration entity is defined,
1269 -- then this procedure generates an assignment statement to set it True,
1270 -- immediately after the body is elaborated. However, no assignment is
1271 -- generated in the case of library level procedures, since the setting of
1272 -- the flag in this case is generated in the binder. We do that so that we
1273 -- can detect cases where this is the only elaboration action that is
1274 -- required.
1275
1276 procedure Set_Renamed_Subprogram (N : Node_Id; E : Entity_Id);
1277 -- N is an node which is an entity name that represents the name of a
1278 -- renamed subprogram. The node is rewritten to be an identifier that
1279 -- refers directly to the renamed subprogram, given by entity E.
1280
1281 function Side_Effect_Free
1282 (N : Node_Id;
1283 Name_Req : Boolean := False;
1284 Variable_Ref : Boolean := False) return Boolean;
1285 -- Determines if the tree N represents an expression that is known not
1286 -- to have side effects. If this function returns True, then for example
1287 -- a call to Remove_Side_Effects has no effect.
1288 --
1289 -- Name_Req controls the handling of volatile variable references. If
1290 -- Name_Req is False (the normal case), then volatile references are
1291 -- considered to be side effects. If Name_Req is True, then volatility
1292 -- of variables is ignored.
1293 --
1294 -- If Variable_Ref is True, then all variable references are considered to
1295 -- be side effects (regardless of volatility or the setting of Name_Req).
1296
1297 function Side_Effect_Free
1298 (L : List_Id;
1299 Name_Req : Boolean := False;
1300 Variable_Ref : Boolean := False) return Boolean;
1301 -- Determines if all elements of the list L are side-effect-free. Name_Req
1302 -- and Variable_Ref are as described above.
1303
1304 procedure Silly_Boolean_Array_Not_Test (N : Node_Id; T : Entity_Id);
1305 -- N is the node for a boolean array NOT operation, and T is the type of
1306 -- the array. This routine deals with the silly case where the subtype of
1307 -- the boolean array is False..False or True..True, where it is required
1308 -- that a Constraint_Error exception be raised (RM 4.5.6(6)).
1309
1310 procedure Silly_Boolean_Array_Xor_Test
1311 (N : Node_Id;
1312 R : Node_Id;
1313 T : Entity_Id);
1314 -- N is the node for a boolean array XOR operation, T is the type of the
1315 -- array, and R is a copy of the right operand of N, required to prevent
1316 -- scope anomalies when unnesting is in effect. This routine deals with
1317 -- the admitedly silly case where the subtype of the boolean array is
1318 -- True..True, where a raise of a Constraint_Error exception is required
1319 -- (RM 4.5.6(6)) and ACATS-tested.
1320
1321 function Small_Integer_Type_For (S : Uint; Uns : Boolean) return Entity_Id;
1322 -- Return the smallest standard integer type containing at least S bits and
1323 -- of the signedness given by Uns. See also Integer_Type_For.
1324
1325 function Thunk_Target (Thunk : Entity_Id) return Entity_Id;
1326 -- Return the entity ultimately called by the thunk, that is to say return
1327 -- the Thunk_Entity of the last member on the thunk chain.
1328
1329 -- WARNING: There is a matching C declaration of this subprogram in fe.h
1330
1331 function Try_Inline_Always (Subp : Entity_Id) return Boolean;
1332 -- Determines if the backend should try hard to inline Subp. This is
1333 -- similar to Subp having a pragma Inline_Always, but doesn't cause an
1334 -- error if Subp can't actually be inlined.
1335
1336 function Type_May_Have_Bit_Aligned_Components
1337 (Typ : Entity_Id) return Boolean;
1338 -- Determines if Typ is a composite type that has within it (looking down
1339 -- recursively at subcomponents) a record which contains a component that
1340 -- may be bit aligned in a manner that causes trouble for the back end
1341 -- (see also Component_May_Be_Bit_Aligned for further details). The result
1342 -- is conservative, in that a result of False is decisive. A result of True
1343 -- means that such a component may or may not be present.
1344
1345 function Unconditional_Parent (N : Node_Id) return Node_Id;
1346 -- Return the first parent of arbitrary node N that is not a conditional
1347 -- expression, one of whose dependent expressions is N, and that is not
1348 -- a qualified expression, whose expression is N, recursively.
1349
1350 procedure Update_Primitives_Mapping
1351 (Inher_Id : Entity_Id;
1352 Subp_Id : Entity_Id);
1353 -- Map primitive operations of the parent type to the corresponding
1354 -- operations of the descendant. Note that the descendant type may not be
1355 -- frozen yet, so we cannot use the dispatch table directly. This is called
1356 -- when elaborating a contract for a subprogram, and when freezing a type
1357 -- extension to verify legality rules on inherited conditions.
1358
1359 function Within_Conditional_Expression (N : Node_Id) return Boolean;
1360 -- Determine whether arbitrary node N is immediately within a dependent
1361 -- expression of a conditional expression. The criterion is whether
1362 -- temporaries created by the actions attached to N need to outlive an
1363 -- enclosing conditional expression.
1364
1365 private
1366 pragma Inline (Duplicate_Subexpr);
1367 pragma Inline (Find_Controlled_Prim_Op);
1368 pragma Inline (Find_Prim_Op);
1369 pragma Inline (Force_Evaluation);
1370 pragma Inline (Get_Mapped_Entity);
1371 pragma Inline (Is_Library_Level_Tagged_Type);
1372 pragma Inline (Is_Secondary_Stack_Thunk);
1373 pragma Inline (Thunk_Target);
1374 end Exp_Util;