1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2007, 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 2, 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 COPYING. If not, write --
19 -- to the Free Software Foundation, 51 Franklin Street, Fifth Floor, --
20 -- Boston, MA 02110-1301, USA. --
22 -- GNAT was originally developed by the GNAT team at New York University. --
23 -- Extensive contributions were provided by Ada Core Technologies Inc. --
25 ------------------------------------------------------------------------------
27 -- Package containing utility procedures used throughout the expander
29 with Exp_Tss; use Exp_Tss;
30 with Namet; use Namet;
31 with Rtsfind; use Rtsfind;
32 with Sinfo; use Sinfo;
33 with Types; use Types;
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.
57 -- The following special cases arise:
59 -- For actions associated with the right operand of a short circuit
60 -- form, the actions are first stored in the short circuit form node
61 -- in the Actions field. The expansion of these forms subsequently
62 -- expands the short circuit forms into if statements which can then
63 -- be moved as described above.
65 -- For actions appearing in the Condition expression of a while loop,
66 -- or an elsif clause, the actions are similarly temporarily stored in
67 -- in the node (N_Elsif_Part or N_Iteration_Scheme) associated with
68 -- the expression using the Condition_Actions field. Subsequently, the
69 -- expansion of these nodes rewrites the control structures involved to
70 -- reposition the actions in normal statement sequence.
72 -- For actions appearing in the then or else expression of a conditional
73 -- expression, these actions are similarly placed in the node, using the
74 -- Then_Actions or Else_Actions field as appropriate. Once again the
75 -- expansion of the N_Conditional_Expression node rewrites the node so
76 -- that the actions can be normally positioned.
78 -- Basically what we do is to climb up to the tree looking for the
79 -- proper insertion point, as described by one of the above cases,
80 -- and then insert the appropriate action or actions.
82 -- Note if more than one insert call is made specifying the same
83 -- Assoc_Node, then the actions are elaborated in the order of the
84 -- calls, and this guarantee is preserved for the special cases above.
86 procedure Insert_Action
87 (Assoc_Node : Node_Id;
88 Ins_Action : Node_Id);
89 -- Insert the action Ins_Action at the appropriate point as described
90 -- above. The action is analyzed using the default checks after it is
91 -- inserted. Assoc_Node is the node with which the action is associated.
93 procedure Insert_Action
94 (Assoc_Node : Node_Id;
97 -- Insert the action Ins_Action at the appropriate point as described
98 -- above. The action is analyzed using the default checks as modified
99 -- by the given Suppress argument after it is inserted. Assoc_Node is
100 -- the node with which the action is associated.
102 procedure Insert_Actions
103 (Assoc_Node : Node_Id;
104 Ins_Actions : List_Id);
105 -- Insert the list of action Ins_Actions at the appropriate point as
106 -- described above. The actions are analyzed using the default checks
107 -- after they are inserted. Assoc_Node is the node with which the actions
108 -- are associated. Ins_Actions may be No_List, in which case the call has
111 procedure Insert_Actions
112 (Assoc_Node : Node_Id;
113 Ins_Actions : List_Id;
114 Suppress : Check_Id);
115 -- Insert the list of action Ins_Actions at the appropriate point as
116 -- described above. The actions are analyzed using the default checks
117 -- as modified by the given Suppress argument after they are inserted.
118 -- Assoc_Node is the node with which the actions are associated.
119 -- Ins_Actions may be No_List, in which case the call has no effect.
121 procedure Insert_Actions_After
122 (Assoc_Node : Node_Id;
123 Ins_Actions : List_Id);
124 -- Assoc_Node must be a node in a list. Same as Insert_Actions but
125 -- actions will be inserted after N in a manner that is compatible with
126 -- the transient scope mechanism. This procedure must be used instead
127 -- of Insert_List_After if Assoc_Node may be in a transient scope.
129 -- Implementation limitation: Assoc_Node must be a statement. We can
130 -- generalize to expressions if there is a need but this is tricky to
131 -- implement because of short-circuits (among other things).???
133 procedure Insert_Library_Level_Action (N : Node_Id);
134 -- This procedure inserts and analyzes the node N as an action at the
135 -- library level for the current unit (i.e. it is attached to the
136 -- Actions field of the N_Compilation_Aux node for the main unit).
138 procedure Insert_Library_Level_Actions (L : List_Id);
139 -- Similar, but inserts a list of actions
141 -----------------------
142 -- Other Subprograms --
143 -----------------------
145 procedure Adjust_Condition (N : Node_Id);
146 -- The node N is an expression whose root-type is Boolean, and which
147 -- represents a boolean value used as a condition (i.e. a True/False
148 -- value). This routine handles the case of C and Fortran convention
149 -- boolean types, which have zero/non-zero semantics rather than the normal
150 -- 0/1 semantics, and also the case of an enumeration rep clause that
151 -- specifies a non-standard representation. On return, node N always has
152 -- the type Standard.Boolean, with a value that is a standard Boolean
153 -- values of 0/1 for False/True. This procedure is used in two situations.
154 -- First, the processing for a condition field always calls
155 -- Adjust_Condition, so that the boolean value presented to the backend is
156 -- a standard value. Second, for the code for boolean operations such as
157 -- AND, Adjust_Condition is called on both operands, and then the operation
158 -- is done in the domain of Standard_Boolean, then Adjust_Result_Type is
159 -- called on the result to possibly reset the original type. This procedure
160 -- also takes care of validity checking if Validity_Checks = Tests.
162 procedure Adjust_Result_Type (N : Node_Id; T : Entity_Id);
163 -- The processing of boolean operations like AND uses the procedure
164 -- Adjust_Condition so that it can operate on Standard.Boolean, which is
165 -- the only boolean type on which the backend needs to be able to implement
166 -- such operators. This means that the result is also of type
167 -- Standard.Boolean. In general the type must be reset back to the original
168 -- type to get proper semantics, and that is the purpose of this procedure.
169 -- N is the node (of type Standard.Boolean), and T is the desired type. As
170 -- an optimization, this procedure leaves the type as Standard.Boolean in
171 -- contexts where this is permissible (in particular for Condition fields,
172 -- and for operands of other logical operations higher up the tree). The
173 -- call to this procedure is completely ignored if the argument N is not of
176 procedure Append_Freeze_Action (T : Entity_Id; N : Node_Id);
177 -- Add a new freeze action for the given type. The freeze action is
178 -- attached to the freeze node for the type. Actions will be elaborated in
179 -- the order in which they are added. Note that the added node is not
180 -- analyzed. The analyze call is found in Exp_Ch13.Expand_N_Freeze_Entity.
182 procedure Append_Freeze_Actions (T : Entity_Id; L : List_Id);
183 -- Adds the given list of freeze actions (declarations or statements) for
184 -- the given type. The freeze actions are attached to the freeze node for
185 -- the type. Actions will be elaborated in the order in which they are
186 -- added, and the actions within the list will be elaborated in list order.
187 -- Note that the added nodes are not analyzed. The analyze call is found in
188 -- Exp_Ch13.Expand_N_Freeze_Entity.
190 function Build_Runtime_Call (Loc : Source_Ptr; RE : RE_Id) return Node_Id;
191 -- Build an N_Procedure_Call_Statement calling the given runtime entity.
192 -- The call has no parameters. The first argument provides the location
193 -- information for the tree and for error messages. The call node is not
194 -- analyzed on return, the caller is responsible for analyzing it.
196 function Build_Task_Image_Decls
200 In_Init_Proc : Boolean := False) return List_Id;
201 -- Build declaration for a variable that holds an identifying string to be
202 -- used as a task name. Id_Ref is an identifier if the task is a variable,
203 -- and a selected or indexed component if the task is component of an
204 -- object. If it is an indexed component, A_Type is the corresponding array
205 -- type. Its index types are used to build the string as an image of the
206 -- index values. For composite types, the result includes two declarations:
207 -- one for a generated function that computes the image without using
208 -- concatenation, and one for the variable that holds the result.
209 -- If In_Init_Proc is true, the call is part of the initialization of
210 -- a component of a composite type, and the enclosing initialization
211 -- procedure must be flagged as using the secondary stack. If In_Init_Proc
212 -- is false, the call is for a stand-alone object, and the generated
213 -- function itself must do its own cleanups.
215 function Component_May_Be_Bit_Aligned (Comp : Entity_Id) return Boolean;
216 -- This function is in charge of detecting record components that may cause
217 -- trouble in the back end if an attempt is made to assign the component.
218 -- The back end can handle such assignments with no problem if the
219 -- components involved are small (64-bits or less) records or scalar items
220 -- (including bit-packed arrays represented with modular types) or are both
221 -- aligned on a byte boundary (starting on a byte boundary, and occupying
222 -- an integral number of bytes).
224 -- However, problems arise for records larger than 64 bits, or for arrays
225 -- (other than bit-packed arrays represented with a modular type) if the
226 -- component starts on a non-byte boundary, or does not occupy an integral
227 -- number of bytes (i.e. there are some bits possibly shared with fields at
228 -- the start or beginning of the component). The back end cannot handle
229 -- loading and storing such components in a single operation.
231 -- This function is used to detect the troublesome situation. it is
232 -- conservative in the sense that it produces True unless it knows for sure
233 -- that the component is safe (as outlined in the first paragraph above).
234 -- The code generation for record and array assignment checks for trouble
235 -- using this function, and if so the assignment is generated
236 -- component-wise, which the back end is required to handle correctly.
238 -- Note that in GNAT 3, the back end will reject such components anyway, so
239 -- the hard work in checking for this case is wasted in GNAT 3, but it's
240 -- harmless, so it is easier to do it in all cases, rather than
241 -- conditionalize it in GNAT 5 or beyond.
243 procedure Convert_To_Actual_Subtype (Exp : Node_Id);
244 -- The Etype of an expression is the nominal type of the expression, not
245 -- the actual subtype. Often these are the same, but not always. For
246 -- example, a reference to a formal of unconstrained type has the
247 -- unconstrained type as its Etype, but the actual subtype is obtained by
248 -- applying the actual bounds. This routine is given an expression, Exp,
249 -- and (if necessary), replaces it using Rewrite, with a conversion to the
250 -- actual subtype, building the actual subtype if necessary. If the
251 -- expression is already of the requested type, then it is unchanged.
253 function Current_Sem_Unit_Declarations return List_Id;
254 -- Return the a place where it is fine to insert declarations for the
255 -- current semantic unit. If the unit is a package body, return the
256 -- visible declarations of the corresponding spec. For RCI stubs, this
257 -- is necessary because the point at which they are generated may not
258 -- be the earliest point at which they are used.
260 function Duplicate_Subexpr
262 Name_Req : Boolean := False) return Node_Id;
263 -- Given the node for a subexpression, this function makes a logical copy
264 -- of the subexpression, and returns it. This is intended for use when the
265 -- expansion of an expression needs to repeat part of it. For example,
266 -- replacing a**2 by a*a requires two references to a which may be a
267 -- complex subexpression. Duplicate_Subexpr guarantees not to duplicate
268 -- side effects. If necessary, it generates actions to save the expression
269 -- value in a temporary, inserting these actions into the tree using
270 -- Insert_Actions with Exp as the insertion location. The original
271 -- expression and the returned result then become references to this saved
272 -- value. Exp must be analyzed on entry. On return, Exp is analyzed, but
273 -- the caller is responsible for analyzing the returned copy after it is
274 -- attached to the tree. The Name_Req flag is set to ensure that the result
275 -- is suitable for use in a context requiring name (e.g. the prefix of an
276 -- attribute reference).
278 -- Note that if there are any run time checks in Exp, these same checks
279 -- will be duplicated in the returned duplicated expression. The two
280 -- following functions allow this behavior to be modified.
282 function Duplicate_Subexpr_No_Checks
284 Name_Req : Boolean := False) return Node_Id;
285 -- Identical in effect to Duplicate_Subexpr, except that Remove_Checks
286 -- is called on the result, so that the duplicated expression does not
287 -- include checks. This is appropriate for use when Exp, the original
288 -- expression is unconditionally elaborated before the duplicated
289 -- expression, so that there is no need to repeat any checks.
291 function Duplicate_Subexpr_Move_Checks
293 Name_Req : Boolean := False) return Node_Id;
294 -- Identical in effect to Duplicate_Subexpr, except that Remove_Checks is
295 -- called on Exp after the duplication is complete, so that the original
296 -- expression does not include checks. In this case the result returned
297 -- (the duplicated expression) will retain the original checks. This is
298 -- appropriate for use when the duplicated expression is sure to be
299 -- elaborated before the original expression Exp, so that there is no need
300 -- to repeat the checks.
302 procedure Ensure_Defined (Typ : Entity_Id; N : Node_Id);
303 -- This procedure ensures that type referenced by Typ is defined. For the
304 -- case of a type other than an Itype, nothing needs to be done, since
305 -- all such types have declaration nodes. For Itypes, an N_Itype_Reference
306 -- node is generated and inserted at the given node N. This is typically
307 -- used to ensure that an Itype is properly defined outside a conditional
308 -- construct when it is referenced in more than one branch.
310 procedure Evolve_And_Then (Cond : in out Node_Id; Cond1 : Node_Id);
311 -- Rewrites Cond with the expression: Cond and then Cond1. If Cond is
312 -- Empty, then simply returns Cond1 (this allows the use of Empty to
313 -- initialize a series of checks evolved by this routine, with a final
314 -- result of Empty indicating that no checks were required). The Sloc field
315 -- of the constructed N_And_Then node is copied from Cond1.
317 procedure Evolve_Or_Else (Cond : in out Node_Id; Cond1 : Node_Id);
318 -- Rewrites Cond with the expression: Cond or else Cond1. If Cond is Empty,
319 -- then simply returns Cond1 (this allows the use of Empty to initialize a
320 -- series of checks evolved by this routine, with a final result of Empty
321 -- indicating that no checks were required). The Sloc field of the
322 -- constructed N_Or_Else node is copied from Cond1.
324 procedure Expand_Subtype_From_Expr
326 Unc_Type : Entity_Id;
327 Subtype_Indic : Node_Id;
329 -- Build a constrained subtype from the initial value in object
330 -- declarations and/or allocations when the type is indefinite (including
333 function Find_Interface
335 Comp : Entity_Id) return Entity_Id;
336 -- Ada 2005 (AI-251): Given a tagged type and one of its components
337 -- associated with the secondary dispatch table of an abstract interface
338 -- type, return the associated abstract interface type.
340 function Find_Interface_ADT
342 Iface : Entity_Id) return Entity_Id;
343 -- Ada 2005 (AI-251): Given a type T implementing the interface Iface,
344 -- return the Access_Disp_Table value of the interface.
346 function Find_Interface_Tag
348 Iface : Entity_Id) return Entity_Id;
349 -- Ada 2005 (AI-251): Given a type T implementing the interface Iface,
350 -- return the record component containing the tag of Iface.
352 function Find_Prim_Op (T : Entity_Id; Name : Name_Id) return Entity_Id;
353 -- Find the first primitive operation of type T whose name is 'Name'.
354 -- This function allows the use of a primitive operation which is not
355 -- directly visible. If T is a class wide type, then the reference is
356 -- to an operation of the corresponding root type.
358 function Find_Prim_Op
360 Name : TSS_Name_Type) return Entity_Id;
361 -- Find the first primitive operation of type T whose name has the form
362 -- indicated by the name parameter (i.e. is a type support subprogram
363 -- with the indicated suffix). This function allows use of a primitive
364 -- operation which is not directly visible. If T is a class wide type,
365 -- then the reference is to an operation of the corresponding root type.
367 procedure Force_Evaluation
369 Name_Req : Boolean := False);
370 -- Force the evaluation of the expression right away. Similar behavior
371 -- to Remove_Side_Effects when Variable_Ref is set to TRUE. That is to
372 -- say, it removes the side-effects and capture the values of the
373 -- variables. Remove_Side_Effects guarantees that multiple evaluations
374 -- of the same expression won't generate multiple side effects, whereas
375 -- Force_Evaluation further guarantees that all evaluations will yield
378 procedure Generate_Poll_Call (N : Node_Id);
379 -- If polling is active, then a call to the Poll routine is built,
380 -- and then inserted before the given node N and analyzed.
382 procedure Get_Current_Value_Condition
386 -- This routine processes the Current_Value field of the variable Var. If
387 -- the Current_Value field is null or if it represents a known value, then
388 -- on return Cond is set to N_Empty, and Val is set to Empty.
390 -- The other case is when Current_Value points to an N_If_Statement or an
391 -- N_Elsif_Part or a N_Iteration_Scheme node (see description in Einfo for
392 -- exact details). In this case, Get_Current_Condition digs out the
393 -- condition, and then checks if the condition is known false, known true,
394 -- or not known at all. In the first two cases, Get_Current_Condition will
395 -- return with Op set to the appropriate conditional operator (inverted if
396 -- the condition is known false), and Val set to the constant value. If the
397 -- condition is not known, then Op and Val are set for the empty case
398 -- (N_Empty and Empty).
400 -- The check for whether the condition is true/false unknown depends
403 -- For an IF, the condition is known true in the THEN part, known false
404 -- in any ELSIF or ELSE part, and not known outside the IF statement in
407 -- For an ELSIF, the condition is known true in the ELSIF part, known
408 -- FALSE in any subsequent ELSIF, or ELSE part, and not known before the
409 -- ELSIF, or after the end of the IF statement.
411 -- The caller can use this result to determine the value (for the case of
412 -- N_Op_Eq), or to determine the result of some other test in other cases
413 -- (e.g. no access check required if N_Op_Ne Null).
415 function Has_Controlled_Coextensions (Typ : Entity_Id) return Boolean;
416 -- Determine whether a record type has anonymous access discriminants with
417 -- a controlled designated type.
419 function Homonym_Number (Subp : Entity_Id) return Nat;
420 -- Here subp is the entity for a subprogram. This routine returns the
421 -- homonym number used to disambiguate overloaded subprograms in the same
422 -- scope (the number is used as part of constructed names to make sure that
423 -- they are unique). The number is the ordinal position on the Homonym
424 -- chain, counting only entries in the curren scope. If an entity is not
425 -- overloaded, the returned number will be one.
427 function Inside_Init_Proc return Boolean;
428 -- Returns True if current scope is within an init proc
430 function In_Unconditional_Context (Node : Node_Id) return Boolean;
431 -- Node is the node for a statement or a component of a statement. This
432 -- function deteermines if the statement appears in a context that is
433 -- unconditionally executed, i.e. it is not within a loop or a conditional
434 -- or a case statement etc.
436 function Is_All_Null_Statements (L : List_Id) return Boolean;
437 -- Return True if all the items of the list are N_Null_Statement nodes.
438 -- False otherwise. True for an empty list. It is an error to call this
439 -- routine with No_List as the argument.
441 function Is_Library_Level_Tagged_Type (Typ : Entity_Id) return Boolean;
442 -- Return True if Typ is a library level tagged type. Currently we use
443 -- this information to build statically allocated dispatch tables.
445 function Is_Predefined_Dispatching_Operation (E : Entity_Id) return Boolean;
446 -- Ada 2005 (AI-251): Determines if E is a predefined primitive operation
448 function Is_Ref_To_Bit_Packed_Array (N : Node_Id) return Boolean;
449 -- Determine whether the node P is a reference to a bit packed array, i.e.
450 -- whether the designated object is a component of a bit packed array, or a
451 -- subcomponent of such a component. If so, then all subscripts in P are
452 -- evaluated with a call to Force_Evaluation, and True is returned.
453 -- Otherwise False is returned, and P is not affected.
455 function Is_Ref_To_Bit_Packed_Slice (N : Node_Id) return Boolean;
456 -- Determine whether the node P is a reference to a bit packed slice, i.e.
457 -- whether the designated object is bit packed slice or a component of a
458 -- bit packed slice. Return True if so.
460 function Is_Possibly_Unaligned_Slice (N : Node_Id) return Boolean;
461 -- Determine whether the node P is a slice of an array where the slice
462 -- result may cause alignment problems because it has an alignment that
463 -- is not compatible with the type. Return True if so.
465 function Is_Possibly_Unaligned_Object (N : Node_Id) return Boolean;
466 -- Node N is an object reference. This function returns True if it is
467 -- possible that the object may not be aligned according to the normal
468 -- default alignment requirement for its type (e.g. if it appears in a
469 -- packed record, or as part of a component that has a component clause.
471 function Is_Renamed_Object (N : Node_Id) return Boolean;
472 -- Returns True if the node N is a renamed object. An expression is
473 -- considered to be a renamed object if either it is the Name of an object
474 -- renaming declaration, or is the prefix of a name which is a renamed
475 -- object. For example, in:
477 -- x : r renames a (1 .. 2) (1);
479 -- We consider that a (1 .. 2) is a renamed object since it is the prefix
480 -- of the name in the renaming declaration.
482 function Is_Untagged_Derivation (T : Entity_Id) return Boolean;
483 -- Returns true if type T is not tagged and is a derived type,
484 -- or is a private type whose completion is such a type.
486 procedure Kill_Dead_Code (N : Node_Id; Warn : Boolean := False);
487 -- N represents a node for a section of code that is known to be dead. The
488 -- node is deleted, and any exception handler references and warning
489 -- messages relating to this code are removed. If Warn is True, a warning
490 -- will be output at the start of N indicating the deletion of the code.
492 procedure Kill_Dead_Code (L : List_Id; Warn : Boolean := False);
493 -- Like the above procedure, but applies to every element in the given
494 -- list. Each of the entries is removed from the list before killing it.
495 -- If Warn is True, a warning will be output at the start of N indicating
496 -- the deletion of the code.
498 function Known_Non_Negative (Opnd : Node_Id) return Boolean;
499 -- Given a node for a subexpression, determines if it represents a value
500 -- that cannot possibly be negative, and if so returns True. A value of
501 -- False means that it is not known if the value is positive or negative.
503 function Known_Non_Null (N : Node_Id) return Boolean;
504 -- Given a node N for a subexpression of an access type, determines if
505 -- this subexpression yields a value that is known at compile time to
506 -- be non-null and returns True if so. Returns False otherwise. It is
507 -- an error to call this function if N is not of an access type.
509 function Known_Null (N : Node_Id) return Boolean;
510 -- Given a node N for a subexpression of an access type, determines if this
511 -- subexpression yields a value that is known at compile time to be null
512 -- and returns True if so. Returns False otherwise. It is an error to call
513 -- this function if N is not of an access type.
515 function Make_Subtype_From_Expr
517 Unc_Typ : Entity_Id) return Node_Id;
518 -- Returns a subtype indication corresponding to the actual type of an
519 -- expression E. Unc_Typ is an unconstrained array or record, or
522 function May_Generate_Large_Temp (Typ : Entity_Id) return Boolean;
523 -- Determines if the given type, Typ, may require a large temporary of the
524 -- kind that causes back-end trouble if stack checking is enabled. The
525 -- result is True only the size of the type is known at compile time and
526 -- large, where large is defined heuristically by the body of this routine.
527 -- The purpose of this routine is to help avoid generating troublesome
528 -- temporaries that interfere with stack checking mechanism. Note that the
529 -- caller has to check whether stack checking is actually enabled in order
530 -- to guide the expansion (typically of a function call).
532 function Non_Limited_Designated_Type (T : Entity_Id) return Entity_Id;
533 -- An anonymous access type may designate a limited view. Check whether
534 -- non-limited view is available during expansion, to examine components
535 -- or other characteristics of the full type.
537 function OK_To_Do_Constant_Replacement (E : Entity_Id) return Boolean;
538 -- This function is used when testing whether or not to replace a reference
539 -- to entity E by a known constant value. Such replacement must be done
540 -- only in a scope known to be safe for such replacements. In particular,
541 -- if we are within a subprogram and the entity E is declared outside the
542 -- subprogram then we cannot do the replacement, since we do not attempt to
543 -- trace subprogram call flow. It is also unsafe to replace statically
544 -- allocated values (since they can be modified outside the scope), and we
545 -- also inhibit replacement of Volatile or aliased objects since their
546 -- address might be captured in a way we do not detect. A value of True is
547 -- returned only if the replacement is safe.
549 function Possible_Bit_Aligned_Component (N : Node_Id) return Boolean;
550 -- This function is used in processing the assignment of a record or
551 -- indexed component. The argument N is either the left hand or right
552 -- hand side of an assignment, and this function determines if there
553 -- is a record component reference where the record may be bit aligned
554 -- in a manner that causes trouble for the back end (see description
555 -- of Exp_Util.Component_May_Be_Bit_Aligned for further details).
557 procedure Remove_Side_Effects
559 Name_Req : Boolean := False;
560 Variable_Ref : Boolean := False);
561 -- Given the node for a subexpression, this function replaces the node if
562 -- necessary by an equivalent subexpression that is guaranteed to be side
563 -- effect free. This is done by extracting any actions that could cause
564 -- side effects, and inserting them using Insert_Actions into the tree to
565 -- which Exp is attached. Exp must be analyzed and resolved before the call
566 -- and is analyzed and resolved on return. The Name_Req may only be set to
567 -- True if Exp has the form of a name, and the effect is to guarantee that
568 -- any replacement maintains the form of name. If Variable_Ref is set to
569 -- TRUE, a variable is considered as side effect (used in implementing
570 -- Force_Evaluation). Note: after call to Remove_Side_Effects, it is safe
571 -- to call New_Copy_Tree to obtain a copy of the resulting expression.
573 function Represented_As_Scalar (T : Entity_Id) return Boolean;
574 -- Returns True iff the implementation of this type in code generation
575 -- terms is scalar. This is true for scalars in the Ada sense, and for
576 -- packed arrays which are represented by a scalar (modular) type.
578 function Safe_Unchecked_Type_Conversion (Exp : Node_Id) return Boolean;
579 -- Given the node for an N_Unchecked_Type_Conversion, return True if this
580 -- is an unchecked conversion that Gigi can handle directly. Otherwise
581 -- return False if it is one for which the front end must provide a
582 -- temporary. Note that the node need not be analyzed, and thus the Etype
583 -- field may not be set, but in that case it must be the case that the
584 -- Subtype_Mark field of the node is set/analyzed.
586 procedure Set_Current_Value_Condition (Cnode : Node_Id);
587 -- Cnode is N_If_Statement, N_Elsif_Part, or N_Iteration_Scheme (the latter
588 -- when a WHILE condition is present). This call checks whether Condition
589 -- (Cnode) has embedded expressions of a form that should result in setting
590 -- the Current_Value field of one or more entities, and if so sets these
591 -- fields to point to Cnode.
593 procedure Set_Elaboration_Flag (N : Node_Id; Spec_Id : Entity_Id);
594 -- N is the node for a subprogram or generic body, and Spec_Id is the
595 -- entity for the corresponding spec. If an elaboration entity is defined,
596 -- then this procedure generates an assignment statement to set it True,
597 -- immediately after the body is elaborated. However, no assignment is
598 -- generated in the case of library level procedures, since the setting of
599 -- the flag in this case is generated in the binder. We do that so that we
600 -- can detect cases where this is the only elaboration action that is
603 procedure Set_Renamed_Subprogram (N : Node_Id; E : Entity_Id);
604 -- N is an node which is an entity name that represents the name of a
605 -- renamed subprogram. The node is rewritten to be an identifier that
606 -- refers directly to the renamed subprogram, given by entity E.
608 function Target_Has_Fixed_Ops
609 (Left_Typ : Entity_Id;
610 Right_Typ : Entity_Id;
611 Result_Typ : Entity_Id) return Boolean;
612 -- Returns True if and only if the target machine has direct support
613 -- for fixed-by-fixed multiplications and divisions for the given
614 -- operand and result types. This is called in package Exp_Fixd to
615 -- determine whether to expand such operations.
617 function Type_May_Have_Bit_Aligned_Components
618 (Typ : Entity_Id) return Boolean;
619 -- Determines if Typ is a composite type that has within it (looking down
620 -- recursively at any subcomponents), a record type which has component
621 -- that may be bit aligned (see Possible_Bit_Aligned_Component). The result
622 -- is conservative, in that a result of False is decisive. A result of True
623 -- means that such a component may or may not be present.
625 procedure Wrap_Cleanup_Procedure (N : Node_Id);
626 -- Given an N_Subprogram_Body node, this procedure adds an Abort_Defer call
627 -- at the start of the statement sequence, and an Abort_Undefer call at the
628 -- end of the statement sequence. All cleanup routines (i.e. those that are
629 -- called from "at end" handlers) must defer abort on entry and undefer
630 -- abort on exit. Note that it is assumed that the code for the procedure
631 -- does not contain any return statements which would allow the flow of
632 -- control to escape doing the undefer call.
635 pragma Inline (Duplicate_Subexpr);
636 pragma Inline (Force_Evaluation);
637 pragma Inline (Is_Library_Level_Tagged_Type);