I'm using SPARK.Text_IO from the spark_io example in SPARK Discovery 2017.
My problem is that many of the SPARK.Text_IO procedures have a precondition that I do not know how to begin to try to prove namely that the standard input is readable and we're not at end of file. My attempt, as displayed in the code below, was to add the precondition of the SPARK.Text_IO procedure (Get_Immediate in this case) to the precondition of the calling procedure, thinking that maybe that would guarantee to the prover that that precondition would be true. It didn't work. Here's an example of what I'm talking about:
Test spec:
with SPARK.Ada.Text_IO; use SPARK.Ada.Text_IO;
package test with SPARK_Mode
is
continue_messages_key : Character := ' ';
procedure User_Wait_For_Continue_Messages_Key
with Global => (In_Out => Standard_Input,
Input => continue_messages_key),
Pre => Is_Readable (Standard_Input) and then
not End_Of_File;
end test;
Test body:
pragma SPARK_Mode(On);
package body test is
procedure User_Wait_For_Continue_Messages_Key
is
IR : Immediate_Result;
Avail : Boolean;
begin
loop
Get_Immediate(IR, Avail);
if Avail then
if IR.Status = Success then
if IR.Available = True then
if IR.Item = continue_messages_key then
return;
end if;
end if;
end if;
end if;
end loop;
end User_Wait_For_Continue_Messages_Key;
end test;
The error the prover gives is on the Get_Immediate line "medium: precondition might fail" The prototype and contract of the Get_Immediate procedure is below:
procedure Get_Immediate (Item : out Character_Result)
with Global => (In_Out => Standard_Input),
Pre => Is_Readable (Standard_Input) and then
not End_Of_File,
Post => Is_Readable (Standard_Input) and
Name (Standard_Input) = Name (Standard_Input)'Old and
Form (Standard_Input) = Form (Standard_Input)'Old and
Is_Standard_Input (Standard_Input);
How do you prove to SPARK that Standard_Input is readable and that it's not end of file?