1 |
|
/****************************************************************************** |
2 |
|
* Top contributors (to current version): |
3 |
|
* Morgan Deters, Aina Niemetz, Andrew Reynolds |
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 |
|
* A node value. |
14 |
|
* |
15 |
|
* The actual node implementation. |
16 |
|
* Instances of this class are generally referenced through cvc5::Node rather |
17 |
|
* than by pointer. Note that cvc5::Node maintains the reference count on |
18 |
|
* NodeValue instances. |
19 |
|
*/ |
20 |
|
#include "expr/node_value.h" |
21 |
|
|
22 |
|
#include <sstream> |
23 |
|
|
24 |
|
#include "expr/kind.h" |
25 |
|
#include "expr/metakind.h" |
26 |
|
#include "expr/node.h" |
27 |
|
#include "options/base_options.h" |
28 |
|
#include "options/language.h" |
29 |
|
#include "options/options.h" |
30 |
|
#include "printer/printer.h" |
31 |
|
|
32 |
|
using namespace std; |
33 |
|
|
34 |
|
namespace cvc5 { |
35 |
|
namespace expr { |
36 |
|
|
37 |
6236 |
string NodeValue::toString() const { |
38 |
12472 |
stringstream ss; |
39 |
|
|
40 |
|
Language outlang = |
41 |
6236 |
(this == &null()) ? Language::LANG_AUTO : options::outputLanguage(); |
42 |
6236 |
toStream(ss, -1, false, outlang); |
43 |
12472 |
return ss.str(); |
44 |
|
} |
45 |
|
|
46 |
86639 |
void NodeValue::toStream(std::ostream& out, |
47 |
|
int toDepth, |
48 |
|
size_t dag, |
49 |
|
Language language) const |
50 |
|
{ |
51 |
|
// Ensure that this node value is live for the length of this call. |
52 |
|
// It really breaks things badly if we don't have a nonzero ref |
53 |
|
// count, even just for printing. |
54 |
173278 |
RefCountGuard guard(this); |
55 |
|
|
56 |
86653 |
Printer::getPrinter(language)->toStream(out, TNode(this), toDepth, dag); |
57 |
86625 |
} |
58 |
|
|
59 |
|
void NodeValue::printAst(std::ostream& out, int ind) const { |
60 |
|
RefCountGuard guard(this); |
61 |
|
|
62 |
|
indent(out, ind); |
63 |
|
out << '('; |
64 |
|
out << getKind(); |
65 |
|
if (getMetaKind() == kind::metakind::VARIABLE || getMetaKind() == kind::metakind::NULLARY_OPERATOR ) { |
66 |
|
out << ' ' << getId(); |
67 |
|
} else if (getMetaKind() == kind::metakind::CONSTANT) { |
68 |
|
out << ' '; |
69 |
|
kind::metakind::NodeValueConstPrinter::toStream(out, this); |
70 |
|
} else { |
71 |
|
if (nv_begin() != nv_end()) { |
72 |
|
for (const_nv_iterator child = nv_begin(); child != nv_end(); ++child) { |
73 |
|
out << std::endl; |
74 |
|
(*child)->printAst(out, ind + 1); |
75 |
|
} |
76 |
|
out << std::endl; |
77 |
|
indent(out, ind); |
78 |
|
} |
79 |
|
} |
80 |
|
out << ')'; |
81 |
|
} |
82 |
|
|
83 |
|
NodeValue::iterator<NodeTemplate<true> > operator+( |
84 |
|
NodeValue::iterator<NodeTemplate<true> >::difference_type p, |
85 |
|
NodeValue::iterator<NodeTemplate<true> > i) |
86 |
|
{ |
87 |
|
return i + p; |
88 |
|
} |
89 |
|
|
90 |
|
NodeValue::iterator<NodeTemplate<false> > operator+( |
91 |
|
NodeValue::iterator<NodeTemplate<false> >::difference_type p, |
92 |
|
NodeValue::iterator<NodeTemplate<false> > i) |
93 |
|
{ |
94 |
|
return i + p; |
95 |
|
} |
96 |
|
|
97 |
|
} // namespace expr |
98 |
29505 |
} // namespace cvc5 |