Public Member Functions | List of all members
clang::insights::OutputFormatHelper Class Reference

The C++ Insights formatter. More...

#include "OutputFormatHelper.h"

Public Member Functions

 OutputFormatHelper ()=default
 
 OutputFormatHelper (const unsigned indent)
 
 operator std::string_view () const &
 
auto size () const
 
size_t CurrentPos () const
 Returns the current position in the output buffer.
 
void InsertAt (const size_t atPos, std::string_view data)
 Insert a string before the position atPos.
 
 STRONG_BOOL (SkipIndenting)
 
auto GetIndent () const
 
void SetIndent (const unsigned indent, const SkipIndenting skipIndenting=SkipIndenting::No)
 Set the indent level of this class to indent.
 
void SetIndent (const OutputFormatHelper &rhs, const SkipIndenting skipIndenting=SkipIndenting::No)
 Set the indent level of this class to that of rhs.
 
bool empty () const
 Check whether the buffer is empty.
 
std::string & GetString ()
 Returns a reference to the underlying string buffer.
 
void Append (const char c)
 Append a single character.
 
void Append (const std::string_view &arg)
 
void Append (const auto &... args)
 Append a variable number of data.
 
void AppendNewLine (const char c)
 Same as Append but adds a newline after the last argument.
 
void AppendNewLine (const std::string_view &arg)
 
void AppendNewLine (const auto &... args)
 Same as Append but adds a newline after the last argument.
 
void AppendComment (const std::string_view &arg)
 
void AppendCommentNewLine (const std::string_view &arg)
 
void AppendCommentNewLine (const auto &... args)
 
 STRONG_BOOL (NameOnly)
 
 STRONG_BOOL (GenMissingParamName)
 
void AppendParameterList (const ArrayRef< ParmVarDecl * > parameters, const NameOnly nameOnly=NameOnly::No, const GenMissingParamName genMissingParamName=GenMissingParamName::No)
 Append a ParamVarDecl array.
 
void IncreaseIndent ()
 Increase the current indention by SCOPE_INDENT.
 
void DecreaseIndent ()
 Decrease the current indention by SCOPE_INDENT.
 
void OpenScope ()
 Open a scope by inserting a '{' followed by an indented newline.
 
 STRONG_BOOL (NoNewLineBefore)
 
void CloseScope (const NoNewLineBefore newLineBefore=NoNewLineBefore::No)
 Close a scope by inserting a '}'.
 
void CloseScopeWithSemi (const NoNewLineBefore newLineBefore=NoNewLineBefore::No)
 Similiar to CloseScope only this time a ';' is inserted after the brace.
 
void AppendComma (OnceFalse &needsComma)
 Append a comma if needed.
 
void AppendSemiNewLine ()
 Append a semicolon and a newline.
 
template<typename... Args>
void AppendSemiNewLine (const Args &... args)
 Append a semicolon and a newline.
 
void AppendSemiNewLine (const std::string_view &arg)
 
void ForEachArg (const auto &arguments, auto &&lambda)
 Append a argument list to the buffer.
 
void InsertIfDefTemplateGuard ()
 
void InsertEndIfTemplateGuard ()
 

Detailed Description

The C++ Insights formatter.

Most of the code is handed to OutputFormatHelper for easy code formatting.

Definition at line 27 of file OutputFormatHelper.h.

Constructor & Destructor Documentation

◆ OutputFormatHelper() [1/2]

clang::insights::OutputFormatHelper::OutputFormatHelper ( )
default

◆ OutputFormatHelper() [2/2]

clang::insights::OutputFormatHelper::OutputFormatHelper ( const unsigned  indent)
inlineexplicit

Definition at line 32 of file OutputFormatHelper.h.

Member Function Documentation

◆ Append() [1/3]

void clang::insights::OutputFormatHelper::Append ( const auto &...  args)
inline

Append a variable number of data.

The StrCat function which is used ensures, that a StringRef or a char are converted appropriately.

Definition at line 91 of file OutputFormatHelper.h.

References clang::insights::details::StrCat().

◆ Append() [2/3]

void clang::insights::OutputFormatHelper::Append ( const char  c)
inline

Append a single character.

Append a single character to the buffer

Definition at line 84 of file OutputFormatHelper.h.

Referenced by AppendComma(), AppendComment(), AppendParameterList(), clang::insights::AppendTemplateTypeParamName(), CloseScope(), CloseScopeWithSemi(), clang::insights::CodeGenerator::FormatCast(), clang::insights::CfrontCodeGenerator::FormatCast(), clang::insights::GetDeclContext(), clang::insights::details::SimpleTypePrinter::GetTypeString(), clang::insights::ArrayInitCodeGenerator::InsertArg(), clang::insights::StructuredBindingsCodeGenerator::InsertArg(), clang::insights::UsingCodeGenerator::InsertArg(), clang::insights::CfrontCodeGenerator::InsertArg(), clang::insights::CfrontCodeGenerator::InsertArg(), clang::insights::CfrontCodeGenerator::InsertArg(), clang::insights::LambdaCodeGenerator::InsertArg(), clang::insights::StructuredBindingsCodeGenerator::InsertArg(), clang::insights::LambdaInitCaptureCodeGenerator::InsertArg(), clang::insights::UsingCodeGenerator::InsertArg(), clang::insights::LambdaNameOnlyCodeGenerator::InsertArg(), clang::insights::CoroutinesCodeGenerator::InsertArg(), clang::insights::CfrontCodeGenerator::InsertArg(), clang::insights::CodeGenerator::InsertAttribute(), clang::insights::CodeGenerator::InsertAttributes(), clang::insights::CodeGenerator::InsertConceptConstraint(), clang::insights::CodeGenerator::InsertConceptConstraint(), clang::insights::CodeGenerator::InsertConstructorExpr(), clang::insights::CodeGenerator::InsertCurlysIfRequired(), clang::insights::CodeGenerator::InsertCXXMethodDecl(), clang::insights::CodeGenerator::InsertCXXMethodHeader(), clang::insights::CodeGenerator::InsertFunctionNameWithReturnType(), clang::insights::CodeGenerator::LambdaHelper::insertInits(), clang::insights::CodeGenerator::InsertLambdaStaticInvoker(), clang::insights::CodeGenerator::InsertNamespace(), clang::insights::CodeGenerator::InsertQualifierAndName(), clang::insights::CodeGenerator::InsertQualifierAndNameWithTemplateArgs(), clang::insights::CodeGenerator::InsertSuffix(), clang::insights::CodeGenerator::InsertTemplateArg(), clang::insights::CodeGenerator::InsertTemplateArgs(), clang::insights::CodeGenerator::InsertTemplateParameters(), OpenScope(), clang::insights::CodeGenerator::ParseDeclContext(), clang::insights::ToDo(), clang::insights::CodeGenerator::WrapInCompoundIfNeeded(), clang::insights::CodeGenerator::WrapInParensOrCurlys(), and clang::insights::MultiStmtDeclCodeGenerator::~MultiStmtDeclCodeGenerator().

◆ Append() [3/3]

void clang::insights::OutputFormatHelper::Append ( const std::string_view &  arg)
inline

Definition at line 86 of file OutputFormatHelper.h.

◆ AppendComma()

void clang::insights::OutputFormatHelper::AppendComma ( OnceFalse needsComma)
inline

Append a comma if needed.

Definition at line 182 of file OutputFormatHelper.h.

References Append().

Referenced by ForEachArg(), and clang::insights::CodeGenerator::InsertTemplateParameters().

◆ AppendComment()

void clang::insights::OutputFormatHelper::AppendComment ( const std::string_view &  arg)
inline

Definition at line 118 of file OutputFormatHelper.h.

References Append().

Referenced by AppendCommentNewLine(), and AppendCommentNewLine().

◆ AppendCommentNewLine() [1/2]

void clang::insights::OutputFormatHelper::AppendCommentNewLine ( const auto &...  args)
inline

Definition at line 131 of file OutputFormatHelper.h.

References AppendComment(), and clang::insights::StrCat().

◆ AppendCommentNewLine() [2/2]

void clang::insights::OutputFormatHelper::AppendCommentNewLine ( const std::string_view &  arg)
inline

◆ AppendNewLine() [1/3]

void clang::insights::OutputFormatHelper::AppendNewLine ( const auto &...  args)
inline

Same as Append but adds a newline after the last argument.

Definition at line 109 of file OutputFormatHelper.h.

References clang::insights::details::StrCat().

◆ AppendNewLine() [2/3]

void clang::insights::OutputFormatHelper::AppendNewLine ( const char  c)
inline

◆ AppendNewLine() [3/3]

void clang::insights::OutputFormatHelper::AppendNewLine ( const std::string_view &  arg)
inline

Definition at line 102 of file OutputFormatHelper.h.

◆ AppendParameterList()

void clang::insights::OutputFormatHelper::AppendParameterList ( const ArrayRef< ParmVarDecl * >  parameters,
const NameOnly  nameOnly = NameOnly::No,
const GenMissingParamName  genMissingParamName = GenMissingParamName::No 
)

◆ AppendSemiNewLine() [1/3]

void clang::insights::OutputFormatHelper::AppendSemiNewLine ( )
inline

◆ AppendSemiNewLine() [2/3]

template<typename... Args>
void clang::insights::OutputFormatHelper::AppendSemiNewLine ( const Args &...  args)
inline

Append a semicolon and a newline.

Definition at line 194 of file OutputFormatHelper.h.

References AppendNewLine(), and clang::insights::details::StrCat().

◆ AppendSemiNewLine() [3/3]

void clang::insights::OutputFormatHelper::AppendSemiNewLine ( const std::string_view &  arg)
inline

Definition at line 203 of file OutputFormatHelper.h.

References AppendNewLine().

◆ CloseScope()

void clang::insights::OutputFormatHelper::CloseScope ( const NoNewLineBefore  newLineBefore = NoNewLineBefore::No)

Close a scope by inserting a '}'.

With the parameter newLineBefore a newline after the brace can be inserted.

Definition at line 58 of file OutputFormatHelper.cpp.

References Append(), and DecreaseIndent().

Referenced by CloseScopeWithSemi(), clang::insights::CoroutinesCodeGenerator::InsertCoroutine(), clang::insights::CodeGenerator::InsertLambdaStaticInvoker(), and clang::insights::CodeGenerator::WrapInCompoundIfNeeded().

◆ CloseScopeWithSemi()

void clang::insights::OutputFormatHelper::CloseScopeWithSemi ( const NoNewLineBefore  newLineBefore = NoNewLineBefore::No)
inline

Similiar to CloseScope only this time a ';' is inserted after the brace.

Definition at line 175 of file OutputFormatHelper.h.

References Append(), and CloseScope().

◆ CurrentPos()

size_t clang::insights::OutputFormatHelper::CurrentPos ( ) const
inline

Returns the current position in the output buffer.

Definition at line 42 of file OutputFormatHelper.h.

Referenced by clang::insights::CodeGenerator::InsertCXXMethodDecl(), and clang::insights::CodeGenerator::UpdateCurrentPos().

◆ DecreaseIndent()

void clang::insights::OutputFormatHelper::DecreaseIndent ( )
inline

Decrease the current indention by SCOPE_INDENT.

Definition at line 153 of file OutputFormatHelper.h.

Referenced by CloseScope().

◆ empty()

bool clang::insights::OutputFormatHelper::empty ( ) const
inline

Check whether the buffer is empty.

This also treats a string of just whitespaces as empty.

Definition at line 76 of file OutputFormatHelper.h.

Referenced by clang::insights::CodeGenerator::LambdaHelper::finish().

◆ ForEachArg()

void clang::insights::OutputFormatHelper::ForEachArg ( const auto &  arguments,
auto &&  lambda 
)
inline

Append a argument list to the buffer.

This function takes care of the delimiting ',' between the parameters. The lambda lambda is called to each argument after the comma was inserted. Usage:

ForEachArg(parameters, [&](const auto& p) {
// do something with p
});
void ForEachArg(const auto &arguments, auto &&lambda)
Append a argument list to the buffer.

Definition at line 219 of file OutputFormatHelper.h.

References AppendComma().

Referenced by AppendParameterList(), and clang::insights::CodeGenerator::ForEachArg().

◆ GetIndent()

auto clang::insights::OutputFormatHelper::GetIndent ( ) const
inline

Definition at line 49 of file OutputFormatHelper.h.

◆ GetString()

std::string & clang::insights::OutputFormatHelper::GetString ( )
inline

◆ IncreaseIndent()

void clang::insights::OutputFormatHelper::IncreaseIndent ( )
inline

Increase the current indention by SCOPE_INDENT.

Definition at line 151 of file OutputFormatHelper.h.

Referenced by OpenScope().

◆ InsertAt()

void clang::insights::OutputFormatHelper::InsertAt ( const size_t  atPos,
std::string_view  data 
)
inline

◆ InsertEndIfTemplateGuard()

void clang::insights::OutputFormatHelper::InsertEndIfTemplateGuard ( )
inline

◆ InsertIfDefTemplateGuard()

void clang::insights::OutputFormatHelper::InsertIfDefTemplateGuard ( )
inline

◆ OpenScope()

void clang::insights::OutputFormatHelper::OpenScope ( )
inline

◆ operator std::string_view()

clang::insights::OutputFormatHelper::operator std::string_view ( ) const &
inline

Definition at line 37 of file OutputFormatHelper.h.

◆ SetIndent() [1/2]

void clang::insights::OutputFormatHelper::SetIndent ( const OutputFormatHelper rhs,
const SkipIndenting  skipIndenting = SkipIndenting::No 
)
inline

Set the indent level of this class to that of rhs.

Definition at line 62 of file OutputFormatHelper.h.

◆ SetIndent() [2/2]

void clang::insights::OutputFormatHelper::SetIndent ( const unsigned  indent,
const SkipIndenting  skipIndenting = SkipIndenting::No 
)
inline

◆ size()

auto clang::insights::OutputFormatHelper::size ( ) const
inline

Definition at line 39 of file OutputFormatHelper.h.

◆ STRONG_BOOL() [1/4]

clang::insights::OutputFormatHelper::STRONG_BOOL ( GenMissingParamName  )

◆ STRONG_BOOL() [2/4]

clang::insights::OutputFormatHelper::STRONG_BOOL ( NameOnly  )

◆ STRONG_BOOL() [3/4]

clang::insights::OutputFormatHelper::STRONG_BOOL ( NoNewLineBefore  )

◆ STRONG_BOOL() [4/4]

clang::insights::OutputFormatHelper::STRONG_BOOL ( SkipIndenting  )

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