GCC Code Coverage Report
Directory: . Exec Total Coverage
File: src/smt/command.cpp Lines: 687 1266 54.3 %
Date: 2021-05-22 Branches: 502 1551 32.4 %

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