1 |
|
/****************************************************************************** |
2 |
|
* Top contributors (to current version): |
3 |
|
* Morgan Deters, Tim King, Kshitij Bansal |
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 |
|
* Expr IO manipulation classes. |
14 |
|
*/ |
15 |
|
|
16 |
|
#include "expr/expr_iomanip.h" |
17 |
|
|
18 |
|
#include <iomanip> |
19 |
|
#include <iostream> |
20 |
|
|
21 |
|
#include "options/options.h" |
22 |
|
#include "options/expr_options.h" |
23 |
|
|
24 |
|
namespace cvc5 { |
25 |
|
namespace expr { |
26 |
|
|
27 |
9780 |
const int ExprSetDepth::s_iosIndex = std::ios_base::xalloc(); |
28 |
9780 |
const int ExprDag::s_iosIndex = std::ios_base::xalloc(); |
29 |
|
|
30 |
30 |
ExprSetDepth::ExprSetDepth(long depth) : d_depth(depth) {} |
31 |
|
|
32 |
30 |
void ExprSetDepth::applyDepth(std::ostream& out) { |
33 |
30 |
out.iword(s_iosIndex) = d_depth; |
34 |
30 |
} |
35 |
|
|
36 |
52862 |
long ExprSetDepth::getDepth(std::ostream& out) { |
37 |
52862 |
long& l = out.iword(s_iosIndex); |
38 |
52862 |
if(l == 0) { |
39 |
|
// set the default print depth on this ostream |
40 |
52780 |
if(not Options::isCurrentNull()) { |
41 |
52780 |
l = options::defaultExprDepth(); |
42 |
|
} |
43 |
52780 |
if(l == 0) { |
44 |
|
// if called from outside the library, we may not have options |
45 |
|
// available to us at this point (or perhaps the output language |
46 |
|
// is not set in Options). Default to something reasonable, but |
47 |
|
// don't set "l" since that would make it "sticky" for this |
48 |
|
// stream. |
49 |
52780 |
return s_defaultPrintDepth; |
50 |
|
} |
51 |
|
} |
52 |
82 |
return l; |
53 |
|
} |
54 |
|
|
55 |
|
void ExprSetDepth::setDepth(std::ostream& out, long depth) { |
56 |
|
out.iword(s_iosIndex) = depth; |
57 |
|
} |
58 |
|
|
59 |
|
|
60 |
|
ExprSetDepth::Scope::Scope(std::ostream& out, long depth) |
61 |
|
: d_out(out), d_oldDepth(ExprSetDepth::getDepth(out)) |
62 |
|
{ |
63 |
|
ExprSetDepth::setDepth(out, depth); |
64 |
|
} |
65 |
|
|
66 |
|
ExprSetDepth::Scope::~Scope() { |
67 |
|
ExprSetDepth::setDepth(d_out, d_oldDepth); |
68 |
|
} |
69 |
|
|
70 |
4 |
ExprDag::ExprDag(bool dag) : d_dag(dag ? 1 : 0) {} |
71 |
|
|
72 |
10 |
ExprDag::ExprDag(int dag) : d_dag(dag < 0 ? 0 : dag) {} |
73 |
|
|
74 |
14 |
void ExprDag::applyDag(std::ostream& out) { |
75 |
|
// (offset by one to detect whether default has been set yet) |
76 |
14 |
out.iword(s_iosIndex) = static_cast<long>(d_dag) + 1; |
77 |
14 |
} |
78 |
|
|
79 |
52979 |
size_t ExprDag::getDag(std::ostream& out) { |
80 |
52979 |
long& l = out.iword(s_iosIndex); |
81 |
52979 |
if(l == 0) { |
82 |
|
// set the default dag setting on this ostream |
83 |
|
// (offset by one to detect whether default has been set yet) |
84 |
10182 |
if(not Options::isCurrentNull()) { |
85 |
10122 |
l = options::defaultDagThresh() + 1; |
86 |
|
} |
87 |
10182 |
if(l == 0) { |
88 |
|
// if called from outside the library, we may not have options |
89 |
|
// available to us at this point (or perhaps the output language |
90 |
|
// is not set in Options). Default to something reasonable, but |
91 |
|
// don't set "l" since that would make it "sticky" for this |
92 |
|
// stream. |
93 |
60 |
return s_defaultDag + 1; |
94 |
|
} |
95 |
|
} |
96 |
52919 |
return static_cast<size_t>(l - 1); |
97 |
|
} |
98 |
|
|
99 |
234 |
void ExprDag::setDag(std::ostream& out, size_t dag) { |
100 |
|
// (offset by one to detect whether default has been set yet) |
101 |
234 |
out.iword(s_iosIndex) = static_cast<long>(dag) + 1; |
102 |
234 |
} |
103 |
|
|
104 |
117 |
ExprDag::Scope::Scope(std::ostream& out, size_t dag) |
105 |
|
: d_out(out), |
106 |
117 |
d_oldDag(ExprDag::getDag(out)) { |
107 |
117 |
ExprDag::setDag(out, dag); |
108 |
117 |
} |
109 |
|
|
110 |
234 |
ExprDag::Scope::~Scope() { |
111 |
117 |
ExprDag::setDag(d_out, d_oldDag); |
112 |
117 |
} |
113 |
|
|
114 |
14 |
std::ostream& operator<<(std::ostream& out, ExprDag d) { |
115 |
14 |
d.applyDag(out); |
116 |
14 |
return out; |
117 |
|
} |
118 |
|
|
119 |
30 |
std::ostream& operator<<(std::ostream& out, ExprSetDepth sd) { |
120 |
30 |
sd.applyDepth(out); |
121 |
30 |
return out; |
122 |
|
} |
123 |
|
|
124 |
|
} // namespace expr |
125 |
29340 |
} // namespace cvc5 |