#include <expr_stream.h>
Collaboration diagram for CVCL::ExprStream:
Use this class as a standard ostream for Expr, string, int, Rational, manipulators like endl, and it will do the expected thing. Additionally, it has methods to access the current printing flags.
In order for the indentation engine to work correctly, you must use the manipulators properly.
Never use "\\n" in a string; always use endl manipulator, which knows about indentation and will do the right thing.
Always assume that the object you are printing may start printing on a new line from the current indentation position. Therefore, no string should start with an empty space (otherwise parts of your expression will be mis-indented). If you need a white space separator, or an operator surrounded by spaces, like os << " = ", use os << space << "= " instead. The 'space' manipulator adds one white space only if it's not at the beginning of a newly indented line. Think of it as a logical white-space separator with intelligent behavior, rather than a stupid hard space like " ".
Indentation can be set to the current position with os << push, and restored to the previous with os << pop. You do not need to restore it before exiting your print function, ExprStream knows how to restore it automatically. For example, you can write:
os << "(" << push << e[0] << space << "+ " << e[1] << push << ")";
to print (PLUS a b) as "(a + b)". Notice the second 'push' before the closing paren. This is intentional (not a typo), and prevents the paren ")" from jumping to the next line by itself. ExprStream will not go to the next line if the current position is too close to the indentation, since this will not give the expression a better look.
The indentation level is not restored in this example, and that is fine, ExprStream will take care of that.
For complex expressions like IF-THEN-ELSE, you may want to remember the indentation to which you want to return later. You can save the current indentation position with os << popSave, and restore it later with os << pushRestore. These manipulators are similar to pop and push, but 'pushRestore' will set the new indentation level to the one popped by the last popSave instead of the current one. At the moment, there is only one register for saving an indentation position, so multiple pushRestore will not work as you would expect (maybe this should be fixed?..).
For concrete examples, see TheoryCore::print() and TheoryArith::print().
Definition at line 117 of file expr_stream.h.
|
Default constructor.
Definition at line 39 of file expr_stream.cpp. References d_dagPtr, d_em, d_indentLast, d_indentStack, d_lastDagSize, and CVCL::ExprManager::indent(). |
|
Destructor.
Definition at line 169 of file expr_stream.h. |
|
Generating unique names in DAG expr.
Definition at line 53 of file expr_stream.cpp. References d_idCounter. Referenced by collectShared(). |
|
Traverse the Expr, collect shared subexpressions in d_dagMap.
Definition at line 79 of file expr_stream.cpp. References CVCL::Expr::begin(), CVCL::ExprMap< Data >::count(), d_dagBuilt, d_dagMap, d_dagStack, d_lang, d_newDagMap, CVCL::Expr::end(), CVCL::Type::isBool(), CVCL::isTrivialExpr(), newName(), and CVCL::SMTLIB_LANG. Referenced by CVCL::operator<<(). |
|
Wrap e into the top-level LET ... IN header from the dagMap. We rely on the fact that d_dagMap is ordered by the Expr creation order, so earlier expressions cannot depend on later ones. Definition at line 110 of file expr_stream.cpp. References CVCL::ExprMap< Data >::begin(), CVCL::ExprMap< Data >::clear(), d_newDagMap, CVCL::ExprMap< Data >::end(), CVCL::Expr::getEM(), CVCL::LET, CVCL::LETDECL, CVCL::LETDECLS, CVCL::ExprManager::newLeafExpr(), CVCL::ExprManager::newVarExpr(), CVCL::ExprMap< Data >::size(), and CVCL::TYPE. Referenced by CVCL::operator<<(). |
|
Set a new output stream. Note, that there is no method to access the ostream. This is done on purpose, so that DP designers had to use only ExprStream to print everything in their versions of Theory::print(). Definition at line 174 of file expr_stream.h. References d_os. Referenced by CVCL::operator<<(), and CVCL::Expr::toString(). |
|
Get the current output language.
Definition at line 176 of file expr_stream.h. References d_lang. Referenced by CVCL::TheoryUF::print(), CVCL::TheorySimulate::print(), CVCL::TheoryRecords::print(), CVCL::TheoryQuant::print(), CVCL::TheoryDatatype::print(), TheoryCore::print(), CVCL::TheoryBitvector::print(), CVCL::TheoryArray::print(), CVCL::TheoryArith::print(), CVCL::Expr::print(), and CVCL::Expr::toString(). |
|
Set the output language.
Definition at line 178 of file expr_stream.h. References d_lang. |
|
Get the printing depth.
Definition at line 180 of file expr_stream.h. References d_depth. |
|
Set the printing depth.
Definition at line 182 of file expr_stream.h. References d_depth. |
|
Set the line width.
Definition at line 184 of file expr_stream.h. References d_lineWidth. |
|
Set the DAG flag.
Definition at line 186 of file expr_stream.h. References d_dag. Referenced by CVCL::Expr::pprintnodag(), and CVCL::Expr::print(). |
|
Set the indentation to the current column. The value will be restorted automatically after the DP print() function returns Definition at line 190 of file expr_stream.h. References d_col, and d_indentStack. Referenced by CVCL::push(), and CVCL::pushRestore(). |
|
Set the indentation to the given absolute position. The value will be restorted automatically after the DP print() function returns Definition at line 194 of file expr_stream.h. References d_indentStack. |
|
Restore the indentation (user cannot pop more than pushed).
Definition at line 127 of file expr_stream.cpp. References d_indentLast, d_indentStack, and CVCL::int2string(). Referenced by CVCL::pop(), and CVCL::popSave(). |
|
Reset indentation to what it was at this level.
Definition at line 138 of file expr_stream.cpp. References d_indentLast, and d_indentStack. Referenced by CVCL::operator<<(), CVCL::Expr::print(), CVCL::Expr::printAST(), and CVCL::reset(). |
|
Return the current column position.
Definition at line 200 of file expr_stream.h. References d_col. |
|
Recompute shared subexpression for the next Expr.
Definition at line 144 of file expr_stream.cpp. References d_dagBuilt, d_dagPtr, and d_dagStack. Referenced by CVCL::pushdag(). |
|
Delete shared subexpressions previously added with pushdag.
Definition at line 149 of file expr_stream.cpp. References CVCL::ExprMap< Data >::clear(), d_dagMap, d_dagPtr, d_dagStack, d_lastDagSize, d_newDagMap, and CVCL::ExprMap< Data >::erase(). Referenced by CVCL::popdag(), and resetDag(). |
|
Reset the DAG to what it was at this level.
Definition at line 164 of file expr_stream.cpp. References d_dagPtr, d_lastDagSize, and popDag(). Referenced by CVCL::operator<<(). |
|
Get parent of current expr being printed.
Definition at line 208 of file expr_stream.h. References d_parent. Referenced by CVCL::TheoryArith::print(). |
|
Use manipulators which are functions over ExprStream&.
Definition at line 173 of file expr_stream.cpp. |
|
Print Expr.
Definition at line 179 of file expr_stream.cpp. |
|
Print Type.
Definition at line 247 of file expr_stream.cpp. |
|
Print string.
|
|
Print char* string.
Definition at line 294 of file expr_stream.cpp. |
|
Print Rational.
Definition at line 299 of file expr_stream.cpp. |
|
Print int.
Definition at line 306 of file expr_stream.cpp. |
|
Set the indentation to the current position.
Definition at line 319 of file expr_stream.cpp. |
|
Restore the indentation to the previous position.
Definition at line 322 of file expr_stream.cpp. |
|
Remember the current indentation and pop to the previous position. There is only one register to save the previous position. If you use popSave() more than once, only the latest position can be restored with pushRestore(). Definition at line 327 of file expr_stream.cpp. |
|
Set the indentation to the position saved by popSave(). There is only one register to save the previous position. Using pushRestore() several times will set intendation to the same position. Definition at line 336 of file expr_stream.cpp. |
|
Reset the indentation to the default at this level.
Definition at line 341 of file expr_stream.cpp. |
|
Insert a single white space separator. It is preferred to use 'space' rather than a string of spaces (" ") because ExprStream needs to delete extra white space if it decides to end the line. If you use strings for spaces, you'll mess up the indentation. Definition at line 347 of file expr_stream.cpp. |
|
Print the next top-level expression node without DAG-ifying. DAG-printing will resume for the children of the node. This is useful when printing definitions in the header of a DAGified LET expressions: defs have names, but must be printed expanded. Definition at line 353 of file expr_stream.cpp. |
|
Recompute shared subexpression for the next Expr. For some constructs with bound variables (notably, quantifiers), shared subexpressions are not computed, because they cannot be defined outside the scope of bound variables. If this manipulator is applied before an expression within the scope of bound vars, these internal subexpressions will then be computed. Definition at line 358 of file expr_stream.cpp. |
|
Delete shared subexpressions previously added with pushdag. Similar to push/pop, shared subexpressions are automatically deleted upon a return from a recursive call, so popdag is not necessary after a pushdag in theory-specific print() functions. Also, you cannot pop more than you pushed an the current recursion level. Definition at line 360 of file expr_stream.cpp. |
|
Print the end-of-line. The new line will not necessarily start at column 0 because of indentation. Definition at line 374 of file expr_stream.cpp. |
|
The ExprManager to use.
Definition at line 119 of file expr_stream.h. Referenced by ExprStream(), and CVCL::operator<<(). |
|
The ostream to print into.
Definition at line 120 of file expr_stream.h. Referenced by std::endl(), CVCL::operator<<(), and os(). |
|
Printing only upto this depth; -1 == unlimited.
Definition at line 121 of file expr_stream.h. Referenced by depth(), and CVCL::operator<<(). |
|
Current depth of Expr.
Definition at line 122 of file expr_stream.h. Referenced by CVCL::operator<<(). |
|
Output language.
Definition at line 123 of file expr_stream.h. Referenced by collectShared(), lang(), and CVCL::operator<<(). |
|
Whether to print with indentations.
Definition at line 124 of file expr_stream.h. Referenced by std::endl(), and CVCL::operator<<(). |
|
Current column in a line.
Definition at line 125 of file expr_stream.h. Referenced by column(), std::endl(), CVCL::operator<<(), and pushIndent(). |
|
Try to format/indent for this line width Definition at line 126 of file expr_stream.h. Referenced by lineWidth(), and CVCL::operator<<(). |
|
Indentation stack. The user code can set the indentation to the current d_col by pushing the new value on the stack. This value is popped automatically when returning from the recursive call. Definition at line 131 of file expr_stream.h. Referenced by std::endl(), ExprStream(), CVCL::operator<<(), popIndent(), CVCL::popSave(), pushIndent(), and resetIndent(). |
|
The lowest position of the indent stack the user can pop.
Definition at line 133 of file expr_stream.h. Referenced by ExprStream(), CVCL::operator<<(), popIndent(), and resetIndent(). |
|
Indentation register for popSave() and pushRestore().
Definition at line 135 of file expr_stream.h. Referenced by CVCL::operator<<(), CVCL::popSave(), and CVCL::pushRestore(). |
|
Whether it is a beginning of line (for eating up extra spaces).
Definition at line 137 of file expr_stream.h. Referenced by std::endl(), CVCL::operator<<(), and CVCL::space(). |
|
Print Expr as a DAG Definition at line 138 of file expr_stream.h. Referenced by dagFlag(), and CVCL::operator<<(). |
|
Mapping subexpressions to names for DAG printing.
Definition at line 140 of file expr_stream.h. Referenced by collectShared(), CVCL::operator<<(), and popDag(). |
|
New subexpressions not yet printed in a LET header.
Definition at line 142 of file expr_stream.h. Referenced by addLetHeader(), collectShared(), and popDag(). |
|
Stack of shared subexpressions (same as in d_dagMap).
Definition at line 144 of file expr_stream.h. Referenced by collectShared(), popDag(), and pushDag(). |
|
Stack of pointers to d_dagStack for pushing/popping shared subexprs.
Definition at line 146 of file expr_stream.h. Referenced by ExprStream(), CVCL::operator<<(), popDag(), pushDag(), and resetDag(). |
|
The smallest size of d_dagPtr the user can `popDag'.
Definition at line 148 of file expr_stream.h. Referenced by ExprStream(), CVCL::operator<<(), popDag(), and resetDag(). |
|
Flag whether the dagMap is already built.
Definition at line 150 of file expr_stream.h. Referenced by collectShared(), CVCL::operator<<(), and pushDag(). |
|
Counter for generating unique LET var names.
Definition at line 152 of file expr_stream.h. Referenced by newName(). |
|
nodag() manipulator has been applied
Definition at line 154 of file expr_stream.h. Referenced by CVCL::nodag(), and CVCL::operator<<(). |
|
Parent of current expr being printed.
Definition at line 156 of file expr_stream.h. Referenced by getParent(), and CVCL::operator<<(). |
|
Current expr being printed.
Definition at line 158 of file expr_stream.h. Referenced by CVCL::operator<<(). |