GCC Code Coverage Report
Directory: . Exec Total Coverage
File: src/smt/command.cpp Lines: 686 1273 53.9 %
Date: 2021-09-15 Branches: 496 1542 32.2 %

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