9
#include "simodo/engine/utility/generateDotFile.h"
10
#include "simodo/engine/utility/common_functions.h"
14
#include "simodo/inout/convert/functions.h"
21
void generateDotBoxes(const simodo::ast::Node & node, std::ostream & dot, const std::map<simodo::ast::OperationCode,std::string> &excluded_nodes)
23
for(const simodo::ast::Node & n : node.branches())
25
std::string substitute_text;
27
if (auto it=excluded_nodes.find(n.operation()); it != excluded_nodes.end()) {
28
substitute_text = it->second;
30
if (substitute_text.empty())
34
std::string text = simodo::inout::toU8(n.token().token());
36
simodo::engine::replaceAll(text, "\\", "\\\\");
37
simodo::engine::replaceAll(text, "{", "\\{");
38
simodo::engine::replaceAll(text, "}", "\\}");
39
simodo::engine::replaceAll(text, ">", "\\>");
40
simodo::engine::replaceAll(text, "<", "\\<");
41
simodo::engine::replaceAll(text, "\"", "\\\"");
42
simodo::engine::replaceAll(text, "|", "\\|");
47
if (!substitute_text.empty())
48
dot << "[fillcolor=\"gold\", label=\"{"
52
dot << ((n.operation() == 0 || n.operation() >= 1000)
54
: "[fillcolor=\"lightgreen\", label=\"{")
55
<< simodo::inout::toU8(n.host())
56
<< " | " << n.operation()
63
generateDotBoxes(n, dot, excluded_nodes);
67
void generateDotLines(const simodo::ast::Node & node, std::ostream & dot, const std::map<simodo::ast::OperationCode,std::string> &excluded_nodes)
70
for(const simodo::ast::Node & n : node.branches())
72
if (auto it=excluded_nodes.find(n.operation()); it != excluded_nodes.end()) {
73
if (it->second.empty())
76
dot << "\tS" << &node << " -> S" << &n
79
generateDotLines(n, dot, excluded_nodes);
85
namespace simodo::engine
87
void generateDotFile(const std::string & dot_file_name,
88
const ast::Node & node,
89
const std::map<ast::OperationCode,std::string> &excluded_nodes)
91
std::ofstream dot(dot_file_name);
95
std::cout << "Не удалось записать в файл '" << dot_file_name << "'" << std::endl;
99
dot << "digraph \"" << dot_file_name << "\" { rankdir=\"LR\";" << std::endl;
100
dot << "\t" << "node [ shape=record, fontsize=12, style=\"rounded,filled\", width=0, height=0 ];" << std::endl;
101
dot << "\t" << "edge [ arrowsize=0.7 ];" << std::endl;
102
dot << "\tS" << &node << " [shape=point]" << std::endl;
104
generateDotBoxes(node, dot, excluded_nodes);
105
generateDotLines(node, dot, excluded_nodes);
107
dot << "}" << std::endl;