GCC Code Coverage Report
Directory: . Exec Total Coverage
File: src/expr/expr_iomanip.cpp Lines: 44 54 81.5 %
Date: 2021-09-18 Branches: 13 18 72.2 %

Line Exec Source
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
9858
const int ExprSetDepth::s_iosIndex = std::ios_base::xalloc();
28
9858
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
58267
long ExprSetDepth::getDepth(std::ostream& out) {
37
58267
  long& l = out.iword(s_iosIndex);
38
58267
  if(l == 0) {
39
    // set the default print depth on this ostream
40
58185
    if(not Options::isCurrentNull()) {
41
58185
      l = options::defaultExprDepth();
42
    }
43
58185
    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
58185
      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
58388
size_t ExprDag::getDag(std::ostream& out) {
80
58388
  long& l = out.iword(s_iosIndex);
81
58388
  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
11016
    if(not Options::isCurrentNull()) {
85
10956
      l = options::defaultDagThresh() + 1;
86
    }
87
11016
    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
58328
  return static_cast<size_t>(l - 1);
97
}
98
99
242
void ExprDag::setDag(std::ostream& out, size_t dag) {
100
  // (offset by one to detect whether default has been set yet)
101
242
  out.iword(s_iosIndex) = static_cast<long>(dag) + 1;
102
242
}
103
104
121
ExprDag::Scope::Scope(std::ostream& out, size_t dag)
105
  : d_out(out),
106
121
    d_oldDag(ExprDag::getDag(out)) {
107
121
  ExprDag::setDag(out, dag);
108
121
}
109
110
242
ExprDag::Scope::~Scope() {
111
121
  ExprDag::setDag(d_out, d_oldDag);
112
121
}
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
29574
}  // namespace cvc5