【发布时间】:2011-11-14 21:46:53
【问题描述】:
我正在使用 SPARK 方法对 Ada 进行自动列车保护。这是我在 SPARK 中的规范:
package Sensors
--# own State,Pointer,State1,State2;
--# initializes State,Pointer,State1,State2;
is
type Sensor_Type is (Proceed, Caution, Danger, Undef);
subtype Sensor_Index_Type is Integer range 1..3;
procedure Write_Sensors(Value_1, Value_2, Value_3: in Sensor_Type);
--# global in out State,Pointer;
--# derives State from State,Value_1, Value_2, Value_3,Pointer &
--# Pointer from Pointer;
function Read_Sensor(Sensor_Index: in Sensor_Index_Type) return Sensor_Type;
function Read_Sensor_Majority return Sensor_Type;
end Sensors;
这是我的阿达:
package body Sensors is
type Vector is array(Sensor_Index_Type) of Sensor_Type;
State: Vector;
Pointer:Integer;
State1:Sensor_Type;
State2:Sensor_Type;
procedure Write_Sensors(Value_1, Value_2, Value_3: in Sensor_Type) is
begin
State(Pointer):=Value_1;
Pointer:= Pointer + 1;
State(Pointer):=Value_2;
Pointer:= Pointer + 1;
State(Pointer):=Value_3;
end Write_Sensors;
function Read_Sensor (Sensor_Index: in Sensor_Index_Type) return Sensor_Type
is
State1:Sensor_Type;
begin
State1:=Proceed;
if Sensor_Index=1 then
State1:=Proceed;
elsif Sensor_Index=2 then
State1:=Caution;
elsif Sensor_Index=3 then
State1:=Danger;
end if;
return State1;
end Read_Sensor;
function Read_Sensor_Majority return Sensor_Type is
State2:Sensor_Type;
begin
State2 := state(1);
return State2;
end Read_Sensor_Majority;
begin -- initialization
State:=Vector'(Sensor_Index_Type =>Proceed);
pointer:= 0;
State1:=Proceed;
State2:=Proceed;
end Sensors;
我想知道为什么在函数 Read_Sensor_Majority 中我不能使用 State(1) 或任何 State() 数组值。如果有使用它们的方法,我应该在 SPARK 的规格中添加任何内容来实现它吗?
它显示的错误是:
1)Expression contains referenced to variable state which has an undefined value flow error 20
2)the variable state is nether imported nor defined flow error 32
3)the undefined initial value of state maybe used in the derivation of the function value flow error 602
【问题讨论】:
-
(1) 我不知道 SPARK 工具集,但是错误消息没有给您一些提示吗?也许如果您发布它们,它会帮助我们帮助您。 (2) SPARK Ada 必须是合法的 Ada,但你最后对 State 的初始化不是。我想你的意思是说
State := Vector'(others => Proceed);。 (3) 您的代码已经出现相当混乱,如果它更整洁,我们会帮助您! -
在这里备份西蒙。我怀疑您的“我不能使用状态数组值”等同于普通编译错误。如果没有看到有问题的错误,我们真的没有什么可做的了。
-
好的,我在问题末尾添加了错误
标签: arrays function ada spark-ada