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 Predicate_Check


This implements a new check name Predicate_Check that can be used in
Suppress and Unsuppress pragmas. This allows predicate checks to be
turned on and off for specific sections of code (unlike the effect
of Assertion_Policy which is to enable or disable predicates at the
point where they are defined).

The following compiled with -gnata prints

OK 1
OK 2

     1. pragma Ada_2012;
     2. with Text_IO; use Text_IO;
     3. procedure Pcheck is
     4.    pragma Assertion_Policy (Predicate => Check);
     5.    type R is new Integer with
     6.      Dynamic_Predicate => R in 1 .. 10;
     7.    R1 : R;
     8.
     9. begin
    10.    declare
    11.       pragma Suppress (Predicate_Check);
    12.    begin
    13.       R1 := 11;
    14.       Put_Line ("OK 1");
    15.
    16.       declare
    17.          pragma Unsuppress (Predicate_Check);
    18.       begin
    19.          R1 := 11;
    20.          Put_Line ("Not OK 1");
    21.       exception
    22.          when others =>
    23.             Put_Line ("OK 2");
    24.       end;
    25.    exception
    26.       when others =>
    27.          Put_Line ("Not OK 2");
    28.    end;
    29. end Pcheck;

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

2013-04-24  Robert Dewar  <dewar@adacore.com>

	* checks.ads, checks.adb (Predicate_Checks_Suppressed): New function.
	* exp_util.ads, exp_util.adb (Make_Predicate_Check): Check setting of
	Predicate_Check.
	* snames.ads-tmpl (Name_Predicate_Check): New check name.
	* types.ads (Predicate_Check): New definition.
	* gnat_rm.texi: Add documentation for Predicate_Check.

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]