| 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 |
-- B o d y -- |
| 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 |
with System; use System; |
| 33 |
with System.Storage_Elements; use System.Storage_Elements; |
| 34 |
with Interfaces.C; use Interfaces.C; |
| 35 |
with Interfaces.C.Extensions; use Interfaces.C.Extensions; |
| 36 |
with Interfaces.C.Strings; use Interfaces.C.Strings; |
| 37 |
with Ada.Unchecked_Conversion; |
| 38 |
|
| 39 |
package body GNAT.CPP.Std.Type_Info is |
| 40 |
|
| 41 |
function strcmp (L, R : chars_ptr) return Interfaces.C.int; |
| 42 |
pragma Import (Intrinsic, strcmp, "__builtin_strcmp"); |
| 43 |
|
| 44 |
function Name_Starts_With_Asterisk (this : access constant type_info'Class) |
| 45 |
return Boolean; |
| 46 |
|
| 47 |
function Name_Past_Asterisk (this : access constant type_info'Class) |
| 48 |
return chars_ptr; |
| 49 |
|
| 50 |
function To_Address is |
| 51 |
new Ada.Unchecked_Conversion (chars_ptr, System.Address); |
| 52 |
function To_Pointer is |
| 53 |
new Ada.Unchecked_Conversion (System.Address, chars_ptr); |
| 54 |
|
| 55 |
function Name_Starts_With_Asterisk (this : access constant type_info'Class) |
| 56 |
return Boolean is |
| 57 |
Addr : constant System.Address := To_Address (this.Raw_Name); |
| 58 |
C : aliased char; |
| 59 |
for C'Address use Addr; |
| 60 |
begin |
| 61 |
return C = '*'; |
| 62 |
end Name_Starts_With_Asterisk; |
| 63 |
|
| 64 |
function Name_Past_Asterisk (this : access constant type_info'Class) |
| 65 |
return chars_ptr is |
| 66 |
Addr : System.Address := To_Address (this.Raw_Name); |
| 67 |
begin |
| 68 |
if this.Name_Starts_With_Asterisk then |
| 69 |
Addr := Addr + Storage_Offset (1); |
| 70 |
end if; |
| 71 |
|
| 72 |
return To_Pointer (Addr); |
| 73 |
end Name_Past_Asterisk; |
| 74 |
|
| 75 |
------------ |
| 76 |
-- Name -- |
| 77 |
------------ |
| 78 |
|
| 79 |
function Name (this : access constant type_info'Class) |
| 80 |
return chars_ptr |
| 81 |
is (this.Name_Past_Asterisk); |
| 82 |
|
| 83 |
-------------- |
| 84 |
-- Before -- |
| 85 |
-------------- |
| 86 |
|
| 87 |
function Before (this, that : access constant type_info'Class) |
| 88 |
return Boolean is |
| 89 |
begin |
| 90 |
if not this.Name_Starts_With_Asterisk |
| 91 |
or else not that.Name_Starts_With_Asterisk |
| 92 |
then |
| 93 |
return strcmp (this.Raw_Name, that.Raw_Name) < 0; |
| 94 |
end if; |
| 95 |
|
| 96 |
return To_Address (this.Raw_Name) < To_Address (that.Raw_Name); |
| 97 |
end Before; |
| 98 |
|
| 99 |
-------------- |
| 100 |
-- Equals -- |
| 101 |
-------------- |
| 102 |
|
| 103 |
function Equals (this, that : access constant type_info'Class) |
| 104 |
return Boolean is |
| 105 |
begin |
| 106 |
if this = that then |
| 107 |
return True; |
| 108 |
end if; |
| 109 |
|
| 110 |
if this.Name_Starts_With_Asterisk then |
| 111 |
return False; |
| 112 |
end if; |
| 113 |
|
| 114 |
return strcmp (this.Raw_Name, that.Raw_Name) = 0; |
| 115 |
end Equals; |
| 116 |
|
| 117 |
function Convert_Caught_Object (Choice, Except : access type_info'Class; |
| 118 |
Thrown : in out Address; |
| 119 |
Lang : Character) |
| 120 |
return Interfaces.C.C_bool; |
| 121 |
pragma Export (Cpp, Convert_Caught_Object, "__gnat_convert_caught_object"); |
| 122 |
-- Convert the exception object at Thrown, under Lang convention, |
| 123 |
-- from type Except to type Choice, adjusting Thrown as needed and |
| 124 |
-- returning True, or returning False in case the conversion |
| 125 |
-- fails. This is called from raise-gcc, and it is placed here |
| 126 |
-- rather than in GNAT.CPP_Exceptions to avoid dragging all that |
| 127 |
-- in when the program doesn't use C++ exceptions. |
| 128 |
|
| 129 |
--------------------------- |
| 130 |
-- Convert_Caught_Object -- |
| 131 |
--------------------------- |
| 132 |
|
| 133 |
function Convert_Caught_Object (Choice, Except : access type_info'Class; |
| 134 |
Thrown : in out Address; |
| 135 |
Lang : Character) |
| 136 |
return Interfaces.C.C_bool is |
| 137 |
begin |
| 138 |
if Choice.Equals (Except) then |
| 139 |
return C_bool'(True); |
| 140 |
end if; |
| 141 |
|
| 142 |
if Lang = 'B' then |
| 143 |
if Except.Is_Pointer_P then |
| 144 |
declare |
| 145 |
Thrown_Indirect : Address; |
| 146 |
for Thrown_Indirect'Address use Thrown; |
| 147 |
begin |
| 148 |
Thrown := Thrown_Indirect; |
| 149 |
end; |
| 150 |
end if; |
| 151 |
|
| 152 |
if Choice.Do_Catch (Except, Thrown, 1) then |
| 153 |
return C_bool'(True); |
| 154 |
end if; |
| 155 |
end if; |
| 156 |
|
| 157 |
return C_bool'(False); |
| 158 |
end Convert_Caught_Object; |
| 159 |
|
| 160 |
end GNAT.CPP.Std.Type_Info; |