1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2017, 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 Types
; use Types
;
33 with Uintp
; use Uintp
;
37 -----------------------------------------------
38 -- Handling of Actions Associated with Nodes --
39 -----------------------------------------------
41 -- The evaluation of certain expression nodes involves the elaboration
42 -- of associated types and other declarations, and the execution of
43 -- statement sequences. Expansion routines generating such actions must
44 -- find an appropriate place in the tree to hang the actions so that
45 -- they will be evaluated at the appropriate point.
47 -- Some cases are simple:
49 -- For an expression occurring in a simple statement that is in a list
50 -- of statements, the actions are simply inserted into the list before
51 -- the associated statement.
53 -- For an expression occurring in a declaration (declarations always
54 -- appear in lists), the actions are similarly inserted into the list
55 -- just before the associated declaration. ???Declarations do not always
56 -- appear in lists; in particular, a library unit declaration does not
57 -- appear in a list, and Insert_Action will crash in that case.
59 -- The following special cases arise:
61 -- For actions associated with the right operand of a short circuit
62 -- form, the actions are first stored in the short circuit form node
63 -- in the Actions field. The expansion of these forms subsequently
64 -- expands the short circuit forms into if statements which can then
65 -- be moved as described above.
67 -- For actions appearing in the Condition expression of a while loop,
68 -- or an elsif clause, the actions are similarly temporarily stored in
69 -- in the node (N_Elsif_Part or N_Iteration_Scheme) associated with
70 -- the expression using the Condition_Actions field. Subsequently, the
71 -- expansion of these nodes rewrites the control structures involved to
72 -- reposition the actions in normal statement sequence.
74 -- For actions appearing in the then or else expression of a conditional
75 -- expression, these actions are similarly placed in the node, using the
76 -- Then_Actions or Else_Actions field as appropriate. Once again the
77 -- expansion of the N_If_Expression node rewrites the node so that the
78 -- actions can be positioned normally.
80 -- For actions coming from expansion of the expression in an expression
81 -- with actions node, the action is appended to the list of actions.
83 -- Basically what we do is to climb up to the tree looking for the
84 -- proper insertion point, as described by one of the above cases,
85 -- and then insert the appropriate action or actions.
87 -- Note if more than one insert call is made specifying the same
88 -- Assoc_Node, then the actions are elaborated in the order of the
89 -- calls, and this guarantee is preserved for the special cases above.
91 procedure Insert_Action
92 (Assoc_Node
: Node_Id
;
93 Ins_Action
: Node_Id
);
94 -- Insert the action Ins_Action at the appropriate point as described
95 -- above. The action is analyzed using the default checks after it is
96 -- inserted. Assoc_Node is the node with which the action is associated.
98 procedure Insert_Action
99 (Assoc_Node
: Node_Id
;
100 Ins_Action
: Node_Id
;
101 Suppress
: Check_Id
);
102 -- Insert the action Ins_Action at the appropriate point as described
103 -- above. The action is analyzed using the default checks as modified
104 -- by the given Suppress argument after it is inserted. Assoc_Node is
105 -- the node with which the action is associated.
107 procedure Insert_Actions
108 (Assoc_Node
: Node_Id
;
109 Ins_Actions
: List_Id
);
110 -- Insert the list of action Ins_Actions at the appropriate point as
111 -- described above. The actions are analyzed using the default checks
112 -- after they are inserted. Assoc_Node is the node with which the actions
113 -- are associated. Ins_Actions may be No_List, in which case the call has
116 procedure Insert_Actions
117 (Assoc_Node
: Node_Id
;
118 Ins_Actions
: List_Id
;
119 Suppress
: Check_Id
);
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 -- as modified by the given Suppress argument after they are inserted.
123 -- Assoc_Node is the node with which the actions are associated.
124 -- Ins_Actions may be No_List, in which case the call has no effect.
126 procedure Insert_Action_After
127 (Assoc_Node
: Node_Id
;
128 Ins_Action
: Node_Id
);
129 -- Assoc_Node must be a node in a list. Same as Insert_Action but the
130 -- action will be inserted after N in a manner that is compatible with
131 -- the transient scope mechanism.
133 -- Note: If several successive calls to Insert_Action_After are made for
134 -- the same node, they will each in turn be inserted just after the node.
135 -- This means they will end up being executed in reverse order. Use the
136 -- call to Insert_Actions_After to insert a list of actions to be executed
137 -- in the sequence in which they are given in the list.
139 procedure Insert_Actions_After
140 (Assoc_Node
: Node_Id
;
141 Ins_Actions
: List_Id
);
142 -- Assoc_Node must be a node in a list. Same as Insert_Actions but
143 -- actions will be inserted after N in a manner that is compatible with
144 -- the transient scope mechanism. This procedure must be used instead
145 -- of Insert_List_After if Assoc_Node may be in a transient scope.
147 -- Implementation limitation: Assoc_Node must be a statement. We can
148 -- generalize to expressions if there is a need but this is tricky to
149 -- implement because of short-circuits (among other things).???
151 procedure Insert_Declaration
(N
: Node_Id
; Decl
: Node_Id
);
152 -- N must be a subexpression (Nkind in N_Subexpr). This is similar to
153 -- Insert_Action (N, Decl), but inserts Decl outside the expression in
154 -- which N appears. This is called Insert_Declaration because the intended
155 -- use is for declarations that have no associated code. We can't go
156 -- moving other kinds of things out of the current expression, since they
157 -- could be executed conditionally (e.g. right operand of short circuit,
158 -- or THEN/ELSE of if expression). This is currently used only in
159 -- Modify_Tree_For_C mode, where it is needed because in C we have no
160 -- way of having declarations within an expression (a really annoying
163 procedure Insert_Library_Level_Action
(N
: Node_Id
);
164 -- This procedure inserts and analyzes the node N as an action at the
165 -- library level for the current unit (i.e. it is attached to the
166 -- Actions field of the N_Compilation_Aux node for the main unit).
168 procedure Insert_Library_Level_Actions
(L
: List_Id
);
169 -- Similar, but inserts a list of actions
171 -----------------------
172 -- Other Subprograms --
173 -----------------------
175 procedure Activate_Atomic_Synchronization
(N
: Node_Id
);
176 -- N is a node for which atomic synchronization may be required (it is
177 -- either an identifier, expanded name, or selected/indexed component or
178 -- an explicit dereference). The caller has checked the basic conditions
179 -- (atomic variable appearing and Atomic_Sync not disabled). This function
180 -- checks if atomic synchronization is required and if so sets the flag
181 -- and if appropriate generates a warning (in -gnatw.n mode).
183 procedure Adjust_Condition
(N
: Node_Id
);
184 -- The node N is an expression whose root-type is Boolean, and which
185 -- represents a boolean value used as a condition (i.e. a True/False
186 -- value). This routine handles the case of C and Fortran convention
187 -- boolean types, which have zero/non-zero semantics rather than the normal
188 -- 0/1 semantics, and also the case of an enumeration rep clause that
189 -- specifies a non-standard representation. On return, node N always has
190 -- the type Standard.Boolean, with a value that is a standard Boolean
191 -- values of 0/1 for False/True. This procedure is used in two situations.
192 -- First, the processing for a condition field always calls
193 -- Adjust_Condition, so that the boolean value presented to the backend is
194 -- a standard value. Second, for the code for boolean operations such as
195 -- AND, Adjust_Condition is called on both operands, and then the operation
196 -- is done in the domain of Standard_Boolean, then Adjust_Result_Type is
197 -- called on the result to possibly reset the original type. This procedure
198 -- also takes care of validity checking if Validity_Checks = Tests.
200 procedure Adjust_Result_Type
(N
: Node_Id
; T
: Entity_Id
);
201 -- The processing of boolean operations like AND uses the procedure
202 -- Adjust_Condition so that it can operate on Standard.Boolean, which is
203 -- the only boolean type on which the backend needs to be able to implement
204 -- such operators. This means that the result is also of type
205 -- Standard.Boolean. In general the type must be reset back to the original
206 -- type to get proper semantics, and that is the purpose of this procedure.
207 -- N is the node (of type Standard.Boolean), and T is the desired type. As
208 -- an optimization, this procedure leaves the type as Standard.Boolean in
209 -- contexts where this is permissible (in particular for Condition fields,
210 -- and for operands of other logical operations higher up the tree). The
211 -- call to this procedure is completely ignored if the argument N is not of
214 procedure Append_Freeze_Action
(T
: Entity_Id
; N
: Node_Id
);
215 -- Add a new freeze action for the given type. The freeze action is
216 -- attached to the freeze node for the type. Actions will be elaborated in
217 -- the order in which they are added. Note that the added node is not
218 -- analyzed. The analyze call is found in Exp_Ch13.Expand_N_Freeze_Entity.
220 procedure Append_Freeze_Actions
(T
: Entity_Id
; L
: List_Id
);
221 -- Adds the given list of freeze actions (declarations or statements) for
222 -- the given type. The freeze actions are attached to the freeze node for
223 -- the type. Actions will be elaborated in the order in which they are
224 -- added, and the actions within the list will be elaborated in list order.
225 -- Note that the added nodes are not analyzed. The analyze call is found in
226 -- Exp_Ch13.Expand_N_Freeze_Entity.
228 procedure Build_Allocate_Deallocate_Proc
230 Is_Allocate
: Boolean);
231 -- Create a custom Allocate/Deallocate to be associated with an allocation
234 -- 1) controlled objects
235 -- 2) class-wide objects
236 -- 3) any kind of object on a subpool
238 -- N must be an allocator or the declaration of a temporary variable which
239 -- represents the expression of the original allocator node, otherwise N
240 -- must be a free statement. If flag Is_Allocate is set, the generated
241 -- routine is allocate, deallocate otherwise.
243 function Build_Abort_Undefer_Block
246 Context
: Node_Id
) return Node_Id
;
247 -- Wrap statements Stmts in a block where the AT END handler contains a
248 -- call to Abort_Undefer_Direct. Context is the node which prompted the
249 -- inlining of the abort undefer routine. Note that this routine does
250 -- not install a call to Abort_Defer.
252 procedure Build_Class_Wide_Expression
255 Par_Subp
: Entity_Id
;
256 Adjust_Sloc
: Boolean;
257 Needs_Wrapper
: out Boolean);
258 -- Build the expression for an inherited class-wide condition. Prag is
259 -- the pragma constructed from the corresponding aspect of the parent
260 -- subprogram, and Subp is the overriding operation, and Par_Subp is
261 -- the overridden operation that has the condition. Adjust_Sloc is True
262 -- when the sloc of nodes traversed should be adjusted for the inherited
263 -- pragma. The routine is also called to check whether an inherited
264 -- operation that is not overridden but has inherited conditions needs
265 -- a wrapper, because the inherited condition includes calls to other
266 -- primitives that have been overridden. In that case the first argument
267 -- is the expression of the original class-wide aspect. In SPARK_Mode, such
268 -- operation which are just inherited but have modified pre/postconditions
270 -- If there are calls to overridden operations in the condition, and the
271 -- pragma applies to an inherited operation, a wrapper must be built for
272 -- it to capture the new inherited condition. The flag Needs_Wrapper is
273 -- set in that case so that the wrapper can be built, when the controlling
276 function Build_DIC_Call
279 Typ
: Entity_Id
) return Node_Id
;
280 -- Build a call to the DIC procedure of type Typ with Obj_Id as the actual
283 procedure Build_DIC_Procedure_Body
285 For_Freeze
: Boolean := False);
286 -- Create the body of the procedure which verifies the assertion expression
287 -- of pragma Default_Initial_Condition at run time. Flag For_Freeze should
288 -- be set when the body is constructed as part of the freezing actions for
291 procedure Build_DIC_Procedure_Declaration
(Typ
: Entity_Id
);
292 -- Create the declaration of the procedure which verifies the assertion
293 -- expression of pragma Default_Initial_Condition at run time.
295 procedure Build_Invariant_Procedure_Body
297 Partial_Invariant
: Boolean := False);
298 -- Create the body of the procedure which verifies the invariants of type
299 -- Typ at runtime. Flag Partial_Invariant should be set when Typ denotes a
300 -- private type, otherwise it is assumed that Typ denotes the full view of
303 procedure Build_Invariant_Procedure_Declaration
305 Partial_Invariant
: Boolean := False);
306 -- Create the declaration of the procedure which verifies the invariants of
307 -- type Typ at runtime. Flag Partial_Invariant should be set when building
308 -- the invariant procedure for a private type.
310 procedure Build_Procedure_Form
(N
: Node_Id
);
311 -- Create a procedure declaration which emulates the behavior of a function
312 -- that returns an array type, for C-compatible generation.
314 function Build_Runtime_Call
(Loc
: Source_Ptr
; RE
: RE_Id
) return Node_Id
;
315 -- Build an N_Procedure_Call_Statement calling the given runtime entity.
316 -- The call has no parameters. The first argument provides the location
317 -- information for the tree and for error messages. The call node is not
318 -- analyzed on return, the caller is responsible for analyzing it.
320 function Build_SS_Mark_Call
322 Mark
: Entity_Id
) return Node_Id
;
323 -- Build a call to routine System.Secondary_Stack.Mark. Mark denotes the
324 -- entity of the secondary stack mark.
326 function Build_SS_Release_Call
328 Mark
: Entity_Id
) return Node_Id
;
329 -- Build a call to routine System.Secondary_Stack.Release. Mark denotes the
330 -- entity of the secondary stack mark.
332 function Build_Task_Image_Decls
336 In_Init_Proc
: Boolean := False) return List_Id
;
337 -- Build declaration for a variable that holds an identifying string to be
338 -- used as a task name. Id_Ref is an identifier if the task is a variable,
339 -- and a selected or indexed component if the task is component of an
340 -- object. If it is an indexed component, A_Type is the corresponding array
341 -- type. Its index types are used to build the string as an image of the
342 -- index values. For composite types, the result includes two declarations:
343 -- one for a generated function that computes the image without using
344 -- concatenation, and one for the variable that holds the result.
346 -- If In_Init_Proc is true, the call is part of the initialization of
347 -- a component of a composite type, and the enclosing initialization
348 -- procedure must be flagged as using the secondary stack. If In_Init_Proc
349 -- is false, the call is for a stand-alone object, and the generated
350 -- function itself must do its own cleanups.
352 procedure Build_Transient_Object_Statements
354 Fin_Call
: out Node_Id
;
355 Hook_Assign
: out Node_Id
;
356 Hook_Clear
: out Node_Id
;
357 Hook_Decl
: out Node_Id
;
358 Ptr_Decl
: out Node_Id
;
359 Finalize_Obj
: Boolean := True);
360 -- Subsidiary to the processing of transient objects in transient scopes,
361 -- if expressions, case expressions, expression_with_action nodes, array
362 -- aggregates, and record aggregates. Obj_Decl denotes the declaration of
363 -- the transient object. Generate the following nodes:
365 -- * Fin_Call - the call to [Deep_]Finalize which cleans up the transient
366 -- object if flag Finalize_Obj is set to True, or finalizes the hook when
367 -- the flag is False.
369 -- * Hook_Assign - the assignment statement which captures a reference to
370 -- the transient object in the hook.
372 -- * Hook_Clear - the assignment statement which resets the hook to null
374 -- * Hook_Decl - the declaration of the hook object
376 -- * Ptr_Decl - the full type declaration of the hook type
378 -- These nodes are inserted in specific places depending on the context by
379 -- the various Process_Transient_xxx routines.
381 procedure Check_Float_Op_Overflow
(N
: Node_Id
);
382 -- Called where we could have a floating-point binary operator where we
383 -- must check for infinities if we are operating in Check_Float_Overflow
384 -- mode. Note that we don't need to worry about unary operator cases,
385 -- since for floating-point, abs, unary "-", and unary "+" can never
388 function Component_May_Be_Bit_Aligned
(Comp
: Entity_Id
) return Boolean;
389 -- This function is in charge of detecting record components that may
390 -- cause trouble in the back end if an attempt is made to assign the
391 -- component. The back end can handle such assignments with no problem if
392 -- the components involved are small (64-bits or less) records or scalar
393 -- items (including bit-packed arrays represented with modular types) or
394 -- are both aligned on a byte boundary (starting on a byte boundary, and
395 -- occupying an integral number of bytes).
397 -- However, problems arise for records larger than 64 bits, or for arrays
398 -- (other than bit-packed arrays represented with a modular type) if the
399 -- component starts on a non-byte boundary, or does not occupy an integral
400 -- number of bytes (i.e. there are some bits possibly shared with fields
401 -- at the start or beginning of the component). The back end cannot handle
402 -- loading and storing such components in a single operation.
404 -- This function is used to detect the troublesome situation. it is
405 -- conservative in the sense that it produces True unless it knows for
406 -- sure that the component is safe (as outlined in the first paragraph
407 -- above). The code generation for record and array assignment checks for
408 -- trouble using this function, and if so the assignment is generated
409 -- component-wise, which the back end is required to handle correctly.
411 -- Note that in GNAT 3, the back end will reject such components anyway,
412 -- so the hard work in checking for this case is wasted in GNAT 3, but
413 -- it is harmless, so it is easier to do it in all cases, rather than
414 -- conditionalize it in GNAT 5 or beyond.
416 function Containing_Package_With_Ext_Axioms
417 (E
: Entity_Id
) return Entity_Id
;
418 -- Returns the package entity with an external axiomatization containing E,
419 -- if any, or Empty if none.
421 procedure Convert_To_Actual_Subtype
(Exp
: Node_Id
);
422 -- The Etype of an expression is the nominal type of the expression,
423 -- not the actual subtype. Often these are the same, but not always.
424 -- For example, a reference to a formal of unconstrained type has the
425 -- unconstrained type as its Etype, but the actual subtype is obtained by
426 -- applying the actual bounds. This routine is given an expression, Exp,
427 -- and (if necessary), replaces it using Rewrite, with a conversion to
428 -- the actual subtype, building the actual subtype if necessary. If the
429 -- expression is already of the requested type, then it is unchanged.
431 function Corresponding_Runtime_Package
(Typ
: Entity_Id
) return RTU_Id
;
432 -- Return the id of the runtime package that will provide support for
433 -- concurrent type Typ. Currently only protected types are supported,
434 -- and the returned value is one of the following:
435 -- System_Tasking_Protected_Objects
436 -- System_Tasking_Protected_Objects_Entries
437 -- System_Tasking_Protected_Objects_Single_Entry
439 function Current_Sem_Unit_Declarations
return List_Id
;
440 -- Return the place where it is fine to insert declarations for the
441 -- current semantic unit. If the unit is a package body, return the
442 -- visible declarations of the corresponding spec. For RCI stubs, this
443 -- is necessary because the point at which they are generated may not
444 -- be the earliest point at which they are used.
446 function Duplicate_Subexpr
448 Name_Req
: Boolean := False;
449 Renaming_Req
: Boolean := False) return Node_Id
;
450 -- Given the node for a subexpression, this function makes a logical copy
451 -- of the subexpression, and returns it. This is intended for use when the
452 -- expansion of an expression needs to repeat part of it. For example,
453 -- replacing a**2 by a*a requires two references to a which may be a
454 -- complex subexpression. Duplicate_Subexpr guarantees not to duplicate
455 -- side effects. If necessary, it generates actions to save the expression
456 -- value in a temporary, inserting these actions into the tree using
457 -- Insert_Actions with Exp as the insertion location. The original
458 -- expression and the returned result then become references to this saved
459 -- value. Exp must be analyzed on entry. On return, Exp is analyzed, but
460 -- the caller is responsible for analyzing the returned copy after it is
461 -- attached to the tree.
463 -- The Name_Req flag is set to ensure that the result is suitable for use
464 -- in a context requiring a name (for example, the prefix of an attribute
465 -- reference) (can't this just be a qualification in Ada 2012???).
467 -- The Renaming_Req flag is set to produce an object renaming declaration
468 -- rather than an object declaration. This is valid only if the expression
469 -- Exp designates a renamable object. This is used for example in the case
470 -- of an unchecked deallocation, to make sure the object gets set to null.
472 -- Note that if there are any run time checks in Exp, these same checks
473 -- will be duplicated in the returned duplicated expression. The two
474 -- following functions allow this behavior to be modified.
476 function Duplicate_Subexpr_No_Checks
478 Name_Req
: Boolean := False;
479 Renaming_Req
: Boolean := False;
480 Related_Id
: Entity_Id
:= Empty
;
481 Is_Low_Bound
: Boolean := False;
482 Is_High_Bound
: Boolean := False) return Node_Id
;
483 -- Identical in effect to Duplicate_Subexpr, except that Remove_Checks is
484 -- called on the result, so that the duplicated expression does not include
485 -- checks. This is appropriate for use when Exp, the original expression is
486 -- unconditionally elaborated before the duplicated expression, so that
487 -- there is no need to repeat any checks.
489 -- Related_Id denotes the entity of the context where Expr appears. Flags
490 -- Is_Low_Bound and Is_High_Bound specify whether the expression to check
491 -- is the low or the high bound of a range. These three optional arguments
492 -- signal Remove_Side_Effects to create an external symbol of the form
493 -- Chars (Related_Id)_FIRST/_LAST. For suggested use of these parameters
494 -- see the warning in the body of Sem_Ch3.Process_Range_Expr_In_Decl.
496 function Duplicate_Subexpr_Move_Checks
498 Name_Req
: Boolean := False;
499 Renaming_Req
: Boolean := False) return Node_Id
;
500 -- Identical in effect to Duplicate_Subexpr, except that Remove_Checks is
501 -- called on Exp after the duplication is complete, so that the original
502 -- expression does not include checks. In this case the result returned
503 -- (the duplicated expression) will retain the original checks. This is
504 -- appropriate for use when the duplicated expression is sure to be
505 -- elaborated before the original expression Exp, so that there is no need
506 -- to repeat the checks.
508 procedure Ensure_Defined
(Typ
: Entity_Id
; N
: Node_Id
);
509 -- This procedure ensures that type referenced by Typ is defined. For the
510 -- case of a type other than an Itype, nothing needs to be done, since
511 -- all such types have declaration nodes. For Itypes, an N_Itype_Reference
512 -- node is generated and inserted as an action on node N. This is typically
513 -- used to ensure that an Itype is properly defined outside a conditional
514 -- construct when it is referenced in more than one branch.
516 function Entry_Names_OK
return Boolean;
517 -- Determine whether it is appropriate to dynamically allocate strings
518 -- which represent entry [family member] names. These strings are created
519 -- by the compiler and used by GDB.
521 procedure Evaluate_Name
(Nam
: Node_Id
);
522 -- Remove all side effects from a name which appears as part of an object
523 -- renaming declaration. Similarly to Force_Evaluation, it removes the
524 -- side effects and captures the values of the variables, except for the
525 -- variable being renamed. Hence this differs from Force_Evaluation and
526 -- Remove_Side_Effects (but it calls Force_Evaluation on subexpressions
527 -- whose value needs to be fixed).
529 procedure Evolve_And_Then
(Cond
: in out Node_Id
; Cond1
: Node_Id
);
530 -- Rewrites Cond with the expression: Cond and then Cond1. If Cond is
531 -- Empty, then simply returns Cond1 (this allows the use of Empty to
532 -- initialize a series of checks evolved by this routine, with a final
533 -- result of Empty indicating that no checks were required). The Sloc field
534 -- of the constructed N_And_Then node is copied from Cond1.
536 procedure Evolve_Or_Else
(Cond
: in out Node_Id
; Cond1
: Node_Id
);
537 -- Rewrites Cond with the expression: Cond or else Cond1. If Cond is Empty,
538 -- then simply returns Cond1 (this allows the use of Empty to initialize a
539 -- series of checks evolved by this routine, with a final result of Empty
540 -- indicating that no checks were required). The Sloc field of the
541 -- constructed N_Or_Else node is copied from Cond1.
543 function Exceptions_In_Finalization_OK
return Boolean;
544 -- Determine whether the finalization machinery can safely add exception
545 -- handlers and recovery circuitry.
547 procedure Expand_Static_Predicates_In_Choices
(N
: Node_Id
);
548 -- N is either a case alternative or a variant. The Discrete_Choices field
549 -- of N points to a list of choices. If any of these choices is the name
550 -- of a (statically) predicated subtype, then it is rewritten as the series
551 -- of choices that correspond to the values allowed for the subtype.
553 procedure Expand_Subtype_From_Expr
555 Unc_Type
: Entity_Id
;
556 Subtype_Indic
: Node_Id
;
558 Related_Id
: Entity_Id
:= Empty
);
559 -- Build a constrained subtype from the initial value in object
560 -- declarations and/or allocations when the type is indefinite (including
561 -- class-wide). Set Related_Id to request an external name for the subtype
562 -- rather than an internal temporary.
564 function Expression_Contains_Primitives_Calls_Of
566 Typ
: Entity_Id
) return Boolean;
567 -- Return True if the expression Expr contains a nondispatching call to a
568 -- function which is a primitive of the tagged type Typ.
570 function Finalize_Address
(Typ
: Entity_Id
) return Entity_Id
;
571 -- Locate TSS primitive Finalize_Address in type Typ. Return Empty if the
572 -- subprogram is not available.
574 function Find_Interface_ADT
576 Iface
: Entity_Id
) return Elmt_Id
;
577 -- Ada 2005 (AI-251): Given a type T implementing the interface Iface,
578 -- return the element of Access_Disp_Table containing the tag of the
581 function Find_Interface_Tag
583 Iface
: Entity_Id
) return Entity_Id
;
584 -- Ada 2005 (AI-251): Given a type T implementing the interface Iface,
585 -- return the record component containing the tag of Iface.
587 function Find_Prim_Op
(T
: Entity_Id
; Name
: Name_Id
) return Entity_Id
;
588 -- Find the first primitive operation of a tagged type T with name Name.
589 -- This function allows the use of a primitive operation which is not
590 -- directly visible. If T is a class wide type, then the reference is to an
591 -- operation of the corresponding root type. It is an error if no primitive
592 -- operation with the given name is found.
594 function Find_Prim_Op
596 Name
: TSS_Name_Type
) return Entity_Id
;
597 -- Same as Find_Prim_Op above, except we're searching for an op that has
598 -- the form indicated by Name (i.e. is a type support subprogram with the
599 -- indicated suffix).
601 function Find_Optional_Prim_Op
602 (T
: Entity_Id
; Name
: Name_Id
) return Entity_Id
;
603 function Find_Optional_Prim_Op
605 Name
: TSS_Name_Type
) return Entity_Id
;
606 -- Same as Find_Prim_Op, except returns Empty if not found
608 function Find_Protection_Object
(Scop
: Entity_Id
) return Entity_Id
;
609 -- Traverse the scope stack starting from Scop and look for an entry, entry
610 -- family, or a subprogram that has a Protection_Object and return it. Must
611 -- always return a value since the context in which this routine is invoked
612 -- should always have a protection object.
614 function Find_Protection_Type
(Conc_Typ
: Entity_Id
) return Entity_Id
;
615 -- Given a protected type or its corresponding record, find the type of
618 function Find_Hook_Context
(N
: Node_Id
) return Node_Id
;
619 -- Determine a suitable node on which to attach actions related to N that
620 -- need to be elaborated unconditionally. In general this is the topmost
621 -- expression of which N is a subexpression, which in turn may or may not
622 -- be evaluated, for example if N is the right operand of a short circuit
625 function Following_Address_Clause
(D
: Node_Id
) return Node_Id
;
626 -- D is the node for an object declaration. This function searches the
627 -- current declarative part to look for an address clause for the object
628 -- being declared, and returns the clause if one is found, returns
631 -- Note: this function can be costly and must be invoked with special care.
632 -- Possibly we could introduce a flag at parse time indicating the presence
633 -- of an address clause to speed this up???
635 -- Note: currently this function does not scan the private part, that seems
636 -- like a potential bug ???
638 type Force_Evaluation_Mode
is (Relaxed
, Strict
);
640 procedure Force_Evaluation
642 Name_Req
: Boolean := False;
643 Related_Id
: Entity_Id
:= Empty
;
644 Is_Low_Bound
: Boolean := False;
645 Is_High_Bound
: Boolean := False;
646 Mode
: Force_Evaluation_Mode
:= Relaxed
);
647 -- Force the evaluation of the expression right away. Similar behavior
648 -- to Remove_Side_Effects when Variable_Ref is set to TRUE. That is to
649 -- say, it removes the side effects and captures the values of the
650 -- variables. Remove_Side_Effects guarantees that multiple evaluations
651 -- of the same expression won't generate multiple side effects, whereas
652 -- Force_Evaluation further guarantees that all evaluations will yield
653 -- the same result. If Mode is Relaxed then calls to this subprogram have
654 -- no effect if Exp is side-effect free; if Mode is Strict and Exp is not
655 -- a static expression then no side-effect check is performed on Exp and
656 -- temporaries are unconditionally generated.
658 -- Related_Id denotes the entity of the context where Expr appears. Flags
659 -- Is_Low_Bound and Is_High_Bound specify whether the expression to check
660 -- is the low or the high bound of a range. These three optional arguments
661 -- signal Remove_Side_Effects to create an external symbol of the form
662 -- Chars (Related_Id)_FIRST/_LAST. If Related_Id is set, then exactly one
663 -- of the Is_xxx_Bound flags must be set. For use of these parameters see
664 -- the warning in the body of Sem_Ch3.Process_Range_Expr_In_Decl.
666 function Fully_Qualified_Name_String
668 Append_NUL
: Boolean := True) return String_Id
;
669 -- Generates the string literal corresponding to the fully qualified name
670 -- of entity E, in all upper case, with an ASCII.NUL appended at the end
671 -- of the name if Append_NUL is True.
673 procedure Generate_Poll_Call
(N
: Node_Id
);
674 -- If polling is active, then a call to the Poll routine is built,
675 -- and then inserted before the given node N and analyzed.
677 procedure Get_Current_Value_Condition
681 -- This routine processes the Current_Value field of the variable Var. If
682 -- the Current_Value field is null or if it represents a known value, then
683 -- on return Cond is set to N_Empty, and Val is set to Empty.
685 -- The other case is when Current_Value points to an N_If_Statement or an
686 -- N_Elsif_Part or a N_Iteration_Scheme node (see description in Einfo for
687 -- exact details). In this case, Get_Current_Condition digs out the
688 -- condition, and then checks if the condition is known false, known true,
689 -- or not known at all. In the first two cases, Get_Current_Condition will
690 -- return with Op set to the appropriate conditional operator (inverted if
691 -- the condition is known false), and Val set to the constant value. If the
692 -- condition is not known, then Op and Val are set for the empty case
693 -- (N_Empty and Empty).
695 -- The check for whether the condition is true/false unknown depends
698 -- For an IF, the condition is known true in the THEN part, known false
699 -- in any ELSIF or ELSE part, and not known outside the IF statement in
702 -- For an ELSIF, the condition is known true in the ELSIF part, known
703 -- FALSE in any subsequent ELSIF, or ELSE part, and not known before the
704 -- ELSIF, or after the end of the IF statement.
706 -- The caller can use this result to determine the value (for the case of
707 -- N_Op_Eq), or to determine the result of some other test in other cases
708 -- (e.g. no access check required if N_Op_Ne Null).
710 function Get_Stream_Size
(E
: Entity_Id
) return Uint
;
711 -- Return the stream size value of the subtype E
713 function Has_Access_Constraint
(E
: Entity_Id
) return Boolean;
714 -- Given object or type E, determine if a discriminant is of an access type
716 function Has_Annotate_Pragma_For_External_Axiomatization
717 (E
: Entity_Id
) return Boolean;
718 -- Returns whether E is a package entity, for which the initial list of
719 -- pragmas at the start of the package declaration contains
720 -- pragma Annotate (GNATprove, External_Axiomatization);
722 function Homonym_Number
(Subp
: Entity_Id
) return Nat
;
723 -- Here subp is the entity for a subprogram. This routine returns the
724 -- homonym number used to disambiguate overloaded subprograms in the same
725 -- scope (the number is used as part of constructed names to make sure that
726 -- they are unique). The number is the ordinal position on the Homonym
727 -- chain, counting only entries in the current scope. If an entity is not
728 -- overloaded, the returned number will be one.
730 function Inside_Init_Proc
return Boolean;
731 -- Returns True if current scope is within an init proc
733 function In_Library_Level_Package_Body
(Id
: Entity_Id
) return Boolean;
734 -- Given an arbitrary entity, determine whether it appears at the library
735 -- level of a package body.
737 function In_Unconditional_Context
(Node
: Node_Id
) return Boolean;
738 -- Node is the node for a statement or a component of a statement. This
739 -- function determines if the statement appears in a context that is
740 -- unconditionally executed, i.e. it is not within a loop or a conditional
741 -- or a case statement etc.
743 function Is_All_Null_Statements
(L
: List_Id
) return Boolean;
744 -- Return True if all the items of the list are N_Null_Statement nodes.
745 -- False otherwise. True for an empty list. It is an error to call this
746 -- routine with No_List as the argument.
748 function Is_Displacement_Of_Object_Or_Function_Result
749 (Obj_Id
: Entity_Id
) return Boolean;
750 -- Determine whether Obj_Id is a source entity that has been initialized by
751 -- either a controlled function call or the assignment of another source
752 -- object. In both cases the initialization expression is rewritten as a
753 -- class-wide conversion of Ada.Tags.Displace.
755 function Is_Finalizable_Transient
757 Rel_Node
: Node_Id
) return Boolean;
758 -- Determine whether declaration Decl denotes a controlled transient which
759 -- should be finalized. Rel_Node is the related context. Even though some
760 -- transients are controlled, they may act as renamings of other objects or
763 function Is_Fully_Repped_Tagged_Type
(T
: Entity_Id
) return Boolean;
764 -- Tests given type T, and returns True if T is a non-discriminated tagged
765 -- type which has a record representation clause that specifies the layout
766 -- of all the components, including recursively components in all parent
767 -- types. We exclude discriminated types for convenience, it is extremely
768 -- unlikely that the special processing associated with the use of this
769 -- routine is useful for the case of a discriminated type, and testing for
770 -- component overlap would be a pain.
772 function Is_Library_Level_Tagged_Type
(Typ
: Entity_Id
) return Boolean;
773 -- Return True if Typ is a library level tagged type. Currently we use
774 -- this information to build statically allocated dispatch tables.
776 function Is_Non_BIP_Func_Call
(Expr
: Node_Id
) return Boolean;
777 -- Determine whether node Expr denotes a non build-in-place function call
779 function Is_Possibly_Unaligned_Object
(N
: Node_Id
) return Boolean;
780 -- Node N is an object reference. This function returns True if it is
781 -- possible that the object may not be aligned according to the normal
782 -- default alignment requirement for its type (e.g. if it appears in a
783 -- packed record, or as part of a component that has a component clause.)
785 function Is_Possibly_Unaligned_Slice
(N
: Node_Id
) return Boolean;
786 -- Determine whether the node P is a slice of an array where the slice
787 -- result may cause alignment problems because it has an alignment that
788 -- is not compatible with the type. Return True if so.
790 function Is_Ref_To_Bit_Packed_Array
(N
: Node_Id
) return Boolean;
791 -- Determine whether the node P is a reference to a bit packed array, i.e.
792 -- whether the designated object is a component of a bit packed array, or a
793 -- subcomponent of such a component. If so, then all subscripts in P are
794 -- evaluated with a call to Force_Evaluation, and True is returned.
795 -- Otherwise False is returned, and P is not affected.
797 function Is_Ref_To_Bit_Packed_Slice
(N
: Node_Id
) return Boolean;
798 -- Determine whether the node P is a reference to a bit packed slice, i.e.
799 -- whether the designated object is bit packed slice or a component of a
800 -- bit packed slice. Return True if so.
802 function Is_Related_To_Func_Return
(Id
: Entity_Id
) return Boolean;
803 -- Determine whether object Id is related to an expanded return statement.
804 -- The case concerned is "return Id.all;".
806 function Is_Renamed_Object
(N
: Node_Id
) return Boolean;
807 -- Returns True if the node N is a renamed object. An expression is
808 -- considered to be a renamed object if either it is the Name of an object
809 -- renaming declaration, or is the prefix of a name which is a renamed
810 -- object. For example, in:
812 -- x : r renames a (1 .. 2) (1);
814 -- We consider that a (1 .. 2) is a renamed object since it is the prefix
815 -- of the name in the renaming declaration.
817 function Is_Secondary_Stack_BIP_Func_Call
(Expr
: Node_Id
) return Boolean;
818 -- Determine whether Expr denotes a build-in-place function which returns
819 -- its result on the secondary stack.
821 function Is_Tag_To_Class_Wide_Conversion
822 (Obj_Id
: Entity_Id
) return Boolean;
823 -- Determine whether object Obj_Id is the result of a tag-to-class-wide
826 function Is_Untagged_Derivation
(T
: Entity_Id
) return Boolean;
827 -- Returns true if type T is not tagged and is a derived type,
828 -- or is a private type whose completion is such a type.
830 function Is_Untagged_Private_Derivation
831 (Priv_Typ
: Entity_Id
;
832 Full_Typ
: Entity_Id
) return Boolean;
833 -- Determine whether private type Priv_Typ and its full view Full_Typ
834 -- represent an untagged derivation from a private parent.
836 function Is_Volatile_Reference
(N
: Node_Id
) return Boolean;
837 -- Checks if the node N represents a volatile reference, which can be
838 -- either a direct reference to a variable treated as volatile, or an
839 -- indexed/selected component where the prefix is treated as volatile,
840 -- or has Volatile_Components set. A slice of a volatile variable is
843 procedure Kill_Dead_Code
(N
: Node_Id
; Warn
: Boolean := False);
844 -- N represents a node for a section of code that is known to be dead. Any
845 -- exception handler references and warning messages relating to this code
846 -- are removed. If Warn is True, a warning will be output at the start of N
847 -- indicating the deletion of the code. Note that the tree for the deleted
848 -- code is left intact so that e.g. cross-reference data is still valid.
850 procedure Kill_Dead_Code
(L
: List_Id
; Warn
: Boolean := False);
851 -- Like the above procedure, but applies to every element in the given
852 -- list. If Warn is True, a warning will be output at the start of N
853 -- indicating the deletion of the code.
855 function Known_Non_Negative
(Opnd
: Node_Id
) return Boolean;
856 -- Given a node for a subexpression, determines if it represents a value
857 -- that cannot possibly be negative, and if so returns True. A value of
858 -- False means that it is not known if the value is positive or negative.
860 function Make_Invariant_Call
(Expr
: Node_Id
) return Node_Id
;
861 -- Generate a call to the Invariant_Procedure associated with the type of
862 -- expression Expr. Expr is passed as an actual parameter in the call.
864 function Make_Predicate_Call
867 Mem
: Boolean := False) return Node_Id
;
868 -- Typ is a type with Predicate_Function set. This routine builds a call to
869 -- this function passing Expr as the argument, and returns it unanalyzed.
870 -- If Mem is set True, this is the special call for the membership case,
871 -- and the function called is the Predicate_Function_M if present.
873 function Make_Predicate_Check
875 Expr
: Node_Id
) return Node_Id
;
876 -- Typ is a type with Predicate_Function set. This routine builds a Check
877 -- pragma whose first argument is Predicate, and the second argument is
878 -- a call to the predicate function of Typ with Expr as the argument. If
879 -- Predicate_Check is suppressed then a null statement is returned instead.
881 function Make_Subtype_From_Expr
884 Related_Id
: Entity_Id
:= Empty
) return Node_Id
;
885 -- Returns a subtype indication corresponding to the actual type of an
886 -- expression E. Unc_Typ is an unconstrained array or record, or a class-
887 -- wide type. Set Related_Id to request an external name for the subtype
888 -- rather than an internal temporary.
890 procedure Map_Types
(Parent_Type
: Entity_Id
; Derived_Type
: Entity_Id
);
891 -- Establish the following mapping between the attributes of tagged parent
892 -- type Parent_Type and tagged derived type Derived_Type.
894 -- * Map each discriminant of Parent_Type to ether the corresponding
895 -- discriminant of Derived_Type or come constraint.
897 -- * Map each primitive operation of Parent_Type to the corresponding
898 -- primitive of Derived_Type.
900 -- The mapping Parent_Type -> Derived_Type is also added to the table in
901 -- order to prevent subsequent attempts of the same mapping.
903 function Matching_Standard_Type
(Typ
: Entity_Id
) return Entity_Id
;
904 -- Given a scalar subtype Typ, returns a matching type in standard that
905 -- has the same object size value. For example, a 16 bit signed type will
906 -- typically return Standard_Short_Integer. For fixed-point types, this
907 -- will return integer types of the corresponding size.
909 function May_Generate_Large_Temp
(Typ
: Entity_Id
) return Boolean;
910 -- Determines if the given type, Typ, may require a large temporary of the
911 -- kind that causes back-end trouble if stack checking is enabled. The
912 -- result is True only the size of the type is known at compile time and
913 -- large, where large is defined heuristically by the body of this routine.
914 -- The purpose of this routine is to help avoid generating troublesome
915 -- temporaries that interfere with stack checking mechanism. Note that the
916 -- caller has to check whether stack checking is actually enabled in order
917 -- to guide the expansion (typically of a function call).
919 function Needs_Constant_Address
921 Typ
: Entity_Id
) return Boolean;
922 -- Check whether the expression in an address clause is restricted to
923 -- consist of constants, when the object has a nontrivial initialization
926 function Needs_Finalization
(Typ
: Entity_Id
) return Boolean;
927 -- Determine whether type Typ is controlled and this requires finalization
930 function Non_Limited_Designated_Type
(T
: Entity_Id
) return Entity_Id
;
931 -- An anonymous access type may designate a limited view. Check whether
932 -- non-limited view is available during expansion, to examine components
933 -- or other characteristics of the full type.
935 function OK_To_Do_Constant_Replacement
(E
: Entity_Id
) return Boolean;
936 -- This function is used when testing whether or not to replace a reference
937 -- to entity E by a known constant value. Such replacement must be done
938 -- only in a scope known to be safe for such replacements. In particular,
939 -- if we are within a subprogram and the entity E is declared outside the
940 -- subprogram then we cannot do the replacement, since we do not attempt to
941 -- trace subprogram call flow. It is also unsafe to replace statically
942 -- allocated values (since they can be modified outside the scope), and we
943 -- also inhibit replacement of Volatile or aliased objects since their
944 -- address might be captured in a way we do not detect. A value of True is
945 -- returned only if the replacement is safe.
947 function Possible_Bit_Aligned_Component
(N
: Node_Id
) return Boolean;
948 -- This function is used during processing the assignment of a record or
949 -- indexed component. The argument N is either the left hand or right hand
950 -- side of an assignment, and this function determines if there is a record
951 -- component reference where the record may be bit aligned in a manner that
952 -- causes trouble for the back end (see Component_May_Be_Bit_Aligned for
955 function Power_Of_Two
(N
: Node_Id
) return Nat
;
956 -- Determines if N is a known at compile time value which is of the form
957 -- 2**K, where K is in the range 1 .. M, where the Esize of N is 2**(M+1).
958 -- If so, returns the value K, otherwise returns zero. The caller checks
959 -- that N is of an integer type.
961 procedure Process_Statements_For_Controlled_Objects
(N
: Node_Id
);
962 -- N is a node which contains a non-handled statement list. Inspect the
963 -- statements looking for declarations of controlled objects. If at least
964 -- one such object is found, wrap the statement list in a block.
966 function Remove_Init_Call
968 Rep_Clause
: Node_Id
) return Node_Id
;
969 -- Look for init_proc call or aggregate initialization statements for
970 -- variable Var, either among declarations between that of Var and a
971 -- subsequent Rep_Clause applying to Var, or in the list of freeze actions
972 -- associated with Var, and if found, remove and return that call node.
974 procedure Remove_Side_Effects
976 Name_Req
: Boolean := False;
977 Renaming_Req
: Boolean := False;
978 Variable_Ref
: Boolean := False;
979 Related_Id
: Entity_Id
:= Empty
;
980 Is_Low_Bound
: Boolean := False;
981 Is_High_Bound
: Boolean := False;
982 Check_Side_Effects
: Boolean := True);
983 -- Given the node for a subexpression, this function replaces the node if
984 -- necessary by an equivalent subexpression that is guaranteed to be side
985 -- effect free. This is done by extracting any actions that could cause
986 -- side effects, and inserting them using Insert_Actions into the tree
987 -- to which Exp is attached. Exp must be analyzed and resolved before the
988 -- call and is analyzed and resolved on return. Name_Req may only be set to
989 -- True if Exp has the form of a name, and the effect is to guarantee that
990 -- any replacement maintains the form of name. If Renaming_Req is set to
991 -- True, the routine produces an object renaming reclaration capturing the
992 -- expression. If Variable_Ref is set to True, a variable is considered as
993 -- side effect (used in implementing Force_Evaluation). Note: after call to
994 -- Remove_Side_Effects, it is safe to call New_Copy_Tree to obtain a copy
995 -- of the resulting expression. If Check_Side_Effects is set to True then
996 -- no action is performed if Exp is known to be side-effect free.
998 -- Related_Id denotes the entity of the context where Expr appears. Flags
999 -- Is_Low_Bound and Is_High_Bound specify whether the expression to check
1000 -- is the low or the high bound of a range. These three optional arguments
1001 -- signal Remove_Side_Effects to create an external symbol of the form
1002 -- Chars (Related_Id)_FIRST/_LAST. If Related_Id is set, then exactly one
1003 -- of the Is_xxx_Bound flags must be set. For use of these parameters see
1004 -- the warning in the body of Sem_Ch3.Process_Range_Expr_In_Decl.
1006 -- The side effects are captured using one of the following methods:
1008 -- 1) a constant initialized with the value of the subexpression
1009 -- 2) a renaming of the subexpression
1010 -- 3) a reference to the subexpression
1012 -- For elementary types, methods 1) and 2) are used; for composite types,
1013 -- methods 2) and 3) are used. The renaming (method 2) is used only when
1014 -- the subexpression denotes a name, so that it can be elaborated by gigi
1015 -- without evaluating the subexpression.
1017 -- Historical note: the reference (method 3) used to be the common fallback
1018 -- method but it gives rise to aliasing issues if the subexpression denotes
1019 -- a name that is not aliased, since it is equivalent to taking the address
1020 -- in this case. The renaming (method 2) used to be applied to any objects
1021 -- in the RM sense, that is to say to the cases where a renaming is legal
1022 -- in Ada. But for some of these cases, most notably functions calls, the
1023 -- renaming cannot be elaborated without evaluating the subexpression, so
1024 -- gigi would resort to method 1) or 3) under the hood for them.
1026 procedure Replace_References
1028 Par_Typ
: Entity_Id
;
1029 Deriv_Typ
: Entity_Id
;
1030 Par_Obj
: Entity_Id
:= Empty
;
1031 Deriv_Obj
: Entity_Id
:= Empty
);
1032 -- Expr denotes an arbitrary expression. Par_Typ is a tagged parent type
1033 -- in a type hierarchy. Deriv_Typ is a tagged type derived from Par_Typ
1034 -- with optional ancestors in between. Par_Obj is a formal parameter
1035 -- which emulates the current instance of Par_Typ. Deriv_Obj is a formal
1036 -- parameter which emulates the current instance of Deriv_Typ. Perform the
1037 -- following substitutions in Expr:
1039 -- * Replace a reference to Par_Obj with a reference to Deriv_Obj
1041 -- * Replace a reference to a discriminant of Par_Typ with a suitable
1042 -- value from the point of view of Deriv_Typ.
1044 -- * Replace a call to an overridden primitive of Par_Typ with a call to
1045 -- an overriding primitive of Deriv_Typ.
1047 -- * Replace a call to an inherited primitive of Par_Type with a call to
1048 -- the internally-generated inherited primitive of Deriv_Typ.
1050 procedure Replace_Type_References
1053 Obj_Id
: Entity_Id
);
1054 -- Substitute all references of the current instance of type Typ with
1055 -- references to formal parameter Obj_Id within expression Expr.
1057 function Represented_As_Scalar
(T
: Entity_Id
) return Boolean;
1058 -- Returns True iff the implementation of this type in code generation
1059 -- terms is scalar. This is true for scalars in the Ada sense, and for
1060 -- packed arrays which are represented by a scalar (modular) type.
1062 function Requires_Cleanup_Actions
1064 Lib_Level
: Boolean) return Boolean;
1065 -- Given a node N, determine whether its declarative and/or statement list
1066 -- contains one of the following:
1068 -- 1) controlled objects
1069 -- 2) library-level tagged types
1071 -- These cases require special actions on scope exit. The flag Lib_Level
1072 -- is set True if the construct is at library level, and False otherwise.
1074 function Safe_Unchecked_Type_Conversion
(Exp
: Node_Id
) return Boolean;
1075 -- Given the node for an N_Unchecked_Type_Conversion, return True if this
1076 -- is an unchecked conversion that Gigi can handle directly. Otherwise
1077 -- return False if it is one for which the front end must provide a
1078 -- temporary. Note that the node need not be analyzed, and thus the Etype
1079 -- field may not be set, but in that case it must be the case that the
1080 -- Subtype_Mark field of the node is set/analyzed.
1082 procedure Set_Current_Value_Condition
(Cnode
: Node_Id
);
1083 -- Cnode is N_If_Statement, N_Elsif_Part, or N_Iteration_Scheme (the latter
1084 -- when a WHILE condition is present). This call checks whether Condition
1085 -- (Cnode) has embedded expressions of a form that should result in setting
1086 -- the Current_Value field of one or more entities, and if so sets these
1087 -- fields to point to Cnode.
1089 procedure Set_Elaboration_Flag
(N
: Node_Id
; Spec_Id
: Entity_Id
);
1090 -- N is the node for a subprogram or generic body, and Spec_Id is the
1091 -- entity for the corresponding spec. If an elaboration entity is defined,
1092 -- then this procedure generates an assignment statement to set it True,
1093 -- immediately after the body is elaborated. However, no assignment is
1094 -- generated in the case of library level procedures, since the setting of
1095 -- the flag in this case is generated in the binder. We do that so that we
1096 -- can detect cases where this is the only elaboration action that is
1099 procedure Set_Renamed_Subprogram
(N
: Node_Id
; E
: Entity_Id
);
1100 -- N is an node which is an entity name that represents the name of a
1101 -- renamed subprogram. The node is rewritten to be an identifier that
1102 -- refers directly to the renamed subprogram, given by entity E.
1104 function Side_Effect_Free
1106 Name_Req
: Boolean := False;
1107 Variable_Ref
: Boolean := False) return Boolean;
1108 -- Determines if the tree N represents an expression that is known not
1109 -- to have side effects. If this function returns True, then for example
1110 -- a call to Remove_Side_Effects has no effect.
1112 -- Name_Req controls the handling of volatile variable references. If
1113 -- Name_Req is False (the normal case), then volatile references are
1114 -- considered to be side effects. If Name_Req is True, then volatility
1115 -- of variables is ignored.
1117 -- If Variable_Ref is True, then all variable references are considered to
1118 -- be side effects (regardless of volatility or the setting of Name_Req).
1120 function Side_Effect_Free
1122 Name_Req
: Boolean := False;
1123 Variable_Ref
: Boolean := False) return Boolean;
1124 -- Determines if all elements of the list L are side-effect free. Name_Req
1125 -- and Variable_Ref are as described above.
1127 procedure Silly_Boolean_Array_Not_Test
(N
: Node_Id
; T
: Entity_Id
);
1128 -- N is the node for a boolean array NOT operation, and T is the type of
1129 -- the array. This routine deals with the silly case where the subtype of
1130 -- the boolean array is False..False or True..True, where it is required
1131 -- that a Constraint_Error exception be raised (RM 4.5.6(6)).
1133 procedure Silly_Boolean_Array_Xor_Test
(N
: Node_Id
; T
: Entity_Id
);
1134 -- N is the node for a boolean array XOR operation, and T is the type of
1135 -- the array. This routine deals with the silly case where the subtype of
1136 -- the boolean array is True..True, where a raise of a Constraint_Error
1137 -- exception is required (RM 4.5.6(6)).
1139 function Target_Has_Fixed_Ops
1140 (Left_Typ
: Entity_Id
;
1141 Right_Typ
: Entity_Id
;
1142 Result_Typ
: Entity_Id
) return Boolean;
1143 -- Returns True if and only if the target machine has direct support
1144 -- for fixed-by-fixed multiplications and divisions for the given
1145 -- operand and result types. This is called in package Exp_Fixd to
1146 -- determine whether to expand such operations.
1148 function Type_May_Have_Bit_Aligned_Components
1149 (Typ
: Entity_Id
) return Boolean;
1150 -- Determines if Typ is a composite type that has within it (looking down
1151 -- recursively at any subcomponents), a record type which has component
1152 -- that may be bit aligned (see Possible_Bit_Aligned_Component). The result
1153 -- is conservative, in that a result of False is decisive. A result of True
1154 -- means that such a component may or may not be present.
1156 procedure Update_Primitives_Mapping
1157 (Inher_Id
: Entity_Id
;
1158 Subp_Id
: Entity_Id
);
1159 -- Map primitive operations of the parent type to the corresponding
1160 -- operations of the descendant. Note that the descendant type may not be
1161 -- frozen yet, so we cannot use the dispatch table directly. This is called
1162 -- when elaborating a contract for a subprogram, and when freezing a type
1163 -- extension to verify legality rules on inherited conditions.
1165 function Within_Case_Or_If_Expression
(N
: Node_Id
) return Boolean;
1166 -- Determine whether arbitrary node N is within a case or an if expression
1168 function Within_Internal_Subprogram
return Boolean;
1169 -- Indicates that some expansion is taking place within the body of a
1170 -- predefined primitive operation. Some expansion activity (e.g. predicate
1171 -- checks) is disabled in such. Because we want to detect invalid uses
1172 -- of function calls within predicates (which lead to infinite recursion)
1173 -- predicate functions themselves are not considered internal here.
1176 pragma Inline
(Duplicate_Subexpr
);
1177 pragma Inline
(Force_Evaluation
);
1178 pragma Inline
(Is_Library_Level_Tagged_Type
);