void Parser::checkDeclaration(const std::string& varName,
DeclarationCheck check,
- SymbolType type)
+ SymbolType type,
+ std::string notes)
throw(ParserException) {
if(!d_checksEnabled) {
return;
case CHECK_DECLARED:
if( !isDeclared(varName, type) ) {
parseError("Symbol " + varName + " not declared as a " +
- (type == SYM_VARIABLE ? "variable" : "type"));
+ (type == SYM_VARIABLE ? "variable" : "type") +
+ (notes.size() == 0 ? notes : "\n" + notes));
}
break;
case CHECK_UNDECLARED:
if( isDeclared(varName, type) ) {
parseError("Symbol " + varName + " previously declared as a " +
- (type == SYM_VARIABLE ? "variable" : "type"));
+ (type == SYM_VARIABLE ? "variable" : "type") +
+ (notes.size() == 0 ? notes : "\n" + notes));
}
break;
* @throws ParserException if checks are enabled and the check fails
*/
void checkDeclaration(const std::string& name, DeclarationCheck check,
- SymbolType type = SYM_VARIABLE) throw(ParserException);
+ SymbolType type = SYM_VARIABLE,
+ std::string notes = "") throw(ParserException);
/**
* Reserve a symbol at the assertion level.
return getExprManager()->mkConst(AbstractValue(Integer(name.substr(1))));
}
+ /**
+ * Smt2 parser provides its own checkDeclaration, which does the
+ * same as the base, but with some more helpful errors.
+ */
+ void checkDeclaration(const std::string& name, DeclarationCheck check,
+ SymbolType type = SYM_VARIABLE,
+ std::string notes = "") throw(ParserException) {
+ // if the symbol is something like "-1", we'll give the user a helpful
+ // syntax hint. (-1 is a valid identifier in SMT-LIB, NOT unary minus.)
+ if( check != CHECK_DECLARED ||
+ name[0] != '-' ||
+ name.find_first_not_of("0123456789", 1) != std::string::npos ) {
+ this->Parser::checkDeclaration(name, check, type, notes);
+ return;
+ }
+
+ std::stringstream ss;
+ ss << notes
+ << "You may have intended to apply unary minus: `(- "
+ << name.substr(1)
+ << ")'\n";
+ this->Parser::checkDeclaration(name, check, type, ss.str());
+ }
+
private:
void addArithmeticOperators();