Alexandria  2.22.0
Please provide a description of the project.
GraphvizGenerator.cpp
Go to the documentation of this file.
1 
20 #include <boost/algorithm/string.hpp>
21 
22 namespace Pyston {
23 
24 static std::string escape(const std::string& str) {
25  return boost::replace_all_copy(str, "\"", "\\\"");
26 }
27 
28 GraphvizGenerator::GraphvizGenerator(const std::string& label) : m_unique_id(0) {
29  m_stream << "digraph G {" << std::endl << "\tlabel=\"" << escape(label) << "\"" << std::endl;
30 }
31 
33  m_stream << "\t" << '"' << m_unique_id << '"' << " [label=\"" << escape(node->repr()) << "\"];" << std::endl;
34  if (!m_stack.empty()) {
35  m_stream << "\t\"" << m_stack.back() << '"' << " -> \"" << m_unique_id << "\"" << std::endl;
36  }
38  ++m_unique_id;
39 }
40 
42  m_stack.pop_back();
43 }
44 
46  return m_stream.str() + "}";
47 }
48 
49 } // end of namespace Pyston
T back(T... args)
void exit(const NodeBase *) override
std::list< int64_t > m_stack
std::stringstream m_stream
GraphvizGenerator(const std::string &label)
void enter(const NodeBase *node) override
virtual std::string repr() const =0
T empty(T... args)
T endl(T... args)
static std::string escape(const std::string &str)
T pop_back(T... args)
T push_back(T... args)
T str(T... args)