GCC Code Coverage Report
Directory: . Exec Total Coverage
File: src/expr/expr_iomanip.cpp Lines: 44 54 81.5 %
Date: 2021-05-22 Branches: 13 24 54.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
9398
const int ExprSetDepth::s_iosIndex = std::ios_base::xalloc();
28
9398
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
54018
long ExprSetDepth::getDepth(std::ostream& out) {
37
54018
  long& l = out.iword(s_iosIndex);
38
54018
  if(l == 0) {
39
    // set the default print depth on this ostream
40
53936
    if(not Options::isCurrentNull()) {
41
53936
      l = options::defaultExprDepth();
42
    }
43
53936
    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
53936
      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
90
ExprDag::ExprDag(int dag) : d_dag(dag < 0 ? 0 : dag) {}
73
74
94
void ExprDag::applyDag(std::ostream& out) {
75
  // (offset by one to detect whether default has been set yet)
76
94
  out.iword(s_iosIndex) = static_cast<long>(d_dag) + 1;
77
94
}
78
79
54132
size_t ExprDag::getDag(std::ostream& out) {
80
54132
  long& l = out.iword(s_iosIndex);
81
54132
  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
11341
    if(not Options::isCurrentNull()) {
85
11281
      l = options::defaultDagThresh() + 1;
86
    }
87
11341
    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
54072
  return static_cast<size_t>(l - 1);
97
}
98
99
228
void ExprDag::setDag(std::ostream& out, size_t dag) {
100
  // (offset by one to detect whether default has been set yet)
101
228
  out.iword(s_iosIndex) = static_cast<long>(dag) + 1;
102
228
}
103
104
114
ExprDag::Scope::Scope(std::ostream& out, size_t dag)
105
  : d_out(out),
106
114
    d_oldDag(ExprDag::getDag(out)) {
107
114
  ExprDag::setDag(out, dag);
108
114
}
109
110
228
ExprDag::Scope::~Scope() {
111
114
  ExprDag::setDag(d_out, d_oldDag);
112
114
}
113
114
94
std::ostream& operator<<(std::ostream& out, ExprDag d) {
115
94
  d.applyDag(out);
116
94
  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
28194
}  // namespace cvc5