Improve error message when not using strings-exp (#8203)
authorAndrew Reynolds <andrew.j.reynolds@gmail.com>
Wed, 2 Mar 2022 18:16:20 +0000 (12:16 -0600)
committerGitHub <noreply@github.com>
Wed, 2 Mar 2022 18:16:20 +0000 (18:16 +0000)
Fixes #6005.

Also improves smt2 printing of sequences so that we print the compliant kinds, which is work towards cvc5/cvc5-wishues#106.

src/printer/smt2/smt2_printer.cpp
src/printer/smt2/smt2_printer.h
src/theory/strings/term_registry.cpp
test/regress/CMakeLists.txt
test/regress/regress0/seq/issue6005-no-strings-exp.smt2 [new file with mode: 0644]

index f3078a450bb4ec334a71b192cbb33aa6df27d9d8..773d5fd4bb53f6b16bdb64cd7d88d01528d10a57 100644 (file)
@@ -953,7 +953,7 @@ void Smt2Printer::toStream(std::ostream& out,
       if(forceBinary && i < n.getNumChildren() - 1) {
         // not going to work properly for parameterized kinds!
         Assert(n.getMetaKind() != kind::metakind::PARAMETERIZED);
-        out << " (" << smtKindString(n.getKind(), d_variant) << ' ';
+        out << " (" << smtKindStringOf(n, d_variant) << ' ';
         parens << ')';
         ++c;
       } else {
@@ -1269,6 +1269,35 @@ std::string Smt2Printer::smtKindString(Kind k, Variant v)
   return kind::kindToString(k);
 }
 
+std::string Smt2Printer::smtKindStringOf(const Node& n, Variant v)
+{
+  Kind k = n.getKind();
+  if (n.getNumChildren() > 0 && n[0].getType().isSequence())
+  {
+    // this method parallels api::Term::getKind
+    switch (k)
+    {
+      case kind::STRING_CONCAT: return "seq.concat";
+      case kind::STRING_LENGTH: return "seq.len";
+      case kind::STRING_SUBSTR: return "seq.extract";
+      case kind::STRING_UPDATE: return "seq.update";
+      case kind::STRING_CHARAT: return "seq.at";
+      case kind::STRING_CONTAINS: return "seq.contains";
+      case kind::STRING_INDEXOF: return "seq.indexof";
+      case kind::STRING_REPLACE: return "seq.replace";
+      case kind::STRING_REPLACE_ALL: return "seq.replace_all";
+      case kind::STRING_REV: return "seq.rev";
+      case kind::STRING_PREFIX: return "seq.prefixof";
+      case kind::STRING_SUFFIX: return "seq.suffixof";
+      default:
+        // fall through to conversion below
+        break;
+    }
+  }
+  // by default
+  return smtKindString(k, v);
+}
+
 void Smt2Printer::toStreamType(std::ostream& out, TypeNode tn) const
 {
   // we currently must call TypeNode::toStream here.
index bf6c20d40699e4bbd8bf6cd8e26b156cb804ef4b..4170fe88fdeb0eaa9db6ed7346f8985839d907d0 100644 (file)
@@ -256,6 +256,11 @@ class Smt2Printer : public cvc5::Printer
    * the SMT-LIB format (with variant v).
    */
   static std::string smtKindString(Kind k, Variant v = smt2_6_variant);
+  /**
+   * Same as above, but also takes into account the type of the node, which
+   * makes a difference for printing sequences.
+   */
+  static std::string smtKindStringOf(const Node& n, Variant v = smt2_6_variant);
   /**
    * Get the string corresponding to the sygus datatype t printed as a grammar.
    */
index fff869c7d8a124b062f9221d6459d04de3f93fe3..84a290f3c2b4c606bf2495004b202714d2be3682 100644 (file)
@@ -18,6 +18,7 @@
 #include "expr/attribute.h"
 #include "options/smt_options.h"
 #include "options/strings_options.h"
+#include "printer/smt2/smt2_printer.h"
 #include "smt/logic_exception.h"
 #include "theory/rewriter.h"
 #include "theory/strings/inference_manager.h"
@@ -162,7 +163,7 @@ void TermRegistry::preRegisterTerm(TNode n)
         || k == STRING_UPDATE)
     {
       std::stringstream ss;
-      ss << "Term of kind " << k
+      ss << "Term of kind " << printer::smt2::Smt2Printer::smtKindStringOf(n)
          << " not supported in default mode, try --strings-exp";
       throw LogicException(ss.str());
     }
index 0439943680aa8c12c0b284bce9e2e0bcd3ea1c86..a4921e5c96f117f5c9623cd1c137bc96c739b091 100644 (file)
@@ -1170,6 +1170,7 @@ set(regress_0_tests
   regress0/seq/array/nth-concat.smt2
   regress0/seq/array/update-fallback.smt2
   regress0/seq/array/update-word-eq.smt2
+  regress0/seq/issue6005-no-strings-exp.smt2
   regress0/seq/seq-2var.smt2
   regress0/seq/seq-ex1.smt2
   regress0/seq/seq-ex2.smt2
diff --git a/test/regress/regress0/seq/issue6005-no-strings-exp.smt2 b/test/regress/regress0/seq/issue6005-no-strings-exp.smt2
new file mode 100644 (file)
index 0000000..54f5520
--- /dev/null
@@ -0,0 +1,6 @@
+; EXPECT: (error "Term of kind seq.extract not supported in default mode, try --strings-exp")
+; EXIT: 1
+(set-logic ALL)
+(declare-fun x () (Seq Int))
+(assert (not (= x (seq.extract x 4 7))))
+(check-sat)