Debian Codegraph @

gcc/ada/exp_sel.adb

raw
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT COMPILER COMPONENTS --
4 -- --
5 -- E X P _ S E L --
6 -- --
7 -- B o d y --
8 -- --
9 -- Copyright (C) 1992-2025, 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 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. --
20 -- --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
23 -- --
24 ------------------------------------------------------------------------------
25
26 with Einfo; use Einfo;
27 with Einfo.Entities; use Einfo.Entities;
28 with Nlists; use Nlists;
29 with Nmake; use Nmake;
30 with Rtsfind; use Rtsfind;
31 with Sem_Util; use Sem_Util;
32 with Snames; use Snames;
33 with Stand; use Stand;
34 with Tbuild; use Tbuild;
35
36 package body Exp_Sel is
37
38 -----------------------
39 -- Build_Abort_Block --
40 -----------------------
41
42 function Build_Abort_Block
43 (Loc : Source_Ptr;
44 Blk_Ent : Entity_Id;
45 Blk : Node_Id) return Node_Id
46 is
47 begin
48 return
49 Make_Block_Statement (Loc,
50 Handled_Statement_Sequence =>
51 Make_Handled_Sequence_Of_Statements (Loc,
52 Statements =>
53 New_List (
54 Make_Implicit_Label_Declaration (Loc,
55 Defining_Identifier => Blk_Ent,
56 Label_Construct => Blk),
57 Blk),
58
59 Exception_Handlers =>
60 New_List (Build_Abort_Block_Handler (Loc))));
61 end Build_Abort_Block;
62
63 -------------------------------
64 -- Build_Abort_Block_Handler --
65 -------------------------------
66
67 function Build_Abort_Block_Handler (Loc : Source_Ptr) return Node_Id is
68 begin
69 return Make_Implicit_Exception_Handler (Loc,
70 Exception_Choices =>
71 New_List (New_Occurrence_Of (Stand.Abort_Signal, Loc)),
72 Statements => New_List (Make_Null_Statement (Loc)));
73 end Build_Abort_Block_Handler;
74
75 -------------
76 -- Build_B --
77 -------------
78
79 function Build_B
80 (Loc : Source_Ptr;
81 Decls : List_Id) return Entity_Id
82 is
83 B : constant Entity_Id := Make_Temporary (Loc, 'B');
84 begin
85 Append_To (Decls,
86 Make_Object_Declaration (Loc,
87 Defining_Identifier => B,
88 Object_Definition => New_Occurrence_Of (Standard_Boolean, Loc),
89 Expression => New_Occurrence_Of (Standard_False, Loc)));
90 return B;
91 end Build_B;
92
93 -------------
94 -- Build_C --
95 -------------
96
97 function Build_C
98 (Loc : Source_Ptr;
99 Decls : List_Id) return Entity_Id
100 is
101 C : constant Entity_Id := Make_Temporary (Loc, 'C');
102 begin
103 Append_To (Decls,
104 Make_Object_Declaration (Loc,
105 Defining_Identifier => C,
106 Object_Definition =>
107 New_Occurrence_Of (RTE (RE_Prim_Op_Kind), Loc)));
108 return C;
109 end Build_C;
110
111 -------------------------
112 -- Build_Cleanup_Block --
113 -------------------------
114
115 function Build_Cleanup_Block
116 (Loc : Source_Ptr;
117 Blk_Ent : Entity_Id;
118 Stmts : List_Id;
119 Clean_Ent : Entity_Id) return Node_Id
120 is
121 Cleanup_Block : constant Node_Id :=
122 Make_Block_Statement (Loc,
123 Identifier =>
124 New_Occurrence_Of (Blk_Ent, Loc),
125 Declarations => No_List,
126 Handled_Statement_Sequence =>
127 Make_Handled_Sequence_Of_Statements (Loc,
128 Statements => Stmts),
129 Is_Asynchronous_Call_Block => True);
130
131 begin
132 Set_Entry_Cancel_Parameter (Blk_Ent, Clean_Ent);
133
134 return Cleanup_Block;
135 end Build_Cleanup_Block;
136
137 -------------
138 -- Build_K --
139 -------------
140
141 function Build_K
142 (Loc : Source_Ptr;
143 Decls : List_Id;
144 Obj : Entity_Id) return Entity_Id
145 is
146 K : constant Entity_Id := Make_Temporary (Loc, 'K');
147 Tag_Node : constant Node_Id :=
148 Make_Attribute_Reference (Loc,
149 Prefix => New_Copy_Tree (Obj),
150 Attribute_Name => Name_Tag);
151
152 begin
153 Append_To (Decls,
154 Make_Object_Declaration (Loc,
155 Defining_Identifier => K,
156 Object_Definition =>
157 New_Occurrence_Of (RTE (RE_Tagged_Kind), Loc),
158 Expression =>
159 Make_Function_Call (Loc,
160 Name => New_Occurrence_Of (RTE (RE_Get_Tagged_Kind), Loc),
161 Parameter_Associations => New_List (Tag_Node))));
162
163 return K;
164 end Build_K;
165
166 -------------
167 -- Build_S --
168 -------------
169
170 function Build_S
171 (Loc : Source_Ptr;
172 Decls : List_Id) return Entity_Id
173 is
174 S : constant Entity_Id := Make_Temporary (Loc, 'S');
175 begin
176 Append_To (Decls,
177 Make_Object_Declaration (Loc,
178 Defining_Identifier => S,
179 Object_Definition => New_Occurrence_Of (Standard_Integer, Loc)));
180 return S;
181 end Build_S;
182
183 ------------------------
184 -- Build_S_Assignment --
185 ------------------------
186
187 function Build_S_Assignment
188 (Loc : Source_Ptr;
189 S : Entity_Id;
190 Obj : Entity_Id;
191 Call_Ent : Entity_Id) return Node_Id
192 is
193 begin
194 return
195 Make_Assignment_Statement (Loc,
196 Name => New_Occurrence_Of (S, Loc),
197 Expression =>
198 Make_Function_Call (Loc,
199 Name => New_Occurrence_Of (RTE (RE_Get_Offset_Index), Loc),
200 Parameter_Associations => New_List (
201 Make_Attribute_Reference (Loc,
202 Prefix => New_Copy_Tree (Obj),
203 Attribute_Name => Name_Tag),
204 Make_Integer_Literal (Loc, DT_Position (Call_Ent)))));
205 end Build_S_Assignment;
206
207 end Exp_Sel;