| 1 |
------------------------------------------------------------------------------ |
| 2 |
-- -- |
| 3 |
-- GNAT RUN-TIME COMPONENTS -- |
| 4 |
-- -- |
| 5 |
-- G N A T . C P P . S T D . T Y P E _ I N F O -- |
| 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::type_info objects |
| 33 |
|
| 34 |
with System; |
| 35 |
with Interfaces.C; |
| 36 |
with Interfaces.C.Extensions; |
| 37 |
with Interfaces.C.Strings; |
| 38 |
|
| 39 |
-- This unit should be kept private. We can't run constructors |
| 40 |
-- (they're inline), and destructors have to be declared before the |
| 41 |
-- public methods because of their position in the virtual method |
| 42 |
-- table, so they have to be public as well. It would be unsafe to |
| 43 |
-- run them, since std::type_info objects are typically |
| 44 |
-- statically-allocated. Without out-of-line constructors, deriving |
| 45 |
-- from this type would be a challenge. However, there are some |
| 46 |
-- select APIs that we wish to use for exception handling machinery, |
| 47 |
-- and others that could be potentially useful in Ada/C++ programs, |
| 48 |
-- that are exposed in GNAT.CPP.Std. |
| 49 |
private package GNAT.CPP.Std.Type_Info is |
| 50 |
type type_info is abstract tagged limited private; |
| 51 |
pragma Import (CPP, type_info); |
| 52 |
|
| 53 |
pragma Warnings (Off, "CPP constructor required for type"); |
| 54 |
|
| 55 |
-- Defined inline, no out-of-line version available. |
| 56 |
-- function Constructor (name : Interfaces.C.Strings.chars_ptr) |
| 57 |
-- return type_info is abstract; |
| 58 |
-- pragma Cpp_Constructor (Constructor, "_ZNSt9type_infoC1EPKc"); |
| 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 (this : access type_info); |
| 64 |
pragma Import (CPP, Destructor, "_ZNSt9type_infoD1Ev"); |
| 65 |
pragma Machine_Attribute (Destructor, "nothrow"); |
| 66 |
procedure Delete_Destructor (This : access type_info); |
| 67 |
pragma Import (CPP, Delete_Destructor, "_ZNSt9type_InfoD0Ev"); |
| 68 |
pragma Machine_Attribute (Delete_Destructor, "nothrow"); |
| 69 |
|
| 70 |
-- Defined inline, no out-of-line version available. |
| 71 |
-- Reimplemented in Ada, using Ada types. |
| 72 |
function Name (this : access constant type_info'Class) |
| 73 |
-- return Interfaces.C.Strings.chars_ptr; |
| 74 |
return Interfaces.C.Strings.chars_ptr; |
| 75 |
-- pragma Import (CPP, Name, "_ZNKSt9type_info4nameEv"); |
| 76 |
pragma Machine_Attribute (Name, "nothrow"); |
| 77 |
|
| 78 |
-- Defined inline, no out-of-line version available. |
| 79 |
-- Reimplemented in Ada, using Ada types. |
| 80 |
function Before (this, that : access constant type_info'Class) |
| 81 |
-- return Interfaces.C.Extensions.bool; |
| 82 |
return Boolean; |
| 83 |
-- pragma Import (CPP, Before, "_ZNKSt9type_info6beforeERKS_"); |
| 84 |
pragma Machine_Attribute (Before, "nothrow"); |
| 85 |
|
| 86 |
-- Defined inline, no out-of-line version available. |
| 87 |
-- Reimplemented in Ada, with an Ada interface. |
| 88 |
function Equals (this, that : access constant type_info'Class) |
| 89 |
-- return Interfaces.C.Extensions.bool; |
| 90 |
return Boolean; |
| 91 |
-- pragma Import (CPP, Equals, "_ZNKSt9type_infoeqERKS_"); |
| 92 |
pragma Machine_Attribute (Equals, "nothrow"); |
| 93 |
|
| 94 |
-- function "/=" (this : access constant type_info'Class; |
| 95 |
-- arg : access constant type_info'Class) |
| 96 |
-- return Interfaces.C.Extensions.bool; |
| 97 |
-- pragma Import (CPP, "/=", "_ZNKSt9type_infoneERKS_"); |
| 98 |
-- pragma Machine_Attribute ("/=", "nothrow"); |
| 99 |
|
| 100 |
-- Defined inline, no out-of-line version available. |
| 101 |
-- function Hash_Code (this : access constant type_info'Class) |
| 102 |
-- return Interfaces.C.size_t; |
| 103 |
-- pragma Import (CPP, Hash_Code, "_ZNKSt9type_info9hash_codeEv"); |
| 104 |
-- pragma Machine_Attribute (Hash_Code, "nothrow"); |
| 105 |
|
| 106 |
function Is_Pointer_P (this : access constant type_info) |
| 107 |
return Interfaces.C.Extensions.bool; |
| 108 |
pragma Import (CPP, Is_Pointer_P, |
| 109 |
"_ZNKSt9type_info14__is_pointer_pEv"); |
| 110 |
|
| 111 |
function Is_Function_P (this : access constant type_info) |
| 112 |
return Interfaces.C.Extensions.bool; |
| 113 |
pragma Import (CPP, Is_Function_P, |
| 114 |
"_ZNKSt9type_info15__is_function_pEv"); |
| 115 |
|
| 116 |
function Do_Catch |
| 117 |
(this : access constant type_info; |
| 118 |
thrown_type : access constant type_info'Class; |
| 119 |
thrown_object : in out System.Address; |
| 120 |
outer_count : Interfaces.C.unsigned) |
| 121 |
return Interfaces.C.Extensions.bool; |
| 122 |
pragma Import (CPP, Do_Catch, |
| 123 |
"_ZNKSt9type_info10__do_catchEPKS_PPvj"); |
| 124 |
|
| 125 |
function Do_Upcast |
| 126 |
(this : access constant type_info; |
| 127 |
target : access constant type_info'Class; |
| 128 |
obj_ptr : in out System.Address) |
| 129 |
return Interfaces.C.Extensions.bool; |
| 130 |
pragma Import |
| 131 |
(CPP, Do_Upcast, |
| 132 |
"_ZNKSt9type_info11__do_upcastEPKN10" |
| 133 |
& "__cxxabiv117__class_type_infoEPPv"); |
| 134 |
|
| 135 |
private |
| 136 |
|
| 137 |
type type_info is abstract tagged limited record |
| 138 |
Raw_Name : Interfaces.C.Strings.chars_ptr; |
| 139 |
end record; |
| 140 |
|
| 141 |
end GNAT.CPP.Std.Type_Info; |