main
| Line | |
|---|
| 1 | /**
|
|---|
| 2 | * Issue here is that focus cannot be applied across functions as usual.
|
|---|
| 3 | * If we want to apply focus to a loop in a function then that function
|
|---|
| 4 | * needs a function contract.
|
|---|
| 5 |
|
|---|
| 6 | * Function contract here doesn't work for some reason (CIVL bug)
|
|---|
| 7 |
|
|---|
| 8 | * Also the postcondition currently can't be transformed with focus
|
|---|
| 9 | * so an assertion must be inserted into the function to apply focus.
|
|---|
| 10 | * This could be fixed.
|
|---|
| 11 | */
|
|---|
| 12 | #include<assert.h>
|
|---|
| 13 |
|
|---|
| 14 | #pragma CIVL ACSL
|
|---|
| 15 |
|
|---|
| 16 | $input int N;
|
|---|
| 17 | $assume(N > 0);
|
|---|
| 18 | $input double a[N];
|
|---|
| 19 | $input double b[N];
|
|---|
| 20 |
|
|---|
| 21 | /*@ requires n > 0;
|
|---|
| 22 | @ requires \valid(a+(0..n)) && \valid(b+(0..n));
|
|---|
| 23 | @ assigns \nothing;
|
|---|
| 24 | @ ensures (\result == \true) ==> (\forall int i; 0 <= i && i < n ==> a[i] == b[i]);
|
|---|
| 25 | @*/
|
|---|
| 26 | _Bool arrayEquals(double * a, double * b, int n) {
|
|---|
| 27 | _Bool equal = $true;
|
|---|
| 28 |
|
|---|
| 29 | //@ focus F;
|
|---|
| 30 | for (int i = 0; i < n; i++)
|
|---|
| 31 | if (a[i] != b[i])
|
|---|
| 32 | equal = $false;
|
|---|
| 33 | //@ focus F;
|
|---|
| 34 | assert($forall (int i: 0 .. n-1) equal => a[i] == b[i]);
|
|---|
| 35 | return equal;
|
|---|
| 36 | }
|
|---|
| 37 |
|
|---|
| 38 | int main() {
|
|---|
| 39 | _Bool ret = arrayEquals(a, b, N);
|
|---|
| 40 |
|
|---|
| 41 | if (ret) {
|
|---|
| 42 | assert($forall (int i: 0 .. N-1) a[i] == b[i]);
|
|---|
| 43 | }
|
|---|
| 44 | }
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.