* [Ada] Add a Is_Foreign_Exception predicate to GNAT.Exception_Actions
@ 2018-05-23 10:33 Pierre-Marie de Rodat
0 siblings, 0 replies; only message in thread
From: Pierre-Marie de Rodat @ 2018-05-23 10:33 UTC (permalink / raw)
To: gcc-patches; +Cc: Olivier Hainque
[-- Attachment #1: Type: text/plain, Size: 324 bytes --]
Useful to check if an occurrence caught by a "when others" choice originates
from a foreign language, e.g. C++.
Tested on x86_64-pc-linux-gnu, committed on trunk
2018-05-23 Olivier Hainque <hainque@adacore.com>
gcc/ada/
* libgnat/g-excact.ads (Is_Foreign_Exception): New predicate.
* libgnat/g-excact.adb: Implement.
[-- Attachment #2: patch.diff --]
[-- Type: text/x-diff, Size: 2177 bytes --]
--- gcc/ada/libgnat/g-excact.adb
+++ gcc/ada/libgnat/g-excact.adb
@@ -91,6 +91,19 @@ package body GNAT.Exception_Actions is
procedure Core_Dump (Occurrence : Exception_Occurrence) is separate;
+ --------------------------
+ -- Is_Foreign_Exception --
+ --------------------------
+
+ function Is_Foreign_Exception (E : Exception_Occurrence) return Boolean is
+ Foreign_Exception : aliased Exception_Data;
+ pragma Import
+ (Ada, Foreign_Exception, "system__exceptions__foreign_exception");
+ begin
+ return (To_Data (Exception_Identity (E))
+ = Foreign_Exception'Unchecked_Access);
+ end Is_Foreign_Exception;
+
----------------
-- Name_To_Id --
----------------
--- gcc/ada/libgnat/g-excact.ads
+++ gcc/ada/libgnat/g-excact.ads
@@ -29,9 +29,11 @@
-- --
------------------------------------------------------------------------------
--- This package provides support for callbacks on exceptions
+-- This package provides support for callbacks on exceptions as well as
+-- exception-related utility subprograms of possible interest together with
+-- exception actions or more generally.
--- These callbacks are called immediately when either a specific exception,
+-- The callbacks are called immediately when either a specific exception,
-- or any exception, is raised, before any other actions taken by raise, in
-- particular before any unwinding of the stack occurs.
@@ -85,6 +87,10 @@ package GNAT.Exception_Actions is
-- Note: All non-predefined exceptions will return Null_Id for programs
-- compiled with pragma Restriction (No_Exception_Registration)
+ function Is_Foreign_Exception (E : Exception_Occurrence) return Boolean;
+ -- Tell whether the exception occurrence E represents a foreign exception,
+ -- such as one raised in C++ and caught by a when others choice in Ada.
+
function Registered_Exceptions_Count return Natural;
-- Return the number of exceptions that have been registered so far.
-- Exceptions declared locally will not appear in this list until their
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2018-05-23 10:33 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-05-23 10:33 [Ada] Add a Is_Foreign_Exception predicate to GNAT.Exception_Actions Pierre-Marie de Rodat
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).