User Guide
nmodl_printer.cpp
Go to the documentation of this file.
1
/*
2
* Copyright 2023 Blue Brain Project, EPFL.
3
* See the top-level LICENSE file for details.
4
*
5
* SPDX-License-Identifier: Apache-2.0
6
*/
7
8
#include "
printer/nmodl_printer.hpp
"
9
#include "
utils/string_utils.hpp
"
10
11
namespace
nmodl
{
12
namespace
printer {
13
14
NMODLPrinter::NMODLPrinter
(
const
std::string& filename) {
15
if
(filename.empty()) {
16
throw
std::runtime_error(
"Empty filename for NMODLPrinter"
);
17
}
18
19
ofs
.open(filename.c_str());
20
21
if
(
ofs
.fail()) {
22
auto
msg =
"Error while opening file '"
+ filename +
"' for NMODLPrinter"
;
23
throw
std::runtime_error(msg);
24
}
25
26
sbuf
=
ofs
.rdbuf();
27
result
= std::make_shared<std::ostream>(
sbuf
);
28
}
29
30
void
NMODLPrinter::push_level
() {
31
indent_level
++;
32
*
result
<<
"{"
;
33
add_newline
();
34
}
35
36
void
NMODLPrinter::add_indent
() {
37
*
result
<< std::string(
indent_level
* 4,
' '
);
38
}
39
40
void
NMODLPrinter::add_element
(
const
std::string& name) {
41
*
result
<< name <<
""
;
42
}
43
44
void
NMODLPrinter::add_newline
() {
45
*
result
<< std::endl;
46
}
47
48
void
NMODLPrinter::pop_level
() {
49
indent_level
--;
50
add_indent
();
51
*
result
<<
"}"
;
52
}
53
54
}
// namespace printer
55
}
// namespace nmodl
nmodl::printer::NMODLPrinter::result
std::shared_ptr< std::ostream > result
Definition:
nmodl_printer.hpp:42
nmodl::printer::NMODLPrinter::sbuf
std::streambuf * sbuf
Definition:
nmodl_printer.hpp:41
nmodl
encapsulates code generation backend implementations
Definition:
ast_common.hpp:26
nmodl::printer::NMODLPrinter::NMODLPrinter
NMODLPrinter()
Definition:
nmodl_printer.hpp:46
nmodl::printer::NMODLPrinter::add_element
void add_element(const std::string &)
Definition:
nmodl_printer.cpp:40
string_utils.hpp
Implement string manipulation functions.
nmodl::printer::NMODLPrinter::pop_level
void pop_level()
end of current block scope (i.e.
Definition:
nmodl_printer.cpp:48
nmodl::printer::NMODLPrinter::add_newline
void add_newline()
Definition:
nmodl_printer.cpp:44
nmodl::printer::NMODLPrinter::add_indent
void add_indent()
print whitespaces for indentation
Definition:
nmodl_printer.cpp:36
nmodl::printer::NMODLPrinter::indent_level
size_t indent_level
Definition:
nmodl_printer.hpp:43
nmodl_printer.hpp
Helper class for printing AST back to NMDOL test.
nmodl::printer::NMODLPrinter::ofs
std::ofstream ofs
Definition:
nmodl_printer.hpp:40
nmodl::printer::NMODLPrinter::push_level
void push_level()
start of new block scope (i.e.
Definition:
nmodl_printer.cpp:30
src
printer
nmodl_printer.cpp