Spicy
Public Member Functions | Public Attributes | List of all members
hilti::detail::cxx::Formatter Class Reference

#include <formatter.h>

Inheritance diagram for hilti::detail::cxx::Formatter:
hilti::CodeFormatter

Public Member Functions

void pushNamespace (std::string relative_ns)
 
void popNamespace ()
 
void enterNamespace (const std::string &absolute_ns)
 
void leaveNamespace ()
 
std::optional< std::string > namespace_ (int level=-1) const
 
cxx::ID relativeID (const cxx::ID &id, int level) const
 
- Public Member Functions inherited from hilti::CodeFormatter
 CodeFormatter (std::string comment="//")
 
bool output (std::ostream &out)
 
auto str () const
 
void next ()
 
void separator ()
 
void eol ()
 
void eos ()
 
void quoted (const std::string &s)
 
void comment (const std::string &s)
 
void indent ()
 
void dedent ()
 
auto & stream ()
 
CodeFormatterprintString (const std::string &s)
 
 CodeFormatter (const CodeFormatter &)=delete
 
 CodeFormatter (CodeFormatter &&)=delete
 
CodeFormatteroperator= (const CodeFormatter &f)=delete
 
CodeFormatteroperator= (CodeFormatter &&f)=delete
 

Public Attributes

bool ensure_braces_for_block = true
 
bool compact_block = true
 
bool eos_after_block = false
 
bool sep_after_block = true
 

Detailed Description

Formatter for generating C++ code.

Member Function Documentation

◆ enterNamespace()

void Formatter::enterNamespace ( const std::string &  absolute_ns)

Enters a namespace for subsequent elements. In contrast to pushNamespace, this takes an absolute namespace (i.e., from the root level) that the method might adopt based on what the formatter's current namespace is. For example, if the current namespace matches the new namespace, no namespace directive needs to be inserted at all. If the new namespace is a sub-namespace of the current one, the inserted namespace directive will include only the relative part.

Parameters
absolute_nsthe namespace, which will be adapted before being used as part of a a namespace directive.

◆ leaveNamespace()

void Formatter::leaveNamespace ( )

Leaves all current namespaces, clearing out the stack.

◆ namespace_()

std::optional< std::string > Formatter::namespace_ ( int  level = -1) const

Returns the formatter's current absolute namespace, optionally just to a given level.

Parameters
levelmax level to include, with 1 being the first.

◆ popNamespace()

void Formatter::popNamespace ( )

Removes the most recently opened namespace from the stack.

◆ pushNamespace()

void Formatter::pushNamespace ( std::string  relative_ns)

Opens a new namespace that's relative to whatever the current namespace is. The new namespace will go onto the formatter's namespace stack.

Parameters
relative_nsthe namespace, which will be used as is for a new namespace directive.

◆ relativeID()

hilti::detail::cxx::ID Formatter::relativeID ( const cxx::ID id,
int  level 
) const

Adjust an ID's scoping relative to a namespace.

Parameters
idwith absolute scoping
leveldepth of current namespace to consider
Returns
id with scoping relative to level elements of the current namespacing path

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