InutitionTC  0.30
namemap.h
Go to the documentation of this file.
1 /****************************************************************************
2  * Copyright (C) 2016 by University of Warsaw *
3  * *
4  * This file is part of IntuitionTC. *
5  * *
6  ****************************************************************************/
14 #ifndef _NAMEMAP_H
15 #define _NAMEMAP_H
16 
17 #include <string.h>
18 #include "checker.h"
19 #ifdef _FRAMAC_
20 #include "libc/__fc_namemap.h"
21 #else
22 
29 typedef struct {
32  size_t size;
35  size_t bufsize;
37  char **keys;
39  char **vals;
40 } namemap;
41 #endif
42 
43 
44 /*@
45  @ predicate IsIn{A}(namemap n, integer size, Name elem) =
46  @ \exists integer i; 0 <= i < size && strcmp(elem, n.keys[i]) == 0;
47  @ predicate IsInRes{A}(namemap n, Name where, Name what) =
48  @ \exists integer i; 0 <= i < n.size && strcmp(where, n.keys[i]) == 0 &&
49  @ n.vals[i] == what;
50  @
51  @*/
52 
53 /*@
54  @ //Both sizes are non-negative and bufsize is not less than size.
55  @ predicate valid_sizes(size_t size, size_t bufsize) =
56  @ 0<= size <= UINT32_MAX && 0 <= 2*bufsize*sizeof(char*) <= UINT32_MAX && bufsize >= size && 0 < bufsize;
57  @
58  @ predicate valid_content{L}(char** keys, size_t size) =
59  @ \forall int i; 0 <= i < size ==> valid_string(keys[i]);
60  @
61  @ predicate valid_charray{L}(char** keys, size_t bufsize, size_t size) =
62  @ \separated(__allocated+(0..MAX_ALLOCS-1),
63  (char*)keys+(0..bufsize*sizeof(char*)-1)) &&
64  @ keys != \null &&
65  @ \valid{L}(keys+(0..bufsize-1)) &&
66  @ is_allocated_size{L}((char*)keys, (size_t)(bufsize*sizeof(char*))) &&
67  @ valid_content{L}(keys, size);
68  @
69  @ predicate well_separated{L}(char** keys, size_t size, namemap *n) =
70  @ \separated(keys+(0..size-1), n);
71  @
72  @ predicate well_separated_arrays{L}(char** keys, char** vals, size_t size) =
73  @ \separated(keys+(0..(size-1)), vals+(0..(size-1)));
74  @
75  @ predicate valid_namemap{L}(namemap n) =
76  @ valid_sizes(n.size, n.bufsize) && n.keys!= n.vals &&
77  @ valid_charray{L}(n.keys, n.bufsize, n.size) &&
78  @ valid_charray{L}(n.vals, n.bufsize, n.size);
79  @
80  @ predicate valid_namemap_ptr{L}(namemap *n) =
81  @ n!=\null &&
82  @ \valid{L}(n) &&
83  @ is_allocated_size{L}((char*)n, (size_t)sizeof(namemap)) &&
84  @ valid_namemap{L}(*n) &&
85  @ well_separated_arrays{L}(n->keys, n->vals, n->bufsize) &&
86  @ well_separated{L}(n->keys, n->bufsize, n) &&
87  @ well_separated{L}(n->vals, n->bufsize, n);
88  @*/
89 
90 //@ ghost size_t charr_bufsize;
91 
92 /*@
93  @ requires \valid(dest+(0..charr_bufsize));
94  @ requires \valid_read(src+(0..size-1));
95  @ requires src==\null <==> dest==\null;
96  @ requires size <= charr_bufsize;
97  @ requires \separated(dest+(0..(size_t)(charr_bufsize-1)), src+(0..charr_bufsize-1));
98  @ requires 0 <= size < UINT32_MAX;
99  @ requires \separated(__allocated+(0..MAX_ALLOCS-1),(char*)dest+(0..sizeof(char*)*charr_bufsize-1));
100  @ requires is_allocated_size((char*)src, (size_t)(charr_bufsize*sizeof(char*))) &&
101  @ is_allocated_size((char*)dest, (size_t)(charr_bufsize*sizeof(char*)));
102  @ requires \valid{Pre}(src+(0..(size_t)(charr_bufsize-1))) && \valid{Pre}(dest+(0..(size_t)(charr_bufsize-1)));
103  @ requires
104  @ \separated(__allocated+(0..MAX_ALLOCS-1),(char*)src+(0..sizeof(char*)*charr_bufsize-1)) ==>
105  @ \separated(__allocated+(0..MAX_ALLOCS-1),(char*)dest+(0..sizeof(char*)*charr_bufsize-1));
106  @ requires valid_charray{Pre}(src, charr_bufsize, size);
107  @ assigns dest[0..size-1];
108  @ exits \false;
109  @ ensures \forall size_t i; 0 <= i < size ==> \at(dest[i],Post)==\at(src[i],Pre);
110  @ ensures \forall char* p, size_t i; is_allocated_size{Pre}(p, i) ==> is_allocated_size{Post}(p,i);
111  @ ensures \forall char* p, size_t i; \valid{Pre}(p+(0..i)) ==> \valid{Post}(p+(0..i));
112  @ ensures \forall char** p, size_t i; \valid{Pre}(p+(0..i)) ==> \valid{Post}(p+(0..i));
113  @ ensures \forall size_t i; 0 <= i < MAX_ALLOCS ==> \at(__allocated[i],Pre) == \at(__allocated[i],Post);
114  @ ensures \forall char* p,*q, size_t n,m; \separated(\at(p,Pre)+(0..n-1),\at(q,Pre)+(0..m-1)) ==>
115  @ \separated(\at(p,Post)+(0..n-1),\at(q,Post)+(0..m-1));
116  @ ensures \forall char** p,**q, size_t n,m; \separated(\at(p,Pre)+(0..n-1),\at(q,Pre)+(0..m-1)) ==>
117  @ \separated(\at(p,Post)+(0..n-1),\at(q,Post)+(0..m-1));
118  @ ensures valid_charray{Post}(src, charr_bufsize, size);
119  @ ensures valid_charray{Post}(dest, charr_bufsize, size);
120  @ ensures \at(__num_allocated,Pre) == \at(__num_allocated,Post);
121  @ ensures \at(__size_allocated,Pre) == \at(__size_allocated,Post);
122  @*/
123 void memcpy_charr(char** dest, char** src, size_t size);
124 
125 
126 /*@ requires default_size_inv(DEFAULT_SIZE) && correct_allocation((size_t)0);
127  @ requires 0 <= 2*DEFAULT_SIZE*sizeof(char*) <= UINT32_MAX;
128  @ behavior alloc_new:
129  @ assumes is_allocable{Pre}((size_t)(2*DEFAULT_SIZE*sizeof(char*)),(size_t)2);
130  @ assigns __allocated[__num_allocated..__num_allocated+1], __size_allocated, __num_allocated;
131  @ ensures valid_namemap(\result);
132  @ ensures allocation_footprint{Pre,Post}((size_t)(2*DEFAULT_SIZE*sizeof(char*)),(size_t)2);
133  @ behavior alloc_no:
134  @ assumes !is_allocable{Pre}((size_t)(2*DEFAULT_SIZE*sizeof(char*)),(size_t)2);
135  @ assigns __allocated[__num_allocated];
136  @ ensures \result.size==0 && \result.bufsize==0 && \result.keys == \null && \result.vals == \null;
137  @ ensures allocation_footprint{Pre,Post}((size_t)0,(size_t)0);
138  @ complete behaviors;
139  @ disjoint behaviors;
140  @*/
141 namemap namemap_new();
142 
143 /*@ requires valid_namemap(n) && correct_allocation((size_t)0);
144  @ assigns __allocated[0..MAX_ALLOCS], __size_allocated, __num_allocated;
145  @ ensures \at(__num_allocated,Post) == \at(__num_allocated,Pre) - 2;
146  @ ensures \at(__size_allocated,Post) == \at(__size_allocated,Pre) -
147  @ 2*n.bufsize*sizeof(char*);
148  @*/
149 void namemap_free(namemap n); /* shallow */
150 
151 /*@ requires valid_namemap_ptr(n) && correct_allocation((size_t)0);
152  @ requires 0 < n->bufsize < UINT32_MAX;
153  @ requires 0 <= 2*n->bufsize*sizeof(char*) <= UINT32_MAX;
154  @ requires (n->size == n->bufsize) ==>
155  @ is_allocable((size_t)(2*n->bufsize*sizeof(char*)),(size_t)1);
156  @ requires valid_string(elem) && valid_string(val);
157  @ ensures \result!=\null ==> valid_namemap_ptr(\result);
158  @*/
159 namemap *namemap_insert(namemap *n, Name elem, Name val);
160 
161 /*@
162  @ requires valid_namemap(n) && valid_Name(elem) && correct_allocation((size_t)0);
163  @ assigns \nothing;
164  @
165  @ behavior found:
166  @ assumes IsIn(n, n.size, elem);
167  @ ensures \result!= \null && IsInRes(n, elem, \result);
168  @ behavior non_found:
169  @ assumes !IsIn(n, n.size, elem);
170  @ ensures \result==\null;
171  @ complete behaviors;
172  @ disjoint behaviors;
173  @*/
174 Name namemap_lookup(const namemap n, const Name elem);
175 
176 /*@
177  @ requires default_size_inv(DEFAULT_SIZE) && valid_namemap(in) && correct_allocation((size_t)0);
178  @ requires 0 <= (2*in.bufsize*sizeof(char*)) + sizeof(namemap) <= UINT32_MAX;
179  @
180  @ behavior alloc_new:
181  @ assumes is_allocable{Pre}((size_t)((2*in.bufsize*sizeof(char*))+sizeof(namemap)),(size_t)3);
182  @ assigns __allocated[__num_allocated..__num_allocated+1], __size_allocated, __num_allocated;
183  @ ensures valid_namemap_ptr(\result);
184  @ ensures allocation_footprint{Pre,Post}((size_t)((2*in.bufsize*sizeof(char*))+sizeof(namemap)), (size_t)3);
185  @
186  @ behavior alloc_no:
187  @ assumes !is_allocable{Pre}((size_t)((2*in.bufsize*sizeof(char*))+sizeof(namemap)),(size_t)3);
188  @ assumes __num_allocated <= UINT32_MAX - 1;
189  @ assigns __allocated[__num_allocated];
190  @ ensures \result == \null;
191  @ ensures allocation_footprint{Pre,Post}((size_t)0, (size_t)0);
192  @
193  @ complete behaviors;
194  @ disjoint behaviors;
195  @*/
196 namemap* namemap_copy(const namemap in);
197 
198 #endif
char ** vals
The array with the dictionary values keys.
Definition: namemap.h:39
size_t bufsize
The size of the area that can hold valid keys and values before reallocation is done.
Definition: namemap.h:35
Definitions of the base structures that represent the formulas and proofs.
The representation of the dictionary to hold strings under string keys.
Definition: namemap.h:29
size_t size
The size of the area in the representation which is occupied by valid keys and values.
Definition: namemap.h:32
char * Name
The type to structurally represent identifier names.
Definition: checker.h:46
char ** keys
The array with the dictionary keys.
Definition: namemap.h:37