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 |
|
api::Result d_result; |
57 |
|
|
58 |
|
public: |
59 |
|
CommandExecutor(const Options& options); |
60 |
|
|
61 |
|
virtual ~CommandExecutor(); |
62 |
|
|
63 |
|
/** |
64 |
|
* Executes a command. Recursively handles if cmd is a command |
65 |
|
* sequence. Eventually uses doCommandSingleton (which can be |
66 |
|
* overridden by a derived class). |
67 |
|
*/ |
68 |
|
bool doCommand(cvc5::Command* cmd); |
69 |
|
|
70 |
296087 |
bool doCommand(std::unique_ptr<cvc5::Command>& cmd) |
71 |
|
{ |
72 |
296087 |
return doCommand(cmd.get()); |
73 |
|
} |
74 |
|
|
75 |
|
/** Get a pointer to the solver object owned by this CommandExecutor. */ |
76 |
6131 |
api::Solver* getSolver() { return d_solver.get(); } |
77 |
|
|
78 |
|
/** Get a pointer to the symbol manager owned by this CommandExecutor */ |
79 |
6131 |
SymbolManager* getSymbolManager() { return d_symman.get(); } |
80 |
|
|
81 |
6073 |
api::Result getResult() const { return d_result; } |
82 |
|
void reset(); |
83 |
|
|
84 |
12262 |
SmtEngine* getSmtEngine() const { return d_solver->getSmtEngine(); } |
85 |
|
|
86 |
|
/** |
87 |
|
* Prints statistics to an output stream. |
88 |
|
* Checks whether statistics should be printed according to the options. |
89 |
|
* Thus, this method can always be called without checking the options. |
90 |
|
*/ |
91 |
|
virtual void printStatistics(std::ostream& out) const; |
92 |
|
|
93 |
|
/** |
94 |
|
* Safely prints statistics to a file descriptor. |
95 |
|
* This method is safe to be used within a signal handler. |
96 |
|
* Checks whether statistics should be printed according to the options. |
97 |
|
* Thus, this method can always be called without checking the options. |
98 |
|
*/ |
99 |
|
void printStatisticsSafe(int fd) const; |
100 |
|
|
101 |
|
void flushOutputStreams(); |
102 |
|
|
103 |
|
protected: |
104 |
|
/** Executes treating cmd as a singleton */ |
105 |
|
virtual bool doCommandSingleton(cvc5::Command* cmd); |
106 |
|
|
107 |
|
private: |
108 |
|
CommandExecutor(); |
109 |
|
|
110 |
|
}; /* class CommandExecutor */ |
111 |
|
|
112 |
|
bool solverInvoke(api::Solver* solver, |
113 |
|
SymbolManager* sm, |
114 |
|
Command* cmd, |
115 |
|
std::ostream* out); |
116 |
|
|
117 |
|
} // namespace main |
118 |
|
} // namespace cvc5 |
119 |
|
|
120 |
|
#endif /* CVC5__MAIN__COMMAND_EXECUTOR_H */ |