GET_LEARNED_LITERALS_TOK { PARSER_STATE->checkThatLogicIsSet(); }
{ cmd->reset(new GetLearnedLiteralsCommand); }
| /* push */
- PUSH_TOK { PARSER_STATE->checkThatLogicIsSet(); }
+ PUSH_TOK
( k=INTEGER_LITERAL
- { unsigned num = AntlrInput::tokenToUnsigned(k);
- if(num == 0) {
- cmd->reset(new EmptyCommand());
- } else if(num == 1) {
- PARSER_STATE->pushScope(true);
- cmd->reset(new PushCommand());
- } else {
- std::unique_ptr<CommandSequence> seq(new CommandSequence());
- do {
- PARSER_STATE->pushScope(true);
- Command* push_cmd = new PushCommand();
- push_cmd->setMuted(num > 1);
- seq->addCommand(push_cmd);
- --num;
- } while(num > 0);
- cmd->reset(seq.release());
- }
+ {
+ uint32_t num = AntlrInput::tokenToUnsigned(k);
+ *cmd = PARSER_STATE->handlePush(num);
}
- | { if(PARSER_STATE->strictModeEnabled()) {
- PARSER_STATE->parseError(
- "Strict compliance mode demands an integer to be provided to "
- "PUSH. Maybe you want (push 1)?");
- } else {
- PARSER_STATE->pushScope(true);
- cmd->reset(new PushCommand());
- }
- } )
- | POP_TOK { PARSER_STATE->checkThatLogicIsSet(); }
+ | {
+ *cmd = PARSER_STATE->handlePush(std::nullopt);
+ }
+ )
+ | /* pop */
+ POP_TOK
( k=INTEGER_LITERAL
- { unsigned num = AntlrInput::tokenToUnsigned(k);
- // we don't compare num to PARSER_STATE->scopeLevel() here, since
- // when global declarations is true, the scope level of the parser
- // is not indicative of the context level.
- if(num == 0) {
- cmd->reset(new EmptyCommand());
- } else if(num == 1) {
- PARSER_STATE->popScope();
- cmd->reset(new PopCommand());
- } else {
- std::unique_ptr<CommandSequence> seq(new CommandSequence());
- do {
- PARSER_STATE->popScope();
- Command* pop_command = new PopCommand();
- pop_command->setMuted(num > 1);
- seq->addCommand(pop_command);
- --num;
- } while(num > 0);
- cmd->reset(seq.release());
- }
+ {
+ uint32_t num = AntlrInput::tokenToUnsigned(k);
+ *cmd = PARSER_STATE->handlePop(num);
}
- | { if(PARSER_STATE->strictModeEnabled()) {
- PARSER_STATE->parseError(
- "Strict compliance mode demands an integer to be provided to POP."
- "Maybe you want (pop 1)?");
- } else {
- PARSER_STATE->popScope();
- cmd->reset(new PopCommand());
- }
+ | {
+ *cmd = PARSER_STATE->handlePop(std::nullopt);
}
)
/* exit */
return ret;
}
+std::unique_ptr<Command> Smt2::handlePush(std::optional<uint32_t> nscopes)
+{
+ checkThatLogicIsSet();
+
+ if (!nscopes)
+ {
+ if (strictModeEnabled())
+ {
+ parseError(
+ "Strict compliance mode demands an integer to be provided to "
+ "(push). Maybe you want (push 1)?");
+ }
+ nscopes = 1;
+ }
+
+ for (uint32_t i = 0; i < *nscopes; i++)
+ {
+ pushScope(true);
+ }
+ return std::make_unique<PushCommand>(*nscopes);
+}
+
+std::unique_ptr<Command> Smt2::handlePop(std::optional<uint32_t> nscopes)
+{
+ checkThatLogicIsSet();
+
+ if (!nscopes)
+ {
+ if (strictModeEnabled())
+ {
+ parseError(
+ "Strict compliance mode demands an integer to be provided to "
+ "(pop). Maybe you want (pop 1)?");
+ }
+ nscopes = 1;
+ }
+
+ for (uint32_t i = 0; i < *nscopes; i++)
+ {
+ popScope();
+ }
+ return std::make_unique<PopCommand>(*nscopes);
+}
+
void Smt2::notifyNamedExpression(cvc5::Term& expr, std::string name)
{
checkUserSymbol(name);
#ifndef CVC5__PARSER__SMT2_H
#define CVC5__PARSER__SMT2_H
+#include <optional>
#include <sstream>
#include <stack>
#include <string>
*/
cvc5::Term applyParseOp(ParseOp& p, std::vector<cvc5::Term>& args);
//------------------------- end processing parse operators
+
+ /**
+ * Handles a push command.
+ *
+ * @return An instance of `PushCommand`
+ */
+ std::unique_ptr<Command> handlePush(std::optional<uint32_t> nscopes);
+ /**
+ * Handles a pop command.
+ *
+ * @return An instance of `PopCommand`
+ */
+ std::unique_ptr<Command> handlePop(std::optional<uint32_t> nscopes);
+
private:
void addArithmeticOperators();
out << "Assert(" << n << ')' << std::endl;
}
-void AstPrinter::toStreamCmdPush(std::ostream& out) const
+void AstPrinter::toStreamCmdPush(std::ostream& out, uint32_t nscopes) const
{
- out << "Push()" << std::endl;
+ out << "Push(" << nscopes << ")" << std::endl;
}
-void AstPrinter::toStreamCmdPop(std::ostream& out) const {
- out << "Pop()" << std::endl;
+void AstPrinter::toStreamCmdPop(std::ostream& out, uint32_t nscopes) const
+{
+ out << "Pop(" << nscopes << ")" << std::endl;
}
void AstPrinter::toStreamCmdCheckSat(std::ostream& out) const
void toStreamCmdAssert(std::ostream& out, Node n) const override;
/** Print push command */
- void toStreamCmdPush(std::ostream& out) const override;
+ void toStreamCmdPush(std::ostream& out, uint32_t nscopes) const override;
/** Print pop command */
- void toStreamCmdPop(std::ostream& out) const override;
+ void toStreamCmdPop(std::ostream& out, uint32_t nscopes) const override;
/** Print declare-fun command */
void toStreamCmdDeclareFunction(std::ostream& out,
printUnknownCommand(out, "assert");
}
-void Printer::toStreamCmdPush(std::ostream& out) const
+void Printer::toStreamCmdPush(std::ostream& out, uint32_t nscopes) const
{
printUnknownCommand(out, "push");
}
-void Printer::toStreamCmdPop(std::ostream& out) const
+void Printer::toStreamCmdPop(std::ostream& out, uint32_t nscopes) const
{
printUnknownCommand(out, "pop");
}
virtual void toStreamCmdAssert(std::ostream& out, Node n) const;
/** Print push command */
- virtual void toStreamCmdPush(std::ostream& out) const;
+ virtual void toStreamCmdPush(std::ostream& out, uint32_t nscopes) const;
/** Print pop command */
- virtual void toStreamCmdPop(std::ostream& out) const;
+ virtual void toStreamCmdPop(std::ostream& out, uint32_t nscopes) const;
/** Print declare-fun command */
virtual void toStreamCmdDeclareFunction(std::ostream& out,
out << "(assert " << n << ')' << std::endl;
}
-void Smt2Printer::toStreamCmdPush(std::ostream& out) const
+void Smt2Printer::toStreamCmdPush(std::ostream& out, uint32_t nscopes) const
{
- out << "(push 1)" << std::endl;
+ out << "(push " << nscopes << ")" << std::endl;
}
-void Smt2Printer::toStreamCmdPop(std::ostream& out) const
+void Smt2Printer::toStreamCmdPop(std::ostream& out, uint32_t nscopes) const
{
- out << "(pop 1)" << std::endl;
+ out << "(pop " << nscopes << ")" << std::endl;
}
void Smt2Printer::toStreamCmdCheckSat(std::ostream& out) const
void toStreamCmdAssert(std::ostream& out, Node n) const override;
/** Print push command */
- void toStreamCmdPush(std::ostream& out) const override;
+ void toStreamCmdPush(std::ostream& out, uint32_t nscopes) const override;
/** Print pop command */
- void toStreamCmdPop(std::ostream& out) const override;
+ void toStreamCmdPop(std::ostream& out, uint32_t nscopes) const override;
/** Print declare-fun command */
void toStreamCmdDeclareFunction(std::ostream& out,
/* class PushCommand */
/* -------------------------------------------------------------------------- */
+PushCommand::PushCommand(uint32_t nscopes) : d_nscopes(nscopes) {}
+
void PushCommand::invoke(cvc5::Solver* solver, SymbolManager* sm)
{
try
{
- solver->push();
+ solver->push(d_nscopes);
d_commandStatus = CommandSuccess::instance();
}
catch (exception& e)
}
}
-Command* PushCommand::clone() const { return new PushCommand(); }
+Command* PushCommand::clone() const { return new PushCommand(d_nscopes); }
std::string PushCommand::getCommandName() const { return "push"; }
void PushCommand::toStream(std::ostream& out,
size_t dag,
Language language) const
{
- Printer::getPrinter(language)->toStreamCmdPush(out);
+ Printer::getPrinter(language)->toStreamCmdPush(out, d_nscopes);
}
/* -------------------------------------------------------------------------- */
/* class PopCommand */
/* -------------------------------------------------------------------------- */
+PopCommand::PopCommand(uint32_t nscopes) : d_nscopes(nscopes) {}
+
void PopCommand::invoke(cvc5::Solver* solver, SymbolManager* sm)
{
try
{
- solver->pop();
+ solver->pop(d_nscopes);
d_commandStatus = CommandSuccess::instance();
}
catch (exception& e)
}
}
-Command* PopCommand::clone() const { return new PopCommand(); }
+Command* PopCommand::clone() const { return new PopCommand(d_nscopes); }
std::string PopCommand::getCommandName() const { return "pop"; }
void PopCommand::toStream(std::ostream& out,
size_t dag,
Language language) const
{
- Printer::getPrinter(language)->toStreamCmdPop(out);
+ Printer::getPrinter(language)->toStreamCmdPop(out, d_nscopes);
}
/* -------------------------------------------------------------------------- */
class CVC5_EXPORT PushCommand : public Command
{
public:
+ PushCommand(uint32_t nscopes);
+
void invoke(cvc5::Solver* solver, SymbolManager* sm) override;
Command* clone() const override;
std::string getCommandName() const override;
size_t dag = 1,
internal::Language language =
internal::Language::LANG_AUTO) const override;
+
+ private:
+ uint32_t d_nscopes;
}; /* class PushCommand */
class CVC5_EXPORT PopCommand : public Command
{
public:
+ PopCommand(uint32_t nscopes);
+
void invoke(cvc5::Solver* solver, SymbolManager* sm) override;
Command* clone() const override;
std::string getCommandName() const override;
size_t dag = 1,
internal::Language language =
internal::Language::LANG_AUTO) const override;
+
+ private:
+ uint32_t d_nscopes;
}; /* class PopCommand */
class CVC5_EXPORT DeclarationDefinitionCommand : public Command