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] A static predicate can be specified by a Case expression.


This patch completes the implementation of Ada 2012 static predicates, by
adding support for case expressions that can be transformed into a statically
evaluable expression on values of the subtype. Compiling:

    gcc -c -gnata test_predicate.adb

must yield:

test_predicate.adb:11:20:
     warning: static expression fails static predicate check on "Weekend"
test_predicate.adb:19:25:
     warning: static expression fails static predicate check on "French_School"

---
with Text_IO; use Text_IO;
procedure Test_Predicate is

    type Days is (Sun, Mon, Tue, Wed, Thu, Fri, Sat);

    subtype Weekend is Days with Static_Predicate =>
      (case Weekend is
         when Sat | Sun => True,
         when Mon .. Fri => False);

    W : Weekend := Tue;
    subtype French_School is Days with Static_Predicate =>
      (case French_School is
         when Mon  | Tue => True,
         when Wed => False,
         when Thu..Fri => True,
         when Sat | Sun => False);
         
   J : French_School := Wed;
begin
    Put_Line (W'Img);
end Test_Predicate;

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

2014-07-16  Ed Schonberg  <schonberg@adacore.com>

	* exp_ch4.adb (Expand_N_Case_Expression): Do not expand case
	expression if it is the specification of a subtype predicate:
	it will be expanded when the return statement is analyzed, or
	when a static predicate is transformed into a static expression
	for evaluation by the front-end.
	* sem_ch13.adb (Get_RList): If the expression for a static
	predicate is a case expression, extract the alternatives of the
	branches with a True value to create the required statically
	evaluable expression.

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]