annotate gcc/ada/libgnat/g-cppexc.adb @ 131:84e7813d76e9

gcc-8.2
author mir3636
date Thu, 25 Oct 2018 07:37:49 +0900
parents 04ced10e8804
children 1830386684a0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 ------------------------------------------------------------------------------
kono
parents:
diff changeset
2 -- --
kono
parents:
diff changeset
3 -- GNAT RUN-TIME COMPONENTS --
kono
parents:
diff changeset
4 -- --
kono
parents:
diff changeset
5 -- G N A T . C P P _ E X C E P T I O N S --
kono
parents:
diff changeset
6 -- --
kono
parents:
diff changeset
7 -- B o d y --
kono
parents:
diff changeset
8 -- --
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
9 -- Copyright (C) 2013-2018, AdaCore --
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. --
kono
parents:
diff changeset
17 -- --
kono
parents:
diff changeset
18 -- As a special exception under Section 7 of GPL version 3, you are granted --
kono
parents:
diff changeset
19 -- additional permissions described in the GCC Runtime Library Exception, --
kono
parents:
diff changeset
20 -- version 3.1, as published by the Free Software Foundation. --
kono
parents:
diff changeset
21 -- --
kono
parents:
diff changeset
22 -- You should have received a copy of the GNU General Public License and --
kono
parents:
diff changeset
23 -- a copy of the GCC Runtime Library Exception along with this program; --
kono
parents:
diff changeset
24 -- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
kono
parents:
diff changeset
25 -- <http://www.gnu.org/licenses/>. --
kono
parents:
diff changeset
26 -- --
kono
parents:
diff changeset
27 -- GNAT was originally developed by the GNAT team at New York University. --
kono
parents:
diff changeset
28 -- Extensive contributions were provided by Ada Core Technologies Inc. --
kono
parents:
diff changeset
29 -- --
kono
parents:
diff changeset
30 ------------------------------------------------------------------------------
kono
parents:
diff changeset
31
kono
parents:
diff changeset
32 with System;
kono
parents:
diff changeset
33 with System.Storage_Elements;
kono
parents:
diff changeset
34 with Interfaces.C; use Interfaces.C;
kono
parents:
diff changeset
35 with Ada.Unchecked_Conversion;
kono
parents:
diff changeset
36 with System.Standard_Library; use System.Standard_Library;
kono
parents:
diff changeset
37
kono
parents:
diff changeset
38 package body GNAT.CPP_Exceptions is
kono
parents:
diff changeset
39
kono
parents:
diff changeset
40 -- Note: all functions prefixed by __cxa are part of the c++ ABI for
kono
parents:
diff changeset
41 -- exception handling. As they are provided by the c++ library, there
kono
parents:
diff changeset
42 -- must be no dependencies on it in the compiled code of this unit, but
kono
parents:
diff changeset
43 -- there can be dependencies in instances. This is required to be able
kono
parents:
diff changeset
44 -- to build the shared library without the c++ library.
kono
parents:
diff changeset
45
kono
parents:
diff changeset
46 function To_Exception_Data_Ptr is new
kono
parents:
diff changeset
47 Ada.Unchecked_Conversion
kono
parents:
diff changeset
48 (Exception_Id, Exception_Data_Ptr);
kono
parents:
diff changeset
49 -- Convert an Exception_Id to its non-private type. This is used to get
kono
parents:
diff changeset
50 -- the RTTI of a C++ exception
kono
parents:
diff changeset
51
kono
parents:
diff changeset
52 function Get_Exception_Machine_Occurrence
kono
parents:
diff changeset
53 (X : Exception_Occurrence) return System.Address;
kono
parents:
diff changeset
54 pragma Import (Ada, Get_Exception_Machine_Occurrence,
kono
parents:
diff changeset
55 "__gnat_get_exception_machine_occurrence");
kono
parents:
diff changeset
56 -- Imported function (from Ada.Exceptions) that returns the machine
kono
parents:
diff changeset
57 -- occurrence from an exception occurrence.
kono
parents:
diff changeset
58
kono
parents:
diff changeset
59 -------------------------
kono
parents:
diff changeset
60 -- Raise_Cpp_Exception --
kono
parents:
diff changeset
61 -------------------------
kono
parents:
diff changeset
62
kono
parents:
diff changeset
63 procedure Raise_Cpp_Exception (Id : Exception_Id; Value : T)
kono
parents:
diff changeset
64 is
kono
parents:
diff changeset
65 Id_Data : constant Exception_Data_Ptr := To_Exception_Data_Ptr (Id);
kono
parents:
diff changeset
66 -- Get a non-private view on the exception
kono
parents:
diff changeset
67
kono
parents:
diff changeset
68 type T_Acc is access all T;
kono
parents:
diff changeset
69 pragma Convention (C, T_Acc);
kono
parents:
diff changeset
70 -- Access type to the object compatible with C
kono
parents:
diff changeset
71
kono
parents:
diff changeset
72 Occ : T_Acc;
kono
parents:
diff changeset
73 -- The occurrence to propagate
kono
parents:
diff changeset
74
kono
parents:
diff changeset
75 function cxa_allocate_exception (Size : size_t) return T_Acc;
kono
parents:
diff changeset
76 pragma Import (C, cxa_allocate_exception, "__cxa_allocate_exception");
kono
parents:
diff changeset
77 -- The C++ function to allocate an occurrence
kono
parents:
diff changeset
78
kono
parents:
diff changeset
79 procedure cxa_throw (Obj : T_Acc; Tinfo : System.Address;
kono
parents:
diff changeset
80 Dest : System.Address);
kono
parents:
diff changeset
81 pragma Import (C, cxa_throw, "__cxa_throw");
kono
parents:
diff changeset
82 pragma No_Return (cxa_throw);
kono
parents:
diff changeset
83 -- The C++ function to raise an exception
kono
parents:
diff changeset
84 begin
kono
parents:
diff changeset
85 -- Check the exception was imported from C++
kono
parents:
diff changeset
86
kono
parents:
diff changeset
87 if Id_Data.Lang /= 'C' then
kono
parents:
diff changeset
88 raise Constraint_Error;
kono
parents:
diff changeset
89 end if;
kono
parents:
diff changeset
90
kono
parents:
diff changeset
91 -- Allocate the C++ occurrence
kono
parents:
diff changeset
92
kono
parents:
diff changeset
93 Occ := cxa_allocate_exception (T'Size / System.Storage_Unit);
kono
parents:
diff changeset
94
kono
parents:
diff changeset
95 -- Set the object
kono
parents:
diff changeset
96
kono
parents:
diff changeset
97 Occ.all := Value;
kono
parents:
diff changeset
98
kono
parents:
diff changeset
99 -- Throw the exception
kono
parents:
diff changeset
100
kono
parents:
diff changeset
101 cxa_throw (Occ, Id_Data.Foreign_Data, System.Null_Address);
kono
parents:
diff changeset
102 end Raise_Cpp_Exception;
kono
parents:
diff changeset
103
kono
parents:
diff changeset
104 ----------------
kono
parents:
diff changeset
105 -- Get_Object --
kono
parents:
diff changeset
106 ----------------
kono
parents:
diff changeset
107
kono
parents:
diff changeset
108 function Get_Object (X : Exception_Occurrence) return T
kono
parents:
diff changeset
109 is
kono
parents:
diff changeset
110 use System;
kono
parents:
diff changeset
111 use System.Storage_Elements;
kono
parents:
diff changeset
112
kono
parents:
diff changeset
113 Unwind_Exception_Size : Natural;
kono
parents:
diff changeset
114 pragma Import (C, Unwind_Exception_Size, "__gnat_unwind_exception_size");
kono
parents:
diff changeset
115 -- Size in bytes of _Unwind_Exception
kono
parents:
diff changeset
116
kono
parents:
diff changeset
117 Exception_Addr : constant Address :=
kono
parents:
diff changeset
118 Get_Exception_Machine_Occurrence (X);
kono
parents:
diff changeset
119 -- Machine occurrence of X
kono
parents:
diff changeset
120
kono
parents:
diff changeset
121 begin
kono
parents:
diff changeset
122 -- Check the machine occurrence exists
kono
parents:
diff changeset
123
kono
parents:
diff changeset
124 if Exception_Addr = Null_Address then
kono
parents:
diff changeset
125 raise Constraint_Error;
kono
parents:
diff changeset
126 end if;
kono
parents:
diff changeset
127
kono
parents:
diff changeset
128 declare
kono
parents:
diff changeset
129 -- Import the object from the occurrence
kono
parents:
diff changeset
130 Result : T;
kono
parents:
diff changeset
131 pragma Import (Ada, Result);
kono
parents:
diff changeset
132 for Result'Address use
kono
parents:
diff changeset
133 Exception_Addr + Storage_Offset (Unwind_Exception_Size);
kono
parents:
diff changeset
134 begin
kono
parents:
diff changeset
135 -- And return it
kono
parents:
diff changeset
136 return Result;
kono
parents:
diff changeset
137 end;
kono
parents:
diff changeset
138 end Get_Object;
kono
parents:
diff changeset
139 end GNAT.CPP_Exceptions;