annotate gcc/ada/exp_ch11.adb @ 158:494b0b89df80 default tip

...
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Mon, 25 May 2020 18:13:55 +0900
parents 1830386684a0
children
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 _ C H 1 1 --
kono
parents:
diff changeset
6 -- --
kono
parents:
diff changeset
7 -- B o d y --
kono
parents:
diff changeset
8 -- --
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
9 -- Copyright (C) 1992-2019, 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 Debug; use Debug;
kono
parents:
diff changeset
28 with Einfo; use Einfo;
kono
parents:
diff changeset
29 with Elists; use Elists;
kono
parents:
diff changeset
30 with Errout; use Errout;
kono
parents:
diff changeset
31 with Exp_Ch7; use Exp_Ch7;
kono
parents:
diff changeset
32 with Exp_Intr; use Exp_Intr;
kono
parents:
diff changeset
33 with Exp_Util; use Exp_Util;
kono
parents:
diff changeset
34 with Namet; use Namet;
kono
parents:
diff changeset
35 with Nlists; use Nlists;
kono
parents:
diff changeset
36 with Nmake; use Nmake;
kono
parents:
diff changeset
37 with Opt; use Opt;
kono
parents:
diff changeset
38 with Restrict; use Restrict;
kono
parents:
diff changeset
39 with Rident; use Rident;
kono
parents:
diff changeset
40 with Rtsfind; use Rtsfind;
kono
parents:
diff changeset
41 with Sem; use Sem;
kono
parents:
diff changeset
42 with Sem_Ch8; use Sem_Ch8;
kono
parents:
diff changeset
43 with Sem_Res; use Sem_Res;
kono
parents:
diff changeset
44 with Sem_Util; use Sem_Util;
kono
parents:
diff changeset
45 with Sinfo; use Sinfo;
kono
parents:
diff changeset
46 with Sinput; use Sinput;
kono
parents:
diff changeset
47 with Snames; use Snames;
kono
parents:
diff changeset
48 with Stand; use Stand;
kono
parents:
diff changeset
49 with Stringt; use Stringt;
kono
parents:
diff changeset
50 with Targparm; use Targparm;
kono
parents:
diff changeset
51 with Tbuild; use Tbuild;
kono
parents:
diff changeset
52 with Uintp; use Uintp;
kono
parents:
diff changeset
53
kono
parents:
diff changeset
54 package body Exp_Ch11 is
kono
parents:
diff changeset
55
kono
parents:
diff changeset
56 -----------------------
kono
parents:
diff changeset
57 -- Local Subprograms --
kono
parents:
diff changeset
58 -----------------------
kono
parents:
diff changeset
59
kono
parents:
diff changeset
60 procedure Warn_No_Exception_Propagation_Active (N : Node_Id);
kono
parents:
diff changeset
61 -- Generates warning that pragma Restrictions (No_Exception_Propagation)
kono
parents:
diff changeset
62 -- is in effect. Caller then generates appropriate continuation message.
kono
parents:
diff changeset
63 -- N is the node on which the warning is placed.
kono
parents:
diff changeset
64
kono
parents:
diff changeset
65 procedure Warn_If_No_Propagation (N : Node_Id);
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
66 -- Called for an exception raise that is not a local raise (and thus cannot
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
67 -- be optimized to a goto). Issues warning if No_Exception_Propagation
111
kono
parents:
diff changeset
68 -- restriction is set. N is the node for the raise or equivalent call.
kono
parents:
diff changeset
69
kono
parents:
diff changeset
70 ---------------------------
kono
parents:
diff changeset
71 -- Expand_At_End_Handler --
kono
parents:
diff changeset
72 ---------------------------
kono
parents:
diff changeset
73
kono
parents:
diff changeset
74 -- For a handled statement sequence that has a cleanup (At_End_Proc
kono
parents:
diff changeset
75 -- field set), an exception handler of the following form is required:
kono
parents:
diff changeset
76
kono
parents:
diff changeset
77 -- exception
kono
parents:
diff changeset
78 -- when all others =>
kono
parents:
diff changeset
79 -- cleanup call
kono
parents:
diff changeset
80 -- raise;
kono
parents:
diff changeset
81
kono
parents:
diff changeset
82 -- Note: this exception handler is treated rather specially by
kono
parents:
diff changeset
83 -- subsequent expansion in two respects:
kono
parents:
diff changeset
84
kono
parents:
diff changeset
85 -- The normal call to Undefer_Abort is omitted
kono
parents:
diff changeset
86 -- The raise call does not do Defer_Abort
kono
parents:
diff changeset
87
kono
parents:
diff changeset
88 -- This is because the current tasking code seems to assume that
kono
parents:
diff changeset
89 -- the call to the cleanup routine that is made from an exception
kono
parents:
diff changeset
90 -- handler for the abort signal is called with aborts deferred.
kono
parents:
diff changeset
91
kono
parents:
diff changeset
92 -- This expansion is only done if we have front end exception handling.
kono
parents:
diff changeset
93 -- If we have back end exception handling, then the AT END handler is
kono
parents:
diff changeset
94 -- left alone, and cleanups (including the exceptional case) are handled
kono
parents:
diff changeset
95 -- by the back end.
kono
parents:
diff changeset
96
kono
parents:
diff changeset
97 -- In the front end case, the exception handler described above handles
kono
parents:
diff changeset
98 -- the exceptional case. The AT END handler is left in the generated tree
kono
parents:
diff changeset
99 -- and the code generator (e.g. gigi) must still handle proper generation
kono
parents:
diff changeset
100 -- of cleanup calls for the non-exceptional case.
kono
parents:
diff changeset
101
kono
parents:
diff changeset
102 procedure Expand_At_End_Handler (HSS : Node_Id; Blk_Id : Entity_Id) is
kono
parents:
diff changeset
103 Clean : constant Entity_Id := Entity (At_End_Proc (HSS));
kono
parents:
diff changeset
104 Ohandle : Node_Id;
kono
parents:
diff changeset
105 Stmnts : List_Id;
kono
parents:
diff changeset
106
kono
parents:
diff changeset
107 Loc : constant Source_Ptr := No_Location;
kono
parents:
diff changeset
108 -- Location used for expansion. We quite deliberately do not set a
kono
parents:
diff changeset
109 -- specific source location for the expanded handler. This makes
kono
parents:
diff changeset
110 -- sense since really the handler is not associated with specific
kono
parents:
diff changeset
111 -- source. We used to set this to Sloc (Clean), but that caused
kono
parents:
diff changeset
112 -- useless and annoying bouncing around of line numbers in the
kono
parents:
diff changeset
113 -- debugger in some circumstances.
kono
parents:
diff changeset
114
kono
parents:
diff changeset
115 begin
kono
parents:
diff changeset
116 pragma Assert (Present (Clean));
kono
parents:
diff changeset
117 pragma Assert (No (Exception_Handlers (HSS)));
kono
parents:
diff changeset
118
kono
parents:
diff changeset
119 -- Back end exception schemes don't need explicit handlers to
kono
parents:
diff changeset
120 -- trigger AT-END actions on exceptional paths.
kono
parents:
diff changeset
121
kono
parents:
diff changeset
122 if Back_End_Exceptions then
kono
parents:
diff changeset
123 return;
kono
parents:
diff changeset
124 end if;
kono
parents:
diff changeset
125
kono
parents:
diff changeset
126 -- Don't expand an At End handler if we have already had configurable
kono
parents:
diff changeset
127 -- run-time violations, since likely this will just be a matter of
kono
parents:
diff changeset
128 -- generating useless cascaded messages
kono
parents:
diff changeset
129
kono
parents:
diff changeset
130 if Configurable_Run_Time_Violations > 0 then
kono
parents:
diff changeset
131 return;
kono
parents:
diff changeset
132 end if;
kono
parents:
diff changeset
133
kono
parents:
diff changeset
134 -- Don't expand an At End handler if we are not allowing exceptions
kono
parents:
diff changeset
135 -- or if exceptions are transformed into local gotos, and never
kono
parents:
diff changeset
136 -- propagated (No_Exception_Propagation).
kono
parents:
diff changeset
137
kono
parents:
diff changeset
138 if No_Exception_Handlers_Set then
kono
parents:
diff changeset
139 return;
kono
parents:
diff changeset
140 end if;
kono
parents:
diff changeset
141
kono
parents:
diff changeset
142 if Present (Blk_Id) then
kono
parents:
diff changeset
143 Push_Scope (Blk_Id);
kono
parents:
diff changeset
144 end if;
kono
parents:
diff changeset
145
kono
parents:
diff changeset
146 Ohandle :=
kono
parents:
diff changeset
147 Make_Others_Choice (Loc);
kono
parents:
diff changeset
148 Set_All_Others (Ohandle);
kono
parents:
diff changeset
149
kono
parents:
diff changeset
150 Stmnts := New_List (
kono
parents:
diff changeset
151 Make_Procedure_Call_Statement (Loc,
kono
parents:
diff changeset
152 Name => New_Occurrence_Of (Clean, Loc)));
kono
parents:
diff changeset
153
kono
parents:
diff changeset
154 -- Generate reraise statement as last statement of AT-END handler,
kono
parents:
diff changeset
155 -- unless we are under control of No_Exception_Propagation, in which
kono
parents:
diff changeset
156 -- case no exception propagation is possible anyway, so we do not need
kono
parents:
diff changeset
157 -- a reraise (the AT END handler in this case is only for normal exits
kono
parents:
diff changeset
158 -- not for exceptional exits). Also, we flag the Reraise statement as
kono
parents:
diff changeset
159 -- being part of an AT END handler to prevent signalling this reraise
kono
parents:
diff changeset
160 -- as a violation of the restriction when it is not set.
kono
parents:
diff changeset
161
kono
parents:
diff changeset
162 if not Restriction_Active (No_Exception_Propagation) then
kono
parents:
diff changeset
163 declare
kono
parents:
diff changeset
164 Rstm : constant Node_Id := Make_Raise_Statement (Loc);
kono
parents:
diff changeset
165 begin
kono
parents:
diff changeset
166 Set_From_At_End (Rstm);
kono
parents:
diff changeset
167 Append_To (Stmnts, Rstm);
kono
parents:
diff changeset
168 end;
kono
parents:
diff changeset
169 end if;
kono
parents:
diff changeset
170
kono
parents:
diff changeset
171 Set_Exception_Handlers (HSS, New_List (
kono
parents:
diff changeset
172 Make_Implicit_Exception_Handler (Loc,
kono
parents:
diff changeset
173 Exception_Choices => New_List (Ohandle),
kono
parents:
diff changeset
174 Statements => Stmnts)));
kono
parents:
diff changeset
175
kono
parents:
diff changeset
176 Analyze_List (Stmnts, Suppress => All_Checks);
kono
parents:
diff changeset
177 Expand_Exception_Handlers (HSS);
kono
parents:
diff changeset
178
kono
parents:
diff changeset
179 if Present (Blk_Id) then
kono
parents:
diff changeset
180 Pop_Scope;
kono
parents:
diff changeset
181 end if;
kono
parents:
diff changeset
182 end Expand_At_End_Handler;
kono
parents:
diff changeset
183
kono
parents:
diff changeset
184 -------------------------------
kono
parents:
diff changeset
185 -- Expand_Exception_Handlers --
kono
parents:
diff changeset
186 -------------------------------
kono
parents:
diff changeset
187
kono
parents:
diff changeset
188 procedure Expand_Exception_Handlers (HSS : Node_Id) is
kono
parents:
diff changeset
189 Handlrs : constant List_Id := Exception_Handlers (HSS);
kono
parents:
diff changeset
190 Loc : constant Source_Ptr := Sloc (HSS);
kono
parents:
diff changeset
191 Handler : Node_Id;
kono
parents:
diff changeset
192 Others_Choice : Boolean;
kono
parents:
diff changeset
193 Obj_Decl : Node_Id;
kono
parents:
diff changeset
194 Next_Handler : Node_Id;
kono
parents:
diff changeset
195
kono
parents:
diff changeset
196 procedure Expand_Local_Exception_Handlers;
kono
parents:
diff changeset
197 -- This procedure handles the expansion of exception handlers for the
kono
parents:
diff changeset
198 -- optimization of local raise statements into goto statements.
kono
parents:
diff changeset
199
kono
parents:
diff changeset
200 procedure Prepend_Call_To_Handler
kono
parents:
diff changeset
201 (Proc : RE_Id;
kono
parents:
diff changeset
202 Args : List_Id := No_List);
kono
parents:
diff changeset
203 -- Routine to prepend a call to the procedure referenced by Proc at
kono
parents:
diff changeset
204 -- the start of the handler code for the current Handler.
kono
parents:
diff changeset
205
kono
parents:
diff changeset
206 procedure Replace_Raise_By_Goto (Raise_S : Node_Id; Goto_L1 : Node_Id);
kono
parents:
diff changeset
207 -- Raise_S is a raise statement (possibly expanded, and possibly of the
kono
parents:
diff changeset
208 -- form of a Raise_xxx_Error node with a condition. This procedure is
kono
parents:
diff changeset
209 -- called to replace the raise action with the (already analyzed) goto
kono
parents:
diff changeset
210 -- statement passed as Goto_L1. This procedure also takes care of the
kono
parents:
diff changeset
211 -- requirement of inserting a Local_Raise call where possible.
kono
parents:
diff changeset
212
kono
parents:
diff changeset
213 -------------------------------------
kono
parents:
diff changeset
214 -- Expand_Local_Exception_Handlers --
kono
parents:
diff changeset
215 -------------------------------------
kono
parents:
diff changeset
216
kono
parents:
diff changeset
217 -- There are two cases for this transformation. First the case of
kono
parents:
diff changeset
218 -- explicit raise statements. For this case, the transformation we do
kono
parents:
diff changeset
219 -- looks like this. Right now we have for example (where L1, L2 are
kono
parents:
diff changeset
220 -- exception labels)
kono
parents:
diff changeset
221
kono
parents:
diff changeset
222 -- begin
kono
parents:
diff changeset
223 -- ...
kono
parents:
diff changeset
224 -- raise_exception (excep1'identity); -- was raise excep1
kono
parents:
diff changeset
225 -- ...
kono
parents:
diff changeset
226 -- raise_exception (excep2'identity); -- was raise excep2
kono
parents:
diff changeset
227 -- ...
kono
parents:
diff changeset
228 -- exception
kono
parents:
diff changeset
229 -- when excep1 =>
kono
parents:
diff changeset
230 -- estmts1
kono
parents:
diff changeset
231 -- when excep2 =>
kono
parents:
diff changeset
232 -- estmts2
kono
parents:
diff changeset
233 -- end;
kono
parents:
diff changeset
234
kono
parents:
diff changeset
235 -- This gets transformed into:
kono
parents:
diff changeset
236
kono
parents:
diff changeset
237 -- begin
kono
parents:
diff changeset
238 -- L1 : label; -- marked Exception_Junk
kono
parents:
diff changeset
239 -- L2 : label; -- marked Exception_Junk
kono
parents:
diff changeset
240 -- L3 : label; -- marked Exception_Junk
kono
parents:
diff changeset
241
kono
parents:
diff changeset
242 -- begin -- marked Exception_Junk
kono
parents:
diff changeset
243 -- ...
kono
parents:
diff changeset
244 -- local_raise (excep1'address); -- was raise excep1
kono
parents:
diff changeset
245 -- goto L1;
kono
parents:
diff changeset
246 -- ...
kono
parents:
diff changeset
247 -- local_raise (excep2'address); -- was raise excep2
kono
parents:
diff changeset
248 -- goto L2;
kono
parents:
diff changeset
249 -- ...
kono
parents:
diff changeset
250 -- exception
kono
parents:
diff changeset
251 -- when excep1 =>
kono
parents:
diff changeset
252 -- goto L1;
kono
parents:
diff changeset
253 -- when excep2 =>
kono
parents:
diff changeset
254 -- goto L2;
kono
parents:
diff changeset
255 -- end;
kono
parents:
diff changeset
256
kono
parents:
diff changeset
257 -- goto L3; -- skip handler if no raise, marked Exception_Junk
kono
parents:
diff changeset
258
kono
parents:
diff changeset
259 -- <<L1>> -- local excep target label, marked Exception_Junk
kono
parents:
diff changeset
260 -- begin -- marked Exception_Junk
kono
parents:
diff changeset
261 -- estmts1
kono
parents:
diff changeset
262 -- end;
kono
parents:
diff changeset
263 -- goto L3; -- marked Exception_Junk
kono
parents:
diff changeset
264
kono
parents:
diff changeset
265 -- <<L2>> -- marked Exception_Junk
kono
parents:
diff changeset
266 -- begin -- marked Exception_Junk
kono
parents:
diff changeset
267 -- estmts2
kono
parents:
diff changeset
268 -- end;
kono
parents:
diff changeset
269 -- goto L3; -- marked Exception_Junk
kono
parents:
diff changeset
270 -- <<L3>> -- marked Exception_Junk
kono
parents:
diff changeset
271 -- end;
kono
parents:
diff changeset
272
kono
parents:
diff changeset
273 -- Note: the reason we wrap the original statement sequence in an
kono
parents:
diff changeset
274 -- inner block is that there may be raise statements within the
kono
parents:
diff changeset
275 -- sequence of statements in the handlers, and we must ensure that
kono
parents:
diff changeset
276 -- these are properly handled, and in particular, such raise statements
kono
parents:
diff changeset
277 -- must not reenter the same exception handlers.
kono
parents:
diff changeset
278
kono
parents:
diff changeset
279 -- If the restriction No_Exception_Propagation is in effect, then we
kono
parents:
diff changeset
280 -- can omit the exception handlers.
kono
parents:
diff changeset
281
kono
parents:
diff changeset
282 -- begin
kono
parents:
diff changeset
283 -- L1 : label; -- marked Exception_Junk
kono
parents:
diff changeset
284 -- L2 : label; -- marked Exception_Junk
kono
parents:
diff changeset
285 -- L3 : label; -- marked Exception_Junk
kono
parents:
diff changeset
286
kono
parents:
diff changeset
287 -- begin -- marked Exception_Junk
kono
parents:
diff changeset
288 -- ...
kono
parents:
diff changeset
289 -- local_raise (excep1'address); -- was raise excep1
kono
parents:
diff changeset
290 -- goto L1;
kono
parents:
diff changeset
291 -- ...
kono
parents:
diff changeset
292 -- local_raise (excep2'address); -- was raise excep2
kono
parents:
diff changeset
293 -- goto L2;
kono
parents:
diff changeset
294 -- ...
kono
parents:
diff changeset
295 -- end;
kono
parents:
diff changeset
296
kono
parents:
diff changeset
297 -- goto L3; -- skip handler if no raise, marked Exception_Junk
kono
parents:
diff changeset
298
kono
parents:
diff changeset
299 -- <<L1>> -- local excep target label, marked Exception_Junk
kono
parents:
diff changeset
300 -- begin -- marked Exception_Junk
kono
parents:
diff changeset
301 -- estmts1
kono
parents:
diff changeset
302 -- end;
kono
parents:
diff changeset
303 -- goto L3; -- marked Exception_Junk
kono
parents:
diff changeset
304
kono
parents:
diff changeset
305 -- <<L2>> -- marked Exception_Junk
kono
parents:
diff changeset
306 -- begin -- marked Exception_Junk
kono
parents:
diff changeset
307 -- estmts2
kono
parents:
diff changeset
308 -- end;
kono
parents:
diff changeset
309
kono
parents:
diff changeset
310 -- <<L3>> -- marked Exception_Junk
kono
parents:
diff changeset
311 -- end;
kono
parents:
diff changeset
312
kono
parents:
diff changeset
313 -- The second case is for exceptions generated by the back end in one
kono
parents:
diff changeset
314 -- of three situations:
kono
parents:
diff changeset
315
kono
parents:
diff changeset
316 -- 1. Front end generates N_Raise_xxx_Error node
kono
parents:
diff changeset
317 -- 2. Front end sets Do_xxx_Check flag in subexpression node
kono
parents:
diff changeset
318 -- 3. Back end detects a situation where an exception is appropriate
kono
parents:
diff changeset
319
kono
parents:
diff changeset
320 -- In all these cases, the current processing in gigi is to generate a
kono
parents:
diff changeset
321 -- call to the appropriate Rcheck_xx routine (where xx encodes both the
kono
parents:
diff changeset
322 -- exception message and the exception to be raised, Constraint_Error,
kono
parents:
diff changeset
323 -- Program_Error, or Storage_Error.
kono
parents:
diff changeset
324
kono
parents:
diff changeset
325 -- We could handle some subcases of 1 using the same front end expansion
kono
parents:
diff changeset
326 -- into gotos, but even for case 1, we can't handle all cases, since
kono
parents:
diff changeset
327 -- generating gotos in the middle of expressions is not possible (it's
kono
parents:
diff changeset
328 -- possible at the gigi/gcc level, but not at the level of the GNAT
kono
parents:
diff changeset
329 -- tree).
kono
parents:
diff changeset
330
kono
parents:
diff changeset
331 -- In any case, it seems easier to have a scheme which handles all three
kono
parents:
diff changeset
332 -- cases in a uniform manner. So here is how we proceed in this case.
kono
parents:
diff changeset
333
kono
parents:
diff changeset
334 -- This procedure detects all handlers for these three exceptions,
kono
parents:
diff changeset
335 -- Constraint_Error, Program_Error and Storage_Error (including WHEN
kono
parents:
diff changeset
336 -- OTHERS handlers that cover one or more of these cases).
kono
parents:
diff changeset
337
kono
parents:
diff changeset
338 -- If the handler meets the requirements for being the target of a local
kono
parents:
diff changeset
339 -- raise, then the front end does the expansion described previously,
kono
parents:
diff changeset
340 -- creating a label to be used as a goto target to raise the exception.
kono
parents:
diff changeset
341 -- However, no attempt is made in the front end to convert any related
kono
parents:
diff changeset
342 -- raise statements into gotos, e.g. all N_Raise_xxx_Error nodes are
kono
parents:
diff changeset
343 -- left unchanged and passed to the back end.
kono
parents:
diff changeset
344
kono
parents:
diff changeset
345 -- Instead, the front end generates three nodes
kono
parents:
diff changeset
346
kono
parents:
diff changeset
347 -- N_Push_Constraint_Error_Label
kono
parents:
diff changeset
348 -- N_Push_Program_Error_Label
kono
parents:
diff changeset
349 -- N_Push_Storage_Error_Label
kono
parents:
diff changeset
350
kono
parents:
diff changeset
351 -- The Push node is generated at the start of the statements
kono
parents:
diff changeset
352 -- covered by the handler, and has as a parameter the label to be
kono
parents:
diff changeset
353 -- used as the raise target.
kono
parents:
diff changeset
354
kono
parents:
diff changeset
355 -- N_Pop_Constraint_Error_Label
kono
parents:
diff changeset
356 -- N_Pop_Program_Error_Label
kono
parents:
diff changeset
357 -- N_Pop_Storage_Error_Label
kono
parents:
diff changeset
358
kono
parents:
diff changeset
359 -- The Pop node is generated at the end of the covered statements
kono
parents:
diff changeset
360 -- and undoes the effect of the preceding corresponding Push node.
kono
parents:
diff changeset
361
kono
parents:
diff changeset
362 -- In the case where the handler does NOT meet the requirements, the
kono
parents:
diff changeset
363 -- front end will still generate the Push and Pop nodes, but the label
kono
parents:
diff changeset
364 -- field in the Push node will be empty signifying that for this region
kono
parents:
diff changeset
365 -- of code, no optimization is possible.
kono
parents:
diff changeset
366
kono
parents:
diff changeset
367 -- These Push/Pop nodes are inhibited if No_Exception_Handlers is set
kono
parents:
diff changeset
368 -- since they are useless in this case, and in CodePeer mode, where
kono
parents:
diff changeset
369 -- they serve no purpose and can intefere with the analysis.
kono
parents:
diff changeset
370
kono
parents:
diff changeset
371 -- The back end must maintain three stacks, one for each exception case,
kono
parents:
diff changeset
372 -- the Push node pushes an entry onto the corresponding stack, and Pop
kono
parents:
diff changeset
373 -- node pops off the entry. Then instead of calling Rcheck_nn, if the
kono
parents:
diff changeset
374 -- corresponding top stack entry has an non-empty label, a goto is
kono
parents:
diff changeset
375 -- generated. This goto should be preceded by a call to Local_Raise as
kono
parents:
diff changeset
376 -- described above.
kono
parents:
diff changeset
377
kono
parents:
diff changeset
378 -- An example of this transformation is as follows, given:
kono
parents:
diff changeset
379
kono
parents:
diff changeset
380 -- declare
kono
parents:
diff changeset
381 -- A : Integer range 1 .. 10;
kono
parents:
diff changeset
382 -- begin
kono
parents:
diff changeset
383 -- A := B + C;
kono
parents:
diff changeset
384 -- exception
kono
parents:
diff changeset
385 -- when Constraint_Error =>
kono
parents:
diff changeset
386 -- estmts
kono
parents:
diff changeset
387 -- end;
kono
parents:
diff changeset
388
kono
parents:
diff changeset
389 -- gets transformed to:
kono
parents:
diff changeset
390
kono
parents:
diff changeset
391 -- declare
kono
parents:
diff changeset
392 -- A : Integer range 1 .. 10;
kono
parents:
diff changeset
393
kono
parents:
diff changeset
394 -- begin
kono
parents:
diff changeset
395 -- L1 : label;
kono
parents:
diff changeset
396 -- L2 : label;
kono
parents:
diff changeset
397
kono
parents:
diff changeset
398 -- begin
kono
parents:
diff changeset
399 -- %push_constraint_error_label (L1)
kono
parents:
diff changeset
400 -- R1b : constant long_long_integer := long_long_integer?(b) +
kono
parents:
diff changeset
401 -- long_long_integer?(c);
kono
parents:
diff changeset
402 -- [constraint_error when
kono
parents:
diff changeset
403 -- not (R1b in -16#8000_0000# .. 16#7FFF_FFFF#)
kono
parents:
diff changeset
404 -- "overflow check failed"]
kono
parents:
diff changeset
405 -- a := integer?(R1b);
kono
parents:
diff changeset
406 -- %pop_constraint_error_Label
kono
parents:
diff changeset
407
kono
parents:
diff changeset
408 -- exception
kono
parents:
diff changeset
409 -- ...
kono
parents:
diff changeset
410 -- when constraint_error =>
kono
parents:
diff changeset
411 -- goto L1;
kono
parents:
diff changeset
412 -- end;
kono
parents:
diff changeset
413
kono
parents:
diff changeset
414 -- goto L2; -- skip handler when exception not raised
kono
parents:
diff changeset
415 -- <<L1>> -- target label for local exception
kono
parents:
diff changeset
416 -- estmts
kono
parents:
diff changeset
417 -- <<L2>>
kono
parents:
diff changeset
418 -- end;
kono
parents:
diff changeset
419
kono
parents:
diff changeset
420 -- Note: the generated labels and goto statements all have the flag
kono
parents:
diff changeset
421 -- Exception_Junk set True, so that Sem_Ch6.Check_Returns will ignore
kono
parents:
diff changeset
422 -- this generated exception stuff when checking for missing return
kono
parents:
diff changeset
423 -- statements (see circuitry in Check_Statement_Sequence).
kono
parents:
diff changeset
424
kono
parents:
diff changeset
425 -- Note: All of the processing described above occurs only if
kono
parents:
diff changeset
426 -- restriction No_Exception_Propagation applies or debug flag .g is
kono
parents:
diff changeset
427 -- enabled.
kono
parents:
diff changeset
428
kono
parents:
diff changeset
429 CE_Locally_Handled : Boolean := False;
kono
parents:
diff changeset
430 SE_Locally_Handled : Boolean := False;
kono
parents:
diff changeset
431 PE_Locally_Handled : Boolean := False;
kono
parents:
diff changeset
432 -- These three flags indicate whether a handler for the corresponding
kono
parents:
diff changeset
433 -- exception (CE=Constraint_Error, SE=Storage_Error, PE=Program_Error)
kono
parents:
diff changeset
434 -- is present. If so the switch is set to True, the Exception_Label
kono
parents:
diff changeset
435 -- field of the corresponding handler is set, and appropriate Push
kono
parents:
diff changeset
436 -- and Pop nodes are inserted into the code.
kono
parents:
diff changeset
437
kono
parents:
diff changeset
438 Local_Expansion_Required : Boolean := False;
kono
parents:
diff changeset
439 -- Set True if we have at least one handler requiring local raise
kono
parents:
diff changeset
440 -- expansion as described above.
kono
parents:
diff changeset
441
kono
parents:
diff changeset
442 procedure Expand_Local_Exception_Handlers is
kono
parents:
diff changeset
443 procedure Add_Exception_Label (H : Node_Id);
kono
parents:
diff changeset
444 -- H is an exception handler. First check for an Exception_Label
kono
parents:
diff changeset
445 -- already allocated for H. If none, allocate one, set the field in
kono
parents:
diff changeset
446 -- the handler node, add the label declaration, and set the flag
kono
parents:
diff changeset
447 -- Local_Expansion_Required. Note: if Local_Raise_Not_OK is set
kono
parents:
diff changeset
448 -- the call has no effect and Exception_Label is left empty.
kono
parents:
diff changeset
449
kono
parents:
diff changeset
450 procedure Add_Label_Declaration (L : Entity_Id);
kono
parents:
diff changeset
451 -- Add an implicit declaration of the given label to the declaration
kono
parents:
diff changeset
452 -- list in the parent of the current sequence of handled statements.
kono
parents:
diff changeset
453
kono
parents:
diff changeset
454 generic
kono
parents:
diff changeset
455 Exc_Locally_Handled : in out Boolean;
kono
parents:
diff changeset
456 -- Flag indicating whether a local handler for this exception
kono
parents:
diff changeset
457 -- has already been generated.
kono
parents:
diff changeset
458
kono
parents:
diff changeset
459 with function Make_Push_Label (Loc : Source_Ptr) return Node_Id;
kono
parents:
diff changeset
460 -- Function to create a Push_xxx_Label node
kono
parents:
diff changeset
461
kono
parents:
diff changeset
462 with function Make_Pop_Label (Loc : Source_Ptr) return Node_Id;
kono
parents:
diff changeset
463 -- Function to create a Pop_xxx_Label node
kono
parents:
diff changeset
464
kono
parents:
diff changeset
465 procedure Generate_Push_Pop (H : Node_Id);
kono
parents:
diff changeset
466 -- Common code for Generate_Push_Pop_xxx below, used to generate an
kono
parents:
diff changeset
467 -- exception label and Push/Pop nodes for Constraint_Error,
kono
parents:
diff changeset
468 -- Program_Error, or Storage_Error.
kono
parents:
diff changeset
469
kono
parents:
diff changeset
470 -------------------------
kono
parents:
diff changeset
471 -- Add_Exception_Label --
kono
parents:
diff changeset
472 -------------------------
kono
parents:
diff changeset
473
kono
parents:
diff changeset
474 procedure Add_Exception_Label (H : Node_Id) is
kono
parents:
diff changeset
475 begin
kono
parents:
diff changeset
476 if No (Exception_Label (H))
kono
parents:
diff changeset
477 and then not Local_Raise_Not_OK (H)
kono
parents:
diff changeset
478 and then not Special_Exception_Package_Used
kono
parents:
diff changeset
479 then
kono
parents:
diff changeset
480 Local_Expansion_Required := True;
kono
parents:
diff changeset
481
kono
parents:
diff changeset
482 declare
kono
parents:
diff changeset
483 L : constant Entity_Id := Make_Temporary (Sloc (H), 'L');
kono
parents:
diff changeset
484 begin
kono
parents:
diff changeset
485 Set_Exception_Label (H, L);
kono
parents:
diff changeset
486 Add_Label_Declaration (L);
kono
parents:
diff changeset
487 end;
kono
parents:
diff changeset
488 end if;
kono
parents:
diff changeset
489 end Add_Exception_Label;
kono
parents:
diff changeset
490
kono
parents:
diff changeset
491 ---------------------------
kono
parents:
diff changeset
492 -- Add_Label_Declaration --
kono
parents:
diff changeset
493 ---------------------------
kono
parents:
diff changeset
494
kono
parents:
diff changeset
495 procedure Add_Label_Declaration (L : Entity_Id) is
kono
parents:
diff changeset
496 P : constant Node_Id := Parent (HSS);
kono
parents:
diff changeset
497
kono
parents:
diff changeset
498 Decl_L : constant Node_Id :=
kono
parents:
diff changeset
499 Make_Implicit_Label_Declaration (Loc,
kono
parents:
diff changeset
500 Defining_Identifier => L);
kono
parents:
diff changeset
501
kono
parents:
diff changeset
502 begin
kono
parents:
diff changeset
503 if Declarations (P) = No_List then
kono
parents:
diff changeset
504 Set_Declarations (P, Empty_List);
kono
parents:
diff changeset
505 end if;
kono
parents:
diff changeset
506
kono
parents:
diff changeset
507 Append (Decl_L, Declarations (P));
kono
parents:
diff changeset
508 Analyze (Decl_L);
kono
parents:
diff changeset
509 end Add_Label_Declaration;
kono
parents:
diff changeset
510
kono
parents:
diff changeset
511 -----------------------
kono
parents:
diff changeset
512 -- Generate_Push_Pop --
kono
parents:
diff changeset
513 -----------------------
kono
parents:
diff changeset
514
kono
parents:
diff changeset
515 procedure Generate_Push_Pop (H : Node_Id) is
kono
parents:
diff changeset
516 begin
kono
parents:
diff changeset
517 if Restriction_Active (No_Exception_Handlers)
kono
parents:
diff changeset
518 or else CodePeer_Mode
kono
parents:
diff changeset
519 then
kono
parents:
diff changeset
520 return;
kono
parents:
diff changeset
521 end if;
kono
parents:
diff changeset
522
kono
parents:
diff changeset
523 if Exc_Locally_Handled then
kono
parents:
diff changeset
524 return;
kono
parents:
diff changeset
525 else
kono
parents:
diff changeset
526 Exc_Locally_Handled := True;
kono
parents:
diff changeset
527 end if;
kono
parents:
diff changeset
528
kono
parents:
diff changeset
529 Add_Exception_Label (H);
kono
parents:
diff changeset
530
kono
parents:
diff changeset
531 declare
kono
parents:
diff changeset
532 F : constant Node_Id := First (Statements (HSS));
kono
parents:
diff changeset
533 L : constant Node_Id := Last (Statements (HSS));
kono
parents:
diff changeset
534
kono
parents:
diff changeset
535 Push : constant Node_Id := Make_Push_Label (Sloc (F));
kono
parents:
diff changeset
536 Pop : constant Node_Id := Make_Pop_Label (Sloc (L));
kono
parents:
diff changeset
537
kono
parents:
diff changeset
538 begin
kono
parents:
diff changeset
539 -- We make sure that a call to Get_Local_Raise_Call_Entity is
kono
parents:
diff changeset
540 -- made during front end processing, so that when we need it
kono
parents:
diff changeset
541 -- in the back end, it will already be available and loaded.
kono
parents:
diff changeset
542
kono
parents:
diff changeset
543 Discard_Node (Get_Local_Raise_Call_Entity);
kono
parents:
diff changeset
544
kono
parents:
diff changeset
545 -- Prepare and insert Push and Pop nodes
kono
parents:
diff changeset
546
kono
parents:
diff changeset
547 Set_Exception_Label (Push, Exception_Label (H));
kono
parents:
diff changeset
548 Insert_Before (F, Push);
kono
parents:
diff changeset
549 Set_Analyzed (Push);
kono
parents:
diff changeset
550
kono
parents:
diff changeset
551 Insert_After (L, Pop);
kono
parents:
diff changeset
552 Set_Analyzed (Pop);
kono
parents:
diff changeset
553 end;
kono
parents:
diff changeset
554 end Generate_Push_Pop;
kono
parents:
diff changeset
555
kono
parents:
diff changeset
556 -- Local declarations
kono
parents:
diff changeset
557
kono
parents:
diff changeset
558 Loc : constant Source_Ptr := Sloc (HSS);
kono
parents:
diff changeset
559 Stmts : List_Id := No_List;
kono
parents:
diff changeset
560 Choice : Node_Id;
kono
parents:
diff changeset
561 Excep : Entity_Id;
kono
parents:
diff changeset
562
kono
parents:
diff changeset
563 procedure Generate_Push_Pop_For_Constraint_Error is
kono
parents:
diff changeset
564 new Generate_Push_Pop
kono
parents:
diff changeset
565 (Exc_Locally_Handled => CE_Locally_Handled,
kono
parents:
diff changeset
566 Make_Push_Label => Make_Push_Constraint_Error_Label,
kono
parents:
diff changeset
567 Make_Pop_Label => Make_Pop_Constraint_Error_Label);
kono
parents:
diff changeset
568 -- If no Push/Pop has been generated for CE yet, then set the flag
kono
parents:
diff changeset
569 -- CE_Locally_Handled, allocate an Exception_Label for handler H (if
kono
parents:
diff changeset
570 -- not already done), and generate Push/Pop nodes for the exception
kono
parents:
diff changeset
571 -- label at the start and end of the statements of HSS.
kono
parents:
diff changeset
572
kono
parents:
diff changeset
573 procedure Generate_Push_Pop_For_Program_Error is
kono
parents:
diff changeset
574 new Generate_Push_Pop
kono
parents:
diff changeset
575 (Exc_Locally_Handled => PE_Locally_Handled,
kono
parents:
diff changeset
576 Make_Push_Label => Make_Push_Program_Error_Label,
kono
parents:
diff changeset
577 Make_Pop_Label => Make_Pop_Program_Error_Label);
kono
parents:
diff changeset
578 -- If no Push/Pop has been generated for PE yet, then set the flag
kono
parents:
diff changeset
579 -- PE_Locally_Handled, allocate an Exception_Label for handler H (if
kono
parents:
diff changeset
580 -- not already done), and generate Push/Pop nodes for the exception
kono
parents:
diff changeset
581 -- label at the start and end of the statements of HSS.
kono
parents:
diff changeset
582
kono
parents:
diff changeset
583 procedure Generate_Push_Pop_For_Storage_Error is
kono
parents:
diff changeset
584 new Generate_Push_Pop
kono
parents:
diff changeset
585 (Exc_Locally_Handled => SE_Locally_Handled,
kono
parents:
diff changeset
586 Make_Push_Label => Make_Push_Storage_Error_Label,
kono
parents:
diff changeset
587 Make_Pop_Label => Make_Pop_Storage_Error_Label);
kono
parents:
diff changeset
588 -- If no Push/Pop has been generated for SE yet, then set the flag
kono
parents:
diff changeset
589 -- SE_Locally_Handled, allocate an Exception_Label for handler H (if
kono
parents:
diff changeset
590 -- not already done), and generate Push/Pop nodes for the exception
kono
parents:
diff changeset
591 -- label at the start and end of the statements of HSS.
kono
parents:
diff changeset
592
kono
parents:
diff changeset
593 -- Start of processing for Expand_Local_Exception_Handlers
kono
parents:
diff changeset
594
kono
parents:
diff changeset
595 begin
kono
parents:
diff changeset
596 -- No processing if all exception handlers will get removed
kono
parents:
diff changeset
597
kono
parents:
diff changeset
598 if Debug_Flag_Dot_X then
kono
parents:
diff changeset
599 return;
kono
parents:
diff changeset
600 end if;
kono
parents:
diff changeset
601
kono
parents:
diff changeset
602 -- See for each handler if we have any local raises to expand
kono
parents:
diff changeset
603
kono
parents:
diff changeset
604 Handler := First_Non_Pragma (Handlrs);
kono
parents:
diff changeset
605 while Present (Handler) loop
kono
parents:
diff changeset
606
kono
parents:
diff changeset
607 -- Note, we do not test Local_Raise_Not_OK here, because in the
kono
parents:
diff changeset
608 -- case of Push/Pop generation we want to generate push with a
kono
parents:
diff changeset
609 -- null label. The Add_Exception_Label routine has no effect if
kono
parents:
diff changeset
610 -- Local_Raise_Not_OK is set, so this works as required.
kono
parents:
diff changeset
611
kono
parents:
diff changeset
612 if Present (Local_Raise_Statements (Handler)) then
kono
parents:
diff changeset
613 Add_Exception_Label (Handler);
kono
parents:
diff changeset
614 end if;
kono
parents:
diff changeset
615
kono
parents:
diff changeset
616 -- If we are doing local raise to goto optimization (restriction
kono
parents:
diff changeset
617 -- No_Exception_Propagation set or debug flag .g set), then check
kono
parents:
diff changeset
618 -- to see if handler handles CE, PE, SE and if so generate the
kono
parents:
diff changeset
619 -- appropriate push/pop sequence for the back end.
kono
parents:
diff changeset
620
kono
parents:
diff changeset
621 if (Debug_Flag_Dot_G
kono
parents:
diff changeset
622 or else Restriction_Active (No_Exception_Propagation))
kono
parents:
diff changeset
623 and then Has_Local_Raise (Handler)
kono
parents:
diff changeset
624 then
kono
parents:
diff changeset
625 Choice := First (Exception_Choices (Handler));
kono
parents:
diff changeset
626 while Present (Choice) loop
kono
parents:
diff changeset
627 if Nkind (Choice) = N_Others_Choice
kono
parents:
diff changeset
628 and then not All_Others (Choice)
kono
parents:
diff changeset
629 then
kono
parents:
diff changeset
630 Generate_Push_Pop_For_Constraint_Error (Handler);
kono
parents:
diff changeset
631 Generate_Push_Pop_For_Program_Error (Handler);
kono
parents:
diff changeset
632 Generate_Push_Pop_For_Storage_Error (Handler);
kono
parents:
diff changeset
633
kono
parents:
diff changeset
634 elsif Is_Entity_Name (Choice) then
kono
parents:
diff changeset
635 Excep := Get_Renamed_Entity (Entity (Choice));
kono
parents:
diff changeset
636
kono
parents:
diff changeset
637 if Excep = Standard_Constraint_Error then
kono
parents:
diff changeset
638 Generate_Push_Pop_For_Constraint_Error (Handler);
kono
parents:
diff changeset
639 elsif Excep = Standard_Program_Error then
kono
parents:
diff changeset
640 Generate_Push_Pop_For_Program_Error (Handler);
kono
parents:
diff changeset
641 elsif Excep = Standard_Storage_Error then
kono
parents:
diff changeset
642 Generate_Push_Pop_For_Storage_Error (Handler);
kono
parents:
diff changeset
643 end if;
kono
parents:
diff changeset
644 end if;
kono
parents:
diff changeset
645
kono
parents:
diff changeset
646 Next (Choice);
kono
parents:
diff changeset
647 end loop;
kono
parents:
diff changeset
648 end if;
kono
parents:
diff changeset
649
kono
parents:
diff changeset
650 Next_Non_Pragma (Handler);
kono
parents:
diff changeset
651 end loop;
kono
parents:
diff changeset
652
kono
parents:
diff changeset
653 -- Nothing to do if no handlers requiring the goto transformation
kono
parents:
diff changeset
654
kono
parents:
diff changeset
655 if not (Local_Expansion_Required) then
kono
parents:
diff changeset
656 return;
kono
parents:
diff changeset
657 end if;
kono
parents:
diff changeset
658
kono
parents:
diff changeset
659 -- Prepare to do the transformation
kono
parents:
diff changeset
660
kono
parents:
diff changeset
661 declare
kono
parents:
diff changeset
662 -- L3 is the label to exit the HSS
kono
parents:
diff changeset
663
kono
parents:
diff changeset
664 L3_Dent : constant Entity_Id := Make_Temporary (Loc, 'L');
kono
parents:
diff changeset
665
kono
parents:
diff changeset
666 Labl_L3 : constant Node_Id :=
kono
parents:
diff changeset
667 Make_Label (Loc,
kono
parents:
diff changeset
668 Identifier => New_Occurrence_Of (L3_Dent, Loc));
kono
parents:
diff changeset
669
kono
parents:
diff changeset
670 Blk_Stm : Node_Id;
kono
parents:
diff changeset
671 Relmt : Elmt_Id;
kono
parents:
diff changeset
672
kono
parents:
diff changeset
673 begin
kono
parents:
diff changeset
674 Set_Exception_Junk (Labl_L3);
kono
parents:
diff changeset
675 Add_Label_Declaration (L3_Dent);
kono
parents:
diff changeset
676
kono
parents:
diff changeset
677 -- Wrap existing statements and handlers in an inner block
kono
parents:
diff changeset
678
kono
parents:
diff changeset
679 Blk_Stm :=
kono
parents:
diff changeset
680 Make_Block_Statement (Loc,
kono
parents:
diff changeset
681 Handled_Statement_Sequence => Relocate_Node (HSS));
kono
parents:
diff changeset
682 Set_Exception_Junk (Blk_Stm);
kono
parents:
diff changeset
683
kono
parents:
diff changeset
684 Rewrite (HSS,
kono
parents:
diff changeset
685 Make_Handled_Sequence_Of_Statements (Loc,
kono
parents:
diff changeset
686 Statements => New_List (Blk_Stm),
kono
parents:
diff changeset
687 End_Label => Relocate_Node (End_Label (HSS))));
kono
parents:
diff changeset
688
kono
parents:
diff changeset
689 -- Set block statement as analyzed, we don't want to actually call
kono
parents:
diff changeset
690 -- Analyze on this block, it would cause a recursion in exception
kono
parents:
diff changeset
691 -- handler processing which would mess things up.
kono
parents:
diff changeset
692
kono
parents:
diff changeset
693 Set_Analyzed (Blk_Stm);
kono
parents:
diff changeset
694
kono
parents:
diff changeset
695 -- Now loop through the exception handlers to deal with those that
kono
parents:
diff changeset
696 -- are targets of local raise statements.
kono
parents:
diff changeset
697
kono
parents:
diff changeset
698 Handler := First_Non_Pragma (Handlrs);
kono
parents:
diff changeset
699 while Present (Handler) loop
kono
parents:
diff changeset
700 if Present (Exception_Label (Handler)) then
kono
parents:
diff changeset
701
kono
parents:
diff changeset
702 -- This handler needs the goto expansion
kono
parents:
diff changeset
703
kono
parents:
diff changeset
704 declare
kono
parents:
diff changeset
705 Loc : constant Source_Ptr := Sloc (Handler);
kono
parents:
diff changeset
706
kono
parents:
diff changeset
707 -- L1 is the start label for this handler
kono
parents:
diff changeset
708
kono
parents:
diff changeset
709 L1_Dent : constant Entity_Id := Exception_Label (Handler);
kono
parents:
diff changeset
710
kono
parents:
diff changeset
711 Labl_L1 : constant Node_Id :=
kono
parents:
diff changeset
712 Make_Label (Loc,
kono
parents:
diff changeset
713 Identifier =>
kono
parents:
diff changeset
714 New_Occurrence_Of (L1_Dent, Loc));
kono
parents:
diff changeset
715
kono
parents:
diff changeset
716 -- Jump to L1 to be used as replacement for the original
kono
parents:
diff changeset
717 -- handler (used in the case where exception propagation
kono
parents:
diff changeset
718 -- may still occur).
kono
parents:
diff changeset
719
kono
parents:
diff changeset
720 Name_L1 : constant Node_Id :=
kono
parents:
diff changeset
721 New_Occurrence_Of (L1_Dent, Loc);
kono
parents:
diff changeset
722
kono
parents:
diff changeset
723 Goto_L1 : constant Node_Id :=
kono
parents:
diff changeset
724 Make_Goto_Statement (Loc,
kono
parents:
diff changeset
725 Name => Name_L1);
kono
parents:
diff changeset
726
kono
parents:
diff changeset
727 -- Jump to L3 to be used at the end of handler
kono
parents:
diff changeset
728
kono
parents:
diff changeset
729 Name_L3 : constant Node_Id :=
kono
parents:
diff changeset
730 New_Occurrence_Of (L3_Dent, Loc);
kono
parents:
diff changeset
731
kono
parents:
diff changeset
732 Goto_L3 : constant Node_Id :=
kono
parents:
diff changeset
733 Make_Goto_Statement (Loc,
kono
parents:
diff changeset
734 Name => Name_L3);
kono
parents:
diff changeset
735
kono
parents:
diff changeset
736 H_Stmts : constant List_Id := Statements (Handler);
kono
parents:
diff changeset
737
kono
parents:
diff changeset
738 begin
kono
parents:
diff changeset
739 Set_Exception_Junk (Labl_L1);
kono
parents:
diff changeset
740 Set_Exception_Junk (Goto_L3);
kono
parents:
diff changeset
741
kono
parents:
diff changeset
742 -- Note: we do NOT set Exception_Junk in Goto_L1, since
kono
parents:
diff changeset
743 -- this is a real transfer of control that we want the
kono
parents:
diff changeset
744 -- Sem_Ch6.Check_Returns procedure to recognize properly.
kono
parents:
diff changeset
745
kono
parents:
diff changeset
746 -- Replace handler by a goto L1. We can mark this as
kono
parents:
diff changeset
747 -- analyzed since it is fully formed, and we don't
kono
parents:
diff changeset
748 -- want it going through any further checks. We save
kono
parents:
diff changeset
749 -- the last statement location in the goto L1 node for
kono
parents:
diff changeset
750 -- the benefit of Sem_Ch6.Check_Returns.
kono
parents:
diff changeset
751
kono
parents:
diff changeset
752 Set_Statements (Handler, New_List (Goto_L1));
kono
parents:
diff changeset
753 Set_Analyzed (Goto_L1);
kono
parents:
diff changeset
754 Set_Etype (Name_L1, Standard_Void_Type);
kono
parents:
diff changeset
755
kono
parents:
diff changeset
756 -- Now replace all the raise statements by goto L1
kono
parents:
diff changeset
757
kono
parents:
diff changeset
758 if Present (Local_Raise_Statements (Handler)) then
kono
parents:
diff changeset
759 Relmt := First_Elmt (Local_Raise_Statements (Handler));
kono
parents:
diff changeset
760 while Present (Relmt) loop
kono
parents:
diff changeset
761 declare
kono
parents:
diff changeset
762 Raise_S : constant Node_Id := Node (Relmt);
kono
parents:
diff changeset
763 RLoc : constant Source_Ptr := Sloc (Raise_S);
kono
parents:
diff changeset
764 Name_L1 : constant Node_Id :=
kono
parents:
diff changeset
765 New_Occurrence_Of (L1_Dent, Loc);
kono
parents:
diff changeset
766 Goto_L1 : constant Node_Id :=
kono
parents:
diff changeset
767 Make_Goto_Statement (RLoc,
kono
parents:
diff changeset
768 Name => Name_L1);
kono
parents:
diff changeset
769
kono
parents:
diff changeset
770 begin
kono
parents:
diff changeset
771 -- Replace raise by goto L1
kono
parents:
diff changeset
772
kono
parents:
diff changeset
773 Set_Analyzed (Goto_L1);
kono
parents:
diff changeset
774 Set_Etype (Name_L1, Standard_Void_Type);
kono
parents:
diff changeset
775 Replace_Raise_By_Goto (Raise_S, Goto_L1);
kono
parents:
diff changeset
776 end;
kono
parents:
diff changeset
777
kono
parents:
diff changeset
778 Next_Elmt (Relmt);
kono
parents:
diff changeset
779 end loop;
kono
parents:
diff changeset
780 end if;
kono
parents:
diff changeset
781
kono
parents:
diff changeset
782 -- Add a goto L3 at end of statement list in block. The
kono
parents:
diff changeset
783 -- first time, this is what skips over the exception
kono
parents:
diff changeset
784 -- handlers in the normal case. Subsequent times, it
kono
parents:
diff changeset
785 -- terminates the execution of the previous handler code,
kono
parents:
diff changeset
786 -- and skips subsequent handlers.
kono
parents:
diff changeset
787
kono
parents:
diff changeset
788 Stmts := Statements (HSS);
kono
parents:
diff changeset
789
kono
parents:
diff changeset
790 Insert_After (Last (Stmts), Goto_L3);
kono
parents:
diff changeset
791 Set_Analyzed (Goto_L3);
kono
parents:
diff changeset
792 Set_Etype (Name_L3, Standard_Void_Type);
kono
parents:
diff changeset
793
kono
parents:
diff changeset
794 -- Now we drop the label that marks the handler start,
kono
parents:
diff changeset
795 -- followed by the statements of the handler.
kono
parents:
diff changeset
796
kono
parents:
diff changeset
797 Set_Etype (Identifier (Labl_L1), Standard_Void_Type);
kono
parents:
diff changeset
798
kono
parents:
diff changeset
799 Insert_After_And_Analyze (Last (Stmts), Labl_L1);
kono
parents:
diff changeset
800
kono
parents:
diff changeset
801 declare
kono
parents:
diff changeset
802 Loc : constant Source_Ptr := Sloc (First (H_Stmts));
kono
parents:
diff changeset
803 Blk : constant Node_Id :=
kono
parents:
diff changeset
804 Make_Block_Statement (Loc,
kono
parents:
diff changeset
805 Handled_Statement_Sequence =>
kono
parents:
diff changeset
806 Make_Handled_Sequence_Of_Statements (Loc,
kono
parents:
diff changeset
807 Statements => H_Stmts));
kono
parents:
diff changeset
808 begin
kono
parents:
diff changeset
809 Set_Exception_Junk (Blk);
kono
parents:
diff changeset
810 Insert_After_And_Analyze (Last (Stmts), Blk);
kono
parents:
diff changeset
811 end;
kono
parents:
diff changeset
812 end;
kono
parents:
diff changeset
813
kono
parents:
diff changeset
814 -- Here if we have local raise statements but the handler is
kono
parents:
diff changeset
815 -- not suitable for processing with a local raise. In this
kono
parents:
diff changeset
816 -- case we have to generate possible diagnostics.
kono
parents:
diff changeset
817
kono
parents:
diff changeset
818 elsif Has_Local_Raise (Handler)
kono
parents:
diff changeset
819 and then Local_Raise_Statements (Handler) /= No_Elist
kono
parents:
diff changeset
820 then
kono
parents:
diff changeset
821 Relmt := First_Elmt (Local_Raise_Statements (Handler));
kono
parents:
diff changeset
822 while Present (Relmt) loop
kono
parents:
diff changeset
823 Warn_If_No_Propagation (Node (Relmt));
kono
parents:
diff changeset
824 Next_Elmt (Relmt);
kono
parents:
diff changeset
825 end loop;
kono
parents:
diff changeset
826 end if;
kono
parents:
diff changeset
827
kono
parents:
diff changeset
828 Next (Handler);
kono
parents:
diff changeset
829 end loop;
kono
parents:
diff changeset
830
kono
parents:
diff changeset
831 -- Only remaining step is to drop the L3 label and we are done
kono
parents:
diff changeset
832
kono
parents:
diff changeset
833 Set_Etype (Identifier (Labl_L3), Standard_Void_Type);
kono
parents:
diff changeset
834
kono
parents:
diff changeset
835 -- If we had at least one handler, then we drop the label after
kono
parents:
diff changeset
836 -- the last statement of that handler.
kono
parents:
diff changeset
837
kono
parents:
diff changeset
838 if Stmts /= No_List then
kono
parents:
diff changeset
839 Insert_After_And_Analyze (Last (Stmts), Labl_L3);
kono
parents:
diff changeset
840
kono
parents:
diff changeset
841 -- Otherwise we have removed all the handlers (this results from
kono
parents:
diff changeset
842 -- use of pragma Restrictions (No_Exception_Propagation), and we
kono
parents:
diff changeset
843 -- drop the label at the end of the statements of the HSS.
kono
parents:
diff changeset
844
kono
parents:
diff changeset
845 else
kono
parents:
diff changeset
846 Insert_After_And_Analyze (Last (Statements (HSS)), Labl_L3);
kono
parents:
diff changeset
847 end if;
kono
parents:
diff changeset
848
kono
parents:
diff changeset
849 return;
kono
parents:
diff changeset
850 end;
kono
parents:
diff changeset
851 end Expand_Local_Exception_Handlers;
kono
parents:
diff changeset
852
kono
parents:
diff changeset
853 -----------------------------
kono
parents:
diff changeset
854 -- Prepend_Call_To_Handler --
kono
parents:
diff changeset
855 -----------------------------
kono
parents:
diff changeset
856
kono
parents:
diff changeset
857 procedure Prepend_Call_To_Handler
kono
parents:
diff changeset
858 (Proc : RE_Id;
kono
parents:
diff changeset
859 Args : List_Id := No_List)
kono
parents:
diff changeset
860 is
kono
parents:
diff changeset
861 Ent : constant Entity_Id := RTE (Proc);
kono
parents:
diff changeset
862
kono
parents:
diff changeset
863 begin
kono
parents:
diff changeset
864 -- If we have no Entity, then we are probably in no run time mode or
kono
parents:
diff changeset
865 -- some weird error has occurred. In either case do nothing. Note use
kono
parents:
diff changeset
866 -- of No_Location to hide this code from the debugger, so single
kono
parents:
diff changeset
867 -- stepping doesn't jump back and forth.
kono
parents:
diff changeset
868
kono
parents:
diff changeset
869 if Present (Ent) then
kono
parents:
diff changeset
870 declare
kono
parents:
diff changeset
871 Call : constant Node_Id :=
kono
parents:
diff changeset
872 Make_Procedure_Call_Statement (No_Location,
kono
parents:
diff changeset
873 Name => New_Occurrence_Of (RTE (Proc), No_Location),
kono
parents:
diff changeset
874 Parameter_Associations => Args);
kono
parents:
diff changeset
875
kono
parents:
diff changeset
876 begin
kono
parents:
diff changeset
877 Prepend_To (Statements (Handler), Call);
kono
parents:
diff changeset
878 Analyze (Call, Suppress => All_Checks);
kono
parents:
diff changeset
879 end;
kono
parents:
diff changeset
880 end if;
kono
parents:
diff changeset
881 end Prepend_Call_To_Handler;
kono
parents:
diff changeset
882
kono
parents:
diff changeset
883 ---------------------------
kono
parents:
diff changeset
884 -- Replace_Raise_By_Goto --
kono
parents:
diff changeset
885 ---------------------------
kono
parents:
diff changeset
886
kono
parents:
diff changeset
887 procedure Replace_Raise_By_Goto (Raise_S : Node_Id; Goto_L1 : Node_Id) is
kono
parents:
diff changeset
888 Loc : constant Source_Ptr := Sloc (Raise_S);
kono
parents:
diff changeset
889 Excep : Entity_Id;
kono
parents:
diff changeset
890 LR : Node_Id;
kono
parents:
diff changeset
891 Cond : Node_Id;
kono
parents:
diff changeset
892 Orig : Node_Id;
kono
parents:
diff changeset
893
kono
parents:
diff changeset
894 begin
kono
parents:
diff changeset
895 -- If we have a null statement, it means that there is no replacement
kono
parents:
diff changeset
896 -- needed (typically this results from a suppressed check).
kono
parents:
diff changeset
897
kono
parents:
diff changeset
898 if Nkind (Raise_S) = N_Null_Statement then
kono
parents:
diff changeset
899 return;
kono
parents:
diff changeset
900
kono
parents:
diff changeset
901 -- Test for Raise_xxx_Error
kono
parents:
diff changeset
902
kono
parents:
diff changeset
903 elsif Nkind (Raise_S) = N_Raise_Constraint_Error then
kono
parents:
diff changeset
904 Excep := Standard_Constraint_Error;
kono
parents:
diff changeset
905 Cond := Condition (Raise_S);
kono
parents:
diff changeset
906
kono
parents:
diff changeset
907 elsif Nkind (Raise_S) = N_Raise_Storage_Error then
kono
parents:
diff changeset
908 Excep := Standard_Storage_Error;
kono
parents:
diff changeset
909 Cond := Condition (Raise_S);
kono
parents:
diff changeset
910
kono
parents:
diff changeset
911 elsif Nkind (Raise_S) = N_Raise_Program_Error then
kono
parents:
diff changeset
912 Excep := Standard_Program_Error;
kono
parents:
diff changeset
913 Cond := Condition (Raise_S);
kono
parents:
diff changeset
914
kono
parents:
diff changeset
915 -- The only other possibility is a node that is or used to be a
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
916 -- simple raise statement. Note that the string expression in the
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
917 -- original Raise statement is ignored.
111
kono
parents:
diff changeset
918
kono
parents:
diff changeset
919 else
kono
parents:
diff changeset
920 Orig := Original_Node (Raise_S);
kono
parents:
diff changeset
921 pragma Assert (Nkind (Orig) = N_Raise_Statement
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
922 and then Present (Name (Orig)));
111
kono
parents:
diff changeset
923 Excep := Entity (Name (Orig));
kono
parents:
diff changeset
924 Cond := Empty;
kono
parents:
diff changeset
925 end if;
kono
parents:
diff changeset
926
kono
parents:
diff changeset
927 -- Here Excep is the exception to raise, and Cond is the condition
kono
parents:
diff changeset
928 -- First prepare the call to Local_Raise (excep'address).
kono
parents:
diff changeset
929
kono
parents:
diff changeset
930 if RTE_Available (RE_Local_Raise) then
kono
parents:
diff changeset
931 LR :=
kono
parents:
diff changeset
932 Make_Procedure_Call_Statement (Loc,
kono
parents:
diff changeset
933 Name => New_Occurrence_Of (RTE (RE_Local_Raise), Loc),
kono
parents:
diff changeset
934 Parameter_Associations => New_List (
kono
parents:
diff changeset
935 Unchecked_Convert_To (RTE (RE_Address),
kono
parents:
diff changeset
936 Make_Attribute_Reference (Loc,
kono
parents:
diff changeset
937 Prefix => New_Occurrence_Of (Excep, Loc),
kono
parents:
diff changeset
938 Attribute_Name => Name_Identity))));
kono
parents:
diff changeset
939
kono
parents:
diff changeset
940 -- Use null statement if Local_Raise not available
kono
parents:
diff changeset
941
kono
parents:
diff changeset
942 else
kono
parents:
diff changeset
943 LR :=
kono
parents:
diff changeset
944 Make_Null_Statement (Loc);
kono
parents:
diff changeset
945 end if;
kono
parents:
diff changeset
946
kono
parents:
diff changeset
947 -- If there is no condition, we rewrite as
kono
parents:
diff changeset
948
kono
parents:
diff changeset
949 -- begin
kono
parents:
diff changeset
950 -- Local_Raise (excep'Identity);
kono
parents:
diff changeset
951 -- goto L1;
kono
parents:
diff changeset
952 -- end;
kono
parents:
diff changeset
953
kono
parents:
diff changeset
954 if No (Cond) then
kono
parents:
diff changeset
955 Rewrite (Raise_S,
kono
parents:
diff changeset
956 Make_Block_Statement (Loc,
kono
parents:
diff changeset
957 Handled_Statement_Sequence =>
kono
parents:
diff changeset
958 Make_Handled_Sequence_Of_Statements (Loc,
kono
parents:
diff changeset
959 Statements => New_List (LR, Goto_L1))));
kono
parents:
diff changeset
960 Set_Exception_Junk (Raise_S);
kono
parents:
diff changeset
961
kono
parents:
diff changeset
962 -- If there is a condition, we rewrite as
kono
parents:
diff changeset
963
kono
parents:
diff changeset
964 -- if condition then
kono
parents:
diff changeset
965 -- Local_Raise (excep'Identity);
kono
parents:
diff changeset
966 -- goto L1;
kono
parents:
diff changeset
967 -- end if;
kono
parents:
diff changeset
968
kono
parents:
diff changeset
969 else
kono
parents:
diff changeset
970 Rewrite (Raise_S,
kono
parents:
diff changeset
971 Make_If_Statement (Loc,
kono
parents:
diff changeset
972 Condition => Cond,
kono
parents:
diff changeset
973 Then_Statements => New_List (LR, Goto_L1)));
kono
parents:
diff changeset
974 end if;
kono
parents:
diff changeset
975
kono
parents:
diff changeset
976 Analyze (Raise_S);
kono
parents:
diff changeset
977 end Replace_Raise_By_Goto;
kono
parents:
diff changeset
978
kono
parents:
diff changeset
979 -- Start of processing for Expand_Exception_Handlers
kono
parents:
diff changeset
980
kono
parents:
diff changeset
981 begin
kono
parents:
diff changeset
982 Expand_Local_Exception_Handlers;
kono
parents:
diff changeset
983
kono
parents:
diff changeset
984 -- Loop through handlers
kono
parents:
diff changeset
985
kono
parents:
diff changeset
986 Handler := First_Non_Pragma (Handlrs);
kono
parents:
diff changeset
987 Handler_Loop : while Present (Handler) loop
kono
parents:
diff changeset
988 Process_Statements_For_Controlled_Objects (Handler);
kono
parents:
diff changeset
989
kono
parents:
diff changeset
990 Next_Handler := Next_Non_Pragma (Handler);
kono
parents:
diff changeset
991
kono
parents:
diff changeset
992 -- Remove source handler if gnat debug flag .x is set
kono
parents:
diff changeset
993
kono
parents:
diff changeset
994 if Debug_Flag_Dot_X and then Comes_From_Source (Handler) then
kono
parents:
diff changeset
995 Remove (Handler);
kono
parents:
diff changeset
996
kono
parents:
diff changeset
997 -- Remove handler if no exception propagation, generating a warning
kono
parents:
diff changeset
998 -- if a source generated handler was not the target of a local raise.
kono
parents:
diff changeset
999
kono
parents:
diff changeset
1000 else
kono
parents:
diff changeset
1001 if not Has_Local_Raise (Handler)
kono
parents:
diff changeset
1002 and then Comes_From_Source (Handler)
kono
parents:
diff changeset
1003 then
kono
parents:
diff changeset
1004 Warn_If_No_Local_Raise (Handler);
kono
parents:
diff changeset
1005 end if;
kono
parents:
diff changeset
1006
kono
parents:
diff changeset
1007 if No_Exception_Propagation_Active then
kono
parents:
diff changeset
1008 Remove (Handler);
kono
parents:
diff changeset
1009
kono
parents:
diff changeset
1010 -- Exception handler is active and retained and must be processed
kono
parents:
diff changeset
1011
kono
parents:
diff changeset
1012 else
kono
parents:
diff changeset
1013 -- If an exception occurrence is present, then we must declare
kono
parents:
diff changeset
1014 -- it and initialize it from the value stored in the TSD
kono
parents:
diff changeset
1015
kono
parents:
diff changeset
1016 -- declare
kono
parents:
diff changeset
1017 -- name : Exception_Occurrence;
kono
parents:
diff changeset
1018 -- begin
kono
parents:
diff changeset
1019 -- Save_Occurrence (name, Get_Current_Excep.all)
kono
parents:
diff changeset
1020 -- ...
kono
parents:
diff changeset
1021 -- end;
kono
parents:
diff changeset
1022
kono
parents:
diff changeset
1023 -- This expansion is only performed when using front-end
kono
parents:
diff changeset
1024 -- exceptions. Gigi will insert a call to initialize the
kono
parents:
diff changeset
1025 -- choice parameter.
kono
parents:
diff changeset
1026
kono
parents:
diff changeset
1027 if Present (Choice_Parameter (Handler))
kono
parents:
diff changeset
1028 and then (Front_End_Exceptions
kono
parents:
diff changeset
1029 or else CodePeer_Mode)
kono
parents:
diff changeset
1030 then
kono
parents:
diff changeset
1031 declare
kono
parents:
diff changeset
1032 Cparm : constant Entity_Id := Choice_Parameter (Handler);
kono
parents:
diff changeset
1033 Cloc : constant Source_Ptr := Sloc (Cparm);
kono
parents:
diff changeset
1034 Hloc : constant Source_Ptr := Sloc (Handler);
kono
parents:
diff changeset
1035 Save : Node_Id;
kono
parents:
diff changeset
1036
kono
parents:
diff changeset
1037 begin
kono
parents:
diff changeset
1038 -- Note: No_Location used to hide code from the debugger,
kono
parents:
diff changeset
1039 -- so single stepping doesn't jump back and forth.
kono
parents:
diff changeset
1040
kono
parents:
diff changeset
1041 Save :=
kono
parents:
diff changeset
1042 Make_Procedure_Call_Statement (No_Location,
kono
parents:
diff changeset
1043 Name =>
kono
parents:
diff changeset
1044 New_Occurrence_Of
kono
parents:
diff changeset
1045 (RTE (RE_Save_Occurrence), No_Location),
kono
parents:
diff changeset
1046 Parameter_Associations => New_List (
kono
parents:
diff changeset
1047 New_Occurrence_Of (Cparm, No_Location),
kono
parents:
diff changeset
1048 Make_Explicit_Dereference (No_Location,
kono
parents:
diff changeset
1049 Prefix =>
kono
parents:
diff changeset
1050 Make_Function_Call (No_Location,
kono
parents:
diff changeset
1051 Name =>
kono
parents:
diff changeset
1052 Make_Explicit_Dereference (No_Location,
kono
parents:
diff changeset
1053 Prefix =>
kono
parents:
diff changeset
1054 New_Occurrence_Of
kono
parents:
diff changeset
1055 (RTE (RE_Get_Current_Excep),
kono
parents:
diff changeset
1056 No_Location))))));
kono
parents:
diff changeset
1057
kono
parents:
diff changeset
1058 Mark_Rewrite_Insertion (Save);
kono
parents:
diff changeset
1059 Prepend (Save, Statements (Handler));
kono
parents:
diff changeset
1060
kono
parents:
diff changeset
1061 Obj_Decl :=
kono
parents:
diff changeset
1062 Make_Object_Declaration (Cloc,
kono
parents:
diff changeset
1063 Defining_Identifier => Cparm,
kono
parents:
diff changeset
1064 Object_Definition =>
kono
parents:
diff changeset
1065 New_Occurrence_Of
kono
parents:
diff changeset
1066 (RTE (RE_Exception_Occurrence), Cloc));
kono
parents:
diff changeset
1067 Set_No_Initialization (Obj_Decl, True);
kono
parents:
diff changeset
1068
kono
parents:
diff changeset
1069 Rewrite (Handler,
kono
parents:
diff changeset
1070 Make_Exception_Handler (Hloc,
kono
parents:
diff changeset
1071 Choice_Parameter => Empty,
kono
parents:
diff changeset
1072 Exception_Choices => Exception_Choices (Handler),
kono
parents:
diff changeset
1073 Statements => New_List (
kono
parents:
diff changeset
1074 Make_Block_Statement (Hloc,
kono
parents:
diff changeset
1075 Declarations => New_List (Obj_Decl),
kono
parents:
diff changeset
1076 Handled_Statement_Sequence =>
kono
parents:
diff changeset
1077 Make_Handled_Sequence_Of_Statements (Hloc,
kono
parents:
diff changeset
1078 Statements => Statements (Handler))))));
kono
parents:
diff changeset
1079
kono
parents:
diff changeset
1080 -- Local raise statements can't occur, since exception
kono
parents:
diff changeset
1081 -- handlers with choice parameters are not allowed when
kono
parents:
diff changeset
1082 -- No_Exception_Propagation applies, so set attributes
kono
parents:
diff changeset
1083 -- accordingly.
kono
parents:
diff changeset
1084
kono
parents:
diff changeset
1085 Set_Local_Raise_Statements (Handler, No_Elist);
kono
parents:
diff changeset
1086 Set_Local_Raise_Not_OK (Handler);
kono
parents:
diff changeset
1087
kono
parents:
diff changeset
1088 Analyze_List
kono
parents:
diff changeset
1089 (Statements (Handler), Suppress => All_Checks);
kono
parents:
diff changeset
1090 end;
kono
parents:
diff changeset
1091 end if;
kono
parents:
diff changeset
1092
kono
parents:
diff changeset
1093 -- For the normal case, we have to worry about the state of
kono
parents:
diff changeset
1094 -- abort deferral. Generally, we defer abort during runtime
kono
parents:
diff changeset
1095 -- handling of exceptions. When control is passed to the
kono
parents:
diff changeset
1096 -- handler, then in the normal case we undefer aborts. In
kono
parents:
diff changeset
1097 -- any case this entire handling is relevant only if aborts
kono
parents:
diff changeset
1098 -- are allowed.
kono
parents:
diff changeset
1099
kono
parents:
diff changeset
1100 if Abort_Allowed
kono
parents:
diff changeset
1101 and then not ZCX_Exceptions
kono
parents:
diff changeset
1102 then
kono
parents:
diff changeset
1103 -- There are some special cases in which we do not do the
kono
parents:
diff changeset
1104 -- undefer. In particular a finalization (AT END) handler
kono
parents:
diff changeset
1105 -- wants to operate with aborts still deferred.
kono
parents:
diff changeset
1106
kono
parents:
diff changeset
1107 -- We also suppress the call if this is the special handler
kono
parents:
diff changeset
1108 -- for Abort_Signal, since if we are aborting, we want to
kono
parents:
diff changeset
1109 -- keep aborts deferred (one abort is enough).
kono
parents:
diff changeset
1110
kono
parents:
diff changeset
1111 -- If abort really needs to be deferred the expander must
kono
parents:
diff changeset
1112 -- add this call explicitly, see
kono
parents:
diff changeset
1113 -- Expand_N_Asynchronous_Select.
kono
parents:
diff changeset
1114
kono
parents:
diff changeset
1115 Others_Choice :=
kono
parents:
diff changeset
1116 Nkind (First (Exception_Choices (Handler))) =
kono
parents:
diff changeset
1117 N_Others_Choice;
kono
parents:
diff changeset
1118
kono
parents:
diff changeset
1119 if (Others_Choice
kono
parents:
diff changeset
1120 or else Entity (First (Exception_Choices (Handler))) /=
kono
parents:
diff changeset
1121 Stand.Abort_Signal)
kono
parents:
diff changeset
1122 and then not
kono
parents:
diff changeset
1123 (Others_Choice
kono
parents:
diff changeset
1124 and then
kono
parents:
diff changeset
1125 All_Others (First (Exception_Choices (Handler))))
kono
parents:
diff changeset
1126 then
kono
parents:
diff changeset
1127 Prepend_Call_To_Handler (RE_Abort_Undefer);
kono
parents:
diff changeset
1128 end if;
kono
parents:
diff changeset
1129 end if;
kono
parents:
diff changeset
1130 end if;
kono
parents:
diff changeset
1131 end if;
kono
parents:
diff changeset
1132
kono
parents:
diff changeset
1133 Handler := Next_Handler;
kono
parents:
diff changeset
1134 end loop Handler_Loop;
kono
parents:
diff changeset
1135
kono
parents:
diff changeset
1136 -- If all handlers got removed, then remove the list. Note we cannot
kono
parents:
diff changeset
1137 -- reference HSS here, since expanding local handlers may have buried
kono
parents:
diff changeset
1138 -- the handlers in an inner block.
kono
parents:
diff changeset
1139
kono
parents:
diff changeset
1140 if Is_Empty_List (Handlrs) then
kono
parents:
diff changeset
1141 Set_Exception_Handlers (Parent (Handlrs), No_List);
kono
parents:
diff changeset
1142 end if;
kono
parents:
diff changeset
1143 end Expand_Exception_Handlers;
kono
parents:
diff changeset
1144
kono
parents:
diff changeset
1145 ------------------------------------
kono
parents:
diff changeset
1146 -- Expand_N_Exception_Declaration --
kono
parents:
diff changeset
1147 ------------------------------------
kono
parents:
diff changeset
1148
kono
parents:
diff changeset
1149 -- Generates:
kono
parents:
diff changeset
1150 -- exceptE : constant String := "A.B.EXCEP"; -- static data
kono
parents:
diff changeset
1151 -- except : exception_data :=
kono
parents:
diff changeset
1152 -- (Handled_By_Other => False,
kono
parents:
diff changeset
1153 -- Lang => 'A',
kono
parents:
diff changeset
1154 -- Name_Length => exceptE'Length,
kono
parents:
diff changeset
1155 -- Full_Name => exceptE'Address,
kono
parents:
diff changeset
1156 -- HTable_Ptr => null,
kono
parents:
diff changeset
1157 -- Foreign_Data => null,
kono
parents:
diff changeset
1158 -- Raise_Hook => null);
kono
parents:
diff changeset
1159
kono
parents:
diff changeset
1160 -- (protecting test only needed if not at library level)
kono
parents:
diff changeset
1161
kono
parents:
diff changeset
1162 -- exceptF : Boolean := True -- static data
kono
parents:
diff changeset
1163 -- if exceptF then
kono
parents:
diff changeset
1164 -- exceptF := False;
kono
parents:
diff changeset
1165 -- Register_Exception (except'Unchecked_Access);
kono
parents:
diff changeset
1166 -- end if;
kono
parents:
diff changeset
1167
kono
parents:
diff changeset
1168 procedure Expand_N_Exception_Declaration (N : Node_Id) is
kono
parents:
diff changeset
1169 Id : constant Entity_Id := Defining_Identifier (N);
kono
parents:
diff changeset
1170 Loc : constant Source_Ptr := Sloc (N);
kono
parents:
diff changeset
1171
kono
parents:
diff changeset
1172 procedure Force_Static_Allocation_Of_Referenced_Objects
kono
parents:
diff changeset
1173 (Aggregate : Node_Id);
kono
parents:
diff changeset
1174 -- A specialized solution to one particular case of an ugly problem
kono
parents:
diff changeset
1175 --
kono
parents:
diff changeset
1176 -- The given aggregate includes an Unchecked_Conversion as one of the
kono
parents:
diff changeset
1177 -- component values. The call to Analyze_And_Resolve below ends up
kono
parents:
diff changeset
1178 -- calling Exp_Ch4.Expand_N_Unchecked_Type_Conversion, which may decide
kono
parents:
diff changeset
1179 -- to introduce a (constant) temporary and then obtain the component
kono
parents:
diff changeset
1180 -- value by evaluating the temporary.
kono
parents:
diff changeset
1181 --
kono
parents:
diff changeset
1182 -- In the case of an exception declared within a subprogram (or any
kono
parents:
diff changeset
1183 -- other dynamic scope), this is a bad transformation. The exception
kono
parents:
diff changeset
1184 -- object is marked as being Statically_Allocated but the temporary is
kono
parents:
diff changeset
1185 -- not. If the initial value of a Statically_Allocated declaration
kono
parents:
diff changeset
1186 -- references a dynamically allocated object, this prevents static
kono
parents:
diff changeset
1187 -- initialization of the object.
kono
parents:
diff changeset
1188 --
kono
parents:
diff changeset
1189 -- We cope with this here by marking the temporary Statically_Allocated.
kono
parents:
diff changeset
1190 -- It might seem cleaner to generalize this utility and then use it to
kono
parents:
diff changeset
1191 -- enforce a rule that the entities referenced in the declaration of any
kono
parents:
diff changeset
1192 -- "hoisted" (i.e., Is_Statically_Allocated and not Is_Library_Level)
kono
parents:
diff changeset
1193 -- entity must also be either Library_Level or hoisted. It turns out
kono
parents:
diff changeset
1194 -- that this would be incompatible with the current treatment of an
kono
parents:
diff changeset
1195 -- object which is local to a subprogram, subject to an Export pragma,
kono
parents:
diff changeset
1196 -- not subject to an address clause, and whose declaration contains
kono
parents:
diff changeset
1197 -- references to other local (non-hoisted) objects (e.g., in the initial
kono
parents:
diff changeset
1198 -- value expression).
kono
parents:
diff changeset
1199
kono
parents:
diff changeset
1200 function Null_String return String_Id;
kono
parents:
diff changeset
1201 -- Build a null-terminated empty string
kono
parents:
diff changeset
1202
kono
parents:
diff changeset
1203 ---------------------------------------------------
kono
parents:
diff changeset
1204 -- Force_Static_Allocation_Of_Referenced_Objects --
kono
parents:
diff changeset
1205 ---------------------------------------------------
kono
parents:
diff changeset
1206
kono
parents:
diff changeset
1207 procedure Force_Static_Allocation_Of_Referenced_Objects
kono
parents:
diff changeset
1208 (Aggregate : Node_Id)
kono
parents:
diff changeset
1209 is
kono
parents:
diff changeset
1210 function Fixup_Node (N : Node_Id) return Traverse_Result;
kono
parents:
diff changeset
1211 -- If the given node references a dynamically allocated object, then
kono
parents:
diff changeset
1212 -- correct the declaration of the object.
kono
parents:
diff changeset
1213
kono
parents:
diff changeset
1214 ----------------
kono
parents:
diff changeset
1215 -- Fixup_Node --
kono
parents:
diff changeset
1216 ----------------
kono
parents:
diff changeset
1217
kono
parents:
diff changeset
1218 function Fixup_Node (N : Node_Id) return Traverse_Result is
kono
parents:
diff changeset
1219 begin
kono
parents:
diff changeset
1220 if Nkind (N) in N_Has_Entity
kono
parents:
diff changeset
1221 and then Present (Entity (N))
kono
parents:
diff changeset
1222 and then not Is_Library_Level_Entity (Entity (N))
kono
parents:
diff changeset
1223
kono
parents:
diff changeset
1224 -- Note: the following test is not needed but it seems cleaner
kono
parents:
diff changeset
1225 -- to do this test (this would be more important if procedure
kono
parents:
diff changeset
1226 -- Force_Static_Allocation_Of_Referenced_Objects recursively
kono
parents:
diff changeset
1227 -- traversed the declaration of an entity after marking it as
kono
parents:
diff changeset
1228 -- statically allocated).
kono
parents:
diff changeset
1229
kono
parents:
diff changeset
1230 and then not Is_Statically_Allocated (Entity (N))
kono
parents:
diff changeset
1231 then
kono
parents:
diff changeset
1232 Set_Is_Statically_Allocated (Entity (N));
kono
parents:
diff changeset
1233 end if;
kono
parents:
diff changeset
1234
kono
parents:
diff changeset
1235 return OK;
kono
parents:
diff changeset
1236 end Fixup_Node;
kono
parents:
diff changeset
1237
kono
parents:
diff changeset
1238 procedure Fixup_Tree is new Traverse_Proc (Fixup_Node);
kono
parents:
diff changeset
1239
kono
parents:
diff changeset
1240 -- Start of processing for Force_Static_Allocation_Of_Referenced_Objects
kono
parents:
diff changeset
1241
kono
parents:
diff changeset
1242 begin
kono
parents:
diff changeset
1243 Fixup_Tree (Aggregate);
kono
parents:
diff changeset
1244 end Force_Static_Allocation_Of_Referenced_Objects;
kono
parents:
diff changeset
1245
kono
parents:
diff changeset
1246 -----------------
kono
parents:
diff changeset
1247 -- Null_String --
kono
parents:
diff changeset
1248 -----------------
kono
parents:
diff changeset
1249
kono
parents:
diff changeset
1250 function Null_String return String_Id is
kono
parents:
diff changeset
1251 begin
kono
parents:
diff changeset
1252 Start_String;
kono
parents:
diff changeset
1253 Store_String_Char (Get_Char_Code (ASCII.NUL));
kono
parents:
diff changeset
1254 return End_String;
kono
parents:
diff changeset
1255 end Null_String;
kono
parents:
diff changeset
1256
kono
parents:
diff changeset
1257 -- Local variables
kono
parents:
diff changeset
1258
kono
parents:
diff changeset
1259 Ex_Id : Entity_Id;
kono
parents:
diff changeset
1260 Ex_Val : String_Id;
kono
parents:
diff changeset
1261 Flag_Id : Entity_Id;
kono
parents:
diff changeset
1262 L : List_Id;
kono
parents:
diff changeset
1263
kono
parents:
diff changeset
1264 -- Start of processing for Expand_N_Exception_Declaration
kono
parents:
diff changeset
1265
kono
parents:
diff changeset
1266 begin
kono
parents:
diff changeset
1267 -- Nothing to do when generating C code
kono
parents:
diff changeset
1268
kono
parents:
diff changeset
1269 if Modify_Tree_For_C then
kono
parents:
diff changeset
1270 return;
kono
parents:
diff changeset
1271 end if;
kono
parents:
diff changeset
1272
kono
parents:
diff changeset
1273 -- Definition of the external name: nam : constant String := "A.B.NAME";
kono
parents:
diff changeset
1274
kono
parents:
diff changeset
1275 Ex_Id :=
kono
parents:
diff changeset
1276 Make_Defining_Identifier (Loc, New_External_Name (Chars (Id), 'E'));
kono
parents:
diff changeset
1277
kono
parents:
diff changeset
1278 -- Do not generate an external name if the exception declaration is
kono
parents:
diff changeset
1279 -- subject to pragma Discard_Names. Use a null-terminated empty name
kono
parents:
diff changeset
1280 -- to ensure that Ada.Exceptions.Exception_Name functions properly.
kono
parents:
diff changeset
1281
kono
parents:
diff changeset
1282 if Global_Discard_Names or else Discard_Names (Ex_Id) then
kono
parents:
diff changeset
1283 Ex_Val := Null_String;
kono
parents:
diff changeset
1284
kono
parents:
diff changeset
1285 -- Otherwise generate the fully qualified name of the exception
kono
parents:
diff changeset
1286
kono
parents:
diff changeset
1287 else
kono
parents:
diff changeset
1288 Ex_Val := Fully_Qualified_Name_String (Id);
kono
parents:
diff changeset
1289 end if;
kono
parents:
diff changeset
1290
kono
parents:
diff changeset
1291 Insert_Action (N,
kono
parents:
diff changeset
1292 Make_Object_Declaration (Loc,
kono
parents:
diff changeset
1293 Defining_Identifier => Ex_Id,
kono
parents:
diff changeset
1294 Constant_Present => True,
kono
parents:
diff changeset
1295 Object_Definition => New_Occurrence_Of (Standard_String, Loc),
kono
parents:
diff changeset
1296 Expression => Make_String_Literal (Loc, Ex_Val)));
kono
parents:
diff changeset
1297
kono
parents:
diff changeset
1298 Set_Is_Statically_Allocated (Ex_Id);
kono
parents:
diff changeset
1299
kono
parents:
diff changeset
1300 -- Create the aggregate list for type Standard.Exception_Type:
kono
parents:
diff changeset
1301 -- Handled_By_Other component: False
kono
parents:
diff changeset
1302
kono
parents:
diff changeset
1303 L := Empty_List;
kono
parents:
diff changeset
1304 Append_To (L, New_Occurrence_Of (Standard_False, Loc));
kono
parents:
diff changeset
1305
kono
parents:
diff changeset
1306 -- Lang component: 'A'
kono
parents:
diff changeset
1307
kono
parents:
diff changeset
1308 Append_To (L,
kono
parents:
diff changeset
1309 Make_Character_Literal (Loc,
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1310 Chars => Name_uA,
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1311 Char_Literal_Value => UI_From_Int (Character'Pos ('A'))));
111
kono
parents:
diff changeset
1312
kono
parents:
diff changeset
1313 -- Name_Length component: Nam'Length
kono
parents:
diff changeset
1314
kono
parents:
diff changeset
1315 Append_To (L,
kono
parents:
diff changeset
1316 Make_Attribute_Reference (Loc,
kono
parents:
diff changeset
1317 Prefix => New_Occurrence_Of (Ex_Id, Loc),
kono
parents:
diff changeset
1318 Attribute_Name => Name_Length));
kono
parents:
diff changeset
1319
kono
parents:
diff changeset
1320 -- Full_Name component: Standard.A_Char!(Nam'Address)
kono
parents:
diff changeset
1321
kono
parents:
diff changeset
1322 -- The unchecked conversion causes capacity issues for CodePeer in some
kono
parents:
diff changeset
1323 -- cases and is never useful, so we set the Full_Name component to null
kono
parents:
diff changeset
1324 -- instead for CodePeer.
kono
parents:
diff changeset
1325
kono
parents:
diff changeset
1326 if CodePeer_Mode then
kono
parents:
diff changeset
1327 Append_To (L, Make_Null (Loc));
kono
parents:
diff changeset
1328 else
kono
parents:
diff changeset
1329 Append_To (L, Unchecked_Convert_To (Standard_A_Char,
kono
parents:
diff changeset
1330 Make_Attribute_Reference (Loc,
kono
parents:
diff changeset
1331 Prefix => New_Occurrence_Of (Ex_Id, Loc),
kono
parents:
diff changeset
1332 Attribute_Name => Name_Address)));
kono
parents:
diff changeset
1333 end if;
kono
parents:
diff changeset
1334
kono
parents:
diff changeset
1335 -- HTable_Ptr component: null
kono
parents:
diff changeset
1336
kono
parents:
diff changeset
1337 Append_To (L, Make_Null (Loc));
kono
parents:
diff changeset
1338
kono
parents:
diff changeset
1339 -- Foreign_Data component: null
kono
parents:
diff changeset
1340
kono
parents:
diff changeset
1341 Append_To (L, Make_Null (Loc));
kono
parents:
diff changeset
1342
kono
parents:
diff changeset
1343 -- Raise_Hook component: null
kono
parents:
diff changeset
1344
kono
parents:
diff changeset
1345 Append_To (L, Make_Null (Loc));
kono
parents:
diff changeset
1346
kono
parents:
diff changeset
1347 Set_Expression (N, Make_Aggregate (Loc, Expressions => L));
kono
parents:
diff changeset
1348 Analyze_And_Resolve (Expression (N), Etype (Id));
kono
parents:
diff changeset
1349
kono
parents:
diff changeset
1350 Force_Static_Allocation_Of_Referenced_Objects (Expression (N));
kono
parents:
diff changeset
1351
kono
parents:
diff changeset
1352 -- Register_Exception (except'Unchecked_Access);
kono
parents:
diff changeset
1353
kono
parents:
diff changeset
1354 if not No_Exception_Handlers_Set
kono
parents:
diff changeset
1355 and then not Restriction_Active (No_Exception_Registration)
kono
parents:
diff changeset
1356 then
kono
parents:
diff changeset
1357 L := New_List (
kono
parents:
diff changeset
1358 Make_Procedure_Call_Statement (Loc,
kono
parents:
diff changeset
1359 Name =>
kono
parents:
diff changeset
1360 New_Occurrence_Of (RTE (RE_Register_Exception), Loc),
kono
parents:
diff changeset
1361 Parameter_Associations => New_List (
kono
parents:
diff changeset
1362 Unchecked_Convert_To (RTE (RE_Exception_Data_Ptr),
kono
parents:
diff changeset
1363 Make_Attribute_Reference (Loc,
kono
parents:
diff changeset
1364 Prefix => New_Occurrence_Of (Id, Loc),
kono
parents:
diff changeset
1365 Attribute_Name => Name_Unrestricted_Access)))));
kono
parents:
diff changeset
1366
kono
parents:
diff changeset
1367 Set_Register_Exception_Call (Id, First (L));
kono
parents:
diff changeset
1368
kono
parents:
diff changeset
1369 if not Is_Library_Level_Entity (Id) then
kono
parents:
diff changeset
1370 Flag_Id :=
kono
parents:
diff changeset
1371 Make_Defining_Identifier (Loc,
kono
parents:
diff changeset
1372 Chars => New_External_Name (Chars (Id), 'F'));
kono
parents:
diff changeset
1373
kono
parents:
diff changeset
1374 Insert_Action (N,
kono
parents:
diff changeset
1375 Make_Object_Declaration (Loc,
kono
parents:
diff changeset
1376 Defining_Identifier => Flag_Id,
kono
parents:
diff changeset
1377 Object_Definition =>
kono
parents:
diff changeset
1378 New_Occurrence_Of (Standard_Boolean, Loc),
kono
parents:
diff changeset
1379 Expression =>
kono
parents:
diff changeset
1380 New_Occurrence_Of (Standard_True, Loc)));
kono
parents:
diff changeset
1381
kono
parents:
diff changeset
1382 Set_Is_Statically_Allocated (Flag_Id);
kono
parents:
diff changeset
1383
kono
parents:
diff changeset
1384 Append_To (L,
kono
parents:
diff changeset
1385 Make_Assignment_Statement (Loc,
kono
parents:
diff changeset
1386 Name => New_Occurrence_Of (Flag_Id, Loc),
kono
parents:
diff changeset
1387 Expression => New_Occurrence_Of (Standard_False, Loc)));
kono
parents:
diff changeset
1388
kono
parents:
diff changeset
1389 Insert_After_And_Analyze (N,
kono
parents:
diff changeset
1390 Make_Implicit_If_Statement (N,
kono
parents:
diff changeset
1391 Condition => New_Occurrence_Of (Flag_Id, Loc),
kono
parents:
diff changeset
1392 Then_Statements => L));
kono
parents:
diff changeset
1393
kono
parents:
diff changeset
1394 else
kono
parents:
diff changeset
1395 Insert_List_After_And_Analyze (N, L);
kono
parents:
diff changeset
1396 end if;
kono
parents:
diff changeset
1397 end if;
kono
parents:
diff changeset
1398 end Expand_N_Exception_Declaration;
kono
parents:
diff changeset
1399
kono
parents:
diff changeset
1400 ---------------------------------------------
kono
parents:
diff changeset
1401 -- Expand_N_Handled_Sequence_Of_Statements --
kono
parents:
diff changeset
1402 ---------------------------------------------
kono
parents:
diff changeset
1403
kono
parents:
diff changeset
1404 procedure Expand_N_Handled_Sequence_Of_Statements (N : Node_Id) is
kono
parents:
diff changeset
1405 begin
kono
parents:
diff changeset
1406 -- Expand exception handlers
kono
parents:
diff changeset
1407
kono
parents:
diff changeset
1408 if Present (Exception_Handlers (N))
kono
parents:
diff changeset
1409 and then not Restriction_Active (No_Exception_Handlers)
kono
parents:
diff changeset
1410 then
kono
parents:
diff changeset
1411 Expand_Exception_Handlers (N);
kono
parents:
diff changeset
1412 end if;
kono
parents:
diff changeset
1413
kono
parents:
diff changeset
1414 -- If local exceptions are being expanded, the previous call will
kono
parents:
diff changeset
1415 -- have rewritten the construct as a block and reanalyzed it. No
kono
parents:
diff changeset
1416 -- further expansion is needed.
kono
parents:
diff changeset
1417
kono
parents:
diff changeset
1418 if Analyzed (N) then
kono
parents:
diff changeset
1419 return;
kono
parents:
diff changeset
1420 end if;
kono
parents:
diff changeset
1421
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1422 -- Add cleanup actions if required. No cleanup actions are needed in
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1423 -- thunks associated with interfaces, because they only displace the
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1424 -- pointer to the object. For extended return statements, we need
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1425 -- cleanup actions if the Handled_Statement_Sequence contains generated
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1426 -- objects of controlled types, for example. We do not want to clean up
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1427 -- the return object.
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1428
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1429 if not Nkind_In (Parent (N), N_Accept_Statement,
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1430 N_Extended_Return_Statement,
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1431 N_Package_Body)
111
kono
parents:
diff changeset
1432 and then not Delay_Cleanups (Current_Scope)
kono
parents:
diff changeset
1433 and then not Is_Thunk (Current_Scope)
kono
parents:
diff changeset
1434 then
kono
parents:
diff changeset
1435 Expand_Cleanup_Actions (Parent (N));
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1436
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1437 elsif Nkind (Parent (N)) = N_Extended_Return_Statement
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1438 and then Handled_Statement_Sequence (Parent (N)) = N
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1439 and then not Delay_Cleanups (Current_Scope)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1440 then
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1441 pragma Assert (not Is_Thunk (Current_Scope));
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1442 Expand_Cleanup_Actions (Parent (N));
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1443
111
kono
parents:
diff changeset
1444 else
kono
parents:
diff changeset
1445 Set_First_Real_Statement (N, First (Statements (N)));
kono
parents:
diff changeset
1446 end if;
kono
parents:
diff changeset
1447 end Expand_N_Handled_Sequence_Of_Statements;
kono
parents:
diff changeset
1448
kono
parents:
diff changeset
1449 -------------------------------------
kono
parents:
diff changeset
1450 -- Expand_N_Raise_Constraint_Error --
kono
parents:
diff changeset
1451 -------------------------------------
kono
parents:
diff changeset
1452
kono
parents:
diff changeset
1453 procedure Expand_N_Raise_Constraint_Error (N : Node_Id) is
kono
parents:
diff changeset
1454 begin
kono
parents:
diff changeset
1455 -- We adjust the condition to deal with the C/Fortran boolean case. This
kono
parents:
diff changeset
1456 -- may well not be necessary, as all such conditions are generated by
kono
parents:
diff changeset
1457 -- the expander and probably are all standard boolean, but who knows
kono
parents:
diff changeset
1458 -- what strange optimization in future may require this adjustment.
kono
parents:
diff changeset
1459
kono
parents:
diff changeset
1460 Adjust_Condition (Condition (N));
kono
parents:
diff changeset
1461
kono
parents:
diff changeset
1462 -- Now deal with possible local raise handling
kono
parents:
diff changeset
1463
kono
parents:
diff changeset
1464 Possible_Local_Raise (N, Standard_Constraint_Error);
kono
parents:
diff changeset
1465 end Expand_N_Raise_Constraint_Error;
kono
parents:
diff changeset
1466
kono
parents:
diff changeset
1467 -------------------------------
kono
parents:
diff changeset
1468 -- Expand_N_Raise_Expression --
kono
parents:
diff changeset
1469 -------------------------------
kono
parents:
diff changeset
1470
kono
parents:
diff changeset
1471 procedure Expand_N_Raise_Expression (N : Node_Id) is
kono
parents:
diff changeset
1472 Loc : constant Source_Ptr := Sloc (N);
kono
parents:
diff changeset
1473 Typ : constant Entity_Id := Etype (N);
kono
parents:
diff changeset
1474 RCE : Node_Id;
kono
parents:
diff changeset
1475
kono
parents:
diff changeset
1476 begin
kono
parents:
diff changeset
1477 Possible_Local_Raise (N, Entity (Name (N)));
kono
parents:
diff changeset
1478
kono
parents:
diff changeset
1479 -- Later we must teach the back end/gigi how to deal with this, but
kono
parents:
diff changeset
1480 -- for now we will assume the type is Standard_Boolean and transform
kono
parents:
diff changeset
1481 -- the node to:
kono
parents:
diff changeset
1482
kono
parents:
diff changeset
1483 -- do
kono
parents:
diff changeset
1484 -- raise X [with string]
kono
parents:
diff changeset
1485 -- in
kono
parents:
diff changeset
1486 -- raise Constraint_Error;
kono
parents:
diff changeset
1487
kono
parents:
diff changeset
1488 -- unless the flag Convert_To_Return_False is set, in which case
kono
parents:
diff changeset
1489 -- the transformation is to:
kono
parents:
diff changeset
1490
kono
parents:
diff changeset
1491 -- do
kono
parents:
diff changeset
1492 -- return False;
kono
parents:
diff changeset
1493 -- in
kono
parents:
diff changeset
1494 -- raise Constraint_Error;
kono
parents:
diff changeset
1495
kono
parents:
diff changeset
1496 -- The raise constraint error can never be executed. It is just a dummy
kono
parents:
diff changeset
1497 -- node that can be labeled with an arbitrary type.
kono
parents:
diff changeset
1498
kono
parents:
diff changeset
1499 RCE := Make_Raise_Constraint_Error (Loc, Reason => CE_Explicit_Raise);
kono
parents:
diff changeset
1500 Set_Etype (RCE, Typ);
kono
parents:
diff changeset
1501
kono
parents:
diff changeset
1502 if Convert_To_Return_False (N) then
kono
parents:
diff changeset
1503 Rewrite (N,
kono
parents:
diff changeset
1504 Make_Expression_With_Actions (Loc,
kono
parents:
diff changeset
1505 Actions => New_List (
kono
parents:
diff changeset
1506 Make_Simple_Return_Statement (Loc,
kono
parents:
diff changeset
1507 Expression => New_Occurrence_Of (Standard_False, Loc))),
kono
parents:
diff changeset
1508 Expression => RCE));
kono
parents:
diff changeset
1509
kono
parents:
diff changeset
1510 else
kono
parents:
diff changeset
1511 Rewrite (N,
kono
parents:
diff changeset
1512 Make_Expression_With_Actions (Loc,
kono
parents:
diff changeset
1513 Actions => New_List (
kono
parents:
diff changeset
1514 Make_Raise_Statement (Loc,
kono
parents:
diff changeset
1515 Name => Name (N),
kono
parents:
diff changeset
1516 Expression => Expression (N))),
kono
parents:
diff changeset
1517 Expression => RCE));
kono
parents:
diff changeset
1518 end if;
kono
parents:
diff changeset
1519
kono
parents:
diff changeset
1520 Analyze_And_Resolve (N, Typ);
kono
parents:
diff changeset
1521 end Expand_N_Raise_Expression;
kono
parents:
diff changeset
1522
kono
parents:
diff changeset
1523 ----------------------------------
kono
parents:
diff changeset
1524 -- Expand_N_Raise_Program_Error --
kono
parents:
diff changeset
1525 ----------------------------------
kono
parents:
diff changeset
1526
kono
parents:
diff changeset
1527 procedure Expand_N_Raise_Program_Error (N : Node_Id) is
kono
parents:
diff changeset
1528 begin
kono
parents:
diff changeset
1529 -- We adjust the condition to deal with the C/Fortran boolean case. This
kono
parents:
diff changeset
1530 -- may well not be necessary, as all such conditions are generated by
kono
parents:
diff changeset
1531 -- the expander and probably are all standard boolean, but who knows
kono
parents:
diff changeset
1532 -- what strange optimization in future may require this adjustment.
kono
parents:
diff changeset
1533
kono
parents:
diff changeset
1534 Adjust_Condition (Condition (N));
kono
parents:
diff changeset
1535
kono
parents:
diff changeset
1536 -- Now deal with possible local raise handling
kono
parents:
diff changeset
1537
kono
parents:
diff changeset
1538 Possible_Local_Raise (N, Standard_Program_Error);
kono
parents:
diff changeset
1539 end Expand_N_Raise_Program_Error;
kono
parents:
diff changeset
1540
kono
parents:
diff changeset
1541 ------------------------------
kono
parents:
diff changeset
1542 -- Expand_N_Raise_Statement --
kono
parents:
diff changeset
1543 ------------------------------
kono
parents:
diff changeset
1544
kono
parents:
diff changeset
1545 procedure Expand_N_Raise_Statement (N : Node_Id) is
kono
parents:
diff changeset
1546 Loc : constant Source_Ptr := Sloc (N);
kono
parents:
diff changeset
1547 Ehand : Node_Id;
kono
parents:
diff changeset
1548 E : Entity_Id;
kono
parents:
diff changeset
1549 Str : String_Id;
kono
parents:
diff changeset
1550 H : Node_Id;
kono
parents:
diff changeset
1551 Src : Boolean;
kono
parents:
diff changeset
1552
kono
parents:
diff changeset
1553 begin
kono
parents:
diff changeset
1554 -- Processing for locally handled exception (exclude reraise case)
kono
parents:
diff changeset
1555
kono
parents:
diff changeset
1556 if Present (Name (N)) and then Nkind (Name (N)) = N_Identifier then
kono
parents:
diff changeset
1557 if Debug_Flag_Dot_G
kono
parents:
diff changeset
1558 or else Restriction_Active (No_Exception_Propagation)
kono
parents:
diff changeset
1559 then
kono
parents:
diff changeset
1560 -- If we have a local handler, then note that this is potentially
kono
parents:
diff changeset
1561 -- able to be transformed into a goto statement.
kono
parents:
diff changeset
1562
kono
parents:
diff changeset
1563 H := Find_Local_Handler (Entity (Name (N)), N);
kono
parents:
diff changeset
1564
kono
parents:
diff changeset
1565 if Present (H) then
kono
parents:
diff changeset
1566 if Local_Raise_Statements (H) = No_Elist then
kono
parents:
diff changeset
1567 Set_Local_Raise_Statements (H, New_Elmt_List);
kono
parents:
diff changeset
1568 end if;
kono
parents:
diff changeset
1569
kono
parents:
diff changeset
1570 -- Append the new entry if it is not there already. Sometimes
kono
parents:
diff changeset
1571 -- we have situations where due to reexpansion, the same node
kono
parents:
diff changeset
1572 -- is analyzed twice and would otherwise be added twice.
kono
parents:
diff changeset
1573
kono
parents:
diff changeset
1574 Append_Unique_Elmt (N, Local_Raise_Statements (H));
kono
parents:
diff changeset
1575 Set_Has_Local_Raise (H);
kono
parents:
diff changeset
1576
kono
parents:
diff changeset
1577 -- If no local handler, then generate no propagation warning
kono
parents:
diff changeset
1578
kono
parents:
diff changeset
1579 else
kono
parents:
diff changeset
1580 Warn_If_No_Propagation (N);
kono
parents:
diff changeset
1581 end if;
kono
parents:
diff changeset
1582
kono
parents:
diff changeset
1583 end if;
kono
parents:
diff changeset
1584 end if;
kono
parents:
diff changeset
1585
kono
parents:
diff changeset
1586 -- If a string expression is present, then the raise statement is
kono
parents:
diff changeset
1587 -- converted to a call:
kono
parents:
diff changeset
1588 -- Raise_Exception (exception-name'Identity, string);
kono
parents:
diff changeset
1589 -- and there is nothing else to do.
kono
parents:
diff changeset
1590
kono
parents:
diff changeset
1591 if Present (Expression (N)) then
kono
parents:
diff changeset
1592
kono
parents:
diff changeset
1593 -- Adjust message to deal with Prefix_Exception_Messages. We only
kono
parents:
diff changeset
1594 -- add the prefix to string literals, if the message is being
kono
parents:
diff changeset
1595 -- constructed, we assume it already deals with uniqueness.
kono
parents:
diff changeset
1596
kono
parents:
diff changeset
1597 if Prefix_Exception_Messages
kono
parents:
diff changeset
1598 and then Nkind (Expression (N)) = N_String_Literal
kono
parents:
diff changeset
1599 then
kono
parents:
diff changeset
1600 declare
kono
parents:
diff changeset
1601 Buf : Bounded_String;
kono
parents:
diff changeset
1602 begin
kono
parents:
diff changeset
1603 Add_Source_Info (Buf, Loc, Name_Enclosing_Entity);
kono
parents:
diff changeset
1604 Append (Buf, ": ");
kono
parents:
diff changeset
1605 Append (Buf, Strval (Expression (N)));
kono
parents:
diff changeset
1606 Rewrite (Expression (N), Make_String_Literal (Loc, +Buf));
kono
parents:
diff changeset
1607 Analyze_And_Resolve (Expression (N), Standard_String);
kono
parents:
diff changeset
1608 end;
kono
parents:
diff changeset
1609 end if;
kono
parents:
diff changeset
1610
kono
parents:
diff changeset
1611 -- Avoid passing exception-name'identity in runtimes in which this
kono
parents:
diff changeset
1612 -- argument is not used. This avoids generating undefined references
kono
parents:
diff changeset
1613 -- to these exceptions when compiling with no optimization
kono
parents:
diff changeset
1614
kono
parents:
diff changeset
1615 if Configurable_Run_Time_On_Target
kono
parents:
diff changeset
1616 and then (Restriction_Active (No_Exception_Handlers)
kono
parents:
diff changeset
1617 or else
kono
parents:
diff changeset
1618 Restriction_Active (No_Exception_Propagation))
kono
parents:
diff changeset
1619 then
kono
parents:
diff changeset
1620 Rewrite (N,
kono
parents:
diff changeset
1621 Make_Procedure_Call_Statement (Loc,
kono
parents:
diff changeset
1622 Name => New_Occurrence_Of (RTE (RE_Raise_Exception), Loc),
kono
parents:
diff changeset
1623 Parameter_Associations => New_List (
kono
parents:
diff changeset
1624 New_Occurrence_Of (RTE (RE_Null_Id), Loc),
kono
parents:
diff changeset
1625 Expression (N))));
kono
parents:
diff changeset
1626 else
kono
parents:
diff changeset
1627 Rewrite (N,
kono
parents:
diff changeset
1628 Make_Procedure_Call_Statement (Loc,
kono
parents:
diff changeset
1629 Name => New_Occurrence_Of (RTE (RE_Raise_Exception), Loc),
kono
parents:
diff changeset
1630 Parameter_Associations => New_List (
kono
parents:
diff changeset
1631 Make_Attribute_Reference (Loc,
kono
parents:
diff changeset
1632 Prefix => Name (N),
kono
parents:
diff changeset
1633 Attribute_Name => Name_Identity),
kono
parents:
diff changeset
1634 Expression (N))));
kono
parents:
diff changeset
1635 end if;
kono
parents:
diff changeset
1636
kono
parents:
diff changeset
1637 Analyze (N);
kono
parents:
diff changeset
1638 return;
kono
parents:
diff changeset
1639 end if;
kono
parents:
diff changeset
1640
kono
parents:
diff changeset
1641 -- Remaining processing is for the case where no string expression is
kono
parents:
diff changeset
1642 -- present.
kono
parents:
diff changeset
1643
kono
parents:
diff changeset
1644 -- Don't expand a raise statement that does not come from source if we
kono
parents:
diff changeset
1645 -- have already had configurable run-time violations, since most likely
kono
parents:
diff changeset
1646 -- it will be junk cascaded nonsense.
kono
parents:
diff changeset
1647
kono
parents:
diff changeset
1648 if Configurable_Run_Time_Violations > 0
kono
parents:
diff changeset
1649 and then not Comes_From_Source (N)
kono
parents:
diff changeset
1650 then
kono
parents:
diff changeset
1651 return;
kono
parents:
diff changeset
1652 end if;
kono
parents:
diff changeset
1653
kono
parents:
diff changeset
1654 -- Convert explicit raise of Program_Error, Constraint_Error, and
kono
parents:
diff changeset
1655 -- Storage_Error into the corresponding raise (in High_Integrity_Mode
kono
parents:
diff changeset
1656 -- all other raises will get normal expansion and be disallowed,
kono
parents:
diff changeset
1657 -- but this is also faster in all modes). Propagate Comes_From_Source
kono
parents:
diff changeset
1658 -- flag to the new node.
kono
parents:
diff changeset
1659
kono
parents:
diff changeset
1660 if Present (Name (N)) and then Nkind (Name (N)) = N_Identifier then
kono
parents:
diff changeset
1661 Src := Comes_From_Source (N);
kono
parents:
diff changeset
1662
kono
parents:
diff changeset
1663 if Entity (Name (N)) = Standard_Constraint_Error then
kono
parents:
diff changeset
1664 Rewrite (N,
kono
parents:
diff changeset
1665 Make_Raise_Constraint_Error (Loc, Reason => CE_Explicit_Raise));
kono
parents:
diff changeset
1666 Set_Comes_From_Source (N, Src);
kono
parents:
diff changeset
1667 Analyze (N);
kono
parents:
diff changeset
1668 return;
kono
parents:
diff changeset
1669
kono
parents:
diff changeset
1670 elsif Entity (Name (N)) = Standard_Program_Error then
kono
parents:
diff changeset
1671 Rewrite (N,
kono
parents:
diff changeset
1672 Make_Raise_Program_Error (Loc, Reason => PE_Explicit_Raise));
kono
parents:
diff changeset
1673 Set_Comes_From_Source (N, Src);
kono
parents:
diff changeset
1674 Analyze (N);
kono
parents:
diff changeset
1675 return;
kono
parents:
diff changeset
1676
kono
parents:
diff changeset
1677 elsif Entity (Name (N)) = Standard_Storage_Error then
kono
parents:
diff changeset
1678 Rewrite (N,
kono
parents:
diff changeset
1679 Make_Raise_Storage_Error (Loc, Reason => SE_Explicit_Raise));
kono
parents:
diff changeset
1680 Set_Comes_From_Source (N, Src);
kono
parents:
diff changeset
1681 Analyze (N);
kono
parents:
diff changeset
1682 return;
kono
parents:
diff changeset
1683 end if;
kono
parents:
diff changeset
1684 end if;
kono
parents:
diff changeset
1685
kono
parents:
diff changeset
1686 -- Case of name present, in this case we expand raise name to
kono
parents:
diff changeset
1687
kono
parents:
diff changeset
1688 -- Raise_Exception (name'Identity, location_string);
kono
parents:
diff changeset
1689
kono
parents:
diff changeset
1690 -- where location_string identifies the file/line of the raise
kono
parents:
diff changeset
1691
kono
parents:
diff changeset
1692 if Present (Name (N)) then
kono
parents:
diff changeset
1693 declare
kono
parents:
diff changeset
1694 Id : Entity_Id := Entity (Name (N));
kono
parents:
diff changeset
1695 Buf : Bounded_String;
kono
parents:
diff changeset
1696
kono
parents:
diff changeset
1697 begin
kono
parents:
diff changeset
1698 Build_Location_String (Buf, Loc);
kono
parents:
diff changeset
1699
kono
parents:
diff changeset
1700 -- If the exception is a renaming, use the exception that it
kono
parents:
diff changeset
1701 -- renames (which might be a predefined exception, e.g.).
kono
parents:
diff changeset
1702
kono
parents:
diff changeset
1703 if Present (Renamed_Object (Id)) then
kono
parents:
diff changeset
1704 Id := Renamed_Object (Id);
kono
parents:
diff changeset
1705 end if;
kono
parents:
diff changeset
1706
kono
parents:
diff changeset
1707 -- Build a C-compatible string in case of no exception handlers,
kono
parents:
diff changeset
1708 -- since this is what the last chance handler is expecting.
kono
parents:
diff changeset
1709
kono
parents:
diff changeset
1710 if No_Exception_Handlers_Set then
kono
parents:
diff changeset
1711
kono
parents:
diff changeset
1712 -- Generate an empty message if configuration pragma
kono
parents:
diff changeset
1713 -- Suppress_Exception_Locations is set for this unit.
kono
parents:
diff changeset
1714
kono
parents:
diff changeset
1715 if Opt.Exception_Locations_Suppressed then
kono
parents:
diff changeset
1716 Buf.Length := 0;
kono
parents:
diff changeset
1717 end if;
kono
parents:
diff changeset
1718
kono
parents:
diff changeset
1719 Append (Buf, ASCII.NUL);
kono
parents:
diff changeset
1720 end if;
kono
parents:
diff changeset
1721
kono
parents:
diff changeset
1722 if Opt.Exception_Locations_Suppressed then
kono
parents:
diff changeset
1723 Buf.Length := 0;
kono
parents:
diff changeset
1724 end if;
kono
parents:
diff changeset
1725
kono
parents:
diff changeset
1726 Str := String_From_Name_Buffer (Buf);
kono
parents:
diff changeset
1727
kono
parents:
diff changeset
1728 -- Convert raise to call to the Raise_Exception routine
kono
parents:
diff changeset
1729
kono
parents:
diff changeset
1730 Rewrite (N,
kono
parents:
diff changeset
1731 Make_Procedure_Call_Statement (Loc,
kono
parents:
diff changeset
1732 Name =>
kono
parents:
diff changeset
1733 New_Occurrence_Of (RTE (RE_Raise_Exception), Loc),
kono
parents:
diff changeset
1734 Parameter_Associations => New_List (
kono
parents:
diff changeset
1735 Make_Attribute_Reference (Loc,
kono
parents:
diff changeset
1736 Prefix => Name (N),
kono
parents:
diff changeset
1737 Attribute_Name => Name_Identity),
kono
parents:
diff changeset
1738 Make_String_Literal (Loc, Strval => Str))));
kono
parents:
diff changeset
1739 end;
kono
parents:
diff changeset
1740
kono
parents:
diff changeset
1741 -- Case of no name present (reraise). We rewrite the raise to:
kono
parents:
diff changeset
1742
kono
parents:
diff changeset
1743 -- Reraise_Occurrence_Always (EO);
kono
parents:
diff changeset
1744
kono
parents:
diff changeset
1745 -- where EO is the current exception occurrence. If the current handler
kono
parents:
diff changeset
1746 -- does not have a choice parameter specification, then we provide one.
kono
parents:
diff changeset
1747
kono
parents:
diff changeset
1748 else
kono
parents:
diff changeset
1749 -- Bypass expansion to a run-time call when back-end exception
kono
parents:
diff changeset
1750 -- handling is active, unless the target is CodePeer or GNATprove.
kono
parents:
diff changeset
1751 -- In CodePeer, raising an exception is treated as an error, while in
kono
parents:
diff changeset
1752 -- GNATprove all code with exceptions falls outside the subset of
kono
parents:
diff changeset
1753 -- code which can be formally analyzed.
kono
parents:
diff changeset
1754
kono
parents:
diff changeset
1755 if not CodePeer_Mode
kono
parents:
diff changeset
1756 and then Back_End_Exceptions
kono
parents:
diff changeset
1757 then
kono
parents:
diff changeset
1758 return;
kono
parents:
diff changeset
1759 end if;
kono
parents:
diff changeset
1760
kono
parents:
diff changeset
1761 -- Find innermost enclosing exception handler (there must be one,
kono
parents:
diff changeset
1762 -- since the semantics has already verified that this raise statement
kono
parents:
diff changeset
1763 -- is valid, and a raise with no arguments is only permitted in the
kono
parents:
diff changeset
1764 -- context of an exception handler.
kono
parents:
diff changeset
1765
kono
parents:
diff changeset
1766 Ehand := Parent (N);
kono
parents:
diff changeset
1767 while Nkind (Ehand) /= N_Exception_Handler loop
kono
parents:
diff changeset
1768 Ehand := Parent (Ehand);
kono
parents:
diff changeset
1769 end loop;
kono
parents:
diff changeset
1770
kono
parents:
diff changeset
1771 -- Make exception choice parameter if none present. Note that we do
kono
parents:
diff changeset
1772 -- not need to put the entity on the entity chain, since no one will
kono
parents:
diff changeset
1773 -- be referencing this entity by normal visibility methods.
kono
parents:
diff changeset
1774
kono
parents:
diff changeset
1775 if No (Choice_Parameter (Ehand)) then
kono
parents:
diff changeset
1776 E := Make_Temporary (Loc, 'E');
kono
parents:
diff changeset
1777 Set_Choice_Parameter (Ehand, E);
kono
parents:
diff changeset
1778 Set_Ekind (E, E_Variable);
kono
parents:
diff changeset
1779 Set_Etype (E, RTE (RE_Exception_Occurrence));
kono
parents:
diff changeset
1780 Set_Scope (E, Current_Scope);
kono
parents:
diff changeset
1781 end if;
kono
parents:
diff changeset
1782
kono
parents:
diff changeset
1783 -- Now rewrite the raise as a call to Reraise. A special case arises
kono
parents:
diff changeset
1784 -- if this raise statement occurs in the context of a handler for
kono
parents:
diff changeset
1785 -- all others (i.e. an at end handler). in this case we avoid
kono
parents:
diff changeset
1786 -- the call to defer abort, cleanup routines are expected to be
kono
parents:
diff changeset
1787 -- called in this case with aborts deferred.
kono
parents:
diff changeset
1788
kono
parents:
diff changeset
1789 declare
kono
parents:
diff changeset
1790 Ech : constant Node_Id := First (Exception_Choices (Ehand));
kono
parents:
diff changeset
1791 Ent : Entity_Id;
kono
parents:
diff changeset
1792
kono
parents:
diff changeset
1793 begin
kono
parents:
diff changeset
1794 if Nkind (Ech) = N_Others_Choice
kono
parents:
diff changeset
1795 and then All_Others (Ech)
kono
parents:
diff changeset
1796 then
kono
parents:
diff changeset
1797 Ent := RTE (RE_Reraise_Occurrence_No_Defer);
kono
parents:
diff changeset
1798 else
kono
parents:
diff changeset
1799 Ent := RTE (RE_Reraise_Occurrence_Always);
kono
parents:
diff changeset
1800 end if;
kono
parents:
diff changeset
1801
kono
parents:
diff changeset
1802 Rewrite (N,
kono
parents:
diff changeset
1803 Make_Procedure_Call_Statement (Loc,
kono
parents:
diff changeset
1804 Name => New_Occurrence_Of (Ent, Loc),
kono
parents:
diff changeset
1805 Parameter_Associations => New_List (
kono
parents:
diff changeset
1806 New_Occurrence_Of (Choice_Parameter (Ehand), Loc))));
kono
parents:
diff changeset
1807 end;
kono
parents:
diff changeset
1808 end if;
kono
parents:
diff changeset
1809
kono
parents:
diff changeset
1810 Analyze (N);
kono
parents:
diff changeset
1811 end Expand_N_Raise_Statement;
kono
parents:
diff changeset
1812
kono
parents:
diff changeset
1813 ----------------------------------
kono
parents:
diff changeset
1814 -- Expand_N_Raise_Storage_Error --
kono
parents:
diff changeset
1815 ----------------------------------
kono
parents:
diff changeset
1816
kono
parents:
diff changeset
1817 procedure Expand_N_Raise_Storage_Error (N : Node_Id) is
kono
parents:
diff changeset
1818 begin
kono
parents:
diff changeset
1819 -- We adjust the condition to deal with the C/Fortran boolean case. This
kono
parents:
diff changeset
1820 -- may well not be necessary, as all such conditions are generated by
kono
parents:
diff changeset
1821 -- the expander and probably are all standard boolean, but who knows
kono
parents:
diff changeset
1822 -- what strange optimization in future may require this adjustment.
kono
parents:
diff changeset
1823
kono
parents:
diff changeset
1824 Adjust_Condition (Condition (N));
kono
parents:
diff changeset
1825
kono
parents:
diff changeset
1826 -- Now deal with possible local raise handling
kono
parents:
diff changeset
1827
kono
parents:
diff changeset
1828 Possible_Local_Raise (N, Standard_Storage_Error);
kono
parents:
diff changeset
1829 end Expand_N_Raise_Storage_Error;
kono
parents:
diff changeset
1830
kono
parents:
diff changeset
1831 --------------------------
kono
parents:
diff changeset
1832 -- Possible_Local_Raise --
kono
parents:
diff changeset
1833 --------------------------
kono
parents:
diff changeset
1834
kono
parents:
diff changeset
1835 procedure Possible_Local_Raise (N : Node_Id; E : Entity_Id) is
kono
parents:
diff changeset
1836 begin
kono
parents:
diff changeset
1837 -- Nothing to do if local raise optimization not active
kono
parents:
diff changeset
1838
kono
parents:
diff changeset
1839 if not Debug_Flag_Dot_G
kono
parents:
diff changeset
1840 and then not Restriction_Active (No_Exception_Propagation)
kono
parents:
diff changeset
1841 then
kono
parents:
diff changeset
1842 return;
kono
parents:
diff changeset
1843 end if;
kono
parents:
diff changeset
1844
kono
parents:
diff changeset
1845 -- Nothing to do if original node was an explicit raise, because in
kono
parents:
diff changeset
1846 -- that case, we already generated the required warning for the raise.
kono
parents:
diff changeset
1847
kono
parents:
diff changeset
1848 if Nkind (Original_Node (N)) = N_Raise_Statement then
kono
parents:
diff changeset
1849 return;
kono
parents:
diff changeset
1850 end if;
kono
parents:
diff changeset
1851
kono
parents:
diff changeset
1852 -- Otherwise see if we have a local handler for the exception
kono
parents:
diff changeset
1853
kono
parents:
diff changeset
1854 declare
kono
parents:
diff changeset
1855 H : constant Node_Id := Find_Local_Handler (E, N);
kono
parents:
diff changeset
1856
kono
parents:
diff changeset
1857 begin
kono
parents:
diff changeset
1858 -- If so, mark that it has a local raise
kono
parents:
diff changeset
1859
kono
parents:
diff changeset
1860 if Present (H) then
kono
parents:
diff changeset
1861 Set_Has_Local_Raise (H, True);
kono
parents:
diff changeset
1862
kono
parents:
diff changeset
1863 -- Otherwise, if the No_Exception_Propagation restriction is active
kono
parents:
diff changeset
1864 -- and the warning is enabled, generate the appropriate warnings.
kono
parents:
diff changeset
1865
kono
parents:
diff changeset
1866 -- ??? Do not do it for the Call_Marker nodes inserted by the ABE
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1867 -- mechanism because this generates too many false positives, or
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1868 -- for generic instantiations for the same reason.
111
kono
parents:
diff changeset
1869
kono
parents:
diff changeset
1870 elsif Warn_On_Non_Local_Exception
kono
parents:
diff changeset
1871 and then Restriction_Active (No_Exception_Propagation)
kono
parents:
diff changeset
1872 and then Nkind (N) /= N_Call_Marker
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1873 and then Nkind (N) not in N_Generic_Instantiation
111
kono
parents:
diff changeset
1874 then
kono
parents:
diff changeset
1875 Warn_No_Exception_Propagation_Active (N);
kono
parents:
diff changeset
1876
kono
parents:
diff changeset
1877 if Configurable_Run_Time_Mode then
kono
parents:
diff changeset
1878 Error_Msg_NE
kono
parents:
diff changeset
1879 ("\?X?& may call Last_Chance_Handler", N, E);
kono
parents:
diff changeset
1880 else
kono
parents:
diff changeset
1881 Error_Msg_NE
kono
parents:
diff changeset
1882 ("\?X?& may result in unhandled exception", N, E);
kono
parents:
diff changeset
1883 end if;
kono
parents:
diff changeset
1884 end if;
kono
parents:
diff changeset
1885 end;
kono
parents:
diff changeset
1886 end Possible_Local_Raise;
kono
parents:
diff changeset
1887
kono
parents:
diff changeset
1888 ------------------------
kono
parents:
diff changeset
1889 -- Find_Local_Handler --
kono
parents:
diff changeset
1890 ------------------------
kono
parents:
diff changeset
1891
kono
parents:
diff changeset
1892 function Find_Local_Handler
kono
parents:
diff changeset
1893 (Ename : Entity_Id;
kono
parents:
diff changeset
1894 Nod : Node_Id) return Node_Id
kono
parents:
diff changeset
1895 is
kono
parents:
diff changeset
1896 N : Node_Id;
kono
parents:
diff changeset
1897 P : Node_Id;
kono
parents:
diff changeset
1898 H : Node_Id;
kono
parents:
diff changeset
1899 C : Node_Id;
kono
parents:
diff changeset
1900
kono
parents:
diff changeset
1901 SSE : Scope_Stack_Entry renames Scope_Stack.Table (Scope_Stack.Last);
kono
parents:
diff changeset
1902 -- This is used to test for wrapped actions below
kono
parents:
diff changeset
1903
kono
parents:
diff changeset
1904 ERaise : Entity_Id;
kono
parents:
diff changeset
1905 EHandle : Entity_Id;
kono
parents:
diff changeset
1906 -- The entity Id's for the exception we are raising and handling, using
kono
parents:
diff changeset
1907 -- the renamed exception if a Renamed_Entity is present.
kono
parents:
diff changeset
1908
kono
parents:
diff changeset
1909 begin
kono
parents:
diff changeset
1910 -- Never any local handler if all handlers removed
kono
parents:
diff changeset
1911
kono
parents:
diff changeset
1912 if Debug_Flag_Dot_X then
kono
parents:
diff changeset
1913 return Empty;
kono
parents:
diff changeset
1914 end if;
kono
parents:
diff changeset
1915
kono
parents:
diff changeset
1916 -- Get the exception we are raising, allowing for renaming
kono
parents:
diff changeset
1917
kono
parents:
diff changeset
1918 ERaise := Get_Renamed_Entity (Ename);
kono
parents:
diff changeset
1919
kono
parents:
diff changeset
1920 -- We need to check if the node we are looking at is contained in
kono
parents:
diff changeset
1921 --
kono
parents:
diff changeset
1922
kono
parents:
diff changeset
1923 -- Loop to search up the tree
kono
parents:
diff changeset
1924
kono
parents:
diff changeset
1925 N := Nod;
kono
parents:
diff changeset
1926 loop
kono
parents:
diff changeset
1927 P := Parent (N);
kono
parents:
diff changeset
1928
kono
parents:
diff changeset
1929 -- If we get to the top of the tree, or to a subprogram, task, entry,
kono
parents:
diff changeset
1930 -- protected body, or accept statement without having found a
kono
parents:
diff changeset
1931 -- matching handler, then there is no local handler.
kono
parents:
diff changeset
1932
kono
parents:
diff changeset
1933 if No (P)
kono
parents:
diff changeset
1934 or else Nkind (P) = N_Subprogram_Body
kono
parents:
diff changeset
1935 or else Nkind (P) = N_Task_Body
kono
parents:
diff changeset
1936 or else Nkind (P) = N_Protected_Body
kono
parents:
diff changeset
1937 or else Nkind (P) = N_Entry_Body
kono
parents:
diff changeset
1938 or else Nkind (P) = N_Accept_Statement
kono
parents:
diff changeset
1939 then
kono
parents:
diff changeset
1940 return Empty;
kono
parents:
diff changeset
1941
kono
parents:
diff changeset
1942 -- Test for handled sequence of statements with at least one
kono
parents:
diff changeset
1943 -- exception handler which might be the one we are looking for.
kono
parents:
diff changeset
1944
kono
parents:
diff changeset
1945 elsif Nkind (P) = N_Handled_Sequence_Of_Statements
kono
parents:
diff changeset
1946 and then Present (Exception_Handlers (P))
kono
parents:
diff changeset
1947 then
kono
parents:
diff changeset
1948 -- Before we proceed we need to check if the node N is covered
kono
parents:
diff changeset
1949 -- by the statement part of P rather than one of its exception
kono
parents:
diff changeset
1950 -- handlers (an exception handler obviously does not cover its
kono
parents:
diff changeset
1951 -- own statements).
kono
parents:
diff changeset
1952
kono
parents:
diff changeset
1953 -- This test is more delicate than might be thought. It is not
kono
parents:
diff changeset
1954 -- just a matter of checking the Statements (P), because the node
kono
parents:
diff changeset
1955 -- might be waiting to be wrapped in a transient scope, in which
kono
parents:
diff changeset
1956 -- case it will end up in the block statements, even though it
kono
parents:
diff changeset
1957 -- is not there now.
kono
parents:
diff changeset
1958
kono
parents:
diff changeset
1959 if Is_List_Member (N) then
kono
parents:
diff changeset
1960 declare
kono
parents:
diff changeset
1961 LCN : constant List_Id := List_Containing (N);
kono
parents:
diff changeset
1962
kono
parents:
diff changeset
1963 begin
kono
parents:
diff changeset
1964 if LCN = Statements (P)
kono
parents:
diff changeset
1965 or else
kono
parents:
diff changeset
1966 LCN = SSE.Actions_To_Be_Wrapped (Before)
kono
parents:
diff changeset
1967 or else
kono
parents:
diff changeset
1968 LCN = SSE.Actions_To_Be_Wrapped (After)
kono
parents:
diff changeset
1969 or else
kono
parents:
diff changeset
1970 LCN = SSE.Actions_To_Be_Wrapped (Cleanup)
kono
parents:
diff changeset
1971 then
kono
parents:
diff changeset
1972 -- Loop through exception handlers
kono
parents:
diff changeset
1973
kono
parents:
diff changeset
1974 H := First (Exception_Handlers (P));
kono
parents:
diff changeset
1975 while Present (H) loop
kono
parents:
diff changeset
1976
kono
parents:
diff changeset
1977 -- Guard against other constructs appearing in the
kono
parents:
diff changeset
1978 -- list of exception handlers.
kono
parents:
diff changeset
1979
kono
parents:
diff changeset
1980 if Nkind (H) = N_Exception_Handler then
kono
parents:
diff changeset
1981
kono
parents:
diff changeset
1982 -- Loop through choices in one handler
kono
parents:
diff changeset
1983
kono
parents:
diff changeset
1984 C := First (Exception_Choices (H));
kono
parents:
diff changeset
1985 while Present (C) loop
kono
parents:
diff changeset
1986
kono
parents:
diff changeset
1987 -- Deal with others case
kono
parents:
diff changeset
1988
kono
parents:
diff changeset
1989 if Nkind (C) = N_Others_Choice then
kono
parents:
diff changeset
1990
kono
parents:
diff changeset
1991 -- Matching others handler, but we need
kono
parents:
diff changeset
1992 -- to ensure there is no choice parameter.
kono
parents:
diff changeset
1993 -- If there is, then we don't have a local
kono
parents:
diff changeset
1994 -- handler after all (since we do not allow
kono
parents:
diff changeset
1995 -- choice parameters for local handlers).
kono
parents:
diff changeset
1996
kono
parents:
diff changeset
1997 if No (Choice_Parameter (H)) then
kono
parents:
diff changeset
1998 return H;
kono
parents:
diff changeset
1999 else
kono
parents:
diff changeset
2000 return Empty;
kono
parents:
diff changeset
2001 end if;
kono
parents:
diff changeset
2002
kono
parents:
diff changeset
2003 -- If not others must be entity name
kono
parents:
diff changeset
2004
kono
parents:
diff changeset
2005 elsif Nkind (C) /= N_Others_Choice then
kono
parents:
diff changeset
2006 pragma Assert (Is_Entity_Name (C));
kono
parents:
diff changeset
2007 pragma Assert (Present (Entity (C)));
kono
parents:
diff changeset
2008
kono
parents:
diff changeset
2009 -- Get exception being handled, dealing with
kono
parents:
diff changeset
2010 -- renaming.
kono
parents:
diff changeset
2011
kono
parents:
diff changeset
2012 EHandle := Get_Renamed_Entity (Entity (C));
kono
parents:
diff changeset
2013
kono
parents:
diff changeset
2014 -- If match, then check choice parameter
kono
parents:
diff changeset
2015
kono
parents:
diff changeset
2016 if ERaise = EHandle then
kono
parents:
diff changeset
2017 if No (Choice_Parameter (H)) then
kono
parents:
diff changeset
2018 return H;
kono
parents:
diff changeset
2019 else
kono
parents:
diff changeset
2020 return Empty;
kono
parents:
diff changeset
2021 end if;
kono
parents:
diff changeset
2022 end if;
kono
parents:
diff changeset
2023 end if;
kono
parents:
diff changeset
2024
kono
parents:
diff changeset
2025 Next (C);
kono
parents:
diff changeset
2026 end loop;
kono
parents:
diff changeset
2027 end if;
kono
parents:
diff changeset
2028
kono
parents:
diff changeset
2029 Next (H);
kono
parents:
diff changeset
2030 end loop;
kono
parents:
diff changeset
2031 end if;
kono
parents:
diff changeset
2032 end;
kono
parents:
diff changeset
2033 end if;
kono
parents:
diff changeset
2034 end if;
kono
parents:
diff changeset
2035
kono
parents:
diff changeset
2036 N := P;
kono
parents:
diff changeset
2037 end loop;
kono
parents:
diff changeset
2038 end Find_Local_Handler;
kono
parents:
diff changeset
2039
kono
parents:
diff changeset
2040 ---------------------------------
kono
parents:
diff changeset
2041 -- Get_Local_Raise_Call_Entity --
kono
parents:
diff changeset
2042 ---------------------------------
kono
parents:
diff changeset
2043
kono
parents:
diff changeset
2044 -- Note: this is primarily provided for use by the back end in generating
kono
parents:
diff changeset
2045 -- calls to Local_Raise. But it would be too late in the back end to call
kono
parents:
diff changeset
2046 -- RTE if this actually caused a load/analyze of the unit. So what we do
kono
parents:
diff changeset
2047 -- is to ensure there is a dummy call to this function during front end
kono
parents:
diff changeset
2048 -- processing so that the unit gets loaded then, and not later.
kono
parents:
diff changeset
2049
kono
parents:
diff changeset
2050 Local_Raise_Call_Entity : Entity_Id;
kono
parents:
diff changeset
2051 Local_Raise_Call_Entity_Set : Boolean := False;
kono
parents:
diff changeset
2052
kono
parents:
diff changeset
2053 function Get_Local_Raise_Call_Entity return Entity_Id is
kono
parents:
diff changeset
2054 begin
kono
parents:
diff changeset
2055 if not Local_Raise_Call_Entity_Set then
kono
parents:
diff changeset
2056 Local_Raise_Call_Entity_Set := True;
kono
parents:
diff changeset
2057
kono
parents:
diff changeset
2058 if RTE_Available (RE_Local_Raise) then
kono
parents:
diff changeset
2059 Local_Raise_Call_Entity := RTE (RE_Local_Raise);
kono
parents:
diff changeset
2060 else
kono
parents:
diff changeset
2061 Local_Raise_Call_Entity := Empty;
kono
parents:
diff changeset
2062 end if;
kono
parents:
diff changeset
2063 end if;
kono
parents:
diff changeset
2064
kono
parents:
diff changeset
2065 return Local_Raise_Call_Entity;
kono
parents:
diff changeset
2066 end Get_Local_Raise_Call_Entity;
kono
parents:
diff changeset
2067
kono
parents:
diff changeset
2068 -----------------------------
kono
parents:
diff changeset
2069 -- Get_RT_Exception_Entity --
kono
parents:
diff changeset
2070 -----------------------------
kono
parents:
diff changeset
2071
kono
parents:
diff changeset
2072 function Get_RT_Exception_Entity (R : RT_Exception_Code) return Entity_Id is
kono
parents:
diff changeset
2073 begin
kono
parents:
diff changeset
2074 case Rkind (R) is
kono
parents:
diff changeset
2075 when CE_Reason => return Standard_Constraint_Error;
kono
parents:
diff changeset
2076 when PE_Reason => return Standard_Program_Error;
kono
parents:
diff changeset
2077 when SE_Reason => return Standard_Storage_Error;
kono
parents:
diff changeset
2078 end case;
kono
parents:
diff changeset
2079 end Get_RT_Exception_Entity;
kono
parents:
diff changeset
2080
kono
parents:
diff changeset
2081 ---------------------------
kono
parents:
diff changeset
2082 -- Get_RT_Exception_Name --
kono
parents:
diff changeset
2083 ---------------------------
kono
parents:
diff changeset
2084
kono
parents:
diff changeset
2085 procedure Get_RT_Exception_Name (Code : RT_Exception_Code) is
kono
parents:
diff changeset
2086 begin
kono
parents:
diff changeset
2087 case Code is
kono
parents:
diff changeset
2088 when CE_Access_Check_Failed =>
kono
parents:
diff changeset
2089 Add_Str_To_Name_Buffer ("CE_Access_Check");
kono
parents:
diff changeset
2090 when CE_Access_Parameter_Is_Null =>
kono
parents:
diff changeset
2091 Add_Str_To_Name_Buffer ("CE_Null_Access_Parameter");
kono
parents:
diff changeset
2092 when CE_Discriminant_Check_Failed =>
kono
parents:
diff changeset
2093 Add_Str_To_Name_Buffer ("CE_Discriminant_Check");
kono
parents:
diff changeset
2094 when CE_Divide_By_Zero =>
kono
parents:
diff changeset
2095 Add_Str_To_Name_Buffer ("CE_Divide_By_Zero");
kono
parents:
diff changeset
2096 when CE_Explicit_Raise =>
kono
parents:
diff changeset
2097 Add_Str_To_Name_Buffer ("CE_Explicit_Raise");
kono
parents:
diff changeset
2098 when CE_Index_Check_Failed =>
kono
parents:
diff changeset
2099 Add_Str_To_Name_Buffer ("CE_Index_Check");
kono
parents:
diff changeset
2100 when CE_Invalid_Data =>
kono
parents:
diff changeset
2101 Add_Str_To_Name_Buffer ("CE_Invalid_Data");
kono
parents:
diff changeset
2102 when CE_Length_Check_Failed =>
kono
parents:
diff changeset
2103 Add_Str_To_Name_Buffer ("CE_Length_Check");
kono
parents:
diff changeset
2104 when CE_Null_Exception_Id =>
kono
parents:
diff changeset
2105 Add_Str_To_Name_Buffer ("CE_Null_Exception_Id");
kono
parents:
diff changeset
2106 when CE_Null_Not_Allowed =>
kono
parents:
diff changeset
2107 Add_Str_To_Name_Buffer ("CE_Null_Not_Allowed");
kono
parents:
diff changeset
2108 when CE_Overflow_Check_Failed =>
kono
parents:
diff changeset
2109 Add_Str_To_Name_Buffer ("CE_Overflow_Check");
kono
parents:
diff changeset
2110 when CE_Partition_Check_Failed =>
kono
parents:
diff changeset
2111 Add_Str_To_Name_Buffer ("CE_Partition_Check");
kono
parents:
diff changeset
2112 when CE_Range_Check_Failed =>
kono
parents:
diff changeset
2113 Add_Str_To_Name_Buffer ("CE_Range_Check");
kono
parents:
diff changeset
2114 when CE_Tag_Check_Failed =>
kono
parents:
diff changeset
2115 Add_Str_To_Name_Buffer ("CE_Tag_Check");
kono
parents:
diff changeset
2116
kono
parents:
diff changeset
2117 when PE_Access_Before_Elaboration =>
kono
parents:
diff changeset
2118 Add_Str_To_Name_Buffer ("PE_Access_Before_Elaboration");
kono
parents:
diff changeset
2119 when PE_Accessibility_Check_Failed =>
kono
parents:
diff changeset
2120 Add_Str_To_Name_Buffer ("PE_Accessibility_Check");
kono
parents:
diff changeset
2121 when PE_Address_Of_Intrinsic =>
kono
parents:
diff changeset
2122 Add_Str_To_Name_Buffer ("PE_Address_Of_Intrinsic");
kono
parents:
diff changeset
2123 when PE_Aliased_Parameters =>
kono
parents:
diff changeset
2124 Add_Str_To_Name_Buffer ("PE_Aliased_Parameters");
kono
parents:
diff changeset
2125 when PE_All_Guards_Closed =>
kono
parents:
diff changeset
2126 Add_Str_To_Name_Buffer ("PE_All_Guards_Closed");
kono
parents:
diff changeset
2127 when PE_Bad_Predicated_Generic_Type =>
kono
parents:
diff changeset
2128 Add_Str_To_Name_Buffer ("PE_Bad_Predicated_Generic_Type");
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2129 when PE_Build_In_Place_Mismatch =>
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2130 Add_Str_To_Name_Buffer ("PE_Build_In_Place_Mismatch");
111
kono
parents:
diff changeset
2131 when PE_Current_Task_In_Entry_Body =>
kono
parents:
diff changeset
2132 Add_Str_To_Name_Buffer ("PE_Current_Task_In_Entry_Body");
kono
parents:
diff changeset
2133 when PE_Duplicated_Entry_Address =>
kono
parents:
diff changeset
2134 Add_Str_To_Name_Buffer ("PE_Duplicated_Entry_Address");
kono
parents:
diff changeset
2135 when PE_Explicit_Raise =>
kono
parents:
diff changeset
2136 Add_Str_To_Name_Buffer ("PE_Explicit_Raise");
kono
parents:
diff changeset
2137 when PE_Finalize_Raised_Exception =>
kono
parents:
diff changeset
2138 Add_Str_To_Name_Buffer ("PE_Finalize_Raised_Exception");
kono
parents:
diff changeset
2139 when PE_Implicit_Return =>
kono
parents:
diff changeset
2140 Add_Str_To_Name_Buffer ("PE_Implicit_Return");
kono
parents:
diff changeset
2141 when PE_Misaligned_Address_Value =>
kono
parents:
diff changeset
2142 Add_Str_To_Name_Buffer ("PE_Misaligned_Address_Value");
kono
parents:
diff changeset
2143 when PE_Missing_Return =>
kono
parents:
diff changeset
2144 Add_Str_To_Name_Buffer ("PE_Missing_Return");
kono
parents:
diff changeset
2145 when PE_Non_Transportable_Actual =>
kono
parents:
diff changeset
2146 Add_Str_To_Name_Buffer ("PE_Non_Transportable_Actual");
kono
parents:
diff changeset
2147 when PE_Overlaid_Controlled_Object =>
kono
parents:
diff changeset
2148 Add_Str_To_Name_Buffer ("PE_Overlaid_Controlled_Object");
kono
parents:
diff changeset
2149 when PE_Potentially_Blocking_Operation =>
kono
parents:
diff changeset
2150 Add_Str_To_Name_Buffer ("PE_Potentially_Blocking_Operation");
kono
parents:
diff changeset
2151 when PE_Stream_Operation_Not_Allowed =>
kono
parents:
diff changeset
2152 Add_Str_To_Name_Buffer ("PE_Stream_Operation_Not_Allowed");
kono
parents:
diff changeset
2153 when PE_Stubbed_Subprogram_Called =>
kono
parents:
diff changeset
2154 Add_Str_To_Name_Buffer ("PE_Stubbed_Subprogram_Called");
kono
parents:
diff changeset
2155 when PE_Unchecked_Union_Restriction =>
kono
parents:
diff changeset
2156 Add_Str_To_Name_Buffer ("PE_Unchecked_Union_Restriction");
kono
parents:
diff changeset
2157
kono
parents:
diff changeset
2158 when SE_Empty_Storage_Pool =>
kono
parents:
diff changeset
2159 Add_Str_To_Name_Buffer ("SE_Empty_Storage_Pool");
kono
parents:
diff changeset
2160 when SE_Explicit_Raise =>
kono
parents:
diff changeset
2161 Add_Str_To_Name_Buffer ("SE_Explicit_Raise");
kono
parents:
diff changeset
2162 when SE_Infinite_Recursion =>
kono
parents:
diff changeset
2163 Add_Str_To_Name_Buffer ("SE_Infinite_Recursion");
kono
parents:
diff changeset
2164 when SE_Object_Too_Large =>
kono
parents:
diff changeset
2165 Add_Str_To_Name_Buffer ("SE_Object_Too_Large");
kono
parents:
diff changeset
2166 end case;
kono
parents:
diff changeset
2167 end Get_RT_Exception_Name;
kono
parents:
diff changeset
2168
kono
parents:
diff changeset
2169 ----------------------------
kono
parents:
diff changeset
2170 -- Warn_If_No_Local_Raise --
kono
parents:
diff changeset
2171 ----------------------------
kono
parents:
diff changeset
2172
kono
parents:
diff changeset
2173 procedure Warn_If_No_Local_Raise (N : Node_Id) is
kono
parents:
diff changeset
2174 begin
kono
parents:
diff changeset
2175 if Restriction_Active (No_Exception_Propagation)
kono
parents:
diff changeset
2176 and then Warn_On_Non_Local_Exception
kono
parents:
diff changeset
2177 then
kono
parents:
diff changeset
2178 Warn_No_Exception_Propagation_Active (N);
kono
parents:
diff changeset
2179
kono
parents:
diff changeset
2180 Error_Msg_N
kono
parents:
diff changeset
2181 ("\?X?this handler can never be entered, and has been removed", N);
kono
parents:
diff changeset
2182 end if;
kono
parents:
diff changeset
2183 end Warn_If_No_Local_Raise;
kono
parents:
diff changeset
2184
kono
parents:
diff changeset
2185 ----------------------------
kono
parents:
diff changeset
2186 -- Warn_If_No_Propagation --
kono
parents:
diff changeset
2187 ----------------------------
kono
parents:
diff changeset
2188
kono
parents:
diff changeset
2189 procedure Warn_If_No_Propagation (N : Node_Id) is
kono
parents:
diff changeset
2190 begin
kono
parents:
diff changeset
2191 if Restriction_Check_Required (No_Exception_Propagation)
kono
parents:
diff changeset
2192 and then Warn_On_Non_Local_Exception
kono
parents:
diff changeset
2193 then
kono
parents:
diff changeset
2194 Warn_No_Exception_Propagation_Active (N);
kono
parents:
diff changeset
2195
kono
parents:
diff changeset
2196 if Configurable_Run_Time_Mode then
kono
parents:
diff changeset
2197 Error_Msg_N
kono
parents:
diff changeset
2198 ("\?X?Last_Chance_Handler will be called on exception", N);
kono
parents:
diff changeset
2199 else
kono
parents:
diff changeset
2200 Error_Msg_N
kono
parents:
diff changeset
2201 ("\?X?execution may raise unhandled exception", N);
kono
parents:
diff changeset
2202 end if;
kono
parents:
diff changeset
2203 end if;
kono
parents:
diff changeset
2204 end Warn_If_No_Propagation;
kono
parents:
diff changeset
2205
kono
parents:
diff changeset
2206 ------------------------------------------
kono
parents:
diff changeset
2207 -- Warn_No_Exception_Propagation_Active --
kono
parents:
diff changeset
2208 ------------------------------------------
kono
parents:
diff changeset
2209
kono
parents:
diff changeset
2210 procedure Warn_No_Exception_Propagation_Active (N : Node_Id) is
kono
parents:
diff changeset
2211 begin
kono
parents:
diff changeset
2212 Error_Msg_N
kono
parents:
diff changeset
2213 ("?X?pragma Restrictions (No_Exception_Propagation) in effect", N);
kono
parents:
diff changeset
2214 end Warn_No_Exception_Propagation_Active;
kono
parents:
diff changeset
2215
kono
parents:
diff changeset
2216 end Exp_Ch11;