From a0b35a8ba9c47ed521082c5ac5a8f50909d9f7c4 Mon Sep 17 00:00:00 2001 From: Ying Sheng Date: Sat, 7 Mar 2020 21:01:16 -0800 Subject: [PATCH] Explicit end marker for models printed in the CVC language (#3934) Fixes https://github.com/CVC4/cvc4-wishues/issues/9. When communicating with CVC4 using pipes and the CVC language, it was not possible to determine when all the lines of a model have been printed. This change adds begin and end markers as the example below: ``` MODEL BEGIN x : INT = -3; y : INT = 0; z : INT = 0; MODEL END; ``` --- src/printer/cvc/cvc_printer.cpp | 17 +++++++++++++++++ src/printer/cvc/cvc_printer.h | 1 + test/regress/CMakeLists.txt | 1 + test/regress/regress0/print_lambda.cvc | 2 ++ test/regress/regress0/print_model.cvc | 12 ++++++++++++ 5 files changed, 33 insertions(+) create mode 100644 test/regress/regress0/print_model.cvc diff --git a/src/printer/cvc/cvc_printer.cpp b/src/printer/cvc/cvc_printer.cpp index 86dd31da2..79a8904cd 100644 --- a/src/printer/cvc/cvc_printer.cpp +++ b/src/printer/cvc/cvc_printer.cpp @@ -1174,6 +1174,23 @@ void DeclareFunctionCommandToStream(std::ostream& out, } // namespace +void CvcPrinter::toStream(std::ostream& out, const Model& m) const +{ + // print the model comments + std::stringstream c; + m.getComments(c); + std::string ln; + while (std::getline(c, ln)) + { + out << "; " << ln << std::endl; + } + + // print the model + out << "MODEL BEGIN" << std::endl; + this->Printer::toStream(out, m); + out << "MODEL END;" << std::endl; +} + void CvcPrinter::toStream(std::ostream& out, const Model& model, const Command* command) const diff --git a/src/printer/cvc/cvc_printer.h b/src/printer/cvc/cvc_printer.h index d379af7e3..1694ea1ec 100644 --- a/src/printer/cvc/cvc_printer.h +++ b/src/printer/cvc/cvc_printer.h @@ -42,6 +42,7 @@ class CvcPrinter : public CVC4::Printer { bool types, size_t dag) const override; void toStream(std::ostream& out, const CommandStatus* s) const override; + void toStream(std::ostream& out, const Model& m) const override; private: void toStream( diff --git a/test/regress/CMakeLists.txt b/test/regress/CMakeLists.txt index 5eaaf3e67..3bcbfa859 100644 --- a/test/regress/CMakeLists.txt +++ b/test/regress/CMakeLists.txt @@ -645,6 +645,7 @@ set(regress_0_tests regress0/preprocess/preprocess_14.cvc regress0/preprocess/preprocess_15.cvc regress0/print_lambda.cvc + regress0/print_model.cvc regress0/printer/bv_consts_bin.smt2 regress0/printer/bv_consts_dec.smt2 regress0/printer/empty_sort.smt2 diff --git a/test/regress/regress0/print_lambda.cvc b/test/regress/regress0/print_lambda.cvc index 548623954..99e5ff174 100644 --- a/test/regress/regress0/print_lambda.cvc +++ b/test/regress/regress0/print_lambda.cvc @@ -1,7 +1,9 @@ % SCRUBBER: sed -e 's/f : (INT) -> INT = (LAMBDA(.*:INT): 0);$/f : (INT) -> INT = (LAMBDA(VAR:INT): 0);/' % COMMAND-LINE: --produce-models % EXPECT: sat +% EXPECT: MODEL BEGIN % EXPECT: f : (INT) -> INT = (LAMBDA(VAR:INT): 0); +% EXPECT: MODEL END; f : INT -> INT; ASSERT f(1) = 0; diff --git a/test/regress/regress0/print_model.cvc b/test/regress/regress0/print_model.cvc new file mode 100644 index 000000000..0ad9ddf4c --- /dev/null +++ b/test/regress/regress0/print_model.cvc @@ -0,0 +1,12 @@ +% COMMAND-LINE: --produce-models +% EXPECT: sat +% EXPECT: MODEL BEGIN +% EXPECT: s1 : INT = 2; +% EXPECT: s2 : INT = 1; +% EXPECT: MODEL END; + +OPTION "produce-models"; +s1, s2 : INT; +ASSERT s1 = 2; +CHECKSAT s2 > 0 AND s2 < s1; +COUNTERMODEL; -- 2.30.2