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 "smt/command.h"
25 #include "util/bitvector.h"
29 // ANTLR defines these, which is really bad!
36 Smt2::Smt2(ExprManager
* exprManager
, Input
* input
, bool strictMode
, bool parseOnly
) :
37 Parser(exprManager
,input
,strictMode
,parseOnly
),
39 if( !strictModeEnabled() ) {
40 addTheory(Smt2::THEORY_CORE
);
44 void Smt2::setLanguage(InputLanguage lang
) {
45 ((Smt2Input
*) getInput())->setLanguage(lang
);
48 void Smt2::addArithmeticOperators() {
49 Parser::addOperator(kind::PLUS
);
50 Parser::addOperator(kind::MINUS
);
51 Parser::addOperator(kind::UMINUS
);
52 Parser::addOperator(kind::MULT
);
53 Parser::addOperator(kind::LT
);
54 Parser::addOperator(kind::LEQ
);
55 Parser::addOperator(kind::GT
);
56 Parser::addOperator(kind::GEQ
);
58 addOperator(kind::POW
, "^");
59 addOperator(kind::EXPONENTIAL
, "exp");
60 addOperator(kind::SINE
, "sin");
61 addOperator(kind::COSINE
, "cos");
62 addOperator(kind::TANGENT
, "tan");
65 void Smt2::addBitvectorOperators() {
66 addOperator(kind::BITVECTOR_CONCAT
, "concat");
67 addOperator(kind::BITVECTOR_NOT
, "bvnot");
68 addOperator(kind::BITVECTOR_AND
, "bvand");
69 addOperator(kind::BITVECTOR_OR
, "bvor");
70 addOperator(kind::BITVECTOR_NEG
, "bvneg");
71 addOperator(kind::BITVECTOR_PLUS
, "bvadd");
72 addOperator(kind::BITVECTOR_MULT
, "bvmul");
73 addOperator(kind::BITVECTOR_UDIV
, "bvudiv");
74 addOperator(kind::BITVECTOR_UREM
, "bvurem");
75 addOperator(kind::BITVECTOR_SHL
, "bvshl");
76 addOperator(kind::BITVECTOR_LSHR
, "bvlshr");
77 addOperator(kind::BITVECTOR_ULT
, "bvult");
78 addOperator(kind::BITVECTOR_NAND
, "bvnand");
79 addOperator(kind::BITVECTOR_NOR
, "bvnor");
80 addOperator(kind::BITVECTOR_XOR
, "bvxor");
81 addOperator(kind::BITVECTOR_XNOR
, "bvxnor");
82 addOperator(kind::BITVECTOR_COMP
, "bvcomp");
83 addOperator(kind::BITVECTOR_SUB
, "bvsub");
84 addOperator(kind::BITVECTOR_SDIV
, "bvsdiv");
85 addOperator(kind::BITVECTOR_SREM
, "bvsrem");
86 addOperator(kind::BITVECTOR_SMOD
, "bvsmod");
87 addOperator(kind::BITVECTOR_ASHR
, "bvashr");
88 addOperator(kind::BITVECTOR_ULE
, "bvule");
89 addOperator(kind::BITVECTOR_UGT
, "bvugt");
90 addOperator(kind::BITVECTOR_UGE
, "bvuge");
91 addOperator(kind::BITVECTOR_SLT
, "bvslt");
92 addOperator(kind::BITVECTOR_SLE
, "bvsle");
93 addOperator(kind::BITVECTOR_SGT
, "bvsgt");
94 addOperator(kind::BITVECTOR_SGE
, "bvsge");
95 addOperator(kind::BITVECTOR_REDOR
, "bvredor");
96 addOperator(kind::BITVECTOR_REDAND
, "bvredand");
98 Parser::addOperator(kind::BITVECTOR_BITOF
);
99 Parser::addOperator(kind::BITVECTOR_EXTRACT
);
100 Parser::addOperator(kind::BITVECTOR_REPEAT
);
101 Parser::addOperator(kind::BITVECTOR_ZERO_EXTEND
);
102 Parser::addOperator(kind::BITVECTOR_SIGN_EXTEND
);
103 Parser::addOperator(kind::BITVECTOR_ROTATE_LEFT
);
104 Parser::addOperator(kind::BITVECTOR_ROTATE_RIGHT
);
106 Parser::addOperator(kind::INT_TO_BITVECTOR
);
107 Parser::addOperator(kind::BITVECTOR_TO_NAT
);
110 void Smt2::addStringOperators() {
111 addOperator(kind::STRING_CONCAT
, "str.++");
112 addOperator(kind::STRING_LENGTH
, "str.len");
113 addOperator(kind::STRING_SUBSTR
, "str.substr" );
114 addOperator(kind::STRING_STRCTN
, "str.contains" );
115 addOperator(kind::STRING_CHARAT
, "str.at" );
116 addOperator(kind::STRING_STRIDOF
, "str.indexof" );
117 addOperator(kind::STRING_STRREPL
, "str.replace" );
118 addOperator(kind::STRING_PREFIX
, "str.prefixof" );
119 addOperator(kind::STRING_SUFFIX
, "str.suffixof" );
120 addOperator(kind::STRING_ITOS
, "int.to.str" );
121 addOperator(kind::STRING_STOI
, "str.to.int" );
122 addOperator(kind::STRING_IN_REGEXP
, "str.in.re");
123 addOperator(kind::STRING_TO_REGEXP
, "str.to.re");
124 addOperator(kind::REGEXP_CONCAT
, "re.++");
125 addOperator(kind::REGEXP_UNION
, "re.union");
126 addOperator(kind::REGEXP_INTER
, "re.inter");
127 addOperator(kind::REGEXP_STAR
, "re.*");
128 addOperator(kind::REGEXP_PLUS
, "re.+");
129 addOperator(kind::REGEXP_OPT
, "re.opt");
130 addOperator(kind::REGEXP_RANGE
, "re.range");
131 addOperator(kind::REGEXP_LOOP
, "re.loop");
134 void Smt2::addFloatingPointOperators() {
135 addOperator(kind::FLOATINGPOINT_FP
, "fp");
136 addOperator(kind::FLOATINGPOINT_EQ
, "fp.eq");
137 addOperator(kind::FLOATINGPOINT_ABS
, "fp.abs");
138 addOperator(kind::FLOATINGPOINT_NEG
, "fp.neg");
139 addOperator(kind::FLOATINGPOINT_PLUS
, "fp.add");
140 addOperator(kind::FLOATINGPOINT_SUB
, "fp.sub");
141 addOperator(kind::FLOATINGPOINT_MULT
, "fp.mul");
142 addOperator(kind::FLOATINGPOINT_DIV
, "fp.div");
143 addOperator(kind::FLOATINGPOINT_FMA
, "fp.fma");
144 addOperator(kind::FLOATINGPOINT_SQRT
, "fp.sqrt");
145 addOperator(kind::FLOATINGPOINT_REM
, "fp.rem");
146 addOperator(kind::FLOATINGPOINT_RTI
, "fp.roundToIntegral");
147 addOperator(kind::FLOATINGPOINT_MIN
, "fp.min");
148 addOperator(kind::FLOATINGPOINT_MAX
, "fp.max");
149 addOperator(kind::FLOATINGPOINT_LEQ
, "fp.leq");
150 addOperator(kind::FLOATINGPOINT_LT
, "fp.lt");
151 addOperator(kind::FLOATINGPOINT_GEQ
, "fp.geq");
152 addOperator(kind::FLOATINGPOINT_GT
, "fp.gt");
153 addOperator(kind::FLOATINGPOINT_ISN
, "fp.isNormal");
154 addOperator(kind::FLOATINGPOINT_ISSN
, "fp.isSubnormal");
155 addOperator(kind::FLOATINGPOINT_ISZ
, "fp.isZero");
156 addOperator(kind::FLOATINGPOINT_ISINF
, "fp.isInfinite");
157 addOperator(kind::FLOATINGPOINT_ISNAN
, "fp.isNaN");
158 addOperator(kind::FLOATINGPOINT_ISNEG
, "fp.isNegative");
159 addOperator(kind::FLOATINGPOINT_ISPOS
, "fp.isPositive");
160 addOperator(kind::FLOATINGPOINT_TO_REAL
, "fp.to_real");
162 Parser::addOperator(kind::FLOATINGPOINT_TO_FP_IEEE_BITVECTOR
);
163 Parser::addOperator(kind::FLOATINGPOINT_TO_FP_FLOATINGPOINT
);
164 Parser::addOperator(kind::FLOATINGPOINT_TO_FP_REAL
);
165 Parser::addOperator(kind::FLOATINGPOINT_TO_FP_SIGNED_BITVECTOR
);
166 Parser::addOperator(kind::FLOATINGPOINT_TO_FP_UNSIGNED_BITVECTOR
);
167 Parser::addOperator(kind::FLOATINGPOINT_TO_UBV
);
168 Parser::addOperator(kind::FLOATINGPOINT_TO_SBV
);
171 void Smt2::addSepOperators() {
172 addOperator(kind::SEP_STAR
, "sep");
173 addOperator(kind::SEP_PTO
, "pto");
174 addOperator(kind::SEP_WAND
, "wand");
175 addOperator(kind::SEP_EMP
, "emp");
176 Parser::addOperator(kind::SEP_STAR
);
177 Parser::addOperator(kind::SEP_PTO
);
178 Parser::addOperator(kind::SEP_WAND
);
179 Parser::addOperator(kind::SEP_EMP
);
182 void Smt2::addTheory(Theory theory
) {
185 addOperator(kind::SELECT
, "select");
186 addOperator(kind::STORE
, "store");
189 case THEORY_BITVECTORS
:
190 addBitvectorOperators();
194 defineType("Bool", getExprManager()->booleanType());
195 defineVar("true", getExprManager()->mkConst(true));
196 defineVar("false", getExprManager()->mkConst(false));
197 Parser::addOperator(kind::AND
);
198 Parser::addOperator(kind::DISTINCT
);
199 Parser::addOperator(kind::EQUAL
);
200 Parser::addOperator(kind::IMPLIES
);
201 Parser::addOperator(kind::ITE
);
202 Parser::addOperator(kind::NOT
);
203 Parser::addOperator(kind::OR
);
204 Parser::addOperator(kind::XOR
);
207 case THEORY_REALS_INTS
:
208 defineType("Real", getExprManager()->realType());
209 Parser::addOperator(kind::DIVISION
);
210 addOperator(kind::TO_INTEGER
, "to_int");
211 addOperator(kind::IS_INTEGER
, "is_int");
212 addOperator(kind::TO_REAL
, "to_real");
213 // falling through on purpose, to add Ints part of Reals_Ints
215 defineType("Int", getExprManager()->integerType());
216 addArithmeticOperators();
217 addOperator(kind::INTS_DIVISION
, "div");
218 addOperator(kind::INTS_MODULUS
, "mod");
219 addOperator(kind::ABS
, "abs");
220 Parser::addOperator(kind::DIVISIBLE
);
224 defineType("Real", getExprManager()->realType());
225 addArithmeticOperators();
226 Parser::addOperator(kind::DIVISION
);
229 case THEORY_QUANTIFIERS
:
233 addOperator(kind::UNION
, "union");
234 addOperator(kind::INTERSECTION
, "intersection");
235 addOperator(kind::SETMINUS
, "setminus");
236 addOperator(kind::SUBSET
, "subset");
237 addOperator(kind::MEMBER
, "member");
238 addOperator(kind::SINGLETON
, "singleton");
239 addOperator(kind::INSERT
, "insert");
240 addOperator(kind::CARD
, "card");
241 addOperator(kind::COMPLEMENT
, "complement");
244 case THEORY_DATATYPES
:
245 Parser::addOperator(kind::APPLY_CONSTRUCTOR
);
246 Parser::addOperator(kind::APPLY_TESTER
);
247 Parser::addOperator(kind::APPLY_SELECTOR
);
248 Parser::addOperator(kind::APPLY_SELECTOR_TOTAL
);
252 defineType("String", getExprManager()->stringType());
253 defineType("Int", getExprManager()->integerType());
254 addStringOperators();
258 Parser::addOperator(kind::APPLY_UF
);
262 defineType("RoundingMode", getExprManager()->roundingModeType());
263 defineType("Float16", getExprManager()->mkFloatingPointType(5, 11));
264 defineType("Float32", getExprManager()->mkFloatingPointType(8, 24));
265 defineType("Float64", getExprManager()->mkFloatingPointType(11, 53));
266 defineType("Float128", getExprManager()->mkFloatingPointType(15, 113));
267 addFloatingPointOperators();
275 std::stringstream ss
;
276 ss
<< "internal error: unsupported theory " << theory
;
277 throw ParserException(ss
.str());
281 void Smt2::addOperator(Kind kind
, const std::string
& name
) {
282 Debug("parser") << "Smt2::addOperator( " << kind
<< ", " << name
<< " )"
284 Parser::addOperator(kind
);
285 operatorKindMap
[name
] = kind
;
288 Kind
Smt2::getOperatorKind(const std::string
& name
) const {
289 // precondition: isOperatorEnabled(name)
290 return operatorKindMap
.find(name
)->second
;
293 bool Smt2::isOperatorEnabled(const std::string
& name
) const {
294 return operatorKindMap
.find(name
) != operatorKindMap
.end();
297 bool Smt2::isTheoryEnabled(Theory theory
) const {
300 return d_logic
.isTheoryEnabled(theory::THEORY_ARRAY
);
301 case THEORY_BITVECTORS
:
302 return d_logic
.isTheoryEnabled(theory::THEORY_BV
);
305 case THEORY_DATATYPES
:
306 return d_logic
.isTheoryEnabled(theory::THEORY_DATATYPES
);
308 return d_logic
.isTheoryEnabled(theory::THEORY_ARITH
) &&
309 d_logic
.areIntegersUsed() && ( !d_logic
.areRealsUsed() );
311 return d_logic
.isTheoryEnabled(theory::THEORY_ARITH
) &&
312 ( !d_logic
.areIntegersUsed() ) && d_logic
.areRealsUsed();
313 case THEORY_REALS_INTS
:
314 return d_logic
.isTheoryEnabled(theory::THEORY_ARITH
) &&
315 d_logic
.areIntegersUsed() && d_logic
.areRealsUsed();
316 case THEORY_QUANTIFIERS
:
317 return d_logic
.isQuantified();
319 return d_logic
.isTheoryEnabled(theory::THEORY_SETS
);
321 return d_logic
.isTheoryEnabled(theory::THEORY_STRINGS
);
323 return d_logic
.isTheoryEnabled(theory::THEORY_UF
);
325 return d_logic
.isTheoryEnabled(theory::THEORY_FP
);
327 return d_logic
.isTheoryEnabled(theory::THEORY_SEP
);
329 std::stringstream ss
;
330 ss
<< "internal error: unsupported theory " << theory
;
331 throw ParserException(ss
.str());
335 bool Smt2::logicIsSet() {
339 Expr
Smt2::getExpressionForNameAndType(const std::string
& name
, Type t
) {
340 if(sygus() && name
[0]=='-' &&
341 name
.find_first_not_of("0123456789", 1) == std::string::npos
) {
342 //allow unary minus in sygus
343 return getExprManager()->mkConst(Rational(name
));
344 }else if(isAbstractValue(name
)) {
345 return mkAbstractValue(name
);
347 return Parser::getExpressionForNameAndType(name
, t
);
353 d_logic
= LogicInfo();
354 operatorKindMap
.clear();
355 d_lastNamedTerm
= std::pair
<Expr
, std::string
>();
356 this->Parser::reset();
358 if( !strictModeEnabled() ) {
359 addTheory(Smt2::THEORY_CORE
);
363 void Smt2::resetAssertions() {
364 this->Parser::reset();
367 void Smt2::setLogic(std::string name
) {
370 // non-smt2-standard sygus logic names go here (http://sygus.seas.upenn.edu/files/sygus.pdf Section 3.2)
371 if(name
== "Arrays") {
373 }else if(name
== "Reals") {
379 if(logicIsForced()) {
380 d_logic
= getForcedLogic();
385 // if sygus is enabled, we must enable UF, datatypes and integer arithmetic
387 // get unlocked copy, modify, copy and relock
388 LogicInfo
log(d_logic
.getUnlockedCopy());
389 log
.enableTheory(theory::THEORY_UF
);
390 log
.enableTheory(theory::THEORY_DATATYPES
);
391 log
.enableIntegers();
396 // Core theory belongs to every logic
397 addTheory(THEORY_CORE
);
399 if(d_logic
.isTheoryEnabled(theory::THEORY_UF
)) {
400 addTheory(THEORY_UF
);
403 if(d_logic
.isTheoryEnabled(theory::THEORY_ARITH
)) {
404 if(d_logic
.areIntegersUsed()) {
405 if(d_logic
.areRealsUsed()) {
406 addTheory(THEORY_REALS_INTS
);
408 addTheory(THEORY_INTS
);
410 } else if(d_logic
.areRealsUsed()) {
411 addTheory(THEORY_REALS
);
415 if(d_logic
.isTheoryEnabled(theory::THEORY_ARRAY
)) {
416 addTheory(THEORY_ARRAYS
);
419 if(d_logic
.isTheoryEnabled(theory::THEORY_BV
)) {
420 addTheory(THEORY_BITVECTORS
);
423 if(d_logic
.isTheoryEnabled(theory::THEORY_DATATYPES
)) {
424 addTheory(THEORY_DATATYPES
);
427 if(d_logic
.isTheoryEnabled(theory::THEORY_SETS
)) {
428 addTheory(THEORY_SETS
);
431 if(d_logic
.isTheoryEnabled(theory::THEORY_STRINGS
)) {
432 addTheory(THEORY_STRINGS
);
435 if(d_logic
.isQuantified()) {
436 addTheory(THEORY_QUANTIFIERS
);
439 if (d_logic
.isTheoryEnabled(theory::THEORY_FP
)) {
440 addTheory(THEORY_FP
);
443 if (d_logic
.isTheoryEnabled(theory::THEORY_SEP
)) {
444 addTheory(THEORY_SEP
);
447 }/* Smt2::setLogic() */
449 void Smt2::setInfo(const std::string
& flag
, const SExpr
& sexpr
) {
453 void Smt2::setOption(const std::string
& flag
, const SExpr
& sexpr
) {
457 void Smt2::checkThatLogicIsSet() {
458 if( ! logicIsSet() ) {
459 if(strictModeEnabled()) {
460 parseError("set-logic must appear before this point.");
462 warning("No set-logic command was given before this point.");
463 warning("CVC4 will make all theories available.");
464 warning("Consider setting a stricter logic for (likely) better performance.");
465 warning("To suppress this warning in the future use (set-logic ALL).");
469 Command
* c
= new SetBenchmarkLogicCommand("ALL");
476 /* The include are managed in the lexer but called in the parser */
477 // Inspired by http://www.antlr3.org/api/C/interop.html
479 static bool newInputStream(const std::string
& filename
, pANTLR3_LEXER lexer
) {
480 Debug("parser") << "Including " << filename
<< std::endl
;
481 // Create a new input stream and take advantage of built in stream stacking
482 // in C target runtime.
484 pANTLR3_INPUT_STREAM in
;
485 #ifdef CVC4_ANTLR3_OLD_INPUT_STREAM
486 in
= antlr3AsciiFileStreamNew((pANTLR3_UINT8
) filename
.c_str());
487 #else /* CVC4_ANTLR3_OLD_INPUT_STREAM */
488 in
= antlr3FileStreamNew((pANTLR3_UINT8
) filename
.c_str(), ANTLR3_ENC_8BIT
);
489 #endif /* CVC4_ANTLR3_OLD_INPUT_STREAM */
491 Debug("parser") << "Can't open " << filename
<< std::endl
;
494 // Same thing as the predefined PUSHSTREAM(in);
495 lexer
->pushCharStream(lexer
, in
);
497 //lexer->rec->state->tokenStartCharIndex = -10;
498 //lexer->emit(lexer);
500 // Note that the input stream is not closed when it EOFs, I don't bother
501 // to do it here, but it is up to you to track streams created like this
502 // and destroy them when the whole parse session is complete. Remember that you
503 // don't want to do this until all tokens have been manipulated all the way through
504 // your tree parsers etc as the token does not store the text it just refers
505 // back to the input stream and trying to get the text for it will abort if you
506 // close the input stream too early.
508 //TODO what said before
512 void Smt2::includeFile(const std::string
& filename
) {
513 // security for online version
514 if(!canIncludeFile()) {
515 parseError("include-file feature was disabled for this run.");
519 AntlrInput
* ai
= static_cast<AntlrInput
*>(getInput());
520 pANTLR3_LEXER lexer
= ai
->getAntlr3Lexer();
521 // get the name of the current stream "Does it work inside an include?"
522 const std::string inputName
= ai
->getInputStreamName();
524 // Find the directory of the current input file
526 size_t pos
= inputName
.rfind('/');
527 if(pos
!= std::string::npos
) {
528 path
= std::string(inputName
, 0, pos
+ 1);
530 path
.append(filename
);
531 if(!newInputStream(path
, lexer
)) {
532 parseError("Couldn't open include file `" + path
+ "'");
536 Expr
Smt2::mkSygusVar(const std::string
& name
, const Type
& type
, bool isPrimed
) {
537 Expr e
= mkBoundVar(name
, type
);
538 d_sygusVars
.push_back(e
);
539 d_sygusVarPrimed
[e
] = false;
541 std::stringstream ss
;
543 Expr ep
= mkBoundVar(ss
.str(), type
);
544 d_sygusVars
.push_back(ep
);
545 d_sygusVarPrimed
[ep
] = true;
550 void Smt2::mkSygusConstantsForType( const Type
& type
, std::vector
<CVC4::Expr
>& ops
) {
551 if( type
.isInteger() ){
552 ops
.push_back(getExprManager()->mkConst(Rational(0)));
553 ops
.push_back(getExprManager()->mkConst(Rational(1)));
554 }else if( type
.isBitVector() ){
555 unsigned sz
= ((BitVectorType
)type
).getSize();
556 BitVector
bval0(sz
, (unsigned int)0);
557 ops
.push_back( getExprManager()->mkConst(bval0
) );
558 BitVector
bval1(sz
, (unsigned int)1);
559 ops
.push_back( getExprManager()->mkConst(bval1
) );
560 }else if( type
.isBoolean() ){
561 ops
.push_back(getExprManager()->mkConst(true));
562 ops
.push_back(getExprManager()->mkConst(false));
567 // 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)
568 // This method may also add new elements pairwise into datatypes/sorts/ops/cnames/cargs in the case of non-flat gterms.
569 void Smt2::processSygusGTerm( CVC4::SygusGTerm
& sgt
, int index
,
570 std::vector
< CVC4::Datatype
>& datatypes
,
571 std::vector
< CVC4::Type
>& sorts
,
572 std::vector
< std::vector
<CVC4::Expr
> >& ops
,
573 std::vector
< std::vector
<std::string
> >& cnames
,
574 std::vector
< std::vector
< std::vector
< CVC4::Type
> > >& cargs
,
575 std::vector
< bool >& allow_const
,
576 std::vector
< std::vector
< std::string
> >& unresolved_gterm_sym
,
577 std::vector
<CVC4::Expr
>& sygus_vars
,
578 std::map
< CVC4::Type
, CVC4::Type
>& sygus_to_builtin
, std::map
< CVC4::Type
, CVC4::Expr
>& sygus_to_builtin_expr
,
579 CVC4::Type
& ret
, bool isNested
){
580 if( sgt
.d_gterm_type
==SygusGTerm::gterm_op
|| sgt
.d_gterm_type
==SygusGTerm::gterm_let
){
581 Debug("parser-sygus") << "Add " << sgt
.d_expr
<< " to datatype " << index
<< std::endl
;
583 Kind newKind
= kind::UNDEFINED_KIND
;
584 //convert to UMINUS if one child of MINUS
585 if( sgt
.d_children
.size()==1 && sgt
.d_expr
==getExprManager()->operatorOf(kind::MINUS
) ){
586 oldKind
= kind::MINUS
;
587 newKind
= kind::UMINUS
;
590 //convert to IFF if boolean EQUAL
591 if( sgt.d_expr==getExprManager()->operatorOf(kind::EQUAL) ){
592 Type ctn = sgt.d_children[0].d_type;
593 std::map< CVC4::Type, CVC4::Type >::iterator it = sygus_to_builtin.find( ctn );
594 if( it != sygus_to_builtin.end() && it->second.isBoolean() ){
595 oldKind = kind::EQUAL;
600 if( newKind
!=kind::UNDEFINED_KIND
){
601 Expr newExpr
= getExprManager()->operatorOf(newKind
);
602 Debug("parser-sygus") << "Replace " << sgt
.d_expr
<< " with " << newExpr
<< std::endl
;
603 sgt
.d_expr
= newExpr
;
604 std::string oldName
= kind::kindToString(oldKind
);
605 std::string newName
= kind::kindToString(newKind
);
607 if((pos
= sgt
.d_name
.find(oldName
, pos
)) != std::string::npos
){
608 sgt
.d_name
.replace(pos
, oldName
.length(), newName
);
611 ops
[index
].push_back( sgt
.d_expr
);
612 cnames
[index
].push_back( sgt
.d_name
);
613 cargs
[index
].push_back( std::vector
< CVC4::Type
>() );
614 for( unsigned i
=0; i
<sgt
.d_children
.size(); i
++ ){
615 std::stringstream ss
;
616 ss
<< datatypes
[index
].getName() << "_" << ops
[index
].size() << "_arg_" << i
;
617 std::string sub_dname
= ss
.str();
618 //add datatype for child
620 pushSygusDatatypeDef( null_type
, sub_dname
, datatypes
, sorts
, ops
, cnames
, cargs
, allow_const
, unresolved_gterm_sym
);
621 int sub_dt_index
= datatypes
.size()-1;
624 processSygusGTerm( sgt
.d_children
[i
], sub_dt_index
, datatypes
, sorts
, ops
, cnames
, cargs
, allow_const
, unresolved_gterm_sym
,
625 sygus_vars
, sygus_to_builtin
, sygus_to_builtin_expr
, sub_ret
, true );
626 //process the nested gterm (either pop the last datatype, or flatten the argument)
627 Type tt
= processSygusNestedGTerm( sub_dt_index
, sub_dname
, datatypes
, sorts
, ops
, cnames
, cargs
, allow_const
, unresolved_gterm_sym
,
628 sygus_to_builtin
, sygus_to_builtin_expr
, sub_ret
);
629 cargs
[index
].back().push_back(tt
);
631 //if let, must create operator
632 if( sgt
.d_gterm_type
==SygusGTerm::gterm_let
){
633 processSygusLetConstructor( sgt
.d_let_vars
, index
, datatypes
, sorts
, ops
, cnames
, cargs
,
634 sygus_vars
, sygus_to_builtin
, sygus_to_builtin_expr
);
636 }else if( sgt
.d_gterm_type
==SygusGTerm::gterm_constant
){
637 if( sgt
.getNumChildren()!=0 ){
638 parseError("Bad syntax for Sygus Constant.");
640 std::vector
< Expr
> consts
;
641 mkSygusConstantsForType( sgt
.d_type
, consts
);
642 Debug("parser-sygus") << "...made " << consts
.size() << " constants." << std::endl
;
643 for( unsigned i
=0; i
<consts
.size(); i
++ ){
644 std::stringstream ss
;
646 Debug("parser-sygus") << "...add for constant " << ss
.str() << std::endl
;
647 ops
[index
].push_back( consts
[i
] );
648 cnames
[index
].push_back( ss
.str() );
649 cargs
[index
].push_back( std::vector
< CVC4::Type
>() );
651 allow_const
[index
] = true;
652 }else if( sgt
.d_gterm_type
==SygusGTerm::gterm_variable
|| sgt
.d_gterm_type
==SygusGTerm::gterm_input_variable
){
653 if( sgt
.getNumChildren()!=0 ){
654 parseError("Bad syntax for Sygus Variable.");
656 Debug("parser-sygus") << "...process " << sygus_vars
.size() << " variables." << std::endl
;
657 for( unsigned i
=0; i
<sygus_vars
.size(); i
++ ){
658 if( sygus_vars
[i
].getType()==sgt
.d_type
){
659 std::stringstream ss
;
661 Debug("parser-sygus") << "...add for variable " << ss
.str() << std::endl
;
662 ops
[index
].push_back( sygus_vars
[i
] );
663 cnames
[index
].push_back( ss
.str() );
664 cargs
[index
].push_back( std::vector
< CVC4::Type
>() );
667 }else if( sgt
.d_gterm_type
==SygusGTerm::gterm_nested_sort
){
669 }else if( sgt
.d_gterm_type
==SygusGTerm::gterm_unresolved
){
671 if( isUnresolvedType(sgt
.d_name
) ){
672 ret
= getSort(sgt
.d_name
);
674 //nested, unresolved symbol...fail
675 std::stringstream ss
;
676 ss
<< "Cannot handle nested unresolved symbol " << sgt
.d_name
<< std::endl
;
677 parseError(ss
.str());
680 //will resolve when adding constructors
681 unresolved_gterm_sym
[index
].push_back(sgt
.d_name
);
683 }else if( sgt
.d_gterm_type
==SygusGTerm::gterm_ignore
){
688 bool Smt2::pushSygusDatatypeDef( Type t
, std::string
& dname
,
689 std::vector
< CVC4::Datatype
>& datatypes
,
690 std::vector
< CVC4::Type
>& sorts
,
691 std::vector
< std::vector
<CVC4::Expr
> >& ops
,
692 std::vector
< std::vector
<std::string
> >& cnames
,
693 std::vector
< std::vector
< std::vector
< CVC4::Type
> > >& cargs
,
694 std::vector
< bool >& allow_const
,
695 std::vector
< std::vector
< std::string
> >& unresolved_gterm_sym
){
697 datatypes
.push_back(Datatype(dname
));
698 ops
.push_back(std::vector
<Expr
>());
699 cnames
.push_back(std::vector
<std::string
>());
700 cargs
.push_back(std::vector
<std::vector
<CVC4::Type
> >());
701 allow_const
.push_back(false);
702 unresolved_gterm_sym
.push_back(std::vector
< std::string
>());
706 bool Smt2::popSygusDatatypeDef( std::vector
< CVC4::Datatype
>& datatypes
,
707 std::vector
< CVC4::Type
>& sorts
,
708 std::vector
< std::vector
<CVC4::Expr
> >& ops
,
709 std::vector
< std::vector
<std::string
> >& cnames
,
710 std::vector
< std::vector
< std::vector
< CVC4::Type
> > >& cargs
,
711 std::vector
< bool >& allow_const
,
712 std::vector
< std::vector
< std::string
> >& unresolved_gterm_sym
){
714 datatypes
.pop_back();
718 allow_const
.pop_back();
719 unresolved_gterm_sym
.pop_back();
723 Type
Smt2::processSygusNestedGTerm( int sub_dt_index
, std::string
& sub_dname
, std::vector
< CVC4::Datatype
>& datatypes
,
724 std::vector
< CVC4::Type
>& sorts
,
725 std::vector
< std::vector
<CVC4::Expr
> >& ops
,
726 std::vector
< std::vector
<std::string
> >& cnames
,
727 std::vector
< std::vector
< std::vector
< CVC4::Type
> > >& cargs
,
728 std::vector
< bool >& allow_const
,
729 std::vector
< std::vector
< std::string
> >& unresolved_gterm_sym
,
730 std::map
< CVC4::Type
, CVC4::Type
>& sygus_to_builtin
,
731 std::map
< CVC4::Type
, CVC4::Expr
>& sygus_to_builtin_expr
, Type sub_ret
) {
733 Debug("parser-sygus") << "Argument is ";
735 //then, it is the datatype we constructed, which should have a single constructor
736 t
= mkUnresolvedType(sub_dname
);
737 Debug("parser-sygus") << "inline flattening of (auxiliary, local) datatype " << t
<< std::endl
;
738 Debug("parser-sygus") << ": to compute type, construct ground term witnessing the grammar, #cons=" << cargs
[sub_dt_index
].size() << std::endl
;
739 if( cargs
[sub_dt_index
].empty() ){
740 parseError(std::string("Internal error : datatype for nested gterm does not have a constructor."));
742 Expr sop
= ops
[sub_dt_index
][0];
744 if( sop
.getKind() != kind::BUILTIN
&& ( sop
.isConst() || cargs
[sub_dt_index
][0].empty() ) ){
745 curr_t
= sop
.getType();
746 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
;
747 sygus_to_builtin_expr
[t
] = sop
;
748 //store that term sop has dedicated sygus type t
749 if( d_sygus_bound_var_type
.find( sop
)==d_sygus_bound_var_type
.end() ){
750 d_sygus_bound_var_type
[sop
] = t
;
753 std::vector
< Expr
> children
;
754 if( sop
.getKind() != kind::BUILTIN
){
755 children
.push_back( sop
);
757 for( unsigned i
=0; i
<cargs
[sub_dt_index
][0].size(); i
++ ){
758 std::map
< CVC4::Type
, CVC4::Expr
>::iterator it
= sygus_to_builtin_expr
.find( cargs
[sub_dt_index
][0][i
] );
759 if( it
==sygus_to_builtin_expr
.end() ){
760 if( sygus_to_builtin
.find( cargs
[sub_dt_index
][0][i
] )==sygus_to_builtin
.end() ){
761 std::stringstream ss
;
762 ss
<< "Missing builtin type for type " << cargs
[sub_dt_index
][0][i
] << "!" << std::endl
;
763 ss
<< "Builtin types are currently : " << std::endl
;
764 for( std::map
< CVC4::Type
, CVC4::Type
>::iterator itb
= sygus_to_builtin
.begin(); itb
!= sygus_to_builtin
.end(); ++itb
){
765 ss
<< " " << itb
->first
<< " -> " << itb
->second
<< std::endl
;
767 parseError(ss
.str());
769 Type bt
= sygus_to_builtin
[cargs
[sub_dt_index
][0][i
]];
770 Debug("parser-sygus") << ": child " << i
<< " introduce type elem for " << cargs
[sub_dt_index
][0][i
] << " " << bt
<< std::endl
;
771 std::stringstream ss
;
772 ss
<< t
<< "_x_" << i
;
773 Expr bv
= mkBoundVar(ss
.str(), bt
);
774 children
.push_back( bv
);
775 d_sygus_bound_var_type
[bv
] = cargs
[sub_dt_index
][0][i
];
777 Debug("parser-sygus") << ": child " << i
<< " existing sygus to builtin expr : " << it
->second
<< std::endl
;
778 children
.push_back( it
->second
);
781 Kind sk
= sop
.getKind() != kind::BUILTIN
? kind::APPLY
: getExprManager()->operatorToKind(sop
);
782 Debug("parser-sygus") << ": operator " << sop
<< " with " << sop
.getKind() << " " << sk
<< std::endl
;
783 Expr e
= getExprManager()->mkExpr( sk
, children
);
784 Debug("parser-sygus") << ": constructed " << e
<< ", which has type " << e
.getType() << std::endl
;
785 curr_t
= e
.getType();
786 sygus_to_builtin_expr
[t
] = e
;
788 sorts
[sub_dt_index
] = curr_t
;
789 sygus_to_builtin
[t
] = curr_t
;
791 Debug("parser-sygus") << "simple argument " << t
<< std::endl
;
792 Debug("parser-sygus") << "...removing " << datatypes
.back().getName() << std::endl
;
793 //otherwise, datatype was unecessary
794 //pop argument datatype definition
795 popSygusDatatypeDef( datatypes
, sorts
, ops
, cnames
, cargs
, allow_const
, unresolved_gterm_sym
);
800 void Smt2::processSygusLetConstructor( std::vector
< CVC4::Expr
>& let_vars
,
802 std::vector
< CVC4::Datatype
>& datatypes
,
803 std::vector
< CVC4::Type
>& sorts
,
804 std::vector
< std::vector
<CVC4::Expr
> >& ops
,
805 std::vector
< std::vector
<std::string
> >& cnames
,
806 std::vector
< std::vector
< std::vector
< CVC4::Type
> > >& cargs
,
807 std::vector
<CVC4::Expr
>& sygus_vars
,
808 std::map
< CVC4::Type
, CVC4::Type
>& sygus_to_builtin
,
809 std::map
< CVC4::Type
, CVC4::Expr
>& sygus_to_builtin_expr
) {
810 std::vector
< CVC4::Expr
> let_define_args
;
812 int dindex
= cargs
[index
].size()-1;
813 Debug("parser-sygus") << "Process let constructor for datatype " << datatypes
[index
].getName() << ", #subtypes = " << cargs
[index
][dindex
].size() << std::endl
;
814 for( unsigned i
=0; i
<cargs
[index
][dindex
].size(); i
++ ){
815 Debug("parser-sygus") << " " << i
<< " : " << cargs
[index
][dindex
][i
] << std::endl
;
816 if( i
+1==cargs
[index
][dindex
].size() ){
817 std::map
< CVC4::Type
, CVC4::Expr
>::iterator it
= sygus_to_builtin_expr
.find( cargs
[index
][dindex
][i
] );
818 if( it
!=sygus_to_builtin_expr
.end() ){
819 let_body
= it
->second
;
821 std::stringstream ss
;
822 ss
<< datatypes
[index
].getName() << "_body";
823 let_body
= mkBoundVar(ss
.str(), sygus_to_builtin
[cargs
[index
][dindex
][i
]]);
824 d_sygus_bound_var_type
[let_body
] = cargs
[index
][dindex
][i
];
828 Debug("parser-sygus") << std::endl
;
829 Debug("parser-sygus") << "Body is " << let_body
<< std::endl
;
830 Debug("parser-sygus") << "# let vars = " << let_vars
.size() << std::endl
;
831 for( unsigned i
=0; i
<let_vars
.size(); i
++ ){
832 Debug("parser-sygus") << " let var " << i
<< " : " << let_vars
[i
] << " " << let_vars
[i
].getType() << std::endl
;
833 let_define_args
.push_back( let_vars
[i
] );
836 Debug("parser-sygus") << "index = " << index << ", start index = " << start_index << ", #Current datatypes = " << datatypes.size() << std::endl;
837 for( unsigned i=start_index; i<datatypes.size(); i++ ){
838 Debug("parser-sygus") << " datatype " << i << " : " << datatypes[i].getName() << ", #cons = " << cargs[i].size() << std::endl;
839 if( !cargs[i].empty() ){
840 Debug("parser-sygus") << " operator 0 is " << ops[i][0] << std::endl;
841 Debug("parser-sygus") << " cons 0 has " << cargs[i][0].size() << " sub fields." << std::endl;
842 for( unsigned j=0; j<cargs[i][0].size(); j++ ){
843 Type bt = sygus_to_builtin[cargs[i][0][j]];
844 Debug("parser-sygus") << " cons 0, selector " << j << " : " << cargs[i][0][j] << " " << bt << std::endl;
849 //last argument is the return, pop
850 cargs
[index
][dindex
].pop_back();
851 collectSygusLetArgs( let_body
, cargs
[index
][dindex
], let_define_args
);
853 Debug("parser-sygus") << "Make define-fun with " << cargs
[index
][dindex
].size() << " arguments..." << std::endl
;
854 std::vector
<CVC4::Type
> fsorts
;
855 for( unsigned i
=0; i
<cargs
[index
][dindex
].size(); i
++ ){
856 Debug("parser-sygus") << " " << i
<< " : " << let_define_args
[i
] << " " << let_define_args
[i
].getType() << " " << cargs
[index
][dindex
][i
] << std::endl
;
857 fsorts
.push_back(let_define_args
[i
].getType());
860 Type ft
= getExprManager()->mkFunctionType(fsorts
, let_body
.getType());
861 std::stringstream ss
;
862 ss
<< datatypes
[index
].getName() << "_let";
863 Expr let_func
= mkFunction(ss
.str(), ft
, ExprManager::VAR_FLAG_DEFINED
);
864 d_sygus_defined_funs
.push_back( let_func
);
865 preemptCommand( new DefineFunctionCommand(ss
.str(), let_func
, let_define_args
, let_body
) );
867 ops
[index
].pop_back();
868 ops
[index
].push_back( let_func
);
869 cnames
[index
].pop_back();
870 cnames
[index
].push_back(ss
.str());
872 //mark function as let constructor
873 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() );
874 d_sygus_let_func_to_body
[let_func
] = let_body
;
875 d_sygus_let_func_to_num_input_vars
[let_func
] = let_vars
.size();
879 void Smt2::collectSygusLetArgs( CVC4::Expr e
, std::vector
< CVC4::Type
>& sygusArgs
, std::vector
< CVC4::Expr
>& builtinArgs
) {
880 if( e
.getKind()==kind::BOUND_VARIABLE
){
881 if( std::find( builtinArgs
.begin(), builtinArgs
.end(), e
)==builtinArgs
.end() ){
882 builtinArgs
.push_back( e
);
883 sygusArgs
.push_back( d_sygus_bound_var_type
[e
] );
884 if( d_sygus_bound_var_type
[e
].isNull() ){
885 std::stringstream ss
;
886 ss
<< "While constructing body of let gterm, can't map " << e
<< " to sygus type." << std::endl
;
887 parseError(ss
.str());
891 for( unsigned i
=0; i
<e
.getNumChildren(); i
++ ){
892 collectSygusLetArgs( e
[i
], sygusArgs
, builtinArgs
);
897 void Smt2::setSygusStartIndex( std::string
& fun
, int startIndex
,
898 std::vector
< CVC4::Datatype
>& datatypes
,
899 std::vector
< CVC4::Type
>& sorts
,
900 std::vector
< std::vector
<CVC4::Expr
> >& ops
) {
902 CVC4::Datatype tmp_dt
= datatypes
[0];
903 Type tmp_sort
= sorts
[0];
904 std::vector
< Expr
> tmp_ops
;
905 tmp_ops
.insert( tmp_ops
.end(), ops
[0].begin(), ops
[0].end() );
906 datatypes
[0] = datatypes
[startIndex
];
907 sorts
[0] = sorts
[startIndex
];
909 ops
[0].insert( ops
[0].end(), ops
[startIndex
].begin(), ops
[startIndex
].end() );
910 datatypes
[startIndex
] = tmp_dt
;
911 sorts
[startIndex
] = tmp_sort
;
912 ops
[startIndex
].clear();
913 ops
[startIndex
].insert( ops
[startIndex
].begin(), tmp_ops
.begin(), tmp_ops
.end() );
914 }else if( startIndex
<0 ){
915 std::stringstream ss
;
916 ss
<< "warning: no symbol named Start for synth-fun " << fun
<< std::endl
;
921 void Smt2::mkSygusDatatype( CVC4::Datatype
& dt
, std::vector
<CVC4::Expr
>& ops
,
922 std::vector
<std::string
>& cnames
, std::vector
< std::vector
< CVC4::Type
> >& cargs
,
923 std::vector
<std::string
>& unresolved_gterm_sym
,
924 std::map
< CVC4::Type
, CVC4::Type
>& sygus_to_builtin
) {
925 Debug("parser-sygus") << "Making sygus datatype " << dt
.getName() << std::endl
;
926 Debug("parser-sygus") << " add constructors..." << std::endl
;
927 std::vector
<std::string
> df_name
;
928 std::vector
<CVC4::Expr
> df_op
;
929 std::vector
< std::vector
<Expr
> > df_let_args
;
930 std::vector
< Expr
> df_let_body
;
931 //dt.mkSygusConstructors( ops, cnames, cargs, sygus_to_builtin,
932 // d_sygus_let_func_to_vars, d_sygus_let_func_to_body, d_sygus_let_func_to_num_input_vars,
933 // df_name, df_op, df_let_args, df_let_body );
935 Debug("parser-sygus") << "SMT2 sygus parser : Making constructors for sygus datatype " << dt
.getName() << std::endl
;
936 Debug("parser-sygus") << " add constructors..." << std::endl
;
937 for( int i
=0; i
<(int)cnames
.size(); i
++ ){
939 bool is_dup_op
= false;
941 std::vector
< Expr
> let_args
;
942 unsigned let_num_input_args
= 0;
943 for( int j
=0; j
<i
; j
++ ){
944 if( ops
[i
]==ops
[j
] ){
946 if( cargs
[i
].size()==cargs
[j
].size() ){
948 for( unsigned k
=0; k
<cargs
[i
].size(); k
++ ){
949 if( cargs
[i
][k
]!=cargs
[j
][k
] ){
961 Debug("parser-sygus") << "--> Duplicate gterm : " << ops
[i
] << " at " << i
<< std::endl
;
962 ops
.erase( ops
.begin() + i
, ops
.begin() + i
+ 1 );
963 cnames
.erase( cnames
.begin() + i
, cnames
.begin() + i
+ 1 );
964 cargs
.erase( cargs
.begin() + i
, cargs
.begin() + i
+ 1 );
966 }else if( is_dup_op
){
967 Debug("parser-sygus") << "--> Duplicate gterm operator : " << ops
[i
] << " at " << i
<< std::endl
;
968 //make into define-fun
969 std::vector
<CVC4::Type
> fsorts
;
970 for( unsigned j
=0; j
<cargs
[i
].size(); j
++ ){
971 Type bt
= sygus_to_builtin
[cargs
[i
][j
]];
972 std::stringstream ss
;
973 ss
<< dt
.getName() << "_x_" << i
<< "_" << j
;
974 Expr v
= mkBoundVar(ss
.str(), bt
);
975 let_args
.push_back( v
);
976 fsorts
.push_back( bt
);
977 Debug("parser-sygus") << ": var " << i
<< " " << v
<< " with type " << bt
<< " from " << cargs
[i
][j
] << std::endl
;
980 std::vector
< Expr
> children
;
981 if( ops
[i
].getKind() != kind::BUILTIN
){
982 children
.push_back( ops
[i
] );
984 children
.insert( children
.end(), let_args
.begin(), let_args
.end() );
985 Kind sk
= ops
[i
].getKind() != kind::BUILTIN
? kind::APPLY
: getExprManager()->operatorToKind(ops
[i
]);
986 Debug("parser-sygus") << ": replace " << ops
[i
] << " " << ops
[i
].getKind() << " " << sk
<< std::endl
;
987 let_body
= getExprManager()->mkExpr( sk
, children
);
988 Debug("parser-sygus") << ": new body of function is " << let_body
<< std::endl
;
990 Type ft
= getExprManager()->mkFunctionType(fsorts
, let_body
.getType());
991 Debug("parser-sygus") << ": function type is " << ft
<< std::endl
;
992 std::stringstream ss
;
993 ss
<< dt
.getName() << "_df_" << i
;
994 //replace operator and name
995 ops
[i
] = mkFunction(ss
.str(), ft
, ExprManager::VAR_FLAG_DEFINED
);
996 cnames
[i
] = ss
.str();
997 // indicate we need a define function
998 df_name
.push_back( ss
.str() );
999 df_op
.push_back( ops
[i
] );
1000 df_let_args
.push_back( let_args
);
1001 df_let_body
.push_back( let_body
);
1003 //d_sygus_defined_funs.push_back( ops[i] );
1004 //preemptCommand( new DefineFunctionCommand(ss.str(), ops[i], let_args, let_body) );
1005 dt
.addSygusConstructor( ops
[i
], cnames
[i
], cargs
[i
], let_body
, let_args
, 0 );
1007 std::map
< CVC4::Expr
, CVC4::Expr
>::iterator it
= d_sygus_let_func_to_body
.find( ops
[i
] );
1008 if( it
!=d_sygus_let_func_to_body
.end() ){
1009 let_body
= it
->second
;
1010 let_args
.insert( let_args
.end(), d_sygus_let_func_to_vars
[ops
[i
]].begin(), d_sygus_let_func_to_vars
[ops
[i
]].end() );
1011 let_num_input_args
= d_sygus_let_func_to_num_input_vars
[ops
[i
]];
1013 dt
.addSygusConstructor( ops
[i
], cnames
[i
], cargs
[i
], let_body
, let_args
, let_num_input_args
);
1017 Debug("parser-sygus") << " add constructors for unresolved symbols..." << std::endl
;
1018 if( !unresolved_gterm_sym
.empty() ){
1019 std::vector
< Type
> types
;
1020 Debug("parser-sygus") << "...resolve " << unresolved_gterm_sym
.size() << " symbols..." << std::endl
;
1021 for( unsigned i
=0; i
<unresolved_gterm_sym
.size(); i
++ ){
1022 Debug("parser-sygus") << " resolve : " << unresolved_gterm_sym
[i
] << std::endl
;
1023 if( isUnresolvedType(unresolved_gterm_sym
[i
]) ){
1024 Debug("parser-sygus") << " it is an unresolved type." << std::endl
;
1025 Type t
= getSort(unresolved_gterm_sym
[i
]);
1026 if( std::find( types
.begin(), types
.end(), t
)==types
.end() ){
1027 types
.push_back( t
);
1029 Type bt
= dt
.getSygusType();
1030 Debug("parser-sygus") << ": make identity function for " << bt
<< ", argument type " << t
<< std::endl
;
1031 std::stringstream ss
;
1033 Expr let_body
= mkBoundVar(ss
.str(), bt
);
1034 std::vector
< Expr
> let_args
;
1035 let_args
.push_back( let_body
);
1036 //make the identity function
1037 Type ft
= getExprManager()->mkFunctionType(bt
, bt
);
1038 std::stringstream ssid
;
1039 ssid
<< unresolved_gterm_sym
[i
] << "_id";
1040 Expr id_op
= mkFunction(ss
.str(), ft
, ExprManager::VAR_FLAG_DEFINED
);
1041 // indicate we need a define function
1042 df_name
.push_back( ssid
.str() );
1043 df_op
.push_back( id_op
);
1044 df_let_args
.push_back( let_args
);
1045 df_let_body
.push_back( let_body
);
1047 //d_sygus_defined_funs.push_back( id_op );
1048 //preemptCommand( new DefineFunctionCommand(ssid.str(), id_op, let_args, let_body) );
1049 //make the sygus argument list
1050 std::vector
< Type
> id_carg
;
1051 id_carg
.push_back( t
);
1052 dt
.addSygusConstructor( id_op
, unresolved_gterm_sym
[i
], id_carg
, let_body
, let_args
, 0 );
1054 ops
.push_back( id_op
);
1057 Debug("parser-sygus") << " ignore. (likely a free let variable)" << std::endl
;
1063 for( unsigned i
=0; i
<df_name
.size(); i
++ ){
1064 d_sygus_defined_funs
.push_back( df_op
[i
] );
1065 preemptCommand( new DefineFunctionCommand(df_name
[i
], df_op
[i
], df_let_args
[i
], df_let_body
[i
]) );
1069 const void Smt2::getSygusPrimedVars( std::vector
<Expr
>& vars
, bool isPrimed
) {
1070 for( unsigned i
=0; i
<d_sygusVars
.size(); i
++ ){
1071 Expr v
= d_sygusVars
[i
];
1072 std::map
< Expr
, bool >::iterator it
= d_sygusVarPrimed
.find( v
);
1073 if( it
!=d_sygusVarPrimed
.end() ){
1074 if( it
->second
==isPrimed
){
1075 vars
.push_back( v
);
1078 //should never happen
1083 const void Smt2::addSygusFunSymbol( Type t
, Expr synth_fun
){
1084 //FIXME #1205 : we should not create a proxy, instead quantify on synth_fun and set Type t as an attribute
1085 Expr sym
= mkBoundVar("sfproxy", t
);
1086 d_sygusFunSymbols
.push_back(sym
);
1088 std::vector
< Expr
> attr_value
;
1089 attr_value
.push_back( synth_fun
);
1090 Command
* cattr
= new SetUserAttributeCommand("sygus-synth-fun", sym
, attr_value
);
1091 cattr
->setMuted(true);
1092 preemptCommand(cattr
);
1095 }/* CVC4::parser namespace */
1096 }/* CVC4 namespace */