annotate gcc/ada/exp_intr.adb @ 131:84e7813d76e9

gcc-8.2
author mir3636
date Thu, 25 Oct 2018 07:37:49 +0900
parents 04ced10e8804
children 1830386684a0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 ------------------------------------------------------------------------------
kono
parents:
diff changeset
2 -- --
kono
parents:
diff changeset
3 -- GNAT COMPILER COMPONENTS --
kono
parents:
diff changeset
4 -- --
kono
parents:
diff changeset
5 -- E X P _ I N T R --
kono
parents:
diff changeset
6 -- --
kono
parents:
diff changeset
7 -- B o d y --
kono
parents:
diff changeset
8 -- --
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
9 -- Copyright (C) 1992-2018, Free Software Foundation, Inc. --
111
kono
parents:
diff changeset
10 -- --
kono
parents:
diff changeset
11 -- GNAT is free software; you can redistribute it and/or modify it under --
kono
parents:
diff changeset
12 -- terms of the GNU General Public License as published by the Free Soft- --
kono
parents:
diff changeset
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
kono
parents:
diff changeset
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
kono
parents:
diff changeset
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
kono
parents:
diff changeset
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
kono
parents:
diff changeset
17 -- for more details. You should have received a copy of the GNU General --
kono
parents:
diff changeset
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
kono
parents:
diff changeset
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
kono
parents:
diff changeset
20 -- --
kono
parents:
diff changeset
21 -- GNAT was originally developed by the GNAT team at New York University. --
kono
parents:
diff changeset
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
kono
parents:
diff changeset
23 -- --
kono
parents:
diff changeset
24 ------------------------------------------------------------------------------
kono
parents:
diff changeset
25
kono
parents:
diff changeset
26 with Atree; use Atree;
kono
parents:
diff changeset
27 with Checks; use Checks;
kono
parents:
diff changeset
28 with Einfo; use Einfo;
kono
parents:
diff changeset
29 with Elists; use Elists;
kono
parents:
diff changeset
30 with Expander; use Expander;
kono
parents:
diff changeset
31 with Exp_Atag; use Exp_Atag;
kono
parents:
diff changeset
32 with Exp_Ch4; use Exp_Ch4;
kono
parents:
diff changeset
33 with Exp_Ch7; use Exp_Ch7;
kono
parents:
diff changeset
34 with Exp_Ch11; use Exp_Ch11;
kono
parents:
diff changeset
35 with Exp_Code; use Exp_Code;
kono
parents:
diff changeset
36 with Exp_Fixd; use Exp_Fixd;
kono
parents:
diff changeset
37 with Exp_Util; use Exp_Util;
kono
parents:
diff changeset
38 with Freeze; use Freeze;
kono
parents:
diff changeset
39 with Inline; use Inline;
kono
parents:
diff changeset
40 with Nmake; use Nmake;
kono
parents:
diff changeset
41 with Nlists; use Nlists;
kono
parents:
diff changeset
42 with Opt; use Opt;
kono
parents:
diff changeset
43 with Restrict; use Restrict;
kono
parents:
diff changeset
44 with Rident; use Rident;
kono
parents:
diff changeset
45 with Rtsfind; use Rtsfind;
kono
parents:
diff changeset
46 with Sem; use Sem;
kono
parents:
diff changeset
47 with Sem_Aux; use Sem_Aux;
kono
parents:
diff changeset
48 with Sem_Eval; use Sem_Eval;
kono
parents:
diff changeset
49 with Sem_Res; use Sem_Res;
kono
parents:
diff changeset
50 with Sem_Type; use Sem_Type;
kono
parents:
diff changeset
51 with Sem_Util; use Sem_Util;
kono
parents:
diff changeset
52 with Sinfo; use Sinfo;
kono
parents:
diff changeset
53 with Sinput; use Sinput;
kono
parents:
diff changeset
54 with Snames; use Snames;
kono
parents:
diff changeset
55 with Stand; use Stand;
kono
parents:
diff changeset
56 with Tbuild; use Tbuild;
kono
parents:
diff changeset
57 with Uintp; use Uintp;
kono
parents:
diff changeset
58 with Urealp; use Urealp;
kono
parents:
diff changeset
59
kono
parents:
diff changeset
60 package body Exp_Intr is
kono
parents:
diff changeset
61
kono
parents:
diff changeset
62 -----------------------
kono
parents:
diff changeset
63 -- Local Subprograms --
kono
parents:
diff changeset
64 -----------------------
kono
parents:
diff changeset
65
kono
parents:
diff changeset
66 procedure Expand_Binary_Operator_Call (N : Node_Id);
kono
parents:
diff changeset
67 -- Expand a call to an intrinsic arithmetic operator when the operand
kono
parents:
diff changeset
68 -- types or sizes are not identical.
kono
parents:
diff changeset
69
kono
parents:
diff changeset
70 procedure Expand_Is_Negative (N : Node_Id);
kono
parents:
diff changeset
71 -- Expand a call to the intrinsic Is_Negative function
kono
parents:
diff changeset
72
kono
parents:
diff changeset
73 procedure Expand_Dispatching_Constructor_Call (N : Node_Id);
kono
parents:
diff changeset
74 -- Expand a call to an instantiation of Generic_Dispatching_Constructor
kono
parents:
diff changeset
75 -- into a dispatching call to the actual subprogram associated with the
kono
parents:
diff changeset
76 -- Constructor formal subprogram, passing it the Parameters actual of
kono
parents:
diff changeset
77 -- the call to the instantiation and dispatching based on call's Tag
kono
parents:
diff changeset
78 -- parameter.
kono
parents:
diff changeset
79
kono
parents:
diff changeset
80 procedure Expand_Exception_Call (N : Node_Id; Ent : RE_Id);
kono
parents:
diff changeset
81 -- Expand a call to Exception_Information/Message/Name. The first
kono
parents:
diff changeset
82 -- parameter, N, is the node for the function call, and Ent is the
kono
parents:
diff changeset
83 -- entity for the corresponding routine in the Ada.Exceptions package.
kono
parents:
diff changeset
84
kono
parents:
diff changeset
85 procedure Expand_Import_Call (N : Node_Id);
kono
parents:
diff changeset
86 -- Expand a call to Import_Address/Longest_Integer/Value. The parameter
kono
parents:
diff changeset
87 -- N is the node for the function call.
kono
parents:
diff changeset
88
kono
parents:
diff changeset
89 procedure Expand_Shift (N : Node_Id; E : Entity_Id; K : Node_Kind);
kono
parents:
diff changeset
90 -- Expand an intrinsic shift operation, N and E are from the call to
kono
parents:
diff changeset
91 -- Expand_Intrinsic_Call (call node and subprogram spec entity) and
kono
parents:
diff changeset
92 -- K is the kind for the shift node
kono
parents:
diff changeset
93
kono
parents:
diff changeset
94 procedure Expand_Unc_Conversion (N : Node_Id; E : Entity_Id);
kono
parents:
diff changeset
95 -- Expand a call to an instantiation of Unchecked_Conversion into a node
kono
parents:
diff changeset
96 -- N_Unchecked_Type_Conversion.
kono
parents:
diff changeset
97
kono
parents:
diff changeset
98 procedure Expand_Unc_Deallocation (N : Node_Id);
kono
parents:
diff changeset
99 -- Expand a call to an instantiation of Unchecked_Deallocation into a node
kono
parents:
diff changeset
100 -- N_Free_Statement and appropriate context.
kono
parents:
diff changeset
101
kono
parents:
diff changeset
102 procedure Expand_To_Address (N : Node_Id);
kono
parents:
diff changeset
103 procedure Expand_To_Pointer (N : Node_Id);
kono
parents:
diff changeset
104 -- Expand a call to corresponding function, declared in an instance of
kono
parents:
diff changeset
105 -- System.Address_To_Access_Conversions.
kono
parents:
diff changeset
106
kono
parents:
diff changeset
107 procedure Expand_Source_Info (N : Node_Id; Nam : Name_Id);
kono
parents:
diff changeset
108 -- Rewrite the node as the appropriate string literal or positive
kono
parents:
diff changeset
109 -- constant. Nam is the name of one of the intrinsics declared in
kono
parents:
diff changeset
110 -- GNAT.Source_Info; see g-souinf.ads for documentation of these
kono
parents:
diff changeset
111 -- intrinsics.
kono
parents:
diff changeset
112
kono
parents:
diff changeset
113 ---------------------
kono
parents:
diff changeset
114 -- Add_Source_Info --
kono
parents:
diff changeset
115 ---------------------
kono
parents:
diff changeset
116
kono
parents:
diff changeset
117 procedure Add_Source_Info
kono
parents:
diff changeset
118 (Buf : in out Bounded_String;
kono
parents:
diff changeset
119 Loc : Source_Ptr;
kono
parents:
diff changeset
120 Nam : Name_Id)
kono
parents:
diff changeset
121 is
kono
parents:
diff changeset
122 begin
kono
parents:
diff changeset
123 case Nam is
kono
parents:
diff changeset
124 when Name_Line =>
kono
parents:
diff changeset
125 Append (Buf, Nat (Get_Logical_Line_Number (Loc)));
kono
parents:
diff changeset
126
kono
parents:
diff changeset
127 when Name_File =>
kono
parents:
diff changeset
128 Append (Buf, Reference_Name (Get_Source_File_Index (Loc)));
kono
parents:
diff changeset
129
kono
parents:
diff changeset
130 when Name_Source_Location =>
kono
parents:
diff changeset
131 Build_Location_String (Buf, Loc);
kono
parents:
diff changeset
132
kono
parents:
diff changeset
133 when Name_Enclosing_Entity =>
kono
parents:
diff changeset
134
kono
parents:
diff changeset
135 -- Skip enclosing blocks to reach enclosing unit
kono
parents:
diff changeset
136
kono
parents:
diff changeset
137 declare
kono
parents:
diff changeset
138 Ent : Entity_Id := Current_Scope;
kono
parents:
diff changeset
139 begin
kono
parents:
diff changeset
140 while Present (Ent) loop
kono
parents:
diff changeset
141 exit when not Ekind_In (Ent, E_Block, E_Loop);
kono
parents:
diff changeset
142 Ent := Scope (Ent);
kono
parents:
diff changeset
143 end loop;
kono
parents:
diff changeset
144
kono
parents:
diff changeset
145 -- Ent now points to the relevant defining entity
kono
parents:
diff changeset
146
kono
parents:
diff changeset
147 Append_Entity_Name (Buf, Ent);
kono
parents:
diff changeset
148 end;
kono
parents:
diff changeset
149
kono
parents:
diff changeset
150 when Name_Compilation_ISO_Date =>
kono
parents:
diff changeset
151 Append (Buf, Opt.Compilation_Time (1 .. 10));
kono
parents:
diff changeset
152
kono
parents:
diff changeset
153 when Name_Compilation_Date =>
kono
parents:
diff changeset
154 declare
kono
parents:
diff changeset
155 subtype S13 is String (1 .. 3);
kono
parents:
diff changeset
156 Months : constant array (1 .. 12) of S13 :=
kono
parents:
diff changeset
157 ("Jan", "Feb", "Mar", "Apr", "May", "Jun",
kono
parents:
diff changeset
158 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
kono
parents:
diff changeset
159
kono
parents:
diff changeset
160 M1 : constant Character := Opt.Compilation_Time (6);
kono
parents:
diff changeset
161 M2 : constant Character := Opt.Compilation_Time (7);
kono
parents:
diff changeset
162
kono
parents:
diff changeset
163 MM : constant Natural range 1 .. 12 :=
kono
parents:
diff changeset
164 (Character'Pos (M1) - Character'Pos ('0')) * 10 +
kono
parents:
diff changeset
165 (Character'Pos (M2) - Character'Pos ('0'));
kono
parents:
diff changeset
166
kono
parents:
diff changeset
167 begin
kono
parents:
diff changeset
168 -- Reformat ISO date into MMM DD YYYY (__DATE__) format
kono
parents:
diff changeset
169
kono
parents:
diff changeset
170 Append (Buf, Months (MM));
kono
parents:
diff changeset
171 Append (Buf, ' ');
kono
parents:
diff changeset
172 Append (Buf, Opt.Compilation_Time (9 .. 10));
kono
parents:
diff changeset
173 Append (Buf, ' ');
kono
parents:
diff changeset
174 Append (Buf, Opt.Compilation_Time (1 .. 4));
kono
parents:
diff changeset
175 end;
kono
parents:
diff changeset
176
kono
parents:
diff changeset
177 when Name_Compilation_Time =>
kono
parents:
diff changeset
178 Append (Buf, Opt.Compilation_Time (12 .. 19));
kono
parents:
diff changeset
179
kono
parents:
diff changeset
180 when others =>
kono
parents:
diff changeset
181 raise Program_Error;
kono
parents:
diff changeset
182 end case;
kono
parents:
diff changeset
183 end Add_Source_Info;
kono
parents:
diff changeset
184
kono
parents:
diff changeset
185 ---------------------------------
kono
parents:
diff changeset
186 -- Expand_Binary_Operator_Call --
kono
parents:
diff changeset
187 ---------------------------------
kono
parents:
diff changeset
188
kono
parents:
diff changeset
189 procedure Expand_Binary_Operator_Call (N : Node_Id) is
kono
parents:
diff changeset
190 T1 : constant Entity_Id := Underlying_Type (Etype (Left_Opnd (N)));
kono
parents:
diff changeset
191 T2 : constant Entity_Id := Underlying_Type (Etype (Right_Opnd (N)));
kono
parents:
diff changeset
192 TR : constant Entity_Id := Etype (N);
kono
parents:
diff changeset
193 T3 : Entity_Id;
kono
parents:
diff changeset
194 Res : Node_Id;
kono
parents:
diff changeset
195
kono
parents:
diff changeset
196 Siz : constant Uint := UI_Max (RM_Size (T1), RM_Size (T2));
kono
parents:
diff changeset
197 -- Maximum of operand sizes
kono
parents:
diff changeset
198
kono
parents:
diff changeset
199 begin
kono
parents:
diff changeset
200 -- Nothing to do if the operands have the same modular type
kono
parents:
diff changeset
201
kono
parents:
diff changeset
202 if Base_Type (T1) = Base_Type (T2)
kono
parents:
diff changeset
203 and then Is_Modular_Integer_Type (T1)
kono
parents:
diff changeset
204 then
kono
parents:
diff changeset
205 return;
kono
parents:
diff changeset
206 end if;
kono
parents:
diff changeset
207
kono
parents:
diff changeset
208 -- Use Unsigned_32 for sizes of 32 or below, else Unsigned_64
kono
parents:
diff changeset
209
kono
parents:
diff changeset
210 if Siz > 32 then
kono
parents:
diff changeset
211 T3 := RTE (RE_Unsigned_64);
kono
parents:
diff changeset
212 else
kono
parents:
diff changeset
213 T3 := RTE (RE_Unsigned_32);
kono
parents:
diff changeset
214 end if;
kono
parents:
diff changeset
215
kono
parents:
diff changeset
216 -- Copy operator node, and reset type and entity fields, for
kono
parents:
diff changeset
217 -- subsequent reanalysis.
kono
parents:
diff changeset
218
kono
parents:
diff changeset
219 Res := New_Copy (N);
kono
parents:
diff changeset
220 Set_Etype (Res, T3);
kono
parents:
diff changeset
221
kono
parents:
diff changeset
222 case Nkind (N) is
kono
parents:
diff changeset
223 when N_Op_And => Set_Entity (Res, Standard_Op_And);
kono
parents:
diff changeset
224 when N_Op_Or => Set_Entity (Res, Standard_Op_Or);
kono
parents:
diff changeset
225 when N_Op_Xor => Set_Entity (Res, Standard_Op_Xor);
kono
parents:
diff changeset
226 when others => raise Program_Error;
kono
parents:
diff changeset
227 end case;
kono
parents:
diff changeset
228
kono
parents:
diff changeset
229 -- Convert operands to large enough intermediate type
kono
parents:
diff changeset
230
kono
parents:
diff changeset
231 Set_Left_Opnd (Res,
kono
parents:
diff changeset
232 Unchecked_Convert_To (T3, Relocate_Node (Left_Opnd (N))));
kono
parents:
diff changeset
233 Set_Right_Opnd (Res,
kono
parents:
diff changeset
234 Unchecked_Convert_To (T3, Relocate_Node (Right_Opnd (N))));
kono
parents:
diff changeset
235
kono
parents:
diff changeset
236 -- Analyze and resolve result formed by conversion to target type
kono
parents:
diff changeset
237
kono
parents:
diff changeset
238 Rewrite (N, Unchecked_Convert_To (TR, Res));
kono
parents:
diff changeset
239 Analyze_And_Resolve (N, TR);
kono
parents:
diff changeset
240 end Expand_Binary_Operator_Call;
kono
parents:
diff changeset
241
kono
parents:
diff changeset
242 -----------------------------------------
kono
parents:
diff changeset
243 -- Expand_Dispatching_Constructor_Call --
kono
parents:
diff changeset
244 -----------------------------------------
kono
parents:
diff changeset
245
kono
parents:
diff changeset
246 -- Transform a call to an instantiation of Generic_Dispatching_Constructor
kono
parents:
diff changeset
247 -- of the form:
kono
parents:
diff changeset
248
kono
parents:
diff changeset
249 -- GDC_Instance (The_Tag, Parameters'Access)
kono
parents:
diff changeset
250
kono
parents:
diff changeset
251 -- to a class-wide conversion of a dispatching call to the actual
kono
parents:
diff changeset
252 -- associated with the formal subprogram Construct, designating The_Tag
kono
parents:
diff changeset
253 -- as the controlling tag of the call:
kono
parents:
diff changeset
254
kono
parents:
diff changeset
255 -- T'Class (Construct'Actual (Params)) -- Controlling tag is The_Tag
kono
parents:
diff changeset
256
kono
parents:
diff changeset
257 -- which will eventually be expanded to the following:
kono
parents:
diff changeset
258
kono
parents:
diff changeset
259 -- T'Class (The_Tag.all (Construct'Actual'Index).all (Params))
kono
parents:
diff changeset
260
kono
parents:
diff changeset
261 -- A class-wide membership test is also generated, preceding the call, to
kono
parents:
diff changeset
262 -- ensure that the controlling tag denotes a type in T'Class.
kono
parents:
diff changeset
263
kono
parents:
diff changeset
264 procedure Expand_Dispatching_Constructor_Call (N : Node_Id) is
kono
parents:
diff changeset
265 Loc : constant Source_Ptr := Sloc (N);
kono
parents:
diff changeset
266 Tag_Arg : constant Node_Id := First_Actual (N);
kono
parents:
diff changeset
267 Param_Arg : constant Node_Id := Next_Actual (Tag_Arg);
kono
parents:
diff changeset
268 Subp_Decl : constant Node_Id := Parent (Parent (Entity (Name (N))));
kono
parents:
diff changeset
269 Inst_Pkg : constant Node_Id := Parent (Subp_Decl);
kono
parents:
diff changeset
270 Act_Rename : Node_Id;
kono
parents:
diff changeset
271 Act_Constr : Entity_Id;
kono
parents:
diff changeset
272 Iface_Tag : Node_Id := Empty;
kono
parents:
diff changeset
273 Cnstr_Call : Node_Id;
kono
parents:
diff changeset
274 Result_Typ : Entity_Id;
kono
parents:
diff changeset
275
kono
parents:
diff changeset
276 begin
kono
parents:
diff changeset
277 -- Remove side effects from tag argument early, before rewriting
kono
parents:
diff changeset
278 -- the dispatching constructor call, as Remove_Side_Effects relies
kono
parents:
diff changeset
279 -- on Tag_Arg's Parent link properly attached to the tree (once the
kono
parents:
diff changeset
280 -- call is rewritten, the Parent is inconsistent as it points to the
kono
parents:
diff changeset
281 -- rewritten node, which is not the syntactic parent of the Tag_Arg
kono
parents:
diff changeset
282 -- anymore).
kono
parents:
diff changeset
283
kono
parents:
diff changeset
284 Remove_Side_Effects (Tag_Arg);
kono
parents:
diff changeset
285
kono
parents:
diff changeset
286 -- Check that we have a proper tag
kono
parents:
diff changeset
287
kono
parents:
diff changeset
288 Insert_Action (N,
kono
parents:
diff changeset
289 Make_Implicit_If_Statement (N,
kono
parents:
diff changeset
290 Condition => Make_Op_Eq (Loc,
kono
parents:
diff changeset
291 Left_Opnd => New_Copy_Tree (Tag_Arg),
kono
parents:
diff changeset
292 Right_Opnd => New_Occurrence_Of (RTE (RE_No_Tag), Loc)),
kono
parents:
diff changeset
293
kono
parents:
diff changeset
294 Then_Statements => New_List (
kono
parents:
diff changeset
295 Make_Raise_Statement (Loc,
kono
parents:
diff changeset
296 New_Occurrence_Of (RTE (RE_Tag_Error), Loc)))));
kono
parents:
diff changeset
297
kono
parents:
diff changeset
298 -- Check that it is not the tag of an abstract type
kono
parents:
diff changeset
299
kono
parents:
diff changeset
300 Insert_Action (N,
kono
parents:
diff changeset
301 Make_Implicit_If_Statement (N,
kono
parents:
diff changeset
302 Condition => Make_Function_Call (Loc,
kono
parents:
diff changeset
303 Name =>
kono
parents:
diff changeset
304 New_Occurrence_Of (RTE (RE_Is_Abstract), Loc),
kono
parents:
diff changeset
305 Parameter_Associations => New_List (New_Copy_Tree (Tag_Arg))),
kono
parents:
diff changeset
306
kono
parents:
diff changeset
307 Then_Statements => New_List (
kono
parents:
diff changeset
308 Make_Raise_Statement (Loc,
kono
parents:
diff changeset
309 New_Occurrence_Of (RTE (RE_Tag_Error), Loc)))));
kono
parents:
diff changeset
310
kono
parents:
diff changeset
311 -- The subprogram is the third actual in the instantiation, and is
kono
parents:
diff changeset
312 -- retrieved from the corresponding renaming declaration. However,
kono
parents:
diff changeset
313 -- freeze nodes may appear before, so we retrieve the declaration
kono
parents:
diff changeset
314 -- with an explicit loop.
kono
parents:
diff changeset
315
kono
parents:
diff changeset
316 Act_Rename := First (Visible_Declarations (Inst_Pkg));
kono
parents:
diff changeset
317 while Nkind (Act_Rename) /= N_Subprogram_Renaming_Declaration loop
kono
parents:
diff changeset
318 Next (Act_Rename);
kono
parents:
diff changeset
319 end loop;
kono
parents:
diff changeset
320
kono
parents:
diff changeset
321 Act_Constr := Entity (Name (Act_Rename));
kono
parents:
diff changeset
322 Result_Typ := Class_Wide_Type (Etype (Act_Constr));
kono
parents:
diff changeset
323
kono
parents:
diff changeset
324 -- Check that the accessibility level of the tag is no deeper than that
kono
parents:
diff changeset
325 -- of the constructor function (unless CodePeer_Mode)
kono
parents:
diff changeset
326
kono
parents:
diff changeset
327 if not CodePeer_Mode then
kono
parents:
diff changeset
328 Insert_Action (N,
kono
parents:
diff changeset
329 Make_Implicit_If_Statement (N,
kono
parents:
diff changeset
330 Condition =>
kono
parents:
diff changeset
331 Make_Op_Gt (Loc,
kono
parents:
diff changeset
332 Left_Opnd =>
kono
parents:
diff changeset
333 Build_Get_Access_Level (Loc, New_Copy_Tree (Tag_Arg)),
kono
parents:
diff changeset
334 Right_Opnd =>
kono
parents:
diff changeset
335 Make_Integer_Literal (Loc, Scope_Depth (Act_Constr))),
kono
parents:
diff changeset
336
kono
parents:
diff changeset
337 Then_Statements => New_List (
kono
parents:
diff changeset
338 Make_Raise_Statement (Loc,
kono
parents:
diff changeset
339 New_Occurrence_Of (RTE (RE_Tag_Error), Loc)))));
kono
parents:
diff changeset
340 end if;
kono
parents:
diff changeset
341
kono
parents:
diff changeset
342 if Is_Interface (Etype (Act_Constr)) then
kono
parents:
diff changeset
343
kono
parents:
diff changeset
344 -- If the result type is not known to be a parent of Tag_Arg then we
kono
parents:
diff changeset
345 -- need to locate the tag of the secondary dispatch table.
kono
parents:
diff changeset
346
kono
parents:
diff changeset
347 if not Is_Ancestor (Etype (Result_Typ), Etype (Tag_Arg),
kono
parents:
diff changeset
348 Use_Full_View => True)
kono
parents:
diff changeset
349 and then Tagged_Type_Expansion
kono
parents:
diff changeset
350 then
kono
parents:
diff changeset
351 -- Obtain the reference to the Ada.Tags service before generating
kono
parents:
diff changeset
352 -- the Object_Declaration node to ensure that if this service is
kono
parents:
diff changeset
353 -- not available in the runtime then we generate a clear error.
kono
parents:
diff changeset
354
kono
parents:
diff changeset
355 declare
kono
parents:
diff changeset
356 Fname : constant Node_Id :=
kono
parents:
diff changeset
357 New_Occurrence_Of (RTE (RE_Secondary_Tag), Loc);
kono
parents:
diff changeset
358
kono
parents:
diff changeset
359 begin
kono
parents:
diff changeset
360 pragma Assert (not Is_Interface (Etype (Tag_Arg)));
kono
parents:
diff changeset
361
kono
parents:
diff changeset
362 -- The tag is the first entry in the dispatch table of the
kono
parents:
diff changeset
363 -- return type of the constructor.
kono
parents:
diff changeset
364
kono
parents:
diff changeset
365 Iface_Tag :=
kono
parents:
diff changeset
366 Make_Object_Declaration (Loc,
kono
parents:
diff changeset
367 Defining_Identifier => Make_Temporary (Loc, 'V'),
kono
parents:
diff changeset
368 Object_Definition =>
kono
parents:
diff changeset
369 New_Occurrence_Of (RTE (RE_Tag), Loc),
kono
parents:
diff changeset
370 Expression =>
kono
parents:
diff changeset
371 Make_Function_Call (Loc,
kono
parents:
diff changeset
372 Name => Fname,
kono
parents:
diff changeset
373 Parameter_Associations => New_List (
kono
parents:
diff changeset
374 Relocate_Node (Tag_Arg),
kono
parents:
diff changeset
375 New_Occurrence_Of
kono
parents:
diff changeset
376 (Node (First_Elmt
kono
parents:
diff changeset
377 (Access_Disp_Table (Etype (Act_Constr)))),
kono
parents:
diff changeset
378 Loc))));
kono
parents:
diff changeset
379 Insert_Action (N, Iface_Tag);
kono
parents:
diff changeset
380 end;
kono
parents:
diff changeset
381 end if;
kono
parents:
diff changeset
382 end if;
kono
parents:
diff changeset
383
kono
parents:
diff changeset
384 -- Create the call to the actual Constructor function
kono
parents:
diff changeset
385
kono
parents:
diff changeset
386 Cnstr_Call :=
kono
parents:
diff changeset
387 Make_Function_Call (Loc,
kono
parents:
diff changeset
388 Name => New_Occurrence_Of (Act_Constr, Loc),
kono
parents:
diff changeset
389 Parameter_Associations => New_List (Relocate_Node (Param_Arg)));
kono
parents:
diff changeset
390
kono
parents:
diff changeset
391 -- Establish its controlling tag from the tag passed to the instance
kono
parents:
diff changeset
392 -- The tag may be given by a function call, in which case a temporary
kono
parents:
diff changeset
393 -- should be generated now, to prevent out-of-order insertions during
kono
parents:
diff changeset
394 -- the expansion of that call when stack-checking is enabled.
kono
parents:
diff changeset
395
kono
parents:
diff changeset
396 if Present (Iface_Tag) then
kono
parents:
diff changeset
397 Set_Controlling_Argument (Cnstr_Call,
kono
parents:
diff changeset
398 New_Occurrence_Of (Defining_Identifier (Iface_Tag), Loc));
kono
parents:
diff changeset
399 else
kono
parents:
diff changeset
400 Set_Controlling_Argument (Cnstr_Call,
kono
parents:
diff changeset
401 Relocate_Node (Tag_Arg));
kono
parents:
diff changeset
402 end if;
kono
parents:
diff changeset
403
kono
parents:
diff changeset
404 -- Rewrite and analyze the call to the instance as a class-wide
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
405 -- conversion of the call to the actual constructor. When the result
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
406 -- type is a class-wide interface type this conversion is required to
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
407 -- force the displacement of the pointer to the object to reference the
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
408 -- corresponding dispatch table.
111
kono
parents:
diff changeset
409
kono
parents:
diff changeset
410 Rewrite (N, Convert_To (Result_Typ, Cnstr_Call));
kono
parents:
diff changeset
411
kono
parents:
diff changeset
412 -- Do not generate a run-time check on the built object if tag
kono
parents:
diff changeset
413 -- checks are suppressed for the result type or tagged type expansion
kono
parents:
diff changeset
414 -- is disabled or if CodePeer_Mode.
kono
parents:
diff changeset
415
kono
parents:
diff changeset
416 if Tag_Checks_Suppressed (Etype (Result_Typ))
kono
parents:
diff changeset
417 or else not Tagged_Type_Expansion
kono
parents:
diff changeset
418 or else CodePeer_Mode
kono
parents:
diff changeset
419 then
kono
parents:
diff changeset
420 null;
kono
parents:
diff changeset
421
kono
parents:
diff changeset
422 -- Generate a class-wide membership test to ensure that the call's tag
kono
parents:
diff changeset
423 -- argument denotes a type within the class. We must keep separate the
kono
parents:
diff changeset
424 -- case in which the Result_Type of the constructor function is a tagged
kono
parents:
diff changeset
425 -- type from the case in which it is an abstract interface because the
kono
parents:
diff changeset
426 -- run-time subprogram required to check these cases differ (and have
kono
parents:
diff changeset
427 -- one difference in their parameters profile).
kono
parents:
diff changeset
428
kono
parents:
diff changeset
429 -- Call CW_Membership if the Result_Type is a tagged type to look for
kono
parents:
diff changeset
430 -- the tag in the table of ancestor tags.
kono
parents:
diff changeset
431
kono
parents:
diff changeset
432 elsif not Is_Interface (Result_Typ) then
kono
parents:
diff changeset
433 declare
kono
parents:
diff changeset
434 Obj_Tag_Node : Node_Id := New_Copy_Tree (Tag_Arg);
kono
parents:
diff changeset
435 CW_Test_Node : Node_Id;
kono
parents:
diff changeset
436
kono
parents:
diff changeset
437 begin
kono
parents:
diff changeset
438 Build_CW_Membership (Loc,
kono
parents:
diff changeset
439 Obj_Tag_Node => Obj_Tag_Node,
kono
parents:
diff changeset
440 Typ_Tag_Node =>
kono
parents:
diff changeset
441 New_Occurrence_Of (
kono
parents:
diff changeset
442 Node (First_Elmt (Access_Disp_Table (
kono
parents:
diff changeset
443 Root_Type (Result_Typ)))), Loc),
kono
parents:
diff changeset
444 Related_Nod => N,
kono
parents:
diff changeset
445 New_Node => CW_Test_Node);
kono
parents:
diff changeset
446
kono
parents:
diff changeset
447 Insert_Action (N,
kono
parents:
diff changeset
448 Make_Implicit_If_Statement (N,
kono
parents:
diff changeset
449 Condition =>
kono
parents:
diff changeset
450 Make_Op_Not (Loc, CW_Test_Node),
kono
parents:
diff changeset
451 Then_Statements =>
kono
parents:
diff changeset
452 New_List (Make_Raise_Statement (Loc,
kono
parents:
diff changeset
453 New_Occurrence_Of (RTE (RE_Tag_Error), Loc)))));
kono
parents:
diff changeset
454 end;
kono
parents:
diff changeset
455
kono
parents:
diff changeset
456 -- Call IW_Membership test if the Result_Type is an abstract interface
kono
parents:
diff changeset
457 -- to look for the tag in the table of interface tags.
kono
parents:
diff changeset
458
kono
parents:
diff changeset
459 else
kono
parents:
diff changeset
460 Insert_Action (N,
kono
parents:
diff changeset
461 Make_Implicit_If_Statement (N,
kono
parents:
diff changeset
462 Condition =>
kono
parents:
diff changeset
463 Make_Op_Not (Loc,
kono
parents:
diff changeset
464 Make_Function_Call (Loc,
kono
parents:
diff changeset
465 Name => New_Occurrence_Of (RTE (RE_IW_Membership), Loc),
kono
parents:
diff changeset
466 Parameter_Associations => New_List (
kono
parents:
diff changeset
467 Make_Attribute_Reference (Loc,
kono
parents:
diff changeset
468 Prefix => New_Copy_Tree (Tag_Arg),
kono
parents:
diff changeset
469 Attribute_Name => Name_Address),
kono
parents:
diff changeset
470
kono
parents:
diff changeset
471 New_Occurrence_Of (
kono
parents:
diff changeset
472 Node (First_Elmt (Access_Disp_Table (
kono
parents:
diff changeset
473 Root_Type (Result_Typ)))), Loc)))),
kono
parents:
diff changeset
474 Then_Statements =>
kono
parents:
diff changeset
475 New_List (
kono
parents:
diff changeset
476 Make_Raise_Statement (Loc,
kono
parents:
diff changeset
477 Name => New_Occurrence_Of (RTE (RE_Tag_Error), Loc)))));
kono
parents:
diff changeset
478 end if;
kono
parents:
diff changeset
479
kono
parents:
diff changeset
480 Analyze_And_Resolve (N, Etype (Act_Constr));
kono
parents:
diff changeset
481 end Expand_Dispatching_Constructor_Call;
kono
parents:
diff changeset
482
kono
parents:
diff changeset
483 ---------------------------
kono
parents:
diff changeset
484 -- Expand_Exception_Call --
kono
parents:
diff changeset
485 ---------------------------
kono
parents:
diff changeset
486
kono
parents:
diff changeset
487 -- If the function call is not within an exception handler, then the call
kono
parents:
diff changeset
488 -- is replaced by a null string. Otherwise the appropriate routine in
kono
parents:
diff changeset
489 -- Ada.Exceptions is called passing the choice parameter specification
kono
parents:
diff changeset
490 -- from the enclosing handler. If the enclosing handler lacks a choice
kono
parents:
diff changeset
491 -- parameter, then one is supplied.
kono
parents:
diff changeset
492
kono
parents:
diff changeset
493 procedure Expand_Exception_Call (N : Node_Id; Ent : RE_Id) is
kono
parents:
diff changeset
494 Loc : constant Source_Ptr := Sloc (N);
kono
parents:
diff changeset
495 P : Node_Id;
kono
parents:
diff changeset
496 E : Entity_Id;
kono
parents:
diff changeset
497
kono
parents:
diff changeset
498 begin
kono
parents:
diff changeset
499 -- Climb up parents to see if we are in exception handler
kono
parents:
diff changeset
500
kono
parents:
diff changeset
501 P := Parent (N);
kono
parents:
diff changeset
502 loop
kono
parents:
diff changeset
503 -- Case of not in exception handler, replace by null string
kono
parents:
diff changeset
504
kono
parents:
diff changeset
505 if No (P) then
kono
parents:
diff changeset
506 Rewrite (N,
kono
parents:
diff changeset
507 Make_String_Literal (Loc,
kono
parents:
diff changeset
508 Strval => ""));
kono
parents:
diff changeset
509 exit;
kono
parents:
diff changeset
510
kono
parents:
diff changeset
511 -- Case of in exception handler
kono
parents:
diff changeset
512
kono
parents:
diff changeset
513 elsif Nkind (P) = N_Exception_Handler then
kono
parents:
diff changeset
514
kono
parents:
diff changeset
515 -- Handler cannot be used for a local raise, and furthermore, this
kono
parents:
diff changeset
516 -- is a violation of the No_Exception_Propagation restriction.
kono
parents:
diff changeset
517
kono
parents:
diff changeset
518 Set_Local_Raise_Not_OK (P);
kono
parents:
diff changeset
519 Check_Restriction (No_Exception_Propagation, N);
kono
parents:
diff changeset
520
kono
parents:
diff changeset
521 -- If no choice parameter present, then put one there. Note that
kono
parents:
diff changeset
522 -- we do not need to put it on the entity chain, since no one will
kono
parents:
diff changeset
523 -- be referencing it by normal visibility methods.
kono
parents:
diff changeset
524
kono
parents:
diff changeset
525 if No (Choice_Parameter (P)) then
kono
parents:
diff changeset
526 E := Make_Temporary (Loc, 'E');
kono
parents:
diff changeset
527 Set_Choice_Parameter (P, E);
kono
parents:
diff changeset
528 Set_Ekind (E, E_Variable);
kono
parents:
diff changeset
529 Set_Etype (E, RTE (RE_Exception_Occurrence));
kono
parents:
diff changeset
530 Set_Scope (E, Current_Scope);
kono
parents:
diff changeset
531 end if;
kono
parents:
diff changeset
532
kono
parents:
diff changeset
533 Rewrite (N,
kono
parents:
diff changeset
534 Make_Function_Call (Loc,
kono
parents:
diff changeset
535 Name => New_Occurrence_Of (RTE (Ent), Loc),
kono
parents:
diff changeset
536 Parameter_Associations => New_List (
kono
parents:
diff changeset
537 New_Occurrence_Of (Choice_Parameter (P), Loc))));
kono
parents:
diff changeset
538 exit;
kono
parents:
diff changeset
539
kono
parents:
diff changeset
540 -- Keep climbing
kono
parents:
diff changeset
541
kono
parents:
diff changeset
542 else
kono
parents:
diff changeset
543 P := Parent (P);
kono
parents:
diff changeset
544 end if;
kono
parents:
diff changeset
545 end loop;
kono
parents:
diff changeset
546
kono
parents:
diff changeset
547 Analyze_And_Resolve (N, Standard_String);
kono
parents:
diff changeset
548 end Expand_Exception_Call;
kono
parents:
diff changeset
549
kono
parents:
diff changeset
550 ------------------------
kono
parents:
diff changeset
551 -- Expand_Import_Call --
kono
parents:
diff changeset
552 ------------------------
kono
parents:
diff changeset
553
kono
parents:
diff changeset
554 -- The function call must have a static string as its argument. We create
kono
parents:
diff changeset
555 -- a dummy variable which uses this string as the external name in an
kono
parents:
diff changeset
556 -- Import pragma. The result is then obtained as the address of this
kono
parents:
diff changeset
557 -- dummy variable, converted to the appropriate target type.
kono
parents:
diff changeset
558
kono
parents:
diff changeset
559 procedure Expand_Import_Call (N : Node_Id) is
kono
parents:
diff changeset
560 Loc : constant Source_Ptr := Sloc (N);
kono
parents:
diff changeset
561 Ent : constant Entity_Id := Entity (Name (N));
kono
parents:
diff changeset
562 Str : constant Node_Id := First_Actual (N);
kono
parents:
diff changeset
563 Dum : constant Entity_Id := Make_Temporary (Loc, 'D');
kono
parents:
diff changeset
564
kono
parents:
diff changeset
565 begin
kono
parents:
diff changeset
566 Insert_Actions (N, New_List (
kono
parents:
diff changeset
567 Make_Object_Declaration (Loc,
kono
parents:
diff changeset
568 Defining_Identifier => Dum,
kono
parents:
diff changeset
569 Object_Definition =>
kono
parents:
diff changeset
570 New_Occurrence_Of (Standard_Character, Loc)),
kono
parents:
diff changeset
571
kono
parents:
diff changeset
572 Make_Pragma (Loc,
kono
parents:
diff changeset
573 Chars => Name_Import,
kono
parents:
diff changeset
574 Pragma_Argument_Associations => New_List (
kono
parents:
diff changeset
575 Make_Pragma_Argument_Association (Loc,
kono
parents:
diff changeset
576 Expression => Make_Identifier (Loc, Name_Ada)),
kono
parents:
diff changeset
577
kono
parents:
diff changeset
578 Make_Pragma_Argument_Association (Loc,
kono
parents:
diff changeset
579 Expression => Make_Identifier (Loc, Chars (Dum))),
kono
parents:
diff changeset
580
kono
parents:
diff changeset
581 Make_Pragma_Argument_Association (Loc,
kono
parents:
diff changeset
582 Chars => Name_Link_Name,
kono
parents:
diff changeset
583 Expression => Relocate_Node (Str))))));
kono
parents:
diff changeset
584
kono
parents:
diff changeset
585 Rewrite (N,
kono
parents:
diff changeset
586 Unchecked_Convert_To (Etype (Ent),
kono
parents:
diff changeset
587 Make_Attribute_Reference (Loc,
kono
parents:
diff changeset
588 Prefix => Make_Identifier (Loc, Chars (Dum)),
kono
parents:
diff changeset
589 Attribute_Name => Name_Address)));
kono
parents:
diff changeset
590
kono
parents:
diff changeset
591 Analyze_And_Resolve (N, Etype (Ent));
kono
parents:
diff changeset
592 end Expand_Import_Call;
kono
parents:
diff changeset
593
kono
parents:
diff changeset
594 ---------------------------
kono
parents:
diff changeset
595 -- Expand_Intrinsic_Call --
kono
parents:
diff changeset
596 ---------------------------
kono
parents:
diff changeset
597
kono
parents:
diff changeset
598 procedure Expand_Intrinsic_Call (N : Node_Id; E : Entity_Id) is
kono
parents:
diff changeset
599 Nam : Name_Id;
kono
parents:
diff changeset
600
kono
parents:
diff changeset
601 begin
kono
parents:
diff changeset
602 -- If an external name is specified for the intrinsic, it is handled
kono
parents:
diff changeset
603 -- by the back-end: leave the call node unchanged for now.
kono
parents:
diff changeset
604
kono
parents:
diff changeset
605 if Present (Interface_Name (E)) then
kono
parents:
diff changeset
606 return;
kono
parents:
diff changeset
607 end if;
kono
parents:
diff changeset
608
kono
parents:
diff changeset
609 -- If the intrinsic subprogram is generic, gets its original name
kono
parents:
diff changeset
610
kono
parents:
diff changeset
611 if Present (Parent (E))
kono
parents:
diff changeset
612 and then Present (Generic_Parent (Parent (E)))
kono
parents:
diff changeset
613 then
kono
parents:
diff changeset
614 Nam := Chars (Generic_Parent (Parent (E)));
kono
parents:
diff changeset
615 else
kono
parents:
diff changeset
616 Nam := Chars (E);
kono
parents:
diff changeset
617 end if;
kono
parents:
diff changeset
618
kono
parents:
diff changeset
619 if Nam = Name_Asm then
kono
parents:
diff changeset
620 Expand_Asm_Call (N);
kono
parents:
diff changeset
621
kono
parents:
diff changeset
622 elsif Nam = Name_Divide then
kono
parents:
diff changeset
623 Expand_Decimal_Divide_Call (N);
kono
parents:
diff changeset
624
kono
parents:
diff changeset
625 elsif Nam = Name_Exception_Information then
kono
parents:
diff changeset
626 Expand_Exception_Call (N, RE_Exception_Information);
kono
parents:
diff changeset
627
kono
parents:
diff changeset
628 elsif Nam = Name_Exception_Message then
kono
parents:
diff changeset
629 Expand_Exception_Call (N, RE_Exception_Message);
kono
parents:
diff changeset
630
kono
parents:
diff changeset
631 elsif Nam = Name_Exception_Name then
kono
parents:
diff changeset
632 Expand_Exception_Call (N, RE_Exception_Name_Simple);
kono
parents:
diff changeset
633
kono
parents:
diff changeset
634 elsif Nam = Name_Generic_Dispatching_Constructor then
kono
parents:
diff changeset
635 Expand_Dispatching_Constructor_Call (N);
kono
parents:
diff changeset
636
kono
parents:
diff changeset
637 elsif Nam_In (Nam, Name_Import_Address,
kono
parents:
diff changeset
638 Name_Import_Largest_Value,
kono
parents:
diff changeset
639 Name_Import_Value)
kono
parents:
diff changeset
640 then
kono
parents:
diff changeset
641 Expand_Import_Call (N);
kono
parents:
diff changeset
642
kono
parents:
diff changeset
643 elsif Nam = Name_Is_Negative then
kono
parents:
diff changeset
644 Expand_Is_Negative (N);
kono
parents:
diff changeset
645
kono
parents:
diff changeset
646 elsif Nam = Name_Rotate_Left then
kono
parents:
diff changeset
647 Expand_Shift (N, E, N_Op_Rotate_Left);
kono
parents:
diff changeset
648
kono
parents:
diff changeset
649 elsif Nam = Name_Rotate_Right then
kono
parents:
diff changeset
650 Expand_Shift (N, E, N_Op_Rotate_Right);
kono
parents:
diff changeset
651
kono
parents:
diff changeset
652 elsif Nam = Name_Shift_Left then
kono
parents:
diff changeset
653 Expand_Shift (N, E, N_Op_Shift_Left);
kono
parents:
diff changeset
654
kono
parents:
diff changeset
655 elsif Nam = Name_Shift_Right then
kono
parents:
diff changeset
656 Expand_Shift (N, E, N_Op_Shift_Right);
kono
parents:
diff changeset
657
kono
parents:
diff changeset
658 elsif Nam = Name_Shift_Right_Arithmetic then
kono
parents:
diff changeset
659 Expand_Shift (N, E, N_Op_Shift_Right_Arithmetic);
kono
parents:
diff changeset
660
kono
parents:
diff changeset
661 elsif Nam = Name_Unchecked_Conversion then
kono
parents:
diff changeset
662 Expand_Unc_Conversion (N, E);
kono
parents:
diff changeset
663
kono
parents:
diff changeset
664 elsif Nam = Name_Unchecked_Deallocation then
kono
parents:
diff changeset
665 Expand_Unc_Deallocation (N);
kono
parents:
diff changeset
666
kono
parents:
diff changeset
667 elsif Nam = Name_To_Address then
kono
parents:
diff changeset
668 Expand_To_Address (N);
kono
parents:
diff changeset
669
kono
parents:
diff changeset
670 elsif Nam = Name_To_Pointer then
kono
parents:
diff changeset
671 Expand_To_Pointer (N);
kono
parents:
diff changeset
672
kono
parents:
diff changeset
673 elsif Nam_In (Nam, Name_File,
kono
parents:
diff changeset
674 Name_Line,
kono
parents:
diff changeset
675 Name_Source_Location,
kono
parents:
diff changeset
676 Name_Enclosing_Entity,
kono
parents:
diff changeset
677 Name_Compilation_ISO_Date,
kono
parents:
diff changeset
678 Name_Compilation_Date,
kono
parents:
diff changeset
679 Name_Compilation_Time)
kono
parents:
diff changeset
680 then
kono
parents:
diff changeset
681 Expand_Source_Info (N, Nam);
kono
parents:
diff changeset
682
kono
parents:
diff changeset
683 -- If we have a renaming, expand the call to the original operation,
kono
parents:
diff changeset
684 -- which must itself be intrinsic, since renaming requires matching
kono
parents:
diff changeset
685 -- conventions and this has already been checked.
kono
parents:
diff changeset
686
kono
parents:
diff changeset
687 elsif Present (Alias (E)) then
kono
parents:
diff changeset
688 Expand_Intrinsic_Call (N, Alias (E));
kono
parents:
diff changeset
689
kono
parents:
diff changeset
690 elsif Nkind (N) in N_Binary_Op then
kono
parents:
diff changeset
691 Expand_Binary_Operator_Call (N);
kono
parents:
diff changeset
692
kono
parents:
diff changeset
693 -- The only other case is where an external name was specified, since
kono
parents:
diff changeset
694 -- this is the only way that an otherwise unrecognized name could
kono
parents:
diff changeset
695 -- escape the checking in Sem_Prag. Nothing needs to be done in such
kono
parents:
diff changeset
696 -- a case, since we pass such a call to the back end unchanged.
kono
parents:
diff changeset
697
kono
parents:
diff changeset
698 else
kono
parents:
diff changeset
699 null;
kono
parents:
diff changeset
700 end if;
kono
parents:
diff changeset
701 end Expand_Intrinsic_Call;
kono
parents:
diff changeset
702
kono
parents:
diff changeset
703 ------------------------
kono
parents:
diff changeset
704 -- Expand_Is_Negative --
kono
parents:
diff changeset
705 ------------------------
kono
parents:
diff changeset
706
kono
parents:
diff changeset
707 procedure Expand_Is_Negative (N : Node_Id) is
kono
parents:
diff changeset
708 Loc : constant Source_Ptr := Sloc (N);
kono
parents:
diff changeset
709 Opnd : constant Node_Id := Relocate_Node (First_Actual (N));
kono
parents:
diff changeset
710
kono
parents:
diff changeset
711 begin
kono
parents:
diff changeset
712
kono
parents:
diff changeset
713 -- We replace the function call by the following expression
kono
parents:
diff changeset
714
kono
parents:
diff changeset
715 -- if Opnd < 0.0 then
kono
parents:
diff changeset
716 -- True
kono
parents:
diff changeset
717 -- else
kono
parents:
diff changeset
718 -- if Opnd > 0.0 then
kono
parents:
diff changeset
719 -- False;
kono
parents:
diff changeset
720 -- else
kono
parents:
diff changeset
721 -- Float_Unsigned!(Float (Opnd)) /= 0
kono
parents:
diff changeset
722 -- end if;
kono
parents:
diff changeset
723 -- end if;
kono
parents:
diff changeset
724
kono
parents:
diff changeset
725 Rewrite (N,
kono
parents:
diff changeset
726 Make_If_Expression (Loc,
kono
parents:
diff changeset
727 Expressions => New_List (
kono
parents:
diff changeset
728 Make_Op_Lt (Loc,
kono
parents:
diff changeset
729 Left_Opnd => Duplicate_Subexpr (Opnd),
kono
parents:
diff changeset
730 Right_Opnd => Make_Real_Literal (Loc, Ureal_0)),
kono
parents:
diff changeset
731
kono
parents:
diff changeset
732 New_Occurrence_Of (Standard_True, Loc),
kono
parents:
diff changeset
733
kono
parents:
diff changeset
734 Make_If_Expression (Loc,
kono
parents:
diff changeset
735 Expressions => New_List (
kono
parents:
diff changeset
736 Make_Op_Gt (Loc,
kono
parents:
diff changeset
737 Left_Opnd => Duplicate_Subexpr_No_Checks (Opnd),
kono
parents:
diff changeset
738 Right_Opnd => Make_Real_Literal (Loc, Ureal_0)),
kono
parents:
diff changeset
739
kono
parents:
diff changeset
740 New_Occurrence_Of (Standard_False, Loc),
kono
parents:
diff changeset
741
kono
parents:
diff changeset
742 Make_Op_Ne (Loc,
kono
parents:
diff changeset
743 Left_Opnd =>
kono
parents:
diff changeset
744 Unchecked_Convert_To
kono
parents:
diff changeset
745 (RTE (RE_Float_Unsigned),
kono
parents:
diff changeset
746 Convert_To
kono
parents:
diff changeset
747 (Standard_Float,
kono
parents:
diff changeset
748 Duplicate_Subexpr_No_Checks (Opnd))),
kono
parents:
diff changeset
749 Right_Opnd =>
kono
parents:
diff changeset
750 Make_Integer_Literal (Loc, 0)))))));
kono
parents:
diff changeset
751
kono
parents:
diff changeset
752 Analyze_And_Resolve (N, Standard_Boolean);
kono
parents:
diff changeset
753 end Expand_Is_Negative;
kono
parents:
diff changeset
754
kono
parents:
diff changeset
755 ------------------
kono
parents:
diff changeset
756 -- Expand_Shift --
kono
parents:
diff changeset
757 ------------------
kono
parents:
diff changeset
758
kono
parents:
diff changeset
759 -- This procedure is used to convert a call to a shift function to the
kono
parents:
diff changeset
760 -- corresponding operator node. This conversion is not done by the usual
kono
parents:
diff changeset
761 -- circuit for converting calls to operator functions (e.g. "+"(1,2)) to
kono
parents:
diff changeset
762 -- operator nodes, because shifts are not predefined operators.
kono
parents:
diff changeset
763
kono
parents:
diff changeset
764 -- As a result, whenever a shift is used in the source program, it will
kono
parents:
diff changeset
765 -- remain as a call until converted by this routine to the operator node
kono
parents:
diff changeset
766 -- form which the back end is expecting to see.
kono
parents:
diff changeset
767
kono
parents:
diff changeset
768 -- Note: it is possible for the expander to generate shift operator nodes
kono
parents:
diff changeset
769 -- directly, which will be analyzed in the normal manner by calling Analyze
kono
parents:
diff changeset
770 -- and Resolve. Such shift operator nodes will not be seen by Expand_Shift.
kono
parents:
diff changeset
771
kono
parents:
diff changeset
772 procedure Expand_Shift (N : Node_Id; E : Entity_Id; K : Node_Kind) is
kono
parents:
diff changeset
773 Entyp : constant Entity_Id := Etype (E);
kono
parents:
diff changeset
774 Left : constant Node_Id := First_Actual (N);
kono
parents:
diff changeset
775 Loc : constant Source_Ptr := Sloc (N);
kono
parents:
diff changeset
776 Right : constant Node_Id := Next_Actual (Left);
kono
parents:
diff changeset
777 Ltyp : constant Node_Id := Etype (Left);
kono
parents:
diff changeset
778 Rtyp : constant Node_Id := Etype (Right);
kono
parents:
diff changeset
779 Typ : constant Entity_Id := Etype (N);
kono
parents:
diff changeset
780 Snode : Node_Id;
kono
parents:
diff changeset
781
kono
parents:
diff changeset
782 begin
kono
parents:
diff changeset
783 Snode := New_Node (K, Loc);
kono
parents:
diff changeset
784 Set_Right_Opnd (Snode, Relocate_Node (Right));
kono
parents:
diff changeset
785 Set_Chars (Snode, Chars (E));
kono
parents:
diff changeset
786 Set_Etype (Snode, Base_Type (Entyp));
kono
parents:
diff changeset
787 Set_Entity (Snode, E);
kono
parents:
diff changeset
788
kono
parents:
diff changeset
789 if Compile_Time_Known_Value (Type_High_Bound (Rtyp))
kono
parents:
diff changeset
790 and then Expr_Value (Type_High_Bound (Rtyp)) < Esize (Ltyp)
kono
parents:
diff changeset
791 then
kono
parents:
diff changeset
792 Set_Shift_Count_OK (Snode, True);
kono
parents:
diff changeset
793 end if;
kono
parents:
diff changeset
794
kono
parents:
diff changeset
795 if Typ = Entyp then
kono
parents:
diff changeset
796
kono
parents:
diff changeset
797 -- Note that we don't call Analyze and Resolve on this node, because
kono
parents:
diff changeset
798 -- it already got analyzed and resolved when it was a function call.
kono
parents:
diff changeset
799
kono
parents:
diff changeset
800 Set_Left_Opnd (Snode, Relocate_Node (Left));
kono
parents:
diff changeset
801 Rewrite (N, Snode);
kono
parents:
diff changeset
802 Set_Analyzed (N);
kono
parents:
diff changeset
803
kono
parents:
diff changeset
804 -- However, we do call the expander, so that the expansion for
kono
parents:
diff changeset
805 -- rotates and shift_right_arithmetic happens if Modify_Tree_For_C
kono
parents:
diff changeset
806 -- is set.
kono
parents:
diff changeset
807
kono
parents:
diff changeset
808 if Expander_Active then
kono
parents:
diff changeset
809 Expand (N);
kono
parents:
diff changeset
810 end if;
kono
parents:
diff changeset
811
kono
parents:
diff changeset
812 else
kono
parents:
diff changeset
813 -- If the context type is not the type of the operator, it is an
kono
parents:
diff changeset
814 -- inherited operator for a derived type. Wrap the node in a
kono
parents:
diff changeset
815 -- conversion so that it is type-consistent for possible further
kono
parents:
diff changeset
816 -- expansion (e.g. within a lock-free protected type).
kono
parents:
diff changeset
817
kono
parents:
diff changeset
818 Set_Left_Opnd (Snode,
kono
parents:
diff changeset
819 Unchecked_Convert_To (Base_Type (Entyp), Relocate_Node (Left)));
kono
parents:
diff changeset
820 Rewrite (N, Unchecked_Convert_To (Typ, Snode));
kono
parents:
diff changeset
821
kono
parents:
diff changeset
822 -- Analyze and resolve result formed by conversion to target type
kono
parents:
diff changeset
823
kono
parents:
diff changeset
824 Analyze_And_Resolve (N, Typ);
kono
parents:
diff changeset
825 end if;
kono
parents:
diff changeset
826 end Expand_Shift;
kono
parents:
diff changeset
827
kono
parents:
diff changeset
828 ------------------------
kono
parents:
diff changeset
829 -- Expand_Source_Info --
kono
parents:
diff changeset
830 ------------------------
kono
parents:
diff changeset
831
kono
parents:
diff changeset
832 procedure Expand_Source_Info (N : Node_Id; Nam : Name_Id) is
kono
parents:
diff changeset
833 Loc : constant Source_Ptr := Sloc (N);
kono
parents:
diff changeset
834 begin
kono
parents:
diff changeset
835 -- Integer cases
kono
parents:
diff changeset
836
kono
parents:
diff changeset
837 if Nam = Name_Line then
kono
parents:
diff changeset
838 Rewrite (N,
kono
parents:
diff changeset
839 Make_Integer_Literal (Loc,
kono
parents:
diff changeset
840 Intval => UI_From_Int (Int (Get_Logical_Line_Number (Loc)))));
kono
parents:
diff changeset
841 Analyze_And_Resolve (N, Standard_Positive);
kono
parents:
diff changeset
842
kono
parents:
diff changeset
843 -- String cases
kono
parents:
diff changeset
844
kono
parents:
diff changeset
845 else
kono
parents:
diff changeset
846 declare
kono
parents:
diff changeset
847 Buf : Bounded_String;
kono
parents:
diff changeset
848 begin
kono
parents:
diff changeset
849 Add_Source_Info (Buf, Loc, Nam);
kono
parents:
diff changeset
850 Rewrite (N, Make_String_Literal (Loc, Strval => +Buf));
kono
parents:
diff changeset
851 Analyze_And_Resolve (N, Standard_String);
kono
parents:
diff changeset
852 end;
kono
parents:
diff changeset
853 end if;
kono
parents:
diff changeset
854
kono
parents:
diff changeset
855 Set_Is_Static_Expression (N);
kono
parents:
diff changeset
856 end Expand_Source_Info;
kono
parents:
diff changeset
857
kono
parents:
diff changeset
858 ---------------------------
kono
parents:
diff changeset
859 -- Expand_Unc_Conversion --
kono
parents:
diff changeset
860 ---------------------------
kono
parents:
diff changeset
861
kono
parents:
diff changeset
862 procedure Expand_Unc_Conversion (N : Node_Id; E : Entity_Id) is
kono
parents:
diff changeset
863 Func : constant Entity_Id := Entity (Name (N));
kono
parents:
diff changeset
864 Conv : Node_Id;
kono
parents:
diff changeset
865 Ftyp : Entity_Id;
kono
parents:
diff changeset
866 Ttyp : Entity_Id;
kono
parents:
diff changeset
867
kono
parents:
diff changeset
868 begin
kono
parents:
diff changeset
869 -- Rewrite as unchecked conversion node. Note that we must convert
kono
parents:
diff changeset
870 -- the operand to the formal type of the input parameter of the
kono
parents:
diff changeset
871 -- function, so that the resulting N_Unchecked_Type_Conversion
kono
parents:
diff changeset
872 -- call indicates the correct types for Gigi.
kono
parents:
diff changeset
873
kono
parents:
diff changeset
874 -- Right now, we only do this if a scalar type is involved. It is
kono
parents:
diff changeset
875 -- not clear if it is needed in other cases. If we do attempt to
kono
parents:
diff changeset
876 -- do the conversion unconditionally, it crashes 3411-018. To be
kono
parents:
diff changeset
877 -- investigated further ???
kono
parents:
diff changeset
878
kono
parents:
diff changeset
879 Conv := Relocate_Node (First_Actual (N));
kono
parents:
diff changeset
880 Ftyp := Etype (First_Formal (Func));
kono
parents:
diff changeset
881
kono
parents:
diff changeset
882 if Is_Scalar_Type (Ftyp) then
kono
parents:
diff changeset
883 Conv := Convert_To (Ftyp, Conv);
kono
parents:
diff changeset
884 Set_Parent (Conv, N);
kono
parents:
diff changeset
885 Analyze_And_Resolve (Conv);
kono
parents:
diff changeset
886 end if;
kono
parents:
diff changeset
887
kono
parents:
diff changeset
888 -- The instantiation of Unchecked_Conversion creates a wrapper package,
kono
parents:
diff changeset
889 -- and the target type is declared as a subtype of the actual. Recover
kono
parents:
diff changeset
890 -- the actual, which is the subtype indic. in the subtype declaration
kono
parents:
diff changeset
891 -- for the target type. This is semantically correct, and avoids
kono
parents:
diff changeset
892 -- anomalies with access subtypes. For entities, leave type as is.
kono
parents:
diff changeset
893
kono
parents:
diff changeset
894 -- We do the analysis here, because we do not want the compiler
kono
parents:
diff changeset
895 -- to try to optimize or otherwise reorganize the unchecked
kono
parents:
diff changeset
896 -- conversion node.
kono
parents:
diff changeset
897
kono
parents:
diff changeset
898 Ttyp := Etype (E);
kono
parents:
diff changeset
899
kono
parents:
diff changeset
900 if Is_Entity_Name (Conv) then
kono
parents:
diff changeset
901 null;
kono
parents:
diff changeset
902
kono
parents:
diff changeset
903 elsif Nkind (Parent (Ttyp)) = N_Subtype_Declaration then
kono
parents:
diff changeset
904 Ttyp := Entity (Subtype_Indication (Parent (Etype (E))));
kono
parents:
diff changeset
905
kono
parents:
diff changeset
906 elsif Is_Itype (Ttyp) then
kono
parents:
diff changeset
907 Ttyp :=
kono
parents:
diff changeset
908 Entity (Subtype_Indication (Associated_Node_For_Itype (Ttyp)));
kono
parents:
diff changeset
909 else
kono
parents:
diff changeset
910 raise Program_Error;
kono
parents:
diff changeset
911 end if;
kono
parents:
diff changeset
912
kono
parents:
diff changeset
913 Rewrite (N, Unchecked_Convert_To (Ttyp, Conv));
kono
parents:
diff changeset
914 Set_Etype (N, Ttyp);
kono
parents:
diff changeset
915 Set_Analyzed (N);
kono
parents:
diff changeset
916
kono
parents:
diff changeset
917 if Nkind (N) = N_Unchecked_Type_Conversion then
kono
parents:
diff changeset
918 Expand_N_Unchecked_Type_Conversion (N);
kono
parents:
diff changeset
919 end if;
kono
parents:
diff changeset
920 end Expand_Unc_Conversion;
kono
parents:
diff changeset
921
kono
parents:
diff changeset
922 -----------------------------
kono
parents:
diff changeset
923 -- Expand_Unc_Deallocation --
kono
parents:
diff changeset
924 -----------------------------
kono
parents:
diff changeset
925
kono
parents:
diff changeset
926 procedure Expand_Unc_Deallocation (N : Node_Id) is
kono
parents:
diff changeset
927 Arg : constant Node_Id := First_Actual (N);
kono
parents:
diff changeset
928 Loc : constant Source_Ptr := Sloc (N);
kono
parents:
diff changeset
929 Typ : constant Entity_Id := Etype (Arg);
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
930 Desig_Typ : constant Entity_Id :=
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
931 Available_View (Designated_Type (Typ));
111
kono
parents:
diff changeset
932 Needs_Fin : constant Boolean := Needs_Finalization (Desig_Typ);
kono
parents:
diff changeset
933 Root_Typ : constant Entity_Id := Underlying_Type (Root_Type (Typ));
kono
parents:
diff changeset
934 Pool : constant Entity_Id := Associated_Storage_Pool (Root_Typ);
kono
parents:
diff changeset
935 Stmts : constant List_Id := New_List;
kono
parents:
diff changeset
936
kono
parents:
diff changeset
937 Arg_Known_Non_Null : constant Boolean := Known_Non_Null (N);
kono
parents:
diff changeset
938 -- This captures whether we know the argument to be non-null so that
kono
parents:
diff changeset
939 -- we can avoid the test. The reason that we need to capture this is
kono
parents:
diff changeset
940 -- that we analyze some generated statements before properly attaching
kono
parents:
diff changeset
941 -- them to the tree, and that can disturb current value settings.
kono
parents:
diff changeset
942
kono
parents:
diff changeset
943 Exceptions_OK : constant Boolean :=
kono
parents:
diff changeset
944 not Restriction_Active (No_Exception_Propagation);
kono
parents:
diff changeset
945
kono
parents:
diff changeset
946 Abrt_Blk : Node_Id := Empty;
kono
parents:
diff changeset
947 Abrt_Blk_Id : Entity_Id;
kono
parents:
diff changeset
948 Abrt_HSS : Node_Id;
kono
parents:
diff changeset
949 AUD : Entity_Id;
kono
parents:
diff changeset
950 Fin_Blk : Node_Id;
kono
parents:
diff changeset
951 Fin_Call : Node_Id;
kono
parents:
diff changeset
952 Fin_Data : Finalization_Exception_Data;
kono
parents:
diff changeset
953 Free_Arg : Node_Id;
kono
parents:
diff changeset
954 Free_Nod : Node_Id;
kono
parents:
diff changeset
955 Gen_Code : Node_Id;
kono
parents:
diff changeset
956 Obj_Ref : Node_Id;
kono
parents:
diff changeset
957
kono
parents:
diff changeset
958 begin
kono
parents:
diff changeset
959 -- Nothing to do if we know the argument is null
kono
parents:
diff changeset
960
kono
parents:
diff changeset
961 if Known_Null (N) then
kono
parents:
diff changeset
962 return;
kono
parents:
diff changeset
963 end if;
kono
parents:
diff changeset
964
kono
parents:
diff changeset
965 -- Processing for pointer to controlled types. Generate:
kono
parents:
diff changeset
966
kono
parents:
diff changeset
967 -- Abrt : constant Boolean := ...;
kono
parents:
diff changeset
968 -- Ex : Exception_Occurrence;
kono
parents:
diff changeset
969 -- Raised : Boolean := False;
kono
parents:
diff changeset
970
kono
parents:
diff changeset
971 -- begin
kono
parents:
diff changeset
972 -- Abort_Defer;
kono
parents:
diff changeset
973
kono
parents:
diff changeset
974 -- begin
kono
parents:
diff changeset
975 -- [Deep_]Finalize (Obj_Ref);
kono
parents:
diff changeset
976
kono
parents:
diff changeset
977 -- exception
kono
parents:
diff changeset
978 -- when others =>
kono
parents:
diff changeset
979 -- if not Raised then
kono
parents:
diff changeset
980 -- Raised := True;
kono
parents:
diff changeset
981 -- Save_Occurrence (Ex, Get_Current_Excep.all.all);
kono
parents:
diff changeset
982 -- end;
kono
parents:
diff changeset
983 -- at end
kono
parents:
diff changeset
984 -- Abort_Undefer_Direct;
kono
parents:
diff changeset
985 -- end;
kono
parents:
diff changeset
986
kono
parents:
diff changeset
987 -- Depending on whether exception propagation is enabled and/or aborts
kono
parents:
diff changeset
988 -- are allowed, the generated code may lack block statements.
kono
parents:
diff changeset
989
kono
parents:
diff changeset
990 if Needs_Fin then
kono
parents:
diff changeset
991 Obj_Ref :=
kono
parents:
diff changeset
992 Make_Explicit_Dereference (Loc,
kono
parents:
diff changeset
993 Prefix => Duplicate_Subexpr_No_Checks (Arg));
kono
parents:
diff changeset
994
kono
parents:
diff changeset
995 -- If the designated type is tagged, the finalization call must
kono
parents:
diff changeset
996 -- dispatch because the designated type may not be the actual type
kono
parents:
diff changeset
997 -- of the object. If the type is synchronized, the deallocation
kono
parents:
diff changeset
998 -- applies to the corresponding record type.
kono
parents:
diff changeset
999
kono
parents:
diff changeset
1000 if Is_Tagged_Type (Desig_Typ) then
kono
parents:
diff changeset
1001 if Is_Concurrent_Type (Desig_Typ) then
kono
parents:
diff changeset
1002 Obj_Ref :=
kono
parents:
diff changeset
1003 Unchecked_Convert_To
kono
parents:
diff changeset
1004 (Class_Wide_Type (Corresponding_Record_Type (Desig_Typ)),
kono
parents:
diff changeset
1005 Obj_Ref);
kono
parents:
diff changeset
1006
kono
parents:
diff changeset
1007 elsif not Is_Class_Wide_Type (Desig_Typ) then
kono
parents:
diff changeset
1008 Obj_Ref :=
kono
parents:
diff changeset
1009 Unchecked_Convert_To (Class_Wide_Type (Desig_Typ), Obj_Ref);
kono
parents:
diff changeset
1010 end if;
kono
parents:
diff changeset
1011
kono
parents:
diff changeset
1012 -- Otherwise the designated type is untagged. Set the type of the
kono
parents:
diff changeset
1013 -- dereference explicitly to force a conversion when needed given
kono
parents:
diff changeset
1014 -- that [Deep_]Finalize may be inherited from a parent type.
kono
parents:
diff changeset
1015
kono
parents:
diff changeset
1016 else
kono
parents:
diff changeset
1017 Set_Etype (Obj_Ref, Desig_Typ);
kono
parents:
diff changeset
1018 end if;
kono
parents:
diff changeset
1019
kono
parents:
diff changeset
1020 -- Generate:
kono
parents:
diff changeset
1021 -- [Deep_]Finalize (Obj_Ref);
kono
parents:
diff changeset
1022
kono
parents:
diff changeset
1023 Fin_Call := Make_Final_Call (Obj_Ref => Obj_Ref, Typ => Desig_Typ);
kono
parents:
diff changeset
1024
kono
parents:
diff changeset
1025 -- Generate:
kono
parents:
diff changeset
1026 -- Abrt : constant Boolean := ...;
kono
parents:
diff changeset
1027 -- Ex : Exception_Occurrence;
kono
parents:
diff changeset
1028 -- Raised : Boolean := False;
kono
parents:
diff changeset
1029
kono
parents:
diff changeset
1030 -- begin
kono
parents:
diff changeset
1031 -- <Fin_Call>
kono
parents:
diff changeset
1032
kono
parents:
diff changeset
1033 -- exception
kono
parents:
diff changeset
1034 -- when others =>
kono
parents:
diff changeset
1035 -- if not Raised then
kono
parents:
diff changeset
1036 -- Raised := True;
kono
parents:
diff changeset
1037 -- Save_Occurrence (Ex, Get_Current_Excep.all.all);
kono
parents:
diff changeset
1038 -- end;
kono
parents:
diff changeset
1039
kono
parents:
diff changeset
1040 if Exceptions_OK then
kono
parents:
diff changeset
1041 Build_Object_Declarations (Fin_Data, Stmts, Loc);
kono
parents:
diff changeset
1042
kono
parents:
diff changeset
1043 Fin_Blk :=
kono
parents:
diff changeset
1044 Make_Block_Statement (Loc,
kono
parents:
diff changeset
1045 Handled_Statement_Sequence =>
kono
parents:
diff changeset
1046 Make_Handled_Sequence_Of_Statements (Loc,
kono
parents:
diff changeset
1047 Statements => New_List (Fin_Call),
kono
parents:
diff changeset
1048 Exception_Handlers => New_List (
kono
parents:
diff changeset
1049 Build_Exception_Handler (Fin_Data))));
kono
parents:
diff changeset
1050
kono
parents:
diff changeset
1051 -- Otherwise exception propagation is not allowed
kono
parents:
diff changeset
1052
kono
parents:
diff changeset
1053 else
kono
parents:
diff changeset
1054 Fin_Blk := Fin_Call;
kono
parents:
diff changeset
1055 end if;
kono
parents:
diff changeset
1056
kono
parents:
diff changeset
1057 -- The finalization action must be protected by an abort defer and
kono
parents:
diff changeset
1058 -- undefer pair when aborts are allowed. Generate:
kono
parents:
diff changeset
1059
kono
parents:
diff changeset
1060 -- begin
kono
parents:
diff changeset
1061 -- Abort_Defer;
kono
parents:
diff changeset
1062 -- <Fin_Blk>
kono
parents:
diff changeset
1063 -- at end
kono
parents:
diff changeset
1064 -- Abort_Undefer_Direct;
kono
parents:
diff changeset
1065 -- end;
kono
parents:
diff changeset
1066
kono
parents:
diff changeset
1067 if Abort_Allowed then
kono
parents:
diff changeset
1068 AUD := RTE (RE_Abort_Undefer_Direct);
kono
parents:
diff changeset
1069
kono
parents:
diff changeset
1070 Abrt_HSS :=
kono
parents:
diff changeset
1071 Make_Handled_Sequence_Of_Statements (Loc,
kono
parents:
diff changeset
1072 Statements => New_List (
kono
parents:
diff changeset
1073 Build_Runtime_Call (Loc, RE_Abort_Defer),
kono
parents:
diff changeset
1074 Fin_Blk),
kono
parents:
diff changeset
1075 At_End_Proc => New_Occurrence_Of (AUD, Loc));
kono
parents:
diff changeset
1076
kono
parents:
diff changeset
1077 Abrt_Blk :=
kono
parents:
diff changeset
1078 Make_Block_Statement (Loc,
kono
parents:
diff changeset
1079 Handled_Statement_Sequence => Abrt_HSS);
kono
parents:
diff changeset
1080
kono
parents:
diff changeset
1081 Add_Block_Identifier (Abrt_Blk, Abrt_Blk_Id);
kono
parents:
diff changeset
1082 Expand_At_End_Handler (Abrt_HSS, Abrt_Blk_Id);
kono
parents:
diff changeset
1083
kono
parents:
diff changeset
1084 -- Present the Abort_Undefer_Direct function to the backend so
kono
parents:
diff changeset
1085 -- that it can inline the call to the function.
kono
parents:
diff changeset
1086
kono
parents:
diff changeset
1087 Add_Inlined_Body (AUD, N);
kono
parents:
diff changeset
1088
kono
parents:
diff changeset
1089 -- Otherwise aborts are not allowed
kono
parents:
diff changeset
1090
kono
parents:
diff changeset
1091 else
kono
parents:
diff changeset
1092 Abrt_Blk := Fin_Blk;
kono
parents:
diff changeset
1093 end if;
kono
parents:
diff changeset
1094
kono
parents:
diff changeset
1095 Append_To (Stmts, Abrt_Blk);
kono
parents:
diff changeset
1096 end if;
kono
parents:
diff changeset
1097
kono
parents:
diff changeset
1098 -- For a task type, call Free_Task before freeing the ATCB. We used to
kono
parents:
diff changeset
1099 -- detect the case of Abort followed by a Free here, because the Free
kono
parents:
diff changeset
1100 -- wouldn't actually free if it happens before the aborted task actually
kono
parents:
diff changeset
1101 -- terminates. The warning was removed, because Free now works properly
kono
parents:
diff changeset
1102 -- (the task will be freed once it terminates).
kono
parents:
diff changeset
1103
kono
parents:
diff changeset
1104 if Is_Task_Type (Desig_Typ) then
kono
parents:
diff changeset
1105 Append_To (Stmts,
kono
parents:
diff changeset
1106 Cleanup_Task (N, Duplicate_Subexpr_No_Checks (Arg)));
kono
parents:
diff changeset
1107
kono
parents:
diff changeset
1108 -- For composite types that contain tasks, recurse over the structure
kono
parents:
diff changeset
1109 -- to build the selectors for the task subcomponents.
kono
parents:
diff changeset
1110
kono
parents:
diff changeset
1111 elsif Has_Task (Desig_Typ) then
kono
parents:
diff changeset
1112 if Is_Array_Type (Desig_Typ) then
kono
parents:
diff changeset
1113 Append_List_To (Stmts, Cleanup_Array (N, Arg, Desig_Typ));
kono
parents:
diff changeset
1114
kono
parents:
diff changeset
1115 elsif Is_Record_Type (Desig_Typ) then
kono
parents:
diff changeset
1116 Append_List_To (Stmts, Cleanup_Record (N, Arg, Desig_Typ));
kono
parents:
diff changeset
1117 end if;
kono
parents:
diff changeset
1118 end if;
kono
parents:
diff changeset
1119
kono
parents:
diff changeset
1120 -- Same for simple protected types. Eventually call Finalize_Protection
kono
parents:
diff changeset
1121 -- before freeing the PO for each protected component.
kono
parents:
diff changeset
1122
kono
parents:
diff changeset
1123 if Is_Simple_Protected_Type (Desig_Typ) then
kono
parents:
diff changeset
1124 Append_To (Stmts,
kono
parents:
diff changeset
1125 Cleanup_Protected_Object (N, Duplicate_Subexpr_No_Checks (Arg)));
kono
parents:
diff changeset
1126
kono
parents:
diff changeset
1127 elsif Has_Simple_Protected_Object (Desig_Typ) then
kono
parents:
diff changeset
1128 if Is_Array_Type (Desig_Typ) then
kono
parents:
diff changeset
1129 Append_List_To (Stmts, Cleanup_Array (N, Arg, Desig_Typ));
kono
parents:
diff changeset
1130
kono
parents:
diff changeset
1131 elsif Is_Record_Type (Desig_Typ) then
kono
parents:
diff changeset
1132 Append_List_To (Stmts, Cleanup_Record (N, Arg, Desig_Typ));
kono
parents:
diff changeset
1133 end if;
kono
parents:
diff changeset
1134 end if;
kono
parents:
diff changeset
1135
kono
parents:
diff changeset
1136 -- Normal processing for non-controlled types. The argument to free is
kono
parents:
diff changeset
1137 -- a renaming rather than a constant to ensure that the original context
kono
parents:
diff changeset
1138 -- is always set to null after the deallocation takes place.
kono
parents:
diff changeset
1139
kono
parents:
diff changeset
1140 Free_Arg := Duplicate_Subexpr_No_Checks (Arg, Renaming_Req => True);
kono
parents:
diff changeset
1141 Free_Nod := Make_Free_Statement (Loc, Empty);
kono
parents:
diff changeset
1142 Append_To (Stmts, Free_Nod);
kono
parents:
diff changeset
1143 Set_Storage_Pool (Free_Nod, Pool);
kono
parents:
diff changeset
1144
kono
parents:
diff changeset
1145 -- Attach to tree before analysis of generated subtypes below
kono
parents:
diff changeset
1146
kono
parents:
diff changeset
1147 Set_Parent (Stmts, Parent (N));
kono
parents:
diff changeset
1148
kono
parents:
diff changeset
1149 -- Deal with storage pool
kono
parents:
diff changeset
1150
kono
parents:
diff changeset
1151 if Present (Pool) then
kono
parents:
diff changeset
1152
kono
parents:
diff changeset
1153 -- Freeing the secondary stack is meaningless
kono
parents:
diff changeset
1154
kono
parents:
diff changeset
1155 if Is_RTE (Pool, RE_SS_Pool) then
kono
parents:
diff changeset
1156 null;
kono
parents:
diff changeset
1157
kono
parents:
diff changeset
1158 -- If the pool object is of a simple storage pool type, then attempt
kono
parents:
diff changeset
1159 -- to locate the type's Deallocate procedure, if any, and set the
kono
parents:
diff changeset
1160 -- free operation's procedure to call. If the type doesn't have a
kono
parents:
diff changeset
1161 -- Deallocate (which is allowed), then the actual will simply be set
kono
parents:
diff changeset
1162 -- to null.
kono
parents:
diff changeset
1163
kono
parents:
diff changeset
1164 elsif Present
kono
parents:
diff changeset
1165 (Get_Rep_Pragma (Etype (Pool), Name_Simple_Storage_Pool_Type))
kono
parents:
diff changeset
1166 then
kono
parents:
diff changeset
1167 declare
kono
parents:
diff changeset
1168 Pool_Typ : constant Entity_Id := Base_Type (Etype (Pool));
kono
parents:
diff changeset
1169 Dealloc : Entity_Id;
kono
parents:
diff changeset
1170
kono
parents:
diff changeset
1171 begin
kono
parents:
diff changeset
1172 Dealloc := Get_Name_Entity_Id (Name_Deallocate);
kono
parents:
diff changeset
1173 while Present (Dealloc) loop
kono
parents:
diff changeset
1174 if Scope (Dealloc) = Scope (Pool_Typ)
kono
parents:
diff changeset
1175 and then Present (First_Formal (Dealloc))
kono
parents:
diff changeset
1176 and then Etype (First_Formal (Dealloc)) = Pool_Typ
kono
parents:
diff changeset
1177 then
kono
parents:
diff changeset
1178 Set_Procedure_To_Call (Free_Nod, Dealloc);
kono
parents:
diff changeset
1179 exit;
kono
parents:
diff changeset
1180 else
kono
parents:
diff changeset
1181 Dealloc := Homonym (Dealloc);
kono
parents:
diff changeset
1182 end if;
kono
parents:
diff changeset
1183 end loop;
kono
parents:
diff changeset
1184 end;
kono
parents:
diff changeset
1185
kono
parents:
diff changeset
1186 -- Case of a class-wide pool type: make a dispatching call to
kono
parents:
diff changeset
1187 -- Deallocate through the class-wide Deallocate_Any.
kono
parents:
diff changeset
1188
kono
parents:
diff changeset
1189 elsif Is_Class_Wide_Type (Etype (Pool)) then
kono
parents:
diff changeset
1190 Set_Procedure_To_Call (Free_Nod, RTE (RE_Deallocate_Any));
kono
parents:
diff changeset
1191
kono
parents:
diff changeset
1192 -- Case of a specific pool type: make a statically bound call
kono
parents:
diff changeset
1193
kono
parents:
diff changeset
1194 else
kono
parents:
diff changeset
1195 Set_Procedure_To_Call
kono
parents:
diff changeset
1196 (Free_Nod, Find_Prim_Op (Etype (Pool), Name_Deallocate));
kono
parents:
diff changeset
1197 end if;
kono
parents:
diff changeset
1198 end if;
kono
parents:
diff changeset
1199
kono
parents:
diff changeset
1200 if Present (Procedure_To_Call (Free_Nod)) then
kono
parents:
diff changeset
1201
kono
parents:
diff changeset
1202 -- For all cases of a Deallocate call, the back-end needs to be able
kono
parents:
diff changeset
1203 -- to compute the size of the object being freed. This may require
kono
parents:
diff changeset
1204 -- some adjustments for objects of dynamic size.
kono
parents:
diff changeset
1205 --
kono
parents:
diff changeset
1206 -- If the type is class wide, we generate an implicit type with the
kono
parents:
diff changeset
1207 -- right dynamic size, so that the deallocate call gets the right
kono
parents:
diff changeset
1208 -- size parameter computed by GIGI. Same for an access to
kono
parents:
diff changeset
1209 -- unconstrained packed array.
kono
parents:
diff changeset
1210
kono
parents:
diff changeset
1211 if Is_Class_Wide_Type (Desig_Typ)
kono
parents:
diff changeset
1212 or else
kono
parents:
diff changeset
1213 (Is_Array_Type (Desig_Typ)
kono
parents:
diff changeset
1214 and then not Is_Constrained (Desig_Typ)
kono
parents:
diff changeset
1215 and then Is_Packed (Desig_Typ))
kono
parents:
diff changeset
1216 then
kono
parents:
diff changeset
1217 declare
kono
parents:
diff changeset
1218 Deref : constant Node_Id :=
kono
parents:
diff changeset
1219 Make_Explicit_Dereference (Loc,
kono
parents:
diff changeset
1220 Duplicate_Subexpr_No_Checks (Arg));
kono
parents:
diff changeset
1221 D_Subtyp : Node_Id;
kono
parents:
diff changeset
1222 D_Type : Entity_Id;
kono
parents:
diff changeset
1223
kono
parents:
diff changeset
1224 begin
kono
parents:
diff changeset
1225 -- Perform minor decoration as it is needed by the side effect
kono
parents:
diff changeset
1226 -- removal mechanism.
kono
parents:
diff changeset
1227
kono
parents:
diff changeset
1228 Set_Etype (Deref, Desig_Typ);
kono
parents:
diff changeset
1229 Set_Parent (Deref, Free_Nod);
kono
parents:
diff changeset
1230 D_Subtyp := Make_Subtype_From_Expr (Deref, Desig_Typ);
kono
parents:
diff changeset
1231
kono
parents:
diff changeset
1232 if Nkind (D_Subtyp) in N_Has_Entity then
kono
parents:
diff changeset
1233 D_Type := Entity (D_Subtyp);
kono
parents:
diff changeset
1234
kono
parents:
diff changeset
1235 else
kono
parents:
diff changeset
1236 D_Type := Make_Temporary (Loc, 'A');
kono
parents:
diff changeset
1237 Insert_Action (Deref,
kono
parents:
diff changeset
1238 Make_Subtype_Declaration (Loc,
kono
parents:
diff changeset
1239 Defining_Identifier => D_Type,
kono
parents:
diff changeset
1240 Subtype_Indication => D_Subtyp));
kono
parents:
diff changeset
1241 end if;
kono
parents:
diff changeset
1242
kono
parents:
diff changeset
1243 -- Force freezing at the point of the dereference. For the
kono
parents:
diff changeset
1244 -- class wide case, this avoids having the subtype frozen
kono
parents:
diff changeset
1245 -- before the equivalent type.
kono
parents:
diff changeset
1246
kono
parents:
diff changeset
1247 Freeze_Itype (D_Type, Deref);
kono
parents:
diff changeset
1248
kono
parents:
diff changeset
1249 Set_Actual_Designated_Subtype (Free_Nod, D_Type);
kono
parents:
diff changeset
1250 end;
kono
parents:
diff changeset
1251 end if;
kono
parents:
diff changeset
1252 end if;
kono
parents:
diff changeset
1253
kono
parents:
diff changeset
1254 -- Ada 2005 (AI-251): In case of abstract interface type we must
kono
parents:
diff changeset
1255 -- displace the pointer to reference the base of the object to
kono
parents:
diff changeset
1256 -- deallocate its memory, unless we're targetting a VM, in which case
kono
parents:
diff changeset
1257 -- no special processing is required.
kono
parents:
diff changeset
1258
kono
parents:
diff changeset
1259 -- Generate:
kono
parents:
diff changeset
1260 -- free (Base_Address (Obj_Ptr))
kono
parents:
diff changeset
1261
kono
parents:
diff changeset
1262 if Is_Interface (Directly_Designated_Type (Typ))
kono
parents:
diff changeset
1263 and then Tagged_Type_Expansion
kono
parents:
diff changeset
1264 then
kono
parents:
diff changeset
1265 Set_Expression (Free_Nod,
kono
parents:
diff changeset
1266 Unchecked_Convert_To (Typ,
kono
parents:
diff changeset
1267 Make_Function_Call (Loc,
kono
parents:
diff changeset
1268 Name =>
kono
parents:
diff changeset
1269 New_Occurrence_Of (RTE (RE_Base_Address), Loc),
kono
parents:
diff changeset
1270 Parameter_Associations => New_List (
kono
parents:
diff changeset
1271 Unchecked_Convert_To (RTE (RE_Address), Free_Arg)))));
kono
parents:
diff changeset
1272
kono
parents:
diff changeset
1273 -- Generate:
kono
parents:
diff changeset
1274 -- free (Obj_Ptr)
kono
parents:
diff changeset
1275
kono
parents:
diff changeset
1276 else
kono
parents:
diff changeset
1277 Set_Expression (Free_Nod, Free_Arg);
kono
parents:
diff changeset
1278 end if;
kono
parents:
diff changeset
1279
kono
parents:
diff changeset
1280 -- Only remaining step is to set result to null, or generate a raise of
kono
parents:
diff changeset
1281 -- Constraint_Error if the target object is "not null".
kono
parents:
diff changeset
1282
kono
parents:
diff changeset
1283 if Can_Never_Be_Null (Etype (Arg)) then
kono
parents:
diff changeset
1284 Append_To (Stmts,
kono
parents:
diff changeset
1285 Make_Raise_Constraint_Error (Loc,
kono
parents:
diff changeset
1286 Reason => CE_Access_Check_Failed));
kono
parents:
diff changeset
1287
kono
parents:
diff changeset
1288 else
kono
parents:
diff changeset
1289 declare
kono
parents:
diff changeset
1290 Lhs : constant Node_Id := Duplicate_Subexpr_No_Checks (Arg);
kono
parents:
diff changeset
1291 begin
kono
parents:
diff changeset
1292 Set_Assignment_OK (Lhs);
kono
parents:
diff changeset
1293 Append_To (Stmts,
kono
parents:
diff changeset
1294 Make_Assignment_Statement (Loc,
kono
parents:
diff changeset
1295 Name => Lhs,
kono
parents:
diff changeset
1296 Expression => Make_Null (Loc)));
kono
parents:
diff changeset
1297 end;
kono
parents:
diff changeset
1298 end if;
kono
parents:
diff changeset
1299
kono
parents:
diff changeset
1300 -- Generate a test of whether any earlier finalization raised an
kono
parents:
diff changeset
1301 -- exception, and in that case raise Program_Error with the previous
kono
parents:
diff changeset
1302 -- exception occurrence.
kono
parents:
diff changeset
1303
kono
parents:
diff changeset
1304 -- Generate:
kono
parents:
diff changeset
1305 -- if Raised and then not Abrt then
kono
parents:
diff changeset
1306 -- raise Program_Error; -- for restricted RTS
kono
parents:
diff changeset
1307 -- <or>
kono
parents:
diff changeset
1308 -- Raise_From_Controlled_Operation (E); -- all other cases
kono
parents:
diff changeset
1309 -- end if;
kono
parents:
diff changeset
1310
kono
parents:
diff changeset
1311 if Needs_Fin and then Exceptions_OK then
kono
parents:
diff changeset
1312 Append_To (Stmts, Build_Raise_Statement (Fin_Data));
kono
parents:
diff changeset
1313 end if;
kono
parents:
diff changeset
1314
kono
parents:
diff changeset
1315 -- If we know the argument is non-null, then make a block statement
kono
parents:
diff changeset
1316 -- that contains the required statements, no need for a test.
kono
parents:
diff changeset
1317
kono
parents:
diff changeset
1318 if Arg_Known_Non_Null then
kono
parents:
diff changeset
1319 Gen_Code :=
kono
parents:
diff changeset
1320 Make_Block_Statement (Loc,
kono
parents:
diff changeset
1321 Handled_Statement_Sequence =>
kono
parents:
diff changeset
1322 Make_Handled_Sequence_Of_Statements (Loc,
kono
parents:
diff changeset
1323 Statements => Stmts));
kono
parents:
diff changeset
1324
kono
parents:
diff changeset
1325 -- If the argument may be null, wrap the statements inside an IF that
kono
parents:
diff changeset
1326 -- does an explicit test to exclude the null case.
kono
parents:
diff changeset
1327
kono
parents:
diff changeset
1328 else
kono
parents:
diff changeset
1329 Gen_Code :=
kono
parents:
diff changeset
1330 Make_Implicit_If_Statement (N,
kono
parents:
diff changeset
1331 Condition =>
kono
parents:
diff changeset
1332 Make_Op_Ne (Loc,
kono
parents:
diff changeset
1333 Left_Opnd => Duplicate_Subexpr (Arg),
kono
parents:
diff changeset
1334 Right_Opnd => Make_Null (Loc)),
kono
parents:
diff changeset
1335 Then_Statements => Stmts);
kono
parents:
diff changeset
1336 end if;
kono
parents:
diff changeset
1337
kono
parents:
diff changeset
1338 -- Rewrite the call
kono
parents:
diff changeset
1339
kono
parents:
diff changeset
1340 Rewrite (N, Gen_Code);
kono
parents:
diff changeset
1341 Analyze (N);
kono
parents:
diff changeset
1342 end Expand_Unc_Deallocation;
kono
parents:
diff changeset
1343
kono
parents:
diff changeset
1344 -----------------------
kono
parents:
diff changeset
1345 -- Expand_To_Address --
kono
parents:
diff changeset
1346 -----------------------
kono
parents:
diff changeset
1347
kono
parents:
diff changeset
1348 procedure Expand_To_Address (N : Node_Id) is
kono
parents:
diff changeset
1349 Loc : constant Source_Ptr := Sloc (N);
kono
parents:
diff changeset
1350 Arg : constant Node_Id := First_Actual (N);
kono
parents:
diff changeset
1351 Obj : Node_Id;
kono
parents:
diff changeset
1352
kono
parents:
diff changeset
1353 begin
kono
parents:
diff changeset
1354 Remove_Side_Effects (Arg);
kono
parents:
diff changeset
1355
kono
parents:
diff changeset
1356 Obj := Make_Explicit_Dereference (Loc, Relocate_Node (Arg));
kono
parents:
diff changeset
1357
kono
parents:
diff changeset
1358 Rewrite (N,
kono
parents:
diff changeset
1359 Make_If_Expression (Loc,
kono
parents:
diff changeset
1360 Expressions => New_List (
kono
parents:
diff changeset
1361 Make_Op_Eq (Loc,
kono
parents:
diff changeset
1362 Left_Opnd => New_Copy_Tree (Arg),
kono
parents:
diff changeset
1363 Right_Opnd => Make_Null (Loc)),
kono
parents:
diff changeset
1364 New_Occurrence_Of (RTE (RE_Null_Address), Loc),
kono
parents:
diff changeset
1365 Make_Attribute_Reference (Loc,
kono
parents:
diff changeset
1366 Prefix => Obj,
kono
parents:
diff changeset
1367 Attribute_Name => Name_Address))));
kono
parents:
diff changeset
1368
kono
parents:
diff changeset
1369 Analyze_And_Resolve (N, RTE (RE_Address));
kono
parents:
diff changeset
1370 end Expand_To_Address;
kono
parents:
diff changeset
1371
kono
parents:
diff changeset
1372 -----------------------
kono
parents:
diff changeset
1373 -- Expand_To_Pointer --
kono
parents:
diff changeset
1374 -----------------------
kono
parents:
diff changeset
1375
kono
parents:
diff changeset
1376 procedure Expand_To_Pointer (N : Node_Id) is
kono
parents:
diff changeset
1377 Arg : constant Node_Id := First_Actual (N);
kono
parents:
diff changeset
1378
kono
parents:
diff changeset
1379 begin
kono
parents:
diff changeset
1380 Rewrite (N, Unchecked_Convert_To (Etype (N), Arg));
kono
parents:
diff changeset
1381 Analyze (N);
kono
parents:
diff changeset
1382 end Expand_To_Pointer;
kono
parents:
diff changeset
1383
kono
parents:
diff changeset
1384 end Exp_Intr;