From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: a07f3367d7,2901996ead8d0ecd,start X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII-7-bit X-Received: by 10.224.178.207 with SMTP id bn15mr4431469qab.1.1360374733748; Fri, 08 Feb 2013 17:52:13 -0800 (PST) X-Received: by 10.49.60.40 with SMTP id e8mr592589qer.40.1360374733724; Fri, 08 Feb 2013 17:52:13 -0800 (PST) Path: k2ni21154qap.0!nntp.google.com!p13no3863595qai.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Fri, 8 Feb 2013 17:52:13 -0800 (PST) Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=149.32.224.33; posting-account=Qh2kiQoAAADpCLlhT_KTYoGO8dU3n4I6 NNTP-Posting-Host: 149.32.224.33 User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: Subject: Assertion_Policy implementation regarding Aspect Features From: Anh Vo Injection-Date: Sat, 09 Feb 2013 01:52:13 +0000 Content-Type: text/plain; charset=ISO-8859-1 Date: 2013-02-08T17:52:13-08:00 List-Id: I revisited "about the new Ada 2012 pre/post conditions" thread posted by Nasser M. Abbasi, https://groups.google.com/forum/?fromgroups#!search/aspect$20example$20in$20Ada$202012/comp.lang.ada/t4w2M1NVFwI/qOXDIyT6JJ0J. This inspires me to learn this feature a little bit deeper. I would like to know if GNAT comply with ARM by showing the following scenarios. ------------ Scenario 1 -------------- with Ada.Text_Io; with Ada.Exceptions; use Ada; procedure Predicates_Test is use Text_Io; type Even is new Integer range 0 .. Integer'Last with Dynamic_Predicate => Even mod 2 = 0, Default_Value => 0; My_Number : Even; -- set to 0 by default begin Put_Line ("Predicates_Test starts"); Put_Line ("Initial My_Number => " & My_Number'Img); My_Number := 3; -- intentionally violate predicate rules Put_Line ("Final My_Number => " & My_Number'Img); Put_Line ("Predicates_Test ends"); exception when Err : others => Put_Line ("Houston we have a problem: " & Exceptions.Exception_Information(Err)); end Predicates_Test; For scenario 1 the code is compiled with gnatmake -gnat12 -gnata. When running this program, the output is as follows: Predicates_Test starts My_Number => 0 Houston we have a problem: Exception name: SYSTEM.ASSERTIONS.ASSERT_FAILURE Message: predicate failed at predicates_test.adb:16 Observation: GNAT implemented the Aspect feature even pragma Assertion_Policy (Check) is not present. ------------ Scenario 2 -------------- pragma Assertion_Policy (Check); with Ada.Text_Io; with Ada.Exceptions; use Ada; procedure Predicates_Test is use Text_Io; type Even is new Integer range 0 .. Integer'Last with Dynamic_Predicate => Even mod 2 = 0, Default_Value => 0; My_Number : Even; -- set to 0 by default begin Put_Line ("Predicates_Test starts"); Put_Line ("Initial My_Number => " & My_Number'Img); My_Number := 3; -- intentionally violate predicate rules Put_Line ("Final My_Number => " & My_Number'Img); Put_Line ("Predicates_Test ends"); exception when Err : others => Put_Line ("Houston we have a problem: " & Exceptions.Exception_Information(Err)); end Predicates_Test; For scenario 2, it is compliled with gnatmake -gnat12. Then running this program yielding output as Predicates_Test starts Initial My_Number => 0 Final My_Number => 3 Predicates_Test ends Observation: GNAT did not implement the Aspect feature even though pragma Assertion_Policy (Check) is present. ------------ Scenario 3 -------------- pragma Assertion_Policy (Check); with Ada.Text_Io; with Ada.Exceptions; use Ada; procedure Predicates_Test is use Text_Io; type Even is new Integer range 0 .. Integer'Last with Dynamic_Predicate => Even mod 2 = 0, Default_Value => 0; My_Number : Even; -- set to 0 by default begin Put_Line ("Predicates_Test starts"); Put_Line ("Initial My_Number => " & My_Number'Img); My_Number := 3; -- intentionally violate predicate rules Put_Line ("Final My_Number => " & My_Number'Img); Put_Line ("Predicates_Test ends"); exception when Err : others => Put_Line ("Houston we have a problem: " & Exceptions.Exception_Information(Err)); end Predicates_Test; For scenario 3, it is compliled with gnatmake -gnat12 -gnata. Then running this program yielding output as below. Predicates_Test starts Initial My_Number => 0 Houston we have a problem: Exception name: SYSTEM.ASSERTIONS.ASSERT_FAILURE Message: predicate failed at predicates_test.adb:17 Observation: GNAT implements Aspect feature through compiler option. Thanks in advance for your insight. Anh Vo