1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2022, Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 ------------------------------------------------------------------------------
26 with Einfo
; use Einfo
;
27 with Einfo
.Entities
; use Einfo
.Entities
;
28 with Nlists
; use Nlists
;
29 with Nmake
; use Nmake
;
31 with Rtsfind
; use Rtsfind
;
32 with Sinfo
; use Sinfo
;
33 with Sinfo
.Nodes
; use Sinfo
.Nodes
;
34 with Snames
; use Snames
;
35 with Stand
; use Stand
;
36 with Tbuild
; use Tbuild
;
38 package body Exp_Sel
is
40 -----------------------
41 -- Build_Abort_Block --
42 -----------------------
44 function Build_Abort_Block
46 Abr_Blk_Ent
: Entity_Id
;
47 Cln_Blk_Ent
: Entity_Id
;
48 Blk
: Node_Id
) return Node_Id
52 Make_Block_Statement
(Loc
,
53 Identifier
=> New_Occurrence_Of
(Abr_Blk_Ent
, Loc
),
55 Declarations
=> No_List
,
57 Handled_Statement_Sequence
=>
58 Make_Handled_Sequence_Of_Statements
(Loc
,
61 Make_Implicit_Label_Declaration
(Loc
,
62 Defining_Identifier
=> Cln_Blk_Ent
,
63 Label_Construct
=> Blk
),
67 New_List
(Build_Abort_Block_Handler
(Loc
))));
68 end Build_Abort_Block
;
70 -------------------------------
71 -- Build_Abort_Block_Handler --
72 -------------------------------
74 function Build_Abort_Block_Handler
(Loc
: Source_Ptr
) return Node_Id
is
76 return Make_Implicit_Exception_Handler
(Loc
,
78 New_List
(New_Occurrence_Of
(Stand
.Abort_Signal
, Loc
)),
79 Statements
=> New_List
(Make_Null_Statement
(Loc
)));
80 end Build_Abort_Block_Handler
;
88 Decls
: List_Id
) return Entity_Id
90 B
: constant Entity_Id
:= Make_Temporary
(Loc
, 'B');
93 Make_Object_Declaration
(Loc
,
94 Defining_Identifier
=> B
,
95 Object_Definition
=> New_Occurrence_Of
(Standard_Boolean
, Loc
),
96 Expression
=> New_Occurrence_Of
(Standard_False
, Loc
)));
106 Decls
: List_Id
) return Entity_Id
108 C
: constant Entity_Id
:= Make_Temporary
(Loc
, 'C');
111 Make_Object_Declaration
(Loc
,
112 Defining_Identifier
=> C
,
114 New_Occurrence_Of
(RTE
(RE_Prim_Op_Kind
), Loc
)));
118 -------------------------
119 -- Build_Cleanup_Block --
120 -------------------------
122 function Build_Cleanup_Block
126 Clean_Ent
: Entity_Id
) return Node_Id
128 Cleanup_Block
: constant Node_Id
:=
129 Make_Block_Statement
(Loc
,
131 New_Occurrence_Of
(Blk_Ent
, Loc
),
132 Declarations
=> No_List
,
133 Handled_Statement_Sequence
=>
134 Make_Handled_Sequence_Of_Statements
(Loc
,
135 Statements
=> Stmts
),
136 Is_Asynchronous_Call_Block
=> True);
139 Set_Entry_Cancel_Parameter
(Blk_Ent
, Clean_Ent
);
141 return Cleanup_Block
;
142 end Build_Cleanup_Block
;
151 Obj
: Entity_Id
) return Entity_Id
153 K
: constant Entity_Id
:= Make_Temporary
(Loc
, 'K');
157 if Tagged_Type_Expansion
then
158 Tag_Node
:= Unchecked_Convert_To
(RTE
(RE_Tag
), Obj
);
161 Make_Attribute_Reference
(Loc
,
163 Attribute_Name
=> Name_Tag
);
167 Make_Object_Declaration
(Loc
,
168 Defining_Identifier
=> K
,
170 New_Occurrence_Of
(RTE
(RE_Tagged_Kind
), Loc
),
172 Make_Function_Call
(Loc
,
173 Name
=> New_Occurrence_Of
(RTE
(RE_Get_Tagged_Kind
), Loc
),
174 Parameter_Associations
=> New_List
(Tag_Node
))));
184 Decls
: List_Id
) return Entity_Id
186 S
: constant Entity_Id
:= Make_Temporary
(Loc
, 'S');
189 Make_Object_Declaration
(Loc
,
190 Defining_Identifier
=> S
,
191 Object_Definition
=> New_Occurrence_Of
(Standard_Integer
, Loc
)));
195 ------------------------
196 -- Build_S_Assignment --
197 ------------------------
199 function Build_S_Assignment
203 Call_Ent
: Entity_Id
) return Node_Id
205 Typ
: constant Entity_Id
:= Etype
(Obj
);
208 if Tagged_Type_Expansion
then
210 Make_Assignment_Statement
(Loc
,
211 Name
=> New_Occurrence_Of
(S
, Loc
),
213 Make_Function_Call
(Loc
,
214 Name
=> New_Occurrence_Of
(RTE
(RE_Get_Offset_Index
), Loc
),
215 Parameter_Associations
=> New_List
(
216 Unchecked_Convert_To
(RTE
(RE_Tag
), Obj
),
217 Make_Integer_Literal
(Loc
, DT_Position
(Call_Ent
)))));
223 Make_Assignment_Statement
(Loc
,
224 Name
=> New_Occurrence_Of
(S
, Loc
),
226 Make_Function_Call
(Loc
,
227 Name
=> New_Occurrence_Of
(RTE
(RE_Get_Offset_Index
), Loc
),
229 Parameter_Associations
=> New_List
(
233 Make_Attribute_Reference
(Loc
,
235 Attribute_Name
=> Name_Tag
),
239 Make_Attribute_Reference
(Loc
,
240 Prefix
=> New_Occurrence_Of
(Typ
, Loc
),
241 Attribute_Name
=> Name_Tag
),
245 Make_Integer_Literal
(Loc
, DT_Position
(Call_Ent
)))));
247 end Build_S_Assignment
;