CIRCT
20.0.0git
|
Wrap a PrettyPrinter with TokenBuilder features as well as operator<<'s. More...
#include <PrettyPrinterHelpers.h>
Public Member Functions | |
TokenStream (PPTy &pp, TokenStringSaver &saver) | |
Create a TokenStream using the specified PrettyPrinter and StringSaver storage. More... | |
TokenStream & | operator<< (const char *s) |
Add a string literal (external storage). More... | |
TokenStream & | operator<< (StringRef s) |
Add a string token (saved to storage). More... | |
TokenStream & | operator<< (const PPExtString &str) |
String has external storage. More... | |
TokenStream & | operator<< (const PPSaveString &str) |
String must be saved. More... | |
TokenStream & | operator<< (PP s) |
Convenience for inline streaming of builder methods. More... | |
TokenStream & | operator<< (Token t) |
Stream support for user-created Token's. More... | |
template<typename T > | |
TokenStream & | addAsString (T &&t) |
General-purpose "format this" helper, for types not supported by operator<< yet. More... | |
template<typename Callable , unsigned BufferLen = 128> | |
auto | invokeWithStringOS (Callable &&c) |
Helper to invoke code with a llvm::raw_ostream argument for compatibility. More... | |
TokenStream & | writeEscaped (StringRef str, bool useHexEscapes=false) |
Write escaped versions of the string, saved in storage. More... | |
TokenStream & | writeQuotedEscaped (StringRef str, bool useHexEscapes=false, StringRef left="\"", StringRef right="\"") |
template<typename T , typename Callable > | |
auto | scopedBox (T &&t, Callable &&c, Token close=EndToken()) |
Open a box, invoke the lambda, and close it after. More... | |
Public Member Functions inherited from circt::pretty::TokenBuilder< PrettyPrinter > | |
TokenBuilder (PrettyPrinter &pp) | |
std::enable_if_t< std::is_base_of_v< Token, T > > | add (Args &&...args) |
Add new token. More... | |
void | addToken (Token t) |
void | eof () |
End of a stream. More... | |
void | literal (StringRef str) |
Add a literal (with external storage). More... | |
void | nbsp () |
Add a non-breaking space. More... | |
void | nbsp (unsigned n) |
Add multiple non-breaking spaces as a single token. More... | |
void | neverbreak () |
Add a 'neverbreak' break. Always 'fits'. More... | |
void | newline () |
Add a newline (break too wide to fit, always breaks). More... | |
void | spaces (uint32_t n) |
Add breakable spaces. More... | |
void | space () |
Add a breakable space. More... | |
void | zerobreak () |
Add a break that is zero-wide if not broken. More... | |
void | bbox (int32_t offset=0, Breaks breaks=Breaks::Consistent) |
Start a IndentStyle::Block group with specified offset. More... | |
void | cbox (int32_t offset=0, IndentStyle style=IndentStyle::Visual) |
Start a consistent group with specified offset. More... | |
void | ibox (int32_t offset=0, IndentStyle style=IndentStyle::Visual) |
Start an inconsistent group with specified offset. More... | |
void | neverbox () |
Start a group that cannot break, including nested groups. More... | |
void | end () |
End a group. More... | |
Protected Attributes | |
TokenStringSaver & | saver |
Private Types | |
using | Base = TokenBuilder< PPTy > |
Wrap a PrettyPrinter with TokenBuilder features as well as operator<<'s.
String behavior: Strings streamed as const char *
are assumed to have external storage, and StringRef's are saved until no longer needed. Use PPExtString() and PPSaveString() wrappers to specify/override behavior.
Definition at line 241 of file PrettyPrinterHelpers.h.
|
private |
Definition at line 242 of file PrettyPrinterHelpers.h.
|
inline |
Create a TokenStream using the specified PrettyPrinter and StringSaver storage.
Strings are saved in saver
, which is generally the listener in the PrettyPrinter, but may not be (e.g., using BufferingPP).
Definition at line 251 of file PrettyPrinterHelpers.h.
|
inline |
General-purpose "format this" helper, for types not supported by operator<< yet.
Definition at line 331 of file PrettyPrinterHelpers.h.
References circt::pretty::TokenStream< PPTy >::invokeWithStringOS().
|
inline |
Helper to invoke code with a llvm::raw_ostream argument for compatibility.
All data is gathered into a single string token.
Definition at line 339 of file PrettyPrinterHelpers.h.
Referenced by circt::pretty::TokenStream< PPTy >::addAsString(), and circt::pretty::TokenStream< PPTy >::writeQuotedEscaped().
|
inline |
Add a string literal (external storage).
Definition at line 254 of file PrettyPrinterHelpers.h.
References circt::pretty::TokenBuilder< PPTy >::literal().
|
inline |
String has external storage.
Definition at line 265 of file PrettyPrinterHelpers.h.
References circt::pretty::TokenBuilder< PPTy >::literal(), and circt::pretty::PPExtString::str.
|
inline |
String must be saved.
Definition at line 271 of file PrettyPrinterHelpers.h.
References circt::pretty::TokenStringSaver::save(), circt::pretty::TokenStream< PPTy >::saver, and circt::pretty::PPSaveString::str.
|
inline |
Convenience for inline streaming of builder methods.
Definition at line 277 of file PrettyPrinterHelpers.h.
References circt::pretty::TokenBuilder< PPTy >::bbox(), circt::pretty::bbox2, circt::pretty::TokenBuilder< PPTy >::cbox(), circt::pretty::cbox0, circt::pretty::cbox2, circt::pretty::TokenBuilder< PPTy >::end(), circt::pretty::end, circt::pretty::TokenBuilder< PPTy >::eof(), circt::pretty::eof, circt::pretty::TokenBuilder< PPTy >::ibox(), circt::pretty::ibox0, circt::pretty::ibox2, circt::pretty::TokenBuilder< PPTy >::nbsp(), circt::pretty::nbsp, circt::pretty::TokenBuilder< PPTy >::neverbox(), circt::pretty::neverbox, circt::pretty::TokenBuilder< PPTy >::neverbreak(), circt::pretty::neverbreak, circt::pretty::TokenBuilder< PPTy >::newline(), circt::pretty::newline, circt::pretty::TokenBuilder< PPTy >::space(), circt::pretty::space, circt::pretty::TokenBuilder< PPTy >::zerobreak(), and circt::pretty::zerobreak.
|
inline |
Add a string token (saved to storage).
Definition at line 259 of file PrettyPrinterHelpers.h.
References circt::pretty::TokenStringSaver::save(), and circt::pretty::TokenStream< PPTy >::saver.
|
inline |
Stream support for user-created Token's.
Definition at line 323 of file PrettyPrinterHelpers.h.
References circt::pretty::TokenBuilder< PPTy >::addToken().
|
inline |
Open a box, invoke the lambda, and close it after.
Definition at line 367 of file PrettyPrinterHelpers.h.
|
inline |
Write escaped versions of the string, saved in storage.
Definition at line 350 of file PrettyPrinterHelpers.h.
References circt::pretty::TokenStream< PPTy >::writeQuotedEscaped().
|
inline |
Definition at line 353 of file PrettyPrinterHelpers.h.
References circt::pretty::TokenStream< PPTy >::invokeWithStringOS().
Referenced by circt::pretty::TokenStream< PPTy >::writeEscaped().
|
protected |
Definition at line 245 of file PrettyPrinterHelpers.h.
Referenced by circt::pretty::TokenStream< PPTy >::operator<<().