CIRCT
20.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) | |
PrettyPrinter for specified stream. More... | |
~PrettyPrinter () | |
void | add (Token t) |
Add token for printing. In Oppen, this is "scan". More... | |
template<typename R > | |
void | addTokens (R &&tokens) |
Add a range of tokens. More... | |
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. More... | |
void | checkStack () |
Break encountered, set sizes of begin/breaks in scanStack we now know. More... | |
void | checkStream () |
Check if there's enough tokens to hit width, if so print. More... | |
void | print (const FormattedToken &f) |
Print a token, maintaining printStack for context. More... | |
void | clear () |
Clear token buffer, scanStack must be empty. More... | |
void | rebaseIfNeeded () |
Reset leftTotal and tokenOffset, rebase size data and scanStack indices. More... | |
auto & | getPrintFrame () |
Get current printing frame. More... | |
Private Attributes | |
int32_t | space |
Characters left on this line. More... | |
int32_t | leftTotal |
Sizes: printed, enqueued. More... | |
int32_t | rightTotal |
std::deque< FormattedToken > | tokens |
Unprinted tokens, combination of 'token' and 'size' in Oppen. More... | |
uint32_t | tokenOffset = 0 |
index of first token, for resolving scanStack entries. More... | |
std::deque< uint32_t > | scanStack |
Stack of begin/break tokens, adjust by tokenOffset to index into tokens. More... | |
SmallVector< PrintEntry > | printStack |
Stack of printing contexts (indentation + breaking behavior). More... | |
const PrintEntry | defaultFrame |
Printing context when stack is empty. More... | |
uint32_t | alwaysFits = 0 |
Number of "AlwaysFits" on print stack. More... | |
uint32_t | indent |
Current indentation level. More... | |
uint32_t | pendingIndentation |
Whitespace to print before next, tracked to avoid trailing whitespace. More... | |
const uint32_t | margin |
Target line width. More... | |
const uint32_t | maxStartingIndent |
Maximum starting indentation level (default=kInfinity/4). More... | |
llvm::raw_ostream & | os |
Output stream. More... | |
Listener * | listener = nullptr |
Hook for Token storage events. More... | |
bool | donotClear = false |
Flag to identify a state when the clear cannot be called. More... | |
Static Private Attributes | |
static constexpr decltype(leftTotal) | rebaseThreshold |
Threshold for walking scan state and "rebasing" totals/offsets. More... | |
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 242 of file PrettyPrinter.h.
|
inline |
PrettyPrinter for specified stream.
Definition at line 191 of file PrettyPrinter.h.
References assert(), circt::pretty::Inconsistent, kInfinity, margin, maxStartingIndent, and pendingIndentation.
|
inline |
Definition at line 206 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(), circt::pretty::StringToken::text(), tokenOffset, and tokens.
Referenced by addTokens().
|
inline |
Add a range of tokens.
Definition at line 213 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(), circt::pretty::StringToken::text(), 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 228 of file PrettyPrinter.h.
References listener.
|
inlineprivate |
Get current printing frame.
Definition at line 270 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(), circt::pretty::BreakToken::offset(), os, pendingIndentation, circt::pretty::PrettyPrinter::Listener::print(), printStack, circt::pretty::PrettyPrinter::FormattedToken::size, space, circt::pretty::BreakToken::spaces(), circt::pretty::StringToken::text(), 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 227 of file PrettyPrinter.h.
References listener.
|
private |
Number of "AlwaysFits" on print stack.
Definition at line 296 of file PrettyPrinter.h.
Referenced by print().
|
private |
Printing context when stack is empty.
Definition at line 293 of file PrettyPrinter.h.
Referenced by getPrintFrame().
|
private |
Flag to identify a state when the clear cannot be called.
Definition at line 319 of file PrettyPrinter.h.
Referenced by addTokens(), and clear().
|
private |
|
staticconstexpr |
Definition at line 230 of file PrettyPrinter.h.
Referenced by checkStream(), circt::pretty::TokenBuilder< PPTy >::newline(), PrettyPrinter(), and print().
|
private |
Sizes: printed, enqueued.
Definition at line 278 of file PrettyPrinter.h.
Referenced by advanceLeft(), checkStream(), clear(), and rebaseIfNeeded().
|
private |
Hook for Token storage events.
Definition at line 316 of file PrettyPrinter.h.
Referenced by add(), clear(), getListener(), print(), and setListener().
|
private |
Target line width.
Definition at line 305 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 310 of file PrettyPrinter.h.
Referenced by PrettyPrinter(), and print().
|
private |
|
private |
Whitespace to print before next, tracked to avoid trailing whitespace.
Definition at line 302 of file PrettyPrinter.h.
Referenced by PrettyPrinter(), and print().
|
private |
Stack of printing contexts (indentation + breaking behavior).
Definition at line 290 of file PrettyPrinter.h.
Referenced by getPrintFrame(), and print().
|
staticconstexprprivate |
Threshold for walking scan state and "rebasing" totals/offsets.
Definition at line 322 of file PrettyPrinter.h.
Referenced by rebaseIfNeeded().
|
private |
Definition at line 279 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 287 of file PrettyPrinter.h.
Referenced by add(), addTokens(), checkStack(), checkStream(), clear(), eof(), and rebaseIfNeeded().
|
private |
Characters left on this line.
Definition at line 275 of file PrettyPrinter.h.
Referenced by checkStream(), and print().
|
private |
index of first token, for resolving scanStack entries.
Definition at line 284 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 282 of file PrettyPrinter.h.
Referenced by add(), addTokens(), advanceLeft(), checkStack(), checkStream(), clear(), and rebaseIfNeeded().