GCC Code Coverage Report
Directory: . Exec Total Coverage
File: src/smt/command.cpp Lines: 692 1271 54.4 %
Date: 2021-08-20 Branches: 509 1551 32.8 %

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