Better error on illegal (pop N); also more compliant SMT-LIB error messages in some...
authorMorgan Deters <mdeters@cs.nyu.edu>
Fri, 17 May 2013 13:54:15 +0000 (09:54 -0400)
committerMorgan Deters <mdeters@cs.nyu.edu>
Fri, 17 May 2013 13:54:15 +0000 (09:54 -0400)
Thanks to David Cok for reporting these issues.

src/main/interactive_shell.cpp
src/main/main.cpp
src/parser/parser.h
src/parser/smt2/Smt2.g

index 3376e9d0b912ffcee7cd20238a92692c32877547..5c9f8af218fa78a3d6aa068cab9739326b40ff07 100644 (file)
@@ -313,7 +313,11 @@ restart:
     line += "\n";
     goto restart;
   } catch(ParserException& pe) {
-    d_out << pe << endl;
+    if(d_options[options::outputLanguage] == output::LANG_SMTLIB_V2) {
+      d_out << "(error \"" << pe << "\")" << endl;
+    } else {
+      d_out << pe << endl;
+    }
     // We can't really clear out the sequence and abort the current line,
     // because the parse error might be for the second command on the
     // line.  The first ones haven't yet been executed by the SmtEngine,
index 7b61b48aaf2b9b71bdaf3603a130032a4ac90a6b..a4c4b9c0a682caab7e3202e6318b7e0f7f6f654b 100644 (file)
 #include "util/output.h"
 #include "util/result.h"
 #include "util/statistics.h"
+#include "util/language.h"
 
 using namespace std;
 using namespace CVC4;
 using namespace CVC4::main;
+using namespace CVC4::language;
 
 /**
  * CVC4's main() routine is just an exception-safe wrapper around CVC4.
@@ -64,7 +66,11 @@ int main(int argc, char* argv[]) {
 #ifdef CVC4_COMPETITION_MODE
     *opts[options::out] << "unknown" << endl;
 #endif
-    *opts[options::err] << "CVC4 Error:" << endl << e << endl;
+    if(opts[options::outputLanguage] == output::LANG_SMTLIB_V2) {
+      *opts[options::err] << "(error \"" << e << "\")" << endl;
+    } else {
+      *opts[options::err] << "CVC4 Error:" << endl << e << endl;
+    }
     if(opts[options::statistics] && pExecutor != NULL) {
       pTotalTime->stop();
       pExecutor->flushStatistics(*opts[options::err]);
index 1ca56dc0662e0d0f387b66a631fcb53dc53b6c53..d13fbf2d6a719eb7bf9cd0cb5ffd89eb21e1d968 100644 (file)
@@ -482,6 +482,7 @@ public:
     }
   }
 
+  inline size_t scopeLevel() const { return d_symtab->getLevel(); }
   inline void pushScope() { d_symtab->pushScope(); }
   inline void popScope() { d_symtab->popScope(); }
 
index 6c98a552984cf0b37fbba891d9921fa310c0f614..dbe1135b39d12e936752ea0cbbe61261829e8ff2 100644 (file)
@@ -284,7 +284,7 @@ command returns [CVC4::Command* cmd = NULL]
     { $cmd = new GetValueCommand(terms); }
   | /* get-assignment */
     GET_ASSIGNMENT_TOK { PARSER_STATE->checkThatLogicIsSet(); }
-    { cmd = new GetAssignmentCommand; }
+    { cmd = new GetAssignmentCommand(); }
   | /* assertion */
     ASSERT_TOK { PARSER_STATE->checkThatLogicIsSet(); }
     term[expr, expr2]
@@ -294,13 +294,13 @@ command returns [CVC4::Command* cmd = NULL]
     { cmd = new CheckSatCommand(MK_CONST(bool(true))); }
   | /* get-assertions */
     GET_ASSERTIONS_TOK { PARSER_STATE->checkThatLogicIsSet(); }
-    { cmd = new GetAssertionsCommand; }
+    { cmd = new GetAssertionsCommand(); }
   | /* get-proof */
     GET_PROOF_TOK { PARSER_STATE->checkThatLogicIsSet(); }
-    { cmd = new GetProofCommand; }
+    { cmd = new GetProofCommand(); }
   | /* get-unsat-core */
     GET_UNSAT_CORE_TOK { PARSER_STATE->checkThatLogicIsSet(); }
-    { cmd = new GetUnsatCoreCommand; }
+    { cmd = new GetUnsatCoreCommand(); }
   | /* push */
     PUSH_TOK { PARSER_STATE->checkThatLogicIsSet(); }
     ( k=INTEGER_LITERAL
@@ -324,12 +324,15 @@ command returns [CVC4::Command* cmd = NULL]
     | { if(PARSER_STATE->strictModeEnabled()) {
           PARSER_STATE->parseError("Strict compliance mode demands an integer to be provided to PUSH.  Maybe you want (push 1)?");
         } else {
-          cmd = new PushCommand;
+          cmd = new PushCommand();
         }
       } )
   | POP_TOK { PARSER_STATE->checkThatLogicIsSet(); }
     ( k=INTEGER_LITERAL
       { unsigned n = AntlrInput::tokenToUnsigned(k);
+        if(n > PARSER_STATE->scopeLevel()) {
+          PARSER_STATE->parseError("Attempted to pop above the top stack frame.");
+        }
         if(n == 0) {
           cmd = new EmptyCommand();
         } else if(n == 1) {
@@ -349,11 +352,11 @@ command returns [CVC4::Command* cmd = NULL]
     | { if(PARSER_STATE->strictModeEnabled()) {
           PARSER_STATE->parseError("Strict compliance mode demands an integer to be provided to POP.  Maybe you want (pop 1)?");
         } else {
-          cmd = new PopCommand;
+          cmd = new PopCommand();
         }
       } )
   | EXIT_TOK
-    { cmd = new QuitCommand; }
+    { cmd = new QuitCommand(); }
 
     /* CVC4-extended SMT-LIB commands */
   | extendedCommand[cmd]
@@ -400,7 +403,7 @@ extendedCommand[CVC4::Command*& cmd]
       cmd = new DatatypeDeclarationCommand(PARSER_STATE->mkMutualDatatypeTypes(dts)); }
   | /* get model */
     GET_MODEL_TOK { PARSER_STATE->checkThatLogicIsSet(); }
-    { cmd = new GetModelCommand; }
+    { cmd = new GetModelCommand(); }
   | ECHO_TOK
     ( simpleSymbolicExpr[sexpr]
       { std::stringstream ss;