Debian Codegraph @

gcc/ada/libgnat/g-csclex.ads

raw
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT RUN-TIME COMPONENTS --
4 -- --
5 -- G N A T . C P P . S T D . C L A S S _ E X C E P T I O N --
6 -- --
7 -- S p e c --
8 -- --
9 -- Copyright (C) 2022-2025, AdaCore --
10 -- --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. --
17 -- --
18 -- As a special exception under Section 7 of GPL version 3, you are granted --
19 -- additional permissions described in the GCC Runtime Library Exception, --
20 -- version 3.1, as published by the Free Software Foundation. --
21 -- --
22 -- You should have received a copy of the GNU General Public License and --
23 -- a copy of the GCC Runtime Library Exception along with this program; --
24 -- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
25 -- <http://www.gnu.org/licenses/>. --
26 -- --
27 -- GNAT was originally developed by the GNAT team at New York University. --
28 -- Extensive contributions were provided by Ada Core Technologies Inc. --
29 -- --
30 ------------------------------------------------------------------------------
31
32 -- This package provides an interface to C++'s std::exception objects
33
34 with Interfaces.C;
35 with Interfaces.C.Strings; use Interfaces.C.Strings;
36 -- with GNAT.CPP_Exceptions; use GNAT.CPP_Exceptions;
37
38 -- ??? Should we expose, or even keep this unit? We can't run
39 -- constructors (they're inline), and destructors have to be declared
40 -- before the public methods because of their position in the virtual
41 -- method table, so they have to be public as well. It could be
42 -- unsafe to run them without running the constructors we can't get
43 -- at, so deriving from this type would be a challenge, though it
44 -- could be potentially useful for obscure cross-language exception
45 -- handling scenarios. Adding this unit to libgnat would require
46 -- libgnat.so to depend on libsupc++, if the exception declarations
47 -- were uncommented out.
48 private package GNAT.CPP.Std.Class_Exception is
49 type Class_Exception is abstract tagged limited record
50 null;
51 end record;
52 pragma Import (CPP, Class_Exception);
53
54 -- Defined inline, no out-of-line version available.
55 -- function New_Class_Exception return Class_Exception;
56 -- pragma Cpp_Constructor (New_Class_Exception);
57 -- pragma Machine_Attribute (New_Class_Exception, "nothrow");
58 pragma Warnings (Off, "CPP constructor required for type");
59
60 -- Allowing destruction is undesirable, but since these are in
61 -- the virtual method table, we have to declare them.
62 -- ??? Could we make them private somehow?
63 procedure Destructor (Ex : access Class_Exception);
64 pragma Import (CPP, Destructor, "_ZNSt9exceptionD1Ev");
65 pragma Machine_Attribute (Destructor, "nothrow");
66 procedure Delete_Destructor (Ex : access Class_Exception);
67 pragma Import (CPP, Delete_Destructor, "_ZNSt9exceptionD0Ev");
68 pragma Machine_Attribute (Delete_Destructor, "nothrow");
69
70 function What (Ex : access constant Class_Exception) return chars_ptr;
71 pragma Import (CPP, What, "_ZNKSt9exception4whatEv");
72 pragma Machine_Attribute (What, "nothrow");
73 -- Obtain the C string stored in the std::exception object.
74
75 function What (Ex : access constant Class_Exception'Class) return String is
76 (Value (What (Ex)));
77 -- Obtain the C string stored in the std::exception object,
78 -- converted to an Ada String.
79
80 -- function Get_Class_Exception_From_Occurrence is
81 -- new Get_Access_To_Tagged_Object (Class_Exception);
82 -- Obtain access to Class_Exception'Class of an
83 -- Exception_Occurrence handled as Class_Exception_Only or
84 -- Class_Exception_Or_Derived, as defined in comments below.
85 -- Adding this to libgnat would cause libgnat.so to depend on
86 -- libsupc++.
87
88 -- Class_Exception_Only : exception;
89 -- pragma Import (Cpp, Class_Exception_Only,
90 -- "_ZTISt9exception");
91 -- Exception to catch std::exception exact matches only.
92
93 -- Class_Exception_Or_Derived : exception;
94 -- pragma Import (Cpp, Class_Exception_Or_Derived,
95 -- "_ZTISt9exception'Class");
96 -- Exception to catch std::exception or derived types.
97
98 end GNAT.CPP.Std.Class_Exception;