17 : blame_printer(std::
move(blame)) {
18 if (filename.empty()) {
19 throw std::runtime_error(
"Empty filename for CodePrinter");
22 ofs.open(filename.c_str());
25 auto msg =
"Error while opening file '" + filename +
"' for CodePrinter";
26 throw std::runtime_error(msg);
63 while (start_line < lines.size()) {
64 const auto& line = lines[start_line];
72 for (
auto line_it = line.begin(); line_it != line.end() && *line_it ==
' '; ++line_it) {
78 for (
const auto& line: lines) {
79 if (line.size() < prefix_length) {
81 if (std::find_if_not(line.begin(), line.end(), [](
char c) { return c ==
' '; }) !=
83 throw std::invalid_argument(
"Indentation mismatch");
86 add_line(line.substr(prefix_length));
92 for (std::size_t
i = 0;
i <
n; ++
i) {
void chain_block(std::string const &expression)
end a block and immediately start a new one (i.e. "[indent-1]} [expression] {\n")
void blame()
Blame when on the requested line.
void pop_block()
end of current block scope (i.e. end with "}") and adds one NL character
std::unique_ptr< utils::Blame > blame_printer
CodePrinter(std::unique_ptr< utils::Blame > blame)
void add_indent()
print whitespaces for indentation
void add_multi_line(const std::string &)
void push_block()
start a block scope without indentation (i.e. "{\n")
void add_text(Args &&... args)
void add_newline(std::size_t n=1)
void add_line(Args &&... args)
void pop_block_nl(std::size_t num_newlines=0)
same as pop_block but control the number of NL characters (0 or more) with num_newlines parameter
std::unique_ptr< std::ostream > result
Helper class for printing C/C++ code.
static std::vector< std::string > split_string(const std::string &text, char delimiter)
Split a text in a list of words, using a given delimiter character.
void move(Item *q1, Item *q2, Item *q3)
encapsulates code generation backend implementations
int const size_t const size_t n
Implement string manipulation functions.