ada - 如何在将过程作为访问参数的过程/函数的前/后契约(Contract)中访问过程的参数?

标签 ada spark-ada

Containers.Vector 包定义了一些过程,这些过程可以访问作为参数的过程。该程序支持一个参数。

示例:

procedure Update_Element
  (Container : in out Vector;
   Index     : in     Index_Type;
   Process   : not null access procedure (E : in out Element_Type));

procedure Query_Element
  (Container : in Vector;
   Index     : in Index_Type;
   Process   : not null access procedure (E : in Element_Type));

是否有可能在过程 Query_ElementUpdate_Element 的 Pre 和 Post 契约中使用 E

写这样的东西:

procedure Update_Element
  (Container : in out Vector;
   Index     : in     Index_Type;
   Process   : not null access procedure (E : in out Element_Type))
with Post => Element(Container,Index) = E;

导致编译错误:"E"is undefined

如果可能,该解决方案应与 Spark 兼容。

最佳答案

据我所知,Ada (2012) 的当前标准不允许在子程序指针上有契约。它将在下一个 Ada 标准版本(目前称为 202x)中被允许。有关它的更多信息,以及示例:

https://docs.adacore.com/spark2014-docs/html/ug/en/source/access.html#contracts-for-subprogram-pointers

关于ada - 如何在将过程作为访问参数的过程/函数的前/后契约(Contract)中访问过程的参数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69556260/

相关文章:

c - Ada 到 C : Value of argument changes on imported function across languages

ada - 没有可用于程序/功能的全局契约(Contract)

ada - "Taking on a Challenge in SPARK Ada"- 在具有意外行为的后置条件中求和幽灵函数

ada - 即使在程序结束时断言并为相同的条件,也不能证明程序的后置条件

ada - 如何在ada中分配除一个元素之外的所有元素?

Ada 条目和when 语句的使用

Java/Ada Big Endian 到 Linux Little Endian 问题

linux - Ada POSIX 绑定(bind)和多套 IPC 的 POSIX 接口(interface)

ada - 数组总数的 Spark-Ada 后置条件

Ada GNAT 证明 1 不是 >= 0