GCC Code Coverage Report
Directory: . Exec Total Coverage
File: src/main/command_executor.h Lines: 5 5 100.0 %
Date: 2021-09-18 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
25
namespace cvc5 {
26
27
class Command;
28
29
namespace main {
30
31
class CommandExecutor
32
{
33
 protected:
34
  /**
35
   * The solver object, which is allocated by this class and is used for
36
   * executing most commands (e.g. check-sat).
37
   */
38
  std::unique_ptr<api::Solver>& d_solver;
39
  /**
40
   * The symbol manager, which is allocated by this class. This manages
41
   * all things related to definitions of symbols and their impact on behaviors
42
   * for commands (e.g. get-unsat-core, get-model, get-assignment), as well
43
   * as tracking expression names. Note the symbol manager is independent from
44
   * the parser, which uses this symbol manager given a text input.
45
   *
46
   * Certain commands (e.g. reset-assertions) have a specific impact on the
47
   * symbol manager.
48
   */
49
  std::unique_ptr<SymbolManager> d_symman;
50
51
  api::Result d_result;
52
53
 public:
54
  CommandExecutor(std::unique_ptr<api::Solver>& solver);
55
56
  virtual ~CommandExecutor();
57
58
  /**
59
   * Executes a command. Recursively handles if cmd is a command
60
   * sequence.  Eventually uses doCommandSingleton (which can be
61
   * overridden by a derived class).
62
   */
63
  bool doCommand(cvc5::Command* cmd);
64
65
295756
  bool doCommand(std::unique_ptr<cvc5::Command>& cmd)
66
  {
67
295756
    return doCommand(cmd.get());
68
  }
69
70
  /** Get a pointer to the solver object owned by this CommandExecutor. */
71
6172
  api::Solver* getSolver() { return d_solver.get(); }
72
73
  /** Get a pointer to the symbol manager owned by this CommandExecutor */
74
6172
  SymbolManager* getSymbolManager() { return d_symman.get(); }
75
76
6114
  api::Result getResult() const { return d_result; }
77
  void reset();
78
79
  /** Store the current options as the original options */
80
  void storeOptionsAsOriginal();
81
82
  /**
83
   * Prints statistics to an output stream.
84
   * Checks whether statistics should be printed according to the options.
85
   * Thus, this method can always be called without checking the options.
86
   */
87
  virtual void printStatistics(std::ostream& out) const;
88
89
  /**
90
   * Safely prints statistics to a file descriptor.
91
   * This method is safe to be used within a signal handler.
92
   * Checks whether statistics should be printed according to the options.
93
   * Thus, this method can always be called without checking the options.
94
   */
95
  void printStatisticsSafe(int fd) const;
96
97
  void flushOutputStreams();
98
99
protected:
100
  /** Executes treating cmd as a singleton */
101
 virtual bool doCommandSingleton(cvc5::Command* cmd);
102
103
private:
104
  CommandExecutor();
105
106
}; /* class CommandExecutor */
107
108
bool solverInvoke(api::Solver* solver,
109
                  SymbolManager* sm,
110
                  Command* cmd,
111
                  std::ostream& out);
112
113
}  // namespace main
114
}  // namespace cvc5
115
116
#endif /* CVC5__MAIN__COMMAND_EXECUTOR_H */