-
Notifications
You must be signed in to change notification settings - Fork 1
/
smtlib2parserinterface.h
341 lines (296 loc) · 12.6 KB
/
smtlib2parserinterface.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
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
/* -*- C -*-
*
* An abstract parser interface for the SMT-LIB v2 language
*
* Author: Alberto Griggio <[email protected]>
*
* Copyright (C) 2010 Alberto Griggio
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
#ifndef SMTLIB2PARSERINTERFACE_H_INCLUDED
#define SMTLIB2PARSERINTERFACE_H_INCLUDED
#include "smtlib2types.h"
#include "smtlib2utils.h"
/* typedefs */
typedef struct smtlib2_parser_interface smtlib2_parser_interface;
#define SMTLIB2_PARSER_INTERFACE(p) ((smtlib2_parser_interface *)p)
/**
* Interface for SMT-LIB v2 parsers
*/
struct smtlib2_parser_interface {
/**
* callback for a "set-logic" command
*/
void (*set_logic)(smtlib2_parser_interface *parser, const char *logic);
/**
* callback for a "declare-sort" command
*/
void (*declare_sort)(smtlib2_parser_interface *parser,
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
*/
void (*define_sort)(smtlib2_parser_interface *parser,
const char *sortname, smtlib2_vector *params,
smtlib2_sort sort);
/**
* callback for a "declare-fun" command
*/
void (*declare_function)(smtlib2_parser_interface *parser,
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
*/
void (*declare_variable)(smtlib2_parser_interface *parser,
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
*/
void (*define_function)(smtlib2_parser_interface *parser,
const char *name,
smtlib2_vector *params,
smtlib2_sort sort, smtlib2_term term);
/**
* callback for a "push" command
*/
void (*push)(smtlib2_parser_interface *parser, int n);
/**
* callback for a "pop" command
*/
void (*pop)(smtlib2_parser_interface *parser, int n);
/**
* callback for an "assert" command
*/
void (*assert_formula)(smtlib2_parser_interface *parser, smtlib2_term term);
/**
* callback for a "check-sat" command
*/
void (*check_sat)(smtlib2_parser_interface *parser);
/**
* callback for a "get-assignment" command
*/
void (*get_assignment)(smtlib2_parser_interface *parser);
/**
* callback for a "get-assertions" command
*/
void (*get_assertions)(smtlib2_parser_interface *parser);
/**
* callback for a "get-unsat-core" command
*/
void (*get_unsat_core)(smtlib2_parser_interface *parser);
/**
* callback for a "get-proof" command
*/
void (*get_proof)(smtlib2_parser_interface *parser);
/**
* callback for a "set-option" command with string value
*/
void (*set_str_option)(smtlib2_parser_interface *parser,
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
*/
void (*set_int_option)(smtlib2_parser_interface *parser,
const char *keyword, int value);
/**
* callback for a "set-option" command with a rational value (e.g. timeout)
*/
void (*set_rat_option)(smtlib2_parser_interface *parser,
const char *keyword, double value);
/**
* callback for a "get-info" command
*/
void (*get_info)(smtlib2_parser_interface *parser,
const char *keyword);
/**
* callback for a "set-info" command
*/
void (*set_info)(smtlib2_parser_interface *parser,
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
*/
void (*get_value)(smtlib2_parser_interface *parser, smtlib2_vector *terms);
/**
* callback for a "get-model" command
*/
void (*get_model)(smtlib2_parser_interface *parser);
/**
* callback for a "exit" command
*/
void (*exit)(smtlib2_parser_interface *parser);
/**
* callback for handling parse errors
*/
void (*handle_error)(smtlib2_parser_interface *parser, const char *msg);
/**
* callback for the ".internal-parse-terms" command (see above)
*/
void (*set_internal_parsed_terms)(smtlib2_parser_interface *parser,
smtlib2_vector *terms);
/**
* push a scope for let bindings. called every time a "let" is parsed
*/
void (*push_let_scope)(smtlib2_parser_interface *parser);
/**
* pop a scope for let bindings. called every time the closing parenthesis
* for a "let" is parsed
*/
smtlib2_term (*pop_let_scope)(smtlib2_parser_interface *parser);
/**
* 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
*/
smtlib2_term (*push_quantifier_scope)(smtlib2_parser_interface *parser);
/**
* pop a scope for quantified variabled. called when the closing
* parenthesis for an "exists", "forall" or "define-fun" is parsed
*/
smtlib2_term (*pop_quantifier_scope)(smtlib2_parser_interface *parser);
/**
* push a scope for sort parameters. called when a "define-sort" is parsed
*/
void (*push_sort_param_scope)(smtlib2_parser_interface *parser);
/**
* pop a scope for sort parameters. called when the closing parenthesis
* for a "define-sort" is parsed
*/
void (*pop_sort_param_scope)(smtlib2_parser_interface *parser);
/**
* 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)
*/
smtlib2_term (*make_term)(smtlib2_parser_interface *parser,
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
*/
smtlib2_term (*make_number_term)(smtlib2_parser_interface *parser,
const char *numval, int width, int base);
/**
* callback for creating universally-quantified terms
*/
smtlib2_term (*make_forall_term)(smtlib2_parser_interface *parser,
smtlib2_term term);
/**
* callback for creating existentially-quantified terms
*/
smtlib2_term (*make_exists_term)(smtlib2_parser_interface *parser,
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" } }
*/
void (*annotate_term)(smtlib2_parser_interface *parser,
smtlib2_term term, smtlib2_vector *annotations);
/**
* callback for defining let bindings
* "symbol" is the name of the binding
* "term" is the definition
*/
void (*define_let_binding)(smtlib2_parser_interface *parser,
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 })
*/
smtlib2_sort (*make_sort)(smtlib2_parser_interface *parser,
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"
*/
smtlib2_sort (*make_parametric_sort)(smtlib2_parser_interface *parser,
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
*/
smtlib2_sort (*make_function_sort)(smtlib2_parser_interface *parser,
smtlib2_vector *tps);
};
#endif /* SMTLIB2PARSERINTERFACE_H_INCLUDED */