我正在使用 SPARK Discovery 2017 中 spark_io 示例中的 SPARK.Text_IO。
我的问题是,许多 SPARK.Text_IO 过程都有一个前提条件,即我不知道如何开始尝试证明标准输入是可读的并且我们不在文件末尾。如下面的代码所示,我的尝试是将 SPARK.Text_IO 过程(在本例中为 Get_Immediate)的前提条件添加到调用过程的前提条件中,认为这可能会向证明者保证该前提条件为真. 它没有用。这是我正在谈论的一个例子:
测试规格:
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;
测试机构:
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;
证明者给出的错误在 Get_Immediate 行“medium: precondition may fail” Get_Immediate 过程的原型和合同如下:
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);
你如何向 SPARK 证明 Standard_Input 是可读的并且它不是文件结尾?