我最近在旧考试中阅读了以下JML代码:
Class L {
/*@non_null*/ int[] a;
/*@ public normal_behaviour
@ requires !(\exists int i; 0 <= i && i < a.length; a[i] == d);
@ ensures a.length == \old(a.length) + 1;
@ ensures a[\old(a.length)] == d;
@ ensures (\forall int i; 0 <= i && i < \old(a.length);
a[i] == \old(a[i]));
@ assignable a, a[*];
@*/
public void st(int d) {
...
}
}
我不明白
assignable a, a[*];
一部分。 a[*]
是什么意思?如果只有
assignable a;
(参考链接很棒。)
答案 0 :(得分:1)
JML
中的assignable子句仅允许方法在以下情况下修改位置loc:
- loc is mentioned in the method’s assignable clause;
- loc is not allocated when the method starts execution; or
- loc is local to the method (i.e., a local variable or a formal parameter)
使用a[*]
是[0 ... a.length-1];
¹