comp.lang.ada
 help / color / mirror / Atom feed
* SPARK - refactoring and refinement of own state
@ 2009-08-20  7:18 Maciej Sobczak
  2009-08-20  7:37 ` Georg Bauhaus
  2009-08-20  8:11 ` Rod Chapman
  0 siblings, 2 replies; 5+ messages in thread
From: Maciej Sobczak @ 2009-08-20  7:18 UTC (permalink / raw)


I have a problem that can be reduced to a simple hello world program
in SPARK.
Consider the following:

with Spark_IO;
--# inherit Spark_IO;

--# main_program;
procedure Hello
  --# global in out Spark_IO.Outputs;
  --# derives Spark_IO.Outputs from *;
is
begin
   Spark_IO.Put_String (File => Spark_IO.Standard_Output,
                        Item => "Hello ",
                        Stop => 0);
end Hello;

Let's suppose that I want to refactor it a bit and move the details of
printing to some other package and use that other package from the
main program. In other words, I want to isolate the main program from
Spark_IO.
Consider this package spec:

package Greetings
  --# own State;
  --# initializes State;
is

   procedure Say_Hello;
   --# global in out State;
   --# derives State from *;

end Greetings;

The main program then becomes:

with Greetings;
--# inherit Greetings;

--# main_program;
procedure Hello
  --# global in out Greetings.State;
  --# derives Greetings.State from *;
is
begin
   Greetings.Say_Hello;
end Hello;

The SPARK Examiner is happy with both the main program and the spec
for the Greetings package.

The problem is with the package body.
This is what I believe should work:

with Spark_IO;
--# inherit Spark_IO;

package body Greetings
  --# own State is Spark_IO.Outputs;
is

   procedure Say_Hello
     --# global in out Spark_IO.Outputs;
     --# derives Spark_IO.Outputs from *;
   is
   begin
      Spark_IO.Put_String (File => Spark_IO.Standard_Output,
                           Item => "Hello ",
                           Stop => 0);
   end Say_Hello;

end Greetings;

However, the examiner says:

   4  package body Greetings
              ^
***        Syntax Error      : No DOTTED_SIMPLE_NAME can start with
reserved
           word "BODY".

What is most interesting is that after removing the inherit clause
from the package body the examiner no longer complains about the
"body" keyword, but of course fails later on with the "Spark_IO"
procedure prefix, which is reported as undeclared or not visible
(semantic error 142).

The whole problem is really about refining the own state of some
package in terms of the abstract own state of some other package. I
have not found anything about this in the SPARK documentation and the
error message about the "body" keyword is confusing.

Am I going in the right direction anyway? Is this kind of refactoring
and refinement possible?

--
Maciej Sobczak * www.msobczak.com * www.inspirel.com

Database Access Library for Ada: www.inspirel.com/soci-ada



^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2009-08-20  8:44 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-08-20  7:18 SPARK - refactoring and refinement of own state Maciej Sobczak
2009-08-20  7:37 ` Georg Bauhaus
2009-08-20  8:06   ` Rod Chapman
2009-08-20  8:11 ` Rod Chapman
2009-08-20  8:44   ` Maciej Sobczak

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