1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2023, Free Software Foundation, Inc. --
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. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 ------------------------------------------------------------------------------
26 -- Package containing utility procedures used throughout the expander
28 with Exp_Tss
; use Exp_Tss
;
29 with Namet
; use Namet
;
30 with Rtsfind
; use Rtsfind
;
31 with Sinfo
; use Sinfo
;
32 with Sinfo
.Nodes
; use Sinfo
.Nodes
;
33 with Types
; use Types
;
34 with Uintp
; use Uintp
;
38 -----------------------------------------------
39 -- Handling of Actions Associated with Nodes --
40 -----------------------------------------------
42 -- The evaluation of certain expression nodes involves the elaboration
43 -- of associated types and other declarations, and the execution of
44 -- statement sequences. Expansion routines generating such actions must
45 -- find an appropriate place in the tree to hang the actions so that
46 -- they will be evaluated at the appropriate point.
48 -- Some cases are simple:
50 -- For an expression occurring in a simple statement that is in a list
51 -- of statements, the actions are simply inserted into the list before
52 -- the associated statement.
54 -- For an expression occurring in a declaration the actions are similarly
55 -- inserted into the list just before the associated declaration. (But
56 -- note that although declarations usually appear in lists, they don't
57 -- always; in particular, a library unit declaration does not appear in
58 -- a list, and Insert_Action will crash in that case.)
60 -- The following special cases arise:
62 -- For actions associated with the right operand of a short circuit
63 -- form, the actions are first stored in the short circuit form node
64 -- in the Actions field. The expansion of these forms subsequently
65 -- expands the short circuit forms into if statements which can then
66 -- be moved as described above.
68 -- For actions appearing in the Condition expression of a while loop,
69 -- or an elsif clause, the actions are similarly temporarily stored in
70 -- in the node (N_Elsif_Part or N_Iteration_Scheme) associated with
71 -- the expression using the Condition_Actions field. Subsequently, the
72 -- expansion of these nodes rewrites the control structures involved to
73 -- reposition the actions in normal statement sequence.
75 -- For actions appearing in the then or else expression of a conditional
76 -- expression, these actions are similarly placed in the node, using the
77 -- Then_Actions or Else_Actions field as appropriate. Once again the
78 -- expansion of the N_If_Expression node rewrites the node so that the
79 -- actions can be positioned normally.
81 -- For actions coming from expansion of the expression in an expression
82 -- with actions node, the action is appended to the list of actions.
84 -- Basically what we do is to climb up to the tree looking for the
85 -- proper insertion point, as described by one of the above cases,
86 -- and then insert the appropriate action or actions.
88 -- Note if more than one insert call is made specifying the same
89 -- Assoc_Node, then the actions are elaborated in the order of the
90 -- calls, and this guarantee is preserved for the special cases above.
92 procedure Insert_Action
93 (Assoc_Node
: Node_Id
;
95 Spec_Expr_OK
: Boolean := False);
96 -- Insert the action Ins_Action at the appropriate point as described
97 -- above. The action is analyzed using the default checks after it is
98 -- inserted. Assoc_Node is the node with which the action is associated.
99 -- When flag Spec_Expr_OK is set, insertions triggered in the context of
100 -- spec expressions are honored, even though they contradict "Handling
101 -- of Default and Per-Object Expressions".
103 procedure Insert_Action
104 (Assoc_Node
: Node_Id
;
105 Ins_Action
: Node_Id
;
107 Spec_Expr_OK
: Boolean := False);
108 -- Insert the action Ins_Action at the appropriate point as described
109 -- above. The action is analyzed using the default checks as modified
110 -- by the given Suppress argument after it is inserted. Assoc_Node is
111 -- the node with which the action is associated. When flag Spec_Expr_OK
112 -- is set, insertions triggered in the context of spec expressions are
113 -- honored, even though they contradict "Handling of Default and Per-
114 -- Object Expressions".
116 procedure Insert_Actions
117 (Assoc_Node
: Node_Id
;
118 Ins_Actions
: List_Id
;
119 Spec_Expr_OK
: Boolean := False);
120 -- Insert the list of action Ins_Actions at the appropriate point as
121 -- described above. The actions are analyzed using the default checks
122 -- after they are inserted. Assoc_Node is the node with which the actions
123 -- are associated. Ins_Actions may be No_List, in which case the call has
124 -- no effect. When flag Spec_Expr_OK is set, insertions triggered in the
125 -- context of spec expressions are honored, even though they contradict
126 -- "Handling of Default and Per-Object Expressions".
128 procedure Insert_Actions
129 (Assoc_Node
: Node_Id
;
130 Ins_Actions
: List_Id
;
132 Spec_Expr_OK
: Boolean := False);
133 -- Insert the list of action Ins_Actions at the appropriate point as
134 -- described above. The actions are analyzed using the default checks
135 -- as modified by the given Suppress argument after they are inserted.
136 -- Assoc_Node is the node with which the actions are associated. List
137 -- Ins_Actions may be No_List, in which case the call has no effect.
138 -- When flag Spec_Expr_OK is set, insertions triggered in the context of
139 -- spec expressions are honored, even though they contradict "Handling
140 -- of Default and Per-Object Expressions".
142 procedure Insert_Action_After
143 (Assoc_Node
: Node_Id
;
144 Ins_Action
: Node_Id
);
145 -- Assoc_Node must be a node in a list. Same as Insert_Action but the
146 -- action will be inserted after N in a manner that is compatible with
147 -- the transient scope mechanism.
149 -- Note: If several successive calls to Insert_Action_After are made for
150 -- the same node, they will each in turn be inserted just after the node.
151 -- This means they will end up being executed in reverse order. Use the
152 -- call to Insert_Actions_After to insert a list of actions to be executed
153 -- in the sequence in which they are given in the list.
155 procedure Insert_Actions_After
156 (Assoc_Node
: Node_Id
;
157 Ins_Actions
: List_Id
);
158 -- Assoc_Node must be a node in a list. Same as Insert_Actions but
159 -- actions will be inserted after N in a manner that is compatible with
160 -- the transient scope mechanism. This procedure must be used instead
161 -- of Insert_List_After if Assoc_Node may be in a transient scope.
163 -- Implementation limitation: Assoc_Node must be a statement. We can
164 -- generalize to expressions if there is a need but this is tricky to
165 -- implement because of short-circuits (among other things).
167 procedure Insert_Library_Level_Action
(N
: Node_Id
);
168 -- This procedure inserts and analyzes the node N as an action at the
169 -- library level for the current unit (i.e. it is attached to the
170 -- Actions field of the N_Compilation_Aux node for the main unit).
172 procedure Insert_Library_Level_Actions
(L
: List_Id
);
173 -- Similar, but inserts a list of actions
175 -----------------------
176 -- Other Subprograms --
177 -----------------------
179 procedure Activate_Atomic_Synchronization
(N
: Node_Id
);
180 -- N is a node for which atomic synchronization may be required (it is
181 -- either an identifier, expanded name, or selected/indexed component or
182 -- an explicit dereference). The caller has checked the basic conditions
183 -- (atomic variable appearing and Atomic_Sync not disabled). This function
184 -- checks if atomic synchronization is required and if so sets the flag
185 -- and if appropriate generates a warning (in -gnatw.n mode).
187 procedure Adjust_Condition
(N
: Node_Id
);
188 -- The node N is an expression whose root-type is Boolean, and which
189 -- represents a boolean value used as a condition (i.e. a True/False
190 -- value). This routine handles the case of C and Fortran convention
191 -- boolean types, which have zero/non-zero semantics rather than the normal
192 -- 0/1 semantics, and also the case of an enumeration rep clause that
193 -- specifies a non-standard representation. On return, node N always has
194 -- the type Standard.Boolean, with a value that is a standard Boolean
195 -- values of 0/1 for False/True. This procedure is used in two situations.
196 -- First, the processing for a condition field always calls
197 -- Adjust_Condition, so that the boolean value presented to the backend is
198 -- a standard value. Second, for the code for boolean operations such as
199 -- AND, Adjust_Condition is called on both operands, and then the operation
200 -- is done in the domain of Standard_Boolean, then Adjust_Result_Type is
201 -- called on the result to possibly reset the original type. This procedure
202 -- also takes care of validity checking if Validity_Checks = Tests.
204 procedure Adjust_Result_Type
(N
: Node_Id
; T
: Entity_Id
);
205 -- The processing of boolean operations like AND uses the procedure
206 -- Adjust_Condition so that it can operate on Standard.Boolean, which is
207 -- the only boolean type on which the backend needs to be able to implement
208 -- such operators. This means that the result is also of type
209 -- Standard.Boolean. In general the type must be reset back to the original
210 -- type to get proper semantics, and that is the purpose of this procedure.
211 -- N is the node (of type Standard.Boolean), and T is the desired type. As
212 -- an optimization, this procedure leaves the type as Standard.Boolean in
213 -- contexts where this is permissible (in particular for Condition fields,
214 -- and for operands of other logical operations higher up the tree). The
215 -- call to this procedure is completely ignored if the argument N is not of
218 procedure Append_Freeze_Action
(T
: Entity_Id
; N
: Node_Id
);
219 -- Add a new freeze action for the given type. The freeze action is
220 -- attached to the freeze node for the type. Actions will be elaborated in
221 -- the order in which they are added. Note that the added node is not
222 -- analyzed. The analyze call is found in Exp_Ch13.Expand_N_Freeze_Entity.
224 procedure Append_Freeze_Actions
(T
: Entity_Id
; L
: List_Id
);
225 -- Adds the given list of freeze actions (declarations or statements) for
226 -- the given type. The freeze actions are attached to the freeze node for
227 -- the type. Actions will be elaborated in the order in which they are
228 -- added, and the actions within the list will be elaborated in list order.
229 -- Note that the added nodes are not analyzed. The analyze call is found in
230 -- Exp_Ch13.Expand_N_Freeze_Entity.
232 function Attribute_Constrained_Static_Value
(Pref
: Node_Id
) return Boolean;
233 -- Return the static value of a statically known attribute reference
236 procedure Build_Allocate_Deallocate_Proc
238 Is_Allocate
: Boolean);
239 -- Create a custom Allocate/Deallocate to be associated with an allocation
242 -- 1) controlled objects
243 -- 2) class-wide objects
244 -- 3) any kind of object on a subpool
246 -- N must be an allocator or the declaration of a temporary variable which
247 -- represents the expression of the original allocator node, otherwise N
248 -- must be a free statement. If flag Is_Allocate is set, the generated
249 -- routine is allocate, deallocate otherwise.
251 function Build_Abort_Undefer_Block
254 Context
: Node_Id
) return Node_Id
;
255 -- Wrap statements Stmts in a block where the AT END handler contains a
256 -- call to Abort_Undefer_Direct. Context is the node which prompted the
257 -- inlining of the abort undefer routine. Note that this routine does
258 -- not install a call to Abort_Defer.
260 procedure Build_Class_Wide_Expression
261 (Pragma_Or_Expr
: Node_Id
;
263 Par_Subp
: Entity_Id
;
264 Adjust_Sloc
: Boolean);
265 -- Build the expression for an inherited class-wide condition. Pragma_Or_
266 -- _Expr is either the pragma constructed from the corresponding aspect of
267 -- the parent subprogram or the class-wide pre/postcondition built from the
268 -- parent, Subp is the overriding operation, and Par_Subp is the overridden
269 -- operation that has the condition. Adjust_Sloc is True when the sloc of
270 -- nodes traversed should be adjusted for the inherited pragma.
272 function Build_DIC_Call
275 Typ
: Entity_Id
) return Node_Id
;
276 -- Build a call to the DIC procedure for Typ with Obj_Name as the actual
279 procedure Build_DIC_Procedure_Body
281 Partial_DIC
: Boolean := False);
282 -- Create the body of the procedure which verifies the assertion expression
283 -- of pragma Default_Initial_Condition at run time. Partial_DIC indicates
284 -- that a partial DIC-checking procedure body should be built, for checking
285 -- a DIC associated with the type's partial view, and which will be called
286 -- by the main DIC procedure.
288 procedure Build_DIC_Procedure_Declaration
290 Partial_DIC
: Boolean := False);
291 -- Create the declaration of the procedure which verifies the assertion
292 -- expression of pragma Default_Initial_Condition at run time. Partial_DIC
293 -- indicates that a partial DIC-checking procedure should be declared,
294 -- for checking a DIC associated with the type's partial view, and which
295 -- will be called by the main DIC procedure.
297 procedure Build_Invariant_Procedure_Body
299 Partial_Invariant
: Boolean := False);
300 -- Create the body of the procedure which verifies the invariants of type
301 -- Typ at runtime. Flag Partial_Invariant should be set when Typ denotes a
302 -- private type, otherwise it is assumed that Typ denotes the full view of
305 procedure Build_Invariant_Procedure_Declaration
307 Partial_Invariant
: Boolean := False);
308 -- Create the declaration of the procedure which verifies the invariants of
309 -- type Typ at runtime. Flag Partial_Invariant should be set when building
310 -- the invariant procedure for a private type.
312 procedure Build_Procedure_Form
(N
: Node_Id
);
313 -- Create a procedure declaration which emulates the behavior of a function
314 -- that returns an array type, for C-compatible generation.
316 function Build_Runtime_Call
(Loc
: Source_Ptr
; RE
: RE_Id
) return Node_Id
;
317 -- Build an N_Procedure_Call_Statement calling the given runtime entity.
318 -- The call has no parameters. The first argument provides the location
319 -- information for the tree and for error messages. The call node is not
320 -- analyzed on return, the caller is responsible for analyzing it.
322 function Build_SS_Mark_Call
324 Mark
: Entity_Id
) return Node_Id
;
325 -- Build a call to routine System.Secondary_Stack.Mark. Mark denotes the
326 -- entity of the secondary stack mark.
328 function Build_SS_Release_Call
330 Mark
: Entity_Id
) return Node_Id
;
331 -- Build a call to routine System.Secondary_Stack.Release. Mark denotes the
332 -- entity of the secondary stack mark.
334 function Build_Task_Image_Decls
338 In_Init_Proc
: Boolean := False) return List_Id
;
339 -- Build declaration for a variable that holds an identifying string to be
340 -- used as a task name. Id_Ref is an identifier if the task is a variable,
341 -- and a selected or indexed component if the task is component of an
342 -- object. If it is an indexed component, A_Type is the corresponding array
343 -- type. Its index types are used to build the string as an image of the
344 -- index values. For composite types, the result includes two declarations:
345 -- one for a generated function that computes the image without using
346 -- concatenation, and one for the variable that holds the result.
348 -- If In_Init_Proc is true, the call is part of the initialization of
349 -- a component of a composite type, and the enclosing initialization
350 -- procedure must be flagged as using the secondary stack. If In_Init_Proc
351 -- is false, the call is for a stand-alone object, and the generated
352 -- function itself must do its own cleanups.
354 function Build_Temporary_On_Secondary_Stack
357 Code
: List_Id
) return Entity_Id
;
358 -- Build a temporary of type Typ on the secondary stack, appending the
359 -- necessary actions to Code, and return a constant holding the access
360 -- value designating this temporary, under the assumption that Typ does
361 -- not need finalization.
363 -- This should be used when Typ can potentially be large, to avoid putting
364 -- too much pressure on the primary stack, for example with storage models.
366 procedure Build_Transient_Object_Statements
368 Fin_Call
: out Node_Id
;
369 Hook_Assign
: out Node_Id
;
370 Hook_Clear
: out Node_Id
;
371 Hook_Decl
: out Node_Id
;
372 Ptr_Decl
: out Node_Id
;
373 Finalize_Obj
: Boolean := True);
374 -- Subsidiary to the processing of transient objects in transient scopes,
375 -- if expressions, case expressions, and expression_with_action nodes.
376 -- Obj_Decl denotes the declaration of the transient object. Generate the
379 -- * Fin_Call - the call to [Deep_]Finalize which cleans up the transient
380 -- object if flag Finalize_Obj is set to True, or finalizes the hook when
381 -- the flag is False.
383 -- * Hook_Assign - the assignment statement which captures a reference to
384 -- the transient object in the hook.
386 -- * Hook_Clear - the assignment statement which resets the hook to null
388 -- * Hook_Decl - the declaration of the hook object
390 -- * Ptr_Decl - the full type declaration of the hook type
392 -- These nodes are inserted in specific places depending on the context by
393 -- the various Process_Transient_xxx routines.
395 procedure Check_Float_Op_Overflow
(N
: Node_Id
);
396 -- Called where we could have a floating-point binary operator where we
397 -- must check for infinities if we are operating in Check_Float_Overflow
398 -- mode. Note that we don't need to worry about unary operator cases,
399 -- since for floating-point, abs, unary "-", and unary "+" can never
402 function Component_May_Be_Bit_Aligned
(Comp
: Entity_Id
) return Boolean;
403 -- This function is in charge of detecting record components that may cause
404 -- trouble for the back end if an attempt is made to access the component
405 -- as a whole. The back end can handle such accesses with no problem if the
406 -- components involved are small (64 bits or less) records or scalar items
407 -- (including bit-packed arrays represented with a modular type), or else
408 -- if they are aligned on byte boundaries (i.e. starting on a byte boundary
409 -- and occupying an integral number of bytes).
411 -- However, problems arise for records larger than 64 bits, or for arrays
412 -- (other than bit-packed arrays represented with a modular type) if the
413 -- component either does not start on a byte boundary or does not occupy an
414 -- integral number of bytes (i.e. there are some bits possibly shared with
415 -- other components at the start or the end of the component). The back end
416 -- cannot handle loading from or storing to such components as a whole.
418 -- This function is used to detect the troublesome situation. It is meant
419 -- to be conservative in the sense that it produces True unless it knows
420 -- for sure that the component is safe (as outlined in the first paragraph
421 -- above). The processing for record and array assignment indirectly checks
422 -- for trouble using this function and, if so, the assignment is expanded
423 -- component-wise, which the back end is required to handle correctly.
425 procedure Convert_To_Actual_Subtype
(Exp
: Node_Id
);
426 -- The Etype of an expression is the nominal type of the expression,
427 -- not the actual subtype. Often these are the same, but not always.
428 -- For example, a reference to a formal of unconstrained type has the
429 -- unconstrained type as its Etype, but the actual subtype is obtained by
430 -- applying the actual bounds. This routine is given an expression, Exp,
431 -- and (if necessary), replaces it using Rewrite, with a conversion to
432 -- the actual subtype, building the actual subtype if necessary. If the
433 -- expression is already of the requested type, then it is unchanged.
435 function Corresponding_Runtime_Package
(Typ
: Entity_Id
) return RTU_Id
;
436 -- Return the id of the runtime package that will provide support for
437 -- concurrent type Typ. Currently only protected types are supported,
438 -- and the returned value is one of the following:
439 -- System_Tasking_Protected_Objects
440 -- System_Tasking_Protected_Objects_Entries
441 -- System_Tasking_Protected_Objects_Single_Entry
443 function Current_Sem_Unit_Declarations
return List_Id
;
444 -- Return the place where it is fine to insert declarations for the
445 -- current semantic unit. If the unit is a package body, return the
446 -- visible declarations of the corresponding spec. For RCI stubs, this
447 -- is necessary because the point at which they are generated may not
448 -- be the earliest point at which they are used.
450 function Duplicate_Subexpr
452 Name_Req
: Boolean := False;
453 Renaming_Req
: Boolean := False) return Node_Id
;
454 -- Given the node for a subexpression, this function makes a logical copy
455 -- of the subexpression, and returns it. This is intended for use when the
456 -- expansion of an expression needs to repeat part of it. For example,
457 -- replacing a**2 by a*a requires two references to a which may be a
458 -- complex subexpression. Duplicate_Subexpr guarantees not to duplicate
459 -- side effects. If necessary, it generates actions to save the expression
460 -- value in a temporary, inserting these actions into the tree using
461 -- Insert_Actions with Exp as the insertion location. The original
462 -- expression and the returned result then become references to this saved
463 -- value. Exp must be analyzed on entry. On return, Exp is analyzed, but
464 -- the caller is responsible for analyzing the returned copy after it is
465 -- attached to the tree.
467 -- The Name_Req flag is set to ensure that the result is suitable for use
468 -- in a context requiring a name (for example, the prefix of an attribute
471 -- The Renaming_Req flag is set to produce an object renaming declaration
472 -- rather than an object declaration. This is valid only if the expression
473 -- Exp designates a renamable object. This is used for example in the case
474 -- of an unchecked deallocation, to make sure the object gets set to null.
476 -- Note that if there are any run time checks in Exp, these same checks
477 -- will be duplicated in the returned duplicated expression. The two
478 -- following functions allow this behavior to be modified.
480 function Duplicate_Subexpr_No_Checks
482 Name_Req
: Boolean := False;
483 Renaming_Req
: Boolean := False;
484 Related_Id
: Entity_Id
:= Empty
;
485 Is_Low_Bound
: Boolean := False;
486 Is_High_Bound
: Boolean := False) return Node_Id
;
487 -- Identical in effect to Duplicate_Subexpr, except that Remove_Checks is
488 -- called on the result, so that the duplicated expression does not include
489 -- checks. This is appropriate for use when Exp, the original expression is
490 -- unconditionally elaborated before the duplicated expression, so that
491 -- there is no need to repeat any checks.
493 -- Related_Id denotes the entity of the context where Expr appears. Flags
494 -- Is_Low_Bound and Is_High_Bound specify whether the expression to check
495 -- is the low or the high bound of a range. These three optional arguments
496 -- signal Remove_Side_Effects to create an external symbol of the form
497 -- Chars (Related_Id)_FIRST/_LAST. For suggested use of these parameters
498 -- see the warning in the body of Sem_Ch3.Process_Range_Expr_In_Decl.
500 function Duplicate_Subexpr_Move_Checks
502 Name_Req
: Boolean := False;
503 Renaming_Req
: Boolean := False) return Node_Id
;
504 -- Identical in effect to Duplicate_Subexpr, except that Remove_Checks is
505 -- called on Exp after the duplication is complete, so that the original
506 -- expression does not include checks. In this case the result returned
507 -- (the duplicated expression) will retain the original checks. This is
508 -- appropriate for use when the duplicated expression is sure to be
509 -- elaborated before the original expression Exp, so that there is no need
510 -- to repeat the checks.
512 function Enclosing_Init_Proc
return Entity_Id
;
513 -- Obtain the entity of the type initialization procedure which encloses
514 -- the current scope. Return Empty if no such procedure exists.
516 procedure Ensure_Defined
(Typ
: Entity_Id
; N
: Node_Id
);
517 -- This procedure ensures that type referenced by Typ is defined. For the
518 -- case of a type other than an Itype, nothing needs to be done, since
519 -- all such types have declaration nodes. For Itypes, an N_Itype_Reference
520 -- node is generated and inserted as an action on node N. This is typically
521 -- used to ensure that an Itype is properly defined outside a conditional
522 -- construct when it is referenced in more than one branch.
524 procedure Evaluate_Name
(Nam
: Node_Id
);
525 -- Remove all side effects from a name which appears as part of an object
526 -- renaming declaration. Similarly to Force_Evaluation, it removes the
527 -- side effects and captures the values of the variables, except for the
528 -- variable being renamed. Hence this differs from Force_Evaluation and
529 -- Remove_Side_Effects (but it calls Force_Evaluation on subexpressions
530 -- whose value needs to be fixed).
532 procedure Evolve_And_Then
(Cond
: in out Node_Id
; Cond1
: Node_Id
);
533 -- Rewrites Cond with the expression: Cond and then Cond1. If Cond is
534 -- Empty, then simply returns Cond1 (this allows the use of Empty to
535 -- initialize a series of checks evolved by this routine, with a final
536 -- result of Empty indicating that no checks were required). The Sloc field
537 -- of the constructed N_And_Then node is copied from Cond1.
539 procedure Evolve_Or_Else
(Cond
: in out Node_Id
; Cond1
: Node_Id
);
540 -- Rewrites Cond with the expression: Cond or else Cond1. If Cond is Empty,
541 -- then simply returns Cond1 (this allows the use of Empty to initialize a
542 -- series of checks evolved by this routine, with a final result of Empty
543 -- indicating that no checks were required). The Sloc field of the
544 -- constructed N_Or_Else node is copied from Cond1.
546 procedure Expand_Sliding_Conversion
(N
: Node_Id
; Arr_Typ
: Entity_Id
);
547 -- When sliding is needed for an array object N in the context of an
548 -- unconstrained array type Arr_Typ with fixed lower bound (FLB), create
549 -- a subtype with appropriate index constraint (FLB .. N'Length + FLB - 1)
550 -- and apply a conversion from N to that subtype.
552 procedure Expand_Static_Predicates_In_Choices
(N
: Node_Id
);
553 -- N is either a case alternative or a variant. The Discrete_Choices field
554 -- of N points to a list of choices. If any of these choices is the name
555 -- of a (statically) predicated subtype, then it is rewritten as the series
556 -- of choices that correspond to the values allowed for the subtype.
558 procedure Expand_Subtype_From_Expr
560 Unc_Type
: Entity_Id
;
561 Subtype_Indic
: Node_Id
;
563 Related_Id
: Entity_Id
:= Empty
);
564 -- Build a constrained subtype from the initial value in object
565 -- declarations and/or allocations when the type is indefinite (including
566 -- class-wide). Set Related_Id to request an external name for the subtype
567 -- rather than an internal temporary.
569 function Expression_Contains_Primitives_Calls_Of
571 Typ
: Entity_Id
) return Boolean;
572 -- Return True if the expression Expr contains a nondispatching call to a
573 -- function which is a primitive of the tagged type Typ.
575 function Finalize_Address
(Typ
: Entity_Id
) return Entity_Id
;
576 -- Locate TSS primitive Finalize_Address in type Typ. Return Empty if the
577 -- subprogram is not available.
579 function Find_Interface_ADT
581 Iface
: Entity_Id
) return Elmt_Id
;
582 -- Ada 2005 (AI-251): Given a type T implementing the interface Iface,
583 -- return the element of Access_Disp_Table containing the tag of the
586 function Find_Interface_Tag
588 Iface
: Entity_Id
) return Entity_Id
;
589 -- Ada 2005 (AI-251): Given a type T and an interface Iface, return the
590 -- record component containing the tag of Iface if T implements Iface or
591 -- Empty if it does not.
593 -- WARNING: There is a matching C declaration of this subprogram in fe.h
595 function Find_Prim_Op
(T
: Entity_Id
; Name
: Name_Id
) return Entity_Id
;
596 -- Find the first primitive operation of a tagged type T with name Name.
597 -- This function allows the use of a primitive operation which is not
598 -- directly visible. If T is a class-wide type, then the reference is to an
599 -- operation of the corresponding root type. It is an error if no primitive
600 -- operation with the given name is found.
602 function Find_Prim_Op
604 Name
: TSS_Name_Type
) return Entity_Id
;
605 -- Same as Find_Prim_Op above, except we're searching for an op that has
606 -- the form indicated by Name (i.e. is a type support subprogram with the
607 -- indicated suffix).
609 function Find_Optional_Prim_Op
610 (T
: Entity_Id
; Name
: Name_Id
) return Entity_Id
;
611 function Find_Optional_Prim_Op
613 Name
: TSS_Name_Type
) return Entity_Id
;
614 -- Same as Find_Prim_Op, except returns Empty if not found
616 function Find_Protection_Object
(Scop
: Entity_Id
) return Entity_Id
;
617 -- Traverse the scope stack starting from Scop and look for an entry, entry
618 -- family, or a subprogram that has a Protection_Object and return it. Must
619 -- always return a value since the context in which this routine is invoked
620 -- should always have a protection object.
622 function Find_Protection_Type
(Conc_Typ
: Entity_Id
) return Entity_Id
;
623 -- Given a protected type or its corresponding record, find the type of
626 function Find_Storage_Op
628 Nam
: Name_Id
) return Entity_Id
;
629 -- Given type Typ that's either a descendant of Root_Storage_Pool or else
630 -- specifies aspect Storage_Model_Type, returns the Entity_Id of the
631 -- subprogram associated with Nam, which must either be a primitive op of
632 -- the type in the case of a storage pool, or the operation corresponding
633 -- to Nam as specified in the aspect Storage_Model_Type. In the case of
634 -- aspect Storage_Model_Type, returns Empty when no operation is found,
635 -- indicating that the operation is defaulted in the aspect (can occur in
636 -- the case where the storage-model address type is System.Address).
638 function Find_Hook_Context
(N
: Node_Id
) return Node_Id
;
639 -- Determine a suitable node on which to attach actions related to N that
640 -- need to be elaborated unconditionally. In general this is the topmost
641 -- expression of which N is a subexpression, which in turn may or may not
642 -- be evaluated, for example if N is the right operand of a short circuit
645 function Following_Address_Clause
(D
: Node_Id
) return Node_Id
;
646 -- D is the node for an object declaration. This function searches the
647 -- current declarative part to look for an address clause for the object
648 -- being declared, and returns the clause if one is found, returns
651 type Force_Evaluation_Mode
is (Relaxed
, Strict
);
653 procedure Force_Evaluation
655 Name_Req
: Boolean := False;
656 Related_Id
: Entity_Id
:= Empty
;
657 Is_Low_Bound
: Boolean := False;
658 Is_High_Bound
: Boolean := False;
659 Discr_Number
: Int
:= 0;
660 Mode
: Force_Evaluation_Mode
:= Relaxed
);
661 -- Force the evaluation of the expression right away. Similar behavior
662 -- to Remove_Side_Effects when Variable_Ref is set to TRUE. That is to
663 -- say, it removes the side effects and captures the values of the
664 -- variables. Remove_Side_Effects guarantees that multiple evaluations
665 -- of the same expression won't generate multiple side effects, whereas
666 -- Force_Evaluation further guarantees that all evaluations will yield
667 -- the same result. If Mode is Relaxed then calls to this subprogram have
668 -- no effect if Exp is side-effect free; if Mode is Strict and Exp is not
669 -- a static expression then no side-effect check is performed on Exp and
670 -- temporaries are unconditionally generated.
672 -- Related_Id denotes the entity of the context where Expr appears. Flags
673 -- Is_Low_Bound and Is_High_Bound specify whether the expression to check
674 -- is the low or the high bound of a range. These three optional arguments
675 -- signal Remove_Side_Effects to create an external symbol of the form
676 -- Chars (Related_Id)_FIRST/_LAST. If Related_Id is set, then exactly one
677 -- of the Is_xxx_Bound flags must be set. For use of these parameters see
678 -- the warning in the body of Sem_Ch3.Process_Range_Expr_In_Decl.
680 -- Discr_Number is positive when the expression is a discriminant value
681 -- in an object or component declaration. In that case Discr_Number is
682 -- the position of the corresponding discriminant in the corresponding
683 -- type declaration, and the name for the evaluated expression is built
684 -- out of the Related_Id and the Discr_Number.
686 function Fully_Qualified_Name_String
688 Append_NUL
: Boolean := True) return String_Id
;
689 -- Generates the string literal corresponding to the fully qualified name
690 -- of entity E, in all upper case, with an ASCII.NUL appended at the end
691 -- of the name if Append_NUL is True.
693 procedure Get_Current_Value_Condition
696 Val
: out Node_Id
) with Post
=> Val
/= Var
;
697 -- This routine processes the Current_Value field of the variable Var. If
698 -- the Current_Value field is null or if it represents a known value, then
699 -- on return Cond is set to N_Empty, and Val is set to Empty.
701 -- The other case is when Current_Value points to an N_If_Statement or an
702 -- N_Elsif_Part or a N_Iteration_Scheme node (see description in Einfo for
703 -- exact details). In this case, Get_Current_Condition digs out the
704 -- condition, and then checks if the condition is known false, known true,
705 -- or not known at all. In the first two cases, Get_Current_Condition will
706 -- return with Op set to the appropriate conditional operator (inverted if
707 -- the condition is known false), and Val set to the constant value. If the
708 -- condition is not known, then Op and Val are set for the empty case
709 -- (N_Empty and Empty).
711 -- The check for whether the condition is true/false unknown depends
714 -- For an IF, the condition is known true in the THEN part, known false
715 -- in any ELSIF or ELSE part, and not known outside the IF statement in
718 -- For an ELSIF, the condition is known true in the ELSIF part, known
719 -- FALSE in any subsequent ELSIF, or ELSE part, and not known before the
720 -- ELSIF, or after the end of the IF statement.
722 -- The caller can use this result to determine the value (for the case of
723 -- N_Op_Eq), or to determine the result of some other test in other cases
724 -- (e.g. no access check required if N_Op_Ne Null).
726 function Get_Index_Subtype
(N
: Node_Id
) return Entity_Id
;
727 -- Used for First, Last, and Length, when the prefix is an array type.
728 -- Obtains the corresponding index subtype.
730 function Get_Mapped_Entity
(E
: Entity_Id
) return Entity_Id
;
731 -- Return the mapped entity of E; used to check inherited class-wide
732 -- pre/postconditions.
734 function Get_Stream_Size
(E
: Entity_Id
) return Uint
;
735 -- Return the stream size value of the subtype E
737 function Has_Access_Constraint
(E
: Entity_Id
) return Boolean;
738 -- Given object or type E, determine if a discriminant is of an access type
740 function Has_Tag_Of_Type
(Exp
: Node_Id
) return Boolean;
741 -- Return True if expression Exp of a tagged type is known to statically
742 -- have the tag of this tagged type as specified by RM 3.9(19-25).
744 function Homonym_Number
(Subp
: Entity_Id
) return Pos
;
745 -- Here subp is the entity for a subprogram. This routine returns the
746 -- homonym number used to disambiguate overloaded subprograms in the same
747 -- scope (the number is used as part of constructed names to make sure that
748 -- they are unique). The number is the ordinal position on the Homonym
749 -- chain, counting only entries in the current scope. If an entity is not
750 -- overloaded, the returned number will be one.
752 function Inside_Init_Proc
return Boolean;
753 -- Returns True if current scope is within an init proc
755 function In_Library_Level_Package_Body
(Id
: Entity_Id
) return Boolean;
756 -- Given an arbitrary entity, determine whether it appears at the library
757 -- level of a package body.
759 function In_Unconditional_Context
(Node
: Node_Id
) return Boolean;
760 -- Node is the node for a statement or a component of a statement. This
761 -- function determines if the statement appears in a context that is
762 -- unconditionally executed, i.e. it is not within a loop or a conditional
763 -- or a case statement etc.
765 function Integer_Type_For
(S
: Uint
; Uns
: Boolean) return Entity_Id
;
766 -- Return a suitable standard integer type containing at least S bits and
767 -- of the signedness given by Uns. See also Small_Integer_Type_For.
769 function Is_Captured_Function_Call
(N
: Node_Id
) return Boolean;
770 -- Return True if N is a captured function call, i.e. the result of calling
771 -- Remove_Side_Effects on an N_Function_Call node:
773 -- type Ann is access all Typ;
774 -- Rnn : constant Ann := Func (...)'reference;
777 function Is_Finalizable_Transient
779 Rel_Node
: Node_Id
) return Boolean;
780 -- Determine whether declaration Decl denotes a controlled transient which
781 -- should be finalized. Rel_Node is the related context. Even though some
782 -- transients are controlled, they may act as renamings of other objects or
785 function Is_Fully_Repped_Tagged_Type
(T
: Entity_Id
) return Boolean;
786 -- Tests given type T, and returns True if T is a non-discriminated tagged
787 -- type which has a record representation clause that specifies the layout
788 -- of all the components, including recursively components in all parent
789 -- types. We exclude discriminated types for convenience, it is extremely
790 -- unlikely that the special processing associated with the use of this
791 -- routine is useful for the case of a discriminated type, and testing for
792 -- component overlap would be a pain.
794 -- WARNING: There is a matching C declaration of this subprogram in fe.h
796 function Is_Library_Level_Tagged_Type
(Typ
: Entity_Id
) return Boolean;
797 -- Return True if Typ is a library level tagged type. Currently we use
798 -- this information to build statically allocated dispatch tables.
800 function Is_Non_BIP_Func_Call
(Expr
: Node_Id
) return Boolean;
801 -- Determine whether node Expr denotes a non build-in-place function call
803 function Is_Possibly_Unaligned_Object
(N
: Node_Id
) return Boolean;
804 -- Node N is an object reference. This function returns True if it is
805 -- possible that the object may not be aligned according to the normal
806 -- default alignment requirement for its type (e.g. if it appears in a
807 -- packed record, or as part of a component that has a component clause.)
809 function Is_Possibly_Unaligned_Slice
(N
: Node_Id
) return Boolean;
810 -- Determine whether the node P is a slice of an array where the slice
811 -- result may cause alignment problems because it has an alignment that
812 -- is not compatible with the type. Return True if so.
814 function Is_Ref_To_Bit_Packed_Array
(N
: Node_Id
) return Boolean;
815 -- Determine whether the node P is a reference to a bit packed array, i.e.
816 -- whether the designated object is a component of a bit packed array, or a
817 -- subcomponent of such a component. If so, then all subscripts in P are
818 -- evaluated with a call to Force_Evaluation, and True is returned.
819 -- Otherwise False is returned, and P is not affected.
821 function Is_Ref_To_Bit_Packed_Slice
(N
: Node_Id
) return Boolean;
822 -- Determine whether the node P is a reference to a bit packed slice, i.e.
823 -- whether the designated object is bit packed slice or a component of a
824 -- bit packed slice. Return True if so.
826 function Is_Related_To_Func_Return
(Id
: Entity_Id
) return Boolean;
827 -- Determine whether object Id is related to an expanded return statement.
828 -- The case concerned is "return Id.all;".
830 -- This is effectively used to determine which temporaries generated for
831 -- return statements must be finalized because they are regular temporaries
832 -- and which ones must not be since they are allocated on the return stack.
834 -- WARNING: There is a matching C declaration of this subprogram in fe.h
836 function Is_Renamed_Object
(N
: Node_Id
) return Boolean;
837 -- Returns True if the node N is a renamed object. An expression is
838 -- considered to be a renamed object if either it is the Name of an object
839 -- renaming declaration, or is the prefix of a name which is a renamed
840 -- object. For example, in:
842 -- x : r renames a (1 .. 2) (1);
844 -- We consider that a (1 .. 2) is a renamed object since it is the prefix
845 -- of the name in the renaming declaration.
847 function Is_Secondary_Stack_BIP_Func_Call
(Expr
: Node_Id
) return Boolean;
848 -- Determine whether Expr denotes a build-in-place function which returns
849 -- its result on the secondary stack.
851 function Is_Secondary_Stack_Thunk
(Id
: Entity_Id
) return Boolean;
852 -- Determine whether Id denotes a secondary stack thunk
854 -- WARNING: There is a matching C declaration of this subprogram in fe.h
856 function Is_Untagged_Derivation
(T
: Entity_Id
) return Boolean;
857 -- Returns true if type T is not tagged and is a derived type,
858 -- or is a private type whose completion is such a type.
860 function Is_Untagged_Private_Derivation
861 (Priv_Typ
: Entity_Id
;
862 Full_Typ
: Entity_Id
) return Boolean;
863 -- Determine whether private type Priv_Typ and its full view Full_Typ
864 -- represent an untagged derivation from a private parent.
866 function Is_Volatile_Reference
(N
: Node_Id
) return Boolean;
867 -- Checks if the node N represents a volatile reference, which can be
868 -- either a direct reference to a variable treated as volatile, or an
869 -- indexed/selected component where the prefix is treated as volatile,
870 -- or has Volatile_Components set. A slice of a volatile variable is
873 procedure Kill_Dead_Code
(N
: Node_Id
; Warn
: Boolean := False);
874 -- N represents a node for a section of code that is known to be dead. Any
875 -- exception handler references and warning messages relating to this code
876 -- are removed. If Warn is True, a warning will be output at the start of N
877 -- indicating the deletion of the code. Note that the tree for the deleted
878 -- code is left intact so that e.g. cross-reference data is still valid.
880 procedure Kill_Dead_Code
(L
: List_Id
; Warn
: Boolean := False);
881 -- Like the above procedure, but applies to every element in the given
882 -- list. If Warn is True, a warning will be output at the start of N
883 -- indicating the deletion of the code.
885 function Make_Invariant_Call
(Expr
: Node_Id
) return Node_Id
;
886 -- Generate a call to the Invariant_Procedure associated with the type of
887 -- expression Expr. Expr is passed as an actual parameter in the call.
889 function Make_Predicate_Call
892 Static_Mem
: Boolean := False;
893 Dynamic_Mem
: Node_Id
:= Empty
) return Node_Id
;
894 -- Typ is a type with Predicate_Function set. This routine builds a call to
895 -- this function passing Expr as the argument, and returns it unanalyzed.
896 -- If the callee takes a second parameter (as determined by
897 -- Sem_Util.Predicate_Function_Needs_Membership_Parameter), then the
898 -- actual parameter is determined by the two Mem parameters.
899 -- If Dynamic_Mem is nonempty, then Dynamic_Mem is the actual parameter.
900 -- Otherwise, the value of the Static_Mem parameter is passed in as
901 -- a Boolean literal. It is an error if Dynamic_Mem is nonempty but
902 -- the callee does not take a second parameter.
904 function Make_Predicate_Check
906 Expr
: Node_Id
) return Node_Id
;
907 -- Typ is a type with Predicate_Function set. This routine builds a Check
908 -- pragma whose first argument is Predicate, and the second argument is
909 -- a call to the predicate function of Typ with Expr as the argument. If
910 -- Predicate_Check is suppressed then a null statement is returned instead.
912 function Make_Subtype_From_Expr
915 Related_Id
: Entity_Id
:= Empty
) return Node_Id
;
916 -- Returns a subtype indication corresponding to the actual type of an
917 -- expression E. Unc_Typ is an unconstrained array or record, or a class-
918 -- wide type. Set Related_Id to request an external name for the subtype
919 -- rather than an internal temporary.
921 function Make_Tag_Assignment_From_Type
924 Typ
: Entity_Id
) return Node_Id
;
925 -- Return an assignment of the tag of tagged type Typ to prefix Target,
926 -- which must be a record object of a descendant of Typ.
928 function Make_Variant_Comparison
933 Old_Val
: Node_Id
) return Node_Id
;
934 -- Subsidiary to the expansion of pragmas Loop_Variant and
935 -- Subprogram_Variant. Generate a comparison between Curr_Val and Old_Val
936 -- depending on the variant mode (Increases / Decreases) using less or
937 -- greater operator for Typ.
939 procedure Map_Formals
940 (Parent_Subp
: Entity_Id
;
941 Derived_Subp
: Entity_Id
;
942 Force_Update
: Boolean := False);
943 -- Establish the mapping from the formals of Parent_Subp to the formals
944 -- of Derived_Subp; if Force_Update is True then mapping of Parent_Subp to
945 -- Derived_Subp is also updated; used to update mapping of late-overriding
946 -- primitives of a tagged type.
948 procedure Map_Types
(Parent_Type
: Entity_Id
; Derived_Type
: Entity_Id
);
949 -- Establish the following mapping between the attributes of tagged parent
950 -- type Parent_Type and tagged derived type Derived_Type.
952 -- * Map each discriminant of Parent_Type to either the corresponding
953 -- discriminant of Derived_Type or come constraint.
955 -- * Map each primitive operation of Parent_Type to the corresponding
956 -- primitive of Derived_Type.
958 -- The mapping Parent_Type -> Derived_Type is also added to the table in
959 -- order to prevent subsequent attempts of the same mapping.
961 function Matching_Standard_Type
(Typ
: Entity_Id
) return Entity_Id
;
962 -- Given a scalar subtype Typ, returns a matching type in standard that
963 -- has the same object size value. For example, a 16 bit signed type will
964 -- typically return Standard_Short_Integer. For fixed-point types, this
965 -- will return integer types of the corresponding size.
967 function May_Generate_Large_Temp
(Typ
: Entity_Id
) return Boolean;
968 -- Determines if the given type, Typ, may require a large temporary of the
969 -- kind that causes back-end trouble if stack checking is enabled. The
970 -- result is True only the size of the type is known at compile time and
971 -- large, where large is defined heuristically by the body of this routine.
972 -- The purpose of this routine is to help avoid generating troublesome
973 -- temporaries that interfere with stack checking mechanism. Note that the
974 -- caller has to check whether stack checking is actually enabled in order
975 -- to guide the expansion (typically of a function call).
977 function Needs_Conditional_Null_Excluding_Check
978 (Typ
: Entity_Id
) return Boolean;
979 -- Check if a type meets certain properties that require it to have a
980 -- conditional null-excluding check within its Init_Proc.
982 function Needs_Constant_Address
984 Typ
: Entity_Id
) return Boolean;
985 -- Check whether the expression in an address clause is restricted to
986 -- consist of constants, when the object has a nontrivial initialization
989 function OK_To_Do_Constant_Replacement
(E
: Entity_Id
) return Boolean;
990 -- This function is used when testing whether or not to replace a reference
991 -- to entity E by a known constant value. Such replacement must be done
992 -- only in a scope known to be safe for such replacements. In particular,
993 -- if we are within a subprogram and the entity E is declared outside the
994 -- subprogram then we cannot do the replacement, since we do not attempt to
995 -- trace subprogram call flow. It is also unsafe to replace statically
996 -- allocated values (since they can be modified outside the scope), and we
997 -- also inhibit replacement of Volatile or aliased objects since their
998 -- address might be captured in a way we do not detect. A value of True is
999 -- returned only if the replacement is safe.
1001 function Possible_Bit_Aligned_Component
(N
: Node_Id
) return Boolean;
1002 -- This function is used during processing the assignment of a record or an
1003 -- array, or the construction of an aggregate. The argument N is either the
1004 -- left or the right hand side of an assignment and the function determines
1005 -- whether there is a record component reference where the component may be
1006 -- bit aligned in a manner that causes trouble for the back end (see also
1007 -- Component_May_Be_Bit_Aligned for further details).
1009 function Power_Of_Two
(N
: Node_Id
) return Nat
;
1010 -- Determines if N is a known at compile time value which is of the form
1011 -- 2**K, where K is in the range 1 .. M, where the Esize of N is 2**(M+1).
1012 -- If so, returns the value K, otherwise returns zero. The caller checks
1013 -- that N is of an integer type.
1015 function Predicate_Check_In_Scope
(N
: Node_Id
) return Boolean;
1016 -- Return True if predicate checks should be generated in the current
1017 -- scope on the given node. Will return False for example when the current
1018 -- scope is a predefined primitive operation.
1020 procedure Process_Statements_For_Controlled_Objects
(N
: Node_Id
);
1021 -- N is a node which contains a non-handled statement list. Inspect the
1022 -- statements looking for declarations of controlled objects. If at least
1023 -- one such object is found, wrap the statement list in a block.
1025 function Remove_Init_Call
1027 Rep_Clause
: Node_Id
) return Node_Id
;
1028 -- Look for init_proc call or aggregate initialization statements for
1029 -- variable Var, either among declarations between that of Var and a
1030 -- subsequent Rep_Clause applying to Var, or in the list of freeze actions
1031 -- associated with Var, and if found, remove and return that call node.
1033 procedure Remove_Side_Effects
1035 Name_Req
: Boolean := False;
1036 Renaming_Req
: Boolean := False;
1037 Variable_Ref
: Boolean := False;
1038 Related_Id
: Entity_Id
:= Empty
;
1039 Is_Low_Bound
: Boolean := False;
1040 Is_High_Bound
: Boolean := False;
1041 Discr_Number
: Int
:= 0;
1042 Check_Side_Effects
: Boolean := True);
1043 -- Given the node for a subexpression, this function replaces the node if
1044 -- necessary by an equivalent subexpression that is guaranteed to be side
1045 -- effect free. This is done by extracting any actions that could cause
1046 -- side effects, and inserting them using Insert_Actions into the tree
1047 -- to which Exp is attached. Exp must be analyzed and resolved before the
1048 -- call and is analyzed and resolved on return. Name_Req may only be set to
1049 -- True if Exp has the form of a name, and the effect is to guarantee that
1050 -- any replacement maintains the form of name. If Renaming_Req is set to
1051 -- True, the routine produces an object renaming reclaration capturing the
1052 -- expression. If Variable_Ref is set to True, a variable is considered as
1053 -- side effect (used in implementing Force_Evaluation). Note: after call to
1054 -- Remove_Side_Effects, it is safe to call New_Copy_Tree to obtain a copy
1055 -- of the resulting expression. If Check_Side_Effects is set to True then
1056 -- no action is performed if Exp is known to be side-effect free.
1058 -- Related_Id denotes the entity of the context where Expr appears. Flags
1059 -- Is_Low_Bound and Is_High_Bound specify whether the expression to check
1060 -- is the low or the high bound of a range. These three optional arguments
1061 -- signal Remove_Side_Effects to create an external symbol of the form
1062 -- Chars (Related_Id)_FIRST/_LAST. If Related_Id is set, then exactly one
1063 -- of the Is_xxx_Bound flags must be set. For use of these parameters see
1064 -- the warning in the body of Sem_Ch3.Process_Range_Expr_In_Decl.
1066 -- If Discr_Number is positive, the expression denotes a discrimant value
1067 -- in a constraint, the suffix DISCR is used to create the external name.
1069 -- The side effects are captured using one of the following methods:
1071 -- 1) a constant initialized with the value of the subexpression
1072 -- 2) a renaming of the subexpression
1073 -- 3) a reference to the subexpression
1075 -- For elementary types, methods 1) and 2) are used; for composite types,
1076 -- methods 2) and 3) are used. The renaming (method 2) is used only when
1077 -- the subexpression denotes a name, so that it can be elaborated by gigi
1078 -- without evaluating the subexpression.
1080 -- Historical note: the reference (method 3) used to be the common fallback
1081 -- method but it gives rise to aliasing issues if the subexpression denotes
1082 -- a name that is not aliased, since it is equivalent to taking the address
1083 -- in this case. The renaming (method 2) used to be applied to any objects
1084 -- in the RM sense, that is to say to the cases where a renaming is legal
1085 -- in Ada. But for some of these cases, most notably functions calls, the
1086 -- renaming cannot be elaborated without evaluating the subexpression, so
1087 -- gigi would resort to method 1) or 3) under the hood for them.
1089 procedure Replace_References
1091 Par_Typ
: Entity_Id
;
1092 Deriv_Typ
: Entity_Id
;
1093 Par_Obj
: Entity_Id
:= Empty
;
1094 Deriv_Obj
: Entity_Id
:= Empty
);
1095 -- Expr denotes an arbitrary expression. Par_Typ is a tagged parent type
1096 -- in a type hierarchy. Deriv_Typ is a tagged type derived from Par_Typ
1097 -- with optional ancestors in between. Par_Obj is a formal parameter
1098 -- which emulates the current instance of Par_Typ. Deriv_Obj is a formal
1099 -- parameter which emulates the current instance of Deriv_Typ. Perform the
1100 -- following substitutions in Expr:
1102 -- * Replace a reference to Par_Obj with a reference to Deriv_Obj
1104 -- * Replace a reference to a discriminant of Par_Typ with a suitable
1105 -- value from the point of view of Deriv_Typ.
1107 -- * Replace a call to an overridden primitive of Par_Typ with a call to
1108 -- an overriding primitive of Deriv_Typ.
1110 -- * Replace a call to an inherited primitive of Par_Type with a call to
1111 -- the internally-generated inherited primitive of Deriv_Typ.
1113 procedure Replace_Type_References
1116 Obj_Id
: Entity_Id
);
1117 -- Substitute all references of the current instance of type Typ with
1118 -- references to formal parameter Obj_Id within expression Expr.
1120 function Represented_As_Scalar
(T
: Entity_Id
) return Boolean;
1121 -- Returns True iff the implementation of this type in code generation
1122 -- terms is scalar. This is true for scalars in the Ada sense, and for
1123 -- packed arrays which are represented by a scalar (modular) type.
1125 function Requires_Cleanup_Actions
1127 Lib_Level
: Boolean) return Boolean;
1128 -- Given a node N, determine whether its declarative and/or statement list
1129 -- contains one of the following:
1131 -- 1) controlled objects
1132 -- 2) library-level tagged types
1134 -- These cases require special actions on scope exit. Lib_Level is True if
1135 -- the construct is at library level, and False otherwise.
1137 function Safe_Unchecked_Type_Conversion
(Exp
: Node_Id
) return Boolean;
1138 -- Given the node for an N_Unchecked_Type_Conversion, return True if this
1139 -- is an unchecked conversion that Gigi can handle directly. Otherwise
1140 -- return False if it is one for which the front end must provide a
1141 -- temporary. Note that the node need not be analyzed, and thus the Etype
1142 -- field may not be set, but in that case it must be the case that the
1143 -- Subtype_Mark field of the node is set/analyzed.
1145 procedure Set_Current_Value_Condition
(Cnode
: Node_Id
);
1146 -- Cnode is N_If_Statement, N_Elsif_Part, or N_Iteration_Scheme (the latter
1147 -- when a WHILE condition is present). This call checks whether Condition
1148 -- (Cnode) has embedded expressions of a form that should result in setting
1149 -- the Current_Value field of one or more entities, and if so sets these
1150 -- fields to point to Cnode.
1152 procedure Set_Elaboration_Flag
(N
: Node_Id
; Spec_Id
: Entity_Id
);
1153 -- N is the node for a subprogram or generic body, and Spec_Id is the
1154 -- entity for the corresponding spec. If an elaboration entity is defined,
1155 -- then this procedure generates an assignment statement to set it True,
1156 -- immediately after the body is elaborated. However, no assignment is
1157 -- generated in the case of library level procedures, since the setting of
1158 -- the flag in this case is generated in the binder. We do that so that we
1159 -- can detect cases where this is the only elaboration action that is
1162 procedure Set_Renamed_Subprogram
(N
: Node_Id
; E
: Entity_Id
);
1163 -- N is an node which is an entity name that represents the name of a
1164 -- renamed subprogram. The node is rewritten to be an identifier that
1165 -- refers directly to the renamed subprogram, given by entity E.
1167 function Side_Effect_Free
1169 Name_Req
: Boolean := False;
1170 Variable_Ref
: Boolean := False) return Boolean;
1171 -- Determines if the tree N represents an expression that is known not
1172 -- to have side effects. If this function returns True, then for example
1173 -- a call to Remove_Side_Effects has no effect.
1175 -- Name_Req controls the handling of volatile variable references. If
1176 -- Name_Req is False (the normal case), then volatile references are
1177 -- considered to be side effects. If Name_Req is True, then volatility
1178 -- of variables is ignored.
1180 -- If Variable_Ref is True, then all variable references are considered to
1181 -- be side effects (regardless of volatility or the setting of Name_Req).
1183 function Side_Effect_Free
1185 Name_Req
: Boolean := False;
1186 Variable_Ref
: Boolean := False) return Boolean;
1187 -- Determines if all elements of the list L are side-effect free. Name_Req
1188 -- and Variable_Ref are as described above.
1190 procedure Silly_Boolean_Array_Not_Test
(N
: Node_Id
; T
: Entity_Id
);
1191 -- N is the node for a boolean array NOT operation, and T is the type of
1192 -- the array. This routine deals with the silly case where the subtype of
1193 -- the boolean array is False..False or True..True, where it is required
1194 -- that a Constraint_Error exception be raised (RM 4.5.6(6)).
1196 procedure Silly_Boolean_Array_Xor_Test
1200 -- N is the node for a boolean array XOR operation, T is the type of the
1201 -- array, and R is a copy of the right operand of N, required to prevent
1202 -- scope anomalies when unnesting is in effect. This routine deals with
1203 -- the admitedly silly case where the subtype of the boolean array is
1204 -- True..True, where a raise of a Constraint_Error exception is required
1205 -- (RM 4.5.6(6)) and ACATS-tested.
1207 function Small_Integer_Type_For
(S
: Uint
; Uns
: Boolean) return Entity_Id
;
1208 -- Return the smallest standard integer type containing at least S bits and
1209 -- of the signedness given by Uns. See also Integer_Type_For.
1211 function Thunk_Target
(Thunk
: Entity_Id
) return Entity_Id
;
1212 -- Return the entity ultimately called by the thunk, that is to say return
1213 -- the Thunk_Entity of the last member on the thunk chain.
1215 -- WARNING: There is a matching C declaration of this subprogram in fe.h
1217 function Type_May_Have_Bit_Aligned_Components
1218 (Typ
: Entity_Id
) return Boolean;
1219 -- Determines if Typ is a composite type that has within it (looking down
1220 -- recursively at subcomponents) a record which contains a component that
1221 -- may be bit aligned in a manner that causes trouble for the back end
1222 -- (see also Component_May_Be_Bit_Aligned for further details). The result
1223 -- is conservative, in that a result of False is decisive. A result of True
1224 -- means that such a component may or may not be present.
1226 procedure Update_Primitives_Mapping
1227 (Inher_Id
: Entity_Id
;
1228 Subp_Id
: Entity_Id
);
1229 -- Map primitive operations of the parent type to the corresponding
1230 -- operations of the descendant. Note that the descendant type may not be
1231 -- frozen yet, so we cannot use the dispatch table directly. This is called
1232 -- when elaborating a contract for a subprogram, and when freezing a type
1233 -- extension to verify legality rules on inherited conditions.
1235 function Within_Case_Or_If_Expression
(N
: Node_Id
) return Boolean;
1236 -- Determine whether arbitrary node N is immediately within a case or an if
1237 -- expression. The criterion is whether temporaries created by the actions
1238 -- attached to N need to outlive an enclosing case or if expression.
1241 pragma Inline
(Duplicate_Subexpr
);
1242 pragma Inline
(Force_Evaluation
);
1243 pragma Inline
(Get_Mapped_Entity
);
1244 pragma Inline
(Is_Library_Level_Tagged_Type
);
1245 pragma Inline
(Is_Secondary_Stack_Thunk
);
1246 pragma Inline
(Thunk_Target
);