| 266 | | $access(n) - ($calls(inc(MemorySetExpression)) + $calls(dec(MemorySetExpression)))} |
| 267 | | }}} |
| 268 | | |
| 269 | | |
| | 263 | $access(n) - ($calls(inc(MemorySetExpression)) + $calls(dec(MemorySetExpression))) |
| | 264 | } |
| | 265 | }}} |
| | 266 | * **absence of $depends clause**: |
| | 267 | * assigns-or-reads clause |
| | 268 | * assigns clause: `$assigns [condition] {memory-list}` |
| | 269 | * reads clause: `$reads [condition] {memory-list}` |
| | 270 | * `$reads {$nothing}` implies `$assigns {$nothing}` |
| | 271 | * `$reads {$nothing}` is equivalent to: `$reads {$nothing} $assigns {$nothing}` |
| | 272 | * `$assigns {X}` where `X != $nothing`, implies `$reads {X}` |
| | 273 | * `$assigns {X}` is equivalent to:` $assigns{X} $reads{X}` |
| | 274 | * absence: |
| | 275 | * absence of `$reads` clause: there is no assumption about the read access of the function, i.e., the function could read anything |
| | 276 | * absence of `$assigns` clause: similar to the absence of `$reads` clause |
| | 277 | * `$reads/$assigns {$nothing}` doesn’t necessarily means that the function never reads or assigns any variable. The function could still reads/assigns its “local” variables, including function parameters and any variable declared inside the function body. |
| | 278 | |
| | 279 | * For an independent function which has `$depends {$nothing}`, usually we also need to specify `$reads{nothing}`, for the purpose of reachability analysis. |
| | 280 | e.g., |
| | 281 | {{{ |
| | 282 | /* Returns the size of the given bundle b. */ |
| | 283 | int $bundle_size($bundle b) |
| | 284 | $depends {$nothing} |
| | 285 | $reads {$nothing} |
| | 286 | ; |
| | 287 | }}} |
| | 288 | |
| | 289 | * Example of a function declaration with contracts: |
| | 290 | {{{ |
| | 291 | $atomic_f void sendRecv(int cmd, void*buf) |
| | 292 | $depends [cmd==SEND] {$write(buf)} |
| | 293 | $depends [cmd==RECV] {$access(*buf)} |
| | 294 | $assigns [cmd==SEND] {$nothing} |
| | 295 | $assigns [cmd==RECV] {*buf} |
| | 296 | $reads {*buf} |
| | 297 | { |
| | 298 | if(cmd == SEND){ |
| | 299 | send(*buf, ...); |
| | 300 | }else if(cmd==RECV){ |
| | 301 | *buf=recv(...); |
| | 302 | } |
| | 303 | } |
| | 304 | }}} |