comp.lang.ada
 help / color / mirror / Atom feed
From: "Randy Brukardt" <randy@rrsoftware.com>
Subject: Re: Class wide preconditions: error in GNAT implementation?
Date: Fri, 15 Feb 2013 19:01:53 -0600
Date: 2013-02-15T19:01:53-06:00	[thread overview]
Message-ID: <kfmlq1$puv$1@munin.nbi.dk> (raw)
In-Reply-To: e155e2d6-ba1f-4fc0-a6e3-dafde002670b@googlegroups.com

"ytomino" <aghia05@gmail.com> wrote in message 
news:e155e2d6-ba1f-4fc0-a6e3-dafde002670b@googlegroups.com...
...
>% gnatmake -gnat2012 -gnata precondmain.adb
>% ./precondmain
>B, in!
>B, out!
>A, out!
>
>And change [*] to Pre'Class => Tools.Write_In_Expr ("B, in!") and False,
>
>% gnatmake -gnat2012 -gnata precondmain.adb
>% ./precondmain
>B, in!
>A, in!
>B, out!
>A, out!

This looks right to me (well, actually not quite, see far below).

>It seems that the preconditions were evaluated as pragma Assert 
>(B'Pre'Class and then A'Pre'Class);

Class-wide Preconditions are combined with "or", not "and". And of course 
Once you get True for "or", you don't need to evaluate any more of them. See 
6.1.1(33/3)- "if and only if all ... evaluated to False".

The order of evaluation of these expressions is unspecified, so which one 
gets evaluated depends on the compiler.

Postconditions (and specific preconditions) are combined with "and".

The reasons for this are found in the theories of LSP. I could explain it, 
but it would take me all day, and you'd probably be more confused than you 
started. :-) (It took a long time for most of the ARG, me included, to 
understand this well enough to determine whether or not the features were 
properly defined.)

OTOH, I didn't realize that you had a dispatching call. In that case, the 
precondition is supposed to just be the Pre'Class for A, which is stronger 
that A or B which a direct call would use. Probably GNAT dispatched and then 
checked the precondition. Technically, that's wrong (although I would have a 
hard time caring, the reason for the stronger precondition on dispatching 
calls is to allow analysis without knowing the actual tag, it doesn't have 
anything to do with correctness).

                                 Randy.





  parent reply	other threads:[~2013-02-16  1:01 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-02-15  3:55 Class wide preconditions: error in GNAT implementation? ytomino
2013-02-15 10:15 ` Georg Bauhaus
2013-02-15 13:16   ` ytomino
2013-02-16  1:01 ` Randy Brukardt [this message]
2013-02-16  2:50   ` ytomino
2013-02-16  9:28     ` Dmitry A. Kazakov
2013-02-16 13:13       ` ytomino
2013-02-16 16:35         ` Dmitry A. Kazakov
2013-02-16 19:55           ` ytomino
2013-02-16 20:34             ` ytomino
2013-02-18  8:30             ` Dmitry A. Kazakov
2013-02-18  9:17               ` Simon Wright
2013-02-18 14:25                 ` Dmitry A. Kazakov
2013-02-18 18:04                   ` Simon Wright
2013-02-18 19:27                     ` Dmitry A. Kazakov
2013-02-18 20:42                       ` Simon Wright
2013-02-19  9:07                         ` Dmitry A. Kazakov
2013-02-18 19:02               ` ytomino
2013-02-18 19:44                 ` Dmitry A. Kazakov
2013-02-16 15:16       ` Georg Bauhaus
2013-02-16 20:23   ` Simon Wright
2013-02-17 15:12     ` ytomino
2013-02-18 17:49       ` Simon Wright
2013-02-18 18:45         ` ytomino
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox