This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Ada] Implement new pragma Prefix_Exception_Messages


This implements a new configuration pragma

    pragma Prefix_Exception_Messages;

which causes messages set using "raise x with s" to be
prefixed by the expanded name of the enclosing entity if
s is a string literal (if s is more complex, we assume
the program is calculating exactly the message it wants).

So for example, if we have the program:

      1. pragma Prefix_Exception_Messages;
      2. procedure Prefixem is
      3.    procedure Inner is
      4.    begin
      5.       raise Constraint_Error with "explicit raise";
      6.    end;
      7. begin
      8.    Inner;
      9. end Prefixem;

The output will be:

raised CONSTRAINT_ERROR : Prefixem.Inner: explicit raise

This mode is automatic for run-time library files, so
a typical message from the runtime library which used to
look like:

raised GNAT.CALENDAR.TIME_IO.PICTURE_ERROR :
null picture string

now looks like:

raised GNAT.CALENDAR.TIME_IO.PICTURE_ERROR :
GNAT.Calendar.Time_IO.Image: null picture string

In the case of instantiations of containers, you will get the full
qualified name of the particular instantiation that is involved. For
example, the following program:

      1. with Ada.Containers.Ordered_Sets;
      2. procedure NoElmt is
      3.    package Ordered_Integer_Sets is
      4.      new Ada.Containers.Ordered_Sets (Integer);
      5.    use Ordered_Integer_Sets;
      6. begin
      7.    if No_Element < No_Element then
      8.       null;
      9.    end if;
     10. end;

will output

raised CONSTRAINT_ERROR :
NoElmt.Ordered_Integer_Sets."<": Left cursor equals No_Element

This allows disambiguation of messages without reintroducing
line numbers which are problematic for maintaining tests over
different versions and targets.

Tested on x86_64-pc-linux-gnu, committed on trunk

2014-10-10  Robert Dewar  <dewar@adacore.com>

	* exp_ch11.adb (Expand_N_Raise_Statement): Handle
	Prefix_Exception_Messages.
	* opt.adb: Handle new flags Prefix_Exception_Message[_Config].
	* opt.ads: New flags Prefix_Exception_Message[_Config].
	* par-prag.adb: New dummy entry for pragma Prefix_Exception_Messages.
	* snames.ads-tmpl: Add entries for new pragma Prefix_Exception_Messages.
	* sem_prag.adb: Implement new pragma Prefix_Exception_Messages
	* gnat_rm.texi: Document pragma Prefix_Exception_Messages.

Attachment: difs
Description: Text document


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]