GCC Code Coverage Report
Directory: . Exec Total Coverage
File: src/smt/command.cpp Lines: 696 1274 54.6 %
Date: 2021-08-01 Branches: 519 1575 33.0 %

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