InutitionTC  0.30
envmap_base.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  ****************************************************************************/
13 #ifndef _ENVMAP_BASE_H
14 #define _ENVMAP_BASE_H 1
15 #include <string.h>
16 #include "checker.h"
17 #ifdef _FRAMAC_
18 #include "namemap.h"
19 #endif
20 
27 typedef struct {
30  size_t size;
33  size_t bufsize;
35  char **keys;
37  Any **vals;
38 } envmap;
39 
40 /*@
41  @ predicate IsInEnv{A}(envmap n, integer size, Name elem) =
42  @ \exists integer i; 0 <= i < size && strcmp(elem, n.keys[i]) == 0;
43  @
44  @ predicate IsInResEnv{A}(namemap n, Name where, Any* what) =
45  @ \exists integer i; 0 <= i < n.size && strcmp(where, n.keys[i]) == 0 &&
46  @ \true;
47  @
48  @*/
49 
50 
51 /*@
52  @ //Both sizes are non-negative and bufsize is not less than size.
53  @
54  @ predicate valid_anycontent{L}(Any** keys, size_t size) =
55  @ \forall size_t i; 0 <= i < size ==> (keys[i] != \null &&
56  @ valid_Any_ptr(keys[i]));
57  @
58  @ predicate valid_anyarray{L}(Any** vals, size_t bufsize, size_t size) =
59  @ \separated(__allocated+(0..MAX_ALLOCS-1),(char*)vals+(0..bufsize*sizeof(Any*)-1)) &&
60  @ vals != \null &&
61  @ \valid{L}(vals+(0..bufsize-1)) &&
62  @ is_allocated_size{L}((char*)vals, (size_t)(bufsize*sizeof(Any*))) &&
63  @ valid_anycontent{L}(vals, size);
64  @
65  @ predicate well_separated_envmap{L}(char** keys, size_t size, size_t bufsize, envmap *n) =
66  @ \separated(((char*)keys)+(0..(bufsize*sizeof(char*))-1), n) &&
67  @ \forall size_t i; 0 <= i < size ==>
68  @ \separated(((char*)keys)+(0..(bufsize*sizeof(char*))-1), (keys[i])+(0..\block_length(keys[i])-1)) &&
69  @ \separated((keys[i])+(0..\block_length(keys[i])-1),n);
70  @
71  @
72  @ predicate well_separated_any{L}(Any** vals, size_t size, size_t bufsize, envmap *n) =
73  @ \separated(((char*)vals)+(0..(bufsize*sizeof(Any*))-1), n) &&
74  @ \forall size_t i; 0 <= i < size ==>
75  @ \separated(((char*)vals)+(0..(bufsize*sizeof(Any*))-1), (vals[i])+(0..sizeof(Any)-1)) &&
76  @ \separated((vals[i])+(0..\block_length(vals[i])-1),n);
77  @
78  @
79  @ predicate well_separated_arrays{L}(char** keys, Any** vals, size_t bufsize, size_t size) =
80  @ \separated(((char*)keys)+(0..(bufsize*sizeof(char*))-1),
81  @ ((char*)vals)+(0..(bufsize*sizeof(Any*))-1)) &&
82  @ \forall size_t i; 0 <= i < size ==>
83  @ \separated(((char*)keys)+(0..(bufsize*sizeof(char*))-1),
84  @ ((char*)vals[i])+(0..(sizeof(Any))-1)) &&
85  @ \forall size_t i; 0 <= i < size ==>
86  @ \separated(((char*)vals)+(0..(bufsize*sizeof(Any*))-1),
87  @ (keys[i])+(0..\block_length(keys[i])-1));
88  @
89  @
90  @
91  @ predicate valid_envmap{L}(envmap n) =
92  @ valid_sizes(n.size, n.bufsize) && (char*)n.keys!= (char*)n.vals &&
93  @ valid_charray{L}(n.keys, n.bufsize, n.size) &&
94  @ valid_anyarray{L}(n.vals, n.bufsize, n.size);
95  @
96  @
97  @ predicate valid_envmap_ptr{L}(envmap *n) =
98  @ n != \null &&
99  @ \valid{L}(n) &&
100  @ is_allocated_size{L}((char*)n, (size_t)sizeof(envmap)) &&
101  @ valid_envmap{L}(*n) &&
102  @ well_separated_arrays{L}(n->keys, n->vals, n->bufsize, n->size) &&
103  @ well_separated_envmap{L}(n->keys, n->size, n->bufsize, n) &&
104  @ well_separated_any{L}(n->vals, n->size, n->bufsize, n) &&
105  @ \forall size_t i; 0 <= i < n->size ==> separated_Any(n->keys, n->bufsize, n->vals[i]);
106  @*/
107 
108 
109 
110 /*@ requires default_size_inv(DEFAULT_SIZE) && correct_allocation((size_t)0);
111  @ behavior alloc_new:
112  @ assumes is_allocable{Pre}((size_t)(DEFAULT_SIZE*sizeof(char*)+DEFAULT_SIZE*sizeof(Any*)),(size_t)2);
113  @ assigns __allocated[__num_allocated..__num_allocated+1], __size_allocated, __num_allocated;
114  @ ensures valid_envmap(\result);
115  @ ensures allocation_footprint{Pre,Post}((size_t)(DEFAULT_SIZE*sizeof(char*)+DEFAULT_SIZE*sizeof(Any*)),(size_t)2);
116  @ behavior alloc_no:
117  @ assumes !is_allocable{Pre}((size_t)(DEFAULT_SIZE*sizeof(char*)+DEFAULT_SIZE*sizeof(Any*)),(size_t)2);
118  @ assigns __allocated[__num_allocated];
119  @ ensures \result.size==0 && \result.bufsize==0 && \result.keys == \null && \result.vals == \null;
120  @ ensures allocation_footprint{Pre,Post}((size_t)0,(size_t)0);
121  @ complete behaviors;
122  @ disjoint behaviors;
123  @*/
124 envmap envmap_new();
125 
126 /*@ requires valid_envmap(n) && correct_allocation((size_t)0);
127  @ assigns __allocated[0..MAX_ALLOCS], __size_allocated, __num_allocated;
128  @ ensures \at(__num_allocated,Post) == \at(__num_allocated,Pre) - 2;
129  @ ensures \at(__size_allocated,Post) == \at(__size_allocated,Pre) -
130  @ n.bufsize*sizeof(char*)+n.bufsize*sizeof(Any*);
131  @*/
132 void envmap_free(envmap n); /* shallow */
133 
134 /*@ requires valid_envmap_ptr(n) &&
135  @ valid_Name(elem) && valid_Any(val);
136  @ requires \separated(n,elem+(0..\block_length(elem)-1)) &&
137  @ \separated((char*)(n->vals)+(0..sizeof(char*)*n->bufsize-1),
138  elem+(0..\block_length(elem)-1)) &&
139  @ \separated(n->keys+(0..n->bufsize-1),
140  elem+(0..\block_length(elem)-1));
141  @ requires 0 < n->bufsize*sizeof(char*)+n->bufsize*sizeof(Any*) < UINT32_MAX;
142  @ requires 0 <= n->bufsize <= UINT32_MAX;
143  @ requires (n->size == n->bufsize) ==>
144  @ is_allocable((size_t)(n->bufsize*sizeof(char*)+n->bufsize*sizeof(Any*)+sizeof(Any)),(size_t)2);
145  @ requires (n->size != n->bufsize) ==>
146  @ is_allocable((size_t)(sizeof(Any)),(size_t)1);
147  @ requires valid_Name(elem) && valid_Any(val);
148  @ requires \separated(((char*)(n->keys)+(0..(n->bufsize*sizeof(char*))-1)),
149  @ elem+(0..\block_length(elem)-1));
150  @ ensures \result!=\null ==> valid_envmap_ptr(\result);
151  @*/
152 envmap *envmap_insert(envmap *n, Name elem, Any val);
153 
154 /*@
155  @ requires valid_envmap(n) && valid_Name(elem) && correct_allocation((size_t)0);
156  @ assigns \nothing;
157  @
158  @ behavior found:
159  @ assumes IsInEnv(n, n.size, elem);
160  @ ensures \result!= \null && valid_Any_ptr(\result); // TODO && IsInResEnv(n, elem, \null); // *\result);
161  @ behavior non_found:
162  @ assumes !IsInEnv(n, n.size, elem);
163  @ ensures \result==\null;
164  @ complete behaviors;
165  @ disjoint behaviors;
166  @*/
167 Any *envmap_lookup(const envmap n, const Name elem);
168 
169 /*@
170  @ requires default_size_inv(DEFAULT_SIZE) && valid_envmap(in) && correct_allocation((size_t)0);
171  @ requires 0 <= in.bufsize*sizeof(char*) + in.bufsize*sizeof(Any*) + sizeof(envmap) <= UINT32_MAX;
172  @ requires \forall size_t i; 0 <= i < in.size ==>
173  @ \exists integer j; j>0 && depth_Any((in.vals)[i])==j;
174  @
175  @ behavior alloc_new:
176  @ assumes is_allocable{Pre}((size_t)(in.bufsize*sizeof(char*)+in.bufsize*sizeof(Any*)+sizeof(envmap)),(size_t)3);
177  @ assigns __allocated[__num_allocated..__num_allocated+1], __size_allocated, __num_allocated;
178  @ ensures valid_envmap_ptr(\result);
179  @ ensures allocation_footprint{Pre,Post}((size_t)(in.bufsize*sizeof(char*)+in.bufsize*sizeof(Any*)+sizeof(envmap)), (size_t)3);
180  @ behavior alloc_no:
181  @ assumes !is_allocable{Pre}((size_t)(in.bufsize*sizeof(char*)+in.bufsize*sizeof(Any*)+sizeof(envmap)),(size_t)3);
182  @ assumes __num_allocated <= UINT32_MAX - 1;
183  @ assigns __allocated[__num_allocated];
184  @ ensures \result == \null;
185  @ ensures allocation_footprint{Pre,Post}((size_t)0, (size_t)0);
186  @
187  @ complete behaviors;
188  @ disjoint behaviors;
189  @*/
190 envmap* envmap_copy(const envmap in); /* shallow */
191 
192 #endif
size_t bufsize
The size of the area that can hold valid keys and values before reallocation is done.
Definition: envmap_base.h:33
size_t size
The size of the area in the representation which is occupied by valid keys and values.
Definition: envmap_base.h:30
Operations on the data structure that represents dictionaries of names.
Definitions of the base structures that represent the formulas and proofs.
Any ** vals
The array with the dictionary values keys.
Definition: envmap_base.h:37
char ** keys
The array with the dictionary keys.
Definition: envmap_base.h:35
The representation of the dictionary to hold values wrapped in Any structure and available under stri...
Definition: envmap_base.h:27
The wrapper that makes it possible to store in envmap different species of elements that occur in typ...
Definition: checker.h:329
char * Name
The type to structurally represent identifier names.
Definition: checker.h:46