1 /********************* */
2 /*! \file cvc_printer.cpp
4 ** Top contributors (to current version):
5 ** Morgan Deters, Dejan Jovanovic, Andrew Reynolds
6 ** This file is part of the CVC4 project.
7 ** Copyright (c) 2009-2016 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 The pretty-printer interface for the CVC output language
14 ** The pretty-printer interface for the CVC output language.
17 #include "printer/cvc/cvc_printer.h"
27 #include "expr/expr.h" // for ExprSetDepth etc..
28 #include "expr/node_manager_attributes.h" // for VarNameAttr
29 #include "options/language.h" // for LANG_AST
30 #include "printer/dagification_visitor.h"
31 #include "options/smt_options.h"
32 #include "smt/command.h"
33 #include "smt/smt_engine.h"
34 #include "smt_util/node_visitor.h"
35 #include "theory/arrays/theory_arrays_rewriter.h"
36 #include "theory/substitutions.h"
37 #include "theory/theory_model.h"
45 void CvcPrinter::toStream(std::ostream
& out
, TNode n
, int toDepth
, bool types
, size_t dag
) const throw() {
47 DagificationVisitor
dv(dag
);
48 NodeVisitor
<DagificationVisitor
> visitor
;
50 const theory::SubstitutionMap
& lets
= dv
.getLets();
54 for(theory::SubstitutionMap::const_iterator i
= lets
.begin();
62 toStream(out
, (*i
).second
, toDepth
, types
, false);
64 toStream(out
, (*i
).first
, toDepth
, types
, false);
68 Node body
= dv
.getDagifiedBody();
69 toStream(out
, body
, toDepth
, types
, false);
71 toStream(out
, n
, toDepth
, types
, false);
75 void CvcPrinter::toStream(std::ostream
& out
, TNode n
, int depth
, bool types
, bool bracket
) const throw() {
83 if(n
.getKind() == kind::NULL_EXPR
) {
91 if(n
.getAttribute(expr::VarNameAttr(), s
)) {
94 if(n
.getKind() == kind::VARIABLE
) {
97 out
<< n
.getKind() << '_';
102 // print the whole type, but not *its* type
104 n
.getType().toStream(out
, language::output::LANG_CVC4
);
110 if(n
.getMetaKind() == kind::metakind::CONSTANT
) {
111 switch(n
.getKind()) {
112 case kind::BITVECTOR_TYPE
:
113 out
<< "BITVECTOR(" << n
.getConst
<BitVectorSize
>().size
<< ")";
115 case kind::CONST_BITVECTOR
: {
116 const BitVector
& bv
= n
.getConst
<BitVector
>();
117 const Integer
& x
= bv
.getValue();
119 unsigned n
= bv
.getSize();
121 out
<< (x
.testBit(n
) ? '1' : '0');
125 case kind::CONST_BOOLEAN
:
126 // the default would print "1" or "0" for bool, that's not correct
128 out
<< (n
.getConst
<bool>() ? "TRUE" : "FALSE");
130 case kind::CONST_RATIONAL
: {
131 const Rational
& rat
= n
.getConst
<Rational
>();
132 if(rat
.isIntegral()) {
133 out
<< rat
.getNumerator();
135 out
<< '(' << rat
.getNumerator() << '/' << rat
.getDenominator() << ')';
139 case kind::SUBRANGE_TYPE
:
140 out
<< '[' << n
.getConst
<SubrangeBounds
>() << ']';
142 case kind::SUBTYPE_TYPE
:
143 out
<< "SUBTYPE(" << n
.getConst
<Predicate
>() << ")";
145 case kind::TYPE_CONSTANT
:
146 switch(TypeConstant tc
= n
.getConst
<TypeConstant
>()) {
165 case kind::DATATYPE_TYPE
: {
166 const Datatype
& dt
= n
.getConst
<Datatype
>();
169 for (unsigned i
= 0; i
< dt
[0].getNumArgs(); ++ i
) {
173 Type t
= ((SelectorType
)dt
[0][i
].getSelector().getType()).getRangeType();
177 }else if( dt
.isRecord() ){
179 for (unsigned i
= 0; i
< dt
[0].getNumArgs(); ++ i
) {
183 Type t
= ((SelectorType
)dt
[0][i
].getSelector().getType()).getRangeType();
184 out
<< dt
[0][i
].getSelector() << ":" << t
;
194 out
<< "{} :: " << n
.getConst
<EmptySet
>().getType();
197 case kind::STORE_ALL
: {
198 const ArrayStoreAll
& asa
= n
.getConst
<ArrayStoreAll
>();
199 out
<< "ARRAY(" << asa
.getType().getIndexType() << " OF "
200 << asa
.getType().getConstituentType() << ") : " << asa
.getExpr();
205 // Fall back to whatever operator<< does on underlying type; we
206 // might luck out and print something reasonable.
207 kind::metakind::NodeValueConstPrinter::toStream(out
, n
);
219 //The default operation type is PREFIX
222 stringstream op
; // operation (such as '+')
224 switch(n
.getKind()) {
233 toStream(out
, n
[0], depth
, types
, true);
235 toStream(out
, n
[1], depth
, types
, true);
237 toStream(out
, n
[2], depth
, types
, true);
241 case kind::SEXPR_TYPE
:
243 for (unsigned i
= 0; i
< n
.getNumChildren(); ++ i
) {
247 toStream(out
, n
[i
], depth
, types
, false);
257 toStream(out
, n
[0], depth
, types
, true);
259 toStream(out
, n
[1], depth
, types
, true);
264 toStream(op
, n
.getOperator(), depth
, types
, true);
267 case kind::DISTINCT
: // chain and distinct not supported directly in CVC4, blast them away with the rewriter
268 toStream(out
, theory::Rewriter::rewrite(n
), depth
, types
, true);
270 case kind::SORT_TYPE
:
273 if(n
.getAttribute(expr::VarNameAttr(), name
)) {
308 toStream(op
, n
.getOperator(), depth
, types
, false);
310 case kind::CARDINALITY_CONSTRAINT
:
311 case kind::COMBINED_CARDINALITY_CONSTRAINT
:
312 out
<< "CARDINALITY_CONSTRAINT";
315 case kind::FUNCTION_TYPE
:
316 if (n
.getNumChildren() > 1) {
317 if (n
.getNumChildren() > 2) {
320 for (unsigned i
= 1; i
< n
.getNumChildren(); ++i
) {
324 toStream(out
, n
[i
- 1], depth
, types
, false);
326 if (n
.getNumChildren() > 2) {
331 toStream(out
, n
[n
.getNumChildren() - 1], depth
, types
, false);
336 case kind::PARAMETRIC_DATATYPE
:
337 out
<< n
[0].getConst
<Datatype
>().getName() << '[';
338 for(unsigned i
= 1; i
< n
.getNumChildren(); ++i
) {
347 case kind::APPLY_TYPE_ASCRIPTION
: {
348 toStream(out
, n
[0], depth
, types
, false);
350 TypeNode t
= TypeNode::fromType(n
.getOperator().getConst
<AscriptionType
>().getType());
351 out
<< (t
.isFunctionLike() ? t
.getRangeType() : t
);
355 case kind::APPLY_CONSTRUCTOR
: {
356 TypeNode t
= n
.getType();
358 if( n
.getNumChildren()==1 ){
361 }else if( t
.isRecord() ){
362 const Record
& rec
= t
.getRecord();
364 TNode::iterator i
= n
.begin();
366 const Record::FieldVector
& fields
= rec
.getFields();
367 for(Record::FieldVector::const_iterator j
= fields
.begin(); j
!= fields
.end(); ++i
, ++j
) {
371 out
<< (*j
).first
<< " := ";
372 toStream(out
, *i
, depth
, types
, false);
378 toStream(op
, n
.getOperator(), depth
, types
, false);
382 case kind::APPLY_SELECTOR
:
383 case kind::APPLY_SELECTOR_TOTAL
: {
384 TypeNode t
= n
.getType();
386 toStream(out
, n
[0], depth
, types
, true);
387 out
<< '.' << Datatype::indexOf( n
.getOperator().toExpr() );
388 }else if( t
.isRecord() ){
389 toStream(out
, n
[0], depth
, types
, true);
390 const Record
& rec
= t
.getRecord();
391 unsigned index
= Datatype::indexOf( n
.getOperator().toExpr() );
392 std::pair
<std::string
, Type
> fld
= rec
[index
];
393 out
<< '.' << fld
.first
;
395 toStream(op
, n
.getOperator(), depth
, types
, false);
399 case kind::APPLY_TESTER
:
400 toStream(op
, n
.getOperator(), depth
, types
, false);
402 case kind::CONSTRUCTOR_TYPE
:
403 case kind::SELECTOR_TYPE
:
404 if(n
.getNumChildren() > 1) {
405 if(n
.getNumChildren() > 2) {
408 for(unsigned i
= 0; i
< n
.getNumChildren() - 1; ++i
) {
412 toStream(out
, n
[i
], depth
, types
, false);
414 if(n
.getNumChildren() > 2) {
419 toStream(out
, n
[n
.getNumChildren() - 1], depth
, types
, false);
421 case kind::TESTER_TYPE
:
422 toStream(out
, n
[0], depth
, types
, false);
423 out
<< " -> BOOLEAN";
426 case kind::TUPLE_UPDATE
:
427 toStream(out
, n
[0], depth
, types
, true);
428 out
<< " WITH ." << n
.getOperator().getConst
<TupleUpdate
>().getIndex() << " := ";
429 toStream(out
, n
[1], depth
, types
, true);
432 case kind::RECORD_UPDATE
:
433 toStream(out
, n
[0], depth
, types
, true);
434 out
<< " WITH ." << n
.getOperator().getConst
<RecordUpdate
>().getField() << " := ";
435 toStream(out
, n
[1], depth
, types
, true);
440 case kind::ARRAY_TYPE
:
442 toStream(out
, n
[0], depth
, types
, false);
444 toStream(out
, n
[1], depth
, types
, false);
448 toStream(out
, n
[0], depth
, types
, true);
450 toStream(out
, n
[1], depth
, types
, false);
457 while(stk
.top()[0].getKind() == kind::STORE
) {
458 stk
.push(stk
.top()[0]);
464 toStream(out
, x
[0], depth
, types
, false);
466 toStream(out
, x
[1], depth
, types
, false);
468 toStream(out
, x
[2], depth
, types
, false);
470 while(!stk
.empty()) {
473 toStream(out
, x
[1], depth
, types
, false);
475 toStream(out
, x
[2], depth
, types
, false);
506 case kind::INTS_DIVISION
:
510 case kind::INTS_MODULUS
:
538 case kind::IS_INTEGER
:
542 case kind::TO_INTEGER
:
547 // ignore, there is no to-real in CVC language
548 toStream(out
, n
[0], depth
, types
, false);
550 case kind::DIVISIBLE
:
552 toStream(out
, n
[0], depth
, types
, false);
553 out
<< ", " << n
.getOperator().getConst
<Divisible
>().k
<< ")";
557 case kind::BITVECTOR_XOR
:
560 case kind::BITVECTOR_NAND
:
563 case kind::BITVECTOR_NOR
:
566 case kind::BITVECTOR_XNOR
:
569 case kind::BITVECTOR_COMP
:
572 case kind::BITVECTOR_UDIV
:
575 case kind::BITVECTOR_UDIV_TOTAL
:
576 op
<< "BVUDIV_TOTAL";
578 case kind::BITVECTOR_UREM
:
581 case kind::BITVECTOR_UREM_TOTAL
:
582 op
<< "BVUREM_TOTAL";
584 case kind::BITVECTOR_SDIV
:
587 case kind::BITVECTOR_SREM
:
590 case kind::BITVECTOR_SMOD
:
593 case kind::BITVECTOR_SHL
:
596 case kind::BITVECTOR_LSHR
:
599 case kind::BITVECTOR_ASHR
:
602 case kind::BITVECTOR_ULT
:
605 case kind::BITVECTOR_ULE
:
608 case kind::BITVECTOR_UGT
:
611 case kind::BITVECTOR_UGE
:
614 case kind::BITVECTOR_SLT
:
617 case kind::BITVECTOR_SLE
:
620 case kind::BITVECTOR_SGT
:
623 case kind::BITVECTOR_SGE
:
626 case kind::BITVECTOR_NEG
:
629 case kind::BITVECTOR_NOT
:
632 case kind::BITVECTOR_AND
:
636 case kind::BITVECTOR_OR
:
640 case kind::BITVECTOR_CONCAT
:
644 case kind::BITVECTOR_PLUS
: {
645 // This interprets a BITVECTOR_PLUS as a bvadd in SMT-LIB
646 Assert(n
.getType().isBitVector());
647 unsigned numc
= n
.getNumChildren()-2;
649 while (child
< numc
) {
651 out
<< BitVectorType(n
.getType().toType()).getSize();
653 toStream(out
, n
[child
], depth
, types
, false);
658 out
<< BitVectorType(n
.getType().toType()).getSize();
660 toStream(out
, n
[child
], depth
, types
, false);
662 toStream(out
, n
[child
+ 1], depth
, types
, false);
671 case kind::BITVECTOR_SUB
:
673 Assert(n
.getType().isBitVector());
674 out
<< BitVectorType(n
.getType().toType()).getSize();
676 toStream(out
, n
[0], depth
, types
, false);
678 toStream(out
, n
[1], depth
, types
, false);
682 case kind::BITVECTOR_MULT
: {
683 Assert(n
.getType().isBitVector());
684 unsigned numc
= n
.getNumChildren()-2;
686 while (child
< numc
) {
688 out
<< BitVectorType(n
.getType().toType()).getSize();
690 toStream(out
, n
[child
], depth
, types
, false);
695 out
<< BitVectorType(n
.getType().toType()).getSize();
697 toStream(out
, n
[child
], depth
, types
, false);
699 toStream(out
, n
[child
+ 1], depth
, types
, false);
708 case kind::BITVECTOR_EXTRACT
:
709 op
<< n
.getOperator().getConst
<BitVectorExtract
>();
712 case kind::BITVECTOR_BITOF
:
713 op
<< n
.getOperator().getConst
<BitVectorBitOf
>();
716 case kind::BITVECTOR_REPEAT
:
718 toStream(out
, n
[0], depth
, types
, false);
719 out
<< ", " << n
.getOperator().getConst
<BitVectorRepeat
>() << ')';
722 case kind::BITVECTOR_ZERO_EXTEND
:
723 out
<< "BVZEROEXTEND(";
724 toStream(out
, n
[0], depth
, types
, false);
725 out
<< ", " << n
.getOperator().getConst
<BitVectorZeroExtend
>() << ')';
728 case kind::BITVECTOR_SIGN_EXTEND
:
730 toStream(out
, n
[0], depth
, types
, false);
731 out
<< ", " << BitVectorType(n
.getType().toType()).getSize() << ')';
734 case kind::BITVECTOR_ROTATE_LEFT
:
736 toStream(out
, n
[0], depth
, types
, false);
737 out
<< ", " << n
.getOperator().getConst
<BitVectorRotateLeft
>() << ')';
740 case kind::BITVECTOR_ROTATE_RIGHT
:
742 toStream(out
, n
[0], depth
, types
, false);
743 out
<< ", " << n
.getOperator().getConst
<BitVectorRotateRight
>() << ')';
750 toStream(out
, n
[0], depth
, types
, false);
757 case kind::INTERSECTION
:
781 case kind::TRANSPOSE
:
789 case kind::SINGLETON
:
791 toStream(out
, n
[0], depth
, types
, false);
801 toStream(out
, n
[i
++], depth
, types
, false);
802 for(;i
+1 < n
.getNumChildren(); ++i
) {
804 toStream(out
, n
[i
], depth
, types
, false);
807 toStream(out
, n
[i
], depth
, types
, true);
816 toStream(out
, n
[0], depth
, types
, false);
825 toStream(out
, n
[0], depth
, types
, false);
827 toStream(out
, n
[1], depth
, types
, false);
829 // TODO: user patterns?
833 toStream(out
, n
[0], depth
, types
, false);
835 toStream(out
, n
[1], depth
, types
, false);
837 // TODO: user patterns?
839 case kind::INST_CONSTANT
:
840 out
<< "INST_CONSTANT";
842 case kind::BOUND_VAR_LIST
:
844 for(size_t i
= 0; i
< n
.getNumChildren(); ++i
) {
848 toStream(out
, n
[i
], -1, true, false); // ascribe types
852 case kind::INST_PATTERN
:
853 out
<< "INST_PATTERN";
855 case kind::INST_PATTERN_LIST
:
856 out
<< "INST_PATTERN_LIST";
860 Warning() << "Kind printing not implemented for the case of " << n
.getKind() << endl
;
866 out
<< op
.str() << '(';
878 for (unsigned i
= 0; i
< n
.getNumChildren(); ++ i
) {
880 if (opType
== INFIX
) {
881 out
<< ' ' << op
.str() << ' ';
886 toStream(out
, n
[i
], depth
, types
, opType
== INFIX
);
899 out
<< ')' << op
.str();
903 }/* CvcPrinter::toStream(TNode) */
906 static bool tryToStream(std::ostream
& out
, const Command
* c
, bool cvc3Mode
) throw();
908 void CvcPrinter::toStream(std::ostream
& out
, const Command
* c
,
909 int toDepth
, bool types
, size_t dag
) const throw() {
910 expr::ExprSetDepth::Scope
sdScope(out
, toDepth
);
911 expr::ExprPrintTypes::Scope
ptScope(out
, types
);
912 expr::ExprDag::Scope
dagScope(out
, dag
);
914 if(tryToStream
<AssertCommand
>(out
, c
, d_cvc3Mode
) ||
915 tryToStream
<PushCommand
>(out
, c
, d_cvc3Mode
) ||
916 tryToStream
<PopCommand
>(out
, c
, d_cvc3Mode
) ||
917 tryToStream
<CheckSatCommand
>(out
, c
, d_cvc3Mode
) ||
918 tryToStream
<QueryCommand
>(out
, c
, d_cvc3Mode
) ||
919 tryToStream
<ResetCommand
>(out
, c
, d_cvc3Mode
) ||
920 tryToStream
<ResetAssertionsCommand
>(out
, c
, d_cvc3Mode
) ||
921 tryToStream
<QuitCommand
>(out
, c
, d_cvc3Mode
) ||
922 tryToStream
<DeclarationSequence
>(out
, c
, d_cvc3Mode
) ||
923 tryToStream
<CommandSequence
>(out
, c
, d_cvc3Mode
) ||
924 tryToStream
<DeclareFunctionCommand
>(out
, c
, d_cvc3Mode
) ||
925 tryToStream
<DeclareTypeCommand
>(out
, c
, d_cvc3Mode
) ||
926 tryToStream
<DefineTypeCommand
>(out
, c
, d_cvc3Mode
) ||
927 tryToStream
<DefineNamedFunctionCommand
>(out
, c
, d_cvc3Mode
) ||
928 tryToStream
<DefineFunctionCommand
>(out
, c
, d_cvc3Mode
) ||
929 tryToStream
<SimplifyCommand
>(out
, c
, d_cvc3Mode
) ||
930 tryToStream
<GetValueCommand
>(out
, c
, d_cvc3Mode
) ||
931 tryToStream
<GetModelCommand
>(out
, c
, d_cvc3Mode
) ||
932 tryToStream
<GetAssignmentCommand
>(out
, c
, d_cvc3Mode
) ||
933 tryToStream
<GetAssertionsCommand
>(out
, c
, d_cvc3Mode
) ||
934 tryToStream
<GetProofCommand
>(out
, c
, d_cvc3Mode
) ||
935 tryToStream
<GetUnsatCoreCommand
>(out
, c
, d_cvc3Mode
) ||
936 tryToStream
<SetBenchmarkStatusCommand
>(out
, c
, d_cvc3Mode
) ||
937 tryToStream
<SetBenchmarkLogicCommand
>(out
, c
, d_cvc3Mode
) ||
938 tryToStream
<SetInfoCommand
>(out
, c
, d_cvc3Mode
) ||
939 tryToStream
<GetInfoCommand
>(out
, c
, d_cvc3Mode
) ||
940 tryToStream
<SetOptionCommand
>(out
, c
, d_cvc3Mode
) ||
941 tryToStream
<GetOptionCommand
>(out
, c
, d_cvc3Mode
) ||
942 tryToStream
<DatatypeDeclarationCommand
>(out
, c
, d_cvc3Mode
) ||
943 tryToStream
<CommentCommand
>(out
, c
, d_cvc3Mode
) ||
944 tryToStream
<EmptyCommand
>(out
, c
, d_cvc3Mode
) ||
945 tryToStream
<EchoCommand
>(out
, c
, d_cvc3Mode
)) {
949 out
<< "ERROR: don't know how to print a Command of class: "
950 << typeid(*c
).name() << endl
;
952 }/* CvcPrinter::toStream(Command*) */
955 static bool tryToStream(std::ostream
& out
, const CommandStatus
* s
, bool cvc3Mode
) throw();
957 void CvcPrinter::toStream(std::ostream
& out
, const CommandStatus
* s
) const throw() {
959 if(tryToStream
<CommandSuccess
>(out
, s
, d_cvc3Mode
) ||
960 tryToStream
<CommandFailure
>(out
, s
, d_cvc3Mode
) ||
961 tryToStream
<CommandUnsupported
>(out
, s
, d_cvc3Mode
) ||
962 tryToStream
<CommandInterrupted
>(out
, s
, d_cvc3Mode
)) {
966 out
<< "ERROR: don't know how to print a CommandStatus of class: "
967 << typeid(*s
).name() << endl
;
969 }/* CvcPrinter::toStream(CommandStatus*) */
971 void CvcPrinter::toStream(std::ostream
& out
, const Model
& m
, const Command
* c
) const throw() {
972 const theory::TheoryModel
& tm
= (const theory::TheoryModel
&) m
;
973 if(dynamic_cast<const DeclareTypeCommand
*>(c
) != NULL
) {
974 TypeNode tn
= TypeNode::fromType( ((const DeclareTypeCommand
*)c
)->getType() );
975 if( options::modelUninterpDtEnum() && tn
.isSort() &&
976 tm
.d_rep_set
.d_type_reps
.find( tn
)!=tm
.d_rep_set
.d_type_reps
.end() ){
977 out
<< "DATATYPE" << std::endl
;
978 out
<< " " << dynamic_cast<const DeclareTypeCommand
*>(c
)->getSymbol() << " = ";
979 for( size_t i
=0; i
<(*tm
.d_rep_set
.d_type_reps
.find(tn
)).second
.size(); i
++ ){
983 out
<< (*tm
.d_rep_set
.d_type_reps
.find(tn
)).second
[i
] << " ";
985 out
<< std::endl
<< "END;" << std::endl
;
988 // print the cardinality
989 if( tm
.d_rep_set
.d_type_reps
.find( tn
)!=tm
.d_rep_set
.d_type_reps
.end() ){
990 out
<< "% cardinality of " << tn
<< " is " << (*tm
.d_rep_set
.d_type_reps
.find(tn
)).second
.size() << std::endl
;
993 out
<< c
<< std::endl
;
995 // print the representatives
996 if( tm
.d_rep_set
.d_type_reps
.find( tn
)!=tm
.d_rep_set
.d_type_reps
.end() ){
997 for( size_t i
=0; i
<(*tm
.d_rep_set
.d_type_reps
.find(tn
)).second
.size(); i
++ ){
998 if( (*tm
.d_rep_set
.d_type_reps
.find(tn
)).second
[i
].isVar() ){
999 out
<< (*tm
.d_rep_set
.d_type_reps
.find(tn
)).second
[i
] << " : " << tn
<< ";" << std::endl
;
1001 out
<< "% rep: " << (*tm
.d_rep_set
.d_type_reps
.find(tn
)).second
[i
] << std::endl
;
1007 } else if(dynamic_cast<const DeclareFunctionCommand
*>(c
) != NULL
) {
1008 Node n
= Node::fromExpr( ((const DeclareFunctionCommand
*)c
)->getFunction() );
1009 if(n
.getKind() == kind::SKOLEM
) {
1010 // don't print out internal stuff
1013 TypeNode tn
= n
.getType();
1015 if( tn
.isFunction() || tn
.isPredicate() ){
1017 for( size_t i
=0; i
<tn
.getNumChildren()-1; i
++ ){
1018 if( i
>0 ) out
<< ", ";
1021 out
<< ") -> " << tn
.getRangeType();
1025 Node val
= Node::fromExpr(tm
.getSmtEngine()->getValue(n
.toExpr()));
1026 if( options::modelUninterpDtEnum() && val
.getKind() == kind::STORE
) {
1027 TypeNode tn
= val
[1].getType();
1028 if (tn
.isSort() && tm
.d_rep_set
.d_type_reps
.find( tn
)!=tm
.d_rep_set
.d_type_reps
.end() ){
1029 Cardinality
indexCard((*tm
.d_rep_set
.d_type_reps
.find(tn
)).second
.size());
1030 val
= theory::arrays::TheoryArraysRewriter::normalizeConstant( val
, indexCard
);
1033 out
<< " = " << val
<< ";" << std::endl
;
1036 //for table format (work in progress)
1037 bool printedModel = false;
1038 if( tn.isFunction() ){
1039 if( options::modelFormatMode()==MODEL_FORMAT_MODE_TABLE ){
1040 //specialized table format for functions
1041 RepSetIterator riter( &d_rep_set );
1042 riter.setFunctionDomain( n );
1043 while( !riter.isFinished() ){
1044 std::vector< Node > children;
1045 children.push_back( n );
1046 for( int i=0; i<riter.getNumTerms(); i++ ){
1047 children.push_back( riter.getTerm( i ) );
1049 Node nn = NodeManager::currentNM()->mkNode( APPLY_UF, children );
1050 Node val = getValue( nn );
1054 printedModel = true;
1059 out
<< c
<< std::endl
;
1063 static void toStream(std::ostream
& out
, const AssertCommand
* c
, bool cvc3Mode
) throw() {
1064 out
<< "ASSERT " << c
->getExpr() << ";";
1067 static void toStream(std::ostream
& out
, const PushCommand
* c
, bool cvc3Mode
) throw() {
1071 static void toStream(std::ostream
& out
, const PopCommand
* c
, bool cvc3Mode
) throw() {
1075 static void toStream(std::ostream
& out
, const CheckSatCommand
* c
, bool cvc3Mode
) throw() {
1076 Expr e
= c
->getExpr();
1081 out
<< "CHECKSAT " << e
<< ";";
1090 static void toStream(std::ostream
& out
, const QueryCommand
* c
, bool cvc3Mode
) throw() {
1091 Expr e
= c
->getExpr();
1096 out
<< "QUERY " << e
<< ";";
1098 out
<< "QUERY TRUE;";
1105 static void toStream(std::ostream
& out
, const ResetCommand
* c
, bool cvc3Mode
) throw() {
1109 static void toStream(std::ostream
& out
, const ResetAssertionsCommand
* c
, bool cvc3Mode
) throw() {
1110 out
<< "RESET ASSERTIONS;";
1113 static void toStream(std::ostream
& out
, const QuitCommand
* c
, bool cvc3Mode
) throw() {
1117 static void toStream(std::ostream
& out
, const CommandSequence
* c
, bool cvc3Mode
) throw() {
1118 for(CommandSequence::const_iterator i
= c
->begin();
1125 static void toStream(std::ostream
& out
, const DeclarationSequence
* c
, bool cvc3Mode
) throw() {
1126 DeclarationSequence::const_iterator i
= c
->begin();
1128 DeclarationDefinitionCommand
* dd
=
1129 static_cast<DeclarationDefinitionCommand
*>(*i
++);
1131 out
<< dd
->getSymbol() << ", ";
1139 static void toStream(std::ostream
& out
, const DeclareFunctionCommand
* c
, bool cvc3Mode
) throw() {
1140 out
<< c
->getSymbol() << " : " << c
->getType() << ";";
1143 static void toStream(std::ostream
& out
, const DefineFunctionCommand
* c
, bool cvc3Mode
) throw() {
1144 Expr func
= c
->getFunction();
1145 const vector
<Expr
>& formals
= c
->getFormals();
1146 Expr formula
= c
->getFormula();
1147 out
<< func
<< " : " << func
.getType() << " = ";
1148 if(formals
.size() > 0) {
1150 vector
<Expr
>::const_iterator i
= formals
.begin();
1151 while(i
!= formals
.end()) {
1152 out
<< (*i
) << ":" << (*i
).getType();
1153 if(++i
!= formals
.end()) {
1159 out
<< formula
<< ";";
1162 static void toStream(std::ostream
& out
, const DeclareTypeCommand
* c
, bool cvc3Mode
) throw() {
1163 if(c
->getArity() > 0) {
1165 out
<< "ERROR: Don't know how to print parameterized type declaration "
1166 "in CVC language." << endl
;
1168 out
<< c
->getSymbol() << " : TYPE;";
1172 static void toStream(std::ostream
& out
, const DefineTypeCommand
* c
, bool cvc3Mode
) throw() {
1173 if(c
->getParameters().size() > 0) {
1174 out
<< "ERROR: Don't know how to print parameterized type definition "
1175 "in CVC language:" << endl
<< c
->toString() << endl
;
1177 out
<< c
->getSymbol() << " : TYPE = " << c
->getType() << ";";
1181 static void toStream(std::ostream
& out
, const DefineNamedFunctionCommand
* c
, bool cvc3Mode
) throw() {
1182 toStream(out
, static_cast<const DefineFunctionCommand
*>(c
), cvc3Mode
);
1185 static void toStream(std::ostream
& out
, const SimplifyCommand
* c
, bool cvc3Mode
) throw() {
1186 out
<< "TRANSFORM " << c
->getTerm() << ";";
1189 static void toStream(std::ostream
& out
, const GetValueCommand
* c
, bool cvc3Mode
) throw() {
1190 const vector
<Expr
>& terms
= c
->getTerms();
1191 Assert(!terms
.empty());
1192 out
<< "GET_VALUE ";
1193 copy(terms
.begin(), terms
.end() - 1, ostream_iterator
<Expr
>(out
, ";\nGET_VALUE "));
1194 out
<< terms
.back() << ";";
1197 static void toStream(std::ostream
& out
, const GetModelCommand
* c
, bool cvc3Mode
) throw() {
1198 out
<< "COUNTERMODEL;";
1201 static void toStream(std::ostream
& out
, const GetAssignmentCommand
* c
, bool cvc3Mode
) throw() {
1202 out
<< "% (get-assignment)";
1205 static void toStream(std::ostream
& out
, const GetAssertionsCommand
* c
, bool cvc3Mode
) throw() {
1209 static void toStream(std::ostream
& out
, const GetProofCommand
* c
, bool cvc3Mode
) throw() {
1210 out
<< "DUMP_PROOF;";
1213 static void toStream(std::ostream
& out
, const GetUnsatCoreCommand
* c
, bool cvc3Mode
) throw() {
1214 out
<< "DUMP_UNSAT_CORE;";
1217 static void toStream(std::ostream
& out
, const SetBenchmarkStatusCommand
* c
, bool cvc3Mode
) throw() {
1218 out
<< "% (set-info :status " << c
->getStatus() << ")";
1221 static void toStream(std::ostream
& out
, const SetBenchmarkLogicCommand
* c
, bool cvc3Mode
) throw() {
1222 out
<< "OPTION \"logic\" \"" << c
->getLogic() << "\";";
1225 static void toStream(std::ostream
& out
, const SetInfoCommand
* c
, bool cvc3Mode
) throw() {
1226 out
<< "% (set-info " << c
->getFlag() << " ";
1227 OutputLanguage language
=
1228 cvc3Mode
? language::output::LANG_CVC3
: language::output::LANG_CVC4
;
1229 SExpr::toStream(out
, c
->getSExpr(), language
);
1233 static void toStream(std::ostream
& out
, const GetInfoCommand
* c
, bool cvc3Mode
) throw() {
1234 out
<< "% (get-info " << c
->getFlag() << ")";
1237 static void toStream(std::ostream
& out
, const SetOptionCommand
* c
, bool cvc3Mode
) throw() {
1238 out
<< "OPTION \"" << c
->getFlag() << "\" ";
1239 SExpr::toStream(out
, c
->getSExpr(), language::output::LANG_CVC4
);
1243 static void toStream(std::ostream
& out
, const GetOptionCommand
* c
, bool cvc3Mode
) throw() {
1244 out
<< "% (get-option " << c
->getFlag() << ")";
1247 static void toStream(std::ostream
& out
, const DatatypeDeclarationCommand
* c
, bool cvc3Mode
) throw() {
1248 const vector
<DatatypeType
>& datatypes
= c
->getDatatypes();
1249 out
<< "DATATYPE" << endl
;
1250 bool firstDatatype
= true;
1251 for(vector
<DatatypeType
>::const_iterator i
= datatypes
.begin(),
1252 i_end
= datatypes
.end();
1255 if(! firstDatatype
) {
1258 const Datatype
& dt
= (*i
).getDatatype();
1259 out
<< " " << dt
.getName();
1260 if(dt
.isParametric()) {
1262 for(size_t j
= 0; j
< dt
.getNumParameters(); ++j
) {
1266 out
<< dt
.getParameter(j
);
1271 bool firstConstructor
= true;
1272 for(Datatype::const_iterator j
= dt
.begin(); j
!= dt
.end(); ++j
) {
1273 if(! firstConstructor
) {
1276 firstConstructor
= false;
1277 const DatatypeConstructor
& c
= *j
;
1279 if(c
.getNumArgs() > 0) {
1281 bool firstSelector
= true;
1282 for(DatatypeConstructor::const_iterator k
= c
.begin(); k
!= c
.end(); ++k
) {
1283 if(! firstSelector
) {
1286 firstSelector
= false;
1287 const DatatypeConstructorArg
& selector
= *k
;
1288 Type t
= SelectorType(selector
.getType()).getRangeType();
1289 if( t
.isDatatype() ){
1290 const Datatype
& sdt
= ((DatatypeType
)t
).getDatatype();
1291 out
<< selector
.getName() << ": " << sdt
.getName();
1293 out
<< selector
.getName() << ": " << t
;
1300 out
<< endl
<< "END;";
1303 static void toStream(std::ostream
& out
, const CommentCommand
* c
, bool cvc3Mode
) throw() {
1304 out
<< "% " << c
->getComment();
1307 static void toStream(std::ostream
& out
, const EmptyCommand
* c
, bool cvc3Mode
) throw() {
1310 static void toStream(std::ostream
& out
, const EchoCommand
* c
, bool cvc3Mode
) throw() {
1311 out
<< "ECHO \"" << c
->getOutput() << "\";";
1315 static bool tryToStream(std::ostream
& out
, const Command
* c
, bool cvc3Mode
) throw() {
1316 if(typeid(*c
) == typeid(T
)) {
1317 toStream(out
, dynamic_cast<const T
*>(c
), cvc3Mode
);
1323 static void toStream(std::ostream
& out
, const CommandSuccess
* s
, bool cvc3Mode
) throw() {
1324 if(Command::printsuccess::getPrintSuccess(out
)) {
1325 out
<< "OK" << endl
;
1329 static void toStream(std::ostream
& out
, const CommandUnsupported
* s
, bool cvc3Mode
) throw() {
1330 out
<< "UNSUPPORTED" << endl
;
1333 static void toStream(std::ostream
& out
, const CommandInterrupted
* s
, bool cvc3Mode
) throw() {
1334 out
<< "INTERRUPTED" << endl
;
1337 static void toStream(std::ostream
& out
, const CommandFailure
* s
, bool cvc3Mode
) throw() {
1338 out
<< s
->getMessage() << endl
;
1342 static bool tryToStream(std::ostream
& out
, const CommandStatus
* s
, bool cvc3Mode
) throw() {
1343 if(typeid(*s
) == typeid(T
)) {
1344 toStream(out
, dynamic_cast<const T
*>(s
), cvc3Mode
);
1350 }/* CVC4::printer::cvc namespace */
1351 }/* CVC4::printer namespace */
1352 }/* CVC4 namespace */