summaryrefslogtreecommitdiff
path: root/src/smt/node_command.cpp
blob: 000107341eb15e4bdea1b56948067427bb927509 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
/******************************************************************************
 * Top contributors (to current version):
 *   Abdalrhman Mohamed, Yoni Zohar, Andrew Reynolds
 *
 * This file is part of the cvc5 project.
 *
 * Copyright (c) 2009-2021 by the authors listed in the file AUTHORS
 * in the top-level source directory and their institutional affiliations.
 * All rights reserved.  See the file COPYING in the top-level source
 * directory for licensing information.
 * ****************************************************************************
 *
 * Implementation of NodeCommand functions.
 */

#include "smt/node_command.h"

#include <sstream>

#include "printer/printer.h"

namespace cvc5 {

/* -------------------------------------------------------------------------- */
/* class NodeCommand                                                          */
/* -------------------------------------------------------------------------- */

NodeCommand::~NodeCommand() {}

std::string NodeCommand::toString() const
{
  std::stringstream ss;
  toStream(ss);
  return ss.str();
}

std::ostream& operator<<(std::ostream& out, const NodeCommand& nc)
{
  nc.toStream(out,
              Node::setdepth::getDepth(out),
              Node::dag::getDag(out),
              Node::setlanguage::getLanguage(out));
  return out;
}

/* -------------------------------------------------------------------------- */
/* class DeclareFunctionNodeCommand                                           */
/* -------------------------------------------------------------------------- */

DeclareFunctionNodeCommand::DeclareFunctionNodeCommand(const std::string& id,
                                                       Node expr,
                                                       TypeNode type)
    : d_id(id),
      d_fun(expr),
      d_type(type)
{
}

void DeclareFunctionNodeCommand::toStream(std::ostream& out,
                                          int toDepth,
                                          size_t dag,
                                          Language language) const
{
  Printer::getPrinter(language)->toStreamCmdDeclareFunction(out, d_id, d_type);
}

NodeCommand* DeclareFunctionNodeCommand::clone() const
{
  return new DeclareFunctionNodeCommand(d_id, d_fun, d_type);
}

const Node& DeclareFunctionNodeCommand::getFunction() const { return d_fun; }

/* -------------------------------------------------------------------------- */
/* class DeclareTypeNodeCommand                                               */
/* -------------------------------------------------------------------------- */

DeclareTypeNodeCommand::DeclareTypeNodeCommand(const std::string& id,
                                               size_t arity,
                                               TypeNode type)
    : d_id(id), d_arity(arity), d_type(type)
{
}

void DeclareTypeNodeCommand::toStream(std::ostream& out,
                                      int toDepth,
                                      size_t dag,
                                      Language language) const
{
  Printer::getPrinter(language)->toStreamCmdDeclareType(out, d_type);
}

NodeCommand* DeclareTypeNodeCommand::clone() const
{
  return new DeclareTypeNodeCommand(d_id, d_arity, d_type);
}

const std::string DeclareTypeNodeCommand::getSymbol() const { return d_id; }

const TypeNode& DeclareTypeNodeCommand::getType() const { return d_type; }

/* -------------------------------------------------------------------------- */
/* class DeclareDatatypeNodeCommand                                           */
/* -------------------------------------------------------------------------- */

DeclareDatatypeNodeCommand::DeclareDatatypeNodeCommand(
    const std::vector<TypeNode>& datatypes)
    : d_datatypes(datatypes)
{
}

void DeclareDatatypeNodeCommand::toStream(std::ostream& out,
                                          int toDepth,
                                          size_t dag,
                                          Language language) const
{
  Printer::getPrinter(language)->toStreamCmdDatatypeDeclaration(out,
                                                                d_datatypes);
}

NodeCommand* DeclareDatatypeNodeCommand::clone() const
{
  return new DeclareDatatypeNodeCommand(d_datatypes);
}

/* -------------------------------------------------------------------------- */
/* class DefineFunctionNodeCommand                                            */
/* -------------------------------------------------------------------------- */

DefineFunctionNodeCommand::DefineFunctionNodeCommand(
    const std::string& id,
    Node fun,
    const std::vector<Node>& formals,
    Node formula)
    : d_id(id), d_fun(fun), d_formals(formals), d_formula(formula)
{
}

void DefineFunctionNodeCommand::toStream(std::ostream& out,
                                         int toDepth,
                                         size_t dag,
                                         Language language) const
{
  TypeNode tn = d_fun.getType();
  bool hasRange =
      (tn.isFunction() || tn.isConstructor() || tn.isSelector());
  Printer::getPrinter(language)->toStreamCmdDefineFunction(
      out,
      d_fun.toString(),
      d_formals,
      (hasRange ? d_fun.getType().getRangeType() : tn),
      d_formula);
}

NodeCommand* DefineFunctionNodeCommand::clone() const
{
  return new DefineFunctionNodeCommand(d_id, d_fun, d_formals, d_formula);
}

}  // namespace cvc5
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback