Ada 防火花注释

Ada 防火花注释,ada,spark-ada,Ada,Spark Ada,您好,我正在尝试从该函数编写校对注释。。这是使用Spark编程语言编写的 function Read_Sensor_Majority return Sensor_Type is count1:Integer:=0; count2:Integer:=0; count3:Integer:=0; overall:Sensor_Type; begin for index in Integer range 1..3 loop

您好,我正在尝试从该函数编写校对注释。。这是使用Spark编程语言编写的

function Read_Sensor_Majority return Sensor_Type is
       count1:Integer:=0;
       count2:Integer:=0;
       count3:Integer:=0;

      overall:Sensor_Type;

   begin


      for index in Integer range 1..3 loop
         if State(index) = Proceed then
           count1:=count1+1;
         elsif State (index) = Caution then
            count2:=count2+1;
         elsif State (index)=Danger then
            count3:=count3+1;
         end if;
      end loop;

      if count1>=2 then
         overall:=Proceed;
      elsif count2>=2 then
         overall:=Caution;
      elsif count3>=2 then
         overall:=Danger;
      else
         overall:=Undef;
      end if;

      return overall;

   end Read_Sensor_Majority;

   begin -- initialization
   State:= Sensordata'(Sensor_Index_Type => Undef);
end Sensors;

这是.ads文件

package Sensors
   --# own State;
   --# initializes State;
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;
   --# derives State from State ,Value_1, Value_2, Value_3;

   function Read_Sensor(Sensor_Index: in Sensor_Index_Type) return Sensor_Type;
   --# global in State;

   function Read_Sensor_Majority return Sensor_Type;
   --# global in State;
   --# return overall => (count1>=2 -> overall=Proceed) and
   --#                   (count2>=2 -> overall=Caution) and
   --#                   (count3>=2 -> overall=Danger);


end Sensors;
这些是我在使用spark检查器检查文件后遇到的错误

Examiner Semantic Error   1 - The identifier count1 is either undeclared or not visible at this point. <b>34:27</b>     Semantic Error   1 - The identifier count1 is either undeclared or not visible at this point. Examiner
Sensors.ads:34:27
Semantic Error   1 - The identifier count1 is either undeclared or not visible at this point.
检查者语义错误1-标识符count1未声明或此时不可见。34:27语义错误1-标识符count1未声明或此时不可见。审查员
传感器ads:34:27
语义错误1-标识符count1未声明或此时不可见。

鉴于您正在显示.ads和.adb文件,我注意到.ads文件中的证明引用了正文中的项目。可能是验证者无法进入身体并拉动这些变量吗?(即可见性问题。)

信息:
标识符count1未声明或此时不可见。

似乎表明情况就是这样


我不知道SPARK,所以这是我最好的猜测。

在引用标识符之前必须声明标识符(有些例外)

最重要的是,SPARK和Ada的一个基本原则是,可以在不了解任何可能的匹配实现的情况下处理规范

由于规范中既没有声明
总体
,也没有声明
count1
count2
count3
,因此也不能在此处引用它们

两个小旁注:

  • 请使用与语言参考手册中相同的标识符样式。(前导大写字母,下划线分隔单词。)
  • 为什么
    Sensor\u Index\u Type
    Integer
    的子类型

    • 我只是在玩弄SPARK,所以这不是一个完整的答案

      (值得一提的是哪个SPARK,因为有不同的版本,SPARK-2014似乎与其他版本有很大的不同)我目前只有2006年版,其中不包括最新版本

      基本问题非常明显:提供了包状态的抽象视图
      ——#自己的状态在规范中,您无法进入并观察细节

      我并不完全清楚该怎么做,但它的轮廓形式如下: 为规范中的大多数读者提供更抽象的后置条件形式,并将具体形式移到正文中

      Ada-2012中采用的一种方法(我不知道如何适用于Spark-2005)是在spec
      函数满足_条件(…)返回布尔值中提供一个附加函数可以在注释中调用,其主体包含具体实现


      Barnes(上面的编辑)第278页确实显示了“证明函数”,可以在注释中声明这些函数。然后,他们的身体可以访问内部状态以执行具体检查。

      为什么要将其标记为java?显然,这是因为有一种叫做Spark的java工具包。不要与SPARK混淆!java和C++标签似乎都错了。是的,我想这就是问题所在。但我不知道如何解决这个问题。也许把注释移到主体上?