2005-12-29 Paul Brook <paul@codesourcery.com>
[official-gcc.git] / gcc / ada / exp_util.ads
blobfad07ccafe5067fc45c3215153fe0e13da989df2
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT COMPILER COMPONENTS --
4 -- --
5 -- E X P _ U T I L --
6 -- --
7 -- S p e c --
8 -- --
9 -- Copyright (C) 1992-2005, Free Software Foundation, Inc. --
10 -- --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 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. --
21 -- --
22 -- GNAT was originally developed by the GNAT team at New York University. --
23 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 -- --
25 ------------------------------------------------------------------------------
27 -- Package containing utility procedures used throughout the expander
29 with Exp_Tss; use Exp_Tss;
30 with Rtsfind; use Rtsfind;
31 with Sinfo; use Sinfo;
32 with Types; use Types;
34 package Exp_Util is
36 -- An enumeration type used to capture all the possible interface
37 -- kinds and their hierarchical relation. These values are used in
38 -- Find_Implemented_Interface and Implements_Interface.
40 type Interface_Kind is (
41 Any_Interface, -- Any interface
42 Any_Limited_Interface, -- Only limited interfaces
43 Any_Synchronized_Interface, -- Only synchronized interfaces
45 Iface, -- Individual kinds
46 Limited_Interface,
47 Protected_Interface,
48 Synchronized_Interface,
49 Task_Interface);
51 -----------------------------------------------
52 -- Handling of Actions Associated with Nodes --
53 -----------------------------------------------
55 -- The evaluation of certain expression nodes involves the elaboration
56 -- of associated types and other declarations, and the execution of
57 -- statement sequences. Expansion routines generating such actions must
58 -- find an appropriate place in the tree to hang the actions so that
59 -- they will be evaluated at the appropriate point.
61 -- Some cases are simple:
63 -- For an expression occurring in a simple statement that is in a list
64 -- of statements, the actions are simply inserted into the list before
65 -- the associated statement.
67 -- For an expression occurring in a declaration (declarations always
68 -- appear in lists), the actions are similarly inserted into the list
69 -- just before the associated declaration.
71 -- The following special cases arise:
73 -- For actions associated with the right operand of a short circuit
74 -- form, the actions are first stored in the short circuit form node
75 -- in the Actions field. The expansion of these forms subsequently
76 -- expands the short circuit forms into if statements which can then
77 -- be moved as described above.
79 -- For actions appearing in the Condition expression of a while loop,
80 -- or an elsif clause, the actions are similarly temporarily stored in
81 -- in the node (N_Elsif_Part or N_Iteration_Scheme) associated with
82 -- the expression using the Condition_Actions field. Subsequently, the
83 -- expansion of these nodes rewrites the control structures involved to
84 -- reposition the actions in normal statement sequence.
86 -- For actions appearing in the then or else expression of a conditional
87 -- expression, these actions are similarly placed in the node, using the
88 -- Then_Actions or Else_Actions field as appropriate. Once again the
89 -- expansion of the N_Conditional_Expression node rewrites the node so
90 -- that the actions can be normally positioned.
92 -- Basically what we do is to climb up to the tree looking for the
93 -- proper insertion point, as described by one of the above cases,
94 -- and then insert the appropriate action or actions.
96 -- Note if more than one insert call is made specifying the same
97 -- Assoc_Node, then the actions are elaborated in the order of the
98 -- calls, and this guarantee is preserved for the special cases above.
100 procedure Insert_Action
101 (Assoc_Node : Node_Id;
102 Ins_Action : Node_Id);
103 -- Insert the action Ins_Action at the appropriate point as described
104 -- above. The action is analyzed using the default checks after it is
105 -- inserted. Assoc_Node is the node with which the action is associated.
107 procedure Insert_Action
108 (Assoc_Node : Node_Id;
109 Ins_Action : Node_Id;
110 Suppress : Check_Id);
111 -- Insert the action Ins_Action at the appropriate point as described
112 -- above. The action is analyzed using the default checks as modified
113 -- by the given Suppress argument after it is inserted. Assoc_Node is
114 -- the node with which the action is associated.
116 procedure Insert_Actions
117 (Assoc_Node : Node_Id;
118 Ins_Actions : List_Id);
119 -- Insert the list of action Ins_Actions at the appropriate point as
120 -- described above. The actions are analyzed using the default checks
121 -- after they are inserted. Assoc_Node is the node with which the actions
122 -- are associated. Ins_Actions may be No_List, in which case the call has
123 -- no effect.
125 procedure Insert_Actions
126 (Assoc_Node : Node_Id;
127 Ins_Actions : List_Id;
128 Suppress : Check_Id);
129 -- Insert the list of action Ins_Actions at the appropriate point as
130 -- described above. The actions are analyzed using the default checks
131 -- as modified by the given Suppress argument after they are inserted.
132 -- Assoc_Node is the node with which the actions are associated.
133 -- Ins_Actions may be No_List, in which case the call has no effect.
135 procedure Insert_Actions_After
136 (Assoc_Node : Node_Id;
137 Ins_Actions : List_Id);
138 -- Assoc_Node must be a node in a list. Same as Insert_Actions but
139 -- actions will be inserted after N in a manner that is compatible with
140 -- the transient scope mechanism. This procedure must be used instead
141 -- of Insert_List_After if Assoc_Node may be in a transient scope.
143 -- Implementation limitation: Assoc_Node must be a statement. We can
144 -- generalize to expressions if there is a need but this is tricky to
145 -- implement because of short-circuits (among other things).???
147 procedure Insert_Library_Level_Action (N : Node_Id);
148 -- This procedure inserts and analyzes the node N as an action at the
149 -- library level for the current unit (i.e. it is attached to the
150 -- Actions field of the N_Compilation_Aux node for the main unit).
152 procedure Insert_Library_Level_Actions (L : List_Id);
153 -- Similar, but inserts a list of actions
155 -----------------------
156 -- Other Subprograms --
157 -----------------------
159 procedure Adjust_Condition (N : Node_Id);
160 -- The node N is an expression whose root-type is Boolean, and which
161 -- represents a boolean value used as a condition (i.e. a True/False
162 -- value). This routine handles the case of C and Fortran convention
163 -- boolean types, which have zero/non-zero semantics rather than the normal
164 -- 0/1 semantics, and also the case of an enumeration rep clause that
165 -- specifies a non-standard representation. On return, node N always has
166 -- the type Standard.Boolean, with a value that is a standard Boolean
167 -- values of 0/1 for False/True. This procedure is used in two situations.
168 -- First, the processing for a condition field always calls
169 -- Adjust_Condition, so that the boolean value presented to the backend is
170 -- a standard value. Second, for the code for boolean operations such as
171 -- AND, Adjust_Condition is called on both operands, and then the operation
172 -- is done in the domain of Standard_Boolean, then Adjust_Result_Type is
173 -- called on the result to possibly reset the original type. This procedure
174 -- also takes care of validity checking if Validity_Checks = Tests.
176 procedure Adjust_Result_Type (N : Node_Id; T : Entity_Id);
177 -- The processing of boolean operations like AND uses the procedure
178 -- Adjust_Condition so that it can operate on Standard.Boolean, which is
179 -- the only boolean type on which the backend needs to be able to implement
180 -- such operators. This means that the result is also of type
181 -- Standard.Boolean. In general the type must be reset back to the original
182 -- type to get proper semantics, and that is the purpose of this procedure.
183 -- N is the node (of type Standard.Boolean), and T is the desired type. As
184 -- an optimization, this procedure leaves the type as Standard.Boolean in
185 -- contexts where this is permissible (in particular for Condition fields,
186 -- and for operands of other logical operations higher up the tree). The
187 -- call to this procedure is completely ignored if the argument N is not of
188 -- type Boolean.
190 procedure Append_Freeze_Action (T : Entity_Id; N : Node_Id);
191 -- Add a new freeze action for the given type. The freeze action is
192 -- attached to the freeze node for the type. Actions will be elaborated in
193 -- the order in which they are added. Note that the added node is not
194 -- analyzed. The analyze call is found in Sem_Ch13.Expand_N_Freeze_Entity.
196 procedure Append_Freeze_Actions (T : Entity_Id; L : List_Id);
197 -- Adds the given list of freeze actions (declarations or statements) for
198 -- the given type. The freeze actions are attached to the freeze node for
199 -- the type. Actions will be elaborated in the order in which they are
200 -- added, and the actions within the list will be elaborated in list order.
201 -- Note that the added nodes are not analyzed. The analyze call is found in
202 -- Sem_Ch13.Expand_N_Freeze_Entity.
204 function Build_Runtime_Call (Loc : Source_Ptr; RE : RE_Id) return Node_Id;
205 -- Build an N_Procedure_Call_Statement calling the given runtime entity.
206 -- The call has no parameters. The first argument provides the location
207 -- information for the tree and for error messages. The call node is not
208 -- analyzed on return, the caller is responsible for analyzing it.
210 function Build_Task_Image_Decls
211 (Loc : Source_Ptr;
212 Id_Ref : Node_Id;
213 A_Type : Entity_Id)
214 return List_Id;
215 -- Build declaration for a variable that holds an identifying string to be
216 -- used as a task name. Id_Ref is an identifier if the task is a variable,
217 -- and a selected or indexed component if the task is component of an
218 -- object. If it is an indexed component, A_Type is the corresponding array
219 -- type. Its index types are used to build the string as an image of the
220 -- index values. For composite types, the result includes two declarations:
221 -- one for a generated function that computes the image without using
222 -- concatenation, and one for the variable that holds the result.
224 function Component_May_Be_Bit_Aligned (Comp : Entity_Id) return Boolean;
225 -- This function is in charge of detecting record components that may cause
226 -- trouble in the back end if an attempt is made to assign the component.
227 -- The back end can handle such assignments with no problem if the
228 -- components involved are small (64-bits or less) records or scalar items
229 -- (including bit-packed arrays represented with modular types) or are both
230 -- aligned on a byte boundary (starting on a byte boundary, and occupying
231 -- an integral number of bytes).
233 -- However, problems arise for records larger than 64 bits, or for arrays
234 -- (other than bit-packed arrays represented with a modular type) if the
235 -- component starts on a non-byte boundary, or does not occupy an integral
236 -- number of bytes (i.e. there are some bits possibly shared with fields at
237 -- the start or beginning of the component). The back end cannot handle
238 -- loading and storing such components in a single operation.
240 -- This function is used to detect the troublesome situation. it is
241 -- conservative in the sense that it produces True unless it knows for sure
242 -- that the component is safe (as outlined in the first paragraph above).
243 -- The code generation for record and array assignment checks for trouble
244 -- using this function, and if so the assignment is generated
245 -- component-wise, which the back end is required to handle correctly.
247 -- Note that in GNAT 3, the back end will reject such components anyway, so
248 -- the hard work in checking for this case is wasted in GNAT 3, but it's
249 -- harmless, so it is easier to do it in all cases, rather than
250 -- conditionalize it in GNAT 5 or beyond.
252 procedure Convert_To_Actual_Subtype (Exp : Node_Id);
253 -- The Etype of an expression is the nominal type of the expression, not
254 -- the actual subtype. Often these are the same, but not always. For
255 -- example, a reference to a formal of unconstrained type has the
256 -- unconstrained type as its Etype, but the actual subtype is obtained by
257 -- applying the actual bounds. This routine is given an expression, Exp,
258 -- and (if necessary), replaces it using Rewrite, with a conversion to the
259 -- actual subtype, building the actual subtype if necessary. If the
260 -- expression is already of the requested type, then it is unchanged.
262 function Current_Sem_Unit_Declarations return List_Id;
263 -- Return the a place where it is fine to insert declarations for the
264 -- current semantic unit. If the unit is a package body, return the
265 -- visible declarations of the corresponding spec. For RCI stubs, this
266 -- is necessary because the point at which they are generated may not
267 -- be the earliest point at which they are used.
269 function Duplicate_Subexpr
270 (Exp : Node_Id;
271 Name_Req : Boolean := False) return Node_Id;
272 -- Given the node for a subexpression, this function makes a logical copy
273 -- of the subexpression, and returns it. This is intended for use when the
274 -- expansion of an expression needs to repeat part of it. For example,
275 -- replacing a**2 by a*a requires two references to a which may be a
276 -- complex subexpression. Duplicate_Subexpr guarantees not to duplicate
277 -- side effects. If necessary, it generates actions to save the expression
278 -- value in a temporary, inserting these actions into the tree using
279 -- Insert_Actions with Exp as the insertion location. The original
280 -- expression and the returned result then become references to this saved
281 -- value. Exp must be analyzed on entry. On return, Exp is analyzed, but
282 -- the caller is responsible for analyzing the returned copy after it is
283 -- attached to the tree. The Name_Req flag is set to ensure that the result
284 -- is suitable for use in a context requiring name (e.g. the prefix of an
285 -- attribute reference).
287 -- Note that if there are any run time checks in Exp, these same checks
288 -- will be duplicated in the returned duplicated expression. The two
289 -- following functions allow this behavior to be modified.
291 function Duplicate_Subexpr_No_Checks
292 (Exp : Node_Id;
293 Name_Req : Boolean := False) return Node_Id;
294 -- Identical in effect to Duplicate_Subexpr, except that Remove_Checks
295 -- is called on the result, so that the duplicated expression does not
296 -- include checks. This is appropriate for use when Exp, the original
297 -- expression is unconditionally elaborated before the duplicated
298 -- expression, so that there is no need to repeat any checks.
300 function Duplicate_Subexpr_Move_Checks
301 (Exp : Node_Id;
302 Name_Req : Boolean := False) return Node_Id;
303 -- Identical in effect to Duplicate_Subexpr, except that Remove_Checks is
304 -- called on Exp after the duplication is complete, so that the original
305 -- expression does not include checks. In this case the result returned
306 -- (the duplicated expression) will retain the original checks. This is
307 -- appropriate for use when the duplicated expression is sure to be
308 -- elaborated before the original expression Exp, so that there is no need
309 -- to repeat the checks.
311 procedure Ensure_Defined (Typ : Entity_Id; N : Node_Id);
312 -- This procedure ensures that type referenced by Typ is defined. For the
313 -- case of a type other than an Itype, nothing needs to be done, since
314 -- all such types have declaration nodes. For Itypes, an N_Itype_Reference
315 -- node is generated and inserted at the given node N. This is typically
316 -- used to ensure that an Itype is properly defined outside a conditional
317 -- construct when it is referenced in more than one branch.
319 procedure Evolve_And_Then (Cond : in out Node_Id; Cond1 : Node_Id);
320 -- Rewrites Cond with the expression: Cond and then Cond1. If Cond is
321 -- Empty, then simply returns Cond1 (this allows the use of Empty to
322 -- initialize a series of checks evolved by this routine, with a final
323 -- result of Empty indicating that no checks were required). The Sloc field
324 -- of the constructed N_And_Then node is copied from Cond1.
326 procedure Evolve_Or_Else (Cond : in out Node_Id; Cond1 : Node_Id);
327 -- Rewrites Cond with the expression: Cond or else Cond1. If Cond is Empty,
328 -- then simply returns Cond1 (this allows the use of Empty to initialize a
329 -- series of checks evolved by this routine, with a final result of Empty
330 -- indicating that no checks were required). The Sloc field of the
331 -- constructed N_Or_Else node is copied from Cond1.
333 procedure Expand_Subtype_From_Expr
334 (N : Node_Id;
335 Unc_Type : Entity_Id;
336 Subtype_Indic : Node_Id;
337 Exp : Node_Id);
338 -- Build a constrained subtype from the initial value in object
339 -- declarations and/or allocations when the type is indefinite (including
340 -- class-wide).
342 function Find_Interface
343 (T : Entity_Id;
344 Comp : Entity_Id) return Entity_Id;
345 -- Ada 2005 (AI-251): Given a tagged type and one of its components
346 -- associated with the secondary dispatch table of an abstract interface
347 -- type, return the associated abstract interface type.
349 function Find_Interface_ADT
350 (T : Entity_Id;
351 Iface : Entity_Id) return Entity_Id;
352 -- Ada 2005 (AI-251): Given a type T implementing the interface Iface,
353 -- return the Access_Disp_Table value of the interface.
355 function Find_Interface_Tag
356 (T : Entity_Id;
357 Iface : Entity_Id) return Entity_Id;
358 -- Ada 2005 (AI-251): Given a type T implementing the interface Iface,
359 -- return the record component containing the tag of Iface.
361 function Find_Implemented_Interface
362 (Typ : Entity_Id;
363 Kind : Interface_Kind;
364 Check_Parent : Boolean := False) return Entity_Id;
365 -- Ada 2005 (AI-345): Find a designated kind of interface implemented by
366 -- Typ or any parent subtype. Return the first encountered interface that
367 -- correspond to the selected class. Return Empty if no such interface is
368 -- found. Use Check_Parent to climb a potential derivation chain and
369 -- examine the parent subtypes for any implementation.
371 function Find_Prim_Op (T : Entity_Id; Name : Name_Id) return Entity_Id;
372 -- Find the first primitive operation of type T whose name is 'Name'.
373 -- This function allows the use of a primitive operation which is not
374 -- directly visible. If T is a class wide type, then the reference is
375 -- to an operation of the corresponding root type.
377 function Find_Prim_Op
378 (T : Entity_Id;
379 Name : TSS_Name_Type) return Entity_Id;
380 -- Find the first primitive operation of type T whose name has the form
381 -- indicated by the name parameter (i.e. is a type support subprogram
382 -- with the indicated suffix). This function allows use of a primitive
383 -- operation which is not directly visible. If T is a class wide type,
384 -- then the reference is to an operation of the corresponding root type.
386 procedure Force_Evaluation
387 (Exp : Node_Id;
388 Name_Req : Boolean := False);
389 -- Force the evaluation of the expression right away. Similar behavior
390 -- to Remove_Side_Effects when Variable_Ref is set to TRUE. That is to
391 -- say, it removes the side-effects and capture the values of the
392 -- variables. Remove_Side_Effects guarantees that multiple evaluations
393 -- of the same expression won't generate multiple side effects, whereas
394 -- Force_Evaluation further guarantees that all evaluations will yield
395 -- the same result.
397 procedure Generate_Poll_Call (N : Node_Id);
398 -- If polling is active, then a call to the Poll routine is built,
399 -- and then inserted before the given node N and analyzed.
401 procedure Get_Current_Value_Condition
402 (Var : Node_Id;
403 Op : out Node_Kind;
404 Val : out Node_Id);
405 -- This routine processes the Current_Value field of the variable Var. If
406 -- the Current_Value field is null or if it represents a known value, then
407 -- on return Cond is set to N_Empty, and Val is set to Empty.
409 -- The other case is when Current_Value points to an N_If_Statement or an
410 -- N_Elsif_Part (while statement). Such a setting only occurs if the
411 -- condition of an IF or ELSIF is of the form X op Y, where is the variable
412 -- in question, Y is a compile-time known value, and op is one of the six
413 -- possible relational operators.
415 -- In this case, Get_Current_Condition digs out the condition, and then
416 -- checks if the condition is known false, known true, or not known at all.
417 -- In the first two cases, Get_Current_Condition will return with Op set to
418 -- the appropriate conditional operator (inverted if the condition is known
419 -- false), and Val set to the constant value. If the condition is not
420 -- known, then Cond and Val are set for the empty case (N_Empty and Empty).
422 -- The check for whether the condition is true/false unknown depends
423 -- on the case:
425 -- For an IF, the condition is known true in the THEN part, known false
426 -- in any ELSIF or ELSE part, and not known outside the IF statement in
427 -- question.
429 -- For an ELSIF, the condition is known true in the ELSIF part, known
430 -- FALSE in any subsequent ELSIF, or ELSE part, and not known before the
431 -- ELSIF, or after the end of the IF statement.
433 -- The caller can use this result to determine the value (for the case of
434 -- N_Op_Eq), or to determine the result of some other test in other cases
435 -- (e.g. no access check required if N_Op_Ne Null).
437 function Homonym_Number (Subp : Entity_Id) return Nat;
438 -- Here subp is the entity for a subprogram. This routine returns the
439 -- homonym number used to disambiguate overloaded subprograms in the same
440 -- scope (the number is used as part of constructed names to make sure that
441 -- they are unique). The number is the ordinal position on the Homonym
442 -- chain, counting only entries in the curren scope. If an entity is not
443 -- overloaded, the returned number will be one.
445 function Implements_Interface
446 (Typ : Entity_Id;
447 Kind : Interface_Kind;
448 Check_Parent : Boolean := False) return Boolean;
449 -- Ada 2005 (AI-345): Determine whether Typ implements a designated kind
450 -- of interface. Use Check_Parent to climb a potential derivation chain
451 -- and examine the parent subtypes for any implementation.
453 function Inside_Init_Proc return Boolean;
454 -- Returns True if current scope is within an init proc
456 function In_Unconditional_Context (Node : Node_Id) return Boolean;
457 -- Node is the node for a statement or a component of a statement. This
458 -- function deteermines if the statement appears in a context that is
459 -- unconditionally executed, i.e. it is not within a loop or a conditional
460 -- or a case statement etc.
462 function Is_All_Null_Statements (L : List_Id) return Boolean;
463 -- Return True if all the items of the list are N_Null_Statement nodes.
464 -- False otherwise. True for an empty list. It is an error to call this
465 -- routine with No_List as the argument.
467 function Is_Predefined_Dispatching_Operation
468 (Subp : Entity_Id) return Boolean;
469 -- Ada 2005 (AI-251): Determines if Subp is a predefined primitive
470 -- operation.
472 function Is_Ref_To_Bit_Packed_Array (N : Node_Id) return Boolean;
473 -- Determine whether the node P is a reference to a bit packed array, i.e.
474 -- whether the designated object is a component of a bit packed array, or a
475 -- subcomponent of such a component. If so, then all subscripts in P are
476 -- evaluated with a call to Force_Evaluation, and True is returned.
477 -- Otherwise False is returned, and P is not affected.
479 function Is_Ref_To_Bit_Packed_Slice (N : Node_Id) return Boolean;
480 -- Determine whether the node P is a reference to a bit packed slice, i.e.
481 -- whether the designated object is bit packed slice or a component of a
482 -- bit packed slice. Return True if so.
484 function Is_Possibly_Unaligned_Slice (N : Node_Id) return Boolean;
485 -- Determine whether the node P is a slice of an array where the slice
486 -- result may cause alignment problems because it has an alignment that
487 -- is not compatible with the type. Return True if so.
489 function Is_Possibly_Unaligned_Object (N : Node_Id) return Boolean;
490 -- Node N is an object reference. This function returns True if it is
491 -- possible that the object may not be aligned according to the normal
492 -- default alignment requirement for its type (e.g. if it appears in a
493 -- packed record, or as part of a component that has a component clause.
495 function Is_Renamed_Object (N : Node_Id) return Boolean;
496 -- Returns True if the node N is a renamed object. An expression is
497 -- considered to be a renamed object if either it is the Name of an object
498 -- renaming declaration, or is the prefix of a name which is a renamed
499 -- object. For example, in:
501 -- x : r renames a (1 .. 2) (1);
503 -- We consider that a (1 .. 2) is a renamed object since it is the prefix
504 -- of the name in the renaming declaration.
506 function Is_Untagged_Derivation (T : Entity_Id) return Boolean;
507 -- Returns true if type T is not tagged and is a derived type,
508 -- or is a private type whose completion is such a type.
510 procedure Kill_Dead_Code (N : Node_Id);
511 -- N represents a node for a section of code that is known to be dead. The
512 -- node is deleted, and any exception handler references and warning
513 -- messages relating to this code are removed.
515 procedure Kill_Dead_Code (L : List_Id);
516 -- Like the above procedure, but applies to every element in the given
517 -- list. Each of the entries is removed from the list before killing it.
519 function Known_Non_Negative (Opnd : Node_Id) return Boolean;
520 -- Given a node for a subexpression, determines if it represents a value
521 -- that cannot possibly be negative, and if so returns True. A value of
522 -- False means that it is not known if the value is positive or negative.
524 function Known_Non_Null (N : Node_Id) return Boolean;
525 -- Given a node N for a subexpression of an access type, determines if
526 -- this subexpression yields a value that is known at compile time to
527 -- be non-null and returns True if so. Returns False otherwise. It is
528 -- an error to call this function if N is not of an access type.
530 function Make_Subtype_From_Expr
531 (E : Node_Id;
532 Unc_Typ : Entity_Id) return Node_Id;
533 -- Returns a subtype indication corresponding to the actual type of an
534 -- expression E. Unc_Typ is an unconstrained array or record, or
535 -- a classwide type.
537 function May_Generate_Large_Temp (Typ : Entity_Id) return Boolean;
538 -- Determines if the given type, Typ, may require a large temporary of the
539 -- kind that causes back-end trouble if stack checking is enabled. The
540 -- result is True only the size of the type is known at compile time and
541 -- large, where large is defined heuristically by the body of this routine.
542 -- The purpose of this routine is to help avoid generating troublesome
543 -- temporaries that interfere with stack checking mechanism. Note that the
544 -- caller has to check whether stack checking is actually enabled in order
545 -- to guide the expansion (typically of a function call).
547 procedure Remove_Side_Effects
548 (Exp : Node_Id;
549 Name_Req : Boolean := False;
550 Variable_Ref : Boolean := False);
551 -- Given the node for a subexpression, this function replaces the node if
552 -- necessary by an equivalent subexpression that is guaranteed to be side
553 -- effect free. This is done by extracting any actions that could cause
554 -- side effects, and inserting them using Insert_Actions into the tree to
555 -- which Exp is attached. Exp must be analyzed and resolved before the call
556 -- and is analyzed and resolved on return. The Name_Req may only be set to
557 -- True if Exp has the form of a name, and the effect is to guarantee that
558 -- any replacement maintains the form of name. If Variable_Ref is set to
559 -- TRUE, a variable is considered as side effect (used in implementing
560 -- Force_Evaluation). Note: after call to Remove_Side_Effects, it is safe
561 -- to call New_Copy_Tree to obtain a copy of the resulting expression.
563 function Represented_As_Scalar (T : Entity_Id) return Boolean;
564 -- Returns True iff the implementation of this type in code generation
565 -- terms is scalar. This is true for scalars in the Ada sense, and for
566 -- packed arrays which are represented by a scalar (modular) type.
568 function Safe_Unchecked_Type_Conversion (Exp : Node_Id) return Boolean;
569 -- Given the node for an N_Unchecked_Type_Conversion, return True if this
570 -- is an unchecked conversion that Gigi can handle directly. Otherwise
571 -- return False if it is one for which the front end must provide a
572 -- temporary. Note that the node need not be analyzed, and thus the Etype
573 -- field may not be set, but in that case it must be the case that the
574 -- Subtype_Mark field of the node is set/analyzed.
576 procedure Set_Elaboration_Flag (N : Node_Id; Spec_Id : Entity_Id);
577 -- N is the node for a subprogram or generic body, and Spec_Id is the
578 -- entity for the corresponding spec. If an elaboration entity is defined,
579 -- then this procedure generates an assignment statement to set it True,
580 -- immediately after the body is elaborated. However, no assignment is
581 -- generated in the case of library level procedures, since the setting of
582 -- the flag in this case is generated in the binder. We do that so that we
583 -- can detect cases where this is the only elaboration action that is
584 -- required.
586 function Target_Has_Fixed_Ops
587 (Left_Typ : Entity_Id;
588 Right_Typ : Entity_Id;
589 Result_Typ : Entity_Id) return Boolean;
590 -- Returns True if and only if the target machine has direct support
591 -- for fixed-by-fixed multiplications and divisions for the given
592 -- operand and result types. This is called in package Exp_Fixd to
593 -- determine whether to expand such operations.
595 function Type_May_Have_Bit_Aligned_Components
596 (Typ : Entity_Id) return Boolean;
597 -- Determines if Typ is a composite type that has within it (looking down
598 -- recursively at any subcomponents), a record type which has component
599 -- that may be bit aligned (see Possible_Bit_Aligned_Component). The result
600 -- is conservative, in that a result of False is decisive. A result of True
601 -- means that such a component may or may not be present.
603 procedure Wrap_Cleanup_Procedure (N : Node_Id);
604 -- Given an N_Subprogram_Body node, this procedure adds an Abort_Defer call
605 -- at the start of the statement sequence, and an Abort_Undefer call at the
606 -- end of the statement sequence. All cleanup routines (i.e. those that are
607 -- called from "at end" handlers) must defer abort on entry and undefer
608 -- abort on exit. Note that it is assumed that the code for the procedure
609 -- does not contain any return statements which would allow the flow of
610 -- control to escape doing the undefer call.
612 private
613 pragma Inline (Force_Evaluation);
614 pragma Inline (Duplicate_Subexpr);
616 end Exp_Util;