| 795 | | clauses |
| | 795 | Function contracts can be specified as annotations---formatted comments---preceding a function prototype or definition. |
| | 796 | The language for these annotations is based on the specification language [https://frama-c.com/html/acsl.html ACSL] used by Frama-C. |
| | 797 | The high-level syntax is |
| | 798 | |
| | 799 | `/*@` ''clause''* `*/` |
| | 800 | |
| | 801 | Optionally, any line after the first line (which begins with `/*@` in the contract may have `*` as its first non-white-space character; |
| | 802 | this character is ignored. |
| | 803 | |
| | 804 | There are clauses for preconditions, postconditions, and other concepts. |
| | 805 | These are used in various experimental extensions of CIVL. |
| | 806 | Here me describe the two clauses which are fully supported and in effect by the CIVL model checker. |
| | 807 | |
| | 808 | === Specifying a guard: `enabled_when` |
| | 809 | |
| | 810 | This clause has syntax |
| | 811 | `enabled_when` ''expr'' `;` |
| | 812 | It may be used with an [#atomic_f atomic] or [#system system] function. |
| | 813 | This clause specifies a guard that applies whenever the function is called. |
| | 814 | The ''expr'' may use the formal parameters of the functions as well as any other variables that are in scope. |
| | 815 | Whenever control in a process is at a call to the function, the call will be enabled only if the guard evaluates to ''true''. |
| | 816 | The actual arguments used in the call are substituted for the formal parameters in the guard expression. |
| | 817 | |
| | 818 | Note: if the actual arguments have side-effects, they are automatically refactored so that the side-effects occur once, before the call. |
| | 819 | I.e., the call |
| | 820 | ''f''`(`''expr,,1,,''`,` ''expr,,2,,''`,` ...`)` |
| | 821 | is semantically equivalent to |
| | 822 | `t1 =` ''expr,,1,,''`;` |
| | 823 | |
| | 824 | `t2 =` ''expr,,2,,''`;` |
| | 825 | |
| | 826 | ... |
| | 827 | |
| | 828 | ''f''`(t1, t2,` ... `)` |
| | 829 | |
| | 830 | Hence the guard may be evaluated any number of times without causing additional side-effects. |
| | 831 | |