1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2005 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 with Atree
; use Atree
;
28 with Einfo
; use Einfo
;
29 with Elists
; use Elists
;
30 with Errout
; use Errout
;
31 with Exp_Ch4
; use Exp_Ch4
;
32 with Exp_Ch7
; use Exp_Ch7
;
33 with Exp_Ch11
; use Exp_Ch11
;
34 with Exp_Code
; use Exp_Code
;
35 with Exp_Disp
; use Exp_Disp
;
36 with Exp_Fixd
; use Exp_Fixd
;
37 with Exp_Util
; use Exp_Util
;
38 with Itypes
; use Itypes
;
39 with Namet
; use Namet
;
40 with Nmake
; use Nmake
;
41 with Nlists
; use Nlists
;
42 with Restrict
; use Restrict
;
43 with Rtsfind
; use Rtsfind
;
45 with Sem_Eval
; use Sem_Eval
;
46 with Sem_Res
; use Sem_Res
;
47 with Sem_Util
; use Sem_Util
;
48 with Sinfo
; use Sinfo
;
49 with Sinput
; use Sinput
;
50 with Snames
; use Snames
;
51 with Stand
; use Stand
;
52 with Stringt
; use Stringt
;
53 with Tbuild
; use Tbuild
;
54 with Uintp
; use Uintp
;
55 with Urealp
; use Urealp
;
57 package body Exp_Intr
is
59 -----------------------
60 -- Local Subprograms --
61 -----------------------
63 procedure Expand_Is_Negative
(N
: Node_Id
);
64 -- Expand a call to the intrinsic Is_Negative function
66 procedure Expand_Dispatching_Constructor_Call
(N
: Node_Id
);
67 -- Expand a call to an instantiation of Generic_Dispatching_Constructor
68 -- into a dispatching call to the actual subprogram associated with the
69 -- Constructor formal subprogram, passing it the Parameters actual of
70 -- the call to the instantiation and dispatching based on call's Tag
73 procedure Expand_Exception_Call
(N
: Node_Id
; Ent
: RE_Id
);
74 -- Expand a call to Exception_Information/Message/Name. The first
75 -- parameter, N, is the node for the function call, and Ent is the
76 -- entity for the corresponding routine in the Ada.Exceptions package.
78 procedure Expand_Import_Call
(N
: Node_Id
);
79 -- Expand a call to Import_Address/Longest_Integer/Value. The parameter
80 -- N is the node for the function call.
82 procedure Expand_Shift
(N
: Node_Id
; E
: Entity_Id
; K
: Node_Kind
);
83 -- Expand an intrinsic shift operation, N and E are from the call to
84 -- Expand_Intrinsic_Call (call node and subprogram spec entity) and
85 -- K is the kind for the shift node
87 procedure Expand_Unc_Conversion
(N
: Node_Id
; E
: Entity_Id
);
88 -- Expand a call to an instantiation of Unchecked_Convertion into a node
89 -- N_Unchecked_Type_Conversion.
91 procedure Expand_Unc_Deallocation
(N
: Node_Id
);
92 -- Expand a call to an instantiation of Unchecked_Deallocation into a node
93 -- N_Free_Statement and appropriate context.
95 procedure Expand_To_Address
(N
: Node_Id
);
96 procedure Expand_To_Pointer
(N
: Node_Id
);
97 -- Expand a call to corresponding function, declared in an instance of
98 -- System.Addess_To_Access_Conversions.
100 procedure Expand_Source_Info
(N
: Node_Id
; Nam
: Name_Id
);
101 -- Rewrite the node by the appropriate string or positive constant.
102 -- Nam can be one of the following:
103 -- Name_File - expand string that is the name of source file
104 -- Name_Line - expand integer line number
105 -- Name_Source_Location - expand string of form file:line
106 -- Name_Enclosing_Entity - expand string with name of enclosing entity
108 -----------------------------------------
109 -- Expand_Dispatching_Constructor_Call --
110 -----------------------------------------
112 -- Transform a call to an instantiation of Generic_Dispatching_Constructor
115 -- GDC_Instance (The_Tag, Parameters'Access)
117 -- to a class-wide conversion of a dispatching call to the actual
118 -- associated with the formal subprogram Construct, designating
119 -- The_Tag as the controlling tag of the call:
121 -- T'Class (Construct'Actual (Params)) -- Controlling tag is The_Tag
123 -- which will eventually be expanded to the following:
125 -- T'Class (The_Tag.all (Construct'Actual'Index).all (Params))
127 -- A class-wide membership test is also generated, preceding the call,
128 -- to ensure that the controlling tag denotes a type in T'Class.
130 procedure Expand_Dispatching_Constructor_Call
(N
: Node_Id
) is
131 Loc
: constant Source_Ptr
:= Sloc
(N
);
132 Tag_Arg
: constant Node_Id
:= First_Actual
(N
);
133 Param_Arg
: constant Node_Id
:= Next_Actual
(Tag_Arg
);
134 Subp_Decl
: constant Node_Id
:= Parent
(Parent
(Entity
(Name
(N
))));
135 Inst_Pkg
: constant Node_Id
:= Parent
(Subp_Decl
);
136 Act_Rename
: constant Node_Id
:=
137 Next
(Next
(First
(Visible_Declarations
(Inst_Pkg
))));
138 Act_Constr
: constant Entity_Id
:= Entity
(Name
(Act_Rename
));
139 Result_Typ
: constant Entity_Id
:= Class_Wide_Type
(Etype
(Act_Constr
));
140 Cnstr_Call
: Node_Id
;
143 -- Create the call to the actual Constructor function
146 Make_Function_Call
(Loc
,
147 Name
=> New_Occurrence_Of
(Act_Constr
, Loc
),
148 Parameter_Associations
=> New_List
(Relocate_Node
(Param_Arg
)));
150 -- Establish its controlling tag from the tag passed to the instance
152 Set_Controlling_Argument
(Cnstr_Call
, Relocate_Node
(Tag_Arg
));
154 -- Rewrite and analyze the call to the instance as a class-wide
155 -- conversion of the call to the actual constructor.
157 Rewrite
(N
, Convert_To
(Result_Typ
, Cnstr_Call
));
158 Analyze_And_Resolve
(N
, Etype
(Act_Constr
));
160 -- Generate a class-wide membership test to ensure that the call's tag
161 -- argument denotes a type within the class.
164 Make_Implicit_If_Statement
(N
,
167 Make_DT_Access_Action
(Result_Typ
,
168 Action
=> CW_Membership
,
170 Duplicate_Subexpr
(Tag_Arg
),
172 Node
(First_Elmt
(Access_Disp_Table
(
173 Root_Type
(Result_Typ
)))), Loc
)))),
175 New_List
(Make_Raise_Statement
(Loc
,
176 New_Occurrence_Of
(RTE
(RE_Tag_Error
), Loc
)))));
177 end Expand_Dispatching_Constructor_Call
;
179 ---------------------------
180 -- Expand_Exception_Call --
181 ---------------------------
183 -- If the function call is not within an exception handler, then the
184 -- call is replaced by a null string. Otherwise the appropriate routine
185 -- in Ada.Exceptions is called passing the choice parameter specification
186 -- from the enclosing handler. If the enclosing handler lacks a choice
187 -- parameter, then one is supplied.
189 procedure Expand_Exception_Call
(N
: Node_Id
; Ent
: RE_Id
) is
190 Loc
: constant Source_Ptr
:= Sloc
(N
);
195 -- Climb up parents to see if we are in exception handler
199 -- Case of not in exception handler, replace by null string
203 Make_String_Literal
(Loc
,
207 -- Case of in exception handler
209 elsif Nkind
(P
) = N_Exception_Handler
then
210 if No
(Choice_Parameter
(P
)) then
212 -- If no choice parameter present, then put one there. Note
213 -- that we do not need to put it on the entity chain, since
214 -- no one will be referencing it by normal visibility methods.
216 E
:= Make_Defining_Identifier
(Loc
, New_Internal_Name
('E'));
217 Set_Choice_Parameter
(P
, E
);
218 Set_Ekind
(E
, E_Variable
);
219 Set_Etype
(E
, RTE
(RE_Exception_Occurrence
));
220 Set_Scope
(E
, Current_Scope
);
224 Make_Function_Call
(Loc
,
225 Name
=> New_Occurrence_Of
(RTE
(Ent
), Loc
),
226 Parameter_Associations
=> New_List
(
227 New_Occurrence_Of
(Choice_Parameter
(P
), Loc
))));
237 Analyze_And_Resolve
(N
, Standard_String
);
238 end Expand_Exception_Call
;
240 ------------------------
241 -- Expand_Import_Call --
242 ------------------------
244 -- The function call must have a static string as its argument. We create
245 -- a dummy variable which uses this string as the external name in an
246 -- Import pragma. The result is then obtained as the address of this
247 -- dummy variable, converted to the appropriate target type.
249 procedure Expand_Import_Call
(N
: Node_Id
) is
250 Loc
: constant Source_Ptr
:= Sloc
(N
);
251 Ent
: constant Entity_Id
:= Entity
(Name
(N
));
252 Str
: constant Node_Id
:= First_Actual
(N
);
256 Dum
:= Make_Defining_Identifier
(Loc
, New_Internal_Name
('D'));
258 Insert_Actions
(N
, New_List
(
259 Make_Object_Declaration
(Loc
,
260 Defining_Identifier
=> Dum
,
262 New_Occurrence_Of
(Standard_Character
, Loc
)),
265 Chars
=> Name_Import
,
266 Pragma_Argument_Associations
=> New_List
(
267 Make_Pragma_Argument_Association
(Loc
,
268 Expression
=> Make_Identifier
(Loc
, Name_Ada
)),
270 Make_Pragma_Argument_Association
(Loc
,
271 Expression
=> Make_Identifier
(Loc
, Chars
(Dum
))),
273 Make_Pragma_Argument_Association
(Loc
,
274 Chars
=> Name_Link_Name
,
275 Expression
=> Relocate_Node
(Str
))))));
278 Unchecked_Convert_To
(Etype
(Ent
),
279 Make_Attribute_Reference
(Loc
,
280 Attribute_Name
=> Name_Address
,
281 Prefix
=> Make_Identifier
(Loc
, Chars
(Dum
)))));
283 Analyze_And_Resolve
(N
, Etype
(Ent
));
284 end Expand_Import_Call
;
286 ---------------------------
287 -- Expand_Intrinsic_Call --
288 ---------------------------
290 procedure Expand_Intrinsic_Call
(N
: Node_Id
; E
: Entity_Id
) is
294 -- If the intrinsic subprogram is generic, gets its original name
296 if Present
(Parent
(E
))
297 and then Present
(Generic_Parent
(Parent
(E
)))
299 Nam
:= Chars
(Generic_Parent
(Parent
(E
)));
304 if Nam
= Name_Asm
then
307 elsif Nam
= Name_Divide
then
308 Expand_Decimal_Divide_Call
(N
);
310 elsif Nam
= Name_Exception_Information
then
311 Expand_Exception_Call
(N
, RE_Exception_Information
);
313 elsif Nam
= Name_Exception_Message
then
314 Expand_Exception_Call
(N
, RE_Exception_Message
);
316 elsif Nam
= Name_Exception_Name
then
317 Expand_Exception_Call
(N
, RE_Exception_Name_Simple
);
319 elsif Nam
= Name_Generic_Dispatching_Constructor
then
320 Expand_Dispatching_Constructor_Call
(N
);
322 elsif Nam
= Name_Import_Address
324 Nam
= Name_Import_Largest_Value
326 Nam
= Name_Import_Value
328 Expand_Import_Call
(N
);
330 elsif Nam
= Name_Is_Negative
then
331 Expand_Is_Negative
(N
);
333 elsif Nam
= Name_Rotate_Left
then
334 Expand_Shift
(N
, E
, N_Op_Rotate_Left
);
336 elsif Nam
= Name_Rotate_Right
then
337 Expand_Shift
(N
, E
, N_Op_Rotate_Right
);
339 elsif Nam
= Name_Shift_Left
then
340 Expand_Shift
(N
, E
, N_Op_Shift_Left
);
342 elsif Nam
= Name_Shift_Right
then
343 Expand_Shift
(N
, E
, N_Op_Shift_Right
);
345 elsif Nam
= Name_Shift_Right_Arithmetic
then
346 Expand_Shift
(N
, E
, N_Op_Shift_Right_Arithmetic
);
348 elsif Nam
= Name_Unchecked_Conversion
then
349 Expand_Unc_Conversion
(N
, E
);
351 elsif Nam
= Name_Unchecked_Deallocation
then
352 Expand_Unc_Deallocation
(N
);
354 elsif Nam
= Name_To_Address
then
355 Expand_To_Address
(N
);
357 elsif Nam
= Name_To_Pointer
then
358 Expand_To_Pointer
(N
);
360 elsif Nam
= Name_File
361 or else Nam
= Name_Line
362 or else Nam
= Name_Source_Location
363 or else Nam
= Name_Enclosing_Entity
365 Expand_Source_Info
(N
, Nam
);
367 -- If we have a renaming, expand the call to the original operation,
368 -- which must itself be intrinsic, since renaming requires matching
369 -- conventions and this has already been checked.
371 elsif Present
(Alias
(E
)) then
372 Expand_Intrinsic_Call
(N
, Alias
(E
));
374 -- The only other case is where an external name was specified,
375 -- since this is the only way that an otherwise unrecognized
376 -- name could escape the checking in Sem_Prag. Nothing needs
377 -- to be done in such a case, since we pass such a call to the
378 -- back end unchanged.
383 end Expand_Intrinsic_Call
;
385 ------------------------
386 -- Expand_Is_Negative --
387 ------------------------
389 procedure Expand_Is_Negative
(N
: Node_Id
) is
390 Loc
: constant Source_Ptr
:= Sloc
(N
);
391 Opnd
: constant Node_Id
:= Relocate_Node
(First_Actual
(N
));
395 -- We replace the function call by the following expression
397 -- if Opnd < 0.0 then
400 -- if Opnd > 0.0 then
403 -- Float_Unsigned!(Float (Opnd)) /= 0
408 Make_Conditional_Expression
(Loc
,
409 Expressions
=> New_List
(
411 Left_Opnd
=> Duplicate_Subexpr
(Opnd
),
412 Right_Opnd
=> Make_Real_Literal
(Loc
, Ureal_0
)),
414 New_Occurrence_Of
(Standard_True
, Loc
),
416 Make_Conditional_Expression
(Loc
,
417 Expressions
=> New_List
(
419 Left_Opnd
=> Duplicate_Subexpr_No_Checks
(Opnd
),
420 Right_Opnd
=> Make_Real_Literal
(Loc
, Ureal_0
)),
422 New_Occurrence_Of
(Standard_False
, Loc
),
427 (RTE
(RE_Float_Unsigned
),
430 Duplicate_Subexpr_No_Checks
(Opnd
))),
432 Make_Integer_Literal
(Loc
, 0)))))));
434 Analyze_And_Resolve
(N
, Standard_Boolean
);
435 end Expand_Is_Negative
;
441 -- This procedure is used to convert a call to a shift function to the
442 -- corresponding operator node. This conversion is not done by the usual
443 -- circuit for converting calls to operator functions (e.g. "+"(1,2)) to
444 -- operator nodes, because shifts are not predefined operators.
446 -- As a result, whenever a shift is used in the source program, it will
447 -- remain as a call until converted by this routine to the operator node
448 -- form which Gigi is expecting to see.
450 -- Note: it is possible for the expander to generate shift operator nodes
451 -- directly, which will be analyzed in the normal manner by calling Analyze
452 -- and Resolve. Such shift operator nodes will not be seen by Expand_Shift.
454 procedure Expand_Shift
(N
: Node_Id
; E
: Entity_Id
; K
: Node_Kind
) is
455 Loc
: constant Source_Ptr
:= Sloc
(N
);
456 Typ
: constant Entity_Id
:= Etype
(N
);
457 Left
: constant Node_Id
:= First_Actual
(N
);
458 Right
: constant Node_Id
:= Next_Actual
(Left
);
459 Ltyp
: constant Node_Id
:= Etype
(Left
);
460 Rtyp
: constant Node_Id
:= Etype
(Right
);
464 Snode
:= New_Node
(K
, Loc
);
465 Set_Left_Opnd
(Snode
, Relocate_Node
(Left
));
466 Set_Right_Opnd
(Snode
, Relocate_Node
(Right
));
467 Set_Chars
(Snode
, Chars
(E
));
468 Set_Etype
(Snode
, Base_Type
(Typ
));
469 Set_Entity
(Snode
, E
);
471 if Compile_Time_Known_Value
(Type_High_Bound
(Rtyp
))
472 and then Expr_Value
(Type_High_Bound
(Rtyp
)) < Esize
(Ltyp
)
474 Set_Shift_Count_OK
(Snode
, True);
477 -- Do the rewrite. Note that we don't call Analyze and Resolve on
478 -- this node, because it already got analyzed and resolved when
479 -- it was a function call!
485 ------------------------
486 -- Expand_Source_Info --
487 ------------------------
489 procedure Expand_Source_Info
(N
: Node_Id
; Nam
: Name_Id
) is
490 Loc
: constant Source_Ptr
:= Sloc
(N
);
496 if Nam
= Name_Line
then
498 Make_Integer_Literal
(Loc
,
499 Intval
=> UI_From_Int
(Int
(Get_Logical_Line_Number
(Loc
)))));
500 Analyze_And_Resolve
(N
, Standard_Positive
);
507 Get_Decoded_Name_String
508 (Reference_Name
(Get_Source_File_Index
(Loc
)));
510 when Name_Source_Location
=>
511 Build_Location_String
(Loc
);
513 when Name_Enclosing_Entity
=>
516 Ent
:= Current_Scope
;
518 -- Skip enclosing blocks to reach enclosing unit.
520 while Present
(Ent
) loop
521 exit when Ekind
(Ent
) /= E_Block
522 and then Ekind
(Ent
) /= E_Loop
;
526 -- Ent now points to the relevant defining entity
529 SDef
: Source_Ptr
:= Sloc
(Ent
);
530 TDef
: Source_Buffer_Ptr
;
533 TDef
:= Source_Text
(Get_Source_File_Index
(SDef
));
536 while TDef
(SDef
) in '0' .. '9'
537 or else TDef
(SDef
) >= 'A'
538 or else TDef
(SDef
) = ASCII
.ESC
540 Add_Char_To_Name_Buffer
(TDef
(SDef
));
550 Make_String_Literal
(Loc
, Strval
=> String_From_Name_Buffer
));
551 Analyze_And_Resolve
(N
, Standard_String
);
554 Set_Is_Static_Expression
(N
);
555 end Expand_Source_Info
;
557 ---------------------------
558 -- Expand_Unc_Conversion --
559 ---------------------------
561 procedure Expand_Unc_Conversion
(N
: Node_Id
; E
: Entity_Id
) is
562 Func
: constant Entity_Id
:= Entity
(Name
(N
));
568 -- Rewrite as unchecked conversion node. Note that we must convert
569 -- the operand to the formal type of the input parameter of the
570 -- function, so that the resulting N_Unchecked_Type_Conversion
571 -- call indicates the correct types for Gigi.
573 -- Right now, we only do this if a scalar type is involved. It is
574 -- not clear if it is needed in other cases. If we do attempt to
575 -- do the conversion unconditionally, it crashes 3411-018. To be
576 -- investigated further ???
578 Conv
:= Relocate_Node
(First_Actual
(N
));
579 Ftyp
:= Etype
(First_Formal
(Func
));
581 if Is_Scalar_Type
(Ftyp
) then
582 Conv
:= Convert_To
(Ftyp
, Conv
);
583 Set_Parent
(Conv
, N
);
584 Analyze_And_Resolve
(Conv
);
587 -- The instantiation of Unchecked_Conversion creates a wrapper package,
588 -- and the target type is declared as a subtype of the actual. Recover
589 -- the actual, which is the subtype indic. in the subtype declaration
590 -- for the target type. This is semantically correct, and avoids
591 -- anomalies with access subtypes. For entities, leave type as is.
593 -- We do the analysis here, because we do not want the compiler
594 -- to try to optimize or otherwise reorganize the unchecked
599 if Is_Entity_Name
(Conv
) then
602 elsif Nkind
(Parent
(Ttyp
)) = N_Subtype_Declaration
then
603 Ttyp
:= Entity
(Subtype_Indication
(Parent
(Etype
(E
))));
605 elsif Is_Itype
(Ttyp
) then
607 Entity
(Subtype_Indication
(Associated_Node_For_Itype
(Ttyp
)));
612 Rewrite
(N
, Unchecked_Convert_To
(Ttyp
, Conv
));
616 if Nkind
(N
) = N_Unchecked_Type_Conversion
then
617 Expand_N_Unchecked_Type_Conversion
(N
);
619 end Expand_Unc_Conversion
;
621 -----------------------------
622 -- Expand_Unc_Deallocation --
623 -----------------------------
625 -- Generate the following Code :
627 -- if Arg /= null then
628 -- <Finalize_Call> (.., T'Class(Arg.all), ..); -- for controlled types
633 -- For a task, we also generate a call to Free_Task to ensure that the
634 -- task itself is freed if it is terminated, ditto for a simple protected
635 -- object, with a call to Finalize_Protection. For composite types that
636 -- have tasks or simple protected objects as components, we traverse the
637 -- structures to find and terminate those components.
639 procedure Expand_Unc_Deallocation
(N
: Node_Id
) is
640 Loc
: constant Source_Ptr
:= Sloc
(N
);
641 Arg
: constant Node_Id
:= First_Actual
(N
);
642 Typ
: constant Entity_Id
:= Etype
(Arg
);
643 Stmts
: constant List_Id
:= New_List
;
644 Rtyp
: constant Entity_Id
:= Underlying_Type
(Root_Type
(Typ
));
645 Pool
: constant Entity_Id
:= Associated_Storage_Pool
(Rtyp
);
647 Desig_T
: constant Entity_Id
:= Designated_Type
(Typ
);
656 if No_Pool_Assigned
(Rtyp
) then
657 Error_Msg_N
("?deallocation from empty storage pool", N
);
660 if Controlled_Type
(Desig_T
) then
662 Make_Explicit_Dereference
(Loc
,
663 Prefix
=> Duplicate_Subexpr_No_Checks
(Arg
));
665 -- If the type is tagged, then we must force dispatching on the
666 -- finalization call because the designated type may not be the
667 -- actual type of the object
669 if Is_Tagged_Type
(Desig_T
)
670 and then not Is_Class_Wide_Type
(Desig_T
)
672 Deref
:= Unchecked_Convert_To
(Class_Wide_Type
(Desig_T
), Deref
);
679 With_Detach
=> New_Reference_To
(Standard_True
, Loc
));
681 if Abort_Allowed
then
682 Prepend_To
(Free_Cod
,
683 Build_Runtime_Call
(Loc
, RE_Abort_Defer
));
686 Make_Block_Statement
(Loc
, Handled_Statement_Sequence
=>
687 Make_Handled_Sequence_Of_Statements
(Loc
,
688 Statements
=> Free_Cod
,
690 New_Occurrence_Of
(RTE
(RE_Abort_Undefer_Direct
), Loc
)));
692 -- We now expand the exception (at end) handler. We set a
693 -- temporary parent pointer since we have not attached Blk
698 Expand_At_End_Handler
699 (Handled_Statement_Sequence
(Blk
), Entity
(Identifier
(Blk
)));
703 Append_List_To
(Stmts
, Free_Cod
);
707 -- For a task type, call Free_Task before freeing the ATCB
709 if Is_Task_Type
(Desig_T
) then
711 Stat
: Node_Id
:= Prev
(N
);
716 -- An Abort followed by a Free will not do what the user
717 -- expects, because the abort is not immediate. This is
718 -- worth a friendly warning.
721 and then not Comes_From_Source
(Original_Node
(Stat
))
727 and then Nkind
(Original_Node
(Stat
)) = N_Abort_Statement
729 Stat
:= Original_Node
(Stat
);
730 Nam1
:= First
(Names
(Stat
));
731 Nam2
:= Original_Node
(First
(Parameter_Associations
(N
)));
733 if Nkind
(Nam1
) = N_Explicit_Dereference
734 and then Is_Entity_Name
(Prefix
(Nam1
))
735 and then Is_Entity_Name
(Nam2
)
736 and then Entity
(Prefix
(Nam1
)) = Entity
(Nam2
)
738 Error_Msg_N
("abort may take time to complete?", N
);
739 Error_Msg_N
("\deallocation might have no effect?", N
);
740 Error_Msg_N
("\safer to wait for termination.?", N
);
746 (Stmts
, Cleanup_Task
(N
, Duplicate_Subexpr_No_Checks
(Arg
)));
748 -- For composite types that contain tasks, recurse over the structure
749 -- to build the selectors for the task subcomponents.
751 elsif Has_Task
(Desig_T
) then
752 if Is_Record_Type
(Desig_T
) then
753 Append_List_To
(Stmts
, Cleanup_Record
(N
, Arg
, Desig_T
));
755 elsif Is_Array_Type
(Desig_T
) then
756 Append_List_To
(Stmts
, Cleanup_Array
(N
, Arg
, Desig_T
));
760 -- Same for simple protected types. Eventually call Finalize_Protection
761 -- before freeing the PO for each protected component.
763 if Is_Simple_Protected_Type
(Desig_T
) then
765 Cleanup_Protected_Object
(N
, Duplicate_Subexpr_No_Checks
(Arg
)));
767 elsif Has_Simple_Protected_Object
(Desig_T
) then
768 if Is_Record_Type
(Desig_T
) then
769 Append_List_To
(Stmts
, Cleanup_Record
(N
, Arg
, Desig_T
));
770 elsif Is_Array_Type
(Desig_T
) then
771 Append_List_To
(Stmts
, Cleanup_Array
(N
, Arg
, Desig_T
));
775 -- Normal processing for non-controlled types
777 Free_Arg
:= Duplicate_Subexpr_No_Checks
(Arg
);
778 Free_Node
:= Make_Free_Statement
(Loc
, Empty
);
779 Append_To
(Stmts
, Free_Node
);
780 Set_Storage_Pool
(Free_Node
, Pool
);
782 -- Make implicit if statement. We omit this if we are the then part
783 -- of a test of the form:
785 -- if not (Arg = null) then
787 -- i.e. if the test is explicit in the source. Arg must be a simple
788 -- identifier for the purposes of this special test. Note that the
789 -- use of /= in the source is always transformed into the above form.
792 Test_Needed
: Boolean := True;
793 P
: constant Node_Id
:= Parent
(N
);
797 if Nkind
(Arg
) = N_Identifier
798 and then Nkind
(P
) = N_If_Statement
799 and then First
(Then_Statements
(P
)) = N
801 if Nkind
(Condition
(P
)) = N_Op_Not
then
802 C
:= Right_Opnd
(Condition
(P
));
804 if Nkind
(C
) = N_Op_Eq
805 and then Nkind
(Left_Opnd
(C
)) = N_Identifier
806 and then Chars
(Arg
) = Chars
(Left_Opnd
(C
))
807 and then Nkind
(Right_Opnd
(C
)) = N_Null
809 Test_Needed
:= False;
814 -- Generate If_Statement if needed
818 Make_Implicit_If_Statement
(N
,
821 Left_Opnd
=> Duplicate_Subexpr
(Arg
),
822 Right_Opnd
=> Make_Null
(Loc
)),
823 Then_Statements
=> Stmts
);
827 Make_Block_Statement
(Loc
,
828 Handled_Statement_Sequence
=>
829 Make_Handled_Sequence_Of_Statements
(Loc
,
830 Statements
=> Stmts
));
834 -- Deal with storage pool
836 if Present
(Pool
) then
838 -- Freeing the secondary stack is meaningless
840 if Is_RTE
(Pool
, RE_SS_Pool
) then
843 elsif Is_Class_Wide_Type
(Etype
(Pool
)) then
844 Set_Procedure_To_Call
(Free_Node
,
845 RTE
(RE_Deallocate_Any
));
847 Set_Procedure_To_Call
(Free_Node
,
848 Find_Prim_Op
(Etype
(Pool
), Name_Deallocate
));
850 -- If the type is class wide, we generate an implicit type
851 -- with the right dynamic size, so that the deallocate call
852 -- gets the right size parameter computed by gigi
854 if Is_Class_Wide_Type
(Desig_T
) then
856 Acc_Type
: constant Entity_Id
:=
857 Create_Itype
(E_Access_Type
, N
);
858 Deref
: constant Node_Id
:=
859 Make_Explicit_Dereference
(Loc
,
860 Duplicate_Subexpr_No_Checks
(Arg
));
863 Set_Etype
(Deref
, Typ
);
864 Set_Parent
(Deref
, Free_Node
);
866 Set_Etype
(Acc_Type
, Acc_Type
);
867 Set_Size_Info
(Acc_Type
, Typ
);
868 Set_Directly_Designated_Type
869 (Acc_Type
, Entity
(Make_Subtype_From_Expr
872 Free_Arg
:= Unchecked_Convert_To
(Acc_Type
, Free_Arg
);
878 Set_Expression
(Free_Node
, Free_Arg
);
881 Lhs
: constant Node_Id
:= Duplicate_Subexpr_No_Checks
(Arg
);
884 Set_Assignment_OK
(Lhs
);
886 Make_Assignment_Statement
(Loc
,
888 Expression
=> Make_Null
(Loc
)));
891 Rewrite
(N
, Gen_Code
);
893 end Expand_Unc_Deallocation
;
895 -----------------------
896 -- Expand_To_Address --
897 -----------------------
899 procedure Expand_To_Address
(N
: Node_Id
) is
900 Loc
: constant Source_Ptr
:= Sloc
(N
);
901 Arg
: constant Node_Id
:= First_Actual
(N
);
905 Remove_Side_Effects
(Arg
);
907 Obj
:= Make_Explicit_Dereference
(Loc
, Relocate_Node
(Arg
));
910 Make_Conditional_Expression
(Loc
,
911 Expressions
=> New_List
(
913 Left_Opnd
=> New_Copy_Tree
(Arg
),
914 Right_Opnd
=> Make_Null
(Loc
)),
915 New_Occurrence_Of
(RTE
(RE_Null_Address
), Loc
),
916 Make_Attribute_Reference
(Loc
,
917 Attribute_Name
=> Name_Address
,
920 Analyze_And_Resolve
(N
, RTE
(RE_Address
));
921 end Expand_To_Address
;
923 -----------------------
924 -- Expand_To_Pointer --
925 -----------------------
927 procedure Expand_To_Pointer
(N
: Node_Id
) is
928 Arg
: constant Node_Id
:= First_Actual
(N
);
931 Rewrite
(N
, Unchecked_Convert_To
(Etype
(N
), Arg
));
933 end Expand_To_Pointer
;