GCC Code Coverage Report
Directory: . Exec Total Coverage
File: src/expr/expr_iomanip.cpp Lines: 44 54 81.5 %
Date: 2021-03-22 Branches: 13 24 54.2 %

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