GCC Code Coverage Report
Directory: . Exec Total Coverage
File: src/main/command_executor.h Lines: 6 6 100.0 %
Date: 2021-08-01 Branches: 0 0 0.0 %

Line Exec Source
1
/******************************************************************************
2
 * Top contributors (to current version):
3
 *   Andrew Reynolds, Kshitij Bansal, Gereon Kremer
4
 *
5
 * This file is part of the cvc5 project.
6
 *
7
 * Copyright (c) 2009-2021 by the authors listed in the file AUTHORS
8
 * in the top-level source directory and their institutional affiliations.
9
 * All rights reserved.  See the file COPYING in the top-level source
10
 * directory for licensing information.
11
 * ****************************************************************************
12
 *
13
 * An additional layer between commands and invoking them.
14
 */
15
16
#ifndef CVC5__MAIN__COMMAND_EXECUTOR_H
17
#define CVC5__MAIN__COMMAND_EXECUTOR_H
18
19
#include <iosfwd>
20
#include <string>
21
22
#include "api/cpp/cvc5.h"
23
#include "expr/symbol_manager.h"
24
#include "options/options.h"
25
26
namespace cvc5 {
27
28
class Command;
29
30
namespace smt {
31
class SmtEngine;
32
}
33
34
namespace main {
35
36
class CommandExecutor
37
{
38
 protected:
39
  /**
40
   * The solver object, which is allocated by this class and is used for
41
   * executing most commands (e.g. check-sat).
42
   */
43
  std::unique_ptr<api::Solver> d_solver;
44
  /**
45
   * The symbol manager, which is allocated by this class. This manages
46
   * all things related to definitions of symbols and their impact on behaviors
47
   * for commands (e.g. get-unsat-core, get-model, get-assignment), as well
48
   * as tracking expression names. Note the symbol manager is independent from
49
   * the parser, which uses this symbol manager given a text input.
50
   *
51
   * Certain commands (e.g. reset-assertions) have a specific impact on the
52
   * symbol manager.
53
   */
54
  std::unique_ptr<SymbolManager> d_symman;
55
  /**
56
   * A pointer to the original options from the driver. Contain options as
57
   * parsed from the command line. Used when the solver is reset.
58
   */
59
  const Options* d_driverOptions;
60
61
  api::Result d_result;
62
63
 public:
64
  CommandExecutor(const Options& options);
65
66
  virtual ~CommandExecutor();
67
68
  /**
69
   * Executes a command. Recursively handles if cmd is a command
70
   * sequence.  Eventually uses doCommandSingleton (which can be
71
   * overridden by a derived class).
72
   */
73
  bool doCommand(cvc5::Command* cmd);
74
75
298650
  bool doCommand(std::unique_ptr<cvc5::Command>& cmd)
76
  {
77
298650
    return doCommand(cmd.get());
78
  }
79
80
  /** Get a pointer to the solver object owned by this CommandExecutor. */
81
6121
  api::Solver* getSolver() { return d_solver.get(); }
82
83
  /** Get a pointer to the symbol manager owned by this CommandExecutor */
84
6121
  SymbolManager* getSymbolManager() { return d_symman.get(); }
85
86
6063
  api::Result getResult() const { return d_result; }
87
  void reset();
88
89
12242
  SmtEngine* getSmtEngine() const { return d_solver->getSmtEngine(); }
90
91
  /**
92
   * Prints statistics to an output stream.
93
   * Checks whether statistics should be printed according to the options.
94
   * Thus, this method can always be called without checking the options.
95
   */
96
  virtual void printStatistics(std::ostream& out) const;
97
98
  /**
99
   * Safely prints statistics to a file descriptor.
100
   * This method is safe to be used within a signal handler.
101
   * Checks whether statistics should be printed according to the options.
102
   * Thus, this method can always be called without checking the options.
103
   */
104
  void printStatisticsSafe(int fd) const;
105
106
  void flushOutputStreams();
107
108
protected:
109
  /** Executes treating cmd as a singleton */
110
 virtual bool doCommandSingleton(cvc5::Command* cmd);
111
112
private:
113
  CommandExecutor();
114
115
}; /* class CommandExecutor */
116
117
bool solverInvoke(api::Solver* solver,
118
                  SymbolManager* sm,
119
                  Command* cmd,
120
                  std::ostream* out);
121
122
}  // namespace main
123
}  // namespace cvc5
124
125
#endif /* CVC5__MAIN__COMMAND_EXECUTOR_H */