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] Reorganize handling of predicates


This reorganizes the handling of predicates, in preparation for proper
implementation of real predicates. Several minor errors are corrected
and we properly reject improper static real predicates. Static string
predicates are now always rejected, in line with latest ARG thinking.
The following shows how far we have got. Quite a few minor errors are
fixed in recognizing predicate-static expressions. Still to be done
is actual compile-time testing of real static predicates, and also
noting that constants for which a predicate fails should not be
considered as static.

     1. package TestSP is
     2.    subtype F1 is Float with -- OK
     3.      Static_Predicate => F1 > 0.0 and 4.7 > F1;
     4.    subtype F2 is Float with -- ERROR
     5.      Static_Predicate => (F2 + 1.0) > 0.0 and 4.7 > F2;
                                  |
        >>> expression is not predicate-static (RM 4.3.2(16-22))

     6.    subtype F3 is Float with -- OK
     7.      Dynamic_Predicate => (F3 + 1.0) > 0.0 and 4.7 > F3;
     8.    subtype F4 is Float with -- OK
     9.      Predicate => (F4 + 1.0) > 0.0 and 4.7 > F4;
    10.
    11.    subtype S1 is String with -- OK
    12.      Static_Predicate => S1 > "ABC" and then "DEF" >= S1;
    13.    subtype S2 is String with -- ERROR
    14.      Static_Predicate => S2'First = 1 and then S2(1) = 'A';
                                 |
        >>> static predicate not allowed for non-scalar type "S2"

    15.    subtype S3 is String with -- OK
    16.      Dynamic_Predicate => S3'First = 1 and then S3(1) = 'A';
    17.    subtype S4 is String with -- OK
    18.      Predicate => S4'First = 1 and then S4(1) = 'A';
    19.
    20.    subtype I1 is Integer with -- OK
    21.      Static_Predicate => I1 > 0 and 4 > I1;
    22.    subtype I2 is Integer with -- ERROR
    23.      Static_Predicate => (I2 + 1) > 0 and 4 > I2;
                                  |
        >>> expression is not predicate-static (RM 4.3.2(16-22))

    24.    subtype I3 is Integer with -- OK
    25.      Dynamic_Predicate => (I3 + 1) > 0 and 4 > I3;
    26.    subtype I4 is Integer with -- OK
    27.      Predicate => (I4 + 1) > 0 and 4 > I4;
    28.    subtype I5 is Integer with -- ERROR (not caught before)
    29.      Static_Predicate => Boolean'(I5 > 0);
                                 |
        >>> expression is not predicate-static (RM 4.3.2(16-22))

    30.
    31.    XF1 : constant F1 := 10.0;
                                |
        >>> warning: real predicate not applied

    32.    XF2 : constant F1 := 3.0;
                                |
        >>> warning: real predicate not applied

    33.    XF3 : constant := XF1; -- ERROR (not caught yet)
    34.
    35.    XI1 : constant I1 := 10;
                                |
        >>> warning: static expression fails predicate check on "I1"

    36.    XI2 : constant I1 := 3;
    37.    XI3 : constant := XI1; -- ERROR (not caught yet)
    38. end;

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

2014-07-18  Robert Dewar  <dewar@adacore.com>

	* einfo.adb (Has_Static_Predicate): New function.
	(Set_Has_Static_Predicate): New procedure.
	* einfo.ads (Has_Static_Predicate): New flag.
	* sem_ch13.adb (Is_Predicate_Static): New function
	(Build_Predicate_Functions): Use Is_Predicate_Static to reorganize
	(Add_Call): Minor change in Sloc of generated expression
	(Add_Predicates): Remove setting of Static_Pred, no longer used.
	* sem_ch4.adb (Has_Static_Predicate): Removed this function,
	replace by use of the entity flag Has_Static_Predicate_Aspect.
	* sem_eval.adb (Eval_Static_Predicate_Check): Check real case
	and issue warning that predicate is not checked for now.
	* sem_eval.ads (Eval_Static_Predicate_Check): Fix comments in
	spec.
	* sem_util.adb (Check_Expression_Against_Static_Predicate):
	Carry out check for any case where there is a static predicate,
	and output appropriate message.
	* sinfo.ads: Minor comment corrections.

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]