summaryrefslogtreecommitdiff
path: root/src/expr/command.h
blob: 6a4bb67ed53a1bf96365e5f00a09d326339614fe (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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
/*********************                                                        */
/** command.h
 ** Original author: mdeters
 ** Major contributors: dejan
 ** Minor contributors (to current version): cconway
 ** This file is part of the CVC4 prototype.
 ** Copyright (c) 2009, 2010  The Analysis of Computer Systems Group (ACSys)
 ** Courant Institute of Mathematical Sciences
 ** New York University
 ** See the file COPYING in the top-level source directory for licensing
 ** information.
 **
 ** Implementation of the command pattern on SmtEngines.  Command
 ** objects are generated by the parser (typically) to implement the
 ** commands in parsed input (see Parser::parseNextCommand()), or by
 ** client code.
 **/

#include "cvc4_public.h"

#ifndef __CVC4__COMMAND_H
#define __CVC4__COMMAND_H

#include <iostream>
#include <sstream>
#include <string>
#include <vector>

#include "expr/expr.h"
#include "util/result.h"

namespace CVC4 {

class SmtEngine;
class Command;

inline std::ostream& operator<<(std::ostream&, const Command&) CVC4_PUBLIC;
std::ostream& operator<<(std::ostream&, const Command*) CVC4_PUBLIC;

/** The status an SMT benchmark can have */
enum BenchmarkStatus {
  /** Benchmark is satisfiable */
  SMT_SATISFIABLE,
  /** Benchmark is unsatisfiable */
  SMT_UNSATISFIABLE,
  /** The status of the benchmark is unknown */
  SMT_UNKNOWN
};

inline std::ostream& operator<<(std::ostream& out,
                                BenchmarkStatus status)
  CVC4_PUBLIC;

class CVC4_PUBLIC Command {
public:
  virtual void invoke(CVC4::SmtEngine* smt_engine) = 0;
  virtual ~Command() {};
  virtual void toStream(std::ostream&) const = 0;
  std::string toString() const;
};/* class Command */

class CVC4_PUBLIC EmptyCommand : public Command {
public:
  EmptyCommand(std::string name = "");
  void invoke(CVC4::SmtEngine* smtEngine);
  void toStream(std::ostream& out) const;
private:
  std::string d_name;
};/* class EmptyCommand */

class CVC4_PUBLIC AssertCommand : public Command {
public:
  AssertCommand(const BoolExpr& e);
  void invoke(CVC4::SmtEngine* smtEngine);
  void toStream(std::ostream& out) const;
protected:
  BoolExpr d_expr;
};/* class AssertCommand */

class CVC4_PUBLIC PushCommand : public Command {
public:
  void invoke(CVC4::SmtEngine* smtEngine);
  void toStream(std::ostream& out) const;
};/* class PushCommand */

class CVC4_PUBLIC PopCommand : public Command {
public:
  void invoke(CVC4::SmtEngine* smtEngine);
  void toStream(std::ostream& out) const;
};/* class PopCommand */


class CVC4_PUBLIC DeclarationCommand : public EmptyCommand {
public:
  DeclarationCommand(const std::vector<std::string>& ids, const Type* t);
  void toStream(std::ostream& out) const;
protected:
  std::vector<std::string> d_declaredSymbols;
};

class CVC4_PUBLIC CheckSatCommand : public Command {
public:
  CheckSatCommand(const BoolExpr& expr);
  void invoke(SmtEngine* smt);
  Result getResult();
  void toStream(std::ostream& out) const;
protected:
  BoolExpr d_expr;
  Result d_result;
};/* class CheckSatCommand */

class CVC4_PUBLIC QueryCommand : public Command {
public:
  QueryCommand(const BoolExpr& e);
  void invoke(SmtEngine* smt);
  Result getResult();
  void toStream(std::ostream& out) const;
protected:
  BoolExpr d_expr;
  Result d_result;
};/* class QueryCommand */

class CVC4_PUBLIC SetBenchmarkStatusCommand : public Command {
public:
  SetBenchmarkStatusCommand(BenchmarkStatus status);
  void invoke(SmtEngine* smt);
  void toStream(std::ostream& out) const;
protected:
  BenchmarkStatus d_status;
};/* class SetBenchmarkStatusCommand */


class CVC4_PUBLIC SetBenchmarkLogicCommand : public Command {
public:
  SetBenchmarkLogicCommand(std::string logic);
  void invoke(SmtEngine* smt);
  void toStream(std::ostream& out) const;
protected:
  std::string d_logic;
};/* class SetBenchmarkLogicCommand */

class CVC4_PUBLIC CommandSequence : public Command {
public:
  CommandSequence();
  ~CommandSequence();
  void invoke(SmtEngine* smt);
  void addCommand(Command* cmd);
  void toStream(std::ostream& out) const;

  typedef std::vector<Command*>::iterator iterator;
  typedef std::vector<Command*>::const_iterator const_iterator;

  const_iterator begin() const { return d_commandSequence.begin(); }
  const_iterator end() const { return d_commandSequence.end(); }

  iterator begin() { return d_commandSequence.begin(); }
  iterator end() { return d_commandSequence.end(); }

private:
  /** All the commands to be executed (in sequence) */
  std::vector<Command*> d_commandSequence;
  /** Next command to be executed */
  unsigned int d_index;
};/* class CommandSequence */

}/* CVC4 namespace */

/* =========== inline function definitions =========== */

#include "smt/smt_engine.h"

namespace CVC4 {

inline std::ostream& operator<<(std::ostream& out, const Command& c) {
  c.toStream(out);
  return out;
}

/* class Command */

inline std::string Command::toString() const {
  std::stringstream ss;
  toStream(ss);
  return ss.str();
}

/* class EmptyCommand */

inline EmptyCommand::EmptyCommand(std::string name) :
  d_name(name) {
}

inline void EmptyCommand::invoke(SmtEngine* smtEngine) {
}

inline void EmptyCommand::toStream(std::ostream& out) const {
  out << "EmptyCommand(" << d_name << ")";
}

/* class AssertCommand */

inline AssertCommand::AssertCommand(const BoolExpr& e) :
  d_expr(e) {
}

inline void AssertCommand::invoke(SmtEngine* smtEngine) {
  smtEngine->assertFormula(d_expr);
}

inline void AssertCommand::toStream(std::ostream& out) const {
  out << "Assert(" << d_expr << ")";
}

/* class CheckSatCommand */

inline CheckSatCommand::CheckSatCommand(const BoolExpr& expr) :
  d_expr(expr) {
}

inline void CheckSatCommand::invoke(SmtEngine* smtEngine) {
  d_result = smtEngine->checkSat(d_expr);
}

inline Result CheckSatCommand::getResult() {
  return d_result;
}

/* class QueryCommand */

inline QueryCommand::QueryCommand(const BoolExpr& e) :
  d_expr(e) {
}

inline void QueryCommand::invoke(CVC4::SmtEngine* smtEngine) {
  d_result = smtEngine->query(d_expr);
}

inline Result QueryCommand::getResult() {
  return d_result;
}

inline void QueryCommand::toStream(std::ostream& out) const {
  out << "Query(";
  d_expr.printAst(out, 0);
  out << ")";
}

/* class CommandSequence */

inline CommandSequence::CommandSequence() :
  d_index(0) {
}

inline void CommandSequence::addCommand(Command* cmd) {
  d_commandSequence.push_back(cmd);
}

/* class DeclarationCommand */

inline DeclarationCommand::DeclarationCommand(const std::vector<std::string>& ids, const Type* t) :
  d_declaredSymbols(ids) {
}

/* class SetBenchmarkStatusCommand */

inline SetBenchmarkStatusCommand::SetBenchmarkStatusCommand(BenchmarkStatus status) :
  d_status(status) {
}

inline void SetBenchmarkStatusCommand::invoke(SmtEngine* smt) {
  // FIXME: TODO: something to be done with the status
}

inline void SetBenchmarkStatusCommand::toStream(std::ostream& out) const {
  out << "SetBenchmarkStatus(" << d_status << ")";
}

/* class SetBenchmarkLogicCommand */

inline SetBenchmarkLogicCommand::SetBenchmarkLogicCommand(std::string logic) :
  d_logic(logic) {
}

inline void SetBenchmarkLogicCommand::invoke(SmtEngine* smt) {
  // FIXME: TODO: something to be done with the logic
}

inline void SetBenchmarkLogicCommand::toStream(std::ostream& out) const {
  out << "SetBenchmarkLogic(" << d_logic << ")";
}

/* output stream insertion operator for benchmark statuses */
inline std::ostream& operator<<(std::ostream& out,
                                BenchmarkStatus status) {
  switch(status) {

  case SMT_SATISFIABLE:
    return out << "sat";

  case SMT_UNSATISFIABLE:
    return out << "unsat";

  case SMT_UNKNOWN:
    return out << "unknown";

  default:
    return out << "SetBenchmarkStatusCommand::[UNKNOWNSTATUS!]";
  }
}

}/* CVC4 namespace */

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