CIRCT  20.0.0git
Public Member Functions | Protected Attributes | Private Types | List of all members
circt::pretty::TokenStream< PPTy > Class Template Reference

Wrap a PrettyPrinter with TokenBuilder features as well as operator<<'s. More...

#include <PrettyPrinterHelpers.h>

Inheritance diagram for circt::pretty::TokenStream< PPTy >:
Inheritance graph
[legend]
Collaboration diagram for circt::pretty::TokenStream< PPTy >:
Collaboration graph
[legend]

Public Member Functions

 TokenStream (PPTy &pp, TokenStringSaver &saver)
 Create a TokenStream using the specified PrettyPrinter and StringSaver storage. More...
 
TokenStreamoperator<< (const char *s)
 Add a string literal (external storage). More...
 
TokenStreamoperator<< (StringRef s)
 Add a string token (saved to storage). More...
 
TokenStreamoperator<< (const PPExtString &str)
 String has external storage. More...
 
TokenStreamoperator<< (const PPSaveString &str)
 String must be saved. More...
 
TokenStreamoperator<< (PP s)
 Convenience for inline streaming of builder methods. More...
 
TokenStreamoperator<< (Token t)
 Stream support for user-created Token's. More...
 
template<typename T >
TokenStreamaddAsString (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...
 
TokenStreamwriteEscaped (StringRef str, bool useHexEscapes=false)
 Write escaped versions of the string, saved in storage. More...
 
TokenStreamwriteQuotedEscaped (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

TokenStringSaversaver
 

Private Types

using Base = TokenBuilder< PPTy >
 

Detailed Description

template<typename PPTy = PrettyPrinter>
class circt::pretty::TokenStream< 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.

Member Typedef Documentation

◆ Base

template<typename PPTy = PrettyPrinter>
using circt::pretty::TokenStream< PPTy >::Base = TokenBuilder<PPTy>
private

Definition at line 242 of file PrettyPrinterHelpers.h.

Constructor & Destructor Documentation

◆ TokenStream()

template<typename PPTy = PrettyPrinter>
circt::pretty::TokenStream< PPTy >::TokenStream ( PPTy &  pp,
TokenStringSaver saver 
)
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.

Member Function Documentation

◆ addAsString()

template<typename PPTy = PrettyPrinter>
template<typename T >
TokenStream& circt::pretty::TokenStream< PPTy >::addAsString ( T &&  t)
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().

◆ invokeWithStringOS()

template<typename PPTy = PrettyPrinter>
template<typename Callable , unsigned BufferLen = 128>
auto circt::pretty::TokenStream< PPTy >::invokeWithStringOS ( Callable &&  c)
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().

◆ operator<<() [1/6]

template<typename PPTy = PrettyPrinter>
TokenStream& circt::pretty::TokenStream< PPTy >::operator<< ( const char *  s)
inline

Add a string literal (external storage).

Definition at line 254 of file PrettyPrinterHelpers.h.

References circt::pretty::TokenBuilder< PPTy >::literal().

◆ operator<<() [2/6]

template<typename PPTy = PrettyPrinter>
TokenStream& circt::pretty::TokenStream< PPTy >::operator<< ( const PPExtString str)
inline

String has external storage.

Definition at line 265 of file PrettyPrinterHelpers.h.

References circt::pretty::TokenBuilder< PPTy >::literal(), and circt::pretty::PPExtString::str.

◆ operator<<() [3/6]

template<typename PPTy = PrettyPrinter>
TokenStream& circt::pretty::TokenStream< PPTy >::operator<< ( const PPSaveString str)
inline

◆ operator<<() [4/6]

template<typename PPTy = PrettyPrinter>
TokenStream& circt::pretty::TokenStream< PPTy >::operator<< ( PP  s)
inline

◆ operator<<() [5/6]

template<typename PPTy = PrettyPrinter>
TokenStream& circt::pretty::TokenStream< PPTy >::operator<< ( StringRef  s)
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.

◆ operator<<() [6/6]

template<typename PPTy = PrettyPrinter>
TokenStream& circt::pretty::TokenStream< PPTy >::operator<< ( Token  t)
inline

Stream support for user-created Token's.

Definition at line 323 of file PrettyPrinterHelpers.h.

References circt::pretty::TokenBuilder< PPTy >::addToken().

◆ scopedBox()

template<typename PPTy = PrettyPrinter>
template<typename T , typename Callable >
auto circt::pretty::TokenStream< PPTy >::scopedBox ( T &&  t,
Callable &&  c,
Token  close = EndToken() 
)
inline

Open a box, invoke the lambda, and close it after.

Definition at line 367 of file PrettyPrinterHelpers.h.

◆ writeEscaped()

template<typename PPTy = PrettyPrinter>
TokenStream& circt::pretty::TokenStream< PPTy >::writeEscaped ( StringRef  str,
bool  useHexEscapes = false 
)
inline

Write escaped versions of the string, saved in storage.

Definition at line 350 of file PrettyPrinterHelpers.h.

References circt::pretty::TokenStream< PPTy >::writeQuotedEscaped().

◆ writeQuotedEscaped()

template<typename PPTy = PrettyPrinter>
TokenStream& circt::pretty::TokenStream< PPTy >::writeQuotedEscaped ( StringRef  str,
bool  useHexEscapes = false,
StringRef  left = "\"",
StringRef  right = "\"" 
)
inline

Member Data Documentation

◆ saver

template<typename PPTy = PrettyPrinter>
TokenStringSaver& circt::pretty::TokenStream< PPTy >::saver
protected

The documentation for this class was generated from the following file: