Branch data Line data Source code
1 : : /******************************************************************************
2 : : * This file is part of the cvc5 project.
3 : : *
4 : : * Copyright (c) 2009-2026 by the authors listed in the file AUTHORS
5 : : * in the top-level source directory and their institutional affiliations.
6 : : * All rights reserved. See the file COPYING in the top-level source
7 : : * directory for licensing information.
8 : : * ****************************************************************************
9 : : *
10 : : * Definitions of SMT2 constants.
11 : : */
12 : : #include "parser/smt2/smt2_state.h"
13 : :
14 : : #include <algorithm>
15 : :
16 : : #include "base/check.h"
17 : : #include "base/output.h"
18 : : #include "parser/commands.h"
19 : : #include "util/floatingpoint_size.h"
20 : :
21 : : namespace cvc5 {
22 : : namespace parser {
23 : :
24 : 24292 : Smt2State::Smt2State(ParserStateCallback* psc,
25 : : Solver* solver,
26 : : SymManager* sm,
27 : : ParsingMode parsingMode,
28 : 24292 : bool isSygus)
29 : : : ParserState(psc, solver, sm, parsingMode),
30 : 24292 : d_isSygus(isSygus),
31 : 24292 : d_logicSet(false)
32 : : {
33 : 24292 : d_freshBinders = (d_solver->getOption("fresh-binders") == "true");
34 : 24292 : }
35 : :
36 : 24271 : Smt2State::~Smt2State() {}
37 : :
38 : 29829 : void Smt2State::addArithmeticOperators()
39 : : {
40 : 29829 : addOperator(Kind::ADD, "+");
41 : 29829 : addOperator(Kind::SUB, "-");
42 : : // SUB is converted to NEG if there is only a single operand
43 : 29829 : ParserState::addOperator(Kind::NEG);
44 : 29829 : addOperator(Kind::MULT, "*");
45 : 29829 : addOperator(Kind::LT, "<");
46 : 29829 : addOperator(Kind::LEQ, "<=");
47 : 29829 : addOperator(Kind::GT, ">");
48 : 29829 : addOperator(Kind::GEQ, ">=");
49 : :
50 [ + + ]: 29829 : if (!strictModeEnabled())
51 : : {
52 : : // NOTE: this operator is non-standard
53 : 29792 : addOperator(Kind::POW, "^");
54 : : }
55 : 29829 : }
56 : :
57 : 11465 : void Smt2State::addTranscendentalOperators()
58 : : {
59 : 11465 : addOperator(Kind::EXPONENTIAL, "exp");
60 : 11465 : addOperator(Kind::SINE, "sin");
61 : 11465 : addOperator(Kind::COSINE, "cos");
62 : 11465 : addOperator(Kind::TANGENT, "tan");
63 : 11465 : addOperator(Kind::COSECANT, "csc");
64 : 11465 : addOperator(Kind::SECANT, "sec");
65 : 11465 : addOperator(Kind::COTANGENT, "cot");
66 : 11465 : addOperator(Kind::ARCSINE, "arcsin");
67 : 11465 : addOperator(Kind::ARCCOSINE, "arccos");
68 : 11465 : addOperator(Kind::ARCTANGENT, "arctan");
69 : 11465 : addOperator(Kind::ARCCOSECANT, "arccsc");
70 : 11465 : addOperator(Kind::ARCSECANT, "arcsec");
71 : 11465 : addOperator(Kind::ARCCOTANGENT, "arccot");
72 : 11465 : addOperator(Kind::SQRT, "sqrt");
73 : 11465 : }
74 : :
75 : 14037 : void Smt2State::addQuantifiersOperators() {}
76 : :
77 : 15722 : void Smt2State::addBitvectorOperators()
78 : : {
79 : 15722 : addOperator(Kind::BITVECTOR_CONCAT, "concat");
80 : 15722 : addOperator(Kind::BITVECTOR_NOT, "bvnot");
81 : 15722 : addOperator(Kind::BITVECTOR_AND, "bvand");
82 : 15722 : addOperator(Kind::BITVECTOR_OR, "bvor");
83 : 15722 : addOperator(Kind::BITVECTOR_NEG, "bvneg");
84 : 15722 : addOperator(Kind::BITVECTOR_ADD, "bvadd");
85 : 15722 : addOperator(Kind::BITVECTOR_MULT, "bvmul");
86 : 15722 : addOperator(Kind::BITVECTOR_UDIV, "bvudiv");
87 : 15722 : addOperator(Kind::BITVECTOR_UREM, "bvurem");
88 : 15722 : addOperator(Kind::BITVECTOR_SHL, "bvshl");
89 : 15722 : addOperator(Kind::BITVECTOR_LSHR, "bvlshr");
90 : 15722 : addOperator(Kind::BITVECTOR_ULT, "bvult");
91 : 15722 : addOperator(Kind::BITVECTOR_NAND, "bvnand");
92 : 15722 : addOperator(Kind::BITVECTOR_NOR, "bvnor");
93 : 15722 : addOperator(Kind::BITVECTOR_XOR, "bvxor");
94 : 15722 : addOperator(Kind::BITVECTOR_XNOR, "bvxnor");
95 : 15722 : addOperator(Kind::BITVECTOR_COMP, "bvcomp");
96 : 15722 : addOperator(Kind::BITVECTOR_SUB, "bvsub");
97 : 15722 : addOperator(Kind::BITVECTOR_SDIV, "bvsdiv");
98 : 15722 : addOperator(Kind::BITVECTOR_SREM, "bvsrem");
99 : 15722 : addOperator(Kind::BITVECTOR_SMOD, "bvsmod");
100 : 15722 : addOperator(Kind::BITVECTOR_ASHR, "bvashr");
101 : 15722 : addOperator(Kind::BITVECTOR_ULE, "bvule");
102 : 15722 : addOperator(Kind::BITVECTOR_UGT, "bvugt");
103 : 15722 : addOperator(Kind::BITVECTOR_UGE, "bvuge");
104 : 15722 : addOperator(Kind::BITVECTOR_SLT, "bvslt");
105 : 15722 : addOperator(Kind::BITVECTOR_SLE, "bvsle");
106 : 15722 : addOperator(Kind::BITVECTOR_SGT, "bvsgt");
107 : 15722 : addOperator(Kind::BITVECTOR_SGE, "bvsge");
108 : 15722 : addOperator(Kind::BITVECTOR_REDOR, "bvredor");
109 : 15722 : addOperator(Kind::BITVECTOR_REDAND, "bvredand");
110 : 15722 : addOperator(Kind::BITVECTOR_NEGO, "bvnego");
111 : 15722 : addOperator(Kind::BITVECTOR_UADDO, "bvuaddo");
112 : 15722 : addOperator(Kind::BITVECTOR_SADDO, "bvsaddo");
113 : 15722 : addOperator(Kind::BITVECTOR_UMULO, "bvumulo");
114 : 15722 : addOperator(Kind::BITVECTOR_SMULO, "bvsmulo");
115 : 15722 : addOperator(Kind::BITVECTOR_USUBO, "bvusubo");
116 : 15722 : addOperator(Kind::BITVECTOR_SSUBO, "bvssubo");
117 : 15722 : addOperator(Kind::BITVECTOR_SDIVO, "bvsdivo");
118 [ + + ]: 15722 : if (!strictModeEnabled())
119 : : {
120 : 15701 : addOperator(Kind::BITVECTOR_ITE, "bvite");
121 : : }
122 : :
123 : :
124 : 15722 : addIndexedOperator(Kind::BITVECTOR_EXTRACT, "extract");
125 : 15722 : addIndexedOperator(Kind::BITVECTOR_REPEAT, "repeat");
126 : 15722 : addIndexedOperator(Kind::BITVECTOR_ZERO_EXTEND, "zero_extend");
127 : 15722 : addIndexedOperator(Kind::BITVECTOR_SIGN_EXTEND, "sign_extend");
128 : 15722 : addIndexedOperator(Kind::BITVECTOR_ROTATE_LEFT, "rotate_left");
129 : 15722 : addIndexedOperator(Kind::BITVECTOR_ROTATE_RIGHT, "rotate_right");
130 : 15722 : }
131 : :
132 : 11513 : void Smt2State::addFiniteFieldOperators()
133 : : {
134 : 11513 : addOperator(cvc5::Kind::FINITE_FIELD_ADD, "ff.add");
135 : 11513 : addOperator(cvc5::Kind::FINITE_FIELD_MULT, "ff.mul");
136 : 11513 : addOperator(cvc5::Kind::FINITE_FIELD_NEG, "ff.neg");
137 : 11513 : addOperator(cvc5::Kind::FINITE_FIELD_BITSUM, "ff.bitsum");
138 : 11513 : }
139 : :
140 : 11563 : void Smt2State::addDatatypesOperators()
141 : : {
142 : 11563 : ParserState::addOperator(Kind::APPLY_CONSTRUCTOR);
143 : 11563 : ParserState::addOperator(Kind::APPLY_TESTER);
144 : 11563 : ParserState::addOperator(Kind::APPLY_SELECTOR);
145 : :
146 : 11563 : addIndexedOperator(Kind::APPLY_TESTER, "is");
147 [ + + ]: 11563 : if (!strictModeEnabled())
148 : : {
149 : 11554 : ParserState::addOperator(Kind::APPLY_UPDATER);
150 : 11554 : addIndexedOperator(Kind::APPLY_UPDATER, "update");
151 : : // Tuple projection is both indexed and non-indexed (when indices are empty)
152 : 11554 : addOperator(Kind::TUPLE_PROJECT, "tuple.project");
153 : 11554 : addIndexedOperator(Kind::TUPLE_PROJECT, "tuple.project");
154 : : // Notice that tuple operators, we use the UNDEFINED_KIND kind.
155 : : // These are processed based on the context in which they are parsed, e.g.
156 : : // when parsing identifiers.
157 : : // For the tuple constructor "tuple", this is both a nullary operator
158 : : // (for the 0-ary tuple), and a operator, hence we call both addOperator
159 : : // and defineVar here.
160 : 11554 : addOperator(Kind::APPLY_CONSTRUCTOR, "tuple");
161 : 11554 : defineVar("tuple.unit", d_tm.mkTuple({}));
162 : 11554 : addIndexedOperator(Kind::UNDEFINED_KIND, "tuple.select");
163 : 11554 : addIndexedOperator(Kind::UNDEFINED_KIND, "tuple.update");
164 : 11554 : Sort btype = d_tm.getBooleanSort();
165 : 11554 : defineVar("nullable.null", d_tm.mkNullableNull(d_tm.mkNullableSort(btype)));
166 : 11554 : addOperator(Kind::APPLY_CONSTRUCTOR, "nullable.some");
167 : 11554 : addOperator(Kind::APPLY_SELECTOR, "nullable.val");
168 : 11554 : addOperator(Kind::NULLABLE_LIFT, "nullable.lift");
169 : 11554 : addOperator(Kind::APPLY_TESTER, "nullable.is_null");
170 : 11554 : addOperator(Kind::APPLY_TESTER, "nullable.is_some");
171 : 11554 : addIndexedOperator(Kind::NULLABLE_LIFT, "nullable.lift");
172 : 11554 : }
173 : 11563 : }
174 : :
175 : 12841 : void Smt2State::addStringOperators()
176 : : {
177 : 12841 : defineVar("re.all", d_tm.mkRegexpAll());
178 : 12841 : addOperator(Kind::STRING_CONCAT, "str.++");
179 : 12841 : addOperator(Kind::STRING_LENGTH, "str.len");
180 : 12841 : addOperator(Kind::STRING_SUBSTR, "str.substr");
181 : 12841 : addOperator(Kind::STRING_CONTAINS, "str.contains");
182 : 12841 : addOperator(Kind::STRING_CHARAT, "str.at");
183 : 12841 : addOperator(Kind::STRING_INDEXOF, "str.indexof");
184 : 12841 : addOperator(Kind::STRING_REPLACE, "str.replace");
185 : 12841 : addOperator(Kind::STRING_PREFIX, "str.prefixof");
186 : 12841 : addOperator(Kind::STRING_SUFFIX, "str.suffixof");
187 : 12841 : addOperator(Kind::STRING_FROM_CODE, "str.from_code");
188 : 12841 : addOperator(Kind::STRING_IS_DIGIT, "str.is_digit");
189 : 12841 : addOperator(Kind::STRING_REPLACE_RE, "str.replace_re");
190 : 12841 : addOperator(Kind::STRING_REPLACE_RE_ALL, "str.replace_re_all");
191 [ + + ]: 12841 : if (!strictModeEnabled())
192 : : {
193 : 12832 : addOperator(Kind::STRING_INDEXOF_RE, "str.indexof_re");
194 : 12832 : addOperator(Kind::STRING_UPDATE, "str.update");
195 : 12832 : addOperator(Kind::STRING_TO_LOWER, "str.to_lower");
196 : 12832 : addOperator(Kind::STRING_TO_UPPER, "str.to_upper");
197 : 12832 : addOperator(Kind::STRING_REV, "str.rev");
198 : : // sequence versions
199 : 12832 : addOperator(Kind::SEQ_CONCAT, "seq.++");
200 : 12832 : addOperator(Kind::SEQ_LENGTH, "seq.len");
201 : 12832 : addOperator(Kind::SEQ_EXTRACT, "seq.extract");
202 : 12832 : addOperator(Kind::SEQ_UPDATE, "seq.update");
203 : 12832 : addOperator(Kind::SEQ_AT, "seq.at");
204 : 12832 : addOperator(Kind::SEQ_CONTAINS, "seq.contains");
205 : 12832 : addOperator(Kind::SEQ_INDEXOF, "seq.indexof");
206 : 12832 : addOperator(Kind::SEQ_REPLACE, "seq.replace");
207 : 12832 : addOperator(Kind::SEQ_PREFIX, "seq.prefixof");
208 : 12832 : addOperator(Kind::SEQ_SUFFIX, "seq.suffixof");
209 : 12832 : addOperator(Kind::SEQ_REV, "seq.rev");
210 : 12832 : addOperator(Kind::SEQ_REPLACE_ALL, "seq.replace_all");
211 : 12832 : addOperator(Kind::SEQ_UNIT, "seq.unit");
212 : 12832 : addOperator(Kind::SEQ_NTH, "seq.nth");
213 : : }
214 : 12841 : addOperator(Kind::STRING_FROM_INT, "str.from_int");
215 : 12841 : addOperator(Kind::STRING_TO_INT, "str.to_int");
216 : 12841 : addOperator(Kind::STRING_IN_REGEXP, "str.in_re");
217 : 12841 : addOperator(Kind::STRING_TO_REGEXP, "str.to_re");
218 : 12841 : addOperator(Kind::STRING_TO_CODE, "str.to_code");
219 : 12841 : addOperator(Kind::STRING_REPLACE_ALL, "str.replace_all");
220 : :
221 : 12841 : addOperator(Kind::REGEXP_CONCAT, "re.++");
222 : 12841 : addOperator(Kind::REGEXP_UNION, "re.union");
223 : 12841 : addOperator(Kind::REGEXP_INTER, "re.inter");
224 : 12841 : addOperator(Kind::REGEXP_STAR, "re.*");
225 : 12841 : addOperator(Kind::REGEXP_PLUS, "re.+");
226 : 12841 : addOperator(Kind::REGEXP_OPT, "re.opt");
227 : 12841 : addIndexedOperator(Kind::REGEXP_REPEAT, "re.^");
228 : 12841 : addIndexedOperator(Kind::REGEXP_LOOP, "re.loop");
229 : 12841 : addOperator(Kind::REGEXP_RANGE, "re.range");
230 : 12841 : addOperator(Kind::REGEXP_COMPLEMENT, "re.comp");
231 : 12841 : addOperator(Kind::REGEXP_DIFF, "re.diff");
232 : 12841 : addOperator(Kind::STRING_LT, "str.<");
233 : 12841 : addOperator(Kind::STRING_LEQ, "str.<=");
234 : 12841 : }
235 : :
236 : 11335 : void Smt2State::addFloatingPointOperators()
237 : : {
238 : 11335 : addOperator(Kind::FLOATINGPOINT_FP, "fp");
239 : 11335 : addOperator(Kind::FLOATINGPOINT_EQ, "fp.eq");
240 : 11335 : addOperator(Kind::FLOATINGPOINT_ABS, "fp.abs");
241 : 11335 : addOperator(Kind::FLOATINGPOINT_NEG, "fp.neg");
242 : 11335 : addOperator(Kind::FLOATINGPOINT_ADD, "fp.add");
243 : 11335 : addOperator(Kind::FLOATINGPOINT_SUB, "fp.sub");
244 : 11335 : addOperator(Kind::FLOATINGPOINT_MULT, "fp.mul");
245 : 11335 : addOperator(Kind::FLOATINGPOINT_DIV, "fp.div");
246 : 11335 : addOperator(Kind::FLOATINGPOINT_FMA, "fp.fma");
247 : 11335 : addOperator(Kind::FLOATINGPOINT_SQRT, "fp.sqrt");
248 : 11335 : addOperator(Kind::FLOATINGPOINT_REM, "fp.rem");
249 : 11335 : addOperator(Kind::FLOATINGPOINT_RTI, "fp.roundToIntegral");
250 : 11335 : addOperator(Kind::FLOATINGPOINT_MIN, "fp.min");
251 : 11335 : addOperator(Kind::FLOATINGPOINT_MAX, "fp.max");
252 : 11335 : addOperator(Kind::FLOATINGPOINT_LEQ, "fp.leq");
253 : 11335 : addOperator(Kind::FLOATINGPOINT_LT, "fp.lt");
254 : 11335 : addOperator(Kind::FLOATINGPOINT_GEQ, "fp.geq");
255 : 11335 : addOperator(Kind::FLOATINGPOINT_GT, "fp.gt");
256 : 11335 : addOperator(Kind::FLOATINGPOINT_IS_NORMAL, "fp.isNormal");
257 : 11335 : addOperator(Kind::FLOATINGPOINT_IS_SUBNORMAL, "fp.isSubnormal");
258 : 11335 : addOperator(Kind::FLOATINGPOINT_IS_ZERO, "fp.isZero");
259 : 11335 : addOperator(Kind::FLOATINGPOINT_IS_INF, "fp.isInfinite");
260 : 11335 : addOperator(Kind::FLOATINGPOINT_IS_NAN, "fp.isNaN");
261 : 11335 : addOperator(Kind::FLOATINGPOINT_IS_NEG, "fp.isNegative");
262 : 11335 : addOperator(Kind::FLOATINGPOINT_IS_POS, "fp.isPositive");
263 : 11335 : addOperator(Kind::FLOATINGPOINT_TO_REAL, "fp.to_real");
264 : :
265 : 11335 : addIndexedOperator(Kind::UNDEFINED_KIND, "to_fp");
266 : 11335 : addIndexedOperator(Kind::FLOATINGPOINT_TO_FP_FROM_UBV, "to_fp_unsigned");
267 : 11335 : addIndexedOperator(Kind::FLOATINGPOINT_TO_UBV, "fp.to_ubv");
268 : 11335 : addIndexedOperator(Kind::FLOATINGPOINT_TO_SBV, "fp.to_sbv");
269 : :
270 [ + + ]: 11335 : if (!strictModeEnabled())
271 : : {
272 : 11322 : addIndexedOperator(Kind::FLOATINGPOINT_TO_FP_FROM_IEEE_BV, "to_fp_bv");
273 : 11322 : addIndexedOperator(Kind::FLOATINGPOINT_TO_FP_FROM_FP, "to_fp_fp");
274 : 11322 : addIndexedOperator(Kind::FLOATINGPOINT_TO_FP_FROM_REAL, "to_fp_real");
275 : 11322 : addIndexedOperator(Kind::FLOATINGPOINT_TO_FP_FROM_SBV, "to_fp_signed");
276 : : }
277 : 11335 : }
278 : :
279 : 11172 : void Smt2State::addSepOperators()
280 : : {
281 : 11172 : defineVar("sep.emp", d_tm.mkSepEmp());
282 : : // the Boolean sort is a placeholder here since we don't have type info
283 : : // without type annotation
284 : 11172 : defineVar("sep.nil", d_tm.mkSepNil(d_tm.getBooleanSort()));
285 : 11172 : addOperator(Kind::SEP_STAR, "sep");
286 : 11172 : addOperator(Kind::SEP_PTO, "pto");
287 : 11172 : addOperator(Kind::SEP_WAND, "wand");
288 : 11172 : ParserState::addOperator(Kind::SEP_STAR);
289 : 11172 : ParserState::addOperator(Kind::SEP_PTO);
290 : 11172 : ParserState::addOperator(Kind::SEP_WAND);
291 : 11172 : }
292 : :
293 : 24247 : void Smt2State::addCoreSymbols()
294 : : {
295 : 24247 : defineType("Bool", d_tm.getBooleanSort(), false);
296 : 24247 : Sort tupleSort = d_tm.mkTupleSort({});
297 : 24247 : defineType("Relation", d_tm.mkSetSort(tupleSort), false);
298 : 24247 : defineType("Table", d_tm.mkBagSort(tupleSort), false);
299 : 24247 : defineVar("true", d_tm.mkTrue(), true);
300 : 24247 : defineVar("false", d_tm.mkFalse(), true);
301 : 24247 : addOperator(Kind::AND, "and");
302 : 24247 : addOperator(Kind::DISTINCT, "distinct");
303 : 24247 : addOperator(Kind::EQUAL, "=");
304 : 24247 : addOperator(Kind::IMPLIES, "=>");
305 : 24247 : addOperator(Kind::ITE, "ite");
306 : 24247 : addOperator(Kind::NOT, "not");
307 : 24247 : addOperator(Kind::OR, "or");
308 : 24247 : addOperator(Kind::XOR, "xor");
309 : 24247 : addClosureKind(Kind::FORALL, "forall");
310 : 24247 : addClosureKind(Kind::EXISTS, "exists");
311 : 24247 : }
312 : :
313 : 16 : void Smt2State::addSkolemSymbols()
314 : : {
315 : 992 : for (int32_t s = static_cast<int32_t>(SkolemId::INTERNAL);
316 [ + + ]: 992 : s <= static_cast<int32_t>(SkolemId::NONE);
317 : : ++s)
318 : : {
319 : 976 : auto skolem = static_cast<SkolemId>(s);
320 : 976 : std::stringstream ss;
321 : 976 : ss << "@" << skolem;
322 : 976 : addSkolemId(skolem, ss.str());
323 : 976 : }
324 : 16 : }
325 : :
326 : 3229345 : void Smt2State::addOperator(Kind kind, const std::string& name)
327 : : {
328 [ + - ]: 6458690 : Trace("parser") << "Smt2State::addOperator( " << kind << ", " << name << " )"
329 : 3229345 : << std::endl;
330 : 3229345 : ParserState::addOperator(kind);
331 : 3229345 : d_operatorKindMap[name] = kind;
332 : 3229345 : }
333 : :
334 : 427733 : void Smt2State::addIndexedOperator(Kind tKind, const std::string& name)
335 : : {
336 : 427733 : ParserState::addOperator(tKind);
337 : 427733 : d_indexedOpKindMap[name] = tKind;
338 : 427733 : }
339 : :
340 : 60896 : void Smt2State::addClosureKind(Kind tKind, const std::string& name)
341 : : {
342 : : // also include it as a normal operator
343 : 60896 : addOperator(tKind, name);
344 : 60896 : d_closureKindMap[name] = tKind;
345 : 60896 : }
346 : :
347 : 976 : void Smt2State::addSkolemId(SkolemId skolemID, const std::string& name)
348 : : {
349 : 976 : addOperator(Kind::SKOLEM, name);
350 : 976 : d_skolemMap[name] = skolemID;
351 : 976 : }
352 : :
353 : 0 : bool Smt2State::isIndexedOperatorEnabled(const std::string& name) const
354 : : {
355 : 0 : return d_indexedOpKindMap.find(name) != d_indexedOpKindMap.end();
356 : : }
357 : :
358 : 5181313 : Kind Smt2State::getOperatorKind(const std::string& name) const
359 : : {
360 : : // precondition: isOperatorEnabled(name)
361 : 5181313 : return d_operatorKindMap.find(name)->second;
362 : : }
363 : :
364 : 6341353 : bool Smt2State::isOperatorEnabled(const std::string& name) const
365 : : {
366 : 6341353 : return d_operatorKindMap.find(name) != d_operatorKindMap.end();
367 : : }
368 : :
369 : 38 : modes::BlockModelsMode Smt2State::getBlockModelsMode(const std::string& mode)
370 : : {
371 [ + + ]: 38 : if (mode == "literals")
372 : : {
373 : 22 : return modes::BlockModelsMode::LITERALS;
374 : : }
375 [ + - ]: 16 : else if (mode == "values")
376 : : {
377 : 16 : return modes::BlockModelsMode::VALUES;
378 : : }
379 : 0 : parseError(std::string("Unknown block models mode `") + mode + "'");
380 : 0 : return modes::BlockModelsMode::LITERALS;
381 : : }
382 : :
383 : 23 : modes::LearnedLitType Smt2State::getLearnedLitType(const std::string& mode)
384 : : {
385 [ + + ]: 23 : if (mode == "preprocess_solved")
386 : : {
387 : 4 : return modes::LearnedLitType::PREPROCESS_SOLVED;
388 : : }
389 [ + + ]: 19 : else if (mode == "preprocess")
390 : : {
391 : 4 : return modes::LearnedLitType::PREPROCESS;
392 : : }
393 [ + + ]: 15 : else if (mode == "input")
394 : : {
395 : 3 : return modes::LearnedLitType::INPUT;
396 : : }
397 [ + + ]: 12 : else if (mode == "solvable")
398 : : {
399 : 4 : return modes::LearnedLitType::SOLVABLE;
400 : : }
401 [ + + ]: 8 : else if (mode == "constant_prop")
402 : : {
403 : 4 : return modes::LearnedLitType::CONSTANT_PROP;
404 : : }
405 [ + - ]: 4 : else if (mode == "internal")
406 : : {
407 : 4 : return modes::LearnedLitType::INTERNAL;
408 : : }
409 : 0 : parseError(std::string("Unknown learned literal type `") + mode + "'");
410 : 0 : return modes::LearnedLitType::UNKNOWN;
411 : : }
412 : :
413 : 25 : modes::ProofComponent Smt2State::getProofComponent(const std::string& pc)
414 : : {
415 [ + + ]: 25 : if (pc == "raw_preprocess")
416 : : {
417 : 5 : return modes::ProofComponent::RAW_PREPROCESS;
418 : : }
419 [ + + ]: 20 : else if (pc == "preprocess")
420 : : {
421 : 5 : return modes::ProofComponent::PREPROCESS;
422 : : }
423 [ + + ]: 15 : else if (pc == "sat")
424 : : {
425 : 6 : return modes::ProofComponent::SAT;
426 : : }
427 [ + + ]: 9 : else if (pc == "theory_lemmas")
428 : : {
429 : 5 : return modes::ProofComponent::THEORY_LEMMAS;
430 : : }
431 [ + - ]: 4 : else if (pc == "full")
432 : : {
433 : 4 : return modes::ProofComponent::FULL;
434 : : }
435 : 0 : parseError(std::string("Unknown proof component `") + pc + "'");
436 : 0 : return modes::ProofComponent::FULL;
437 : : }
438 : :
439 : 93 : modes::FindSynthTarget Smt2State::getFindSynthTarget(const std::string& fst)
440 : : {
441 [ + + ]: 93 : if (fst == "enum")
442 : : {
443 : 3 : return modes::FindSynthTarget::ENUM;
444 : : }
445 [ + + ]: 90 : else if (fst == "rewrite")
446 : : {
447 : 24 : return modes::FindSynthTarget::REWRITE;
448 : : }
449 [ + + ]: 66 : else if (fst == "rewrite_unsound")
450 : : {
451 : 24 : return modes::FindSynthTarget::REWRITE_UNSOUND;
452 : : }
453 [ + + ]: 42 : else if (fst == "rewrite_input")
454 : : {
455 : 30 : return modes::FindSynthTarget::REWRITE_INPUT;
456 : : }
457 [ + - ]: 12 : else if (fst == "query")
458 : : {
459 : 12 : return modes::FindSynthTarget::QUERY;
460 : : }
461 : 0 : parseError(std::string("Unknown find synth target `") + fst + "'");
462 : 0 : return modes::FindSynthTarget::ENUM;
463 : : }
464 : :
465 : 13330 : bool Smt2State::isTheoryEnabled(internal::theory::TheoryId theory) const
466 : : {
467 : 13330 : return d_logic.isTheoryEnabled(theory);
468 : : }
469 : :
470 : 1198839 : bool Smt2State::isHoEnabled() const { return d_logic.isHigherOrder(); }
471 : :
472 : 0 : bool Smt2State::hasCardinalityConstraints() const
473 : : {
474 : 0 : return d_logic.hasCardinalityConstraints();
475 : : }
476 : :
477 : 614821 : bool Smt2State::logicIsSet() { return d_logicSet; }
478 : :
479 : 0 : bool Smt2State::getTesterName(Term cons, std::string& name)
480 : : {
481 [ - - ]: 0 : if (strictModeEnabled())
482 : : {
483 : : // 2.6 or above uses indexed tester symbols, if we are in strict mode,
484 : : // we do not automatically define is-cons for constructor cons.
485 : 0 : return false;
486 : : }
487 : 0 : std::stringstream ss;
488 : 0 : ss << "is-" << cons;
489 : 0 : name = ss.str();
490 : 0 : return true;
491 : 0 : }
492 : :
493 : 185093 : Term Smt2State::mkIndexedConstant(const std::string& name,
494 : : const std::vector<uint32_t>& numerals)
495 : : {
496 [ + + ]: 185093 : if (d_logic.isTheoryEnabled(internal::theory::THEORY_FP))
497 : : {
498 [ + + ]: 3279 : if (name == "+oo")
499 : : {
500 [ - + ]: 9 : if (numerals.size() != 2)
501 : : {
502 : 0 : parseError("Unexpected number of numerals for +oo.");
503 : : }
504 : 9 : return d_tm.mkFloatingPointPosInf(numerals[0], numerals[1]);
505 : : }
506 [ + + ]: 3270 : else if (name == "-oo")
507 : : {
508 [ - + ]: 18 : if (numerals.size() != 2)
509 : : {
510 : 0 : parseError("Unexpected number of numerals for -oo.");
511 : : }
512 : 18 : return d_tm.mkFloatingPointNegInf(numerals[0], numerals[1]);
513 : : }
514 [ + + ]: 3252 : else if (name == "NaN")
515 : : {
516 [ - + ]: 15 : if (numerals.size() != 2)
517 : : {
518 : 0 : parseError("Unexpected number of numerals for NaN.");
519 : : }
520 : 15 : return d_tm.mkFloatingPointNaN(numerals[0], numerals[1]);
521 : : }
522 [ + + ]: 3237 : else if (name == "+zero")
523 : : {
524 [ + + ]: 29 : if (numerals.size() != 2)
525 : : {
526 : 3 : parseError("Unexpected number of numerals for +zero.");
527 : : }
528 : 28 : return d_tm.mkFloatingPointPosZero(numerals[0], numerals[1]);
529 : : }
530 [ + + ]: 3208 : else if (name == "-zero")
531 : : {
532 [ - + ]: 18 : if (numerals.size() != 2)
533 : : {
534 : 0 : parseError("Unexpected number of numerals for -zero.");
535 : : }
536 : 18 : return d_tm.mkFloatingPointNegZero(numerals[0], numerals[1]);
537 : : }
538 : : }
539 : :
540 : 185004 : if (d_logic.isTheoryEnabled(internal::theory::THEORY_BV)
541 [ + - ][ + - ]: 185004 : && name.find("bv") == 0)
[ + - ]
542 : : {
543 [ - + ]: 185004 : if (numerals.size() != 1)
544 : : {
545 : 0 : parseError("Unexpected number of numerals for bit-vector constant.");
546 : : }
547 : 185004 : std::string bvStr = name.substr(2);
548 : 185004 : return d_tm.mkBitVector(numerals[0], bvStr, 10);
549 : 185004 : }
550 : :
551 : : // NOTE: Theory parametric constants go here
552 : :
553 : 0 : parseError(std::string("Unknown indexed literal `") + name + "'");
554 : 0 : return Term();
555 : : }
556 : :
557 : 118 : Term Smt2State::mkIndexedConstant(const std::string& name,
558 : : const std::vector<std::string>& symbols)
559 : : {
560 [ + + ]: 118 : if (d_logic.isTheoryEnabled(internal::theory::THEORY_STRINGS))
561 : : {
562 [ + - ]: 14 : if (name == "char")
563 : : {
564 [ - + ]: 14 : if (symbols.size() != 1)
565 : : {
566 : 0 : parseError("Unexpected number of indices for char");
567 : : }
568 [ + - ][ - + ]: 14 : if (symbols[0].length() <= 2 || symbols[0].substr(0, 2) != "#x")
[ + - ][ - + ]
[ - - ]
569 : : {
570 : 0 : parseError(std::string("Unexpected index for char: `") + symbols[0]
571 : 0 : + "'");
572 : : }
573 : 28 : return mkCharConstant(symbols[0].substr(2));
574 : : }
575 : : }
576 [ + - ]: 104 : else if (d_logic.hasCardinalityConstraints())
577 : : {
578 [ + - ]: 104 : if (name == "fmf.card")
579 : : {
580 [ - + ]: 104 : if (symbols.size() != 2)
581 : : {
582 : 0 : parseError("Unexpected number of indices for fmf.card");
583 : : }
584 : 104 : Sort t = getSort(symbols[0]);
585 : : // convert second symbol back to a numeral
586 : 104 : uint32_t ubound = stringToUnsigned(symbols[1]);
587 : 104 : return d_tm.mkCardinalityConstraint(t, ubound);
588 : 104 : }
589 : : }
590 : 0 : parseError(std::string("Unknown indexed literal `") + name + "'");
591 : 0 : return Term();
592 : : }
593 : :
594 : 4443 : Term Smt2State::mkIndexedOp(Kind k,
595 : : const std::vector<std::string>& symbols,
596 : : const std::vector<Term>& args)
597 : : {
598 [ + + ][ + - ]: 4443 : if (k == Kind::APPLY_TESTER || k == Kind::APPLY_UPDATER)
599 : : {
600 [ - + ][ - + ]: 4443 : Assert(symbols.size() == 1);
[ - - ]
601 [ + + ]: 4443 : if (args.empty())
602 : : {
603 : 3 : parseError("Expected argument to tester/updater");
604 : : }
605 : 4442 : const std::string& cname = symbols[0];
606 : : // must be declared
607 : 4442 : checkDeclaration(cname, CHECK_DECLARED, SYM_VARIABLE);
608 : 4442 : Term f = getExpressionForNameAndType(cname, args[0].getSort());
609 [ + + ][ + - ]: 4442 : if (f.getKind() == Kind::APPLY_CONSTRUCTOR && f.getNumChildren() == 1)
[ + + ]
610 : : {
611 : : // for nullary constructors, must get the operator
612 : 1010 : f = f[0];
613 : : }
614 [ + + ]: 4442 : if (k == Kind::APPLY_TESTER)
615 : : {
616 [ - + ]: 4328 : if (!f.getSort().isDatatypeConstructor())
617 : : {
618 : 0 : parseError("Bad syntax for (_ is X), X must be a constructor.");
619 : : }
620 : : // get the datatype that f belongs to
621 : 4328 : Sort sf = f.getSort().getDatatypeConstructorCodomainSort();
622 : 4328 : Datatype d = sf.getDatatype();
623 : : // lookup by name
624 : 4328 : DatatypeConstructor dc = d.getConstructor(f.toString());
625 : 4328 : return dc.getTesterTerm();
626 : 4328 : }
627 : : else
628 : : {
629 [ - + ][ - + ]: 114 : Assert(k == Kind::APPLY_UPDATER);
[ - - ]
630 [ - + ]: 114 : if (!f.getSort().isDatatypeSelector())
631 : : {
632 : 0 : parseError("Bad syntax for (_ update X), X must be a selector.");
633 : : }
634 : 114 : std::string sname = f.toString();
635 : : // get the datatype that f belongs to
636 : 114 : Sort sf = f.getSort().getDatatypeSelectorDomainSort();
637 : 114 : Datatype d = sf.getDatatype();
638 : : // find the selector
639 : 114 : DatatypeSelector ds = d.getSelector(f.toString());
640 : : // get the updater term
641 : 114 : return ds.getUpdaterTerm();
642 : 114 : }
643 : 4442 : }
644 : 0 : std::stringstream ss;
645 : 0 : ss << "Unknown indexed op kind " << k;
646 : 0 : parseError(ss.str());
647 : 0 : return Term();
648 : 0 : }
649 : :
650 : 178501 : Kind Smt2State::getIndexedOpKind(const std::string& name)
651 : : {
652 : 178501 : const auto& kIt = d_indexedOpKindMap.find(name);
653 [ + - ]: 178501 : if (kIt != d_indexedOpKindMap.end())
654 : : {
655 : 178501 : return (*kIt).second;
656 : : }
657 : 0 : parseError(std::string("Unknown indexed function `") + name + "'");
658 : 0 : return Kind::UNDEFINED_KIND;
659 : : }
660 : :
661 : 0 : Kind Smt2State::getClosureKind(const std::string& name)
662 : : {
663 : 0 : const auto& kIt = d_closureKindMap.find(name);
664 [ - - ]: 0 : if (kIt != d_closureKindMap.end())
665 : : {
666 : 0 : return (*kIt).second;
667 : : }
668 : 0 : parseError(std::string("Unknown closure `") + name + "'");
669 : 0 : return Kind::UNDEFINED_KIND;
670 : : }
671 : :
672 : 758 : Term Smt2State::setupDefineFunRecScope(
673 : : const std::string& fname,
674 : : const std::vector<std::pair<std::string, Sort>>& sortedVarNames,
675 : : Sort t,
676 : : std::vector<Term>& flattenVars)
677 : : {
678 : 758 : std::vector<Sort> sorts;
679 [ + + ]: 2186 : for (const std::pair<std::string, Sort>& svn : sortedVarNames)
680 : : {
681 : 1428 : sorts.push_back(svn.second);
682 : : }
683 : :
684 : : // make the flattened function type, add bound variables
685 : : // to flattenVars if the defined function was given a function return type.
686 : 758 : Sort ft = flattenFunctionType(sorts, t, flattenVars);
687 : :
688 [ + + ]: 758 : if (!sorts.empty())
689 : : {
690 : 722 : ft = d_tm.mkFunctionSort(sorts, ft);
691 : : }
692 : : // bind now, with overloading
693 : 1516 : return bindVar(fname, ft, true);
694 : 758 : }
695 : :
696 : 758 : void Smt2State::pushDefineFunRecScope(
697 : : const std::vector<std::pair<std::string, Sort>>& sortedVarNames,
698 : : const std::vector<Term>& flattenVars,
699 : : std::vector<Term>& bvs)
700 : : {
701 : 758 : pushScope();
702 : : // bound variables are those that are explicitly named in the preamble
703 : : // of the define-fun(s)-rec command, we define them here
704 [ + + ]: 2186 : for (const std::pair<std::string, Sort>& svn : sortedVarNames)
705 : : {
706 : 1428 : Term v = bindBoundVar(svn.first, svn.second, d_freshBinders);
707 : 1428 : bvs.push_back(v);
708 : 1428 : }
709 : :
710 : 758 : bvs.insert(bvs.end(), flattenVars.begin(), flattenVars.end());
711 : 758 : }
712 : :
713 : 83 : void Smt2State::reset()
714 : : {
715 : 83 : d_logicSet = false;
716 : 83 : d_logic = internal::LogicInfo();
717 : 83 : d_operatorKindMap.clear();
718 : 83 : d_lastNamedTerm = std::pair<Term, std::string>();
719 : 83 : }
720 : :
721 : 53 : std::unique_ptr<Cmd> Smt2State::invConstraint(
722 : : const std::vector<std::string>& names)
723 : : {
724 : 53 : checkThatLogicIsSet();
725 [ + - ]: 53 : Trace("parser-sygus") << "Sygus : define sygus funs..." << std::endl;
726 [ + - ]: 53 : Trace("parser-sygus") << "Sygus : read inv-constraint..." << std::endl;
727 : :
728 [ - + ]: 53 : if (names.size() != 4)
729 : : {
730 : 0 : parseError(
731 : : "Bad syntax for inv-constraint: expected 4 "
732 : : "arguments.");
733 : : }
734 : :
735 : 53 : std::vector<Term> terms;
736 [ + + ]: 265 : for (const std::string& name : names)
737 : : {
738 [ - + ]: 212 : if (!isDeclared(name))
739 : : {
740 : 0 : std::stringstream ss;
741 : 0 : ss << "Function " << name << " in inv-constraint is not defined.";
742 : 0 : parseError(ss.str());
743 : 0 : }
744 : :
745 : 212 : terms.push_back(getVariable(name));
746 : : }
747 : :
748 : 106 : return std::unique_ptr<Cmd>(new SygusInvConstraintCommand(terms));
749 : 53 : }
750 : :
751 : 24252 : void Smt2State::setLogic(std::string name)
752 : : {
753 : 24252 : bool smLogicAlreadySet = getSymbolManager()->isLogicSet();
754 : : // if logic is already set, this is an error
755 [ + + ]: 24252 : if (d_logicSet)
756 : : {
757 : 15 : parseError("Only one set-logic is allowed.");
758 : : }
759 : 24247 : d_logicSet = true;
760 : 24247 : d_logic = name;
761 : :
762 : : // if sygus is enabled, we must enable UF, datatypes, and integer arithmetic
763 [ + + ]: 24247 : if (sygus())
764 : : {
765 [ - + ]: 971 : if (!d_logic.isQuantified())
766 : : {
767 : 0 : warning("Logics in sygus are assumed to contain quantifiers.");
768 : 0 : warning("Omit QF_ from the logic to avoid this warning.");
769 : : }
770 : : }
771 : :
772 : : // Core theory belongs to every logic
773 : 24247 : addCoreSymbols();
774 : :
775 : : // add skolems
776 [ + + ]: 24247 : if (d_solver->getOption("parse-skolem-definitions") == "true")
777 : : {
778 : 16 : addSkolemSymbols();
779 : : }
780 : :
781 [ + + ]: 24247 : if (d_logic.isTheoryEnabled(internal::theory::THEORY_UF))
782 : : {
783 : 15260 : ParserState::addOperator(Kind::APPLY_UF);
784 : : }
785 : :
786 [ + + ]: 24247 : if (d_logic.isHigherOrder())
787 : : {
788 : 1045 : addOperator(Kind::HO_APPLY, "@");
789 : : // lambda is a closure kind
790 : 1045 : addClosureKind(Kind::LAMBDA, "lambda");
791 : : }
792 : :
793 [ + + ]: 24247 : if (d_logic.isTheoryEnabled(internal::theory::THEORY_ARITH))
794 : : {
795 [ + + ]: 18085 : if (d_logic.areIntegersUsed())
796 : : {
797 : 16550 : defineType("Int", d_tm.getIntegerSort(), false);
798 : 16550 : addArithmeticOperators();
799 [ + + ][ + + ]: 16550 : if (!strictModeEnabled() || !d_logic.isLinear())
[ + + ]
800 : : {
801 : 16539 : addOperator(Kind::INTS_DIVISION, "div");
802 : 16539 : addOperator(Kind::INTS_MODULUS, "mod");
803 : 16539 : addOperator(Kind::ABS, "abs");
804 : : }
805 [ + + ]: 16550 : if (!strictModeEnabled())
806 : : {
807 : 16530 : addOperator(Kind::INTS_DIVISION_TOTAL, "div_total");
808 : 16530 : addOperator(Kind::INTS_MODULUS_TOTAL, "mod_total");
809 : : }
810 : 16550 : addIndexedOperator(Kind::DIVISIBLE, "divisible");
811 : : }
812 : :
813 [ + + ]: 18085 : if (d_logic.areRealsUsed())
814 : : {
815 : 13279 : defineType("Real", d_tm.getRealSort(), false);
816 : 13279 : addArithmeticOperators();
817 : 13279 : addOperator(Kind::DIVISION, "/");
818 [ + + ]: 13279 : if (!strictModeEnabled())
819 : : {
820 : 13262 : addOperator(Kind::ABS, "abs");
821 : 13262 : addOperator(Kind::DIVISION_TOTAL, "/_total");
822 : : }
823 : : }
824 : :
825 [ + + ][ + + ]: 18085 : if (d_logic.areIntegersUsed() && d_logic.areRealsUsed())
[ + + ]
826 : : {
827 : 11744 : addOperator(Kind::TO_INTEGER, "to_int");
828 : 11744 : addOperator(Kind::IS_INTEGER, "is_int");
829 : 11744 : addOperator(Kind::TO_REAL, "to_real");
830 : : }
831 : :
832 [ + + ]: 18085 : if (d_logic.areTranscendentalsUsed())
833 : : {
834 : 11465 : defineVar("real.pi", d_tm.mkPi());
835 : 11465 : addTranscendentalOperators();
836 : : }
837 [ + + ]: 18085 : if (!strictModeEnabled())
838 : : {
839 : : // integer version of AND
840 : 18061 : addIndexedOperator(Kind::IAND, "iand");
841 : : // parametric integer version of AND
842 : 18061 : addOperator(Kind::PIAND, "piand");
843 : : // pow2
844 : 18061 : addOperator(Kind::POW2, "int.pow2");
845 : : // log2
846 : 18061 : addOperator(Kind::LOG2, "int.log2");
847 : : }
848 : : }
849 : :
850 [ + + ]: 24247 : if (d_logic.isTheoryEnabled(internal::theory::THEORY_ARRAYS))
851 : : {
852 : 13093 : addOperator(Kind::SELECT, "select");
853 : 13093 : addOperator(Kind::STORE, "store");
854 : 13093 : addOperator(Kind::EQ_RANGE, "eqrange");
855 : : }
856 : :
857 [ + + ]: 24247 : if (d_logic.isTheoryEnabled(internal::theory::THEORY_BV))
858 : : {
859 : 15722 : addBitvectorOperators();
860 : :
861 : 15722 : if (d_logic.isTheoryEnabled(internal::theory::THEORY_ARITH)
862 [ + + ][ + + ]: 15722 : && d_logic.areIntegersUsed())
[ + + ]
863 : : {
864 : : // Conversions between bit-vectors and integers
865 [ + + ]: 11542 : if (!strictModeEnabled())
866 : : {
867 : : // For the sake of backwards compatability at the moment we support
868 : : // the old syntax, which in the case of bv2nat maps directly to
869 : : // Kind::BITVECTOR_UBV_TO_INT.
870 : 11533 : addOperator(Kind::BITVECTOR_UBV_TO_INT, "bv2nat");
871 : 11533 : addIndexedOperator(Kind::INT_TO_BITVECTOR, "int2bv");
872 : : }
873 : 11542 : addIndexedOperator(Kind::INT_TO_BITVECTOR, "int_to_bv");
874 : 11542 : addOperator(Kind::BITVECTOR_UBV_TO_INT, "ubv_to_int");
875 : 11542 : addOperator(Kind::BITVECTOR_SBV_TO_INT, "sbv_to_int");
876 : : }
877 : : }
878 : :
879 [ + + ]: 24247 : if (d_logic.isTheoryEnabled(internal::theory::THEORY_DATATYPES))
880 : : {
881 : 11563 : const std::vector<Sort> types;
882 : 11563 : defineType("UnitTuple", d_tm.mkTupleSort(types), false);
883 : 11563 : addDatatypesOperators();
884 : 11563 : }
885 : :
886 [ + + ]: 24247 : if (d_logic.isTheoryEnabled(internal::theory::THEORY_SETS))
887 : : {
888 : : // the Boolean sort is a placeholder here since we don't have type info
889 : : // without type annotation
890 : 11357 : Sort btype = d_tm.getBooleanSort();
891 : 11357 : defineVar("set.empty", d_tm.mkEmptySet(d_tm.mkSetSort(btype)));
892 : 11357 : defineVar("set.universe", d_tm.mkUniverseSet(btype));
893 : :
894 : 11357 : addOperator(Kind::SET_UNION, "set.union");
895 : 11357 : addOperator(Kind::SET_INTER, "set.inter");
896 : 11357 : addOperator(Kind::SET_MINUS, "set.minus");
897 : 11357 : addOperator(Kind::SET_SUBSET, "set.subset");
898 : 11357 : addOperator(Kind::SET_MEMBER, "set.member");
899 : 11357 : addOperator(Kind::SET_SINGLETON, "set.singleton");
900 : 11357 : addOperator(Kind::SET_INSERT, "set.insert");
901 : 11357 : addOperator(Kind::SET_CARD, "set.card");
902 : 11357 : addOperator(Kind::SET_COMPLEMENT, "set.complement");
903 : 11357 : addOperator(Kind::SET_CHOOSE, "set.choose");
904 : 11357 : addOperator(Kind::SET_IS_EMPTY, "set.is_empty");
905 : 11357 : addOperator(Kind::SET_IS_SINGLETON, "set.is_singleton");
906 : 11357 : addOperator(Kind::SET_MAP, "set.map");
907 : 11357 : addOperator(Kind::SET_FILTER, "set.filter");
908 : 11357 : addOperator(Kind::SET_ALL, "set.all");
909 : 11357 : addOperator(Kind::SET_SOME, "set.some");
910 : 11357 : addOperator(Kind::SET_FOLD, "set.fold");
911 : 11357 : addOperator(Kind::RELATION_JOIN, "rel.join");
912 : 11357 : addOperator(Kind::RELATION_TABLE_JOIN, "rel.table_join");
913 : 11357 : addOperator(Kind::RELATION_PRODUCT, "rel.product");
914 : 11357 : addOperator(Kind::RELATION_TRANSPOSE, "rel.transpose");
915 : 11357 : addOperator(Kind::RELATION_TCLOSURE, "rel.tclosure");
916 : 11357 : addOperator(Kind::RELATION_JOIN_IMAGE, "rel.join_image");
917 : 11357 : addOperator(Kind::RELATION_IDEN, "rel.iden");
918 : : // these operators can be with/without indices
919 : 11357 : addOperator(Kind::RELATION_GROUP, "rel.group");
920 : 11357 : addOperator(Kind::RELATION_AGGREGATE, "rel.aggr");
921 : 11357 : addOperator(Kind::RELATION_PROJECT, "rel.project");
922 : 11357 : addIndexedOperator(Kind::RELATION_GROUP, "rel.group");
923 : 11357 : addIndexedOperator(Kind::RELATION_TABLE_JOIN, "rel.table_join");
924 : 11357 : addIndexedOperator(Kind::RELATION_AGGREGATE, "rel.aggr");
925 : 11357 : addIndexedOperator(Kind::RELATION_PROJECT, "rel.project");
926 : : // set.comprehension is a closure kind
927 : 11357 : addClosureKind(Kind::SET_COMPREHENSION, "set.comprehension");
928 : 11357 : }
929 : :
930 [ + + ]: 24247 : if (d_logic.isTheoryEnabled(internal::theory::THEORY_BAGS))
931 : : {
932 : : // the Boolean sort is a placeholder here since we don't have type info
933 : : // without type annotation
934 : 11161 : Sort btype = d_tm.getBooleanSort();
935 : 11161 : defineVar("bag.empty", d_tm.mkEmptyBag(d_tm.mkBagSort(btype)));
936 : 11161 : addOperator(Kind::BAG_UNION_MAX, "bag.union_max");
937 : 11161 : addOperator(Kind::BAG_UNION_DISJOINT, "bag.union_disjoint");
938 : 11161 : addOperator(Kind::BAG_INTER_MIN, "bag.inter_min");
939 : 11161 : addOperator(Kind::BAG_DIFFERENCE_SUBTRACT, "bag.difference_subtract");
940 : 11161 : addOperator(Kind::BAG_DIFFERENCE_REMOVE, "bag.difference_remove");
941 : 11161 : addOperator(Kind::BAG_SUBBAG, "bag.subbag");
942 : 11161 : addOperator(Kind::BAG_COUNT, "bag.count");
943 : 11161 : addOperator(Kind::BAG_MEMBER, "bag.member");
944 : 11161 : addOperator(Kind::BAG_SETOF, "bag.setof");
945 : 11161 : addOperator(Kind::BAG_MAKE, "bag");
946 : 11161 : addOperator(Kind::BAG_CARD, "bag.card");
947 : 11161 : addOperator(Kind::BAG_CHOOSE, "bag.choose");
948 : 11161 : addOperator(Kind::BAG_MAP, "bag.map");
949 : 11161 : addOperator(Kind::BAG_FILTER, "bag.filter");
950 : 11161 : addOperator(Kind::BAG_ALL, "bag.all");
951 : 11161 : addOperator(Kind::BAG_SOME, "bag.some");
952 : 11161 : addOperator(Kind::BAG_FOLD, "bag.fold");
953 : 11161 : addOperator(Kind::BAG_PARTITION, "bag.partition");
954 : 11161 : addOperator(Kind::TABLE_PRODUCT, "table.product");
955 : 11161 : addOperator(Kind::BAG_PARTITION, "table.group");
956 : : // these operators can be with/without indices
957 : 11161 : addOperator(Kind::TABLE_PROJECT, "table.project");
958 : 11161 : addOperator(Kind::TABLE_AGGREGATE, "table.aggr");
959 : 11161 : addOperator(Kind::TABLE_JOIN, "table.join");
960 : 11161 : addOperator(Kind::TABLE_GROUP, "table.group");
961 : 11161 : addIndexedOperator(Kind::TABLE_PROJECT, "table.project");
962 : 11161 : addIndexedOperator(Kind::TABLE_AGGREGATE, "table.aggr");
963 : 11161 : addIndexedOperator(Kind::TABLE_JOIN, "table.join");
964 : 11161 : addIndexedOperator(Kind::TABLE_GROUP, "table.group");
965 : 11161 : }
966 [ + + ]: 24247 : if (d_logic.isTheoryEnabled(internal::theory::THEORY_STRINGS))
967 : : {
968 : 12841 : defineType("String", d_tm.getStringSort(), false);
969 : 12841 : defineType("RegLan", d_tm.getRegExpSort(), false);
970 : 12841 : defineType("Int", d_tm.getIntegerSort(), false);
971 : :
972 : 12841 : defineVar("re.none", d_tm.mkRegexpNone());
973 : 12841 : defineVar("re.allchar", d_tm.mkRegexpAllchar());
974 : :
975 : : // Boolean is a placeholder
976 : 12841 : defineVar("seq.empty", d_tm.mkEmptySequence(d_tm.getBooleanSort()));
977 : :
978 : 12841 : addStringOperators();
979 : : }
980 : :
981 [ + + ]: 24247 : if (d_logic.isQuantified())
982 : : {
983 : 14037 : addQuantifiersOperators();
984 : : }
985 : :
986 [ + + ]: 24247 : if (d_logic.isTheoryEnabled(internal::theory::THEORY_FP))
987 : : {
988 : 11335 : defineType("RoundingMode", d_tm.getRoundingModeSort(), false);
989 : 11335 : defineType("Float16", d_tm.mkFloatingPointSort(5, 11), false);
990 : 11335 : defineType("Float32", d_tm.mkFloatingPointSort(8, 24), false);
991 : 11335 : defineType("Float64", d_tm.mkFloatingPointSort(11, 53), false);
992 : 11335 : defineType("Float128", d_tm.mkFloatingPointSort(15, 113), false);
993 : :
994 : 11335 : defineVar("RNE",
995 : 22670 : d_tm.mkRoundingMode(RoundingMode::ROUND_NEAREST_TIES_TO_EVEN));
996 : 11335 : defineVar("roundNearestTiesToEven",
997 : 22670 : d_tm.mkRoundingMode(RoundingMode::ROUND_NEAREST_TIES_TO_EVEN));
998 : 11335 : defineVar("RNA",
999 : 22670 : d_tm.mkRoundingMode(RoundingMode::ROUND_NEAREST_TIES_TO_AWAY));
1000 : 11335 : defineVar("roundNearestTiesToAway",
1001 : 22670 : d_tm.mkRoundingMode(RoundingMode::ROUND_NEAREST_TIES_TO_AWAY));
1002 : 11335 : defineVar("RTP", d_tm.mkRoundingMode(RoundingMode::ROUND_TOWARD_POSITIVE));
1003 : 11335 : defineVar("roundTowardPositive",
1004 : 22670 : d_tm.mkRoundingMode(RoundingMode::ROUND_TOWARD_POSITIVE));
1005 : 11335 : defineVar("RTN", d_tm.mkRoundingMode(RoundingMode::ROUND_TOWARD_NEGATIVE));
1006 : 11335 : defineVar("roundTowardNegative",
1007 : 22670 : d_tm.mkRoundingMode(RoundingMode::ROUND_TOWARD_NEGATIVE));
1008 : 11335 : defineVar("RTZ", d_tm.mkRoundingMode(RoundingMode::ROUND_TOWARD_ZERO));
1009 : 11335 : defineVar("roundTowardZero",
1010 : 22670 : d_tm.mkRoundingMode(RoundingMode::ROUND_TOWARD_ZERO));
1011 : :
1012 : 11335 : addFloatingPointOperators();
1013 : : }
1014 : :
1015 [ + + ]: 24247 : if (d_logic.isTheoryEnabled(internal::theory::THEORY_FF))
1016 : : {
1017 : 11513 : addFiniteFieldOperators();
1018 : : }
1019 : :
1020 [ + + ]: 24247 : if (d_logic.isTheoryEnabled(internal::theory::THEORY_SEP))
1021 : : {
1022 : 11172 : addSepOperators();
1023 : : }
1024 : :
1025 : : // Builtin symbols of the logic are declared at context level zero, hence
1026 : : // we push the outermost scope in the symbol manager here.
1027 : : // We only do this if the logic has not already been set, in which case we have already
1028 : : // pushed the outermost context (and this method redeclares the symbols which does
1029 : : // not impact the symbol manager).
1030 : : // TODO (cvc5-projects #693): refactor this so that this method is moved to the
1031 : : // symbol manager and only called once per symbol manager.
1032 [ + + ]: 24247 : if (!smLogicAlreadySet)
1033 : : {
1034 : 24030 : pushScope(true);
1035 : : }
1036 : 24247 : }
1037 : :
1038 : 808 : Grammar* Smt2State::mkGrammar(const std::vector<Term>& boundVars,
1039 : : const std::vector<Term>& ntSymbols)
1040 : : {
1041 : 1616 : d_allocGrammars.emplace_back(
1042 : 808 : new Grammar(d_solver->mkGrammar(boundVars, ntSymbols)));
1043 : 808 : return d_allocGrammars.back().get();
1044 : : }
1045 : :
1046 : 50703 : bool Smt2State::sygus() const { return d_isSygus; }
1047 : :
1048 : 0 : bool Smt2State::hasGrammars() const
1049 : : {
1050 : 0 : return sygus() || d_solver->getOption("produce-abducts") == "true"
1051 : 0 : || d_solver->getOption("produce-interpolants") == "true";
1052 : : }
1053 : :
1054 : 94077 : bool Smt2State::usingFreshBinders() const { return d_freshBinders; }
1055 : :
1056 : 614821 : void Smt2State::checkThatLogicIsSet()
1057 : : {
1058 [ + + ]: 614821 : if (!logicIsSet())
1059 : : {
1060 [ + + ]: 50 : if (strictModeEnabled())
1061 : : {
1062 : 6 : parseError("set-logic must appear before this point.");
1063 : : }
1064 : : else
1065 : : {
1066 : 48 : SymManager* sm = getSymbolManager();
1067 : : // the calls to setLogic below set the logic on the solver directly
1068 [ + + ]: 48 : if (sm->isLogicForced())
1069 : : {
1070 : 4 : setLogic(sm->getLogic());
1071 : : }
1072 : : else
1073 : : {
1074 : 44 : warning("No set-logic command was given before this point.");
1075 : 44 : warning("cvc5 will make all theories available.");
1076 : 44 : warning(
1077 : : "Consider setting a stricter logic for (likely) better "
1078 : : "performance.");
1079 : 44 : warning("To suppress this warning in the future use (set-logic ALL).");
1080 : :
1081 : 44 : setLogic("ALL");
1082 : : }
1083 : : // Set the logic directly in the solver, without a command. Notice this is
1084 : : // important since we do not want to enqueue a set-logic command and
1085 : : // fully initialize the underlying SolverEngine in the meantime before the
1086 : : // command has a chance to execute, which would lead to an error.
1087 : 48 : std::string logic = d_logic.getLogicString();
1088 : 48 : d_solver->setLogic(logic);
1089 : : // set the logic on the symbol manager as well, non-forced
1090 : 48 : sm->setLogic(logic);
1091 : 48 : }
1092 : : }
1093 : 614819 : }
1094 : :
1095 : 11469 : void Smt2State::checkLogicAllowsFreeSorts()
1096 : : {
1097 : 11469 : if (!d_logic.isTheoryEnabled(internal::theory::THEORY_UF)
1098 [ + + ]: 108 : && !d_logic.isTheoryEnabled(internal::theory::THEORY_ARRAYS)
1099 [ - + ]: 8 : && !d_logic.isTheoryEnabled(internal::theory::THEORY_DATATYPES)
1100 [ - - ]: 0 : && !d_logic.isTheoryEnabled(internal::theory::THEORY_SETS)
1101 [ + + ][ - - ]: 11577 : && !d_logic.isTheoryEnabled(internal::theory::THEORY_BAGS))
[ - + ]
1102 : : {
1103 : 0 : parseErrorLogic("Free sort symbols not allowed in ");
1104 : : }
1105 : 11469 : }
1106 : :
1107 : 41619 : void Smt2State::checkLogicAllowsFunctions()
1108 : : {
1109 [ + + ][ - + ]: 41619 : if (!d_logic.isTheoryEnabled(internal::theory::THEORY_UF) && !isHoEnabled())
[ - + ]
1110 : : {
1111 : 0 : parseError(
1112 : : "Functions (of non-zero arity) cannot "
1113 : : "be declared in logic "
1114 : 0 : + d_logic.getLogicString()
1115 : 0 : + ". Try including UF or adding the prefix HO_.");
1116 : : }
1117 : 41619 : }
1118 : :
1119 : 1247148 : bool Smt2State::isAbstractValue(const std::string& name)
1120 : : {
1121 [ + + ][ + - ]: 2420983 : return name.length() >= 2 && name[0] == '@' && name[1] != '0'
1122 [ + + ][ - + ]: 2420983 : && name.find_first_not_of("0123456789", 1) == std::string::npos;
1123 : : }
1124 : :
1125 : 840173 : Term Smt2State::mkRealOrIntFromNumeral(const std::string& str)
1126 : : {
1127 : : // if arithmetic is enabled, and integers are disabled
1128 : 840173 : if (d_logic.isTheoryEnabled(internal::theory::THEORY_ARITH)
1129 [ + + ][ + + ]: 840173 : && !d_logic.areIntegersUsed())
[ + + ]
1130 : : {
1131 : 77604 : return d_tm.mkReal(str);
1132 : : }
1133 : 762569 : return d_tm.mkInteger(str);
1134 : : }
1135 : :
1136 : 2091 : void Smt2State::parseOpApplyTypeAscription(ParseOp& p, Sort type)
1137 : : {
1138 [ + - ]: 4182 : Trace("parser") << "parseOpApplyTypeAscription : " << p << " " << type
1139 : 2091 : << std::endl;
1140 [ + - ]: 2091 : if (p.d_expr.isNull())
1141 : : {
1142 [ + - ]: 4182 : Trace("parser-overloading")
1143 : 0 : << "Getting variable expression with name " << p.d_name << " and type "
1144 : 2091 : << type << std::endl;
1145 : : // get the variable expression for the type
1146 [ + + ]: 2091 : if (isDeclared(p.d_name, SYM_VARIABLE))
1147 : : {
1148 : 1283 : p.d_expr = getExpressionForNameAndType(p.d_name, type);
1149 : 1283 : p.d_name = std::string("");
1150 : : }
1151 [ + + ]: 2091 : if (p.d_name == "const")
1152 : : {
1153 : : // We use a placeholder as a way to store the type of the constant array.
1154 : : // Since ParseOp only contains a Term field, it is stored as a constant
1155 : : // of the given type. The kind INTERNAL_KIND is used to mark that we
1156 : : // are a placeholder.
1157 : 221 : p.d_kind = Kind::INTERNAL_KIND;
1158 : 221 : p.d_expr = d_tm.mkConst(type, "_placeholder_");
1159 : 221 : return;
1160 : : }
1161 [ + + ]: 1870 : else if (p.d_name.find("ff") == 0)
1162 : : {
1163 : 587 : std::string rest = p.d_name.substr(2);
1164 [ - + ]: 587 : if (!type.isFiniteField())
1165 : : {
1166 : 0 : std::stringstream ss;
1167 : 0 : ss << "expected finite field sort to ascribe " << p.d_name
1168 : 0 : << " but found sort: " << type;
1169 : 0 : parseError(ss.str());
1170 : 0 : }
1171 : 587 : p.d_expr = d_tm.mkFiniteFieldElem(rest, type);
1172 : 587 : return;
1173 : 587 : }
1174 [ - + ]: 1283 : if (p.d_expr.isNull())
1175 : : {
1176 : 0 : std::stringstream ss;
1177 : 0 : ss << "Could not resolve expression with name " << p.d_name
1178 : 0 : << " and type " << type << std::endl;
1179 : 0 : parseError(ss.str());
1180 : 0 : }
1181 : : }
1182 [ + - ]: 1283 : Trace("parser-qid") << "Resolve ascription " << type << " on " << p.d_expr;
1183 [ + - ][ - + ]: 1283 : Trace("parser-qid") << " " << p.d_expr.getKind() << " " << p.d_expr.getSort();
[ - - ]
1184 [ + - ]: 1283 : Trace("parser-qid") << std::endl;
1185 : : // otherwise, we process the type ascription
1186 : 1283 : p.d_expr = applyTypeAscription(p.d_expr, type);
1187 : : }
1188 : :
1189 : 0 : Term Smt2State::parseOpToExpr(ParseOp& p)
1190 : : {
1191 [ - - ]: 0 : Trace("parser") << "parseOpToExpr: " << p << std::endl;
1192 : 0 : Term expr;
1193 [ - - ]: 0 : if (p.d_kind != Kind::NULL_TERM)
1194 : : {
1195 : 0 : parseError(
1196 : : "Bad syntax for qualified identifier operator in term position.");
1197 : : }
1198 [ - - ]: 0 : else if (!p.d_expr.isNull())
1199 : : {
1200 : 0 : expr = p.d_expr;
1201 : : }
1202 : : else
1203 : : {
1204 : 0 : checkDeclaration(p.d_name, CHECK_DECLARED, SYM_VARIABLE);
1205 : 0 : expr = getVariable(p.d_name);
1206 : : }
1207 : 0 : Assert(!expr.isNull());
1208 : 0 : return expr;
1209 : 0 : }
1210 : :
1211 : 6164983 : Term Smt2State::applyParseOp(const ParseOp& p, std::vector<Term>& args)
1212 : : {
1213 : 6164983 : bool isBuiltinOperator = false;
1214 : : // the builtin kind of the overall return expression
1215 : 6164983 : Kind kind = Kind::NULL_TERM;
1216 : : // First phase: process the operator
1217 [ - + ]: 6164983 : if (TraceIsOn("parser"))
1218 : : {
1219 [ - - ]: 0 : Trace("parser") << "applyParseOp: " << p << " to:" << std::endl;
1220 [ - - ]: 0 : for (std::vector<Term>::iterator i = args.begin(); i != args.end(); ++i)
1221 : : {
1222 [ - - ]: 0 : Trace("parser") << "++ " << *i << std::endl;
1223 : : }
1224 : : }
1225 [ + + ]: 6164983 : if (p.d_kind == Kind::NULLABLE_LIFT)
1226 : : {
1227 : 12 : auto it = d_operatorKindMap.find(p.d_name);
1228 [ + + ]: 12 : if (it == d_operatorKindMap.end())
1229 : : {
1230 : : // the lifted symbol is not a defined kind. So we construct a normal
1231 : : // term.
1232 : : // Input : ((_ nullable.lift f) x y)
1233 : : // output: (nullable.lift f x y)
1234 : 9 : ParserState::checkDeclaration(p.d_name, DeclarationCheck::CHECK_DECLARED);
1235 : 9 : Term function = getVariable(p.d_name);
1236 : 9 : args.insert(args.begin(), function);
1237 : 9 : return d_tm.mkTerm(Kind::NULLABLE_LIFT, args);
1238 : 9 : }
1239 : : else
1240 : : {
1241 : 3 : Kind liftedKind = getOperatorKind(p.d_name);
1242 : 3 : return d_tm.mkNullableLift(liftedKind, args);
1243 : : }
1244 : : }
1245 [ + + ]: 6164971 : if (!p.d_indices.empty())
1246 : : {
1247 : 174046 : Op op;
1248 : 174046 : Kind k = getIndexedOpKind(p.d_name);
1249 [ + + ]: 174046 : if (k == Kind::UNDEFINED_KIND)
1250 : : {
1251 : : // Resolve indexed symbols that cannot be resolved without knowing the
1252 : : // type of the arguments. This is currently limited to `to_fp`,
1253 : : // `tuple.select`, and `tuple.update`.
1254 : 1263 : size_t nchildren = args.size();
1255 [ + + ]: 1263 : if (p.d_name == "to_fp")
1256 : : {
1257 [ + + ]: 272 : if (nchildren == 1)
1258 : : {
1259 : 107 : kind = Kind::FLOATINGPOINT_TO_FP_FROM_IEEE_BV;
1260 : 107 : op = d_tm.mkOp(kind, p.d_indices);
1261 : : }
1262 [ + - ][ + + ]: 165 : else if (nchildren > 2 || nchildren == 0)
1263 : : {
1264 : 1 : std::stringstream ss;
1265 : : ss << "Wrong number of arguments for indexed operator to_fp, "
1266 : : "expected "
1267 : 1 : "1 or 2, got "
1268 : 1 : << nchildren;
1269 : 2 : parseError(ss.str());
1270 : 1 : }
1271 [ - + ]: 164 : else if (!args[0].getSort().isRoundingMode())
1272 : : {
1273 : 0 : std::stringstream ss;
1274 : 0 : ss << "Expected a rounding mode as the first argument, got "
1275 : 0 : << args[0].getSort();
1276 : 0 : parseError(ss.str());
1277 : 0 : }
1278 : : else
1279 : : {
1280 : 164 : Sort t = args[1].getSort();
1281 : :
1282 [ + + ]: 164 : if (t.isFloatingPoint())
1283 : : {
1284 : 16 : kind = Kind::FLOATINGPOINT_TO_FP_FROM_FP;
1285 : 16 : op = d_tm.mkOp(kind, p.d_indices);
1286 : : }
1287 [ + - ][ + + ]: 148 : else if (t.isInteger() || t.isReal())
[ + + ]
1288 : : {
1289 : 101 : kind = Kind::FLOATINGPOINT_TO_FP_FROM_REAL;
1290 : 101 : op = d_tm.mkOp(kind, p.d_indices);
1291 : : }
1292 : : else
1293 : : {
1294 : 47 : kind = Kind::FLOATINGPOINT_TO_FP_FROM_SBV;
1295 : 47 : op = d_tm.mkOp(kind, p.d_indices);
1296 : : }
1297 : 164 : }
1298 : : }
1299 [ + + ][ + - ]: 991 : else if (p.d_name == "tuple.select" || p.d_name == "tuple.update")
[ + - ]
1300 : : {
1301 : 991 : bool isSelect = (p.d_name == "tuple.select");
1302 [ - + ]: 991 : if (p.d_indices.size() != 1)
1303 : : {
1304 : 0 : parseError("wrong number of indices for tuple select or update");
1305 : : }
1306 : 991 : uint64_t n = p.d_indices[0];
1307 [ + + ][ - + ]: 991 : if (args.size() != (isSelect ? 1 : 2))
1308 : : {
1309 : 0 : parseError("wrong number of arguments for tuple select or update");
1310 : : }
1311 : 991 : Sort t = args[0].getSort();
1312 [ - + ]: 991 : if (!t.isTuple())
1313 : : {
1314 : 0 : parseError("tuple select or update applied to non-tuple");
1315 : : }
1316 : 991 : size_t length = t.getTupleLength();
1317 [ - + ]: 991 : if (n >= length)
1318 : : {
1319 : 0 : std::stringstream ss;
1320 : 0 : ss << "tuple is of length " << length << "; cannot access index "
1321 : 0 : << n;
1322 : 0 : parseError(ss.str());
1323 : 0 : }
1324 : 991 : const Datatype& dt = t.getDatatype();
1325 : 991 : Term ret;
1326 [ + + ]: 991 : if (isSelect)
1327 : : {
1328 : : ret =
1329 [ + + ][ - - ]: 2853 : d_tm.mkTerm(Kind::APPLY_SELECTOR, {dt[0][n].getTerm(), args[0]});
1330 : : }
1331 : : else
1332 : : {
1333 [ + + ][ - - ]: 280 : ret = d_tm.mkTerm(Kind::APPLY_UPDATER,
1334 : 120 : {dt[0][n].getUpdaterTerm(), args[0], args[1]});
1335 : : }
1336 [ + - ]: 1982 : Trace("parser") << "applyParseOp: return selector/updater " << ret
1337 : 991 : << std::endl;
1338 : 991 : return ret;
1339 : 991 : }
1340 : : else
1341 : : {
1342 : 0 : DebugUnhandled() << "Failed to resolve indexed operator " << p.d_name;
1343 : : }
1344 : : }
1345 : : else
1346 : : {
1347 : : // otherwise, an ordinary operator
1348 : 172783 : op = d_tm.mkOp(k, p.d_indices);
1349 : : }
1350 : 173051 : return d_tm.mkTerm(op, args);
1351 : 174046 : }
1352 [ + + ]: 5990925 : else if (p.d_kind != Kind::NULL_TERM)
1353 : : {
1354 : : // It is a special case, e.g. tuple.select or array constant specification.
1355 : : // We have to wait until the arguments are parsed to resolve it.
1356 : : }
1357 [ + + ]: 5976212 : else if (!p.d_expr.isNull())
1358 : : {
1359 : : // An explicit operator, e.g. an apply function
1360 : 27 : Kind fkind = getKindForFunction(p.d_expr);
1361 [ + - ]: 27 : if (fkind != Kind::UNDEFINED_KIND)
1362 : : {
1363 : : // Some operators may require a specific kind.
1364 : : // Testers are handled differently than other indexed operators,
1365 : : // since they require a kind.
1366 : 27 : kind = fkind;
1367 [ + - ]: 54 : Trace("parser") << "Got function kind " << kind << " for expression "
1368 : 27 : << std::endl;
1369 : : }
1370 : 27 : args.insert(args.begin(), p.d_expr);
1371 : : }
1372 : : else
1373 : : {
1374 : 5976185 : isBuiltinOperator = isOperatorEnabled(p.d_name);
1375 [ + + ]: 5976185 : if (isBuiltinOperator)
1376 : : {
1377 : : // a builtin operator, convert to kind
1378 : 5181310 : kind = getOperatorKind(p.d_name);
1379 : : // special case: indexed operators with zero arguments
1380 [ + + ][ + + ]: 5181310 : if (kind == Kind::TUPLE_PROJECT || kind == Kind::TABLE_PROJECT
1381 [ + - ][ + - ]: 5181302 : || kind == Kind::TABLE_AGGREGATE || kind == Kind::TABLE_JOIN
1382 [ + + ][ + + ]: 5181302 : || kind == Kind::TABLE_GROUP || kind == Kind::RELATION_GROUP
1383 [ + - ][ + + ]: 5181290 : || kind == Kind::RELATION_AGGREGATE || kind == Kind::RELATION_PROJECT
1384 [ - + ]: 5181272 : || kind == Kind::RELATION_TABLE_JOIN)
1385 : : {
1386 : 38 : std::vector<uint32_t> indices;
1387 : 38 : Op op = d_tm.mkOp(kind, indices);
1388 : 38 : return d_tm.mkTerm(op, args);
1389 : 38 : }
1390 [ + + ]: 5181272 : else if (kind == Kind::APPLY_CONSTRUCTOR)
1391 : : {
1392 [ + + ]: 5558 : if (p.d_name == "tuple")
1393 : : {
1394 : : // tuple application
1395 : 5381 : return d_tm.mkTuple(args);
1396 : : }
1397 [ + - ]: 177 : else if (p.d_name == "nullable.some")
1398 : : {
1399 [ + + ]: 177 : if (args.size() == 1)
1400 : : {
1401 : 176 : return d_tm.mkNullableSome(args[0]);
1402 : : }
1403 : 3 : parseError("nullable.some requires exactly one argument.");
1404 : : }
1405 : : else
1406 : : {
1407 : 0 : std::stringstream ss;
1408 : 0 : ss << "Unknown APPLY_CONSTRUCTOR symbol '" << p.d_name << "'";
1409 : 0 : parseError(ss.str());
1410 : 0 : }
1411 : : }
1412 [ + + ]: 5175714 : else if (kind == Kind::APPLY_SELECTOR)
1413 : : {
1414 [ + - ]: 63 : if (p.d_name == "nullable.val")
1415 : : {
1416 [ + - ]: 63 : if (args.size() == 1)
1417 : : {
1418 : 63 : return d_tm.mkNullableVal(args[0]);
1419 : : }
1420 : 0 : parseError("nullable.val requires exactly one argument.");
1421 : : }
1422 : : else
1423 : : {
1424 : 0 : std::stringstream ss;
1425 : 0 : ss << "Unknown APPLY_SELECTOR symbol '" << p.d_name << "'";
1426 : 0 : parseError(ss.str());
1427 : 0 : }
1428 : : }
1429 [ + + ]: 5175651 : else if (kind == Kind::APPLY_TESTER)
1430 : : {
1431 [ + + ]: 67 : if (p.d_name == "nullable.is_null")
1432 : : {
1433 [ + - ]: 53 : if (args.size() == 1)
1434 : : {
1435 : 53 : return d_tm.mkNullableIsNull(args[0]);
1436 : : }
1437 : 0 : parseError("nullable.is_null requires exactly one argument.");
1438 : : }
1439 [ + - ]: 14 : else if (p.d_name == "nullable.is_some")
1440 : : {
1441 [ + - ]: 14 : if (args.size() == 1)
1442 : : {
1443 : 14 : return d_tm.mkNullableIsSome(args[0]);
1444 : : }
1445 : 0 : parseError("nullable.is_some requires exactly one argument.");
1446 : : }
1447 : : else
1448 : : {
1449 : 0 : std::stringstream ss;
1450 : 0 : ss << "Unknown APPLY_TESTER symbol '" << p.d_name << "'";
1451 : 0 : parseError(ss.str());
1452 : 0 : }
1453 : : }
1454 [ + - ]: 10351168 : Trace("parser") << "Got builtin kind " << kind << " for name"
1455 : 5175584 : << std::endl;
1456 : : }
1457 : : else
1458 : : {
1459 : : // A non-built-in function application, get the expression
1460 : 794901 : checkDeclaration(p.d_name, CHECK_DECLARED, SYM_VARIABLE);
1461 : 794862 : Term v = getVariable(p.d_name);
1462 [ + + ]: 794862 : if (!v.isNull())
1463 : : {
1464 : 794027 : checkFunctionLike(v);
1465 : 794025 : kind = getKindForFunction(v);
1466 : 794025 : args.insert(args.begin(), v);
1467 : : }
1468 : : else
1469 : : {
1470 : : // Overloaded symbol?
1471 : : // Could not find the expression. It may be an overloaded symbol,
1472 : : // in which case we may find it after knowing the types of its
1473 : : // arguments.
1474 : 836 : std::vector<Sort> argTypes;
1475 [ + + ]: 2152 : for (std::vector<Term>::iterator i = args.begin(); i != args.end(); ++i)
1476 : : {
1477 : 1316 : argTypes.push_back((*i).getSort());
1478 : : }
1479 : 836 : Term fop = getOverloadedFunctionForTypes(p.d_name, argTypes);
1480 [ + - ]: 836 : if (!fop.isNull())
1481 : : {
1482 : 836 : checkFunctionLike(fop);
1483 : 836 : kind = getKindForFunction(fop);
1484 : 836 : args.insert(args.begin(), fop);
1485 : : }
1486 : : else
1487 : : {
1488 : 0 : parseError(
1489 : : "Cannot find unambiguous overloaded function for argument "
1490 : : "types.");
1491 : : }
1492 : 836 : }
1493 : 794862 : }
1494 : : }
1495 : : // handle special cases
1496 : : // If we marked the operator as "INTERNAL_KIND", then the name/expr
1497 : : // determine the operator. This handles constant arrays.
1498 [ + + ]: 5985185 : if (p.d_kind == Kind::INTERNAL_KIND)
1499 : : {
1500 : : // (as const (Array T1 T2))
1501 [ + - ]: 440 : if (!strictModeEnabled() && p.d_name == "const"
1502 [ + - ][ + - ]: 440 : && isTheoryEnabled(internal::theory::THEORY_ARRAYS))
[ + - ]
1503 : : {
1504 [ - + ]: 220 : if (args.size() != 1)
1505 : : {
1506 : 0 : parseError("Too many arguments to array constant.");
1507 : : }
1508 : 220 : Term constVal = args[0];
1509 : :
1510 [ - + ][ - + ]: 220 : Assert(!p.d_expr.isNull());
[ - - ]
1511 : 220 : Sort sort = p.d_expr.getSort();
1512 [ - + ]: 220 : if (!sort.isArray())
1513 : : {
1514 : 0 : std::stringstream ss;
1515 : 0 : ss << "expected array constant term, but cast is not of array type"
1516 : 0 : << std::endl
1517 : 0 : << "cast type: " << sort;
1518 : 0 : parseError(ss.str());
1519 : 0 : }
1520 [ - + ]: 220 : if (sort.getArrayElementSort() != constVal.getSort())
1521 : : {
1522 : 0 : std::stringstream ss;
1523 : 0 : ss << "type mismatch inside array constant term:" << std::endl
1524 : 0 : << "array type: " << sort << std::endl
1525 : 0 : << "expected const type: " << sort.getArrayElementSort() << std::endl
1526 : 0 : << "computed const type: " << constVal.getSort();
1527 : 0 : parseError(ss.str());
1528 : 0 : }
1529 : 220 : Term ret = d_tm.mkConstArray(sort, constVal);
1530 [ + - ]: 220 : Trace("parser") << "applyParseOp: return store all " << ret << std::endl;
1531 : 220 : return ret;
1532 : 220 : }
1533 : : else
1534 : : {
1535 : : // should never happen
1536 : 0 : parseError("Could not process internal parsed operator");
1537 : : }
1538 : : }
1539 [ + + ][ + + ]: 5984965 : else if (p.d_kind == Kind::APPLY_TESTER || p.d_kind == Kind::APPLY_UPDATER)
1540 : : {
1541 : 13332 : Term iop = mkIndexedOp(p.d_kind, {p.d_name}, args);
1542 : 4442 : kind = p.d_kind;
1543 : 4442 : args.insert(args.begin(), iop);
1544 : 4442 : }
1545 [ + + ]: 5980522 : else if (p.d_kind != Kind::NULL_TERM)
1546 : : {
1547 : : // it should not have an expression or type specified at this point
1548 [ - + ]: 10050 : if (!p.d_expr.isNull())
1549 : : {
1550 : 0 : std::stringstream ss;
1551 : 0 : ss << "Could not process parsed qualified identifier kind " << p.d_kind;
1552 : 0 : parseError(ss.str());
1553 : 0 : }
1554 : : // otherwise it is a simple application
1555 : 10050 : kind = p.d_kind;
1556 : : }
1557 [ + + ]: 5970472 : else if (isBuiltinOperator)
1558 : : {
1559 [ + + ][ + + ]: 5175584 : if (kind == Kind::EQUAL || kind == Kind::DISTINCT)
1560 : : {
1561 : 583055 : bool isReal = false;
1562 : : // need hol if these operators are applied over function args
1563 [ + + ]: 1761257 : for (const Term& i : args)
1564 : : {
1565 : 1178202 : Sort s = i.getSort();
1566 [ + + ]: 1178202 : if (!isHoEnabled())
1567 : : {
1568 [ - + ]: 1138991 : if (s.isFunction())
1569 : : {
1570 : 0 : parseError(
1571 : : "Cannot apply equality to functions unless logic is prefixed "
1572 : : "by HO_.");
1573 : : }
1574 : : }
1575 [ + + ]: 1178202 : if (s.isReal())
1576 : : {
1577 : 110670 : isReal = true;
1578 : : }
1579 : 1178202 : }
1580 : : // If strict mode is not enabled, we are permissive for Int and Real
1581 : : // subtyping. Note that other arithmetic operators and relations are
1582 : : // already permissive, e.g. <=, +.
1583 [ + + ][ + + ]: 583055 : if (isReal && !strictModeEnabled())
[ + + ]
1584 : : {
1585 [ + + ]: 166072 : for (Term& i : args)
1586 : : {
1587 : 110741 : Sort s = i.getSort();
1588 [ + + ]: 110741 : if (s.isInteger())
1589 : : {
1590 : 160 : i = d_tm.mkTerm(Kind::TO_REAL, {i});
1591 : : }
1592 : 110741 : }
1593 : : }
1594 : : }
1595 [ + + ]: 5175584 : if (strictModeEnabled())
1596 : : {
1597 : : // Catch cases of mixed arithmetic, which our internal type checker is
1598 : : // lenient for. In particular, any case that is ill-typed according to
1599 : : // the SMT standard but not in our internal type checker are handled
1600 : : // here.
1601 : 240 : Sort sreq; // if applicable, the sort which all arguments must be.
1602 : 240 : bool sameType = false;
1603 [ + + ][ + - ]: 240 : if (kind == Kind::ADD || kind == Kind::MULT || kind == Kind::SUB
[ + - ]
1604 [ + - ][ + - ]: 239 : || kind == Kind::GEQ || kind == Kind::GT || kind == Kind::LEQ
[ + - ]
1605 [ - + ]: 239 : || kind == Kind::LT)
1606 : : {
1607 : : // no mixed arithmetic
1608 : 1 : sreq = args[0].getSort();
1609 : 1 : sameType = true;
1610 : : }
1611 [ + - ]: 239 : else if (kind == Kind::DIVISION
1612 [ + - ][ - + ]: 239 : || kind == Kind::TO_INTEGER || kind == Kind::IS_INTEGER)
1613 : : {
1614 : : // must apply division, to_int, is_int to real only
1615 : 0 : sreq = d_tm.getRealSort();
1616 : : }
1617 [ + + ][ - + ]: 239 : else if (kind == Kind::TO_REAL || kind == Kind::ABS)
1618 : : {
1619 : : // must apply to_real, abs to integer only
1620 : 1 : sreq = d_tm.getIntegerSort();
1621 : : }
1622 [ + + ]: 240 : if (!sreq.isNull())
1623 : : {
1624 [ + - ]: 3 : for (Term& i : args)
1625 : : {
1626 : 3 : Sort s = i.getSort();
1627 [ + + ]: 3 : if (s != sreq)
1628 : : {
1629 : 2 : std::stringstream ss;
1630 : 2 : ss << "Due to strict parsing, we require the arguments of " << kind;
1631 [ + + ]: 2 : if (sameType)
1632 : : {
1633 : 1 : ss << " to have the same type";
1634 : : }
1635 : : else
1636 : : {
1637 : 1 : ss << " to have type " << sreq;
1638 : : }
1639 : 4 : parseError(ss.str());
1640 : 2 : }
1641 : 3 : }
1642 : : }
1643 : 240 : }
1644 [ + + ][ + + ]: 10350926 : if (!strictModeEnabled() && (kind == Kind::AND || kind == Kind::OR)
1645 [ + + ][ + + ]: 10350926 : && args.size() == 1)
[ + + ]
1646 : : {
1647 : : // Unary AND/OR can be replaced with the argument.
1648 [ + - ]: 1134 : Trace("parser") << "applyParseOp: return unary " << args[0] << std::endl;
1649 : 1134 : return args[0];
1650 : : }
1651 [ + + ][ + + ]: 5174448 : else if (kind == Kind::SUB && args.size() == 1)
[ + + ]
1652 : : {
1653 : 777024 : Term ret = d_tm.mkTerm(Kind::NEG, {args[0]});
1654 [ + - ]: 259008 : Trace("parser") << "applyParseOp: return uminus " << ret << std::endl;
1655 : 259008 : return ret;
1656 : 259008 : }
1657 [ + + ]: 4915440 : else if (kind == Kind::FLOATINGPOINT_FP)
1658 : : {
1659 : : // (fp #bX #bY #bZ) denotes a floating-point value
1660 [ + + ]: 176 : if (args.size() != 3)
1661 : : {
1662 : 1 : parseError("expected 3 arguments to 'fp', got "
1663 : 4 : + std::to_string(args.size()));
1664 : : }
1665 [ + + ][ + - ]: 175 : if (isConstBv(args[0]) && isConstBv(args[1]) && isConstBv(args[2]))
[ + + ][ + + ]
1666 : : {
1667 : 163 : Term ret = d_tm.mkFloatingPoint(args[0], args[1], args[2]);
1668 [ + - ]: 324 : Trace("parser") << "applyParseOp: return floating-point value " << ret
1669 : 162 : << std::endl;
1670 : 162 : return ret;
1671 : 162 : }
1672 : : }
1673 [ + + ]: 4915264 : else if (kind == Kind::SKOLEM)
1674 : : {
1675 : 31 : Term ret;
1676 : 31 : SkolemId skolemId = d_skolemMap[p.d_name];
1677 : 31 : size_t numSkolemIndices = d_tm.getNumIndicesForSkolemId(skolemId);
1678 [ + + ]: 31 : if (numSkolemIndices == args.size())
1679 : : {
1680 : 20 : ret = d_tm.mkSkolem(skolemId, args);
1681 : : }
1682 : : else
1683 : : {
1684 : : std::vector<Term> skolemArgs(args.begin(),
1685 : 11 : args.begin() + numSkolemIndices);
1686 : 11 : Term skolem = d_tm.mkSkolem(skolemId, skolemArgs);
1687 : 33 : std::vector<Term> finalArgs = {skolem};
1688 : 33 : finalArgs.insert(
1689 : 22 : finalArgs.end(), args.begin() + numSkolemIndices, args.end());
1690 : 11 : ret = d_tm.mkTerm(Kind::APPLY_UF, finalArgs);
1691 : 11 : }
1692 [ + - ]: 31 : Trace("parser") << "applyParseOp: return skolem " << ret << std::endl;
1693 : 31 : return ret;
1694 : 31 : }
1695 : 4915245 : Term ret = d_tm.mkTerm(kind, args);
1696 [ + - ]: 9830466 : Trace("parser") << "applyParseOp: return default builtin " << ret
1697 : 4915233 : << std::endl;
1698 : 4915233 : return ret;
1699 : 4915233 : }
1700 : :
1701 [ + + ]: 809380 : if (args.size() >= 2)
1702 : : {
1703 : : // may be partially applied function, in this case we use HO_APPLY
1704 : 800472 : Sort argt = args[0].getSort();
1705 [ + + ]: 800472 : if (argt.isFunction())
1706 : : {
1707 : 754959 : unsigned arity = argt.getFunctionArity();
1708 [ + + ]: 754959 : if (args.size() - 1 < arity)
1709 : : {
1710 [ - + ]: 791 : if (!isHoEnabled())
1711 : : {
1712 : 0 : parseError(
1713 : : "Cannot partially apply functions unless logic is prefixed by "
1714 : : "HO_.");
1715 : : }
1716 [ + - ]: 791 : Trace("parser") << "Partial application of " << args[0];
1717 [ + - ]: 791 : Trace("parser") << " : #argTypes = " << arity;
1718 [ + - ]: 791 : Trace("parser") << ", #args = " << args.size() - 1 << std::endl;
1719 : 791 : Term ret = d_tm.mkTerm(Kind::HO_APPLY, args);
1720 [ + - ]: 1582 : Trace("parser") << "applyParseOp: return curry higher order " << ret
1721 : 791 : << std::endl;
1722 : : // must curry the partial application
1723 : 791 : return ret;
1724 : 791 : }
1725 : : }
1726 [ + + ]: 800472 : }
1727 [ - + ]: 808589 : if (kind == Kind::NULL_TERM)
1728 : : {
1729 : : // should never happen in the new API
1730 : 0 : parseError("do not know how to process parse op");
1731 : : }
1732 [ + - ]: 1617178 : Trace("parser") << "Try default term construction for kind " << kind
1733 : 808589 : << " #args = " << args.size() << "..." << std::endl;
1734 : 808589 : Term ret = d_tm.mkTerm(kind, args);
1735 [ + - ]: 808585 : Trace("parser") << "applyParseOp: return : " << ret << std::endl;
1736 : 808585 : return ret;
1737 : 808585 : }
1738 : :
1739 : 41365 : Sort Smt2State::getParametricSort(const std::string& name,
1740 : : const std::vector<Sort>& args)
1741 : : {
1742 [ - + ]: 41365 : if (args.empty())
1743 : : {
1744 : 0 : parseError(
1745 : : "Extra parentheses around sort name not "
1746 : : "permitted in SMT-LIB");
1747 : : }
1748 : : // builtin parametric sorts are handled manually
1749 : 41365 : Sort t;
1750 [ + + ][ + + ]: 41365 : if (name == "Array" && isTheoryEnabled(internal::theory::THEORY_ARRAYS))
[ + + ]
1751 : : {
1752 [ - + ]: 7070 : if (args.size() != 2)
1753 : : {
1754 : 0 : parseError("Illegal array type.");
1755 : : }
1756 : 7070 : t = d_tm.mkArraySort(args[0], args[1]);
1757 : : }
1758 [ + + ][ + + ]: 34295 : else if (name == "Set" && isTheoryEnabled(internal::theory::THEORY_SETS))
[ + + ]
1759 : : {
1760 [ - + ]: 3803 : if (args.size() != 1)
1761 : : {
1762 : 0 : parseError("Illegal set type.");
1763 : : }
1764 : 3803 : t = d_tm.mkSetSort(args[0]);
1765 : : }
1766 [ + + ][ + - ]: 30492 : else if (name == "Bag" && isTheoryEnabled(internal::theory::THEORY_BAGS))
[ + + ]
1767 : : {
1768 [ - + ]: 714 : if (args.size() != 1)
1769 : : {
1770 : 0 : parseError("Illegal bag type.");
1771 : : }
1772 : 714 : t = d_tm.mkBagSort(args[0]);
1773 : : }
1774 [ + - ]: 31129 : else if (name == "Seq" && !strictModeEnabled()
1775 [ + + ][ + - ]: 31129 : && isTheoryEnabled(internal::theory::THEORY_STRINGS))
[ + + ]
1776 : : {
1777 [ - + ]: 1351 : if (args.size() != 1)
1778 : : {
1779 : 0 : parseError("Illegal sequence type.");
1780 : : }
1781 : 1351 : t = d_tm.mkSequenceSort(args[0]);
1782 : : }
1783 [ + + ][ + - ]: 28427 : else if (name == "Tuple" && !strictModeEnabled())
[ + + ]
1784 : : {
1785 : 4161 : t = d_tm.mkTupleSort(args);
1786 : : }
1787 [ + + ][ + - ]: 24266 : else if (name == "Nullable" && !strictModeEnabled())
[ + + ]
1788 : : {
1789 [ - + ]: 718 : if (args.size() != 1)
1790 : : {
1791 : 0 : parseError("Illegal nullable type.");
1792 : : }
1793 : 718 : t = d_tm.mkNullableSort(args[0]);
1794 : : }
1795 [ + + ][ + - ]: 23548 : else if (name == "Relation" && !strictModeEnabled())
[ + + ]
1796 : : {
1797 : 1942 : Sort tupleSort = d_tm.mkTupleSort(args);
1798 : 1942 : t = d_tm.mkSetSort(tupleSort);
1799 : 1942 : }
1800 [ + + ][ + - ]: 21606 : else if (name == "Table" && !strictModeEnabled())
[ + + ]
1801 : : {
1802 : 182 : Sort tupleSort = d_tm.mkTupleSort(args);
1803 : 182 : t = d_tm.mkBagSort(tupleSort);
1804 : 182 : }
1805 [ + + ][ + + ]: 21424 : else if (name == "->" && isHoEnabled())
[ + + ]
1806 : : {
1807 [ - + ]: 19841 : if (args.size() < 2)
1808 : : {
1809 : 0 : parseError("Arrow types must have at least 2 arguments");
1810 : : }
1811 : : // flatten the type
1812 : 19841 : Sort rangeType = args.back();
1813 : 19841 : std::vector<Sort> dargs(args.begin(), args.end() - 1);
1814 : 19841 : t = mkFlatFunctionType(dargs, rangeType);
1815 : 19841 : }
1816 : : else
1817 : : {
1818 : 1583 : t = ParserState::getParametricSort(name, args);
1819 : : }
1820 : 41362 : return t;
1821 : 3 : }
1822 : :
1823 : 34564 : Sort Smt2State::getIndexedSort(const std::string& name,
1824 : : const std::vector<std::string>& numerals)
1825 : : {
1826 : 34564 : Sort ret;
1827 [ + + ]: 34564 : if (name == "BitVec")
1828 : : {
1829 [ - + ]: 32984 : if (numerals.size() != 1)
1830 : : {
1831 : 0 : parseError("Illegal bitvector type.");
1832 : : }
1833 : 32984 : uint32_t n0 = stringToUnsigned(numerals[0]);
1834 [ - + ]: 32984 : if (n0 == 0)
1835 : : {
1836 : 0 : parseError("Illegal bitvector size: 0");
1837 : : }
1838 : 32984 : ret = d_tm.mkBitVectorSort(n0);
1839 : : }
1840 [ + + ]: 1580 : else if (name == "FiniteField")
1841 : : {
1842 [ - + ]: 1096 : if (numerals.size() != 1)
1843 : : {
1844 : 0 : parseError("Illegal finite field type.");
1845 : : }
1846 : 1096 : ret = d_tm.mkFiniteFieldSort(numerals.front());
1847 : : }
1848 [ + - ]: 484 : else if (name == "FloatingPoint")
1849 : : {
1850 [ - + ]: 484 : if (numerals.size() != 2)
1851 : : {
1852 : 0 : parseError("Illegal floating-point type.");
1853 : : }
1854 : 484 : uint32_t n0 = stringToUnsigned(numerals[0]);
1855 : 484 : uint32_t n1 = stringToUnsigned(numerals[1]);
1856 [ - + ]: 484 : if (!internal::validExponentSize(n0))
1857 : : {
1858 : 0 : parseError("Illegal floating-point exponent size");
1859 : : }
1860 [ - + ]: 484 : if (!internal::validSignificandSize(n1))
1861 : : {
1862 : 0 : parseError("Illegal floating-point significand size");
1863 : : }
1864 : 484 : ret = d_tm.mkFloatingPointSort(n0, n1);
1865 : : }
1866 : : else
1867 : : {
1868 : 0 : std::stringstream ss;
1869 : 0 : ss << "unknown indexed sort symbol `" << name << "'";
1870 : 0 : parseError(ss.str());
1871 : 0 : }
1872 : 34564 : return ret;
1873 : 0 : }
1874 : :
1875 : 5976247 : bool Smt2State::isClosure(const std::string& name)
1876 : : {
1877 : 5976247 : return d_closureKindMap.find(name) != d_closureKindMap.end();
1878 : : }
1879 : :
1880 : 5681 : std::unique_ptr<Cmd> Smt2State::handlePush(std::optional<uint32_t> nscopes)
1881 : : {
1882 : 5681 : checkThatLogicIsSet();
1883 : :
1884 [ + + ]: 5681 : if (!nscopes)
1885 : : {
1886 [ - + ]: 453 : if (strictModeEnabled())
1887 : : {
1888 : 0 : parseError(
1889 : : "Strict compliance mode demands an integer to be provided to "
1890 : : "(push). Maybe you want (push 1)?");
1891 : : }
1892 : 453 : nscopes = 1;
1893 : : }
1894 : :
1895 [ + + ]: 11385 : for (uint32_t i = 0; i < *nscopes; i++)
1896 : : {
1897 : 5704 : pushScope(true);
1898 : : }
1899 : 5681 : return std::make_unique<PushCommand>(*nscopes);
1900 : : }
1901 : :
1902 : 4564 : std::unique_ptr<Cmd> Smt2State::handlePop(std::optional<uint32_t> nscopes)
1903 : : {
1904 : 4564 : checkThatLogicIsSet();
1905 : :
1906 [ + + ]: 4564 : if (!nscopes)
1907 : : {
1908 [ - + ]: 359 : if (strictModeEnabled())
1909 : : {
1910 : 0 : parseError(
1911 : : "Strict compliance mode demands an integer to be provided to "
1912 : : "(pop). Maybe you want (pop 1)?");
1913 : : }
1914 : 359 : nscopes = 1;
1915 : : }
1916 : :
1917 [ + + ]: 9275 : for (uint32_t i = 0; i < *nscopes; i++)
1918 : : {
1919 : 4711 : popScope();
1920 : : }
1921 : 4564 : return std::make_unique<PopCommand>(*nscopes);
1922 : : }
1923 : :
1924 : 11261 : void Smt2State::notifyNamedExpression(Term& expr, std::string name)
1925 : : {
1926 : 11261 : checkUserSymbol(name);
1927 : : // remember the expression name in the symbol manager
1928 : 11261 : NamingResult nr = getSymbolManager()->setExpressionName(expr, name, false);
1929 [ + + ]: 11261 : if (nr == NamingResult::ERROR_IN_BINDER)
1930 : : {
1931 : 3 : parseError(
1932 : : "Cannot name a term in a binder (e.g., quantifiers, definitions)");
1933 : : }
1934 : : // define the variable. This needs to be done here so that in the rest of the
1935 : : // command we can use this name, which is required by the semantics of :named.
1936 : : //
1937 : : // Note that as we are defining the name to the expression here, names never
1938 : : // show up in "-o raw-benchmark" nor in proofs. To be able to do it it'd be
1939 : : // necessary to not define this variable here and create a
1940 : : // DefineFunctionCommand with the binding, so that names are handled as
1941 : : // defined functions. However, these commands would need to be processed
1942 : : // *before* the rest of the command in which the :named attribute appears, so
1943 : : // the name can be defined in the rest of the command. This would greatly
1944 : : // complicate the design of the parser and provide little gain, so we opt to
1945 : : // handle :named as a macro processed directly in the parser.
1946 : 11260 : defineVar(name, expr);
1947 : : // set the last named term, which ensures that we catch when assertions are
1948 : : // named
1949 : 11260 : setLastNamedTerm(expr, name);
1950 : 11260 : }
1951 : :
1952 : 0 : Term Smt2State::mkAnd(const std::vector<Term>& es) const
1953 : : {
1954 [ - - ]: 0 : if (es.size() == 0)
1955 : : {
1956 : 0 : return d_tm.mkTrue();
1957 : : }
1958 [ - - ]: 0 : else if (es.size() == 1)
1959 : : {
1960 : 0 : return es[0];
1961 : : }
1962 : 0 : return d_tm.mkTerm(Kind::AND, es);
1963 : : }
1964 : :
1965 : 0 : bool Smt2State::isConstInt(const Term& t)
1966 : : {
1967 : 0 : return t.getKind() == Kind::CONST_INTEGER;
1968 : : }
1969 : :
1970 : 517 : bool Smt2State::isConstBv(const Term& t)
1971 : : {
1972 : 517 : return t.getKind() == Kind::CONST_BITVECTOR;
1973 : : }
1974 : :
1975 : : } // namespace parser
1976 : : } // namespace cvc5
|