1 /********************* */
4 ** Top contributors (to current version):
5 ** Andrew Reynolds, Kshitij Bansal, Morgan Deters
6 ** This file is part of the CVC4 project.
7 ** Copyright (c) 2009-2017 by the authors listed in the file AUTHORS
8 ** in the top-level source directory) and their institutional affiliations.
9 ** All rights reserved. See the file COPYING in the top-level source
10 ** directory for licensing information.\endverbatim
12 ** \brief Definitions of SMT2 constants.
14 ** Definitions of SMT2 constants.
16 #include "parser/smt2/smt2.h"
19 #include "expr/type.h"
20 #include "parser/antlr_input.h"
21 #include "parser/parser.h"
22 #include "parser/smt1/smt1.h"
23 #include "parser/smt2/smt2_input.h"
24 #include "printer/sygus_print_callback.h"
25 #include "smt/command.h"
26 #include "util/bitvector.h"
30 // ANTLR defines these, which is really bad!
37 Smt2::Smt2(ExprManager
* exprManager
, Input
* input
, bool strictMode
, bool parseOnly
) :
38 Parser(exprManager
,input
,strictMode
,parseOnly
),
40 if( !strictModeEnabled() ) {
41 addTheory(Smt2::THEORY_CORE
);
45 void Smt2::setLanguage(InputLanguage lang
) {
46 ((Smt2Input
*) getInput())->setLanguage(lang
);
49 void Smt2::addArithmeticOperators() {
50 Parser::addOperator(kind::PLUS
);
51 Parser::addOperator(kind::MINUS
);
52 Parser::addOperator(kind::UMINUS
);
53 Parser::addOperator(kind::MULT
);
54 Parser::addOperator(kind::LT
);
55 Parser::addOperator(kind::LEQ
);
56 Parser::addOperator(kind::GT
);
57 Parser::addOperator(kind::GEQ
);
59 addOperator(kind::POW
, "^");
60 addOperator(kind::EXPONENTIAL
, "exp");
61 addOperator(kind::SINE
, "sin");
62 addOperator(kind::COSINE
, "cos");
63 addOperator(kind::TANGENT
, "tan");
66 void Smt2::addBitvectorOperators() {
67 addOperator(kind::BITVECTOR_CONCAT
, "concat");
68 addOperator(kind::BITVECTOR_NOT
, "bvnot");
69 addOperator(kind::BITVECTOR_AND
, "bvand");
70 addOperator(kind::BITVECTOR_OR
, "bvor");
71 addOperator(kind::BITVECTOR_NEG
, "bvneg");
72 addOperator(kind::BITVECTOR_PLUS
, "bvadd");
73 addOperator(kind::BITVECTOR_MULT
, "bvmul");
74 addOperator(kind::BITVECTOR_UDIV
, "bvudiv");
75 addOperator(kind::BITVECTOR_UREM
, "bvurem");
76 addOperator(kind::BITVECTOR_SHL
, "bvshl");
77 addOperator(kind::BITVECTOR_LSHR
, "bvlshr");
78 addOperator(kind::BITVECTOR_ULT
, "bvult");
79 addOperator(kind::BITVECTOR_NAND
, "bvnand");
80 addOperator(kind::BITVECTOR_NOR
, "bvnor");
81 addOperator(kind::BITVECTOR_XOR
, "bvxor");
82 addOperator(kind::BITVECTOR_XNOR
, "bvxnor");
83 addOperator(kind::BITVECTOR_COMP
, "bvcomp");
84 addOperator(kind::BITVECTOR_SUB
, "bvsub");
85 addOperator(kind::BITVECTOR_SDIV
, "bvsdiv");
86 addOperator(kind::BITVECTOR_SREM
, "bvsrem");
87 addOperator(kind::BITVECTOR_SMOD
, "bvsmod");
88 addOperator(kind::BITVECTOR_ASHR
, "bvashr");
89 addOperator(kind::BITVECTOR_ULE
, "bvule");
90 addOperator(kind::BITVECTOR_UGT
, "bvugt");
91 addOperator(kind::BITVECTOR_UGE
, "bvuge");
92 addOperator(kind::BITVECTOR_SLT
, "bvslt");
93 addOperator(kind::BITVECTOR_SLE
, "bvsle");
94 addOperator(kind::BITVECTOR_SGT
, "bvsgt");
95 addOperator(kind::BITVECTOR_SGE
, "bvsge");
96 addOperator(kind::BITVECTOR_REDOR
, "bvredor");
97 addOperator(kind::BITVECTOR_REDAND
, "bvredand");
99 Parser::addOperator(kind::BITVECTOR_BITOF
);
100 Parser::addOperator(kind::BITVECTOR_EXTRACT
);
101 Parser::addOperator(kind::BITVECTOR_REPEAT
);
102 Parser::addOperator(kind::BITVECTOR_ZERO_EXTEND
);
103 Parser::addOperator(kind::BITVECTOR_SIGN_EXTEND
);
104 Parser::addOperator(kind::BITVECTOR_ROTATE_LEFT
);
105 Parser::addOperator(kind::BITVECTOR_ROTATE_RIGHT
);
107 Parser::addOperator(kind::INT_TO_BITVECTOR
);
108 Parser::addOperator(kind::BITVECTOR_TO_NAT
);
111 void Smt2::addStringOperators() {
112 addOperator(kind::STRING_CONCAT
, "str.++");
113 addOperator(kind::STRING_LENGTH
, "str.len");
114 addOperator(kind::STRING_SUBSTR
, "str.substr" );
115 addOperator(kind::STRING_STRCTN
, "str.contains" );
116 addOperator(kind::STRING_CHARAT
, "str.at" );
117 addOperator(kind::STRING_STRIDOF
, "str.indexof" );
118 addOperator(kind::STRING_STRREPL
, "str.replace" );
119 addOperator(kind::STRING_PREFIX
, "str.prefixof" );
120 addOperator(kind::STRING_SUFFIX
, "str.suffixof" );
121 addOperator(kind::STRING_ITOS
, "int.to.str" );
122 addOperator(kind::STRING_STOI
, "str.to.int" );
123 addOperator(kind::STRING_IN_REGEXP
, "str.in.re");
124 addOperator(kind::STRING_TO_REGEXP
, "str.to.re");
125 addOperator(kind::REGEXP_CONCAT
, "re.++");
126 addOperator(kind::REGEXP_UNION
, "re.union");
127 addOperator(kind::REGEXP_INTER
, "re.inter");
128 addOperator(kind::REGEXP_STAR
, "re.*");
129 addOperator(kind::REGEXP_PLUS
, "re.+");
130 addOperator(kind::REGEXP_OPT
, "re.opt");
131 addOperator(kind::REGEXP_RANGE
, "re.range");
132 addOperator(kind::REGEXP_LOOP
, "re.loop");
135 void Smt2::addFloatingPointOperators() {
136 addOperator(kind::FLOATINGPOINT_FP
, "fp");
137 addOperator(kind::FLOATINGPOINT_EQ
, "fp.eq");
138 addOperator(kind::FLOATINGPOINT_ABS
, "fp.abs");
139 addOperator(kind::FLOATINGPOINT_NEG
, "fp.neg");
140 addOperator(kind::FLOATINGPOINT_PLUS
, "fp.add");
141 addOperator(kind::FLOATINGPOINT_SUB
, "fp.sub");
142 addOperator(kind::FLOATINGPOINT_MULT
, "fp.mul");
143 addOperator(kind::FLOATINGPOINT_DIV
, "fp.div");
144 addOperator(kind::FLOATINGPOINT_FMA
, "fp.fma");
145 addOperator(kind::FLOATINGPOINT_SQRT
, "fp.sqrt");
146 addOperator(kind::FLOATINGPOINT_REM
, "fp.rem");
147 addOperator(kind::FLOATINGPOINT_RTI
, "fp.roundToIntegral");
148 addOperator(kind::FLOATINGPOINT_MIN
, "fp.min");
149 addOperator(kind::FLOATINGPOINT_MAX
, "fp.max");
150 addOperator(kind::FLOATINGPOINT_LEQ
, "fp.leq");
151 addOperator(kind::FLOATINGPOINT_LT
, "fp.lt");
152 addOperator(kind::FLOATINGPOINT_GEQ
, "fp.geq");
153 addOperator(kind::FLOATINGPOINT_GT
, "fp.gt");
154 addOperator(kind::FLOATINGPOINT_ISN
, "fp.isNormal");
155 addOperator(kind::FLOATINGPOINT_ISSN
, "fp.isSubnormal");
156 addOperator(kind::FLOATINGPOINT_ISZ
, "fp.isZero");
157 addOperator(kind::FLOATINGPOINT_ISINF
, "fp.isInfinite");
158 addOperator(kind::FLOATINGPOINT_ISNAN
, "fp.isNaN");
159 addOperator(kind::FLOATINGPOINT_ISNEG
, "fp.isNegative");
160 addOperator(kind::FLOATINGPOINT_ISPOS
, "fp.isPositive");
161 addOperator(kind::FLOATINGPOINT_TO_REAL
, "fp.to_real");
163 Parser::addOperator(kind::FLOATINGPOINT_TO_FP_IEEE_BITVECTOR
);
164 Parser::addOperator(kind::FLOATINGPOINT_TO_FP_FLOATINGPOINT
);
165 Parser::addOperator(kind::FLOATINGPOINT_TO_FP_REAL
);
166 Parser::addOperator(kind::FLOATINGPOINT_TO_FP_SIGNED_BITVECTOR
);
167 Parser::addOperator(kind::FLOATINGPOINT_TO_FP_UNSIGNED_BITVECTOR
);
168 Parser::addOperator(kind::FLOATINGPOINT_TO_UBV
);
169 Parser::addOperator(kind::FLOATINGPOINT_TO_SBV
);
172 void Smt2::addSepOperators() {
173 addOperator(kind::SEP_STAR
, "sep");
174 addOperator(kind::SEP_PTO
, "pto");
175 addOperator(kind::SEP_WAND
, "wand");
176 addOperator(kind::SEP_EMP
, "emp");
177 Parser::addOperator(kind::SEP_STAR
);
178 Parser::addOperator(kind::SEP_PTO
);
179 Parser::addOperator(kind::SEP_WAND
);
180 Parser::addOperator(kind::SEP_EMP
);
183 void Smt2::addTheory(Theory theory
) {
186 addOperator(kind::SELECT
, "select");
187 addOperator(kind::STORE
, "store");
190 case THEORY_BITVECTORS
:
191 addBitvectorOperators();
195 defineType("Bool", getExprManager()->booleanType());
196 defineVar("true", getExprManager()->mkConst(true));
197 defineVar("false", getExprManager()->mkConst(false));
198 Parser::addOperator(kind::AND
);
199 Parser::addOperator(kind::DISTINCT
);
200 Parser::addOperator(kind::EQUAL
);
201 Parser::addOperator(kind::IMPLIES
);
202 Parser::addOperator(kind::ITE
);
203 Parser::addOperator(kind::NOT
);
204 Parser::addOperator(kind::OR
);
205 Parser::addOperator(kind::XOR
);
208 case THEORY_REALS_INTS
:
209 defineType("Real", getExprManager()->realType());
210 Parser::addOperator(kind::DIVISION
);
211 addOperator(kind::TO_INTEGER
, "to_int");
212 addOperator(kind::IS_INTEGER
, "is_int");
213 addOperator(kind::TO_REAL
, "to_real");
214 // falling through on purpose, to add Ints part of Reals_Ints
216 defineType("Int", getExprManager()->integerType());
217 addArithmeticOperators();
218 addOperator(kind::INTS_DIVISION
, "div");
219 addOperator(kind::INTS_MODULUS
, "mod");
220 addOperator(kind::ABS
, "abs");
221 Parser::addOperator(kind::DIVISIBLE
);
225 defineType("Real", getExprManager()->realType());
226 addArithmeticOperators();
227 Parser::addOperator(kind::DIVISION
);
230 case THEORY_QUANTIFIERS
:
234 addOperator(kind::UNION
, "union");
235 addOperator(kind::INTERSECTION
, "intersection");
236 addOperator(kind::SETMINUS
, "setminus");
237 addOperator(kind::SUBSET
, "subset");
238 addOperator(kind::MEMBER
, "member");
239 addOperator(kind::SINGLETON
, "singleton");
240 addOperator(kind::INSERT
, "insert");
241 addOperator(kind::CARD
, "card");
242 addOperator(kind::COMPLEMENT
, "complement");
245 case THEORY_DATATYPES
:
246 Parser::addOperator(kind::APPLY_CONSTRUCTOR
);
247 Parser::addOperator(kind::APPLY_TESTER
);
248 Parser::addOperator(kind::APPLY_SELECTOR
);
249 Parser::addOperator(kind::APPLY_SELECTOR_TOTAL
);
253 defineType("String", getExprManager()->stringType());
254 defineType("Int", getExprManager()->integerType());
255 addStringOperators();
259 Parser::addOperator(kind::APPLY_UF
);
263 defineType("RoundingMode", getExprManager()->roundingModeType());
264 defineType("Float16", getExprManager()->mkFloatingPointType(5, 11));
265 defineType("Float32", getExprManager()->mkFloatingPointType(8, 24));
266 defineType("Float64", getExprManager()->mkFloatingPointType(11, 53));
267 defineType("Float128", getExprManager()->mkFloatingPointType(15, 113));
268 addFloatingPointOperators();
276 std::stringstream ss
;
277 ss
<< "internal error: unsupported theory " << theory
;
278 throw ParserException(ss
.str());
282 void Smt2::addOperator(Kind kind
, const std::string
& name
) {
283 Debug("parser") << "Smt2::addOperator( " << kind
<< ", " << name
<< " )"
285 Parser::addOperator(kind
);
286 operatorKindMap
[name
] = kind
;
289 Kind
Smt2::getOperatorKind(const std::string
& name
) const {
290 // precondition: isOperatorEnabled(name)
291 return operatorKindMap
.find(name
)->second
;
294 bool Smt2::isOperatorEnabled(const std::string
& name
) const {
295 return operatorKindMap
.find(name
) != operatorKindMap
.end();
298 bool Smt2::isTheoryEnabled(Theory theory
) const {
301 return d_logic
.isTheoryEnabled(theory::THEORY_ARRAY
);
302 case THEORY_BITVECTORS
:
303 return d_logic
.isTheoryEnabled(theory::THEORY_BV
);
306 case THEORY_DATATYPES
:
307 return d_logic
.isTheoryEnabled(theory::THEORY_DATATYPES
);
309 return d_logic
.isTheoryEnabled(theory::THEORY_ARITH
) &&
310 d_logic
.areIntegersUsed() && ( !d_logic
.areRealsUsed() );
312 return d_logic
.isTheoryEnabled(theory::THEORY_ARITH
) &&
313 ( !d_logic
.areIntegersUsed() ) && d_logic
.areRealsUsed();
314 case THEORY_REALS_INTS
:
315 return d_logic
.isTheoryEnabled(theory::THEORY_ARITH
) &&
316 d_logic
.areIntegersUsed() && d_logic
.areRealsUsed();
317 case THEORY_QUANTIFIERS
:
318 return d_logic
.isQuantified();
320 return d_logic
.isTheoryEnabled(theory::THEORY_SETS
);
322 return d_logic
.isTheoryEnabled(theory::THEORY_STRINGS
);
324 return d_logic
.isTheoryEnabled(theory::THEORY_UF
);
326 return d_logic
.isTheoryEnabled(theory::THEORY_FP
);
328 return d_logic
.isTheoryEnabled(theory::THEORY_SEP
);
330 std::stringstream ss
;
331 ss
<< "internal error: unsupported theory " << theory
;
332 throw ParserException(ss
.str());
336 bool Smt2::logicIsSet() {
340 Expr
Smt2::getExpressionForNameAndType(const std::string
& name
, Type t
) {
341 if(sygus() && name
[0]=='-' &&
342 name
.find_first_not_of("0123456789", 1) == std::string::npos
) {
343 //allow unary minus in sygus
344 return getExprManager()->mkConst(Rational(name
));
345 }else if(isAbstractValue(name
)) {
346 return mkAbstractValue(name
);
348 return Parser::getExpressionForNameAndType(name
, t
);
354 d_logic
= LogicInfo();
355 operatorKindMap
.clear();
356 d_lastNamedTerm
= std::pair
<Expr
, std::string
>();
357 this->Parser::reset();
359 if( !strictModeEnabled() ) {
360 addTheory(Smt2::THEORY_CORE
);
364 void Smt2::resetAssertions() {
365 this->Parser::reset();
368 void Smt2::setLogic(std::string name
) {
371 // non-smt2-standard sygus logic names go here (http://sygus.seas.upenn.edu/files/sygus.pdf Section 3.2)
372 if(name
== "Arrays") {
374 }else if(name
== "Reals") {
380 if(logicIsForced()) {
381 d_logic
= getForcedLogic();
386 // if sygus is enabled, we must enable UF, datatypes, integer arithmetic and
389 // get unlocked copy, modify, copy and relock
390 LogicInfo
log(d_logic
.getUnlockedCopy());
391 log
.enableTheory(theory::THEORY_UF
);
392 log
.enableTheory(theory::THEORY_DATATYPES
);
393 log
.enableIntegers();
394 log
.enableHigherOrder();
399 // Core theory belongs to every logic
400 addTheory(THEORY_CORE
);
402 if(d_logic
.isTheoryEnabled(theory::THEORY_UF
)) {
403 addTheory(THEORY_UF
);
406 if(d_logic
.isTheoryEnabled(theory::THEORY_ARITH
)) {
407 if(d_logic
.areIntegersUsed()) {
408 if(d_logic
.areRealsUsed()) {
409 addTheory(THEORY_REALS_INTS
);
411 addTheory(THEORY_INTS
);
413 } else if(d_logic
.areRealsUsed()) {
414 addTheory(THEORY_REALS
);
418 if(d_logic
.isTheoryEnabled(theory::THEORY_ARRAY
)) {
419 addTheory(THEORY_ARRAYS
);
422 if(d_logic
.isTheoryEnabled(theory::THEORY_BV
)) {
423 addTheory(THEORY_BITVECTORS
);
426 if(d_logic
.isTheoryEnabled(theory::THEORY_DATATYPES
)) {
427 addTheory(THEORY_DATATYPES
);
430 if(d_logic
.isTheoryEnabled(theory::THEORY_SETS
)) {
431 addTheory(THEORY_SETS
);
434 if(d_logic
.isTheoryEnabled(theory::THEORY_STRINGS
)) {
435 addTheory(THEORY_STRINGS
);
438 if(d_logic
.isQuantified()) {
439 addTheory(THEORY_QUANTIFIERS
);
442 if (d_logic
.isTheoryEnabled(theory::THEORY_FP
)) {
443 addTheory(THEORY_FP
);
446 if (d_logic
.isTheoryEnabled(theory::THEORY_SEP
)) {
447 addTheory(THEORY_SEP
);
450 }/* Smt2::setLogic() */
452 void Smt2::setInfo(const std::string
& flag
, const SExpr
& sexpr
) {
456 void Smt2::setOption(const std::string
& flag
, const SExpr
& sexpr
) {
460 void Smt2::checkThatLogicIsSet() {
461 if( ! logicIsSet() ) {
462 if(strictModeEnabled()) {
463 parseError("set-logic must appear before this point.");
465 warning("No set-logic command was given before this point.");
466 warning("CVC4 will make all theories available.");
467 warning("Consider setting a stricter logic for (likely) better performance.");
468 warning("To suppress this warning in the future use (set-logic ALL).");
472 Command
* c
= new SetBenchmarkLogicCommand("ALL");
479 /* The include are managed in the lexer but called in the parser */
480 // Inspired by http://www.antlr3.org/api/C/interop.html
482 static bool newInputStream(const std::string
& filename
, pANTLR3_LEXER lexer
) {
483 Debug("parser") << "Including " << filename
<< std::endl
;
484 // Create a new input stream and take advantage of built in stream stacking
485 // in C target runtime.
487 pANTLR3_INPUT_STREAM in
;
488 #ifdef CVC4_ANTLR3_OLD_INPUT_STREAM
489 in
= antlr3AsciiFileStreamNew((pANTLR3_UINT8
) filename
.c_str());
490 #else /* CVC4_ANTLR3_OLD_INPUT_STREAM */
491 in
= antlr3FileStreamNew((pANTLR3_UINT8
) filename
.c_str(), ANTLR3_ENC_8BIT
);
492 #endif /* CVC4_ANTLR3_OLD_INPUT_STREAM */
494 Debug("parser") << "Can't open " << filename
<< std::endl
;
497 // Same thing as the predefined PUSHSTREAM(in);
498 lexer
->pushCharStream(lexer
, in
);
500 //lexer->rec->state->tokenStartCharIndex = -10;
501 //lexer->emit(lexer);
503 // Note that the input stream is not closed when it EOFs, I don't bother
504 // to do it here, but it is up to you to track streams created like this
505 // and destroy them when the whole parse session is complete. Remember that you
506 // don't want to do this until all tokens have been manipulated all the way through
507 // your tree parsers etc as the token does not store the text it just refers
508 // back to the input stream and trying to get the text for it will abort if you
509 // close the input stream too early.
511 //TODO what said before
515 void Smt2::includeFile(const std::string
& filename
) {
516 // security for online version
517 if(!canIncludeFile()) {
518 parseError("include-file feature was disabled for this run.");
522 AntlrInput
* ai
= static_cast<AntlrInput
*>(getInput());
523 pANTLR3_LEXER lexer
= ai
->getAntlr3Lexer();
524 // get the name of the current stream "Does it work inside an include?"
525 const std::string inputName
= ai
->getInputStreamName();
527 // Find the directory of the current input file
529 size_t pos
= inputName
.rfind('/');
530 if(pos
!= std::string::npos
) {
531 path
= std::string(inputName
, 0, pos
+ 1);
533 path
.append(filename
);
534 if(!newInputStream(path
, lexer
)) {
535 parseError("Couldn't open include file `" + path
+ "'");
539 Expr
Smt2::mkSygusVar(const std::string
& name
, const Type
& type
, bool isPrimed
) {
540 Expr e
= mkBoundVar(name
, type
);
541 d_sygusVars
.push_back(e
);
542 d_sygusVarPrimed
[e
] = false;
544 std::stringstream ss
;
546 Expr ep
= mkBoundVar(ss
.str(), type
);
547 d_sygusVars
.push_back(ep
);
548 d_sygusVarPrimed
[ep
] = true;
553 void Smt2::mkSygusConstantsForType( const Type
& type
, std::vector
<CVC4::Expr
>& ops
) {
554 if( type
.isInteger() ){
555 ops
.push_back(getExprManager()->mkConst(Rational(0)));
556 ops
.push_back(getExprManager()->mkConst(Rational(1)));
557 }else if( type
.isBitVector() ){
558 unsigned sz
= ((BitVectorType
)type
).getSize();
559 BitVector
bval0(sz
, (unsigned int)0);
560 ops
.push_back( getExprManager()->mkConst(bval0
) );
561 BitVector
bval1(sz
, (unsigned int)1);
562 ops
.push_back( getExprManager()->mkConst(bval1
) );
563 }else if( type
.isBoolean() ){
564 ops
.push_back(getExprManager()->mkConst(true));
565 ops
.push_back(getExprManager()->mkConst(false));
570 // This method adds N operators to ops[index], N names to cnames[index] and N type argument vectors to cargs[index] (where typically N=1)
571 // This method may also add new elements pairwise into datatypes/sorts/ops/cnames/cargs in the case of non-flat gterms.
572 void Smt2::processSygusGTerm( CVC4::SygusGTerm
& sgt
, int index
,
573 std::vector
< CVC4::Datatype
>& datatypes
,
574 std::vector
< CVC4::Type
>& sorts
,
575 std::vector
< std::vector
<CVC4::Expr
> >& ops
,
576 std::vector
< std::vector
<std::string
> >& cnames
,
577 std::vector
< std::vector
< std::vector
< CVC4::Type
> > >& cargs
,
578 std::vector
< bool >& allow_const
,
579 std::vector
< std::vector
< std::string
> >& unresolved_gterm_sym
,
580 std::vector
<CVC4::Expr
>& sygus_vars
,
581 std::map
< CVC4::Type
, CVC4::Type
>& sygus_to_builtin
, std::map
< CVC4::Type
, CVC4::Expr
>& sygus_to_builtin_expr
,
582 CVC4::Type
& ret
, bool isNested
){
583 if( sgt
.d_gterm_type
==SygusGTerm::gterm_op
|| sgt
.d_gterm_type
==SygusGTerm::gterm_let
){
584 Debug("parser-sygus") << "Add " << sgt
.d_expr
<< " to datatype " << index
<< std::endl
;
586 Kind newKind
= kind::UNDEFINED_KIND
;
587 //convert to UMINUS if one child of MINUS
588 if( sgt
.d_children
.size()==1 && sgt
.d_expr
==getExprManager()->operatorOf(kind::MINUS
) ){
589 oldKind
= kind::MINUS
;
590 newKind
= kind::UMINUS
;
593 //convert to IFF if boolean EQUAL
594 if( sgt.d_expr==getExprManager()->operatorOf(kind::EQUAL) ){
595 Type ctn = sgt.d_children[0].d_type;
596 std::map< CVC4::Type, CVC4::Type >::iterator it = sygus_to_builtin.find( ctn );
597 if( it != sygus_to_builtin.end() && it->second.isBoolean() ){
598 oldKind = kind::EQUAL;
603 if( newKind
!=kind::UNDEFINED_KIND
){
604 Expr newExpr
= getExprManager()->operatorOf(newKind
);
605 Debug("parser-sygus") << "Replace " << sgt
.d_expr
<< " with " << newExpr
<< std::endl
;
606 sgt
.d_expr
= newExpr
;
607 std::string oldName
= kind::kindToString(oldKind
);
608 std::string newName
= kind::kindToString(newKind
);
610 if((pos
= sgt
.d_name
.find(oldName
, pos
)) != std::string::npos
){
611 sgt
.d_name
.replace(pos
, oldName
.length(), newName
);
614 ops
[index
].push_back( sgt
.d_expr
);
615 cnames
[index
].push_back( sgt
.d_name
);
616 cargs
[index
].push_back( std::vector
< CVC4::Type
>() );
617 for( unsigned i
=0; i
<sgt
.d_children
.size(); i
++ ){
618 std::stringstream ss
;
619 ss
<< datatypes
[index
].getName() << "_" << ops
[index
].size() << "_arg_" << i
;
620 std::string sub_dname
= ss
.str();
621 //add datatype for child
623 pushSygusDatatypeDef( null_type
, sub_dname
, datatypes
, sorts
, ops
, cnames
, cargs
, allow_const
, unresolved_gterm_sym
);
624 int sub_dt_index
= datatypes
.size()-1;
627 processSygusGTerm( sgt
.d_children
[i
], sub_dt_index
, datatypes
, sorts
, ops
, cnames
, cargs
, allow_const
, unresolved_gterm_sym
,
628 sygus_vars
, sygus_to_builtin
, sygus_to_builtin_expr
, sub_ret
, true );
629 //process the nested gterm (either pop the last datatype, or flatten the argument)
630 Type tt
= processSygusNestedGTerm( sub_dt_index
, sub_dname
, datatypes
, sorts
, ops
, cnames
, cargs
, allow_const
, unresolved_gterm_sym
,
631 sygus_to_builtin
, sygus_to_builtin_expr
, sub_ret
);
632 cargs
[index
].back().push_back(tt
);
634 //if let, must create operator
635 if( sgt
.d_gterm_type
==SygusGTerm::gterm_let
){
636 processSygusLetConstructor( sgt
.d_let_vars
, index
, datatypes
, sorts
, ops
, cnames
, cargs
,
637 sygus_vars
, sygus_to_builtin
, sygus_to_builtin_expr
);
639 }else if( sgt
.d_gterm_type
==SygusGTerm::gterm_constant
){
640 if( sgt
.getNumChildren()!=0 ){
641 parseError("Bad syntax for Sygus Constant.");
643 std::vector
< Expr
> consts
;
644 mkSygusConstantsForType( sgt
.d_type
, consts
);
645 Debug("parser-sygus") << "...made " << consts
.size() << " constants." << std::endl
;
646 for( unsigned i
=0; i
<consts
.size(); i
++ ){
647 std::stringstream ss
;
649 Debug("parser-sygus") << "...add for constant " << ss
.str() << std::endl
;
650 ops
[index
].push_back( consts
[i
] );
651 cnames
[index
].push_back( ss
.str() );
652 cargs
[index
].push_back( std::vector
< CVC4::Type
>() );
654 allow_const
[index
] = true;
655 }else if( sgt
.d_gterm_type
==SygusGTerm::gterm_variable
|| sgt
.d_gterm_type
==SygusGTerm::gterm_input_variable
){
656 if( sgt
.getNumChildren()!=0 ){
657 parseError("Bad syntax for Sygus Variable.");
659 Debug("parser-sygus") << "...process " << sygus_vars
.size() << " variables." << std::endl
;
660 for( unsigned i
=0; i
<sygus_vars
.size(); i
++ ){
661 if( sygus_vars
[i
].getType()==sgt
.d_type
){
662 std::stringstream ss
;
664 Debug("parser-sygus") << "...add for variable " << ss
.str() << std::endl
;
665 ops
[index
].push_back( sygus_vars
[i
] );
666 cnames
[index
].push_back( ss
.str() );
667 cargs
[index
].push_back( std::vector
< CVC4::Type
>() );
670 }else if( sgt
.d_gterm_type
==SygusGTerm::gterm_nested_sort
){
672 }else if( sgt
.d_gterm_type
==SygusGTerm::gterm_unresolved
){
674 if( isUnresolvedType(sgt
.d_name
) ){
675 ret
= getSort(sgt
.d_name
);
677 //nested, unresolved symbol...fail
678 std::stringstream ss
;
679 ss
<< "Cannot handle nested unresolved symbol " << sgt
.d_name
<< std::endl
;
680 parseError(ss
.str());
683 //will resolve when adding constructors
684 unresolved_gterm_sym
[index
].push_back(sgt
.d_name
);
686 }else if( sgt
.d_gterm_type
==SygusGTerm::gterm_ignore
){
691 bool Smt2::pushSygusDatatypeDef( Type t
, std::string
& dname
,
692 std::vector
< CVC4::Datatype
>& datatypes
,
693 std::vector
< CVC4::Type
>& sorts
,
694 std::vector
< std::vector
<CVC4::Expr
> >& ops
,
695 std::vector
< std::vector
<std::string
> >& cnames
,
696 std::vector
< std::vector
< std::vector
< CVC4::Type
> > >& cargs
,
697 std::vector
< bool >& allow_const
,
698 std::vector
< std::vector
< std::string
> >& unresolved_gterm_sym
){
700 datatypes
.push_back(Datatype(dname
));
701 ops
.push_back(std::vector
<Expr
>());
702 cnames
.push_back(std::vector
<std::string
>());
703 cargs
.push_back(std::vector
<std::vector
<CVC4::Type
> >());
704 allow_const
.push_back(false);
705 unresolved_gterm_sym
.push_back(std::vector
< std::string
>());
709 bool Smt2::popSygusDatatypeDef( std::vector
< CVC4::Datatype
>& datatypes
,
710 std::vector
< CVC4::Type
>& sorts
,
711 std::vector
< std::vector
<CVC4::Expr
> >& ops
,
712 std::vector
< std::vector
<std::string
> >& cnames
,
713 std::vector
< std::vector
< std::vector
< CVC4::Type
> > >& cargs
,
714 std::vector
< bool >& allow_const
,
715 std::vector
< std::vector
< std::string
> >& unresolved_gterm_sym
){
717 datatypes
.pop_back();
721 allow_const
.pop_back();
722 unresolved_gterm_sym
.pop_back();
726 Type
Smt2::processSygusNestedGTerm( int sub_dt_index
, std::string
& sub_dname
, std::vector
< CVC4::Datatype
>& datatypes
,
727 std::vector
< CVC4::Type
>& sorts
,
728 std::vector
< std::vector
<CVC4::Expr
> >& ops
,
729 std::vector
< std::vector
<std::string
> >& cnames
,
730 std::vector
< std::vector
< std::vector
< CVC4::Type
> > >& cargs
,
731 std::vector
< bool >& allow_const
,
732 std::vector
< std::vector
< std::string
> >& unresolved_gterm_sym
,
733 std::map
< CVC4::Type
, CVC4::Type
>& sygus_to_builtin
,
734 std::map
< CVC4::Type
, CVC4::Expr
>& sygus_to_builtin_expr
, Type sub_ret
) {
736 Debug("parser-sygus") << "Argument is ";
738 //then, it is the datatype we constructed, which should have a single constructor
739 t
= mkUnresolvedType(sub_dname
);
740 Debug("parser-sygus") << "inline flattening of (auxiliary, local) datatype " << t
<< std::endl
;
741 Debug("parser-sygus") << ": to compute type, construct ground term witnessing the grammar, #cons=" << cargs
[sub_dt_index
].size() << std::endl
;
742 if( cargs
[sub_dt_index
].empty() ){
743 parseError(std::string("Internal error : datatype for nested gterm does not have a constructor."));
745 Expr sop
= ops
[sub_dt_index
][0];
747 if( sop
.getKind() != kind::BUILTIN
&& ( sop
.isConst() || cargs
[sub_dt_index
][0].empty() ) ){
748 curr_t
= sop
.getType();
749 Debug("parser-sygus") << ": it is constant/0-arg cons " << sop
<< " with type " << sop
.getType() << ", debug=" << sop
.isConst() << " " << cargs
[sub_dt_index
][0].size() << std::endl
;
750 sygus_to_builtin_expr
[t
] = sop
;
751 //store that term sop has dedicated sygus type t
752 if( d_sygus_bound_var_type
.find( sop
)==d_sygus_bound_var_type
.end() ){
753 d_sygus_bound_var_type
[sop
] = t
;
756 std::vector
< Expr
> children
;
757 if( sop
.getKind() != kind::BUILTIN
){
758 children
.push_back( sop
);
760 for( unsigned i
=0; i
<cargs
[sub_dt_index
][0].size(); i
++ ){
761 std::map
< CVC4::Type
, CVC4::Expr
>::iterator it
= sygus_to_builtin_expr
.find( cargs
[sub_dt_index
][0][i
] );
762 if( it
==sygus_to_builtin_expr
.end() ){
763 if( sygus_to_builtin
.find( cargs
[sub_dt_index
][0][i
] )==sygus_to_builtin
.end() ){
764 std::stringstream ss
;
765 ss
<< "Missing builtin type for type " << cargs
[sub_dt_index
][0][i
] << "!" << std::endl
;
766 ss
<< "Builtin types are currently : " << std::endl
;
767 for( std::map
< CVC4::Type
, CVC4::Type
>::iterator itb
= sygus_to_builtin
.begin(); itb
!= sygus_to_builtin
.end(); ++itb
){
768 ss
<< " " << itb
->first
<< " -> " << itb
->second
<< std::endl
;
770 parseError(ss
.str());
772 Type bt
= sygus_to_builtin
[cargs
[sub_dt_index
][0][i
]];
773 Debug("parser-sygus") << ": child " << i
<< " introduce type elem for " << cargs
[sub_dt_index
][0][i
] << " " << bt
<< std::endl
;
774 std::stringstream ss
;
775 ss
<< t
<< "_x_" << i
;
776 Expr bv
= mkBoundVar(ss
.str(), bt
);
777 children
.push_back( bv
);
778 d_sygus_bound_var_type
[bv
] = cargs
[sub_dt_index
][0][i
];
780 Debug("parser-sygus") << ": child " << i
<< " existing sygus to builtin expr : " << it
->second
<< std::endl
;
781 children
.push_back( it
->second
);
784 Kind sk
= sop
.getKind() != kind::BUILTIN
? kind::APPLY
: getExprManager()->operatorToKind(sop
);
785 Debug("parser-sygus") << ": operator " << sop
<< " with " << sop
.getKind() << " " << sk
<< std::endl
;
786 Expr e
= getExprManager()->mkExpr( sk
, children
);
787 Debug("parser-sygus") << ": constructed " << e
<< ", which has type " << e
.getType() << std::endl
;
788 curr_t
= e
.getType();
789 sygus_to_builtin_expr
[t
] = e
;
791 sorts
[sub_dt_index
] = curr_t
;
792 sygus_to_builtin
[t
] = curr_t
;
794 Debug("parser-sygus") << "simple argument " << t
<< std::endl
;
795 Debug("parser-sygus") << "...removing " << datatypes
.back().getName() << std::endl
;
796 //otherwise, datatype was unecessary
797 //pop argument datatype definition
798 popSygusDatatypeDef( datatypes
, sorts
, ops
, cnames
, cargs
, allow_const
, unresolved_gterm_sym
);
803 void Smt2::processSygusLetConstructor( std::vector
< CVC4::Expr
>& let_vars
,
805 std::vector
< CVC4::Datatype
>& datatypes
,
806 std::vector
< CVC4::Type
>& sorts
,
807 std::vector
< std::vector
<CVC4::Expr
> >& ops
,
808 std::vector
< std::vector
<std::string
> >& cnames
,
809 std::vector
< std::vector
< std::vector
< CVC4::Type
> > >& cargs
,
810 std::vector
<CVC4::Expr
>& sygus_vars
,
811 std::map
< CVC4::Type
, CVC4::Type
>& sygus_to_builtin
,
812 std::map
< CVC4::Type
, CVC4::Expr
>& sygus_to_builtin_expr
) {
813 std::vector
< CVC4::Expr
> let_define_args
;
815 int dindex
= cargs
[index
].size()-1;
816 Debug("parser-sygus") << "Process let constructor for datatype " << datatypes
[index
].getName() << ", #subtypes = " << cargs
[index
][dindex
].size() << std::endl
;
817 for( unsigned i
=0; i
<cargs
[index
][dindex
].size(); i
++ ){
818 Debug("parser-sygus") << " " << i
<< " : " << cargs
[index
][dindex
][i
] << std::endl
;
819 if( i
+1==cargs
[index
][dindex
].size() ){
820 std::map
< CVC4::Type
, CVC4::Expr
>::iterator it
= sygus_to_builtin_expr
.find( cargs
[index
][dindex
][i
] );
821 if( it
!=sygus_to_builtin_expr
.end() ){
822 let_body
= it
->second
;
824 std::stringstream ss
;
825 ss
<< datatypes
[index
].getName() << "_body";
826 let_body
= mkBoundVar(ss
.str(), sygus_to_builtin
[cargs
[index
][dindex
][i
]]);
827 d_sygus_bound_var_type
[let_body
] = cargs
[index
][dindex
][i
];
831 Debug("parser-sygus") << std::endl
;
832 Debug("parser-sygus") << "Body is " << let_body
<< std::endl
;
833 Debug("parser-sygus") << "# let vars = " << let_vars
.size() << std::endl
;
834 for( unsigned i
=0; i
<let_vars
.size(); i
++ ){
835 Debug("parser-sygus") << " let var " << i
<< " : " << let_vars
[i
] << " " << let_vars
[i
].getType() << std::endl
;
836 let_define_args
.push_back( let_vars
[i
] );
839 Debug("parser-sygus") << "index = " << index << ", start index = " << start_index << ", #Current datatypes = " << datatypes.size() << std::endl;
840 for( unsigned i=start_index; i<datatypes.size(); i++ ){
841 Debug("parser-sygus") << " datatype " << i << " : " << datatypes[i].getName() << ", #cons = " << cargs[i].size() << std::endl;
842 if( !cargs[i].empty() ){
843 Debug("parser-sygus") << " operator 0 is " << ops[i][0] << std::endl;
844 Debug("parser-sygus") << " cons 0 has " << cargs[i][0].size() << " sub fields." << std::endl;
845 for( unsigned j=0; j<cargs[i][0].size(); j++ ){
846 Type bt = sygus_to_builtin[cargs[i][0][j]];
847 Debug("parser-sygus") << " cons 0, selector " << j << " : " << cargs[i][0][j] << " " << bt << std::endl;
852 //last argument is the return, pop
853 cargs
[index
][dindex
].pop_back();
854 collectSygusLetArgs( let_body
, cargs
[index
][dindex
], let_define_args
);
856 Debug("parser-sygus") << "Make define-fun with " << cargs
[index
][dindex
].size() << " arguments..." << std::endl
;
857 std::vector
<CVC4::Type
> fsorts
;
858 for( unsigned i
=0; i
<cargs
[index
][dindex
].size(); i
++ ){
859 Debug("parser-sygus") << " " << i
<< " : " << let_define_args
[i
] << " " << let_define_args
[i
].getType() << " " << cargs
[index
][dindex
][i
] << std::endl
;
860 fsorts
.push_back(let_define_args
[i
].getType());
863 Type ft
= getExprManager()->mkFunctionType(fsorts
, let_body
.getType());
864 std::stringstream ss
;
865 ss
<< datatypes
[index
].getName() << "_let";
866 Expr let_func
= mkFunction(ss
.str(), ft
, ExprManager::VAR_FLAG_DEFINED
);
867 d_sygus_defined_funs
.push_back( let_func
);
868 preemptCommand( new DefineFunctionCommand(ss
.str(), let_func
, let_define_args
, let_body
) );
870 ops
[index
].pop_back();
871 ops
[index
].push_back( let_func
);
872 cnames
[index
].pop_back();
873 cnames
[index
].push_back(ss
.str());
875 //mark function as let constructor
876 d_sygus_let_func_to_vars
[let_func
].insert( d_sygus_let_func_to_vars
[let_func
].end(), let_define_args
.begin(), let_define_args
.end() );
877 d_sygus_let_func_to_body
[let_func
] = let_body
;
878 d_sygus_let_func_to_num_input_vars
[let_func
] = let_vars
.size();
882 void Smt2::collectSygusLetArgs( CVC4::Expr e
, std::vector
< CVC4::Type
>& sygusArgs
, std::vector
< CVC4::Expr
>& builtinArgs
) {
883 if( e
.getKind()==kind::BOUND_VARIABLE
){
884 if( std::find( builtinArgs
.begin(), builtinArgs
.end(), e
)==builtinArgs
.end() ){
885 builtinArgs
.push_back( e
);
886 sygusArgs
.push_back( d_sygus_bound_var_type
[e
] );
887 if( d_sygus_bound_var_type
[e
].isNull() ){
888 std::stringstream ss
;
889 ss
<< "While constructing body of let gterm, can't map " << e
<< " to sygus type." << std::endl
;
890 parseError(ss
.str());
894 for( unsigned i
=0; i
<e
.getNumChildren(); i
++ ){
895 collectSygusLetArgs( e
[i
], sygusArgs
, builtinArgs
);
900 void Smt2::setSygusStartIndex( std::string
& fun
, int startIndex
,
901 std::vector
< CVC4::Datatype
>& datatypes
,
902 std::vector
< CVC4::Type
>& sorts
,
903 std::vector
< std::vector
<CVC4::Expr
> >& ops
) {
905 CVC4::Datatype tmp_dt
= datatypes
[0];
906 Type tmp_sort
= sorts
[0];
907 std::vector
< Expr
> tmp_ops
;
908 tmp_ops
.insert( tmp_ops
.end(), ops
[0].begin(), ops
[0].end() );
909 datatypes
[0] = datatypes
[startIndex
];
910 sorts
[0] = sorts
[startIndex
];
912 ops
[0].insert( ops
[0].end(), ops
[startIndex
].begin(), ops
[startIndex
].end() );
913 datatypes
[startIndex
] = tmp_dt
;
914 sorts
[startIndex
] = tmp_sort
;
915 ops
[startIndex
].clear();
916 ops
[startIndex
].insert( ops
[startIndex
].begin(), tmp_ops
.begin(), tmp_ops
.end() );
917 }else if( startIndex
<0 ){
918 std::stringstream ss
;
919 ss
<< "warning: no symbol named Start for synth-fun " << fun
<< std::endl
;
924 void Smt2::mkSygusDatatype( CVC4::Datatype
& dt
, std::vector
<CVC4::Expr
>& ops
,
925 std::vector
<std::string
>& cnames
, std::vector
< std::vector
< CVC4::Type
> >& cargs
,
926 std::vector
<std::string
>& unresolved_gterm_sym
,
927 std::map
< CVC4::Type
, CVC4::Type
>& sygus_to_builtin
) {
928 Debug("parser-sygus") << "Making sygus datatype " << dt
.getName() << std::endl
;
929 Debug("parser-sygus") << " add constructors..." << std::endl
;
931 Debug("parser-sygus") << "SMT2 sygus parser : Making constructors for sygus datatype " << dt
.getName() << std::endl
;
932 Debug("parser-sygus") << " add constructors..." << std::endl
;
933 for (unsigned i
= 0, size
= cnames
.size(); i
< size
; i
++)
936 bool is_dup_op
= false;
937 for (unsigned j
= 0; j
< i
; j
++)
939 if( ops
[i
]==ops
[j
] ){
941 if( cargs
[i
].size()==cargs
[j
].size() ){
943 for( unsigned k
=0; k
<cargs
[i
].size(); k
++ ){
944 if( cargs
[i
][k
]!=cargs
[j
][k
] ){
955 Debug("parser-sygus") << "SYGUS CONS " << i
<< " : ";
957 Debug("parser-sygus") << "--> Duplicate gterm : " << ops
[i
] << std::endl
;
958 ops
.erase( ops
.begin() + i
, ops
.begin() + i
+ 1 );
959 cnames
.erase( cnames
.begin() + i
, cnames
.begin() + i
+ 1 );
960 cargs
.erase( cargs
.begin() + i
, cargs
.begin() + i
+ 1 );
965 std::shared_ptr
<SygusPrintCallback
> spc
;
968 Debug("parser-sygus") << "--> Duplicate gterm operator : " << ops
[i
]
970 // make into define-fun
971 std::vector
<Type
> ltypes
;
972 for (unsigned j
= 0, size
= cargs
[i
].size(); j
< size
; j
++)
974 ltypes
.push_back(sygus_to_builtin
[cargs
[i
][j
]]);
976 std::vector
<Expr
> largs
;
977 Expr lbvl
= makeSygusBoundVarList(dt
, i
, ltypes
, largs
);
980 std::vector
<Expr
> children
;
981 if (ops
[i
].getKind() != kind::BUILTIN
)
983 children
.push_back(ops
[i
]);
985 children
.insert(children
.end(), largs
.begin(), largs
.end());
986 Kind sk
= ops
[i
].getKind() != kind::BUILTIN
988 : getExprManager()->operatorToKind(ops
[i
]);
989 Expr body
= getExprManager()->mkExpr(sk
, children
);
991 ops
[i
] = getExprManager()->mkExpr(kind::LAMBDA
, lbvl
, body
);
992 Debug("parser-sygus") << " ...replace op : " << ops
[i
] << std::endl
;
993 // callback prints as the expression
994 spc
= std::make_shared
<printer::SygusExprPrintCallback
>(body
, largs
);
998 std::map
<Expr
, Expr
>::iterator it
=
999 d_sygus_let_func_to_body
.find(ops
[i
]);
1000 if (it
!= d_sygus_let_func_to_body
.end())
1002 Debug("parser-sygus") << "--> Let expression " << ops
[i
] << std::endl
;
1003 Expr let_body
= it
->second
;
1004 std::vector
<Expr
> let_args
= d_sygus_let_func_to_vars
[ops
[i
]];
1005 unsigned let_num_input_args
=
1006 d_sygus_let_func_to_num_input_vars
[ops
[i
]];
1007 // the operator is just the body for the arguments
1008 std::vector
<Type
> ltypes
;
1009 for (unsigned j
= 0, size
= let_args
.size(); j
< size
; j
++)
1011 ltypes
.push_back(let_args
[j
].getType());
1013 std::vector
<Expr
> largs
;
1014 Expr lbvl
= makeSygusBoundVarList(dt
, i
, ltypes
, largs
);
1015 Expr sbody
= let_body
.substitute(let_args
, largs
);
1016 ops
[i
] = getExprManager()->mkExpr(kind::LAMBDA
, lbvl
, sbody
);
1017 Debug("parser-sygus") << " ...replace op : " << ops
[i
] << std::endl
;
1018 // callback prints as a let expression
1019 spc
= std::make_shared
<printer::SygusLetExprPrintCallback
>(
1020 let_body
, let_args
, let_num_input_args
);
1022 else if (ops
[i
].getType().isBitVector() && ops
[i
].isConst())
1024 Debug("parser-sygus") << "--> Bit-vector constant " << ops
[i
] << " ("
1025 << cnames
[i
] << ")" << std::endl
;
1026 // Since there are multiple output formats for bit-vectors and
1027 // we are required by sygus standards to print in the exact input
1028 // format given by the user, we use a print callback to custom print
1030 spc
= std::make_shared
<printer::SygusNamedPrintCallback
>(cnames
[i
]);
1032 else if (isDefinedFunction(ops
[i
]))
1034 Debug("parser-sygus") << "--> Defined function " << ops
[i
]
1036 // turn f into (lammbda (x) (f x))
1037 // in a degenerate case, ops[i] may be a defined constant,
1038 // in which case we do not replace by a lambda.
1039 if (ops
[i
].getType().isFunction())
1041 std::vector
<Type
> ftypes
=
1042 static_cast<FunctionType
>(ops
[i
].getType()).getArgTypes();
1043 std::vector
<Expr
> largs
;
1044 Expr lbvl
= makeSygusBoundVarList(dt
, i
, ftypes
, largs
);
1045 largs
.insert(largs
.begin(), ops
[i
]);
1046 Expr body
= getExprManager()->mkExpr(kind::APPLY
, largs
);
1047 ops
[i
] = getExprManager()->mkExpr(kind::LAMBDA
, lbvl
, body
);
1048 Debug("parser-sygus") << " ...replace op : " << ops
[i
]
1053 ops
[i
] = getExprManager()->mkExpr(kind::APPLY
, ops
[i
]);
1054 Debug("parser-sygus") << " ...replace op : " << ops
[i
]
1057 // keep a callback to say it should be printed with the defined name
1058 spc
= std::make_shared
<printer::SygusNamedPrintCallback
>(cnames
[i
]);
1062 Debug("parser-sygus") << "--> Default case " << ops
[i
] << std::endl
;
1065 // must rename to avoid duplication
1066 std::stringstream ss
;
1067 ss
<< dt
.getName() << "_" << i
<< "_" << cnames
[i
];
1068 cnames
[i
] = ss
.str();
1069 // add the sygus constructor
1070 dt
.addSygusConstructor(ops
[i
], cnames
[i
], cargs
[i
], spc
);
1074 Debug("parser-sygus") << " add constructors for unresolved symbols..." << std::endl
;
1075 if( !unresolved_gterm_sym
.empty() ){
1076 std::vector
< Type
> types
;
1077 Debug("parser-sygus") << "...resolve " << unresolved_gterm_sym
.size() << " symbols..." << std::endl
;
1078 for( unsigned i
=0; i
<unresolved_gterm_sym
.size(); i
++ ){
1079 Debug("parser-sygus") << " resolve : " << unresolved_gterm_sym
[i
] << std::endl
;
1080 if( isUnresolvedType(unresolved_gterm_sym
[i
]) ){
1081 Debug("parser-sygus") << " it is an unresolved type." << std::endl
;
1082 Type t
= getSort(unresolved_gterm_sym
[i
]);
1083 if( std::find( types
.begin(), types
.end(), t
)==types
.end() ){
1084 types
.push_back( t
);
1086 Type bt
= dt
.getSygusType();
1087 Debug("parser-sygus") << ": make identity function for " << bt
<< ", argument type " << t
<< std::endl
;
1089 std::stringstream ss
;
1091 Expr var
= mkBoundVar(ss
.str(), bt
);
1092 std::vector
<Expr
> lchildren
;
1093 lchildren
.push_back(
1094 getExprManager()->mkExpr(kind::BOUND_VAR_LIST
, var
));
1095 lchildren
.push_back(var
);
1096 Expr id_op
= getExprManager()->mkExpr(kind::LAMBDA
, lchildren
);
1098 // empty sygus callback (should not be printed)
1099 std::shared_ptr
<SygusPrintCallback
> sepc
=
1100 std::make_shared
<printer::SygusEmptyPrintCallback
>();
1102 //make the sygus argument list
1103 std::vector
< Type
> id_carg
;
1104 id_carg
.push_back( t
);
1105 dt
.addSygusConstructor(id_op
, unresolved_gterm_sym
[i
], id_carg
, sepc
);
1108 ops
.push_back( id_op
);
1111 Debug("parser-sygus") << " ignore. (likely a free let variable)" << std::endl
;
1117 Expr
Smt2::makeSygusBoundVarList(Datatype
& dt
,
1119 const std::vector
<Type
>& ltypes
,
1120 std::vector
<Expr
>& lvars
)
1122 for (unsigned j
= 0, size
= ltypes
.size(); j
< size
; j
++)
1124 std::stringstream ss
;
1125 ss
<< dt
.getName() << "_x_" << i
<< "_" << j
;
1126 Expr v
= mkBoundVar(ss
.str(), ltypes
[j
]);
1129 return getExprManager()->mkExpr(kind::BOUND_VAR_LIST
, lvars
);
1132 const void Smt2::getSygusPrimedVars( std::vector
<Expr
>& vars
, bool isPrimed
) {
1133 for( unsigned i
=0; i
<d_sygusVars
.size(); i
++ ){
1134 Expr v
= d_sygusVars
[i
];
1135 std::map
< Expr
, bool >::iterator it
= d_sygusVarPrimed
.find( v
);
1136 if( it
!=d_sygusVarPrimed
.end() ){
1137 if( it
->second
==isPrimed
){
1138 vars
.push_back( v
);
1141 //should never happen
1146 const void Smt2::addSygusFunSymbol( Type t
, Expr synth_fun
){
1147 // When constructing the synthesis conjecture, we quantify on the
1148 // (higher-order) bound variable synth_fun.
1149 d_sygusFunSymbols
.push_back(synth_fun
);
1151 // Variable "sfproxy" carries the type, which may be a SyGuS datatype
1152 // that corresponds to syntactic restrictions.
1153 Expr sym
= mkBoundVar("sfproxy", t
);
1154 std::vector
< Expr
> attr_value
;
1155 attr_value
.push_back(sym
);
1157 new SetUserAttributeCommand("sygus-synth-grammar", synth_fun
, attr_value
);
1158 cattr
->setMuted(true);
1159 preemptCommand(cattr
);
1162 }/* CVC4::parser namespace */
1163 }/* CVC4 namespace */