OSDN Git Service

* tree-chrec.c (avoid_arithmetics_in_type_p): New.
[pf3gnuchains/gcc-fork.git] / gcc / ada / a-except.adb
1 ------------------------------------------------------------------------------
2 --                                                                          --
3 --                         GNAT COMPILER COMPONENTS                         --
4 --                                                                          --
5 --                       A D A . E X C E P T I O N S                        --
6 --                                                                          --
7 --                                 B o d y                                  --
8 --                                                                          --
9 --          Copyright (C) 1992-2006, Free Software Foundation, Inc.         --
10 --                                                                          --
11 -- GNAT is free software;  you can  redistribute it  and/or modify it under --
12 -- terms of the  GNU General Public License as published  by the Free Soft- --
13 -- ware  Foundation;  either version 2,  or (at your option) any later ver- --
14 -- sion.  GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY;  without even the  implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License --
17 -- for  more details.  You should have  received  a copy of the GNU General --
18 -- Public License  distributed with GNAT;  see file COPYING.  If not, write --
19 -- to  the  Free Software Foundation,  51  Franklin  Street,  Fifth  Floor, --
20 -- Boston, MA 02110-1301, USA.                                              --
21 --                                                                          --
22 -- As a special exception,  if other files  instantiate  generics from this --
23 -- unit, or you link  this unit with other files  to produce an executable, --
24 -- this  unit  does not  by itself cause  the resulting  executable  to  be --
25 -- covered  by the  GNU  General  Public  License.  This exception does not --
26 -- however invalidate  any other reasons why  the executable file  might be --
27 -- covered by the  GNU Public License.                                      --
28 --                                                                          --
29 -- GNAT was originally developed  by the GNAT team at  New York University. --
30 -- Extensive contributions were provided by Ada Core Technologies Inc.      --
31 --                                                                          --
32 ------------------------------------------------------------------------------
33
34 --  This version of Ada.Exceptions is a full Ada 95 version, but lacks the
35 --  additional definitions of Exception_Name returning Wide_[Wide_]String.
36 --  It is used for building the compiler and the basic tools, since these
37 --  builds may be done with bootstrap compilers that cannot handle these
38 --  additions. The full version of Ada.Exceptions can be found in the files
39 --  a-except-2005.ads/adb, and is used for all other builds where full Ada
40 --  2005 functionality is required. in particular, it is used for building
41 --  run times on all targets.
42
43 pragma Polling (Off);
44 --  We must turn polling off for this unit, because otherwise we get
45 --  elaboration circularities with System.Exception_Tables.
46
47 with System;                  use System;
48 with System.Standard_Library; use System.Standard_Library;
49 with System.Soft_Links;       use System.Soft_Links;
50
51 package body Ada.Exceptions is
52
53    pragma Suppress (All_Checks);
54    --  We definitely do not want exceptions occurring within this unit, or
55    --  we are in big trouble. If an exceptional situation does occur, better
56    --  that it not be raised, since raising it can cause confusing chaos.
57
58    -----------------------
59    -- Local Subprograms --
60    -----------------------
61
62    --  Note: the exported subprograms in this package body are called directly
63    --  from C clients using the given external name, even though they are not
64    --  technically visible in the Ada sense.
65
66    procedure Process_Raise_Exception (E : Exception_Id);
67    pragma No_Return (Process_Raise_Exception);
68    --  This is the lowest level raise routine. It raises the exception
69    --  referenced by Current_Excep.all in the TSD, without deferring abort
70    --  (the caller must ensure that abort is deferred on entry).
71
72    procedure To_Stderr (S : String);
73    pragma Export (Ada, To_Stderr, "__gnat_to_stderr");
74    --  Little routine to output string to stderr that is also used
75    --  in the tasking run time.
76
77    procedure To_Stderr (C : Character);
78    pragma Inline (To_Stderr);
79    pragma Export (Ada, To_Stderr, "__gnat_to_stderr_char");
80    --  Little routine to output a character to stderr, used by some of
81    --  the separate units below.
82
83    package Exception_Data is
84
85       ---------------------------------
86       -- Exception messages routines --
87       ---------------------------------
88
89       procedure Set_Exception_C_Msg
90         (Id   : Exception_Id;
91          Msg1 : System.Address;
92          Line : Integer        := 0;
93          Msg2 : System.Address := System.Null_Address);
94       --  This routine is called to setup the exception referenced by the
95       --  Current_Excep field in the TSD to contain the indicated Id value
96       --  and message. Msg1 is a null terminated string which is generated
97       --  as the exception message. If line is non-zero, then a colon and
98       --  the decimal representation of this integer is appended to the
99       --  message. When Msg2 is non-null, a space and this additional null
100       --  terminated string is added to the message.
101
102       procedure Set_Exception_Msg
103         (Id      : Exception_Id;
104          Message : String);
105       --  This routine is called to setup the exception referenced by the
106       --  Current_Excep field in the TSD to contain the indicated Id value
107       --  and message. Message is a string which is generated as the
108       --  exception message.
109
110       --------------------------------------
111       -- Exception information subprogram --
112       --------------------------------------
113
114       function Exception_Information (X : Exception_Occurrence) return String;
115       --  The format of the exception information is as follows:
116       --
117       --    Exception_Name: <exception name> (as in Exception_Name)
118       --    Message: <message> (only if Exception_Message is empty)
119       --    PID=nnnn (only if != 0)
120       --    Call stack traceback locations:  (only if at least one location)
121       --    <0xyyyyyyyy 0xyyyyyyyy ...>      (is recorded)
122       --
123       --  The lines are separated by a ASCII.LF character.
124       --  The nnnn is the partition Id given as decimal digits.
125       --  The 0x... line represents traceback program counter locations, in
126       --  execution order with the first one being the exception location. It
127       --  is present only
128       --
129       --  The Exception_Name and Message lines are omitted in the abort
130       --  signal case, since this is not really an exception.
131
132       --  !! If the format of the generated string is changed, please note
133       --  !! that an equivalent modification to the routine String_To_EO must
134       --  !! be made to preserve proper functioning of the stream attributes.
135
136       ---------------------------------------
137       -- Exception backtracing subprograms --
138       ---------------------------------------
139
140       --  What is automatically output when exception tracing is on is the
141       --  usual exception information with the call chain backtrace possibly
142       --  tailored by a backtrace decorator. Modifying Exception_Information
143       --  itself is not a good idea because the decorated output is completely
144       --  out of control and would break all our code related to the streaming
145       --  of exceptions.  We then provide an alternative function to compute
146       --  the possibly tailored output, which is equivalent if no decorator is
147       --  currently set:
148
149       function Tailored_Exception_Information
150         (X : Exception_Occurrence) return String;
151       --  Exception information to be output in the case of automatic tracing
152       --  requested through GNAT.Exception_Traces.
153       --
154       --  This is the same as Exception_Information if no backtrace decorator
155       --  is currently in place. Otherwise, this is Exception_Information with
156       --  the call chain raw addresses replaced by the result of a call to the
157       --  current decorator provided with the call chain addresses.
158
159       pragma Export
160         (Ada, Tailored_Exception_Information,
161            "__gnat_tailored_exception_information");
162       --  This is currently used by System.Tasking.Stages
163
164    end Exception_Data;
165
166    package Exception_Traces is
167
168       use Exception_Data;
169       --  Imports Tailored_Exception_Information
170
171       ----------------------------------------------
172       -- Run-Time Exception Notification Routines --
173       ----------------------------------------------
174
175       --  These subprograms provide a common run-time interface to trigger the
176       --  actions required when an exception is about to be propagated (e.g.
177       --  user specified actions or output of exception information). They are
178       --  exported to be usable by the Ada exception handling personality
179       --  routine when the GCC 3 mechanism is used.
180
181       procedure Notify_Handled_Exception;
182       pragma Export
183         (C, Notify_Handled_Exception, "__gnat_notify_handled_exception");
184       --  This routine is called for a handled occurrence is about to be
185       --  propagated.
186
187       procedure Notify_Unhandled_Exception;
188       pragma Export
189         (C, Notify_Unhandled_Exception, "__gnat_notify_unhandled_exception");
190       --  This routine is called when an unhandled occurrence is about to be
191       --  propagated.
192
193       procedure Unhandled_Exception_Terminate;
194       pragma No_Return (Unhandled_Exception_Terminate);
195       --  This procedure is called to terminate execution following an
196       --  unhandled exception. The exception information, including
197       --  traceback if available is output, and execution is then
198       --  terminated. Note that at the point where this routine is
199       --  called, the stack has typically been destroyed.
200
201    end Exception_Traces;
202
203    package Exception_Propagation is
204
205       procedure Setup_Exception
206         (Excep    : EOA;
207          Current  : EOA;
208          Reraised : Boolean := False);
209       --  Dummy routine used to share a-exexda.adb, do nothing.
210
211    end Exception_Propagation;
212
213    package Stream_Attributes is
214
215       --------------------------------
216       -- Stream attributes routines --
217       --------------------------------
218
219       function EId_To_String (X : Exception_Id) return String;
220       function String_To_EId (S : String) return Exception_Id;
221       --  Functions for implementing Exception_Id stream attributes
222
223       function EO_To_String (X : Exception_Occurrence) return String;
224       function String_To_EO (S : String) return Exception_Occurrence;
225       --  Functions for implementing Exception_Occurrence stream
226       --  attributes
227
228    end Stream_Attributes;
229
230    procedure Raise_Current_Excep (E : Exception_Id);
231    pragma No_Return (Raise_Current_Excep);
232    pragma Export (C, Raise_Current_Excep, "__gnat_raise_nodefer_with_msg");
233    --  This is a simple wrapper to Process_Raise_Exception.
234    --
235    --  This external name for Raise_Current_Excep is historical, and probably
236    --  should be changed but for now we keep it, because gdb and gigi know
237    --  about it.
238
239    procedure Raise_Exception_No_Defer
240       (E : Exception_Id; Message : String := "");
241    pragma Export
242     (Ada, Raise_Exception_No_Defer,
243      "ada__exceptions__raise_exception_no_defer");
244    pragma No_Return (Raise_Exception_No_Defer);
245    --  Similar to Raise_Exception, but with no abort deferral
246
247    procedure Raise_With_Msg (E : Exception_Id);
248    pragma No_Return (Raise_With_Msg);
249    pragma Export (C, Raise_With_Msg, "__gnat_raise_with_msg");
250    --  Raises an exception with given exception id value. A message
251    --  is associated with the raise, and has already been stored in the
252    --  exception occurrence referenced by the Current_Excep in the TSD.
253    --  Abort is deferred before the raise call.
254
255    procedure Raise_With_Location_And_Msg
256      (E : Exception_Id;
257       F : System.Address;
258       L : Integer;
259       M : System.Address := System.Null_Address);
260    pragma No_Return (Raise_With_Location_And_Msg);
261    --  Raise an exception with given exception id value. A filename and line
262    --  number is associated with the raise and is stored in the exception
263    --  occurrence and in addition a string message M is appended to
264    --  this (if M is not null).
265
266    procedure Raise_Constraint_Error
267      (File : System.Address;
268       Line : Integer);
269    pragma No_Return (Raise_Constraint_Error);
270    pragma Export
271      (C, Raise_Constraint_Error, "__gnat_raise_constraint_error");
272    --  Raise constraint error with file:line information
273
274    procedure Raise_Constraint_Error_Msg
275      (File : System.Address;
276       Line : Integer;
277       Msg  : System.Address);
278    pragma No_Return (Raise_Constraint_Error_Msg);
279    pragma Export
280      (C, Raise_Constraint_Error_Msg, "__gnat_raise_constraint_error_msg");
281    --  Raise constraint error with file:line + msg information
282
283    procedure Raise_Program_Error
284      (File : System.Address;
285       Line : Integer);
286    pragma No_Return (Raise_Program_Error);
287    pragma Export
288      (C, Raise_Program_Error, "__gnat_raise_program_error");
289    --  Raise program error with file:line information
290
291    procedure Raise_Program_Error_Msg
292      (File : System.Address;
293       Line : Integer;
294       Msg  : System.Address);
295    pragma No_Return (Raise_Program_Error_Msg);
296    pragma Export
297      (C, Raise_Program_Error_Msg, "__gnat_raise_program_error_msg");
298    --  Raise program error with file:line + msg information
299
300    procedure Raise_Storage_Error
301      (File : System.Address;
302       Line : Integer);
303    pragma No_Return (Raise_Storage_Error);
304    pragma Export
305      (C, Raise_Storage_Error, "__gnat_raise_storage_error");
306    --  Raise storage error with file:line information
307
308    procedure Raise_Storage_Error_Msg
309      (File : System.Address;
310       Line : Integer;
311       Msg  : System.Address);
312    pragma No_Return (Raise_Storage_Error_Msg);
313    pragma Export
314      (C, Raise_Storage_Error_Msg, "__gnat_raise_storage_error_msg");
315    --  Raise storage error with file:line + reason msg information
316
317    --  The exception raising process and the automatic tracing mechanism rely
318    --  on some careful use of flags attached to the exception occurrence. The
319    --  graph below illustrates the relations between the Raise_ subprograms
320    --  and identifies the points where basic flags such as Exception_Raised
321    --  are initialized.
322    --
323    --  (i) signs indicate the flags initialization points. R stands for Raise,
324    --  W for With, and E for Exception.
325    --
326    --                   R_No_Msg    R_E   R_Pe  R_Ce  R_Se
327    --                       |        |     |     |     |
328    --                       +--+  +--+     +---+ | +---+
329    --                          |  |            | | |
330    --     R_E_No_Defer(i)    R_W_Msg(i)       R_W_Loc
331    --           |               |              |   |
332    --           +------------+  |  +-----------+   +--+
333    --                        |  |  |                  |
334    --                        |  |  |             Set_E_C_Msg(i)
335    --                        |  |  |
336    --                   Raise_Current_Excep
337
338    procedure Reraise;
339    pragma No_Return (Reraise);
340    pragma Export (C, Reraise, "__gnat_reraise");
341    --  Reraises the exception referenced by the Current_Excep field of
342    --  the TSD (all fields of this exception occurrence are set). Abort
343    --  is deferred before the reraise operation.
344
345    --  Save_Occurrence variations: As the management of the private data
346    --  attached to occurrences is delicate, wether or not pointers to such
347    --  data has to be copied in various situations is better made explicit.
348    --  The following procedures provide an internal interface to help making
349    --  this explicit.
350
351    procedure Save_Occurrence_No_Private
352      (Target : out Exception_Occurrence;
353       Source : Exception_Occurrence);
354    --  Copy all the components of Source to Target, except the
355    --  Private_Data pointer.
356
357    procedure Transfer_Occurrence
358      (Target : Exception_Occurrence_Access;
359       Source : Exception_Occurrence);
360    pragma Export (C, Transfer_Occurrence, "__gnat_transfer_occurrence");
361    --  Called from System.Tasking.RendezVous.Exceptional_Complete_RendezVous
362    --  to setup Target from Source as an exception to be propagated in the
363    --  caller task. Target is expected to be a pointer to the fixed TSD
364    --  occurrence for this task.
365
366    -----------------------------
367    -- Run-Time Check Routines --
368    -----------------------------
369
370    --  These routines are called from the runtime to raise a specific
371    --  exception with a reason message attached. The parameters are
372    --  the file name and line number in each case. The names are keyed
373    --  to the codes defined in Types.ads and a-types.h (for example,
374    --  the name Rcheck_05 refers to the Reason whose Pos code is 5).
375
376    procedure Rcheck_00 (File : System.Address; Line : Integer);
377    procedure Rcheck_01 (File : System.Address; Line : Integer);
378    procedure Rcheck_02 (File : System.Address; Line : Integer);
379    procedure Rcheck_03 (File : System.Address; Line : Integer);
380    procedure Rcheck_04 (File : System.Address; Line : Integer);
381    procedure Rcheck_05 (File : System.Address; Line : Integer);
382    procedure Rcheck_06 (File : System.Address; Line : Integer);
383    procedure Rcheck_07 (File : System.Address; Line : Integer);
384    procedure Rcheck_08 (File : System.Address; Line : Integer);
385    procedure Rcheck_09 (File : System.Address; Line : Integer);
386    procedure Rcheck_10 (File : System.Address; Line : Integer);
387    procedure Rcheck_11 (File : System.Address; Line : Integer);
388    procedure Rcheck_12 (File : System.Address; Line : Integer);
389    procedure Rcheck_13 (File : System.Address; Line : Integer);
390    procedure Rcheck_14 (File : System.Address; Line : Integer);
391    procedure Rcheck_15 (File : System.Address; Line : Integer);
392    procedure Rcheck_16 (File : System.Address; Line : Integer);
393    procedure Rcheck_17 (File : System.Address; Line : Integer);
394    procedure Rcheck_18 (File : System.Address; Line : Integer);
395    procedure Rcheck_19 (File : System.Address; Line : Integer);
396    procedure Rcheck_20 (File : System.Address; Line : Integer);
397    procedure Rcheck_21 (File : System.Address; Line : Integer);
398    procedure Rcheck_22 (File : System.Address; Line : Integer);
399    procedure Rcheck_23 (File : System.Address; Line : Integer);
400    procedure Rcheck_24 (File : System.Address; Line : Integer);
401    procedure Rcheck_25 (File : System.Address; Line : Integer);
402    procedure Rcheck_26 (File : System.Address; Line : Integer);
403    procedure Rcheck_27 (File : System.Address; Line : Integer);
404    procedure Rcheck_28 (File : System.Address; Line : Integer);
405    procedure Rcheck_29 (File : System.Address; Line : Integer);
406    procedure Rcheck_30 (File : System.Address; Line : Integer);
407    procedure Rcheck_31 (File : System.Address; Line : Integer);
408    procedure Rcheck_32 (File : System.Address; Line : Integer);
409
410    pragma Export (C, Rcheck_00, "__gnat_rcheck_00");
411    pragma Export (C, Rcheck_01, "__gnat_rcheck_01");
412    pragma Export (C, Rcheck_02, "__gnat_rcheck_02");
413    pragma Export (C, Rcheck_03, "__gnat_rcheck_03");
414    pragma Export (C, Rcheck_04, "__gnat_rcheck_04");
415    pragma Export (C, Rcheck_05, "__gnat_rcheck_05");
416    pragma Export (C, Rcheck_06, "__gnat_rcheck_06");
417    pragma Export (C, Rcheck_07, "__gnat_rcheck_07");
418    pragma Export (C, Rcheck_08, "__gnat_rcheck_08");
419    pragma Export (C, Rcheck_09, "__gnat_rcheck_09");
420    pragma Export (C, Rcheck_10, "__gnat_rcheck_10");
421    pragma Export (C, Rcheck_11, "__gnat_rcheck_11");
422    pragma Export (C, Rcheck_12, "__gnat_rcheck_12");
423    pragma Export (C, Rcheck_13, "__gnat_rcheck_13");
424    pragma Export (C, Rcheck_14, "__gnat_rcheck_14");
425    pragma Export (C, Rcheck_15, "__gnat_rcheck_15");
426    pragma Export (C, Rcheck_16, "__gnat_rcheck_16");
427    pragma Export (C, Rcheck_17, "__gnat_rcheck_17");
428    pragma Export (C, Rcheck_18, "__gnat_rcheck_18");
429    pragma Export (C, Rcheck_19, "__gnat_rcheck_19");
430    pragma Export (C, Rcheck_20, "__gnat_rcheck_20");
431    pragma Export (C, Rcheck_21, "__gnat_rcheck_21");
432    pragma Export (C, Rcheck_22, "__gnat_rcheck_22");
433    pragma Export (C, Rcheck_23, "__gnat_rcheck_23");
434    pragma Export (C, Rcheck_24, "__gnat_rcheck_24");
435    pragma Export (C, Rcheck_25, "__gnat_rcheck_25");
436    pragma Export (C, Rcheck_26, "__gnat_rcheck_26");
437    pragma Export (C, Rcheck_27, "__gnat_rcheck_27");
438    pragma Export (C, Rcheck_28, "__gnat_rcheck_28");
439    pragma Export (C, Rcheck_29, "__gnat_rcheck_29");
440    pragma Export (C, Rcheck_30, "__gnat_rcheck_30");
441    pragma Export (C, Rcheck_31, "__gnat_rcheck_31");
442    pragma Export (C, Rcheck_32, "__gnat_rcheck_32");
443
444    --  None of these procedures ever returns (they raise an exception!). By
445    --  using pragma No_Return, we ensure that any junk code after the call,
446    --  such as normal return epilog stuff, can be eliminated).
447
448    pragma No_Return (Rcheck_00);
449    pragma No_Return (Rcheck_01);
450    pragma No_Return (Rcheck_02);
451    pragma No_Return (Rcheck_03);
452    pragma No_Return (Rcheck_04);
453    pragma No_Return (Rcheck_05);
454    pragma No_Return (Rcheck_06);
455    pragma No_Return (Rcheck_07);
456    pragma No_Return (Rcheck_08);
457    pragma No_Return (Rcheck_09);
458    pragma No_Return (Rcheck_10);
459    pragma No_Return (Rcheck_11);
460    pragma No_Return (Rcheck_12);
461    pragma No_Return (Rcheck_13);
462    pragma No_Return (Rcheck_14);
463    pragma No_Return (Rcheck_15);
464    pragma No_Return (Rcheck_16);
465    pragma No_Return (Rcheck_17);
466    pragma No_Return (Rcheck_18);
467    pragma No_Return (Rcheck_19);
468    pragma No_Return (Rcheck_20);
469    pragma No_Return (Rcheck_21);
470    pragma No_Return (Rcheck_22);
471    pragma No_Return (Rcheck_23);
472    pragma No_Return (Rcheck_24);
473    pragma No_Return (Rcheck_25);
474    pragma No_Return (Rcheck_26);
475    pragma No_Return (Rcheck_27);
476    pragma No_Return (Rcheck_28);
477    pragma No_Return (Rcheck_29);
478    pragma No_Return (Rcheck_30);
479    pragma No_Return (Rcheck_32);
480
481    ---------------------------------------------
482    -- Reason Strings for Run-Time Check Calls --
483    ---------------------------------------------
484
485    --  These strings are null-terminated and are used by Rcheck_nn. The
486    --  strings correspond to the definitions for Types.RT_Exception_Code.
487
488    use ASCII;
489
490    Rmsg_00 : constant String := "access check failed"              & NUL;
491    Rmsg_01 : constant String := "access parameter is null"         & NUL;
492    Rmsg_02 : constant String := "discriminant check failed"        & NUL;
493    Rmsg_03 : constant String := "divide by zero"                   & NUL;
494    Rmsg_04 : constant String := "explicit raise"                   & NUL;
495    Rmsg_05 : constant String := "index check failed"               & NUL;
496    Rmsg_06 : constant String := "invalid data"                     & NUL;
497    Rmsg_07 : constant String := "length check failed"              & NUL;
498    Rmsg_08 : constant String := "null Exception_Id"                & NUL;
499    Rmsg_09 : constant String := "null-exclusion check failed"      & NUL;
500    Rmsg_10 : constant String := "overflow check failed"            & NUL;
501    Rmsg_11 : constant String := "partition check failed"           & NUL;
502    Rmsg_12 : constant String := "range check failed"               & NUL;
503    Rmsg_13 : constant String := "tag check failed"                 & NUL;
504    Rmsg_14 : constant String := "access before elaboration"        & NUL;
505    Rmsg_15 : constant String := "accessibility check failed"       & NUL;
506    Rmsg_16 : constant String := "all guards closed"                & NUL;
507    Rmsg_17 : constant String := "duplicated entry address"         & NUL;
508    Rmsg_18 : constant String := "explicit raise"                   & NUL;
509    Rmsg_19 : constant String := "finalize/adjust raised exception" & NUL;
510    Rmsg_20 : constant String := "implicit return with No_Return"   & NUL;
511    Rmsg_21 : constant String := "misaligned address value"         & NUL;
512    Rmsg_22 : constant String := "missing return"                   & NUL;
513    Rmsg_23 : constant String := "overlaid controlled object"       & NUL;
514    Rmsg_24 : constant String := "potentially blocking operation"   & NUL;
515    Rmsg_25 : constant String := "stubbed subprogram called"        & NUL;
516    Rmsg_26 : constant String := "unchecked union restriction"      & NUL;
517    Rmsg_27 : constant String := "illegal use of remote access-to-" &
518                                 "class-wide type, see RM E.4(18)"  & NUL;
519    Rmsg_28 : constant String := "empty storage pool"               & NUL;
520    Rmsg_29 : constant String := "explicit raise"                   & NUL;
521    Rmsg_30 : constant String := "infinite recursion"               & NUL;
522    Rmsg_31 : constant String := "object too large"                 & NUL;
523    Rmsg_32 : constant String := "restriction violation"            & NUL;
524
525    -----------------------
526    -- Polling Interface --
527    -----------------------
528
529    type Unsigned is mod 2 ** 32;
530
531    Counter : Unsigned := 0;
532    pragma Warnings (Off, Counter);
533    --  This counter is provided for convenience. It can be used in Poll to
534    --  perform periodic but not systematic operations.
535
536    procedure Poll is separate;
537    --  The actual polling routine is separate, so that it can easily
538    --  be replaced with a target dependent version.
539
540    ------------------------------
541    -- Current_Target_Exception --
542    ------------------------------
543
544    function Current_Target_Exception return Exception_Occurrence is
545    begin
546       return Null_Occurrence;
547    end Current_Target_Exception;
548
549    -------------------
550    -- EId_To_String --
551    -------------------
552
553    function EId_To_String (X : Exception_Id) return String
554      renames Stream_Attributes.EId_To_String;
555
556    ------------------
557    -- EO_To_String --
558    ------------------
559
560    --  We use the null string to represent the null occurrence, otherwise
561    --  we output the Exception_Information string for the occurrence.
562
563    function EO_To_String (X : Exception_Occurrence) return String
564      renames Stream_Attributes.EO_To_String;
565
566    ------------------------
567    -- Exception_Identity --
568    ------------------------
569
570    function Exception_Identity
571      (X : Exception_Occurrence) return Exception_Id
572    is
573    begin
574       --  Note that the following test used to be here for the original
575       --  Ada 95 semantics, but these were modified by AI-241 to require
576       --  returning Null_Id instead of raising Constraint_Error.
577
578       --  if X.Id = Null_Id then
579       --     raise Constraint_Error;
580       --  end if;
581
582       return X.Id;
583    end Exception_Identity;
584
585    ---------------------------
586    -- Exception_Information --
587    ---------------------------
588
589    function Exception_Information (X : Exception_Occurrence) return String is
590    begin
591       if X.Id = Null_Id then
592          raise Constraint_Error;
593       end if;
594
595       return Exception_Data.Exception_Information (X);
596    end Exception_Information;
597
598    -----------------------
599    -- Exception_Message --
600    -----------------------
601
602    function Exception_Message (X : Exception_Occurrence) return String is
603    begin
604       if X.Id = Null_Id then
605          raise Constraint_Error;
606       end if;
607
608       return X.Msg (1 .. X.Msg_Length);
609    end Exception_Message;
610
611    --------------------
612    -- Exception_Name --
613    --------------------
614
615    function Exception_Name (Id : Exception_Id) return String is
616    begin
617       if Id = null then
618          raise Constraint_Error;
619       end if;
620
621       return To_Ptr (Id.Full_Name) (1 .. Id.Name_Length - 1);
622    end Exception_Name;
623
624    function Exception_Name (X : Exception_Occurrence) return String is
625    begin
626       return Exception_Name (X.Id);
627    end Exception_Name;
628
629    ---------------------------
630    -- Exception_Name_Simple --
631    ---------------------------
632
633    function Exception_Name_Simple (X : Exception_Occurrence) return String is
634       Name : constant String := Exception_Name (X);
635       P    : Natural;
636
637    begin
638       P := Name'Length;
639       while P > 1 loop
640          exit when Name (P - 1) = '.';
641          P := P - 1;
642       end loop;
643
644       --  Return result making sure lower bound is 1
645
646       declare
647          subtype Rname is String (1 .. Name'Length - P + 1);
648       begin
649          return Rname (Name (P .. Name'Length));
650       end;
651    end Exception_Name_Simple;
652
653    --------------------
654    -- Exception_Data --
655    --------------------
656
657    package body Exception_Data is separate;
658    --  This package can be easily dummied out if we do not want the
659    --  basic support for exception messages (such as in Ada 83).
660
661    package body Exception_Propagation is
662
663       procedure Setup_Exception
664         (Excep    : EOA;
665          Current  : EOA;
666          Reraised : Boolean := False)
667       is
668          pragma Warnings (Off, Excep);
669          pragma Warnings (Off, Current);
670          pragma Warnings (Off, Reraised);
671       begin
672          null;
673       end Setup_Exception;
674
675    end Exception_Propagation;
676
677    ----------------------
678    -- Exception_Traces --
679    ----------------------
680
681    package body Exception_Traces is separate;
682    --  Depending on the underlying support for IO the implementation
683    --  will differ. Moreover we would like to dummy out this package
684    --  in case we do not want any exception tracing support. This is
685    --  why this package is separated.
686
687    -----------------------
688    -- Stream Attributes --
689    -----------------------
690
691    package body Stream_Attributes is separate;
692    --  This package can be easily dummied out if we do not want the
693    --  support for streaming Exception_Ids and Exception_Occurrences.
694
695    -----------------------------
696    -- Process_Raise_Exception --
697    -----------------------------
698
699    procedure Process_Raise_Exception (E : Exception_Id) is
700       pragma Inspection_Point (E);
701       --  This is so the debugger can reliably inspect the parameter
702
703       Jumpbuf_Ptr : constant Address := Get_Jmpbuf_Address.all;
704       Excep       : constant EOA := Get_Current_Excep.all;
705
706       procedure builtin_longjmp (buffer : Address; Flag : Integer);
707       pragma No_Return (builtin_longjmp);
708       pragma Import (C, builtin_longjmp, "_gnat_builtin_longjmp");
709
710    begin
711       --  WARNING: There should be no exception handler for this body
712       --  because this would cause gigi to prepend a setup for a new
713       --  jmpbuf to the sequence of statements in case of built-in sjljl.
714       --  We would then always get this new buf in Jumpbuf_Ptr instead of the
715       --  one for the exception we are handling, which would completely break
716       --  the whole design of this procedure.
717
718       --  If the jump buffer pointer is non-null, transfer control using
719       --  it. Otherwise announce an unhandled exception (note that this
720       --  means that we have no finalizations to do other than at the outer
721       --  level). Perform the necessary notification tasks in both cases.
722
723       if Jumpbuf_Ptr /= Null_Address then
724          if not Excep.Exception_Raised then
725             Excep.Exception_Raised := True;
726             Exception_Traces.Notify_Handled_Exception;
727          end if;
728
729          builtin_longjmp (Jumpbuf_Ptr, 1);
730
731       else
732          Exception_Traces.Notify_Unhandled_Exception;
733          Exception_Traces.Unhandled_Exception_Terminate;
734       end if;
735    end Process_Raise_Exception;
736
737    ----------------------------
738    -- Raise_Constraint_Error --
739    ----------------------------
740
741    procedure Raise_Constraint_Error
742      (File : System.Address;
743       Line : Integer)
744    is
745    begin
746       Raise_With_Location_And_Msg
747         (Constraint_Error_Def'Access, File, Line);
748    end Raise_Constraint_Error;
749
750    --------------------------------
751    -- Raise_Constraint_Error_Msg --
752    --------------------------------
753
754    procedure Raise_Constraint_Error_Msg
755      (File : System.Address;
756       Line : Integer;
757       Msg  : System.Address)
758    is
759    begin
760       Raise_With_Location_And_Msg
761         (Constraint_Error_Def'Access, File, Line, Msg);
762    end Raise_Constraint_Error_Msg;
763
764    -------------------------
765    -- Raise_Current_Excep --
766    -------------------------
767
768    procedure Raise_Current_Excep (E : Exception_Id) is
769
770       pragma Inspection_Point (E);
771       --  This is so the debugger can reliably inspect the parameter when
772       --  inserting a breakpoint at the start of this procedure.
773
774       Id : Exception_Id := E;
775       pragma Volatile (Id);
776       pragma Warnings (Off, Id);
777       --  In order to provide support for breakpoints on unhandled exceptions,
778       --  the debugger will also need to be able to inspect the value of E from
779       --  another (inner) frame. So we need to make sure that if E is passed in
780       --  a register, its value is also spilled on stack. For this, we store
781       --  the parameter value in a local variable, and add a pragma Volatile to
782       --  make sure it is spilled. The pragma Warnings (Off) is needed because
783       --  the compiler knows that Id is not referenced and that this use of
784       --  pragma Volatile is peculiar!
785
786    begin
787       Process_Raise_Exception (E);
788    end Raise_Current_Excep;
789
790    ---------------------
791    -- Raise_Exception --
792    ---------------------
793
794    procedure Raise_Exception
795      (E       : Exception_Id;
796       Message : String := "")
797    is
798    begin
799       if E /= null then
800          Exception_Data.Set_Exception_Msg (E, Message);
801          Abort_Defer.all;
802          Raise_Current_Excep (E);
803       end if;
804
805       --  Note: if E is null, then we simply return, which is correct Ada 95
806       --  semantics. If we are operating in Ada 2005 mode, then the expander
807       --  generates a raise Constraint_Error immediately following the call
808       --  to provide the required Ada 2005 semantics (see AI-329). We do it
809       --  this way to avoid having run time dependencies on the Ada version.
810
811       return;
812    end Raise_Exception;
813
814    ----------------------------
815    -- Raise_Exception_Always --
816    ----------------------------
817
818    procedure Raise_Exception_Always
819      (E       : Exception_Id;
820       Message : String := "")
821    is
822    begin
823       Exception_Data.Set_Exception_Msg (E, Message);
824       Abort_Defer.all;
825       Raise_Current_Excep (E);
826    end Raise_Exception_Always;
827
828    -------------------------------
829    -- Raise_From_Signal_Handler --
830    -------------------------------
831
832    procedure Raise_From_Signal_Handler
833      (E : Exception_Id;
834       M : System.Address)
835    is
836    begin
837       Exception_Data.Set_Exception_C_Msg (E, M);
838       Abort_Defer.all;
839       Process_Raise_Exception (E);
840    end Raise_From_Signal_Handler;
841
842    -------------------------
843    -- Raise_Program_Error --
844    -------------------------
845
846    procedure Raise_Program_Error
847      (File : System.Address;
848       Line : Integer)
849    is
850    begin
851       Raise_With_Location_And_Msg
852         (Program_Error_Def'Access, File, Line);
853    end Raise_Program_Error;
854
855    -----------------------------
856    -- Raise_Program_Error_Msg --
857    -----------------------------
858
859    procedure Raise_Program_Error_Msg
860      (File : System.Address;
861       Line : Integer;
862       Msg  : System.Address)
863    is
864    begin
865       Raise_With_Location_And_Msg
866         (Program_Error_Def'Access, File, Line, Msg);
867    end Raise_Program_Error_Msg;
868
869    -------------------------
870    -- Raise_Storage_Error --
871    -------------------------
872
873    procedure Raise_Storage_Error
874      (File : System.Address;
875       Line : Integer)
876    is
877    begin
878       Raise_With_Location_And_Msg
879         (Storage_Error_Def'Access, File, Line);
880    end Raise_Storage_Error;
881
882    -----------------------------
883    -- Raise_Storage_Error_Msg --
884    -----------------------------
885
886    procedure Raise_Storage_Error_Msg
887      (File : System.Address;
888       Line : Integer;
889       Msg  : System.Address)
890    is
891    begin
892       Raise_With_Location_And_Msg
893         (Storage_Error_Def'Access, File, Line, Msg);
894    end Raise_Storage_Error_Msg;
895
896    ---------------------------------
897    -- Raise_With_Location_And_Msg --
898    ---------------------------------
899
900    procedure Raise_With_Location_And_Msg
901      (E : Exception_Id;
902       F : System.Address;
903       L : Integer;
904       M : System.Address := System.Null_Address)
905    is
906    begin
907       Exception_Data.Set_Exception_C_Msg (E, F, L, M);
908       Abort_Defer.all;
909       Raise_Current_Excep (E);
910    end Raise_With_Location_And_Msg;
911
912    --------------------
913    -- Raise_With_Msg --
914    --------------------
915
916    procedure Raise_With_Msg (E : Exception_Id) is
917       Excep : constant EOA := Get_Current_Excep.all;
918
919    begin
920       Excep.Exception_Raised := False;
921       Excep.Id               := E;
922       Excep.Num_Tracebacks   := 0;
923       Excep.Cleanup_Flag     := False;
924       Excep.Pid              := Local_Partition_ID;
925       Abort_Defer.all;
926       Raise_Current_Excep (E);
927    end Raise_With_Msg;
928
929    --------------------------------------
930    -- Calls to Run-Time Check Routines --
931    --------------------------------------
932
933    procedure Rcheck_00 (File : System.Address; Line : Integer) is
934    begin
935       Raise_Constraint_Error_Msg (File, Line, Rmsg_00'Address);
936    end Rcheck_00;
937
938    procedure Rcheck_01 (File : System.Address; Line : Integer) is
939    begin
940       Raise_Constraint_Error_Msg (File, Line, Rmsg_01'Address);
941    end Rcheck_01;
942
943    procedure Rcheck_02 (File : System.Address; Line : Integer) is
944    begin
945       Raise_Constraint_Error_Msg (File, Line, Rmsg_02'Address);
946    end Rcheck_02;
947
948    procedure Rcheck_03 (File : System.Address; Line : Integer) is
949    begin
950       Raise_Constraint_Error_Msg (File, Line, Rmsg_03'Address);
951    end Rcheck_03;
952
953    procedure Rcheck_04 (File : System.Address; Line : Integer) is
954    begin
955       Raise_Constraint_Error_Msg (File, Line, Rmsg_04'Address);
956    end Rcheck_04;
957
958    procedure Rcheck_05 (File : System.Address; Line : Integer) is
959    begin
960       Raise_Constraint_Error_Msg (File, Line, Rmsg_05'Address);
961    end Rcheck_05;
962
963    procedure Rcheck_06 (File : System.Address; Line : Integer) is
964    begin
965       Raise_Constraint_Error_Msg (File, Line, Rmsg_06'Address);
966    end Rcheck_06;
967
968    procedure Rcheck_07 (File : System.Address; Line : Integer) is
969    begin
970       Raise_Constraint_Error_Msg (File, Line, Rmsg_07'Address);
971    end Rcheck_07;
972
973    procedure Rcheck_08 (File : System.Address; Line : Integer) is
974    begin
975       Raise_Constraint_Error_Msg (File, Line, Rmsg_08'Address);
976    end Rcheck_08;
977
978    procedure Rcheck_09 (File : System.Address; Line : Integer) is
979    begin
980       Raise_Constraint_Error_Msg (File, Line, Rmsg_09'Address);
981    end Rcheck_09;
982
983    procedure Rcheck_10 (File : System.Address; Line : Integer) is
984    begin
985       Raise_Constraint_Error_Msg (File, Line, Rmsg_10'Address);
986    end Rcheck_10;
987
988    procedure Rcheck_11 (File : System.Address; Line : Integer) is
989    begin
990       Raise_Constraint_Error_Msg (File, Line, Rmsg_11'Address);
991    end Rcheck_11;
992
993    procedure Rcheck_12 (File : System.Address; Line : Integer) is
994    begin
995       Raise_Constraint_Error_Msg (File, Line, Rmsg_12'Address);
996    end Rcheck_12;
997
998    procedure Rcheck_13 (File : System.Address; Line : Integer) is
999    begin
1000       Raise_Constraint_Error_Msg (File, Line, Rmsg_13'Address);
1001    end Rcheck_13;
1002
1003    procedure Rcheck_14 (File : System.Address; Line : Integer) is
1004    begin
1005       Raise_Program_Error_Msg (File, Line, Rmsg_14'Address);
1006    end Rcheck_14;
1007
1008    procedure Rcheck_15 (File : System.Address; Line : Integer) is
1009    begin
1010       Raise_Program_Error_Msg (File, Line, Rmsg_15'Address);
1011    end Rcheck_15;
1012
1013    procedure Rcheck_16 (File : System.Address; Line : Integer) is
1014    begin
1015       Raise_Program_Error_Msg (File, Line, Rmsg_16'Address);
1016    end Rcheck_16;
1017
1018    procedure Rcheck_17 (File : System.Address; Line : Integer) is
1019    begin
1020       Raise_Program_Error_Msg (File, Line, Rmsg_17'Address);
1021    end Rcheck_17;
1022
1023    procedure Rcheck_18 (File : System.Address; Line : Integer) is
1024    begin
1025       Raise_Program_Error_Msg (File, Line, Rmsg_18'Address);
1026    end Rcheck_18;
1027
1028    procedure Rcheck_19 (File : System.Address; Line : Integer) is
1029    begin
1030       Raise_Program_Error_Msg (File, Line, Rmsg_19'Address);
1031    end Rcheck_19;
1032
1033    procedure Rcheck_20 (File : System.Address; Line : Integer) is
1034    begin
1035       Raise_Program_Error_Msg (File, Line, Rmsg_20'Address);
1036    end Rcheck_20;
1037
1038    procedure Rcheck_21 (File : System.Address; Line : Integer) is
1039    begin
1040       Raise_Program_Error_Msg (File, Line, Rmsg_21'Address);
1041    end Rcheck_21;
1042
1043    procedure Rcheck_22 (File : System.Address; Line : Integer) is
1044    begin
1045       Raise_Program_Error_Msg (File, Line, Rmsg_22'Address);
1046    end Rcheck_22;
1047
1048    procedure Rcheck_23 (File : System.Address; Line : Integer) is
1049    begin
1050       Raise_Program_Error_Msg (File, Line, Rmsg_23'Address);
1051    end Rcheck_23;
1052
1053    procedure Rcheck_24 (File : System.Address; Line : Integer) is
1054    begin
1055       Raise_Program_Error_Msg (File, Line, Rmsg_24'Address);
1056    end Rcheck_24;
1057
1058    procedure Rcheck_25 (File : System.Address; Line : Integer) is
1059    begin
1060       Raise_Program_Error_Msg (File, Line, Rmsg_25'Address);
1061    end Rcheck_25;
1062
1063    procedure Rcheck_26 (File : System.Address; Line : Integer) is
1064    begin
1065       Raise_Program_Error_Msg (File, Line, Rmsg_26'Address);
1066    end Rcheck_26;
1067
1068    procedure Rcheck_27 (File : System.Address; Line : Integer) is
1069    begin
1070       Raise_Program_Error_Msg (File, Line, Rmsg_27'Address);
1071    end Rcheck_27;
1072
1073    procedure Rcheck_28 (File : System.Address; Line : Integer) is
1074    begin
1075       Raise_Storage_Error_Msg (File, Line, Rmsg_28'Address);
1076    end Rcheck_28;
1077
1078    procedure Rcheck_29 (File : System.Address; Line : Integer) is
1079    begin
1080       Raise_Storage_Error_Msg (File, Line, Rmsg_29'Address);
1081    end Rcheck_29;
1082
1083    procedure Rcheck_30 (File : System.Address; Line : Integer) is
1084    begin
1085       Raise_Storage_Error_Msg (File, Line, Rmsg_30'Address);
1086    end Rcheck_30;
1087
1088    procedure Rcheck_31 (File : System.Address; Line : Integer) is
1089    begin
1090       Raise_Storage_Error_Msg (File, Line, Rmsg_31'Address);
1091    end Rcheck_31;
1092
1093    procedure Rcheck_32 (File : System.Address; Line : Integer) is
1094    begin
1095       Raise_Storage_Error_Msg (File, Line, Rmsg_32'Address);
1096    end Rcheck_32;
1097
1098    -------------
1099    -- Reraise --
1100    -------------
1101
1102    procedure Reraise is
1103       Excep : constant EOA := Get_Current_Excep.all;
1104
1105    begin
1106       Abort_Defer.all;
1107       Raise_Current_Excep (Excep.Id);
1108    end Reraise;
1109
1110    ------------------------
1111    -- Reraise_Occurrence --
1112    ------------------------
1113
1114    procedure Reraise_Occurrence (X : Exception_Occurrence) is
1115    begin
1116       if X.Id /= null then
1117          Abort_Defer.all;
1118          Save_Occurrence_No_Private (Get_Current_Excep.all.all, X);
1119          Raise_Current_Excep (X.Id);
1120       end if;
1121    end Reraise_Occurrence;
1122
1123    -------------------------------
1124    -- Reraise_Occurrence_Always --
1125    -------------------------------
1126
1127    procedure Reraise_Occurrence_Always (X : Exception_Occurrence) is
1128    begin
1129       Abort_Defer.all;
1130       Save_Occurrence_No_Private (Get_Current_Excep.all.all, X);
1131       Raise_Current_Excep (X.Id);
1132    end Reraise_Occurrence_Always;
1133
1134    ---------------------------------
1135    -- Reraise_Occurrence_No_Defer --
1136    ---------------------------------
1137
1138    procedure Reraise_Occurrence_No_Defer (X : Exception_Occurrence) is
1139    begin
1140       Save_Occurrence_No_Private (Get_Current_Excep.all.all, X);
1141       Raise_Current_Excep (X.Id);
1142    end Reraise_Occurrence_No_Defer;
1143
1144    ---------------------
1145    -- Save_Occurrence --
1146    ---------------------
1147
1148    procedure Save_Occurrence
1149      (Target : out Exception_Occurrence;
1150       Source : Exception_Occurrence)
1151    is
1152    begin
1153       Save_Occurrence_No_Private (Target, Source);
1154    end Save_Occurrence;
1155
1156    function Save_Occurrence (Source : Exception_Occurrence) return EOA is
1157       Target : constant EOA := new Exception_Occurrence;
1158    begin
1159       Save_Occurrence (Target.all, Source);
1160       return Target;
1161    end Save_Occurrence;
1162
1163    --------------------------------
1164    -- Save_Occurrence_No_Private --
1165    --------------------------------
1166
1167    procedure Save_Occurrence_No_Private
1168      (Target : out Exception_Occurrence;
1169       Source : Exception_Occurrence)
1170    is
1171    begin
1172       Target.Id             := Source.Id;
1173       Target.Msg_Length     := Source.Msg_Length;
1174       Target.Num_Tracebacks := Source.Num_Tracebacks;
1175       Target.Pid            := Source.Pid;
1176       Target.Cleanup_Flag   := Source.Cleanup_Flag;
1177
1178       Target.Msg (1 .. Target.Msg_Length) :=
1179         Source.Msg (1 .. Target.Msg_Length);
1180
1181       Target.Tracebacks (1 .. Target.Num_Tracebacks) :=
1182         Source.Tracebacks (1 .. Target.Num_Tracebacks);
1183    end Save_Occurrence_No_Private;
1184
1185    -------------------------
1186    -- Transfer_Occurrence --
1187    -------------------------
1188
1189    procedure Transfer_Occurrence
1190      (Target : Exception_Occurrence_Access;
1191       Source : Exception_Occurrence)
1192    is
1193    begin
1194       --  Setup Target as an exception to be propagated in the calling task
1195       --  (rendezvous-wise), taking care not to clobber the associated private
1196       --  data.  Target is expected to be a pointer to the calling task's
1197       --  fixed TSD occurrence, which is very different from Get_Current_Excep
1198       --  here because this subprogram is called from the called task.
1199
1200       Save_Occurrence_No_Private (Target.all, Source);
1201    end Transfer_Occurrence;
1202
1203    -------------------
1204    -- String_To_EId --
1205    -------------------
1206
1207    function String_To_EId (S : String) return Exception_Id
1208      renames Stream_Attributes.String_To_EId;
1209
1210    ------------------
1211    -- String_To_EO --
1212    ------------------
1213
1214    function String_To_EO (S : String) return Exception_Occurrence
1215      renames Stream_Attributes.String_To_EO;
1216
1217    ------------------------------
1218    -- Raise_Exception_No_Defer --
1219    ------------------------------
1220
1221    procedure Raise_Exception_No_Defer
1222      (E       : Exception_Id;
1223       Message : String := "")
1224    is
1225    begin
1226       Exception_Data.Set_Exception_Msg (E, Message);
1227
1228       --  Do not call Abort_Defer.all, as specified by the spec
1229
1230       Raise_Current_Excep (E);
1231    end Raise_Exception_No_Defer;
1232
1233    ---------------
1234    -- To_Stderr --
1235    ---------------
1236
1237    procedure To_Stderr (C : Character) is
1238
1239       type int is new Integer;
1240
1241       procedure put_char_stderr (C : int);
1242       pragma Import (C, put_char_stderr, "put_char_stderr");
1243
1244    begin
1245       put_char_stderr (Character'Pos (C));
1246    end To_Stderr;
1247
1248    procedure To_Stderr (S : String) is
1249    begin
1250       for J in S'Range loop
1251          if S (J) /= ASCII.CR then
1252             To_Stderr (S (J));
1253          end if;
1254       end loop;
1255    end To_Stderr;
1256
1257 end Ada.Exceptions;