Minor usability fixes related to SMT-LIB compliance.
authorMorgan Deters <mdeters@cs.nyu.edu>
Sat, 15 Mar 2014 21:29:09 +0000 (17:29 -0400)
committerMorgan Deters <mdeters@cs.nyu.edu>
Wed, 19 Mar 2014 14:38:05 +0000 (10:38 -0400)
src/parser/smt2/Smt2.g
src/parser/smt2/smt2.cpp
src/parser/smt2/smt2.h
test/regress/regress0/bug548a.smt2

index 3c68e4e4c0d126f91fbbb8b9535f6b95a35d126f..f987de2f12a13de3b7c3ddb5f649e71d50fc2973 100644 (file)
@@ -253,6 +253,13 @@ command returns [CVC4::Command* cmd = NULL]
     { cmd = new GetOptionCommand(AntlrInput::tokenText($KEYWORD).c_str() + 1); }
   | /* sort declaration */
     DECLARE_SORT_TOK { PARSER_STATE->checkThatLogicIsSet(); }
+    { if(!PARSER_STATE->isTheoryEnabled(Smt2::THEORY_UF) &&
+         !PARSER_STATE->isTheoryEnabled(Smt2::THEORY_ARRAYS) &&
+         !PARSER_STATE->isTheoryEnabled(Smt2::THEORY_DATATYPES) &&
+         !PARSER_STATE->isTheoryEnabled(Smt2::THEORY_SETS)) {
+        PARSER_STATE->parseError(std::string("Free sort symbols not allowed in ") + PARSER_STATE->getLogic().getLogicString());
+      }
+    }
     symbol[name,CHECK_UNDECLARED,SYM_SORT]
     { PARSER_STATE->checkUserSymbol(name); }
     n=INTEGER_LITERAL
@@ -295,6 +302,9 @@ command returns [CVC4::Command* cmd = NULL]
     sortSymbol[t,CHECK_DECLARED]
     { Debug("parser") << "declare fun: '" << name << "'" << std::endl;
       if( sorts.size() > 0 ) {
+        if(!PARSER_STATE->isTheoryEnabled(Smt2::THEORY_UF)) {
+          PARSER_STATE->parseError(std::string("Functions (of non-zero arity) cannot be declared in logic ") + PARSER_STATE->getLogic().getLogicString());
+        }
         t = EXPR_MANAGER->mkFunctionType(sorts, t);
       }
       Expr func = PARSER_STATE->mkVar(name, t);
@@ -488,6 +498,13 @@ extendedCommand[CVC4::Command*& cmd]
       $cmd = new DeclareFunctionCommand(name, c, t); }
 
   | DECLARE_SORTS_TOK { PARSER_STATE->checkThatLogicIsSet(); }
+    { if(!PARSER_STATE->isTheoryEnabled(Smt2::THEORY_UF) &&
+         !PARSER_STATE->isTheoryEnabled(Smt2::THEORY_ARRAYS) &&
+         !PARSER_STATE->isTheoryEnabled(Smt2::THEORY_DATATYPES) &&
+         !PARSER_STATE->isTheoryEnabled(Smt2::THEORY_SETS)) {
+        PARSER_STATE->parseError(std::string("Free sort symbols not allowed in ") + PARSER_STATE->getLogic().getLogicString());
+      }
+    }
     { $cmd = new CommandSequence(); }
     LPAREN_TOK
     ( symbol[name,CHECK_UNDECLARED,SYM_SORT]
@@ -506,6 +523,9 @@ extendedCommand[CVC4::Command*& cmd]
       nonemptySortList[sorts] RPAREN_TOK
       { Type t;
         if(sorts.size() > 1) {
+          if(!PARSER_STATE->isTheoryEnabled(Smt2::THEORY_UF)) {
+            PARSER_STATE->parseError(std::string("Functions (of non-zero arity) cannot be declared in logic ") + PARSER_STATE->getLogic().getLogicString());
+          }
           t = EXPR_MANAGER->mkFunctionType(sorts);
         } else {
           t = sorts[0];
@@ -524,6 +544,9 @@ extendedCommand[CVC4::Command*& cmd]
       sortList[sorts] RPAREN_TOK
       { Type t = EXPR_MANAGER->booleanType();
         if(sorts.size() > 0) {
+          if(!PARSER_STATE->isTheoryEnabled(Smt2::THEORY_UF)) {
+            PARSER_STATE->parseError(std::string("Predicates (of non-zero arity) cannot be declared in logic ") + PARSER_STATE->getLogic().getLogicString());
+          }
           t = EXPR_MANAGER->mkFunctionType(sorts, t);
         }
         Expr func = PARSER_STATE->mkVar(name, t);
index b59880a5e5e1ce49f967337b4e0509b8dc932eb9..64b321613a43e90ad2188830987c3666f581166e 100644 (file)
@@ -154,6 +154,12 @@ void Smt2::addTheory(Theory theory) {
     addOperator(kind::SET_SINGLETON, "setenum");
     break;
 
+  case THEORY_DATATYPES:
+    Parser::addOperator(kind::APPLY_CONSTRUCTOR);
+    Parser::addOperator(kind::APPLY_TESTER);
+    Parser::addOperator(kind::APPLY_SELECTOR);
+    break;
+
   case THEORY_STRINGS:
     defineType("String", getExprManager()->stringType());
     addStringOperators();
@@ -194,6 +200,8 @@ bool Smt2::isTheoryEnabled(Theory theory) const {
     return d_logic.isTheoryEnabled(theory::THEORY_BV);
   case THEORY_CORE:
     return true;
+  case THEORY_DATATYPES:
+    return d_logic.isTheoryEnabled(theory::THEORY_DATATYPES);
   case THEORY_INTS:
     return d_logic.isTheoryEnabled(theory::THEORY_ARITH) &&
       d_logic.areIntegersUsed() && ( !d_logic.areRealsUsed() );
@@ -253,6 +261,10 @@ void Smt2::setLogic(const std::string& name) {
     addTheory(THEORY_BITVECTORS);
   }
 
+  if(d_logic.isTheoryEnabled(theory::THEORY_DATATYPES)) {
+    addTheory(THEORY_DATATYPES);
+  }
+
   if(d_logic.isTheoryEnabled(theory::THEORY_SETS)) {
     addTheory(THEORY_SETS);
   }
index 969892c5fe937347940eec5fe5b6a9d94def8538..55a06a8e30c2bd83a08445f5e6d8c7076af40308 100644 (file)
@@ -40,6 +40,7 @@ public:
     THEORY_ARRAYS,
     THEORY_BITVECTORS,
     THEORY_CORE,
+    THEORY_DATATYPES,
     THEORY_INTS,
     THEORY_REALS,
     THEORY_REALS_INTS,
@@ -83,6 +84,11 @@ public:
    */
   void setLogic(const std::string& name);
 
+  /**
+   * Get the logic.
+   */
+  const LogicInfo& getLogic() const { return d_logic; }
+
   void setInfo(const std::string& flag, const SExpr& sexpr);
 
   void setOption(const std::string& flag, const SExpr& sexpr);
index 12658e507d541c38a070fe51c16bf8b314350f14..75d82d98f45785c4e060ec5460ecac1ece7f7109 100644 (file)
@@ -1,6 +1,6 @@
 ; COMMAND-LINE: --rewrite-divk --tlimit 1000
 ; EXPECT: unknown
-(set-logic LIA)
+(set-logic AUFLIA)
 (declare-fun f (Int) Int)