c40840cd4b0dc337c5199b37db18a7f5600ace2f
1 /********************* */
2 /*! \file expr_iomanip.h
4 ** Top contributors (to current version):
5 ** Morgan Deters, Tim King, Mathias Preiner
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
12 ** \brief Expr IO manipulation classes.
14 ** Expr IO manipulation classes.
17 #include "cvc4_public.h"
19 #ifndef CVC4__EXPR__EXPR_IOMANIP_H
20 #define CVC4__EXPR__EXPR_IOMANIP_H
28 * IOStream manipulator to set the maximum depth of Exprs when
29 * pretty-printing. -1 means print to any depth. E.g.:
31 * // let a, b, c, and d be VARIABLEs
32 * Expr e = em->mkExpr(OR, a, b, em->mkExpr(AND, c, em->mkExpr(NOT, d)))
33 * out << setdepth(3) << e;
35 * gives "(OR a b (AND c (NOT d)))", but
37 * out << setdepth(1) << [same expr as above]
39 * gives "(OR a b (...))".
41 * The implementation of this class serves two purposes; it holds
42 * information about the depth setting (such as the index of the
43 * allocated word in ios_base), and serves also as the manipulator
50 * Construct a ExprSetDepth with the given depth.
52 ExprSetDepth(long depth
);
54 void applyDepth(std::ostream
& out
);
56 static long getDepth(std::ostream
& out
);
58 static void setDepth(std::ostream
& out
, long depth
);
61 * Set the expression depth on the output stream for the current
62 * stack scope. This makes sure the old depth is reset on the stream
63 * after normal OR exceptional exit from the scope, using the RAII
68 Scope(std::ostream
& out
, long depth
);
74 };/* class ExprSetDepth::Scope */
78 * The allocated index in ios_base for our depth setting.
80 static const int s_iosIndex
;
83 * The default depth to print, for ostreams that haven't yet had a
84 * setdepth() applied to them.
86 static const int s_defaultPrintDepth
= -1;
89 * When this manipulator is used, the depth is stored here.
92 }; /* class ExprSetDepth */
95 * IOStream manipulator to print expressions as a dag (or not).
101 * Construct a ExprDag with the given setting (dagification on or off).
103 explicit ExprDag(bool dag
);
106 * Construct a ExprDag with the given setting (letify only common
107 * subexpressions that appear more than 'dag' times). dag <= 0 means
110 explicit ExprDag(int dag
);
112 void applyDag(std::ostream
& out
);
114 static size_t getDag(std::ostream
& out
);
116 static void setDag(std::ostream
& out
, size_t dag
);
119 * Set the dag state on the output stream for the current
120 * stack scope. This makes sure the old state is reset on the
121 * stream after normal OR exceptional exit from the scope, using the
126 Scope(std::ostream
& out
, size_t dag
);
132 };/* class ExprDag::Scope */
136 * The allocated index in ios_base for our setting.
138 static const int s_iosIndex
;
141 * The default setting, for ostreams that haven't yet had a
142 * dag() applied to them.
144 static const size_t s_defaultDag
= 1;
147 * When this manipulator is used, the setting is stored here.
150 }; /* class ExprDag */
153 * Sets the default dag setting when pretty-printing a Expr to an ostream.
156 * // let out be an ostream, e an Expr
157 * out << Expr::dag(true) << e << endl;
159 * The setting stays permanently (until set again) with the stream.
161 std::ostream
& operator<<(std::ostream
& out
, ExprDag d
);
164 * Sets the default depth when pretty-printing a Expr to an ostream.
167 * // let out be an ostream, e an Expr
168 * out << Expr::setdepth(n) << e << endl;
170 * The depth stays permanently (until set again) with the stream.
172 std::ostream
& operator<<(std::ostream
& out
, ExprSetDepth sd
);
178 #endif /* CVC4__EXPR__EXPR_IOMANIP_H */