-
Notifications
You must be signed in to change notification settings - Fork 0
/
list_generic.h
47 lines (39 loc) · 1.28 KB
/
list_generic.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/****************************************************************
* Singly linked generic list
*
* Copyright Alastair Reid 2020
* SPDX-Licence-Identifier: BSD-3-Clause
****************************************************************/
struct node {
struct node *next;
void* data;
};
//@ predicate_family Ownership(void *destructor)(void *data);
typedef void destructor(void* d);
//@ requires Ownership(this)(d);
//@ ensures true;
/*@
predicate list(struct node *l, destructor* destructor) =
is_destructor(destructor) == true
&*& (l == 0
? true
: malloc_block_node(l)
&*& l->data |-> ?d
&*& Ownership(destructor)(d)
&*& l->next |-> ?n
&*& list(n, destructor))
;
@*/
struct node *cons(void* x, struct node *xs);
//@ requires list(xs, ?d) &*& Ownership(d)(x);
//@ ensures list(result, d);
// return head of list and remove it from original list
void* head(struct node **pl);
//@ requires *pl |-> ?l &*& list(l, ?d) &*& l != 0;
//@ ensures *pl |-> ?r &*& list(r, d) &*& Ownership(d)(result);
void list_dispose(struct node *l, destructor *f);
//@ requires list(l, f);
//@ ensures true;
/****************************************************************
* End
****************************************************************/