|
CIRCT 23.0.0git
|
#include <PrettyPrinter.h>

Classes | |
| struct | FormattedToken |
| Format token with tracked size. More... | |
| struct | Listener |
| Listener to Token storage events. More... | |
| struct | PrintEntry |
| Printing information for active scope, stored in printStack. More... | |
Public Member Functions | |
| PrettyPrinter (llvm::raw_ostream &os, uint32_t margin, uint32_t baseIndent=0, uint32_t currentColumn=0, uint32_t maxStartingIndent=kInfinity/4, Listener *listener=nullptr, bool noWrap=false) | |
| PrettyPrinter for specified stream. | |
| ~PrettyPrinter () | |
| void | add (Token t) |
| Add token for printing. In Oppen, this is "scan". | |
| template<typename R > | |
| void | addTokens (R &&tokens) |
| Add a range of tokens. | |
| void | eof () |
| void | setListener (Listener *newListener) |
| auto * | getListener () const |
Static Public Attributes | |
| static constexpr uint32_t | kInfinity = (1U << 15) - 1 |
Private Types | |
| enum class | PrintBreaks { Consistent , Inconsistent , AlwaysFits , Fits } |
| Breaking style for a printStack entry. More... | |
Private Member Functions | |
| void | advanceLeft () |
| Print out tokens we know sizes for, and drop from token buffer. | |
| void | checkStack () |
| Break encountered, set sizes of begin/breaks in scanStack we now know. | |
| void | checkStream () |
| Check if there's enough tokens to hit width, if so print. | |
| void | print (const FormattedToken &f) |
| Print a token, maintaining printStack for context. | |
| void | clear () |
| Clear token buffer, scanStack must be empty. | |
| void | rebaseIfNeeded () |
| Reset leftTotal and tokenOffset, rebase size data and scanStack indices. | |
| auto & | getPrintFrame () |
| Get current printing frame. | |
Private Attributes | |
| int32_t | space |
| Characters left on this line. | |
| int32_t | leftTotal |
| Sizes: printed, enqueued. | |
| int32_t | rightTotal |
| std::deque< FormattedToken > | tokens |
| Unprinted tokens, combination of 'token' and 'size' in Oppen. | |
| uint32_t | tokenOffset = 0 |
| index of first token, for resolving scanStack entries. | |
| std::deque< uint32_t > | scanStack |
| Stack of begin/break tokens, adjust by tokenOffset to index into tokens. | |
| SmallVector< PrintEntry > | printStack |
| Stack of printing contexts (indentation + breaking behavior). | |
| const PrintEntry | defaultFrame |
| Printing context when stack is empty. | |
| uint32_t | alwaysFits = 0 |
| Number of "AlwaysFits" on print stack. | |
| uint32_t | indent |
| Current indentation level. | |
| uint32_t | pendingIndentation |
| Whitespace to print before next, tracked to avoid trailing whitespace. | |
| const uint32_t | margin |
| Target line width. | |
| const uint32_t | maxStartingIndent |
| Maximum starting indentation level (default=kInfinity/4). | |
| llvm::raw_ostream & | os |
| Output stream. | |
| Listener * | listener = nullptr |
| Hook for Token storage events. | |
| bool | donotClear = false |
| Flag to identify a state when the clear cannot be called. | |
| const bool | noWrap |
| Disables line wrapping on non-newline whitespace. | |
Static Private Attributes | |
| static constexpr decltype(leftTotal) | rebaseThreshold |
| Threshold for walking scan state and "rebasing" totals/offsets. | |
Definition at line 175 of file PrettyPrinter.h.
|
strongprivate |
Breaking style for a printStack entry.
This is "Breaks" values with extra for "Fits". Breaks::Never is "AlwaysFits" here.
| Enumerator | |
|---|---|
| Consistent | |
| Inconsistent | |
| AlwaysFits | |
| Fits | |
Definition at line 243 of file PrettyPrinter.h.
|
inline |
PrettyPrinter for specified stream.
Definition at line 192 of file PrettyPrinter.h.
References assert(), kInfinity, margin, maxStartingIndent, and pendingIndentation.
|
inline |
Definition at line 207 of file PrettyPrinter.h.
References eof().
| void circt::pretty::PrettyPrinter::add | ( | Token | t | ) |
Add token for printing. In Oppen, this is "scan".
Definition at line 79 of file PrettyPrinter.cpp.
References assert(), checkStack(), checkStream(), clear(), circt::pretty::end, listener, print(), rebaseIfNeeded(), rightTotal, scanStack, circt::pretty::BreakToken::spaces(), tokenOffset, and tokens.
Referenced by addTokens().
|
inline |
Add a range of tokens.
Definition at line 214 of file PrettyPrinter.h.
References add(), clear(), donotClear, scanStack, and tokens.
Referenced by circt::pretty::BufferingPP::flush().
|
private |
Print out tokens we know sizes for, and drop from token buffer.
Definition at line 224 of file PrettyPrinter.cpp.
References assert(), leftTotal, print(), circt::pretty::BreakToken::spaces(), tokenOffset, and tokens.
Referenced by checkStream(), and eof().
|
private |
Break encountered, set sizes of begin/breaks in scanStack we now know.
Break encountered, set sizes of begin/breaks in scanStack that we now know.
Definition at line 179 of file PrettyPrinter.cpp.
References assert(), rightTotal, scanStack, tokenOffset, and tokens.
|
private |
Check if there's enough tokens to hit width, if so print.
Check if there are enough tokens to hit width, if so print.
If scan size is wider than line, it's infinity.
Definition at line 206 of file PrettyPrinter.cpp.
References advanceLeft(), assert(), kInfinity, leftTotal, rightTotal, scanStack, space, tokenOffset, and tokens.
Referenced by add().
|
private |
Clear token buffer, scanStack must be empty.
Definition at line 168 of file PrettyPrinter.cpp.
References assert(), circt::pretty::PrettyPrinter::Listener::clear(), donotClear, leftTotal, listener, rightTotal, scanStack, tokenOffset, and tokens.
Referenced by add(), addTokens(), and eof().
| void circt::pretty::PrettyPrinter::eof | ( | ) |
Definition at line 158 of file PrettyPrinter.cpp.
References advanceLeft(), assert(), checkStack(), clear(), and scanStack.
Referenced by circt::pretty::BufferingPP::flush(), and ~PrettyPrinter().
|
inline |
Definition at line 229 of file PrettyPrinter.h.
References listener.
|
inlineprivate |
Get current printing frame.
Definition at line 271 of file PrettyPrinter.h.
References defaultFrame, and printStack.
Referenced by print().
|
private |
Print a token, maintaining printStack for context.
Definition at line 249 of file PrettyPrinter.cpp.
References AlwaysFits, alwaysFits, assert(), circt::pretty::computeNewIndent(), circt::pretty::Consistent, Consistent, Fits, getPrintFrame(), Inconsistent, indent, kInfinity, listener, margin, maxStartingIndent, circt::pretty::Never, circt::pretty::BreakToken::neverbreak(), noWrap, circt::pretty::BreakToken::offset(), os, pendingIndentation, circt::pretty::PrettyPrinter::Listener::print(), printStack, circt::pretty::PrettyPrinter::FormattedToken::size, space, circt::pretty::BreakToken::spaces(), circt::pretty::PrettyPrinter::FormattedToken::token, and circt::pretty::Visual.
Referenced by add(), and advanceLeft().
|
private |
Reset leftTotal and tokenOffset, rebase size data and scanStack indices.
Definition at line 129 of file PrettyPrinter.cpp.
References assert(), leftTotal, rebaseThreshold, rightTotal, scanStack, tokenOffset, and tokens.
Referenced by add().
|
inline |
Definition at line 228 of file PrettyPrinter.h.
References listener.
|
private |
Number of "AlwaysFits" on print stack.
Definition at line 297 of file PrettyPrinter.h.
Referenced by print().
|
private |
Printing context when stack is empty.
Definition at line 294 of file PrettyPrinter.h.
Referenced by getPrintFrame().
|
private |
Flag to identify a state when the clear cannot be called.
Definition at line 320 of file PrettyPrinter.h.
Referenced by addTokens(), and clear().
|
private |
|
staticconstexpr |
Definition at line 231 of file PrettyPrinter.h.
Referenced by checkStream(), circt::pretty::TokenBuilder< PPTy >::newline(), PrettyPrinter(), and print().
|
private |
Sizes: printed, enqueued.
Definition at line 279 of file PrettyPrinter.h.
Referenced by advanceLeft(), checkStream(), clear(), and rebaseIfNeeded().
|
private |
Hook for Token storage events.
Definition at line 317 of file PrettyPrinter.h.
Referenced by add(), clear(), getListener(), print(), and setListener().
|
private |
Target line width.
Definition at line 306 of file PrettyPrinter.h.
Referenced by PrettyPrinter(), and print().
|
private |
Maximum starting indentation level (default=kInfinity/4).
Useful to continue indentation past margin while still providing a limit to avoid pathological output and for consumption by tools with limits.
Definition at line 311 of file PrettyPrinter.h.
Referenced by PrettyPrinter(), and print().
|
private |
Disables line wrapping on non-newline whitespace.
Definition at line 323 of file PrettyPrinter.h.
Referenced by print().
|
private |
|
private |
Whitespace to print before next, tracked to avoid trailing whitespace.
Definition at line 303 of file PrettyPrinter.h.
Referenced by PrettyPrinter(), and print().
|
private |
Stack of printing contexts (indentation + breaking behavior).
Definition at line 291 of file PrettyPrinter.h.
Referenced by getPrintFrame(), and print().
|
staticconstexprprivate |
Threshold for walking scan state and "rebasing" totals/offsets.
Definition at line 326 of file PrettyPrinter.h.
Referenced by rebaseIfNeeded().
|
private |
Definition at line 280 of file PrettyPrinter.h.
Referenced by add(), checkStack(), checkStream(), clear(), and rebaseIfNeeded().
|
private |
Stack of begin/break tokens, adjust by tokenOffset to index into tokens.
Definition at line 288 of file PrettyPrinter.h.
Referenced by add(), addTokens(), checkStack(), checkStream(), clear(), eof(), and rebaseIfNeeded().
|
private |
Characters left on this line.
Definition at line 276 of file PrettyPrinter.h.
Referenced by checkStream(), and print().
|
private |
index of first token, for resolving scanStack entries.
Definition at line 285 of file PrettyPrinter.h.
Referenced by add(), advanceLeft(), checkStack(), checkStream(), clear(), and rebaseIfNeeded().
|
private |
Unprinted tokens, combination of 'token' and 'size' in Oppen.
Definition at line 283 of file PrettyPrinter.h.
Referenced by add(), addTokens(), advanceLeft(), checkStack(), checkStream(), clear(), and rebaseIfNeeded().