SMTCOMP,
STATS,
SEGV_NOSPIN,
- PARSE_ONLY
+ PARSE_ONLY,
+ NO_CHECKING
};/* enum OptionValue */
// FIXME add a comment here describing the option array
{ "smtcomp" , no_argument , NULL, SMTCOMP },
{ "stats" , no_argument , NULL, STATS },
{ "segv-nospin", no_argument , NULL, SEGV_NOSPIN },
- { "parse-only" , no_argument , NULL, PARSE_ONLY }
+ { "parse-only" , no_argument , NULL, PARSE_ONLY },
+ { "no-checking", no_argument , NULL, NO_CHECKING }
};/* if you add things to the above, please remember to update usage.h! */
/** Full argv[0] */
opts->parseOnly = true;
break;
+ case NO_CHECKING:
+ opts->semanticChecks = false;
+ break;
+
case '?':
throw OptionException(string("can't understand option"));// + argv[optind - 1] + "'");
parser = Parser::getNewParser(&exprMgr, options.lang, argv[firstArgIndex]);
}
+ if(!options.semanticChecks) {
+ parser->disableChecks();
+ }
+
// Parse and execute commands until we are done
Command* cmd;
while((cmd = parser->parseNextCommand())) {
namespace parser {
AntlrParser::AntlrParser(const antlr::ParserSharedInputState& state, int k) :
- antlr::LLkParser(state, k) {
+ antlr::LLkParser(state, k), d_checksEnabled(true) {
}
AntlrParser::AntlrParser(antlr::TokenBuffer& tokenBuf, int k) :
- antlr::LLkParser(tokenBuf, k) {
+ antlr::LLkParser(tokenBuf, k), d_checksEnabled(true) {
}
AntlrParser::AntlrParser(antlr::TokenStream& lexer, int k) :
- antlr::LLkParser(lexer, k) {
+ antlr::LLkParser(lexer, k), d_checksEnabled(true) {
}
Expr AntlrParser::getSymbol(std::string name, SymbolType type) {
Assert( isDeclared(name,type) );
+
switch( type ) {
case SYM_VARIABLE: // Functions share var namespace
case SYM_FUNCTION:
LT(1).get()->getColumn());
}
-bool AntlrParser::checkDeclaration(string varName,
+void AntlrParser::checkDeclaration(string varName,
DeclarationCheck check,
SymbolType type)
throw (antlr::SemanticException) {
+ if(!d_checksEnabled) {
+ return;
+ }
+
switch(check) {
case CHECK_DECLARED:
if( !isDeclared(varName, type) ) {
parseError("Symbol " + varName + " not declared");
- } else {
- return true;
}
+ break;
+
case CHECK_UNDECLARED:
if( isDeclared(varName, type) ) {
parseError("Symbol " + varName + " previously declared");
- } else {
- return true;
}
+ break;
+
case CHECK_NONE:
- return true;
+ break;
+
default:
Unhandled("Unknown check type!");
}
}
-bool AntlrParser::checkFunction(string name)
+void AntlrParser::checkFunction(string name)
throw (antlr::SemanticException) {
- if( !isFunction(name) ) {
+ if( d_checksEnabled && !isFunction(name) ) {
parseError("Expecting function symbol, found '" + name + "'");
}
-
- return true;
}
-bool AntlrParser::checkArity(Kind kind, unsigned int numArgs)
+void AntlrParser::checkArity(Kind kind, unsigned int numArgs)
throw (antlr::SemanticException) {
+ if(!d_checksEnabled) {
+ return;
+ }
+
unsigned int min = minArity(kind);
unsigned int max = maxArity(kind);
ss << "found " << numArgs;
parseError(ss.str());
}
- return true;
}
+void AntlrParser::enableChecks() {
+ d_checksEnabled = true;
+}
+
+void AntlrParser::disableChecks() {
+ d_checksEnabled = false;
+}
+
+
}/* CVC4::parser namespace */
}/* CVC4 namespace */
*/
virtual Expr parseExpr() = 0;
+ /** Enable semantic checks during parsing. */
+ void enableChecks();
+
+ /** Disable semantic checks during parsing. Disabling checks may lead to crashes on bad inputs. */
+ void disableChecks();
+
protected:
/**
* Checks if a symbol has been declared.
* @param name the symbol name
* @param type the symbol type
+ * @return true iff the symbol has been declared with the given type
*/
bool isDeclared(std::string name, SymbolType type = SYM_VARIABLE);
/**
- * Return true if the the declaration policy we want to enforce holds
+ * Checks if the declaration policy we want to enforce holds
* for the given symbol.
* @param name the symbol to check
* @param check the kind of check to perform
* @param type the type of the symbol
- * @return true if the check holds
- * @throws SemanticException if the check fails
+ * @throws SemanticException if checks are enabled and the check fails
*/
- bool checkDeclaration(std::string name,
+ void checkDeclaration(std::string name,
DeclarationCheck check,
SymbolType type = SYM_VARIABLE)
throw (antlr::SemanticException);
/**
- * Returns true if the given name is bound to a function.
+ * Checks whether the given name is bound to a function.
* @param name the name to check
- * @return true if name is bound to a function
- * @throws SemanticException if name is not bound to a function
+ * @throws SemanticException if checks are enabled and name is not bound to a function
*/
- bool checkFunction(std::string name) throw (antlr::SemanticException);
+ void checkFunction(std::string name) throw (antlr::SemanticException);
/**
* Check that <code>kind</code> can accept <code>numArgs</codes> arguments.
* @param kind the built-in operator to check
* @param numArgs the number of actual arguments
- * @throws SemanticException if the operator <code>kind</code> cannot be
+ * @throws SemanticException if checks are enabled and the operator <code>kind</code> cannot be
* applied to <code>numArgs</code> arguments.
*/
- bool checkArity(Kind kind, unsigned int numArgs) throw (antlr::SemanticException);
+ void checkArity(Kind kind, unsigned int numArgs) throw (antlr::SemanticException);
/**
* Returns the type for the variable with the given name.
}
}
+// bool checksEnabled();
+
private:
/** The expression manager */
/** The sort table */
SymbolTable<const Type*> d_sortTable;
+ /** Are semantic checks enabled during parsing? */
+ bool d_checksEnabled;
+
/** Lookup a symbol in the given namespace. */
Expr getSymbol(std::string var_name, SymbolType type);
};
returns [std::string id]
: x:IDENTIFIER
{ id = x->getText();
- AlwaysAssert( checkDeclaration(id, check, type) ); }
+ checkDeclaration(id, check, type); }
;
/**
std::string name;
}
: name = identifier[check,SYM_FUNCTION]
- { AlwaysAssert( checkFunction(name) );
+ { checkFunction(name);
f = getFunction(name); }
;
return getNewParser(em, lang, &input, "", false);
}
+void Parser::disableChecks() {
+ d_antlrParser->disableChecks();
+}
+
+void Parser::enableChecks() {
+ d_antlrParser->enableChecks();
+}
+
+
}/* CVC4::parser namespace */
}/* CVC4 namespace */
*/
bool done() const;
+ /** Enable semantic checks during parsing. */
+ void enableChecks();
+
+ /** Disable semantic checks during parsing. Disabling checks may lead to crashes on bad inputs. */
+ void disableChecks();
+
private:
/**
header "post_include_hpp" {
#include "parser/antlr_parser.h"
#include "expr/command.h"
-#include "util/Assert.h"
}
header "post_include_cpp" {
}
: /* a built-in operator application */
LPAREN kind = builtinOp annotatedFormulas[args] RPAREN
- { AlwaysAssert( checkArity(kind, args.size()) );
+ { checkArity(kind, args.size());
formula = mkExpr(kind,args); }
| /* A non-built-in function application */
string name;
}
: name = functionName[CHECK_DECLARED]
- { AlwaysAssert( checkFunction(name) );
+ { checkFunction(name);
fun = getFunction(name); }
;
}
: x:IDENTIFIER
{ id = x->getText();
- AlwaysAssert( checkDeclaration(id, check,type) ); }
+ checkDeclaration(id, check,type); }
;
/** The CNF conversion */
CVC4::CnfConversion d_cnfConversion;
+ /** Should we exit after parsing? */
bool parseOnly;
+ /** Should the parser do semantic checks? */
+ bool semanticChecks;
+
Options() : binary_name(),
smtcomp_mode(false),
statistics(false),
verbosity(0),
lang(parser::Parser::LANG_AUTO),
d_cnfConversion(CVC4::CNF_VAR_INTRODUCTION),
- parseOnly(false)
+ parseOnly(false),
+ semanticChecks(true)
{}
};/* struct Options */