#include <stdint.h>
#include <cassert>
+
+#include "base/ptr_closer.h"
#include "options/set_language.h"
#include "parser/antlr_tracing.h"
#include "parser/parser.h"
#include <vector>
#include "base/output.h"
+#include "base/ptr_closer.h"
#include "expr/expr.h"
#include "expr/kind.h"
#include "expr/type.h"
* Parses a command (the whole benchmark)
* @return the command of the benchmark
*/
-parseCommand returns [CVC4::Command* cmd = NULL]
- : c=command { $cmd = c; }
+parseCommand returns [CVC4::Command* cmd_return = NULL]
+@declarations {
+ CVC4::PtrCloser<CVC4::Command> cmd;
+}
+@after {
+ cmd_return = cmd.release();
+}
+ : c=command[&cmd]
| LPAREN IDENTIFIER
{ std::string s = AntlrInput::tokenText($IDENTIFIER);
- if(s == "benchmark") {
- PARSER_STATE->parseError("In CVC4 presentation language mode, but SMT-LIBv1 format detected. Use --lang smt1 for SMT-LIBv1 support.");
+ if(s == "benchmark") {
+ PARSER_STATE->parseError(
+ "In CVC4 presentation language mode, but SMT-LIBv1 format "
+ "detected. Use --lang smt1 for SMT-LIBv1 support.");
} else if(s == "set" || s == "get" || s == "declare" ||
s == "define" || s == "assert") {
- PARSER_STATE->parseError("In CVC4 presentation language mode, but SMT-LIB format detected. Use --lang smt for SMT-LIB support.");
+ PARSER_STATE->parseError(
+ "In CVC4 presentation language mode, but SMT-LIB format detected. "
+ "Use --lang smt for SMT-LIB support.");
} else {
- PARSER_STATE->parseError("A CVC4 presentation language command cannot begin with a parenthesis; expected command name.");
+ PARSER_STATE->parseError(
+ "A CVC4 presentation language command cannot begin with a "
+ "parenthesis; expected command name.");
}
}
- | EOF { $cmd = NULL; }
+ | EOF
;
/**
* Matches a command of the input. If a declaration, it will return an empty
* command.
*/
-command returns [CVC4::Command* cmd = NULL]
+command [CVC4::PtrCloser<CVC4::Command>* cmd]
: ( mainCommand[cmd] SEMICOLON
| SEMICOLON
| LET_TOK { PARSER_STATE->pushScope(); }
- typeOrVarLetDecl[CHECK_DECLARED] ( COMMA typeOrVarLetDecl[CHECK_DECLARED] )*
- IN_TOK c=command
- { $cmd = c;
- PARSER_STATE->popScope();
- }
+ typeOrVarLetDecl[CHECK_DECLARED] (
+ COMMA typeOrVarLetDecl[CHECK_DECLARED] )*
+ IN_TOK command[cmd]
+ { PARSER_STATE->popScope(); }
)
- { if($cmd == NULL) {
- cmd = new EmptyCommand();
+ { if(!(*cmd)) {
+ cmd->reset(new EmptyCommand());
}
}
| IDENTIFIER SEMICOLON
: letDecl | typeLetDecl[check]
;
-mainCommand[CVC4::Command*& cmd]
+mainCommand[CVC4::PtrCloser<CVC4::Command>* cmd]
@init {
Expr f;
SExpr sexpr;
std::string s;
}
/* our bread & butter */
- : ASSERT_TOK formula[f] { cmd = new AssertCommand(f); }
-
- | QUERY_TOK formula[f] { cmd = new QueryCommand(f); }
- | CHECKSAT_TOK formula[f]? { cmd = f.isNull() ? new CheckSatCommand() : new CheckSatCommand(f); }
+ : ASSERT_TOK formula[f] { cmd->reset(new AssertCommand(f)); }
+ | QUERY_TOK formula[f] { cmd->reset(new QueryCommand(f)); }
+ | CHECKSAT_TOK formula[f]?
+ { cmd->reset(f.isNull() ? new CheckSatCommand() : new CheckSatCommand(f)); }
/* options */
| OPTION_TOK
( str[s] | IDENTIFIER { s = AntlrInput::tokenText($IDENTIFIER); } )
( symbolicExpr[sexpr]
{ if(s == "logic") {
- cmd = new SetBenchmarkLogicCommand(sexpr.getValue());
+ cmd->reset(new SetBenchmarkLogicCommand(sexpr.getValue()));
} else {
- cmd = new SetOptionCommand(s, sexpr);
+ cmd->reset(new SetOptionCommand(s, sexpr));
}
}
- | TRUE_TOK { cmd = new SetOptionCommand(s, SExpr("true")); }
- | FALSE_TOK { cmd = new SetOptionCommand(s, SExpr("false")); }
- | { cmd = new SetOptionCommand(s, SExpr("true")); }
+ | TRUE_TOK { cmd->reset(new SetOptionCommand(s, SExpr("true"))); }
+ | FALSE_TOK { cmd->reset(new SetOptionCommand(s, SExpr("false"))); }
+ | { cmd->reset(new SetOptionCommand(s, SExpr("true"))); }
)
/* push / pop */
- | PUSH_TOK ( k=numeral { cmd = REPEAT_COMMAND(k, PushCommand()); }
- | { cmd = new PushCommand(); } )
- | POP_TOK ( k=numeral { cmd = REPEAT_COMMAND(k, PopCommand()); }
- | { cmd = new PopCommand(); } )
+ | PUSH_TOK ( k=numeral { cmd->reset(REPEAT_COMMAND(k, PushCommand())); }
+ | { cmd->reset(new PushCommand()); } )
+ | POP_TOK ( k=numeral { cmd->reset(REPEAT_COMMAND(k, PopCommand())); }
+ | { cmd->reset(new PopCommand()); } )
| POPTO_TOK k=numeral?
{ UNSUPPORTED("POPTO command"); }
{ UNSUPPORTED("POPTO_SCOPE command"); }
| RESET_TOK
- { cmd = new ResetCommand();
+ { cmd->reset(new ResetCommand());
PARSER_STATE->reset();
}
| RESET_TOK ASSERTIONS_TOK
- { cmd = new ResetAssertionsCommand();
+ { cmd->reset(new ResetAssertionsCommand());
PARSER_STATE->reset();
}
( COMMA datatypeDef[dts] )*
END_TOK
{ PARSER_STATE->popScope();
- cmd = new DatatypeDeclarationCommand(PARSER_STATE->mkMutualDatatypeTypes(dts)); }
+ cmd->reset(new DatatypeDeclarationCommand(
+ PARSER_STATE->mkMutualDatatypeTypes(dts)));
+ }
| CONTEXT_TOK
( ( str[s] | IDENTIFIER { s = AntlrInput::tokenText($IDENTIFIER); } )
{ UNSUPPORTED("GET_OP command"); }
| GET_VALUE_TOK formula[f]
- { cmd = new GetValueCommand(f); }
+ { cmd->reset(new GetValueCommand(f)); }
- | SUBSTITUTE_TOK identifier[id,CHECK_NONE,SYM_VARIABLE] COLON type[t,CHECK_DECLARED] EQUAL_TOK
- formula[f] LBRACKET identifier[id,CHECK_NONE,SYM_VARIABLE] ASSIGN_TOK formula[f] RBRACKET
+ | SUBSTITUTE_TOK identifier[id,CHECK_NONE,SYM_VARIABLE] COLON
+ type[t,CHECK_DECLARED] EQUAL_TOK formula[f] LBRACKET
+ identifier[id,CHECK_NONE,SYM_VARIABLE] ASSIGN_TOK formula[f] RBRACKET
{ UNSUPPORTED("SUBSTITUTE command"); }
/* Like the --debug command line option, DBG turns on both tracing
| HELP_TOK
( ( str[s] | IDENTIFIER { s = AntlrInput::tokenText($IDENTIFIER); } )
{ Message() << "No help available for `" << s << "'." << std::endl; }
- | { Message() << "Please use --help at the command line for help." << std::endl; }
- )
+ | { Message() << "Please use --help at the command line for help."
+ << std::endl; }
+ )
| TRANSFORM_TOK formula[f]
- { cmd = new SimplifyCommand(f); }
+ { cmd->reset(new SimplifyCommand(f)); }
| PRINT_TOK formula[f]
{ UNSUPPORTED("PRINT command"); }
| ECHO_TOK
( simpleSymbolicExpr[sexpr]
- { cmd = new EchoCommand(sexpr.getValue()); }
- | { cmd = new EchoCommand(); }
+ { cmd->reset(new EchoCommand(sexpr.getValue())); }
+ | { cmd->reset(new EchoCommand()); }
)
| EXIT_TOK
- { cmd = new QuitCommand(); }
+ { cmd->reset(new QuitCommand()); }
| INCLUDE_TOK
( ( str[s] | IDENTIFIER { s = AntlrInput::tokenText($IDENTIFIER); } )
)
| DUMP_PROOF_TOK
- { cmd = new GetProofCommand(); }
+ { cmd->reset(new GetProofCommand()); }
| DUMP_UNSAT_CORE_TOK
- { cmd = new GetUnsatCoreCommand(); }
+ { cmd->reset(new GetUnsatCoreCommand()); }
| ( DUMP_ASSUMPTIONS_TOK
| DUMP_SIG_TOK
/* these are all synonyms */
| ( WHERE_TOK | ASSERTIONS_TOK | ASSUMPTIONS_TOK )
- { cmd = new GetAssertionsCommand(); }
+ { cmd->reset(new GetAssertionsCommand()); }
| COUNTEREXAMPLE_TOK
- { cmd = new GetModelCommand; }
+ { cmd->reset(new GetModelCommand); }
| COUNTERMODEL_TOK
- { cmd = new GetModelCommand; }
+ { cmd->reset(new GetModelCommand); }
| ARITH_VAR_ORDER_TOK LPAREN formula[f] ( COMMA formula[f] )* RPAREN
{ UNSUPPORTED("ARITH_VAR_ORDER command"); }
/**
* Match a top-level declaration.
*/
-toplevelDeclaration[CVC4::Command*& cmd]
+toplevelDeclaration[CVC4::PtrCloser<CVC4::Command>* cmd]
@init {
std::vector<std::string> ids;
Type t;
- Debug("parser-extra") << "declaration: " << AntlrInput::tokenText(LT(1)) << std::endl;
+ Debug("parser-extra") << "declaration: " << AntlrInput::tokenText(LT(1))
+ << std::endl;
}
: identifierList[ids,CHECK_NONE,SYM_VARIABLE] COLON
( declareVariables[cmd,t,ids,true]
*/
boundVarDecl[std::vector<std::string>& ids, CVC4::Type& t]
@init {
- Command* local_cmd = NULL;
+ CVC4::PtrCloser<Command> local_cmd;
}
- : identifierList[ids,CHECK_NONE,SYM_VARIABLE] COLON declareVariables[local_cmd,t,ids,false]
+ : identifierList[ids,CHECK_NONE,SYM_VARIABLE] COLON
+ declareVariables[&local_cmd,t,ids,false]
;
/**
* because type declarations are always top-level, except for
* type-lets, which don't use this rule.
*/
-declareTypes[CVC4::Command*& cmd, const std::vector<std::string>& idList]
+declareTypes[CVC4::PtrCloser<CVC4::Command>* cmd,
+ const std::vector<std::string>& idList]
@init {
Type t;
}
/* A sort declaration (e.g., "T : TYPE") */
: TYPE_TOK
- { DeclarationSequence* seq = new DeclarationSequence();
+ { CVC4::PtrCloser<DeclarationSequence> seq(new DeclarationSequence());
for(std::vector<std::string>::const_iterator i = idList.begin();
- i != idList.end();
- ++i) {
+ i != idList.end(); ++i) {
// Don't allow a type variable to clash with a previously
// declared type variable, however a type variable and a
// non-type variable can clash unambiguously. Break from CVC3
Command* decl = new DeclareTypeCommand(*i, 0, sort);
seq->addCommand(decl);
}
- cmd = seq;
+ cmd->reset(seq.release());
}
/* A type alias "T : TYPE = foo..." */
* permitted and "cmd" is output. If topLevel is false, bound vars
* are created
*/
-declareVariables[CVC4::Command*& cmd, CVC4::Type& t, const std::vector<std::string>& idList, bool topLevel]
+declareVariables[CVC4::PtrCloser<CVC4::Command>* cmd, CVC4::Type& t,
+ const std::vector<std::string>& idList, bool topLevel]
@init {
Expr f;
Debug("parser-extra") << "declType: " << AntlrInput::tokenText(LT(1)) << std::endl;
}
/* A variable declaration (or definition) */
: type[t,CHECK_DECLARED] ( EQUAL_TOK formula[f] )?
- { DeclarationSequence* seq = NULL;
+ { CVC4::PtrCloser<DeclarationSequence> seq;
if(topLevel) {
- cmd = seq = new DeclarationSequence();
+ seq.reset(new DeclarationSequence());
}
if(f.isNull()) {
- Debug("parser") << "working on " << idList.front() << " : " << t << std::endl;
+ Debug("parser") << "working on " << idList.front() << " : " << t
+ << std::endl;
// CVC language allows redeclaration of variables if types are the same
for(std::vector<std::string>::const_iterator i = idList.begin(),
i_end = idList.end();
seq->addCommand(decl);
}
}
+ if(topLevel) {
+ cmd->reset(new DeclarationSequence());
+ }
}
;
constructorDef[CVC4::Datatype& type]
@init {
std::string id;
- CVC4::DatatypeConstructor* ctor = NULL;
+ CVC4::PtrCloser<CVC4::DatatypeConstructor> ctor;
}
: identifier[id,CHECK_UNDECLARED,SYM_SORT]
{ // make the tester
std::string testerId("is_");
testerId.append(id);
PARSER_STATE->checkDeclaration(testerId, CHECK_UNDECLARED, SYM_SORT);
- ctor = new CVC4::DatatypeConstructor(id, testerId);
+ ctor.reset(new CVC4::DatatypeConstructor(id, testerId));
}
( LPAREN
- selector[*ctor]
- ( COMMA selector[*ctor] )*
+ selector[&ctor]
+ ( COMMA selector[&ctor] )*
RPAREN
)?
{ // make the constructor
- type.addConstructor(*ctor);
+ type.addConstructor(*ctor.get());
Debug("parser-idt") << "constructor: " << id.c_str() << std::endl;
- delete ctor;
}
;
-selector[CVC4::DatatypeConstructor& ctor]
+selector[CVC4::PtrCloser<CVC4::DatatypeConstructor>* ctor]
@init {
std::string id;
Type t, t2;
}
: identifier[id,CHECK_UNDECLARED,SYM_SORT] COLON type[t,CHECK_NONE]
- { ctor.addArg(id, t);
+ { (*ctor)->addArg(id, t);
Debug("parser-idt") << "selector: " << id.c_str() << std::endl;
}
;