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
|
/********************* */
/*! \file expr_iomanip.cpp
** \verbatim
** Top contributors (to current version):
** Morgan Deters, Tim King, Kshitij Bansal
** This file is part of the CVC4 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.\endverbatim
**
** \brief Expr IO manipulation classes.
**
** Expr IO manipulation classes.
**/
#include "expr/expr_iomanip.h"
#include <iomanip>
#include <iostream>
#include "options/options.h"
#include "options/expr_options.h"
namespace CVC4 {
namespace expr {
const int ExprSetDepth::s_iosIndex = std::ios_base::xalloc();
const int ExprDag::s_iosIndex = std::ios_base::xalloc();
ExprSetDepth::ExprSetDepth(long depth) : d_depth(depth) {}
void ExprSetDepth::applyDepth(std::ostream& out) {
out.iword(s_iosIndex) = d_depth;
}
long ExprSetDepth::getDepth(std::ostream& out) {
long& l = out.iword(s_iosIndex);
if(l == 0) {
// set the default print depth on this ostream
if(not Options::isCurrentNull()) {
l = options::defaultExprDepth();
}
if(l == 0) {
// if called from outside the library, we may not have options
// available to us at this point (or perhaps the output language
// is not set in Options). Default to something reasonable, but
// don't set "l" since that would make it "sticky" for this
// stream.
return s_defaultPrintDepth;
}
}
return l;
}
void ExprSetDepth::setDepth(std::ostream& out, long depth) {
out.iword(s_iosIndex) = depth;
}
ExprSetDepth::Scope::Scope(std::ostream& out, long depth)
: d_out(out), d_oldDepth(ExprSetDepth::getDepth(out))
{
ExprSetDepth::setDepth(out, depth);
}
ExprSetDepth::Scope::~Scope() {
ExprSetDepth::setDepth(d_out, d_oldDepth);
}
ExprDag::ExprDag(bool dag) : d_dag(dag ? 1 : 0) {}
ExprDag::ExprDag(int dag) : d_dag(dag < 0 ? 0 : dag) {}
void ExprDag::applyDag(std::ostream& out) {
// (offset by one to detect whether default has been set yet)
out.iword(s_iosIndex) = static_cast<long>(d_dag) + 1;
}
size_t ExprDag::getDag(std::ostream& out) {
long& l = out.iword(s_iosIndex);
if(l == 0) {
// set the default dag setting on this ostream
// (offset by one to detect whether default has been set yet)
if(not Options::isCurrentNull()) {
l = options::defaultDagThresh() + 1;
}
if(l == 0) {
// if called from outside the library, we may not have options
// available to us at this point (or perhaps the output language
// is not set in Options). Default to something reasonable, but
// don't set "l" since that would make it "sticky" for this
// stream.
return s_defaultDag + 1;
}
}
return static_cast<size_t>(l - 1);
}
void ExprDag::setDag(std::ostream& out, size_t dag) {
// (offset by one to detect whether default has been set yet)
out.iword(s_iosIndex) = static_cast<long>(dag) + 1;
}
ExprDag::Scope::Scope(std::ostream& out, size_t dag)
: d_out(out),
d_oldDag(ExprDag::getDag(out)) {
ExprDag::setDag(out, dag);
}
ExprDag::Scope::~Scope() {
ExprDag::setDag(d_out, d_oldDag);
}
std::ostream& operator<<(std::ostream& out, ExprDag d) {
d.applyDag(out);
return out;
}
std::ostream& operator<<(std::ostream& out, ExprSetDepth sd) {
sd.applyDepth(out);
return out;
}
}/* namespace CVC4::expr */
}/* namespace CVC4 */
|