summaryrefslogtreecommitdiff
path: root/src/main/command_executor.h
blob: d4498664015d93a251533efeb6de331fd16169cd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
/******************************************************************************
 * Top contributors (to current version):
 *   Andrew Reynolds, Kshitij Bansal, Gereon Kremer
 *
 * This file is part of the cvc5 project.
 *
 * Copyright (c) 2009-2021 by the authors listed in the file AUTHORS
 * in the top-level source directory and their institutional affiliations.
 * All rights reserved.  See the file COPYING in the top-level source
 * directory for licensing information.
 * ****************************************************************************
 *
 * An additional layer between commands and invoking them.
 */

#ifndef CVC5__MAIN__COMMAND_EXECUTOR_H
#define CVC5__MAIN__COMMAND_EXECUTOR_H

#include <iosfwd>
#include <string>

#include "api/cpp/cvc5.h"
#include "expr/symbol_manager.h"
#include "options/options.h"

namespace cvc5 {

class Command;

namespace smt {
class SmtEngine;
}

namespace main {

class CommandExecutor
{
 protected:
  /**
   * The solver object, which is allocated by this class and is used for
   * executing most commands (e.g. check-sat).
   */
  std::unique_ptr<api::Solver>& d_solver;
  /**
   * The symbol manager, which is allocated by this class. This manages
   * all things related to definitions of symbols and their impact on behaviors
   * for commands (e.g. get-unsat-core, get-model, get-assignment), as well
   * as tracking expression names. Note the symbol manager is independent from
   * the parser, which uses this symbol manager given a text input.
   *
   * Certain commands (e.g. reset-assertions) have a specific impact on the
   * symbol manager.
   */
  std::unique_ptr<SymbolManager> d_symman;

  api::Result d_result;

 public:
  CommandExecutor(std::unique_ptr<api::Solver>& solver);

  virtual ~CommandExecutor();

  /**
   * Executes a command. Recursively handles if cmd is a command
   * sequence.  Eventually uses doCommandSingleton (which can be
   * overridden by a derived class).
   */
  bool doCommand(cvc5::Command* cmd);

  bool doCommand(std::unique_ptr<cvc5::Command>& cmd)
  {
    return doCommand(cmd.get());
  }

  /** Get a pointer to the solver object owned by this CommandExecutor. */
  api::Solver* getSolver() { return d_solver.get(); }

  /** Get a pointer to the symbol manager owned by this CommandExecutor */
  SymbolManager* getSymbolManager() { return d_symman.get(); }

  api::Result getResult() const { return d_result; }
  void reset();

  SmtEngine* getSmtEngine() const { return d_solver->getSmtEngine(); }

  /** Get the current options from the solver */
  Options& getOptions();
  /** Store the current options as the original options */
  void storeOptionsAsOriginal();

  /**
   * Prints statistics to an output stream.
   * Checks whether statistics should be printed according to the options.
   * Thus, this method can always be called without checking the options.
   */
  virtual void printStatistics(std::ostream& out) const;

  /**
   * Safely prints statistics to a file descriptor.
   * This method is safe to be used within a signal handler.
   * Checks whether statistics should be printed according to the options.
   * Thus, this method can always be called without checking the options.
   */
  void printStatisticsSafe(int fd) const;

  void flushOutputStreams();

protected:
  /** Executes treating cmd as a singleton */
 virtual bool doCommandSingleton(cvc5::Command* cmd);

private:
  CommandExecutor();

}; /* class CommandExecutor */

bool solverInvoke(api::Solver* solver,
                  SymbolManager* sm,
                  Command* cmd,
                  std::ostream& out);

}  // namespace main
}  // namespace cvc5

#endif /* CVC5__MAIN__COMMAND_EXECUTOR_H */
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback