GCC Code Coverage Report
Directory: . Exec Total Coverage
File: src/smt/command.cpp Lines: 692 1269 54.5 %
Date: 2021-08-03 Branches: 517 1571 32.9 %

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