9 #include "utils/logger.hpp"
11 #include <nlohmann/json.hpp>
18 if (filename.empty()) {
19 throw std::runtime_error(
"Empty filename for JSONPrinter");
22 ofs.open(filename.c_str());
25 auto msg =
"Error while opening file '" + filename +
"' for JSONPrinter";
26 throw std::runtime_error(msg);
36 throw std::logic_error{
"Block not initialized (push_block missing?)"};
46 if (
block ==
nullptr) {
47 logger->warn(
"JSONPrinter : can't add property without block");
void flush()
Dump json object to stream (typically at the end) nspaces is number of spaces used for indentation.
const std::string child_key
json key for children
bool expand
true if we need to expand keys i.e.
void add_node(std::string value, const std::string &key="name")
Add node to json (typically basic type)
void add_block_property(std::string const &name, const std::string &value)
Add property to the block which is added last.
std::shared_ptr< json > block
single (current) nmodl block / statement
std::shared_ptr< std::ostream > result
common output stream for file, cout or stringstream
void push_block(const std::string &value, const std::string &key="name")
Add new json object (typically start of new block) name here is type of new block encountered.
void pop_block()
We finished processing a block, add processed block to it's parent block.
JSONPrinter()
By default dump output to std::cout.
bool compact
true if need to print json in compact format
std::stack< std::shared_ptr< json > > stack
stack that holds all parent blocks / statements
Helper class for printing AST in JSON form.
void move(Item *q1, Item *q2, Item *q3)
encapsulates code generation backend implementations