GCC Code Coverage Report
Directory: . Exec Total Coverage
File: src/smt/command.cpp Lines: 667 1267 52.6 %
Date: 2021-05-21 Branches: 468 1507 31.1 %

Line Exec Source
1
/******************************************************************************
2
 * Top contributors (to current version):
3
 *   Tim King, Abdalrhman Mohamed, Morgan Deters
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
 * Implementation of command objects.
14
 */
15
16
#include "smt/command.h"
17
18
#include <exception>
19
#include <iostream>
20
#include <iterator>
21
#include <sstream>
22
#include <utility>
23
#include <vector>
24
25
#include "api/cpp/cvc5.h"
26
#include "base/check.h"
27
#include "base/modal_exception.h"
28
#include "base/output.h"
29
#include "expr/expr_iomanip.h"
30
#include "expr/node.h"
31
#include "expr/symbol_manager.h"
32
#include "expr/type_node.h"
33
#include "options/options.h"
34
#include "options/smt_options.h"
35
#include "printer/printer.h"
36
#include "proof/unsat_core.h"
37
#include "smt/dump.h"
38
#include "smt/model.h"
39
#include "smt/smt_engine.h"
40
#include "smt/smt_engine_scope.h"
41
#include "util/unsafe_interrupt_exception.h"
42
#include "util/utility.h"
43
44
using namespace std;
45
46
namespace cvc5 {
47
48
12446
std::string sexprToString(api::Term sexpr)
49
{
50
  // if sexpr is a constant string, return the stored constant string. We don't
51
  // call Term::toString as its result depends on the output language.
52
  // Notice that we only check for string constants. The sexprs generated by the
53
  // parser don't contains other constants, so we can ignore them.
54
12446
  if (sexpr.isStringValue())
55
  {
56
    // convert std::wstring to std::string
57
24858
    std::wstring wstring = sexpr.getStringValue();
58
12429
    return std::string(wstring.cbegin(), wstring.cend());
59
  }
60
61
  // if sexpr is not a spec constant, make sure it is an array of sub-sexprs
62
17
  Assert(sexpr.getKind() == api::SEXPR);
63
64
34
  std::stringstream ss;
65
34
  auto it = sexpr.begin();
66
67
  // recursively print the sub-sexprs
68
17
  ss << '(' << sexprToString(*it);
69
17
  ++it;
70
59
  while (it != sexpr.end())
71
  {
72
21
    ss << ' ' << sexprToString(*it);
73
21
    ++it;
74
  }
75
17
  ss << ')';
76
77
17
  return ss.str();
78
}
79
80
9245
const int CommandPrintSuccess::s_iosIndex = std::ios_base::xalloc();
81
9245
const CommandSuccess* CommandSuccess::s_instance = new CommandSuccess();
82
9245
const CommandInterrupted* CommandInterrupted::s_instance =
83
9245
    new CommandInterrupted();
84
85
22
std::ostream& operator<<(std::ostream& out, const Command& c)
86
{
87
44
  c.toStream(out,
88
22
             Node::setdepth::getDepth(out),
89
             Node::dag::getDag(out),
90
22
             Node::setlanguage::getLanguage(out));
91
22
  return out;
92
}
93
94
11
ostream& operator<<(ostream& out, const Command* c)
95
{
96
11
  if (c == NULL)
97
  {
98
    out << "null";
99
  }
100
  else
101
  {
102
11
    out << *c;
103
  }
104
11
  return out;
105
}
106
107
279490
std::ostream& operator<<(std::ostream& out, const CommandStatus& s)
108
{
109
279490
  s.toStream(out, Node::setlanguage::getLanguage(out));
110
279490
  return out;
111
}
112
113
ostream& operator<<(ostream& out, const CommandStatus* s)
114
{
115
  if (s == NULL)
116
  {
117
    out << "null";
118
  }
119
  else
120
  {
121
    out << *s;
122
  }
123
  return out;
124
}
125
126
/* output stream insertion operator for benchmark statuses */
127
std::ostream& operator<<(std::ostream& out, BenchmarkStatus status)
128
{
129
  switch (status)
130
  {
131
    case SMT_SATISFIABLE: return out << "sat";
132
133
    case SMT_UNSATISFIABLE: return out << "unsat";
134
135
    case SMT_UNKNOWN: return out << "unknown";
136
137
    default: return out << "BenchmarkStatus::[UNKNOWNSTATUS!]";
138
  }
139
}
140
141
/* -------------------------------------------------------------------------- */
142
/* class CommandPrintSuccess                                                  */
143
/* -------------------------------------------------------------------------- */
144
145
155
void CommandPrintSuccess::applyPrintSuccess(std::ostream& out)
146
{
147
155
  out.iword(s_iosIndex) = d_printSuccess;
148
155
}
149
150
279437
bool CommandPrintSuccess::getPrintSuccess(std::ostream& out)
151
{
152
279437
  return out.iword(s_iosIndex);
153
}
154
155
void CommandPrintSuccess::setPrintSuccess(std::ostream& out, bool printSuccess)
156
{
157
  out.iword(s_iosIndex) = printSuccess;
158
}
159
160
155
std::ostream& operator<<(std::ostream& out, CommandPrintSuccess cps)
161
{
162
155
  cps.applyPrintSuccess(out);
163
155
  return out;
164
}
165
166
/* -------------------------------------------------------------------------- */
167
/* class Command                                                              */
168
/* -------------------------------------------------------------------------- */
169
170
300307
Command::Command() : d_commandStatus(nullptr), d_muted(false) {}
171
172
Command::Command(const Command& cmd)
173
{
174
  d_commandStatus =
175
      (cmd.d_commandStatus == NULL) ? NULL : &cmd.d_commandStatus->clone();
176
  d_muted = cmd.d_muted;
177
}
178
179
600614
Command::~Command()
180
{
181
300307
  if (d_commandStatus != NULL && d_commandStatus != CommandSuccess::instance())
182
  {
183
53
    delete d_commandStatus;
184
  }
185
300307
}
186
187
294704
bool Command::ok() const
188
{
189
  // either we haven't run the command yet, or it ran successfully
190
294704
  return d_commandStatus == NULL
191
294704
         || dynamic_cast<const CommandSuccess*>(d_commandStatus) != NULL;
192
}
193
194
294730
bool Command::fail() const
195
{
196
294730
  return d_commandStatus != NULL
197
294730
         && dynamic_cast<const CommandFailure*>(d_commandStatus) != NULL;
198
}
199
200
286729
bool Command::interrupted() const
201
{
202
286729
  return d_commandStatus != NULL
203
286729
         && dynamic_cast<const CommandInterrupted*>(d_commandStatus) != NULL;
204
}
205
206
294732
void Command::invoke(api::Solver* solver, SymbolManager* sm, std::ostream& out)
207
{
208
294732
  invoke(solver, sm);
209
294732
  if (!(isMuted() && ok()))
210
  {
211
289150
    printResult(
212
        out,
213
578300
        std::stoul(solver->getOption("command-verbosity:" + getCommandName())));
214
  }
215
294732
}
216
217
std::string Command::toString() const
218
{
219
  std::stringstream ss;
220
  toStream(ss);
221
  return ss.str();
222
}
223
224
281482
void CommandStatus::toStream(std::ostream& out, OutputLanguage language) const
225
{
226
281482
  Printer::getPrinter(language)->toStream(out, this);
227
281482
}
228
229
279586
void Command::printResult(std::ostream& out, uint32_t verbosity) const
230
{
231
279586
  if (d_commandStatus != NULL)
232
  {
233
279499
    if ((!ok() && verbosity >= 1) || verbosity >= 2)
234
    {
235
279490
      out << *d_commandStatus;
236
    }
237
  }
238
279586
}
239
240
78860
Node Command::termToNode(const api::Term& term) { return term.getNode(); }
241
242
210
std::vector<Node> Command::termVectorToNodes(
243
    const std::vector<api::Term>& terms)
244
{
245
210
  return api::Term::termVectorToNodes(terms);
246
}
247
248
6
TypeNode Command::sortToTypeNode(const api::Sort& sort)
249
{
250
6
  return sort.getTypeNode();
251
}
252
253
std::vector<TypeNode> Command::sortVectorToTypeNodes(
254
    const std::vector<api::Sort>& sorts)
255
{
256
  return api::Sort::sortVectorToTypeNodes(sorts);
257
}
258
259
1
TypeNode Command::grammarToTypeNode(api::Grammar* grammar)
260
{
261
  return grammar == nullptr ? TypeNode::null()
262
1
                            : sortToTypeNode(grammar->resolve());
263
}
264
265
47
Options& Command::getOriginalOptionsFrom(api::Solver* s)
266
{
267
47
  return *s->d_originalOptions.get();
268
}
269
270
/* -------------------------------------------------------------------------- */
271
/* class EmptyCommand                                                         */
272
/* -------------------------------------------------------------------------- */
273
274
423
EmptyCommand::EmptyCommand(std::string name) : d_name(name) {}
275
std::string EmptyCommand::getName() const { return d_name; }
276
417
void EmptyCommand::invoke(api::Solver* solver, SymbolManager* sm)
277
{
278
  /* empty commands have no implementation */
279
417
  d_commandStatus = CommandSuccess::instance();
280
417
}
281
282
Command* EmptyCommand::clone() const { return new EmptyCommand(d_name); }
283
834
std::string EmptyCommand::getCommandName() const { return "empty"; }
284
285
void EmptyCommand::toStream(std::ostream& out,
286
                            int toDepth,
287
                            size_t dag,
288
                            OutputLanguage language) const
289
{
290
  Printer::getPrinter(language)->toStreamCmdEmpty(out, d_name);
291
}
292
293
/* -------------------------------------------------------------------------- */
294
/* class EchoCommand                                                          */
295
/* -------------------------------------------------------------------------- */
296
297
9
EchoCommand::EchoCommand(std::string output)
298
{
299
  // escape all double-quotes
300
9
  size_t pos = 0;
301
21
  while ((pos = output.find('"', pos)) != string::npos)
302
  {
303
6
    output.replace(pos, 1, "\"\"");
304
6
    pos += 2;
305
  }
306
9
  d_output = '"' + output + '"';
307
9
}
308
309
std::string EchoCommand::getOutput() const { return d_output; }
310
void EchoCommand::invoke(api::Solver* solver, SymbolManager* sm)
311
{
312
  /* we don't have an output stream here, nothing to do */
313
  d_commandStatus = CommandSuccess::instance();
314
}
315
316
9
void EchoCommand::invoke(api::Solver* solver,
317
                         SymbolManager* sm,
318
                         std::ostream& out)
319
{
320
9
  out << d_output << std::endl;
321
18
  Trace("dtview::command") << "* ~COMMAND: echo |" << d_output << "|~"
322
9
                           << std::endl;
323
9
  d_commandStatus = CommandSuccess::instance();
324
18
  printResult(
325
      out,
326
18
      std::stoul(solver->getOption("command-verbosity:" + getCommandName())));
327
9
}
328
329
Command* EchoCommand::clone() const { return new EchoCommand(d_output); }
330
18
std::string EchoCommand::getCommandName() const { return "echo"; }
331
332
void EchoCommand::toStream(std::ostream& out,
333
                           int toDepth,
334
                           size_t dag,
335
                           OutputLanguage language) const
336
{
337
  Printer::getPrinter(language)->toStreamCmdEcho(out, d_output);
338
}
339
340
/* -------------------------------------------------------------------------- */
341
/* class AssertCommand                                                        */
342
/* -------------------------------------------------------------------------- */
343
344
78664
AssertCommand::AssertCommand(const api::Term& t, bool inUnsatCore)
345
78664
    : d_term(t), d_inUnsatCore(inUnsatCore)
346
{
347
78664
}
348
349
api::Term AssertCommand::getTerm() const { return d_term; }
350
78614
void AssertCommand::invoke(api::Solver* solver, SymbolManager* sm)
351
{
352
  try
353
  {
354
78614
    solver->getSmtEngine()->assertFormula(termToNode(d_term), d_inUnsatCore);
355
78614
    d_commandStatus = CommandSuccess::instance();
356
  }
357
  catch (UnsafeInterruptException& e)
358
  {
359
    d_commandStatus = new CommandInterrupted();
360
  }
361
  catch (exception& e)
362
  {
363
    d_commandStatus = new CommandFailure(e.what());
364
  }
365
78614
}
366
367
Command* AssertCommand::clone() const
368
{
369
  return new AssertCommand(d_term, d_inUnsatCore);
370
}
371
372
157228
std::string AssertCommand::getCommandName() const { return "assert"; }
373
374
void AssertCommand::toStream(std::ostream& out,
375
                             int toDepth,
376
                             size_t dag,
377
                             OutputLanguage language) const
378
{
379
  Printer::getPrinter(language)->toStreamCmdAssert(out, termToNode(d_term));
380
}
381
382
/* -------------------------------------------------------------------------- */
383
/* class PushCommand                                                          */
384
/* -------------------------------------------------------------------------- */
385
386
2566
void PushCommand::invoke(api::Solver* solver, SymbolManager* sm)
387
{
388
  try
389
  {
390
2566
    solver->push();
391
2566
    d_commandStatus = CommandSuccess::instance();
392
  }
393
  catch (UnsafeInterruptException& e)
394
  {
395
    d_commandStatus = new CommandInterrupted();
396
  }
397
  catch (exception& e)
398
  {
399
    d_commandStatus = new CommandFailure(e.what());
400
  }
401
2566
}
402
403
Command* PushCommand::clone() const { return new PushCommand(); }
404
5122
std::string PushCommand::getCommandName() const { return "push"; }
405
406
void PushCommand::toStream(std::ostream& out,
407
                           int toDepth,
408
                           size_t dag,
409
                           OutputLanguage language) const
410
{
411
  Printer::getPrinter(language)->toStreamCmdPush(out);
412
}
413
414
/* -------------------------------------------------------------------------- */
415
/* class PopCommand                                                           */
416
/* -------------------------------------------------------------------------- */
417
418
2148
void PopCommand::invoke(api::Solver* solver, SymbolManager* sm)
419
{
420
  try
421
  {
422
2148
    solver->pop();
423
2148
    d_commandStatus = CommandSuccess::instance();
424
  }
425
  catch (UnsafeInterruptException& e)
426
  {
427
    d_commandStatus = new CommandInterrupted();
428
  }
429
  catch (exception& e)
430
  {
431
    d_commandStatus = new CommandFailure(e.what());
432
  }
433
2148
}
434
435
Command* PopCommand::clone() const { return new PopCommand(); }
436
4179
std::string PopCommand::getCommandName() const { return "pop"; }
437
438
void PopCommand::toStream(std::ostream& out,
439
                          int toDepth,
440
                          size_t dag,
441
                          OutputLanguage language) const
442
{
443
  Printer::getPrinter(language)->toStreamCmdPop(out);
444
}
445
446
/* -------------------------------------------------------------------------- */
447
/* class CheckSatCommand                                                      */
448
/* -------------------------------------------------------------------------- */
449
450
457
CheckSatCommand::CheckSatCommand() : d_term() {}
451
452
7262
CheckSatCommand::CheckSatCommand(const api::Term& term) : d_term(term) {}
453
454
api::Term CheckSatCommand::getTerm() const { return d_term; }
455
7701
void CheckSatCommand::invoke(api::Solver* solver, SymbolManager* sm)
456
{
457
15402
  Trace("dtview::command") << "* ~COMMAND: " << getCommandName() << "~"
458
7701
                           << std::endl;
459
  try
460
  {
461
7685
    d_result =
462
15386
        d_term.isNull() ? solver->checkSat() : solver->checkSatAssuming(d_term);
463
464
7685
    d_commandStatus = CommandSuccess::instance();
465
  }
466
32
  catch (exception& e)
467
  {
468
16
    d_commandStatus = new CommandFailure(e.what());
469
  }
470
7701
}
471
472
7701
api::Result CheckSatCommand::getResult() const { return d_result; }
473
7701
void CheckSatCommand::printResult(std::ostream& out, uint32_t verbosity) const
474
{
475
7701
  if (!ok())
476
  {
477
16
    this->Command::printResult(out, verbosity);
478
  }
479
  else
480
  {
481
7685
    Trace("dtview::command") << "* RESULT: " << d_result << std::endl;
482
7685
    out << d_result << endl;
483
  }
484
7701
}
485
486
Command* CheckSatCommand::clone() const
487
{
488
  CheckSatCommand* c = new CheckSatCommand(d_term);
489
  c->d_result = d_result;
490
  return c;
491
}
492
493
23103
std::string CheckSatCommand::getCommandName() const { return "check-sat"; }
494
495
void CheckSatCommand::toStream(std::ostream& out,
496
                               int toDepth,
497
                               size_t dag,
498
                               OutputLanguage language) const
499
{
500
  Printer::getPrinter(language)->toStreamCmdCheckSat(out, termToNode(d_term));
501
}
502
503
/* -------------------------------------------------------------------------- */
504
/* class CheckSatAssumingCommand                                              */
505
/* -------------------------------------------------------------------------- */
506
507
CheckSatAssumingCommand::CheckSatAssumingCommand(api::Term term)
508
    : d_terms({term})
509
{
510
}
511
512
985
CheckSatAssumingCommand::CheckSatAssumingCommand(
513
985
    const std::vector<api::Term>& terms)
514
985
    : d_terms(terms)
515
{
516
985
}
517
518
const std::vector<api::Term>& CheckSatAssumingCommand::getTerms() const
519
{
520
  return d_terms;
521
}
522
523
985
void CheckSatAssumingCommand::invoke(api::Solver* solver, SymbolManager* sm)
524
{
525
1970
  Trace("dtview::command") << "* ~COMMAND: (check-sat-assuming ( " << d_terms
526
985
                           << " )~" << std::endl;
527
  try
528
  {
529
985
    d_result = solver->checkSatAssuming(d_terms);
530
985
    d_commandStatus = CommandSuccess::instance();
531
  }
532
  catch (exception& e)
533
  {
534
    d_commandStatus = new CommandFailure(e.what());
535
  }
536
985
}
537
538
985
api::Result CheckSatAssumingCommand::getResult() const
539
{
540
985
  Trace("dtview::command") << "* ~RESULT: " << d_result << "~" << std::endl;
541
985
  return d_result;
542
}
543
544
985
void CheckSatAssumingCommand::printResult(std::ostream& out,
545
                                          uint32_t verbosity) const
546
{
547
985
  if (!ok())
548
  {
549
    this->Command::printResult(out, verbosity);
550
  }
551
  else
552
  {
553
985
    out << d_result << endl;
554
  }
555
985
}
556
557
Command* CheckSatAssumingCommand::clone() const
558
{
559
  CheckSatAssumingCommand* c = new CheckSatAssumingCommand(d_terms);
560
  c->d_result = d_result;
561
  return c;
562
}
563
564
1970
std::string CheckSatAssumingCommand::getCommandName() const
565
{
566
1970
  return "check-sat-assuming";
567
}
568
569
void CheckSatAssumingCommand::toStream(std::ostream& out,
570
                                       int toDepth,
571
                                       size_t dag,
572
                                       OutputLanguage language) const
573
{
574
  Printer::getPrinter(language)->toStreamCmdCheckSatAssuming(
575
      out, termVectorToNodes(d_terms));
576
}
577
578
/* -------------------------------------------------------------------------- */
579
/* class QueryCommand                                                         */
580
/* -------------------------------------------------------------------------- */
581
582
561
QueryCommand::QueryCommand(const api::Term& t, bool inUnsatCore)
583
561
    : d_term(t), d_inUnsatCore(inUnsatCore)
584
{
585
561
}
586
587
api::Term QueryCommand::getTerm() const { return d_term; }
588
553
void QueryCommand::invoke(api::Solver* solver, SymbolManager* sm)
589
{
590
  try
591
  {
592
553
    d_result = solver->checkEntailed(d_term);
593
549
    d_commandStatus = CommandSuccess::instance();
594
  }
595
8
  catch (exception& e)
596
  {
597
4
    d_commandStatus = new CommandFailure(e.what());
598
  }
599
553
}
600
601
553
api::Result QueryCommand::getResult() const { return d_result; }
602
553
void QueryCommand::printResult(std::ostream& out, uint32_t verbosity) const
603
{
604
553
  if (!ok())
605
  {
606
4
    this->Command::printResult(out, verbosity);
607
  }
608
  else
609
  {
610
549
    out << d_result << endl;
611
  }
612
553
}
613
614
Command* QueryCommand::clone() const
615
{
616
  QueryCommand* c = new QueryCommand(d_term, d_inUnsatCore);
617
  c->d_result = d_result;
618
  return c;
619
}
620
621
1106
std::string QueryCommand::getCommandName() const { return "query"; }
622
623
void QueryCommand::toStream(std::ostream& out,
624
                            int toDepth,
625
                            size_t dag,
626
                            OutputLanguage language) const
627
{
628
  Printer::getPrinter(language)->toStreamCmdQuery(out, termToNode(d_term));
629
}
630
631
/* -------------------------------------------------------------------------- */
632
/* class DeclareSygusVarCommand */
633
/* -------------------------------------------------------------------------- */
634
635
262
DeclareSygusVarCommand::DeclareSygusVarCommand(const std::string& id,
636
                                               api::Term var,
637
262
                                               api::Sort sort)
638
262
    : DeclarationDefinitionCommand(id), d_var(var), d_sort(sort)
639
{
640
262
}
641
642
api::Term DeclareSygusVarCommand::getVar() const { return d_var; }
643
api::Sort DeclareSygusVarCommand::getSort() const { return d_sort; }
644
645
262
void DeclareSygusVarCommand::invoke(api::Solver* solver, SymbolManager* sm)
646
{
647
262
  d_commandStatus = CommandSuccess::instance();
648
262
}
649
650
Command* DeclareSygusVarCommand::clone() const
651
{
652
  return new DeclareSygusVarCommand(d_symbol, d_var, d_sort);
653
}
654
655
524
std::string DeclareSygusVarCommand::getCommandName() const
656
{
657
524
  return "declare-var";
658
}
659
660
1
void DeclareSygusVarCommand::toStream(std::ostream& out,
661
                                      int toDepth,
662
                                      size_t dag,
663
                                      OutputLanguage language) const
664
{
665
2
  Printer::getPrinter(language)->toStreamCmdDeclareVar(
666
2
      out, termToNode(d_var), sortToTypeNode(d_sort));
667
1
}
668
669
/* -------------------------------------------------------------------------- */
670
/* class SynthFunCommand                                                      */
671
/* -------------------------------------------------------------------------- */
672
673
282
SynthFunCommand::SynthFunCommand(const std::string& id,
674
                                 api::Term fun,
675
                                 const std::vector<api::Term>& vars,
676
                                 api::Sort sort,
677
                                 bool isInv,
678
282
                                 api::Grammar* g)
679
    : DeclarationDefinitionCommand(id),
680
      d_fun(fun),
681
      d_vars(vars),
682
      d_sort(sort),
683
      d_isInv(isInv),
684
282
      d_grammar(g)
685
{
686
282
}
687
688
api::Term SynthFunCommand::getFunction() const { return d_fun; }
689
690
const std::vector<api::Term>& SynthFunCommand::getVars() const
691
{
692
  return d_vars;
693
}
694
695
api::Sort SynthFunCommand::getSort() const { return d_sort; }
696
bool SynthFunCommand::isInv() const { return d_isInv; }
697
698
const api::Grammar* SynthFunCommand::getGrammar() const { return d_grammar; }
699
700
282
void SynthFunCommand::invoke(api::Solver* solver, SymbolManager* sm)
701
{
702
282
  d_commandStatus = CommandSuccess::instance();
703
282
}
704
705
Command* SynthFunCommand::clone() const
706
{
707
  return new SynthFunCommand(
708
      d_symbol, d_fun, d_vars, d_sort, d_isInv, d_grammar);
709
}
710
711
564
std::string SynthFunCommand::getCommandName() const
712
{
713
564
  return d_isInv ? "synth-inv" : "synth-fun";
714
}
715
716
2
void SynthFunCommand::toStream(std::ostream& out,
717
                               int toDepth,
718
                               size_t dag,
719
                               OutputLanguage language) const
720
{
721
4
  std::vector<Node> nodeVars = termVectorToNodes(d_vars);
722
6
  Printer::getPrinter(language)->toStreamCmdSynthFun(
723
      out,
724
4
      termToNode(d_fun),
725
      nodeVars,
726
2
      d_isInv,
727
4
      d_grammar == nullptr ? TypeNode::null() : grammarToTypeNode(d_grammar));
728
2
}
729
730
/* -------------------------------------------------------------------------- */
731
/* class SygusConstraintCommand */
732
/* -------------------------------------------------------------------------- */
733
734
598
SygusConstraintCommand::SygusConstraintCommand(const api::Term& t) : d_term(t)
735
{
736
598
}
737
738
598
void SygusConstraintCommand::invoke(api::Solver* solver, SymbolManager* sm)
739
{
740
  try
741
  {
742
598
    solver->addSygusConstraint(d_term);
743
598
    d_commandStatus = CommandSuccess::instance();
744
  }
745
  catch (exception& e)
746
  {
747
    d_commandStatus = new CommandFailure(e.what());
748
  }
749
598
}
750
751
api::Term SygusConstraintCommand::getTerm() const { return d_term; }
752
753
Command* SygusConstraintCommand::clone() const
754
{
755
  return new SygusConstraintCommand(d_term);
756
}
757
758
1196
std::string SygusConstraintCommand::getCommandName() const
759
{
760
1196
  return "constraint";
761
}
762
763
1
void SygusConstraintCommand::toStream(std::ostream& out,
764
                                      int toDepth,
765
                                      size_t dag,
766
                                      OutputLanguage language) const
767
{
768
1
  Printer::getPrinter(language)->toStreamCmdConstraint(out, termToNode(d_term));
769
1
}
770
771
/* -------------------------------------------------------------------------- */
772
/* class SygusInvConstraintCommand */
773
/* -------------------------------------------------------------------------- */
774
775
13
SygusInvConstraintCommand::SygusInvConstraintCommand(
776
13
    const std::vector<api::Term>& predicates)
777
13
    : d_predicates(predicates)
778
{
779
13
}
780
781
SygusInvConstraintCommand::SygusInvConstraintCommand(const api::Term& inv,
782
                                                     const api::Term& pre,
783
                                                     const api::Term& trans,
784
                                                     const api::Term& post)
785
    : SygusInvConstraintCommand(std::vector<api::Term>{inv, pre, trans, post})
786
{
787
}
788
789
13
void SygusInvConstraintCommand::invoke(api::Solver* solver, SymbolManager* sm)
790
{
791
  try
792
  {
793
52
    solver->addSygusInvConstraint(
794
52
        d_predicates[0], d_predicates[1], d_predicates[2], d_predicates[3]);
795
13
    d_commandStatus = CommandSuccess::instance();
796
  }
797
  catch (exception& e)
798
  {
799
    d_commandStatus = new CommandFailure(e.what());
800
  }
801
13
}
802
803
const std::vector<api::Term>& SygusInvConstraintCommand::getPredicates() const
804
{
805
  return d_predicates;
806
}
807
808
Command* SygusInvConstraintCommand::clone() const
809
{
810
  return new SygusInvConstraintCommand(d_predicates);
811
}
812
813
26
std::string SygusInvConstraintCommand::getCommandName() const
814
{
815
26
  return "inv-constraint";
816
}
817
818
1
void SygusInvConstraintCommand::toStream(std::ostream& out,
819
                                         int toDepth,
820
                                         size_t dag,
821
                                         OutputLanguage language) const
822
{
823
2
  Printer::getPrinter(language)->toStreamCmdInvConstraint(
824
      out,
825
2
      termToNode(d_predicates[0]),
826
2
      termToNode(d_predicates[1]),
827
2
      termToNode(d_predicates[2]),
828
2
      termToNode(d_predicates[3]));
829
1
}
830
831
/* -------------------------------------------------------------------------- */
832
/* class CheckSynthCommand                                                    */
833
/* -------------------------------------------------------------------------- */
834
835
189
void CheckSynthCommand::invoke(api::Solver* solver, SymbolManager* sm)
836
{
837
  try
838
  {
839
189
    d_result = solver->checkSynth();
840
180
    d_commandStatus = CommandSuccess::instance();
841
180
    d_solution.clear();
842
    // check whether we should print the status
843
360
    if (!d_result.isUnsat()
844
1044
        || options::sygusOut() == options::SygusSolutionOutMode::STATUS_AND_DEF
845
349
        || options::sygusOut() == options::SygusSolutionOutMode::STATUS)
846
    {
847
180
      if (options::sygusOut() == options::SygusSolutionOutMode::STANDARD)
848
      {
849
        d_solution << "(fail)" << endl;
850
      }
851
      else
852
      {
853
180
        d_solution << d_result << endl;
854
      }
855
    }
856
    // check whether we should print the solution
857
360
    if (d_result.isUnsat()
858
180
        && options::sygusOut() != options::SygusSolutionOutMode::STATUS)
859
    {
860
      // printing a synthesis solution is a non-constant
861
      // method, since it invokes a sophisticated algorithm
862
      // (Figure 5 of Reynolds et al. CAV 2015).
863
      // Hence, we must call here print solution here,
864
      // instead of during printResult.
865
3
      solver->printSynthSolution(d_solution);
866
    }
867
  }
868
18
  catch (exception& e)
869
  {
870
9
    d_commandStatus = new CommandFailure(e.what());
871
  }
872
189
}
873
874
api::Result CheckSynthCommand::getResult() const { return d_result; }
875
189
void CheckSynthCommand::printResult(std::ostream& out, uint32_t verbosity) const
876
{
877
189
  if (!ok())
878
  {
879
9
    this->Command::printResult(out, verbosity);
880
  }
881
  else
882
  {
883
180
    out << d_solution.str();
884
  }
885
189
}
886
887
Command* CheckSynthCommand::clone() const { return new CheckSynthCommand(); }
888
889
378
std::string CheckSynthCommand::getCommandName() const { return "check-synth"; }
890
891
1
void CheckSynthCommand::toStream(std::ostream& out,
892
                                 int toDepth,
893
                                 size_t dag,
894
                                 OutputLanguage language) const
895
{
896
1
  Printer::getPrinter(language)->toStreamCmdCheckSynth(out);
897
1
}
898
899
/* -------------------------------------------------------------------------- */
900
/* class ResetCommand                                                         */
901
/* -------------------------------------------------------------------------- */
902
903
47
void ResetCommand::invoke(api::Solver* solver, SymbolManager* sm)
904
{
905
  try
906
  {
907
47
    sm->reset();
908
94
    Options opts;
909
47
    opts.copyValues(getOriginalOptionsFrom(solver));
910
    // This reconstructs a new solver object at the same memory location as the
911
    // current one. Note that this command does not own the solver object!
912
    // It may be safer to instead make the ResetCommand a special case in the
913
    // CommandExecutor such that this reconstruction can be done within the
914
    // CommandExecutor, who actually owns the solver.
915
47
    solver->~Solver();
916
47
    new (solver) api::Solver(&opts);
917
47
    d_commandStatus = CommandSuccess::instance();
918
  }
919
  catch (exception& e)
920
  {
921
    d_commandStatus = new CommandFailure(e.what());
922
  }
923
47
}
924
925
Command* ResetCommand::clone() const { return new ResetCommand(); }
926
94
std::string ResetCommand::getCommandName() const { return "reset"; }
927
928
void ResetCommand::toStream(std::ostream& out,
929
                            int toDepth,
930
                            size_t dag,
931
                            OutputLanguage language) const
932
{
933
  Printer::getPrinter(language)->toStreamCmdReset(out);
934
}
935
936
/* -------------------------------------------------------------------------- */
937
/* class ResetAssertionsCommand                                               */
938
/* -------------------------------------------------------------------------- */
939
940
31
void ResetAssertionsCommand::invoke(api::Solver* solver, SymbolManager* sm)
941
{
942
  try
943
  {
944
31
    sm->resetAssertions();
945
31
    solver->resetAssertions();
946
31
    d_commandStatus = CommandSuccess::instance();
947
  }
948
  catch (exception& e)
949
  {
950
    d_commandStatus = new CommandFailure(e.what());
951
  }
952
31
}
953
954
Command* ResetAssertionsCommand::clone() const
955
{
956
  return new ResetAssertionsCommand();
957
}
958
959
62
std::string ResetAssertionsCommand::getCommandName() const
960
{
961
62
  return "reset-assertions";
962
}
963
964
void ResetAssertionsCommand::toStream(std::ostream& out,
965
                                      int toDepth,
966
                                      size_t dag,
967
                                      OutputLanguage language) const
968
{
969
  Printer::getPrinter(language)->toStreamCmdResetAssertions(out);
970
}
971
972
/* -------------------------------------------------------------------------- */
973
/* class QuitCommand                                                          */
974
/* -------------------------------------------------------------------------- */
975
976
714
void QuitCommand::invoke(api::Solver* solver, SymbolManager* sm)
977
{
978
714
  Dump("benchmark") << *this;
979
714
  d_commandStatus = CommandSuccess::instance();
980
714
}
981
982
Command* QuitCommand::clone() const { return new QuitCommand(); }
983
1428
std::string QuitCommand::getCommandName() const { return "exit"; }
984
985
void QuitCommand::toStream(std::ostream& out,
986
                           int toDepth,
987
                           size_t dag,
988
                           OutputLanguage language) const
989
{
990
  Printer::getPrinter(language)->toStreamCmdQuit(out);
991
}
992
993
/* -------------------------------------------------------------------------- */
994
/* class CommentCommand                                                       */
995
/* -------------------------------------------------------------------------- */
996
997
CommentCommand::CommentCommand(std::string comment) : d_comment(comment) {}
998
std::string CommentCommand::getComment() const { return d_comment; }
999
void CommentCommand::invoke(api::Solver* solver, SymbolManager* sm)
1000
{
1001
  Dump("benchmark") << *this;
1002
  d_commandStatus = CommandSuccess::instance();
1003
}
1004
1005
Command* CommentCommand::clone() const { return new CommentCommand(d_comment); }
1006
std::string CommentCommand::getCommandName() const { return "comment"; }
1007
1008
void CommentCommand::toStream(std::ostream& out,
1009
                              int toDepth,
1010
                              size_t dag,
1011
                              OutputLanguage language) const
1012
{
1013
  Printer::getPrinter(language)->toStreamCmdComment(out, d_comment);
1014
}
1015
1016
/* -------------------------------------------------------------------------- */
1017
/* class CommandSequence                                                      */
1018
/* -------------------------------------------------------------------------- */
1019
1020
5185
CommandSequence::CommandSequence() : d_index(0) {}
1021
10510
CommandSequence::~CommandSequence()
1022
{
1023
13133
  for (unsigned i = d_index; i < d_commandSequence.size(); ++i)
1024
  {
1025
7948
    delete d_commandSequence[i];
1026
  }
1027
5325
}
1028
1029
7948
void CommandSequence::addCommand(Command* cmd)
1030
{
1031
7948
  d_commandSequence.push_back(cmd);
1032
7948
}
1033
1034
void CommandSequence::clear() { d_commandSequence.clear(); }
1035
void CommandSequence::invoke(api::Solver* solver, SymbolManager* sm)
1036
{
1037
  for (; d_index < d_commandSequence.size(); ++d_index)
1038
  {
1039
    d_commandSequence[d_index]->invoke(solver, sm);
1040
    if (!d_commandSequence[d_index]->ok())
1041
    {
1042
      // abort execution
1043
      d_commandStatus = d_commandSequence[d_index]->getCommandStatus();
1044
      return;
1045
    }
1046
    delete d_commandSequence[d_index];
1047
  }
1048
1049
  AlwaysAssert(d_commandStatus == NULL);
1050
  d_commandStatus = CommandSuccess::instance();
1051
}
1052
1053
void CommandSequence::invoke(api::Solver* solver,
1054
                             SymbolManager* sm,
1055
                             std::ostream& out)
1056
{
1057
  for (; d_index < d_commandSequence.size(); ++d_index)
1058
  {
1059
    d_commandSequence[d_index]->invoke(solver, sm, out);
1060
    if (!d_commandSequence[d_index]->ok())
1061
    {
1062
      // abort execution
1063
      d_commandStatus = d_commandSequence[d_index]->getCommandStatus();
1064
      return;
1065
    }
1066
    delete d_commandSequence[d_index];
1067
  }
1068
1069
  AlwaysAssert(d_commandStatus == NULL);
1070
  d_commandStatus = CommandSuccess::instance();
1071
}
1072
1073
Command* CommandSequence::clone() const
1074
{
1075
  CommandSequence* seq = new CommandSequence();
1076
  for (const_iterator i = begin(); i != end(); ++i)
1077
  {
1078
    seq->addCommand((*i)->clone());
1079
  }
1080
  seq->d_index = d_index;
1081
  return seq;
1082
}
1083
1084
CommandSequence::const_iterator CommandSequence::begin() const
1085
{
1086
  return d_commandSequence.begin();
1087
}
1088
1089
CommandSequence::const_iterator CommandSequence::end() const
1090
{
1091
  return d_commandSequence.end();
1092
}
1093
1094
5051
CommandSequence::iterator CommandSequence::begin()
1095
{
1096
5051
  return d_commandSequence.begin();
1097
}
1098
1099
12859
CommandSequence::iterator CommandSequence::end()
1100
{
1101
12859
  return d_commandSequence.end();
1102
}
1103
1104
std::string CommandSequence::getCommandName() const { return "sequence"; }
1105
1106
void CommandSequence::toStream(std::ostream& out,
1107
                               int toDepth,
1108
                               size_t dag,
1109
                               OutputLanguage language) const
1110
{
1111
  Printer::getPrinter(language)->toStreamCmdCommandSequence(out,
1112
                                                            d_commandSequence);
1113
}
1114
1115
/* -------------------------------------------------------------------------- */
1116
/* class DeclarationSequence                                                  */
1117
/* -------------------------------------------------------------------------- */
1118
1119
void DeclarationSequence::toStream(std::ostream& out,
1120
                                   int toDepth,
1121
                                   size_t dag,
1122
                                   OutputLanguage language) const
1123
{
1124
  Printer::getPrinter(language)->toStreamCmdDeclarationSequence(
1125
      out, d_commandSequence);
1126
}
1127
1128
/* -------------------------------------------------------------------------- */
1129
/* class DeclarationDefinitionCommand                                         */
1130
/* -------------------------------------------------------------------------- */
1131
1132
181068
DeclarationDefinitionCommand::DeclarationDefinitionCommand(
1133
181068
    const std::string& id)
1134
181068
    : d_symbol(id)
1135
{
1136
181068
}
1137
1138
std::string DeclarationDefinitionCommand::getSymbol() const { return d_symbol; }
1139
1140
/* -------------------------------------------------------------------------- */
1141
/* class DeclareFunctionCommand                                               */
1142
/* -------------------------------------------------------------------------- */
1143
1144
174064
DeclareFunctionCommand::DeclareFunctionCommand(const std::string& id,
1145
                                               api::Term func,
1146
174064
                                               api::Sort sort)
1147
174064
    : DeclarationDefinitionCommand(id), d_func(func), d_sort(sort)
1148
{
1149
174064
}
1150
1151
api::Term DeclareFunctionCommand::getFunction() const { return d_func; }
1152
api::Sort DeclareFunctionCommand::getSort() const { return d_sort; }
1153
1154
173898
void DeclareFunctionCommand::invoke(api::Solver* solver, SymbolManager* sm)
1155
{
1156
  // mark that it will be printed in the model
1157
173898
  sm->addModelDeclarationTerm(d_func);
1158
173898
  d_commandStatus = CommandSuccess::instance();
1159
173898
}
1160
1161
Command* DeclareFunctionCommand::clone() const
1162
{
1163
  DeclareFunctionCommand* dfc =
1164
      new DeclareFunctionCommand(d_symbol, d_func, d_sort);
1165
  return dfc;
1166
}
1167
1168
347796
std::string DeclareFunctionCommand::getCommandName() const
1169
{
1170
347796
  return "declare-fun";
1171
}
1172
1173
void DeclareFunctionCommand::toStream(std::ostream& out,
1174
                                      int toDepth,
1175
                                      size_t dag,
1176
                                      OutputLanguage language) const
1177
{
1178
  Printer::getPrinter(language)->toStreamCmdDeclareFunction(
1179
      out, d_func.toString(), sortToTypeNode(d_sort));
1180
}
1181
1182
/* -------------------------------------------------------------------------- */
1183
/* class DeclareFunctionCommand                                               */
1184
/* -------------------------------------------------------------------------- */
1185
1186
3
DeclarePoolCommand::DeclarePoolCommand(const std::string& id,
1187
                                       api::Term func,
1188
                                       api::Sort sort,
1189
3
                                       const std::vector<api::Term>& initValue)
1190
    : DeclarationDefinitionCommand(id),
1191
      d_func(func),
1192
      d_sort(sort),
1193
3
      d_initValue(initValue)
1194
{
1195
3
}
1196
1197
api::Term DeclarePoolCommand::getFunction() const { return d_func; }
1198
api::Sort DeclarePoolCommand::getSort() const { return d_sort; }
1199
const std::vector<api::Term>& DeclarePoolCommand::getInitialValue() const
1200
{
1201
  return d_initValue;
1202
}
1203
1204
3
void DeclarePoolCommand::invoke(api::Solver* solver, SymbolManager* sm)
1205
{
1206
  // Notice that the pool is already declared by the parser so that it the
1207
  // symbol is bound eagerly. This is analogous to DeclareSygusVarCommand.
1208
  // Hence, we do nothing here.
1209
3
  d_commandStatus = CommandSuccess::instance();
1210
3
}
1211
1212
Command* DeclarePoolCommand::clone() const
1213
{
1214
  DeclarePoolCommand* dfc =
1215
      new DeclarePoolCommand(d_symbol, d_func, d_sort, d_initValue);
1216
  return dfc;
1217
}
1218
1219
6
std::string DeclarePoolCommand::getCommandName() const
1220
{
1221
6
  return "declare-pool";
1222
}
1223
1224
void DeclarePoolCommand::toStream(std::ostream& out,
1225
                                  int toDepth,
1226
                                  size_t dag,
1227
                                  OutputLanguage language) const
1228
{
1229
  Printer::getPrinter(language)->toStreamCmdDeclarePool(
1230
      out,
1231
      d_func.toString(),
1232
      sortToTypeNode(d_sort),
1233
      termVectorToNodes(d_initValue));
1234
}
1235
1236
/* -------------------------------------------------------------------------- */
1237
/* class DeclareSortCommand                                                   */
1238
/* -------------------------------------------------------------------------- */
1239
1240
4027
DeclareSortCommand::DeclareSortCommand(const std::string& id,
1241
                                       size_t arity,
1242
4027
                                       api::Sort sort)
1243
4027
    : DeclarationDefinitionCommand(id), d_arity(arity), d_sort(sort)
1244
{
1245
4027
}
1246
1247
size_t DeclareSortCommand::getArity() const { return d_arity; }
1248
api::Sort DeclareSortCommand::getSort() const { return d_sort; }
1249
3983
void DeclareSortCommand::invoke(api::Solver* solver, SymbolManager* sm)
1250
{
1251
  // mark that it will be printed in the model
1252
3983
  sm->addModelDeclarationSort(d_sort);
1253
3983
  d_commandStatus = CommandSuccess::instance();
1254
3983
}
1255
1256
Command* DeclareSortCommand::clone() const
1257
{
1258
  return new DeclareSortCommand(d_symbol, d_arity, d_sort);
1259
}
1260
1261
7966
std::string DeclareSortCommand::getCommandName() const
1262
{
1263
7966
  return "declare-sort";
1264
}
1265
1266
void DeclareSortCommand::toStream(std::ostream& out,
1267
                                  int toDepth,
1268
                                  size_t dag,
1269
                                  OutputLanguage language) const
1270
{
1271
  Printer::getPrinter(language)->toStreamCmdDeclareType(out,
1272
                                                        sortToTypeNode(d_sort));
1273
}
1274
1275
/* -------------------------------------------------------------------------- */
1276
/* class DefineSortCommand                                                    */
1277
/* -------------------------------------------------------------------------- */
1278
1279
DefineSortCommand::DefineSortCommand(const std::string& id, api::Sort sort)
1280
    : DeclarationDefinitionCommand(id), d_params(), d_sort(sort)
1281
{
1282
}
1283
1284
200
DefineSortCommand::DefineSortCommand(const std::string& id,
1285
                                     const std::vector<api::Sort>& params,
1286
200
                                     api::Sort sort)
1287
200
    : DeclarationDefinitionCommand(id), d_params(params), d_sort(sort)
1288
{
1289
200
}
1290
1291
const std::vector<api::Sort>& DefineSortCommand::getParameters() const
1292
{
1293
  return d_params;
1294
}
1295
1296
api::Sort DefineSortCommand::getSort() const { return d_sort; }
1297
200
void DefineSortCommand::invoke(api::Solver* solver, SymbolManager* sm)
1298
{
1299
200
  d_commandStatus = CommandSuccess::instance();
1300
200
}
1301
1302
Command* DefineSortCommand::clone() const
1303
{
1304
  return new DefineSortCommand(d_symbol, d_params, d_sort);
1305
}
1306
1307
400
std::string DefineSortCommand::getCommandName() const { return "define-sort"; }
1308
1309
void DefineSortCommand::toStream(std::ostream& out,
1310
                                 int toDepth,
1311
                                 size_t dag,
1312
                                 OutputLanguage language) const
1313
{
1314
  Printer::getPrinter(language)->toStreamCmdDefineType(
1315
      out, d_symbol, sortVectorToTypeNodes(d_params), sortToTypeNode(d_sort));
1316
}
1317
1318
/* -------------------------------------------------------------------------- */
1319
/* class DefineFunctionCommand                                                */
1320
/* -------------------------------------------------------------------------- */
1321
1322
4
DefineFunctionCommand::DefineFunctionCommand(const std::string& id,
1323
                                             api::Term func,
1324
                                             api::Term formula,
1325
4
                                             bool global)
1326
    : DeclarationDefinitionCommand(id),
1327
      d_func(func),
1328
      d_formals(),
1329
      d_formula(formula),
1330
4
      d_global(global)
1331
{
1332
4
}
1333
1334
2226
DefineFunctionCommand::DefineFunctionCommand(
1335
    const std::string& id,
1336
    api::Term func,
1337
    const std::vector<api::Term>& formals,
1338
    api::Term formula,
1339
2226
    bool global)
1340
    : DeclarationDefinitionCommand(id),
1341
      d_func(func),
1342
      d_formals(formals),
1343
      d_formula(formula),
1344
2226
      d_global(global)
1345
{
1346
2226
}
1347
1348
api::Term DefineFunctionCommand::getFunction() const { return d_func; }
1349
const std::vector<api::Term>& DefineFunctionCommand::getFormals() const
1350
{
1351
  return d_formals;
1352
}
1353
1354
api::Term DefineFunctionCommand::getFormula() const { return d_formula; }
1355
2226
void DefineFunctionCommand::invoke(api::Solver* solver, SymbolManager* sm)
1356
{
1357
  try
1358
  {
1359
2226
    if (!d_func.isNull())
1360
    {
1361
2226
      solver->defineFun(d_func, d_formals, d_formula, d_global);
1362
    }
1363
2226
    d_commandStatus = CommandSuccess::instance();
1364
  }
1365
  catch (exception& e)
1366
  {
1367
    d_commandStatus = new CommandFailure(e.what());
1368
  }
1369
2226
}
1370
1371
Command* DefineFunctionCommand::clone() const
1372
{
1373
  return new DefineFunctionCommand(
1374
      d_symbol, d_func, d_formals, d_formula, d_global);
1375
}
1376
1377
4452
std::string DefineFunctionCommand::getCommandName() const
1378
{
1379
4452
  return "define-fun";
1380
}
1381
1382
3
void DefineFunctionCommand::toStream(std::ostream& out,
1383
                                     int toDepth,
1384
                                     size_t dag,
1385
                                     OutputLanguage language) const
1386
{
1387
6
  Printer::getPrinter(language)->toStreamCmdDefineFunction(
1388
      out,
1389
6
      d_func.toString(),
1390
6
      termVectorToNodes(d_formals),
1391
6
      termToNode(d_func).getType().getRangeType(),
1392
6
      termToNode(d_formula));
1393
3
}
1394
1395
/* -------------------------------------------------------------------------- */
1396
/* class DefineFunctionRecCommand                                             */
1397
/* -------------------------------------------------------------------------- */
1398
1399
69
DefineFunctionRecCommand::DefineFunctionRecCommand(
1400
1401
    api::Term func,
1402
    const std::vector<api::Term>& formals,
1403
    api::Term formula,
1404
69
    bool global)
1405
69
    : d_global(global)
1406
{
1407
69
  d_funcs.push_back(func);
1408
69
  d_formals.push_back(formals);
1409
69
  d_formulas.push_back(formula);
1410
69
}
1411
1412
43
DefineFunctionRecCommand::DefineFunctionRecCommand(
1413
1414
    const std::vector<api::Term>& funcs,
1415
    const std::vector<std::vector<api::Term>>& formals,
1416
    const std::vector<api::Term>& formulas,
1417
43
    bool global)
1418
43
    : d_funcs(funcs), d_formals(formals), d_formulas(formulas), d_global(global)
1419
{
1420
43
}
1421
1422
const std::vector<api::Term>& DefineFunctionRecCommand::getFunctions() const
1423
{
1424
  return d_funcs;
1425
}
1426
1427
const std::vector<std::vector<api::Term>>&
1428
DefineFunctionRecCommand::getFormals() const
1429
{
1430
  return d_formals;
1431
}
1432
1433
const std::vector<api::Term>& DefineFunctionRecCommand::getFormulas() const
1434
{
1435
  return d_formulas;
1436
}
1437
1438
112
void DefineFunctionRecCommand::invoke(api::Solver* solver, SymbolManager* sm)
1439
{
1440
  try
1441
  {
1442
112
    solver->defineFunsRec(d_funcs, d_formals, d_formulas, d_global);
1443
109
    d_commandStatus = CommandSuccess::instance();
1444
  }
1445
6
  catch (exception& e)
1446
  {
1447
3
    d_commandStatus = new CommandFailure(e.what());
1448
  }
1449
112
}
1450
1451
Command* DefineFunctionRecCommand::clone() const
1452
{
1453
  return new DefineFunctionRecCommand(d_funcs, d_formals, d_formulas, d_global);
1454
}
1455
1456
224
std::string DefineFunctionRecCommand::getCommandName() const
1457
{
1458
224
  return "define-fun-rec";
1459
}
1460
1461
void DefineFunctionRecCommand::toStream(std::ostream& out,
1462
                                        int toDepth,
1463
                                        size_t dag,
1464
                                        OutputLanguage language) const
1465
{
1466
  std::vector<std::vector<Node>> formals;
1467
  formals.reserve(d_formals.size());
1468
  for (const std::vector<api::Term>& formal : d_formals)
1469
  {
1470
    formals.push_back(termVectorToNodes(formal));
1471
  }
1472
1473
  Printer::getPrinter(language)->toStreamCmdDefineFunctionRec(
1474
      out, termVectorToNodes(d_funcs), formals, termVectorToNodes(d_formulas));
1475
}
1476
/* -------------------------------------------------------------------------- */
1477
/* class DeclareHeapCommand                                                   */
1478
/* -------------------------------------------------------------------------- */
1479
87
DeclareHeapCommand::DeclareHeapCommand(api::Sort locSort, api::Sort dataSort)
1480
87
    : d_locSort(locSort), d_dataSort(dataSort)
1481
{
1482
87
}
1483
1484
api::Sort DeclareHeapCommand::getLocationSort() const { return d_locSort; }
1485
api::Sort DeclareHeapCommand::getDataSort() const { return d_dataSort; }
1486
1487
87
void DeclareHeapCommand::invoke(api::Solver* solver, SymbolManager* sm)
1488
{
1489
87
  solver->declareSeparationHeap(d_locSort, d_dataSort);
1490
87
}
1491
1492
Command* DeclareHeapCommand::clone() const
1493
{
1494
  return new DeclareHeapCommand(d_locSort, d_dataSort);
1495
}
1496
1497
174
std::string DeclareHeapCommand::getCommandName() const
1498
{
1499
174
  return "declare-heap";
1500
}
1501
1502
void DeclareHeapCommand::toStream(std::ostream& out,
1503
                                  int toDepth,
1504
                                  size_t dag,
1505
                                  OutputLanguage language) const
1506
{
1507
  Printer::getPrinter(language)->toStreamCmdDeclareHeap(
1508
      out, sortToTypeNode(d_locSort), sortToTypeNode(d_dataSort));
1509
}
1510
1511
/* -------------------------------------------------------------------------- */
1512
/* class SetUserAttributeCommand                                              */
1513
/* -------------------------------------------------------------------------- */
1514
1515
202
SetUserAttributeCommand::SetUserAttributeCommand(
1516
    const std::string& attr,
1517
    api::Term term,
1518
    const std::vector<api::Term>& termValues,
1519
202
    const std::string& strValue)
1520
202
    : d_attr(attr), d_term(term), d_termValues(termValues), d_strValue(strValue)
1521
{
1522
202
}
1523
1524
202
SetUserAttributeCommand::SetUserAttributeCommand(const std::string& attr,
1525
202
                                                 api::Term term)
1526
202
    : SetUserAttributeCommand(attr, term, {}, "")
1527
{
1528
202
}
1529
1530
SetUserAttributeCommand::SetUserAttributeCommand(
1531
    const std::string& attr,
1532
    api::Term term,
1533
    const std::vector<api::Term>& values)
1534
    : SetUserAttributeCommand(attr, term, values, "")
1535
{
1536
}
1537
1538
SetUserAttributeCommand::SetUserAttributeCommand(const std::string& attr,
1539
                                                 api::Term term,
1540
                                                 const std::string& value)
1541
    : SetUserAttributeCommand(attr, term, {}, value)
1542
{
1543
}
1544
1545
202
void SetUserAttributeCommand::invoke(api::Solver* solver, SymbolManager* sm)
1546
{
1547
  try
1548
  {
1549
202
    if (!d_term.isNull())
1550
    {
1551
404
      solver->getSmtEngine()->setUserAttribute(d_attr,
1552
404
                                               termToNode(d_term),
1553
404
                                               termVectorToNodes(d_termValues),
1554
                                               d_strValue);
1555
    }
1556
202
    d_commandStatus = CommandSuccess::instance();
1557
  }
1558
  catch (exception& e)
1559
  {
1560
    d_commandStatus = new CommandFailure(e.what());
1561
  }
1562
202
}
1563
1564
Command* SetUserAttributeCommand::clone() const
1565
{
1566
  return new SetUserAttributeCommand(d_attr, d_term, d_termValues, d_strValue);
1567
}
1568
1569
202
std::string SetUserAttributeCommand::getCommandName() const
1570
{
1571
202
  return "set-user-attribute";
1572
}
1573
1574
void SetUserAttributeCommand::toStream(std::ostream& out,
1575
                                       int toDepth,
1576
                                       size_t dag,
1577
                                       OutputLanguage language) const
1578
{
1579
  Printer::getPrinter(language)->toStreamCmdSetUserAttribute(
1580
      out, d_attr, termToNode(d_term));
1581
}
1582
1583
/* -------------------------------------------------------------------------- */
1584
/* class SimplifyCommand                                                      */
1585
/* -------------------------------------------------------------------------- */
1586
1587
SimplifyCommand::SimplifyCommand(api::Term term) : d_term(term) {}
1588
api::Term SimplifyCommand::getTerm() const { return d_term; }
1589
void SimplifyCommand::invoke(api::Solver* solver, SymbolManager* sm)
1590
{
1591
  try
1592
  {
1593
    d_result = solver->simplify(d_term);
1594
    d_commandStatus = CommandSuccess::instance();
1595
  }
1596
  catch (UnsafeInterruptException& e)
1597
  {
1598
    d_commandStatus = new CommandInterrupted();
1599
  }
1600
  catch (exception& e)
1601
  {
1602
    d_commandStatus = new CommandFailure(e.what());
1603
  }
1604
}
1605
1606
api::Term SimplifyCommand::getResult() const { return d_result; }
1607
void SimplifyCommand::printResult(std::ostream& out, uint32_t verbosity) const
1608
{
1609
  if (!ok())
1610
  {
1611
    this->Command::printResult(out, verbosity);
1612
  }
1613
  else
1614
  {
1615
    out << d_result << endl;
1616
  }
1617
}
1618
1619
Command* SimplifyCommand::clone() const
1620
{
1621
  SimplifyCommand* c = new SimplifyCommand(d_term);
1622
  c->d_result = d_result;
1623
  return c;
1624
}
1625
1626
std::string SimplifyCommand::getCommandName() const { return "simplify"; }
1627
1628
void SimplifyCommand::toStream(std::ostream& out,
1629
                               int toDepth,
1630
                               size_t dag,
1631
                               OutputLanguage language) const
1632
{
1633
  Printer::getPrinter(language)->toStreamCmdSimplify(out, termToNode(d_term));
1634
}
1635
1636
/* -------------------------------------------------------------------------- */
1637
/* class GetValueCommand                                                      */
1638
/* -------------------------------------------------------------------------- */
1639
1640
6
GetValueCommand::GetValueCommand(api::Term term) : d_terms()
1641
{
1642
6
  d_terms.push_back(term);
1643
6
}
1644
1645
58
GetValueCommand::GetValueCommand(const std::vector<api::Term>& terms)
1646
58
    : d_terms(terms)
1647
{
1648
58
  PrettyCheckArgument(
1649
      terms.size() >= 1, terms, "cannot get-value of an empty set of terms");
1650
58
}
1651
1652
const std::vector<api::Term>& GetValueCommand::getTerms() const
1653
{
1654
  return d_terms;
1655
}
1656
64
void GetValueCommand::invoke(api::Solver* solver, SymbolManager* sm)
1657
{
1658
  try
1659
  {
1660
126
    std::vector<api::Term> result = solver->getValue(d_terms);
1661
62
    Assert(result.size() == d_terms.size());
1662
152
    for (int i = 0, size = d_terms.size(); i < size; i++)
1663
    {
1664
180
      api::Term request = d_terms[i];
1665
180
      api::Term value = result[i];
1666
90
      result[i] = solver->mkTerm(api::SEXPR, request, value);
1667
    }
1668
62
    d_result = solver->mkTerm(api::SEXPR, result);
1669
62
    d_commandStatus = CommandSuccess::instance();
1670
  }
1671
4
  catch (api::CVC5ApiRecoverableException& e)
1672
  {
1673
2
    d_commandStatus = new CommandRecoverableFailure(e.what());
1674
  }
1675
  catch (UnsafeInterruptException& e)
1676
  {
1677
    d_commandStatus = new CommandInterrupted();
1678
  }
1679
  catch (exception& e)
1680
  {
1681
    d_commandStatus = new CommandFailure(e.what());
1682
  }
1683
64
}
1684
1685
api::Term GetValueCommand::getResult() const { return d_result; }
1686
64
void GetValueCommand::printResult(std::ostream& out, uint32_t verbosity) const
1687
{
1688
64
  if (!ok())
1689
  {
1690
2
    this->Command::printResult(out, verbosity);
1691
  }
1692
  else
1693
  {
1694
124
    expr::ExprDag::Scope scope(out, false);
1695
62
    out << d_result << endl;
1696
  }
1697
64
}
1698
1699
Command* GetValueCommand::clone() const
1700
{
1701
  GetValueCommand* c = new GetValueCommand(d_terms);
1702
  c->d_result = d_result;
1703
  return c;
1704
}
1705
1706
128
std::string GetValueCommand::getCommandName() const { return "get-value"; }
1707
1708
void GetValueCommand::toStream(std::ostream& out,
1709
                               int toDepth,
1710
                               size_t dag,
1711
                               OutputLanguage language) const
1712
{
1713
  Printer::getPrinter(language)->toStreamCmdGetValue(
1714
      out, termVectorToNodes(d_terms));
1715
}
1716
1717
/* -------------------------------------------------------------------------- */
1718
/* class GetAssignmentCommand                                                 */
1719
/* -------------------------------------------------------------------------- */
1720
1721
10
GetAssignmentCommand::GetAssignmentCommand() {}
1722
10
void GetAssignmentCommand::invoke(api::Solver* solver, SymbolManager* sm)
1723
{
1724
  try
1725
  {
1726
20
    std::map<api::Term, std::string> enames = sm->getExpressionNames();
1727
20
    std::vector<api::Term> terms;
1728
20
    std::vector<std::string> names;
1729
22
    for (const std::pair<const api::Term, std::string>& e : enames)
1730
    {
1731
12
      terms.push_back(e.first);
1732
12
      names.push_back(e.second);
1733
    }
1734
    // Must use vector version of getValue to ensure error is thrown regardless
1735
    // of whether terms is empty.
1736
18
    std::vector<api::Term> values = solver->getValue(terms);
1737
8
    Assert(values.size() == names.size());
1738
16
    std::vector<api::Term> sexprs;
1739
20
    for (size_t i = 0, nterms = terms.size(); i < nterms; i++)
1740
    {
1741
      // Treat the expression name as a variable name as opposed to a string
1742
      // constant to avoid printing double quotes around the name.
1743
24
      api::Term name = solver->mkVar(solver->getBooleanSort(), names[i]);
1744
12
      sexprs.push_back(solver->mkTerm(api::SEXPR, name, values[i]));
1745
    }
1746
8
    d_result = solver->mkTerm(api::SEXPR, sexprs);
1747
8
    d_commandStatus = CommandSuccess::instance();
1748
  }
1749
4
  catch (api::CVC5ApiRecoverableException& e)
1750
  {
1751
2
    d_commandStatus = new CommandRecoverableFailure(e.what());
1752
  }
1753
  catch (UnsafeInterruptException& e)
1754
  {
1755
    d_commandStatus = new CommandInterrupted();
1756
  }
1757
  catch (exception& e)
1758
  {
1759
    d_commandStatus = new CommandFailure(e.what());
1760
  }
1761
10
}
1762
1763
api::Term GetAssignmentCommand::getResult() const { return d_result; }
1764
10
void GetAssignmentCommand::printResult(std::ostream& out,
1765
                                       uint32_t verbosity) const
1766
{
1767
10
  if (!ok())
1768
  {
1769
2
    this->Command::printResult(out, verbosity);
1770
  }
1771
  else
1772
  {
1773
8
    out << d_result << endl;
1774
  }
1775
10
}
1776
1777
Command* GetAssignmentCommand::clone() const
1778
{
1779
  GetAssignmentCommand* c = new GetAssignmentCommand();
1780
  c->d_result = d_result;
1781
  return c;
1782
}
1783
1784
20
std::string GetAssignmentCommand::getCommandName() const
1785
{
1786
20
  return "get-assignment";
1787
}
1788
1789
void GetAssignmentCommand::toStream(std::ostream& out,
1790
                                    int toDepth,
1791
                                    size_t dag,
1792
                                    OutputLanguage language) const
1793
{
1794
  Printer::getPrinter(language)->toStreamCmdGetAssignment(out);
1795
}
1796
1797
/* -------------------------------------------------------------------------- */
1798
/* class GetModelCommand                                                      */
1799
/* -------------------------------------------------------------------------- */
1800
1801
30
GetModelCommand::GetModelCommand() : d_result(nullptr) {}
1802
30
void GetModelCommand::invoke(api::Solver* solver, SymbolManager* sm)
1803
{
1804
  try
1805
  {
1806
30
    d_result = solver->getSmtEngine()->getModel();
1807
    // set the model declarations, which determines what is printed in the model
1808
25
    d_result->clearModelDeclarations();
1809
50
    std::vector<api::Sort> declareSorts = sm->getModelDeclareSorts();
1810
29
    for (const api::Sort& s : declareSorts)
1811
    {
1812
4
      d_result->addDeclarationSort(sortToTypeNode(s));
1813
    }
1814
50
    std::vector<api::Term> declareTerms = sm->getModelDeclareTerms();
1815
55
    for (const api::Term& t : declareTerms)
1816
    {
1817
30
      d_result->addDeclarationTerm(termToNode(t));
1818
    }
1819
25
    d_commandStatus = CommandSuccess::instance();
1820
  }
1821
10
  catch (RecoverableModalException& e)
1822
  {
1823
5
    d_commandStatus = new CommandRecoverableFailure(e.what());
1824
  }
1825
  catch (UnsafeInterruptException& e)
1826
  {
1827
    d_commandStatus = new CommandInterrupted();
1828
  }
1829
  catch (exception& e)
1830
  {
1831
    d_commandStatus = new CommandFailure(e.what());
1832
  }
1833
30
}
1834
1835
/* Model is private to the library -- for now
1836
Model* GetModelCommand::getResult() const  {
1837
  return d_result;
1838
}
1839
*/
1840
1841
30
void GetModelCommand::printResult(std::ostream& out, uint32_t verbosity) const
1842
{
1843
30
  if (!ok())
1844
  {
1845
5
    this->Command::printResult(out, verbosity);
1846
  }
1847
  else
1848
  {
1849
25
    out << *d_result;
1850
  }
1851
30
}
1852
1853
Command* GetModelCommand::clone() const
1854
{
1855
  GetModelCommand* c = new GetModelCommand();
1856
  c->d_result = d_result;
1857
  return c;
1858
}
1859
1860
60
std::string GetModelCommand::getCommandName() const { return "get-model"; }
1861
1862
void GetModelCommand::toStream(std::ostream& out,
1863
                               int toDepth,
1864
                               size_t dag,
1865
                               OutputLanguage language) const
1866
{
1867
  Printer::getPrinter(language)->toStreamCmdGetModel(out);
1868
}
1869
1870
/* -------------------------------------------------------------------------- */
1871
/* class BlockModelCommand */
1872
/* -------------------------------------------------------------------------- */
1873
1874
12
BlockModelCommand::BlockModelCommand() {}
1875
12
void BlockModelCommand::invoke(api::Solver* solver, SymbolManager* sm)
1876
{
1877
  try
1878
  {
1879
12
    solver->blockModel();
1880
12
    d_commandStatus = CommandSuccess::instance();
1881
  }
1882
  catch (api::CVC5ApiRecoverableException& e)
1883
  {
1884
    d_commandStatus = new CommandRecoverableFailure(e.what());
1885
  }
1886
  catch (UnsafeInterruptException& e)
1887
  {
1888
    d_commandStatus = new CommandInterrupted();
1889
  }
1890
  catch (exception& e)
1891
  {
1892
    d_commandStatus = new CommandFailure(e.what());
1893
  }
1894
12
}
1895
1896
Command* BlockModelCommand::clone() const
1897
{
1898
  BlockModelCommand* c = new BlockModelCommand();
1899
  return c;
1900
}
1901
1902
24
std::string BlockModelCommand::getCommandName() const { return "block-model"; }
1903
1904
void BlockModelCommand::toStream(std::ostream& out,
1905
                                 int toDepth,
1906
                                 size_t dag,
1907
                                 OutputLanguage language) const
1908
{
1909
  Printer::getPrinter(language)->toStreamCmdBlockModel(out);
1910
}
1911
1912
/* -------------------------------------------------------------------------- */
1913
/* class BlockModelValuesCommand */
1914
/* -------------------------------------------------------------------------- */
1915
1916
6
BlockModelValuesCommand::BlockModelValuesCommand(
1917
6
    const std::vector<api::Term>& terms)
1918
6
    : d_terms(terms)
1919
{
1920
6
  PrettyCheckArgument(terms.size() >= 1,
1921
                      terms,
1922
                      "cannot block-model-values of an empty set of terms");
1923
6
}
1924
1925
const std::vector<api::Term>& BlockModelValuesCommand::getTerms() const
1926
{
1927
  return d_terms;
1928
}
1929
6
void BlockModelValuesCommand::invoke(api::Solver* solver, SymbolManager* sm)
1930
{
1931
  try
1932
  {
1933
6
    solver->blockModelValues(d_terms);
1934
6
    d_commandStatus = CommandSuccess::instance();
1935
  }
1936
  catch (api::CVC5ApiRecoverableException& e)
1937
  {
1938
    d_commandStatus = new CommandRecoverableFailure(e.what());
1939
  }
1940
  catch (UnsafeInterruptException& e)
1941
  {
1942
    d_commandStatus = new CommandInterrupted();
1943
  }
1944
  catch (exception& e)
1945
  {
1946
    d_commandStatus = new CommandFailure(e.what());
1947
  }
1948
6
}
1949
1950
Command* BlockModelValuesCommand::clone() const
1951
{
1952
  BlockModelValuesCommand* c = new BlockModelValuesCommand(d_terms);
1953
  return c;
1954
}
1955
1956
12
std::string BlockModelValuesCommand::getCommandName() const
1957
{
1958
12
  return "block-model-values";
1959
}
1960
1961
void BlockModelValuesCommand::toStream(std::ostream& out,
1962
                                       int toDepth,
1963
                                       size_t dag,
1964
                                       OutputLanguage language) const
1965
{
1966
  Printer::getPrinter(language)->toStreamCmdBlockModelValues(
1967
      out, termVectorToNodes(d_terms));
1968
}
1969
1970
/* -------------------------------------------------------------------------- */
1971
/* class GetProofCommand                                                      */
1972
/* -------------------------------------------------------------------------- */
1973
1974
1
GetProofCommand::GetProofCommand() {}
1975
1
void GetProofCommand::invoke(api::Solver* solver, SymbolManager* sm)
1976
{
1977
  try
1978
  {
1979
1
    d_result = solver->getSmtEngine()->getProof();
1980
1
    d_commandStatus = CommandSuccess::instance();
1981
  }
1982
  catch (api::CVC5ApiRecoverableException& e)
1983
  {
1984
    d_commandStatus = new CommandRecoverableFailure(e.what());
1985
  }
1986
  catch (exception& e)
1987
  {
1988
    d_commandStatus = new CommandFailure(e.what());
1989
  }
1990
1
}
1991
1992
1
void GetProofCommand::printResult(std::ostream& out, uint32_t verbosity) const
1993
{
1994
1
  if (ok())
1995
  {
1996
1
    out << d_result;
1997
  }
1998
  else
1999
  {
2000
    this->Command::printResult(out, verbosity);
2001
  }
2002
1
}
2003
2004
Command* GetProofCommand::clone() const
2005
{
2006
  GetProofCommand* c = new GetProofCommand();
2007
  return c;
2008
}
2009
2010
2
std::string GetProofCommand::getCommandName() const { return "get-proof"; }
2011
2012
void GetProofCommand::toStream(std::ostream& out,
2013
                               int toDepth,
2014
                               size_t dag,
2015
                               OutputLanguage language) const
2016
{
2017
  Printer::getPrinter(language)->toStreamCmdGetProof(out);
2018
}
2019
2020
/* -------------------------------------------------------------------------- */
2021
/* class GetInstantiationsCommand                                             */
2022
/* -------------------------------------------------------------------------- */
2023
2024
12
GetInstantiationsCommand::GetInstantiationsCommand() : d_solver(nullptr) {}
2025
12
void GetInstantiationsCommand::invoke(api::Solver* solver, SymbolManager* sm)
2026
{
2027
  try
2028
  {
2029
12
    d_solver = solver;
2030
12
    d_commandStatus = CommandSuccess::instance();
2031
  }
2032
  catch (exception& e)
2033
  {
2034
    d_commandStatus = new CommandFailure(e.what());
2035
  }
2036
12
}
2037
2038
12
void GetInstantiationsCommand::printResult(std::ostream& out,
2039
                                           uint32_t verbosity) const
2040
{
2041
12
  if (!ok())
2042
  {
2043
    this->Command::printResult(out, verbosity);
2044
  }
2045
  else
2046
  {
2047
12
    d_solver->printInstantiations(out);
2048
  }
2049
12
}
2050
2051
Command* GetInstantiationsCommand::clone() const
2052
{
2053
  GetInstantiationsCommand* c = new GetInstantiationsCommand();
2054
  // c->d_result = d_result;
2055
  c->d_solver = d_solver;
2056
  return c;
2057
}
2058
2059
24
std::string GetInstantiationsCommand::getCommandName() const
2060
{
2061
24
  return "get-instantiations";
2062
}
2063
2064
void GetInstantiationsCommand::toStream(std::ostream& out,
2065
                                        int toDepth,
2066
                                        size_t dag,
2067
                                        OutputLanguage language) const
2068
{
2069
  Printer::getPrinter(language)->toStreamCmdGetInstantiations(out);
2070
}
2071
2072
/* -------------------------------------------------------------------------- */
2073
/* class GetSynthSolutionCommand                                              */
2074
/* -------------------------------------------------------------------------- */
2075
2076
GetSynthSolutionCommand::GetSynthSolutionCommand() : d_solver(nullptr) {}
2077
void GetSynthSolutionCommand::invoke(api::Solver* solver, SymbolManager* sm)
2078
{
2079
  try
2080
  {
2081
    d_solver = solver;
2082
    d_commandStatus = CommandSuccess::instance();
2083
  }
2084
  catch (exception& e)
2085
  {
2086
    d_commandStatus = new CommandFailure(e.what());
2087
  }
2088
}
2089
2090
void GetSynthSolutionCommand::printResult(std::ostream& out,
2091
                                          uint32_t verbosity) const
2092
{
2093
  if (!ok())
2094
  {
2095
    this->Command::printResult(out, verbosity);
2096
  }
2097
  else
2098
  {
2099
    d_solver->printSynthSolution(out);
2100
  }
2101
}
2102
2103
Command* GetSynthSolutionCommand::clone() const
2104
{
2105
  GetSynthSolutionCommand* c = new GetSynthSolutionCommand();
2106
  c->d_solver = d_solver;
2107
  return c;
2108
}
2109
2110
std::string GetSynthSolutionCommand::getCommandName() const
2111
{
2112
  return "get-synth-solution";
2113
}
2114
2115
void GetSynthSolutionCommand::toStream(std::ostream& out,
2116
                                       int toDepth,
2117
                                       size_t dag,
2118
                                       OutputLanguage language) const
2119
{
2120
  Printer::getPrinter(language)->toStreamCmdGetSynthSolution(out);
2121
}
2122
2123
/* -------------------------------------------------------------------------- */
2124
/* class GetInterpolCommand                                                   */
2125
/* -------------------------------------------------------------------------- */
2126
2127
GetInterpolCommand::GetInterpolCommand(const std::string& name, api::Term conj)
2128
    : d_name(name), d_conj(conj), d_resultStatus(false)
2129
{
2130
}
2131
8
GetInterpolCommand::GetInterpolCommand(const std::string& name,
2132
                                       api::Term conj,
2133
8
                                       api::Grammar* g)
2134
8
    : d_name(name), d_conj(conj), d_sygus_grammar(g), d_resultStatus(false)
2135
{
2136
8
}
2137
2138
api::Term GetInterpolCommand::getConjecture() const { return d_conj; }
2139
2140
const api::Grammar* GetInterpolCommand::getGrammar() const
2141
{
2142
  return d_sygus_grammar;
2143
}
2144
2145
api::Term GetInterpolCommand::getResult() const { return d_result; }
2146
2147
8
void GetInterpolCommand::invoke(api::Solver* solver, SymbolManager* sm)
2148
{
2149
  try
2150
  {
2151
8
    if (d_sygus_grammar == nullptr)
2152
    {
2153
7
      d_resultStatus = solver->getInterpolant(d_conj, d_result);
2154
    }
2155
    else
2156
    {
2157
1
      d_resultStatus =
2158
1
          solver->getInterpolant(d_conj, *d_sygus_grammar, d_result);
2159
    }
2160
8
    d_commandStatus = CommandSuccess::instance();
2161
  }
2162
  catch (exception& e)
2163
  {
2164
    d_commandStatus = new CommandFailure(e.what());
2165
  }
2166
8
}
2167
2168
8
void GetInterpolCommand::printResult(std::ostream& out,
2169
                                     uint32_t verbosity) const
2170
{
2171
8
  if (!ok())
2172
  {
2173
    this->Command::printResult(out, verbosity);
2174
  }
2175
  else
2176
  {
2177
16
    expr::ExprDag::Scope scope(out, false);
2178
8
    if (d_resultStatus)
2179
    {
2180
8
      out << "(define-fun " << d_name << " () Bool " << d_result << ")"
2181
8
          << std::endl;
2182
    }
2183
    else
2184
    {
2185
      out << "none" << std::endl;
2186
    }
2187
  }
2188
8
}
2189
2190
Command* GetInterpolCommand::clone() const
2191
{
2192
  GetInterpolCommand* c =
2193
      new GetInterpolCommand(d_name, d_conj, d_sygus_grammar);
2194
  c->d_result = d_result;
2195
  c->d_resultStatus = d_resultStatus;
2196
  return c;
2197
}
2198
2199
16
std::string GetInterpolCommand::getCommandName() const
2200
{
2201
16
  return "get-interpol";
2202
}
2203
2204
void GetInterpolCommand::toStream(std::ostream& out,
2205
                                  int toDepth,
2206
                                  size_t dag,
2207
                                  OutputLanguage language) const
2208
{
2209
  Printer::getPrinter(language)->toStreamCmdGetInterpol(
2210
      out, d_name, termToNode(d_conj), grammarToTypeNode(d_sygus_grammar));
2211
}
2212
2213
/* -------------------------------------------------------------------------- */
2214
/* class GetAbductCommand                                                     */
2215
/* -------------------------------------------------------------------------- */
2216
2217
GetAbductCommand::GetAbductCommand(const std::string& name, api::Term conj)
2218
    : d_name(name), d_conj(conj), d_resultStatus(false)
2219
{
2220
}
2221
11
GetAbductCommand::GetAbductCommand(const std::string& name,
2222
                                   api::Term conj,
2223
11
                                   api::Grammar* g)
2224
11
    : d_name(name), d_conj(conj), d_sygus_grammar(g), d_resultStatus(false)
2225
{
2226
11
}
2227
2228
api::Term GetAbductCommand::getConjecture() const { return d_conj; }
2229
2230
const api::Grammar* GetAbductCommand::getGrammar() const
2231
{
2232
  return d_sygus_grammar;
2233
}
2234
2235
std::string GetAbductCommand::getAbductName() const { return d_name; }
2236
api::Term GetAbductCommand::getResult() const { return d_result; }
2237
2238
11
void GetAbductCommand::invoke(api::Solver* solver, SymbolManager* sm)
2239
{
2240
  try
2241
  {
2242
11
    if (d_sygus_grammar == nullptr)
2243
    {
2244
7
      d_resultStatus = solver->getAbduct(d_conj, d_result);
2245
    }
2246
    else
2247
    {
2248
4
      d_resultStatus = solver->getAbduct(d_conj, *d_sygus_grammar, d_result);
2249
    }
2250
9
    d_commandStatus = CommandSuccess::instance();
2251
  }
2252
4
  catch (exception& e)
2253
  {
2254
2
    d_commandStatus = new CommandFailure(e.what());
2255
  }
2256
11
}
2257
2258
11
void GetAbductCommand::printResult(std::ostream& out, uint32_t verbosity) const
2259
{
2260
11
  if (!ok())
2261
  {
2262
2
    this->Command::printResult(out, verbosity);
2263
  }
2264
  else
2265
  {
2266
18
    expr::ExprDag::Scope scope(out, false);
2267
9
    if (d_resultStatus)
2268
    {
2269
9
      out << "(define-fun " << d_name << " () Bool " << d_result << ")"
2270
9
          << std::endl;
2271
    }
2272
    else
2273
    {
2274
      out << "none" << std::endl;
2275
    }
2276
  }
2277
11
}
2278
2279
Command* GetAbductCommand::clone() const
2280
{
2281
  GetAbductCommand* c = new GetAbductCommand(d_name, d_conj, d_sygus_grammar);
2282
  c->d_result = d_result;
2283
  c->d_resultStatus = d_resultStatus;
2284
  return c;
2285
}
2286
2287
22
std::string GetAbductCommand::getCommandName() const { return "get-abduct"; }
2288
2289
void GetAbductCommand::toStream(std::ostream& out,
2290
                                int toDepth,
2291
                                size_t dag,
2292
                                OutputLanguage language) const
2293
{
2294
  Printer::getPrinter(language)->toStreamCmdGetAbduct(
2295
      out, d_name, termToNode(d_conj), grammarToTypeNode(d_sygus_grammar));
2296
}
2297
2298
/* -------------------------------------------------------------------------- */
2299
/* class GetQuantifierEliminationCommand                                      */
2300
/* -------------------------------------------------------------------------- */
2301
2302
GetQuantifierEliminationCommand::GetQuantifierEliminationCommand()
2303
    : d_term(), d_doFull(true)
2304
{
2305
}
2306
8
GetQuantifierEliminationCommand::GetQuantifierEliminationCommand(
2307
8
    const api::Term& term, bool doFull)
2308
8
    : d_term(term), d_doFull(doFull)
2309
{
2310
8
}
2311
2312
api::Term GetQuantifierEliminationCommand::getTerm() const { return d_term; }
2313
bool GetQuantifierEliminationCommand::getDoFull() const { return d_doFull; }
2314
8
void GetQuantifierEliminationCommand::invoke(api::Solver* solver,
2315
                                             SymbolManager* sm)
2316
{
2317
  try
2318
  {
2319
8
    if (d_doFull)
2320
    {
2321
7
      d_result = solver->getQuantifierElimination(d_term);
2322
    }
2323
    else
2324
    {
2325
1
      d_result = solver->getQuantifierEliminationDisjunct(d_term);
2326
    }
2327
8
    d_commandStatus = CommandSuccess::instance();
2328
  }
2329
  catch (exception& e)
2330
  {
2331
    d_commandStatus = new CommandFailure(e.what());
2332
  }
2333
8
}
2334
2335
api::Term GetQuantifierEliminationCommand::getResult() const
2336
{
2337
  return d_result;
2338
}
2339
8
void GetQuantifierEliminationCommand::printResult(std::ostream& out,
2340
                                                  uint32_t verbosity) const
2341
{
2342
8
  if (!ok())
2343
  {
2344
    this->Command::printResult(out, verbosity);
2345
  }
2346
  else
2347
  {
2348
8
    out << d_result << endl;
2349
  }
2350
8
}
2351
2352
Command* GetQuantifierEliminationCommand::clone() const
2353
{
2354
  GetQuantifierEliminationCommand* c =
2355
      new GetQuantifierEliminationCommand(d_term, d_doFull);
2356
  c->d_result = d_result;
2357
  return c;
2358
}
2359
2360
16
std::string GetQuantifierEliminationCommand::getCommandName() const
2361
{
2362
16
  return d_doFull ? "get-qe" : "get-qe-disjunct";
2363
}
2364
2365
void GetQuantifierEliminationCommand::toStream(std::ostream& out,
2366
                                               int toDepth,
2367
                                               size_t dag,
2368
                                               OutputLanguage language) const
2369
{
2370
  Printer::getPrinter(language)->toStreamCmdGetQuantifierElimination(
2371
      out, termToNode(d_term));
2372
}
2373
2374
/* -------------------------------------------------------------------------- */
2375
/* class GetUnsatAssumptionsCommand                                           */
2376
/* -------------------------------------------------------------------------- */
2377
2378
8
GetUnsatAssumptionsCommand::GetUnsatAssumptionsCommand() {}
2379
2380
8
void GetUnsatAssumptionsCommand::invoke(api::Solver* solver, SymbolManager* sm)
2381
{
2382
  try
2383
  {
2384
8
    d_result = solver->getUnsatAssumptions();
2385
8
    d_commandStatus = CommandSuccess::instance();
2386
  }
2387
  catch (api::CVC5ApiRecoverableException& e)
2388
  {
2389
    d_commandStatus = new CommandRecoverableFailure(e.what());
2390
  }
2391
  catch (exception& e)
2392
  {
2393
    d_commandStatus = new CommandFailure(e.what());
2394
  }
2395
8
}
2396
2397
std::vector<api::Term> GetUnsatAssumptionsCommand::getResult() const
2398
{
2399
  return d_result;
2400
}
2401
2402
8
void GetUnsatAssumptionsCommand::printResult(std::ostream& out,
2403
                                             uint32_t verbosity) const
2404
{
2405
8
  if (!ok())
2406
  {
2407
    this->Command::printResult(out, verbosity);
2408
  }
2409
  else
2410
  {
2411
8
    container_to_stream(out, d_result, "(", ")\n", " ");
2412
  }
2413
8
}
2414
2415
Command* GetUnsatAssumptionsCommand::clone() const
2416
{
2417
  GetUnsatAssumptionsCommand* c = new GetUnsatAssumptionsCommand;
2418
  c->d_result = d_result;
2419
  return c;
2420
}
2421
2422
16
std::string GetUnsatAssumptionsCommand::getCommandName() const
2423
{
2424
16
  return "get-unsat-assumptions";
2425
}
2426
2427
void GetUnsatAssumptionsCommand::toStream(std::ostream& out,
2428
                                          int toDepth,
2429
                                          size_t dag,
2430
                                          OutputLanguage language) const
2431
{
2432
  Printer::getPrinter(language)->toStreamCmdGetUnsatAssumptions(out);
2433
}
2434
2435
/* -------------------------------------------------------------------------- */
2436
/* class GetUnsatCoreCommand                                                  */
2437
/* -------------------------------------------------------------------------- */
2438
2439
12
GetUnsatCoreCommand::GetUnsatCoreCommand() : d_sm(nullptr) {}
2440
12
void GetUnsatCoreCommand::invoke(api::Solver* solver, SymbolManager* sm)
2441
{
2442
  try
2443
  {
2444
12
    d_sm = sm;
2445
12
    d_result = solver->getUnsatCore();
2446
2447
10
    d_commandStatus = CommandSuccess::instance();
2448
  }
2449
4
  catch (api::CVC5ApiRecoverableException& e)
2450
  {
2451
2
    d_commandStatus = new CommandRecoverableFailure(e.what());
2452
  }
2453
  catch (exception& e)
2454
  {
2455
    d_commandStatus = new CommandFailure(e.what());
2456
  }
2457
12
}
2458
2459
12
void GetUnsatCoreCommand::printResult(std::ostream& out,
2460
                                      uint32_t verbosity) const
2461
{
2462
12
  if (!ok())
2463
  {
2464
2
    this->Command::printResult(out, verbosity);
2465
  }
2466
  else
2467
  {
2468
303673
    if (options::dumpUnsatCoresFull())
2469
    {
2470
      // use the assertions
2471
6
      UnsatCore ucr(termVectorToNodes(d_result));
2472
3
      ucr.toStream(out);
2473
    }
2474
    else
2475
    {
2476
      // otherwise, use the names
2477
14
      std::vector<std::string> names;
2478
7
      d_sm->getExpressionNames(d_result, names, true);
2479
14
      UnsatCore ucr(names);
2480
7
      ucr.toStream(out);
2481
    }
2482
  }
2483
12
}
2484
2485
const std::vector<api::Term>& GetUnsatCoreCommand::getUnsatCore() const
2486
{
2487
  // of course, this will be empty if the command hasn't been invoked yet
2488
  return d_result;
2489
}
2490
2491
Command* GetUnsatCoreCommand::clone() const
2492
{
2493
  GetUnsatCoreCommand* c = new GetUnsatCoreCommand;
2494
  c->d_sm = d_sm;
2495
  c->d_result = d_result;
2496
  return c;
2497
}
2498
2499
24
std::string GetUnsatCoreCommand::getCommandName() const
2500
{
2501
24
  return "get-unsat-core";
2502
}
2503
2504
void GetUnsatCoreCommand::toStream(std::ostream& out,
2505
                                   int toDepth,
2506
                                   size_t dag,
2507
                                   OutputLanguage language) const
2508
{
2509
  Printer::getPrinter(language)->toStreamCmdGetUnsatCore(out);
2510
}
2511
2512
/* -------------------------------------------------------------------------- */
2513
/* class GetAssertionsCommand                                                 */
2514
/* -------------------------------------------------------------------------- */
2515
2516
GetAssertionsCommand::GetAssertionsCommand() {}
2517
void GetAssertionsCommand::invoke(api::Solver* solver, SymbolManager* sm)
2518
{
2519
  try
2520
  {
2521
    stringstream ss;
2522
    const vector<api::Term> v = solver->getAssertions();
2523
    ss << "(\n";
2524
    copy(v.begin(), v.end(), ostream_iterator<api::Term>(ss, "\n"));
2525
    ss << ")\n";
2526
    d_result = ss.str();
2527
    d_commandStatus = CommandSuccess::instance();
2528
  }
2529
  catch (exception& e)
2530
  {
2531
    d_commandStatus = new CommandFailure(e.what());
2532
  }
2533
}
2534
2535
std::string GetAssertionsCommand::getResult() const { return d_result; }
2536
void GetAssertionsCommand::printResult(std::ostream& out,
2537
                                       uint32_t verbosity) const
2538
{
2539
  if (!ok())
2540
  {
2541
    this->Command::printResult(out, verbosity);
2542
  }
2543
  else
2544
  {
2545
    out << d_result;
2546
  }
2547
}
2548
2549
Command* GetAssertionsCommand::clone() const
2550
{
2551
  GetAssertionsCommand* c = new GetAssertionsCommand();
2552
  c->d_result = d_result;
2553
  return c;
2554
}
2555
2556
std::string GetAssertionsCommand::getCommandName() const
2557
{
2558
  return "get-assertions";
2559
}
2560
2561
void GetAssertionsCommand::toStream(std::ostream& out,
2562
                                    int toDepth,
2563
                                    size_t dag,
2564
                                    OutputLanguage language) const
2565
{
2566
  Printer::getPrinter(language)->toStreamCmdGetAssertions(out);
2567
}
2568
2569
/* -------------------------------------------------------------------------- */
2570
/* class SetBenchmarkStatusCommand                                            */
2571
/* -------------------------------------------------------------------------- */
2572
2573
SetBenchmarkStatusCommand::SetBenchmarkStatusCommand(BenchmarkStatus status)
2574
    : d_status(status)
2575
{
2576
}
2577
2578
BenchmarkStatus SetBenchmarkStatusCommand::getStatus() const
2579
{
2580
  return d_status;
2581
}
2582
2583
void SetBenchmarkStatusCommand::invoke(api::Solver* solver, SymbolManager* sm)
2584
{
2585
  try
2586
  {
2587
    stringstream ss;
2588
    ss << d_status;
2589
    solver->setInfo("status", ss.str());
2590
    d_commandStatus = CommandSuccess::instance();
2591
  }
2592
  catch (exception& e)
2593
  {
2594
    d_commandStatus = new CommandFailure(e.what());
2595
  }
2596
}
2597
2598
Command* SetBenchmarkStatusCommand::clone() const
2599
{
2600
  return new SetBenchmarkStatusCommand(d_status);
2601
}
2602
2603
std::string SetBenchmarkStatusCommand::getCommandName() const
2604
{
2605
  return "set-info";
2606
}
2607
2608
void SetBenchmarkStatusCommand::toStream(std::ostream& out,
2609
                                         int toDepth,
2610
                                         size_t dag,
2611
                                         OutputLanguage language) const
2612
{
2613
  Result::Sat status = Result::SAT_UNKNOWN;
2614
  switch (d_status)
2615
  {
2616
    case BenchmarkStatus::SMT_SATISFIABLE: status = Result::SAT; break;
2617
    case BenchmarkStatus::SMT_UNSATISFIABLE: status = Result::UNSAT; break;
2618
    case BenchmarkStatus::SMT_UNKNOWN: status = Result::SAT_UNKNOWN; break;
2619
  }
2620
2621
  Printer::getPrinter(language)->toStreamCmdSetBenchmarkStatus(out, status);
2622
}
2623
2624
/* -------------------------------------------------------------------------- */
2625
/* class SetBenchmarkLogicCommand                                             */
2626
/* -------------------------------------------------------------------------- */
2627
2628
5239
SetBenchmarkLogicCommand::SetBenchmarkLogicCommand(std::string logic)
2629
5239
    : d_logic(logic)
2630
{
2631
5239
}
2632
2633
std::string SetBenchmarkLogicCommand::getLogic() const { return d_logic; }
2634
5174
void SetBenchmarkLogicCommand::invoke(api::Solver* solver, SymbolManager* sm)
2635
{
2636
  try
2637
  {
2638
5174
    solver->setLogic(d_logic);
2639
5174
    d_commandStatus = CommandSuccess::instance();
2640
  }
2641
  catch (exception& e)
2642
  {
2643
    d_commandStatus = new CommandFailure(e.what());
2644
  }
2645
5174
}
2646
2647
Command* SetBenchmarkLogicCommand::clone() const
2648
{
2649
  return new SetBenchmarkLogicCommand(d_logic);
2650
}
2651
2652
10313
std::string SetBenchmarkLogicCommand::getCommandName() const
2653
{
2654
10313
  return "set-logic";
2655
}
2656
2657
1
void SetBenchmarkLogicCommand::toStream(std::ostream& out,
2658
                                        int toDepth,
2659
                                        size_t dag,
2660
                                        OutputLanguage language) const
2661
{
2662
1
  Printer::getPrinter(language)->toStreamCmdSetBenchmarkLogic(out, d_logic);
2663
1
}
2664
2665
/* -------------------------------------------------------------------------- */
2666
/* class SetInfoCommand                                                       */
2667
/* -------------------------------------------------------------------------- */
2668
2669
5537
SetInfoCommand::SetInfoCommand(const std::string& flag,
2670
5537
                               const std::string& value)
2671
5537
    : d_flag(flag), d_value(value)
2672
{
2673
5537
}
2674
2675
const std::string& SetInfoCommand::getFlag() const { return d_flag; }
2676
const std::string& SetInfoCommand::getValue() const { return d_value; }
2677
5533
void SetInfoCommand::invoke(api::Solver* solver, SymbolManager* sm)
2678
{
2679
  try
2680
  {
2681
5533
    solver->setInfo(d_flag, d_value);
2682
5520
    d_commandStatus = CommandSuccess::instance();
2683
  }
2684
26
  catch (api::CVC5ApiRecoverableException&)
2685
  {
2686
    // As per SMT-LIB spec, silently accept unknown set-info keys
2687
13
    d_commandStatus = CommandSuccess::instance();
2688
  }
2689
  catch (exception& e)
2690
  {
2691
    d_commandStatus = new CommandFailure(e.what());
2692
  }
2693
5533
}
2694
2695
Command* SetInfoCommand::clone() const
2696
{
2697
  return new SetInfoCommand(d_flag, d_value);
2698
}
2699
2700
11066
std::string SetInfoCommand::getCommandName() const { return "set-info"; }
2701
2702
void SetInfoCommand::toStream(std::ostream& out,
2703
                              int toDepth,
2704
                              size_t dag,
2705
                              OutputLanguage language) const
2706
{
2707
  Printer::getPrinter(language)->toStreamCmdSetInfo(out, d_flag, d_value);
2708
}
2709
2710
/* -------------------------------------------------------------------------- */
2711
/* class GetInfoCommand                                                       */
2712
/* -------------------------------------------------------------------------- */
2713
2714
20
GetInfoCommand::GetInfoCommand(std::string flag) : d_flag(flag) {}
2715
std::string GetInfoCommand::getFlag() const { return d_flag; }
2716
20
void GetInfoCommand::invoke(api::Solver* solver, SymbolManager* sm)
2717
{
2718
  try
2719
  {
2720
40
    std::vector<api::Term> v;
2721
20
    v.push_back(solver->mkString(":" + d_flag));
2722
20
    v.push_back(solver->mkString(solver->getInfo(d_flag)));
2723
12
    d_result = sexprToString(solver->mkTerm(api::SEXPR, v));
2724
12
    d_commandStatus = CommandSuccess::instance();
2725
  }
2726
14
  catch (api::CVC5ApiRecoverableException& e)
2727
  {
2728
7
    d_commandStatus = new CommandRecoverableFailure(e.what());
2729
  }
2730
2
  catch (exception& e)
2731
  {
2732
1
    d_commandStatus = new CommandFailure(e.what());
2733
  }
2734
20
}
2735
2736
std::string GetInfoCommand::getResult() const { return d_result; }
2737
20
void GetInfoCommand::printResult(std::ostream& out, uint32_t verbosity) const
2738
{
2739
20
  if (!ok())
2740
  {
2741
8
    this->Command::printResult(out, verbosity);
2742
  }
2743
12
  else if (d_result != "")
2744
  {
2745
12
    out << d_result << endl;
2746
  }
2747
20
}
2748
2749
Command* GetInfoCommand::clone() const
2750
{
2751
  GetInfoCommand* c = new GetInfoCommand(d_flag);
2752
  c->d_result = d_result;
2753
  return c;
2754
}
2755
2756
29
std::string GetInfoCommand::getCommandName() const { return "get-info"; }
2757
2758
11
void GetInfoCommand::toStream(std::ostream& out,
2759
                              int toDepth,
2760
                              size_t dag,
2761
                              OutputLanguage language) const
2762
{
2763
11
  Printer::getPrinter(language)->toStreamCmdGetInfo(out, d_flag);
2764
11
}
2765
2766
/* -------------------------------------------------------------------------- */
2767
/* class SetOptionCommand                                                     */
2768
/* -------------------------------------------------------------------------- */
2769
2770
7072
SetOptionCommand::SetOptionCommand(const std::string& flag,
2771
7072
                                   const std::string& value)
2772
7072
    : d_flag(flag), d_value(value)
2773
{
2774
7072
}
2775
2776
const std::string& SetOptionCommand::getFlag() const { return d_flag; }
2777
const std::string& SetOptionCommand::getValue() const { return d_value; }
2778
7072
void SetOptionCommand::invoke(api::Solver* solver, SymbolManager* sm)
2779
{
2780
  try
2781
  {
2782
7072
    solver->setOption(d_flag, d_value);
2783
7072
    d_commandStatus = CommandSuccess::instance();
2784
  }
2785
  catch (api::CVC5ApiRecoverableException&)
2786
  {
2787
    d_commandStatus = new CommandUnsupported();
2788
  }
2789
  catch (exception& e)
2790
  {
2791
    d_commandStatus = new CommandFailure(e.what());
2792
  }
2793
7072
}
2794
2795
Command* SetOptionCommand::clone() const
2796
{
2797
  return new SetOptionCommand(d_flag, d_value);
2798
}
2799
2800
8926
std::string SetOptionCommand::getCommandName() const { return "set-option"; }
2801
2802
1
void SetOptionCommand::toStream(std::ostream& out,
2803
                                int toDepth,
2804
                                size_t dag,
2805
                                OutputLanguage language) const
2806
{
2807
1
  Printer::getPrinter(language)->toStreamCmdSetOption(out, d_flag, d_value);
2808
1
}
2809
2810
/* -------------------------------------------------------------------------- */
2811
/* class GetOptionCommand                                                     */
2812
/* -------------------------------------------------------------------------- */
2813
2814
11
GetOptionCommand::GetOptionCommand(std::string flag) : d_flag(flag) {}
2815
std::string GetOptionCommand::getFlag() const { return d_flag; }
2816
11
void GetOptionCommand::invoke(api::Solver* solver, SymbolManager* sm)
2817
{
2818
  try
2819
  {
2820
11
    d_result = solver->getOption(d_flag);
2821
11
    d_commandStatus = CommandSuccess::instance();
2822
  }
2823
  catch (api::CVC5ApiRecoverableException&)
2824
  {
2825
    d_commandStatus = new CommandUnsupported();
2826
  }
2827
  catch (exception& e)
2828
  {
2829
    d_commandStatus = new CommandFailure(e.what());
2830
  }
2831
11
}
2832
2833
std::string GetOptionCommand::getResult() const { return d_result; }
2834
11
void GetOptionCommand::printResult(std::ostream& out, uint32_t verbosity) const
2835
{
2836
11
  if (!ok())
2837
  {
2838
    this->Command::printResult(out, verbosity);
2839
  }
2840
11
  else if (d_result != "")
2841
  {
2842
11
    out << d_result << endl;
2843
  }
2844
11
}
2845
2846
Command* GetOptionCommand::clone() const
2847
{
2848
  GetOptionCommand* c = new GetOptionCommand(d_flag);
2849
  c->d_result = d_result;
2850
  return c;
2851
}
2852
2853
22
std::string GetOptionCommand::getCommandName() const { return "get-option"; }
2854
2855
void GetOptionCommand::toStream(std::ostream& out,
2856
                                int toDepth,
2857
                                size_t dag,
2858
                                OutputLanguage language) const
2859
{
2860
  Printer::getPrinter(language)->toStreamCmdGetOption(out, d_flag);
2861
}
2862
2863
/* -------------------------------------------------------------------------- */
2864
/* class DatatypeDeclarationCommand                                           */
2865
/* -------------------------------------------------------------------------- */
2866
2867
DatatypeDeclarationCommand::DatatypeDeclarationCommand(
2868
    const api::Sort& datatype)
2869
    : d_datatypes()
2870
{
2871
  d_datatypes.push_back(datatype);
2872
}
2873
2874
923
DatatypeDeclarationCommand::DatatypeDeclarationCommand(
2875
923
    const std::vector<api::Sort>& datatypes)
2876
923
    : d_datatypes(datatypes)
2877
{
2878
923
}
2879
2880
const std::vector<api::Sort>& DatatypeDeclarationCommand::getDatatypes() const
2881
{
2882
  return d_datatypes;
2883
}
2884
2885
909
void DatatypeDeclarationCommand::invoke(api::Solver* solver, SymbolManager* sm)
2886
{
2887
909
  d_commandStatus = CommandSuccess::instance();
2888
909
}
2889
2890
Command* DatatypeDeclarationCommand::clone() const
2891
{
2892
  return new DatatypeDeclarationCommand(d_datatypes);
2893
}
2894
2895
1818
std::string DatatypeDeclarationCommand::getCommandName() const
2896
{
2897
1818
  return "declare-datatypes";
2898
}
2899
2900
void DatatypeDeclarationCommand::toStream(std::ostream& out,
2901
                                          int toDepth,
2902
                                          size_t dag,
2903
                                          OutputLanguage language) const
2904
{
2905
  Printer::getPrinter(language)->toStreamCmdDatatypeDeclaration(
2906
      out, sortVectorToTypeNodes(d_datatypes));
2907
}
2908
2909
332270
}  // namespace cvc5