-
Notifications
You must be signed in to change notification settings - Fork 1
/
smtlib2cpp.h
293 lines (249 loc) · 9.62 KB
/
smtlib2cpp.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
#pragma once
#include <cstdio>
#include <span>
#include "smtlib2types.h"
#include "smtlib2vector.h"
class smtlib2_cpp_parser
{
struct smtlib2_cpp_inner* inner = nullptr;
public:
smtlib2_cpp_parser();
virtual ~smtlib2_cpp_parser();
smtlib2_cpp_parser(const smtlib2_cpp_parser&) = delete;
smtlib2_cpp_parser& operator=(const smtlib2_cpp_parser&) = delete;
void parse(FILE* src);
protected:
void set_error(const char* msg, ...);
/**
* callback for a "set-logic" command
*/
virtual void set_logic(const char* logic);
/**
* callback for a "declare-sort" command
*/
virtual void declare_sort(const char* sortname, int arity);
/**
* callback for a "define-sort" command
* "params" is a vector of smtlib2_sort for the parameters,
* NULL when no parameters are given
* "sort" is the "template" sort when parameters are used,
* otherwise it is a concrete sort
*/
virtual void define_sort(const char* sortname, smtlib2_vector* params, smtlib2_sort sort);
/**
* callback for a "declare-fun" command
*/
virtual void declare_function(const char* name, smtlib2_sort sort);
/**
* callback for declaring a quantified variable
* This gets called for variables declared by an "exists" or "forall"
* quantification, but also for parameters of a "define-fun" command
*/
virtual void declare_variable(const char* name, smtlib2_sort sort);
/**
* callback for a "define-fun" command
* "params" is a vector of smtlib2_term returned by make_term (see below),
* declared by declare_variable (see above) in the current scope
* (see push_quantifier_scope below),
* NULL when no parameters are given
* "sort" is the sort of the definition
* "term" is the term "template" term when parameters are used,
* or the actual definition when no parameters are given
*/
virtual void define_function(const char* name, smtlib2_vector* params, smtlib2_sort sort, smtlib2_term term);
/**
* callback for a "push" command
*/
virtual void push(int n);
/**
* callback for a "pop" command
*/
virtual void pop(int n);
/**
* callback for an "assert" command
*/
virtual void assert_formula(smtlib2_term term);
/**
* callback for a "check-sat" command
*/
virtual void check_sat();
/**
* callback for a "get-assignment" command
*/
virtual void get_assignment();
/**
* callback for a "get-assertions" command
*/
virtual void get_assertions();
/**
* callback for a "get-unsat-core" command
*/
virtual void get_unsat_core();
/**
* callback for a "get-proof" command
*/
virtual void get_proof();
/**
* callback for a "set-option" command with string value
*/
virtual void set_str_option(const char* keyword, const char* value);
/**
* callback for a "set-option" command with integer value
* also options with true/false values will trigger this callback
*/
virtual void set_int_option(const char* keyword, int value);
/**
* callback for a "set-option" command with a rational value (e.g. timeout)
*/
virtual void set_rat_option(const char* keyword, double value);
/**
* callback for a "get-info" command
*/
virtual void get_info(const char* keyword);
/**
* callback for a "set-info" command
*/
virtual void set_info(const char* keyword, const char* value);
/**
* callback for a "get-value" command
* "terms" is a vector of *string representations* of the terms for which
* the model value is requested. In order to get the actual terms,
* such strings should be parsed. For this, the (non-standard)
* ".internal-parse-terms" command can be used.
*
* The reason for this choice is that the SMT-LIB v2 language
* mandates that responses to a get-value command return the same
* string representation as the input: by explicitly passing the
* strings themselves, it is actually possible to perform
* arbitrary simplifications to terms (including e.g. expansion of
* let bindings) directly at parsing time
*
* See smtlib2yices.c for an example of use of
* ".internal-parse-terms" from within a "get-value" callback
*/
virtual void get_value(smtlib2_vector* terms);
/**
* callback for a "get-model" command
*/
virtual void get_model();
/**
* callback for a "exit" command
*/
virtual void exit();
/**
* callback for handling parse errors
*/
virtual void handle_error(const char* msg);
/**
* callback for the ".internal-parse-terms" command (see above)
*/
virtual void set_internal_parsed_terms(smtlib2_vector* terms);
/**
* push a scope for let bindings. called every time a "let" is parsed
*/
virtual void push_let_scope();
/**
* pop a scope for let bindings. called every time the closing parenthesis
* for a "let" is parsed
*/
virtual smtlib2_term pop_let_scope();
/**
* push a scope for quantified variables. called every time an "exist" or
* "forall" is parsed, and also when a "define-fun" with parameters
* is parsed
*/
virtual smtlib2_term push_quantifier_scope();
/**
* pop a scope for quantified variabled. called when the closing
* parenthesis for an "exists", "forall" or "define-fun" is parsed
*/
virtual smtlib2_term pop_quantifier_scope();
/**
* push a scope for sort parameters. called when a "define-sort" is parsed
*/
virtual void push_sort_param_scope();
/**
* pop a scope for sort parameters. called when the closing parenthesis
* for a "define-sort" is parsed
*/
virtual void pop_sort_param_scope();
/**
* callback for creating terms
* "symbol" is the identifier associated to this term,
* which must have been declared or defined before by a
* "declare-fun", "define-fun", "declare-variable"
* command or by a let binding
* "sort" is the requested sort for this term. it is not NULL only when
* an "(as term sort)" construct is used
* "index" is the index for the identifier (a vector of integers),
* used in bit-vector terms.
* example: in "(_ extract 3 1)" "extract" is the symbol,
* and {3, 1} is the index
* "args" is the vector of arguments for this term
* (a vector of smtlib2_term)
*/
virtual smtlib2_term make_term(const char* symbol, smtlib2_sort sort, smtlib2_vector* index, smtlib2_vector* args);
/**
* callback for creating numbers
* "numval" is the string representation of the number, in the given base
* (see below). notice that the prefix which identifies the base
* (e.g. "#b" for base 2) is not included in "numval"
* (so for instance when parsing "#b011" "numval" will be "011")
* "width" is the bit-width of the number. this is zero if the number
* is not a bit-vector
* "base" is the base used for the representation "numval".
* can be 2, 10 or 16
*/
virtual smtlib2_term make_number_term(const char* numval, int width, int base);
/**
* callback for creating universally-quantified terms
*/
virtual smtlib2_term make_forall_term(smtlib2_term term);
/**
* callback for creating existentially-quantified terms
*/
virtual smtlib2_term make_exists_term(smtlib2_term term);
/**
* callback for attaching annotations to terms
* "term" is the term to annotate
* "annotations" is a vector of size-2 arrays of strings. each element
* represents a pair <keyword, value>. the parser checks
* that values are valid sexps, but doesn't interpret
* them in any way
*
* example: parsing "(! x :named pippo)" will result in a call to
* "annotate_term" with "term" set to "x" and annotations to
* { { ":named", "pippo" } }
*/
virtual void annotate_term(smtlib2_term term, smtlib2_vector* annotations);
/**
* callback for defining let bindings
* "symbol" is the name of the binding
* "term" is the definition
*/
virtual void define_let_binding(const char* symbol, smtlib2_term term);
/**
* callback for creating sorts
* "sortname" is the name of the sort. it must have been declared with
* "declare-sort" or defined with "define-sort"
* "index" is the sort index, a vector of integers
* (e.g. when parsing "(_ BitVec 32)"
* "sortname" is "BitVec" and "index" is { 32 })
*/
virtual smtlib2_sort make_sort(const char* sortname, smtlib2_vector* index);
/**
* callback for instantiating parametric sorts
* "name" is the name of the parametric sort. it must have been declared
* with "declare-sort" or defined with "define-sort"
* "tps" is a vector of smtlib2_sort corresponding to the actual parameters
* for the parametric sort "name"
*/
virtual smtlib2_sort make_parametric_sort(const char* name, smtlib2_vector* tps);
/**
* callback for creating function sorts
* "tps" is a vector of size N of smtlib2_sort.
* the first N-1 elements are the sorts of the function domain,
* and the last one is the sort of the codomain
*/
virtual smtlib2_sort make_function_sort(smtlib2_vector* tps);
};